:root {
    --bg: #F7F8FA;
    --surface: #FFFFFF;
    --sidebar: #1A1D23;
    --sidebar-hover: #2A2D35;
    --border: #E6E8EC;
    --text: #1A1D23;
    --text-dim: #6B7280;
    --accent: #7B68EE;
    --accent-dim: #EEEAFE;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --gold: #FFD100;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
body:has(main.main-no-sidebar) { grid-template-columns: 1fr; }
a { color: inherit; text-decoration: none; }
pre, code { font-family: ui-monospace, SFMono-Regular, monospace; }

/* Sidebar — sized to fit 14 nav items + brand + section labels + user
   footer in ~620px vertical so nothing scrolls on a typical laptop. */
.sidebar {
    background: var(--sidebar); color: #fff; padding: 14px 14px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 12px; border-bottom: 1px solid #2A2D35; margin-bottom: 8px; }
.brand-mark { width: 30px; height: 30px; background: linear-gradient(135deg, #7B68EE, #FFD100); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #1A1D23; font-size: 13px; flex-shrink: 0; }
.brand-text { font-weight: 700; font-size: 14px; line-height: 1.2; }
.brand-text span { display: block; font-size: 9px; color: #9CA3AF; font-weight: 500; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.nav-label { text-transform: uppercase; font-size: 10px; font-weight: 700; color: #6B7280; letter-spacing: 1.2px; padding: 8px 10px 3px; }
.nav-item { display: block; padding: 6px 10px; border-radius: 7px; font-size: 13px; color: #D1D5DB; font-weight: 500; transition: background 0.12s, color 0.12s; line-height: 1.3; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.user { margin-top: auto; padding: 8px 6px 0; display: flex; align-items: center; gap: 10px; border-top: 1px solid #2A2D35; padding-top: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; flex-shrink: 0; }
.user-info .name { color: #fff; font-weight: 600; font-size: 12px; }
.user-info .role { color: #9CA3AF; font-size: 11px; }

/* Main */
.main { padding: 24px 32px 48px; max-width: 1400px; }
.main-no-sidebar { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 0; max-width: none; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.topbar .sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: transform 0.08s, box-shadow 0.12s; font-family: inherit; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(123,104,238,0.25); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(123,104,238,0.35); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-link-danger { background: none; border: none; color: var(--danger); cursor: pointer; font-weight: 600; font-size: 13px; padding: 4px 8px; }
.btn-link-danger:hover { background: #FEE2E2; border-radius: 6px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; transition: transform 0.12s, box-shadow 0.12s; }
.stat:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.05); }
.stat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stat-label { font-size: 11px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-dim); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.stat-icon svg { width: 16px; height: 16px; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.stat-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* Onboarding setup card */
.setup-card { border-color: var(--accent); background: linear-gradient(135deg, rgba(123,104,238,0.04) 0%, rgba(255,209,0,0.03) 100%); }
.setup-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.setup-progress { display: flex; align-items: center; gap: 10px; }
.setup-progress-track { width: 120px; height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.setup-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 999px; transition: width 0.3s; }
.setup-progress-label { font-size: 12px; font-weight: 700; color: var(--accent); min-width: 32px; text-align: right; }
.setup-steps { display: flex; flex-direction: column; gap: 10px; }
.setup-step { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.setup-step.done { opacity: 0.7; }
.setup-step-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.setup-step.done .setup-step-icon { background: var(--success); color: #fff; }
.setup-step.done .setup-step-icon svg { width: 14px; height: 14px; }
.setup-step-body { flex: 1; }
.setup-step-label { font-size: 13.5px; font-weight: 600; }
.setup-step.done .setup-step-label { text-decoration: line-through; color: var(--text-dim); }
.setup-done-pill { font-size: 11px; font-weight: 700; color: var(--success); background: #DCFCE7; padding: 4px 10px; border-radius: 999px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* Rich empty state */
.empty-rich { text-align: center; padding: 32px 16px; }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.empty-sub { font-size: 13px; color: var(--text-dim); margin-bottom: 16px; max-width: 320px; margin-left: auto; margin-right: auto; }

/* Card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; }
.card-link { font-size: 12px; color: var(--accent); font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1024px) { .cols { grid-template-columns: 1fr; } }
.row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.row:last-child { border-bottom: none; }
.dim { color: var(--text-dim); }
.empty { text-align: center; padding: 32px; color: var(--text-dim); font-size: 13px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* Pills */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill-active     { background: #DCFCE7; color: #166534; }
.pill-pending    { background: #FEF3C7; color: #92400E; }
.pill-disconnected { background: #FEE2E2; color: #991B1B; }
.pill-connected  { background: #DBEAFE; color: #1E40AF; }
.pill-draft      { background: #E5E7EB; color: #374151; }
.pill-paused     { background: #FEF3C7; color: #92400E; }
.pill-completed  { background: #DBEAFE; color: #1E40AF; }
.pill-role-admin  { background: #EEEAFE; color: #4B3FAE; }
.pill-role-client { background: #DBEAFE; color: #1E40AF; }
.pill-role-viewer { background: #F3F4F6; color: #4B5563; }
.flash-info       { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
.form label { display: block; font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.form input, .form select, .form textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text); }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-actions { display: flex; gap: 10px; }

/* Login — split screen with hero panel */
.login-shell { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; width: 100vw; }
.login-hero {
    background: linear-gradient(135deg, #1A1D23 0%, #2A2D35 60%, #4B3FAE 100%);
    color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
    position: relative; overflow: hidden;
}
.login-hero::before {
    content: ''; position: absolute; inset: 0;
    background: radial-gradient(circle at 20% 0%, rgba(123,104,238,0.4) 0%, transparent 50%),
                radial-gradient(circle at 80% 100%, rgba(255,209,0,0.2) 0%, transparent 50%);
    pointer-events: none;
}
.login-hero > * { position: relative; z-index: 1; }
.login-hero .brand { padding: 0; border: none; margin: 0; }
.login-hero .brand-mark { width: 44px; height: 44px; font-size: 16px; }
.login-hero .brand-text { font-size: 18px; }
.login-hero h2 { font-size: 38px; font-weight: 800; line-height: 1.15; letter-spacing: -1px; margin-bottom: 16px; }
.login-hero p { color: #D1D5DB; font-size: 15px; line-height: 1.6; max-width: 420px; }
.login-hero .features { display: flex; flex-direction: column; gap: 14px; margin-top: 24px; }
.login-hero .feature { display: flex; align-items: center; gap: 12px; font-size: 14px; color: #E5E7EB; }
.login-hero .feature-icon { width: 28px; height: 28px; border-radius: 8px; background: rgba(123,104,238,0.25); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.login-hero .footnote { font-size: 12px; color: #9CA3AF; }

.login-form-side { display: flex; align-items: center; justify-content: center; padding: 48px 32px; background: var(--bg); }
.login-card { background: var(--surface); padding: 40px; border-radius: 16px; max-width: 400px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.06); border: 1px solid var(--border); }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.3px; }
.login-card .sub { color: var(--text-dim); font-size: 14px; margin-bottom: 28px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.login-form .input-wrap { position: relative; margin-top: 6px; }
.login-form .input-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-dim); pointer-events: none; }
.login-form input { width: 100%; padding: 12px 14px 12px 38px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit; transition: border-color 0.12s, box-shadow 0.12s; }
.login-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.login-form button { padding: 13px; border-radius: 10px; font-size: 14px; font-weight: 700; margin-top: 8px; }

@media (max-width: 900px) {
    .login-shell { grid-template-columns: 1fr; }
    .login-hero { padding: 32px; min-height: 240px; }
    .login-hero h2 { font-size: 24px; }
    .login-hero .features { display: none; }
    .login-form-side { padding: 24px 16px; }
}

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; font-weight: 500; }
.flash-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.flash-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.flash-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* Mobile — SPEC §4.5 */
@media (max-width: 1024px) {
    body { grid-template-columns: 1fr; }
    .sidebar { position: fixed; bottom: 0; width: 100%; height: auto; top: auto; flex-direction: row; gap: 4px; padding: 8px; overflow-x: auto; z-index: 50; }
    .sidebar .brand, .sidebar .user, .nav-label { display: none; }
    .nav-item { padding: 8px 12px; white-space: nowrap; }
    .main { padding: 16px 16px 96px; }
}

/* SPEC §4.5 — phone breakpoint: WCAG 2.1 AA touch targets (44px) + tighter spacing */
@media (max-width: 768px) {
    .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
    .topbar h1 { font-size: 20px; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-value { font-size: 22px; }
    .card { padding: 16px; }
    .cols { grid-template-columns: 1fr; gap: 12px; }

    /* All actionable elements >= 44px tall for thumbs */
    .btn, .nav-item, .form input, .form select, .form textarea {
        min-height: 44px;
    }
    .btn-sm { min-height: 36px; padding: 8px 12px; }

    /* Forms stack their grid columns */
    .form .row, .form .grid, .grid { grid-template-columns: 1fr !important; }

    /* Tables collapse to scroll horizontally rather than break layout */
    .card > table { display: block; overflow-x: auto; white-space: nowrap; }

    /* Bottom-nav badges shouldn't push items off-screen */
    .nav-item span { display: none; }
    .nav-item.active span { display: inline-block; }
}
