/* ============================================================
   STA Sync Dashboard — Light Theme Styles
   ============================================================ */

:root {
    /* Palette (Light Theme) */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-modal: #ffffff;
    --border: #e2e8f0;
    --border-light: #cbd5e1;

    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    /* Status colours (STA Branding) */
    --color-success: #009933;
    --color-success-bg: #e6f5ea;
    --color-error: #e60000;
    --color-error-bg: #fce6e6;
    --color-warning: #ff6600;
    --color-warning-bg: #ffebe6;
    --color-info: #663399;
    --color-info-bg: #f2eefa;
    --color-muted: #64748b;
    --color-muted-bg: #f1f5f9;

    /* Accent & Action */
    --accent: #0066cc;
    --accent-hover: #0052a3;

    /* Spacing & Shadows */
    --radius: 12px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.header-logo { height: 32px; }
.header-title { color: var(--text-muted); font-weight: 500; font-size: 16px; margin-left: 8px; }
.header-right { display: flex; gap: 8px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 13px; font-weight: 500;
    cursor: pointer; transition: all 0.15s ease;
}
.btn-primary { background: var(--accent); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-danger { background: var(--color-error); color: white; }
.btn-danger:hover { background: #cc0000; }
.btn-retry { background: var(--color-warning); color: white; font-weight: 600; box-shadow: var(--shadow-sm); }
.btn-retry:hover { background: #e65c00; transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none; }

/* Stats Bar */
.stats-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 24px 32px; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 24px;
    display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-sm);
}
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-success .stat-value { color: var(--color-success); }
.stat-error .stat-value { color: var(--color-error); }
.stat-skipped .stat-value { color: var(--text-muted); }

/* Filter Bar */
.filter-bar { padding: 0 32px 16px; display: flex; justify-content: space-between; align-items: center; }
.filter-group { display: flex; gap: 4px; background: var(--bg-secondary); padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.filter-btn { padding: 6px 16px; border: none; border-radius: 4px; background: transparent; color: var(--text-secondary); font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s ease; }
.filter-btn:hover { color: var(--text-primary); background: var(--bg-card-hover); }
.filter-btn.active { background: var(--accent); color: white; box-shadow: var(--shadow-sm); }

/* Events Table */
.table-container { padding: 0 32px 32px; }
.events-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.events-table thead th { background: var(--bg-primary); padding: 12px 16px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px solid var(--border); }
.events-table tbody td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.events-table tbody tr:hover { background: var(--bg-card-hover); }
.events-table tbody tr:last-child td { border-bottom: none; }

/* Status badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-associated { background: var(--color-success-bg); color: var(--color-success); border: 1px solid rgba(0,153,51,0.2); }
.badge-associated .badge-dot { background: var(--color-success); }
.badge-error { background: var(--color-error-bg); color: var(--color-error); border: 1px solid rgba(230,0,0,0.2); }
.badge-error .badge-dot { background: var(--color-error); }
.badge-ignored { background: var(--color-muted-bg); color: var(--color-muted); border: 1px solid rgba(100,116,139,0.2); }
.badge-ignored .badge-dot { background: var(--color-muted); }
.badge-already_associated { background: var(--color-info-bg); color: var(--color-info); border: 1px solid rgba(102,51,153,0.2); }
.badge-already_associated .badge-dot { background: var(--color-info); }

/* Loading & Empty state */
.loading-row td { text-align: center; padding: 40px !important; color: var(--text-muted); }
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; margin-right: 8px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 60px 20px !important; color: var(--text-muted); font-size: 14px; }
.error-text { color: var(--color-error); font-size: 12px; max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monospace { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; color: var(--text-primary); font-weight: 500; }
.email-cell { color: var(--text-secondary); font-size: 13px; }
.link-external { font-weight: 500; }
.link-external:hover { text-decoration: underline !important; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); z-index: 200; justify-content: center; align-items: center; }
.modal-overlay.active { display: flex; animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--bg-modal); border: 1px solid var(--border); border-radius: var(--radius); width: 560px; max-width: 90vw; max-height: 80vh; display: flex; flex-direction: column; animation: slideUp 0.2s ease; box-shadow: var(--shadow-lg); }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); background: var(--bg-primary); border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.modal-header h2 { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.modal-close { width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; border: none; background: transparent; cursor: pointer; color: var(--text-muted); }
.modal-close:hover { color: var(--text-primary); background: var(--border); border-radius: 4px; }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.detail-grid { display: grid; grid-template-columns: 140px 1fr; gap: 12px 16px; }
.detail-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.detail-value { font-size: 13px; word-break: break-all; color: var(--text-primary); }
.detail-error { background: var(--color-error-bg); color: var(--color-error); padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13px; margin-top: 16px; border-left: 3px solid var(--color-error); }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-primary); border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 20px; font-size: 13px; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); animation: toastIn 0.25s ease; max-width: 360px; color: var(--text-primary); font-weight: 500; }
.toast-success { border-left: 4px solid var(--color-success); }
.toast-error { border-left: 4px solid var(--color-error); }
.toast-info { border-left: 4px solid var(--accent); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* User Management UI */
#mainNavTabs { margin-left: 32px; display: flex; gap: 16px; }
#syncAllBtn { margin-right: 8px; }
.d-none { display: none !important; }
.users-filter-bar { padding-top: 24px; }
.users-title { font-size: 18px; font-weight: 600; }
.add-user-form { display: flex; flex-direction: column; gap: 16px; }

/* Login UI */
.login-overlay { display: none; position: fixed; inset: 0; background: var(--bg-primary); z-index: 9999; justify-content: center; align-items: center; }
.login-overlay.active { display: flex; }
.login-logo { height: 48px; margin-bottom: 24px; }
.login-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; width: 380px; display: flex; flex-direction: column; align-items: center; box-shadow: var(--shadow-lg); }
.login-card h2 { font-size: 20px; margin-bottom: 24px; color: var(--text-primary); font-weight: 600; text-align: center; }
.login-card form { width: 100%; display: flex; flex-direction: column; gap: 16px; }
.login-card input { width: 100%; background: var(--bg-primary); border: 1px solid var(--border); color: var(--text-primary); padding: 12px 16px; border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,102,204,0.1); }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 14px; margin-top: 8px; }
.login-card .error-text { text-align: center; margin-top: 8px; white-space: normal; }

@media (max-width: 768px) {
    .stats-bar { grid-template-columns: repeat(2, 1fr); padding: 16px; gap: 8px; }
    .header { padding: 12px 16px; }
    .table-container, .filter-bar { padding-left: 16px; padding-right: 16px; }
    .events-table { font-size: 12px; }
}
