/* Agent 402 Design System — see docs/DESIGN_SYSTEM.md */

:root {
    /* Backgrounds */
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-input: #1a1a25;
    --bg-hover: rgba(99, 102, 241, 0.04);

    /* Borders */
    --border: #2a2a3a;
    --border-focus: var(--accent);

    /* Text */
    --text-primary: #e0e0e8;
    --text-secondary: #8888a0;
    --text-muted: #555570;

    /* Accent */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.15);

    /* Semantic */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Typography */
    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px */
    --text-base: 1rem;      /* 16px */
    --text-lg: 1.25rem;     /* 20px */
    --text-xl: 1.5rem;      /* 24px */
    --text-2xl: 2rem;       /* 32px */

    /* Spacing */
    --space-1: 0.25rem;     /* 4px */
    --space-2: 0.5rem;      /* 8px */
    --space-3: 0.75rem;     /* 12px */
    --space-4: 1rem;        /* 16px */
    --space-5: 1.25rem;     /* 20px */
    --space-6: 1.5rem;      /* 24px */
    --space-8: 2rem;        /* 32px */
    --space-10: 2.5rem;     /* 40px */
}

/* Light theme overrides */
body.light {
    --bg-primary: #f8f9fb;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f3f4f6;
    --bg-hover: rgba(99, 102, 241, 0.06);
    --border: #e2e4e9;
    --border-focus: var(--accent);
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-glow: rgba(79, 70, 229, 0.12);
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;
}

/* System preference: auto-apply light if user has no saved preference */
@media (prefers-color-scheme: light) {
    body:not(.dark):not(.light) {
        --bg-primary: #f8f9fb;
        --bg-secondary: #ffffff;
        --bg-card: #ffffff;
        --bg-input: #f3f4f6;
        --bg-hover: rgba(99, 102, 241, 0.06);
        --border: #e2e4e9;
        --border-focus: var(--accent);
        --text-primary: #111827;
        --text-secondary: #4b5563;
        --text-muted: #9ca3af;
        --accent: #4f46e5;
        --accent-hover: #4338ca;
        --accent-glow: rgba(79, 70, 229, 0.12);
        --success: #059669;
        --warning: #d97706;
        --danger: #dc2626;
        --info: #2563eb;
    }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--text-base);
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color 0.2s, color 0.2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
}
.sidebar-brand {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}
.sidebar-nav { padding: 1rem 0; flex: 1; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: all 0.15s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    color: var(--accent);
    background: rgba(99,102,241,0.08);
    border-right: 2px solid var(--accent);
}
.sidebar-user {
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 16px));
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.sidebar-user .user-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    cursor: default;
}
.sidebar-user .user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}
.sidebar-user .user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.main-content { flex: 1; padding: 2rem; overflow-y: auto; }
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.page-title { font-size: 1.5rem; font-weight: 600; }

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
}
.card-header { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }
.stat-value.success { color: var(--success); }
.stat-value.accent { color: var(--accent); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: rgba(99,102,241,0.04); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #ffffff; }
.btn-primary:hover { background: #4f46e5; color: #ffffff; }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.375rem; }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 0.875rem;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}
.form-textarea { min-height: 80px; resize: vertical; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 500;
}
.badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-muted { background: rgba(85,85,112,0.15); color: var(--text-muted); }

/* Wizard steps */
.wizard-steps {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}
.wizard-step {
    flex: 1;
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.wizard-step.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(99,102,241,0.08);
}
.wizard-step.completed {
    border-color: var(--success);
    color: var(--success);
    background: rgba(16,185,129,0.08);
}
.step-panel { display: none; }
.step-panel.active { display: block; }

/* Code block */
.code-block {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 1rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre;
    color: var(--text-secondary);
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.alert-success { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.3); color: var(--success); }
.alert-danger { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.alert-info { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: var(--info); }

/* Health indicator */
.health-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.375rem;
}
.health-dot.healthy { background: var(--success); }
.health-dot.degraded { background: var(--warning); }
.health-dot.unhealthy { background: var(--danger); }
.health-dot.unknown { background: var(--text-muted); }

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}
.login-title { text-align: center; font-size: 1.25rem; font-weight: 600; margin-bottom: 1.5rem; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 2rem; }
.login-toggle { text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--text-muted); }
.login-toggle a { cursor: pointer; }

/* Truncate */
.truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Compliance sections */
.compliance-section { margin-bottom: 2rem; }
.compliance-section h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--accent); }
.compliance-section p, .compliance-section li { font-size: 0.875rem; color: var(--text-secondary); line-height: 1.7; }

/* Theme toggle switch */
.theme-switch {
    position: relative;
    width: 48px;
    height: 26px;
    background: #3b3b52;
    border-radius: 13px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0;
    transition: background 0.25s, border-color 0.25s, box-shadow 0.25s;
    flex-shrink: 0;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}
.theme-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: #e8e8f0;
    border-radius: 50%;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 0 1px rgba(0,0,0,0.2);
}
.theme-switch:hover {
    background: #4a4a62;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3), 0 0 0 3px rgba(99,102,241,0.15);
}
.theme-switch:focus-visible {
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3), 0 0 0 3px rgba(99,102,241,0.4);
}

/* Light mode: accent track, white thumb */
body.light .theme-switch {
    background: var(--accent);
    border-color: rgba(0,0,0,0.08);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
}
body.light .theme-switch::after {
    transform: translateX(22px);
    background: #ffffff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2), 0 0 1px rgba(0,0,0,0.1);
}
body.light .theme-switch:hover {
    background: var(--accent-hover);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.15), 0 0 0 3px rgba(79,70,229,0.2);
}

@media (prefers-color-scheme: light) {
    body:not(.dark):not(.light) .theme-switch {
        background: var(--accent);
        border-color: rgba(0,0,0,0.08);
        box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
    }
    body:not(.dark):not(.light) .theme-switch::after {
        transform: translateX(22px);
        background: #ffffff;
        box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    }
}

/* Validation error states */
.form-input.field-error,
.form-select.field-error,
.form-textarea.field-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}
.field-error-msg {
    font-size: var(--text-xs);
    color: var(--danger);
    margin-top: var(--space-1);
}

/* Utility classes (design system) */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.helper-text { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-1); }
.section-desc { font-size: var(--text-sm); color: var(--text-secondary); margin-bottom: var(--space-4); }
.form-actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-6); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

/* Service form card (used in wizard step 2) */
.service-form-card {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    margin-bottom: var(--space-3);
}
.service-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}
.service-form-header strong { font-size: var(--text-sm); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
}
