/* Theme layer. Light colors stay in super-admin.css.
   This file defines the shared tokens and the dark override.
   Load it after super-admin.css. Inline colors use the tokens below. */

:root {
    color-scheme: light;
    --bg: #f9fafb;
    --surface: #ffffff;
    --sunken: #f3f4f6;
    --text: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --placeholder: #9ca3af;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --control-border: #d1d5db;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-ink: #ffffff;
    --link: #2563eb;
    --link-hover: #1d4ed8;
    --focus: #2563eb;
    --danger: #dc2626;
    --danger-solid: #dc2626;
    --danger-text: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --success-text: #166534;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --code-bg: #f3f4f6;
    --toggle-face: #ffffff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #2B2F33;
    --surface: #33373C;
    --sunken: #262A2E;
    --text: #F4F7F8;
    --text-secondary: #E2E6EA;
    --text-muted: #C5CCD1;
    --text-faint: #B0B8BE;
    --placeholder: #A8B2BA;
    --border: #4A4F55;
    --border-strong: #5C636A;
    /* Control edges meet WCAG 1.4.11 (3:1) against page and surface. */
    --control-border: #7C848C;
    --accent: #5FD3A0;
    --accent-hover: #49C48E;
    --accent-ink: #10241C;
    --link: #5FD3A0;
    --link-hover: #8BE8C2;
    --focus: #5FD3A0;
    --danger: #FCA5A5;
    --danger-solid: #dc2626;
    --danger-text: #FECACA;
    --danger-bg: #3A2224;
    --danger-border: #C45A60;
    --success-text: #BBF7D0;
    --success-bg: #17332A;
    --success-border: #3FAE7A;
    --code-bg: #262A2E;
    --toggle-face: #3A3F45;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.theme-toggle {
    width: 2.125rem;
    height: 2.125rem;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--control-border);
    background: var(--toggle-face);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
    line-height: 0;
}

.nav-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

@media (max-width: 640px) {
    .super-nav {
        flex-wrap: wrap;
        row-gap: 0.65rem;
    }
    .nav-brand {
        flex: 1 1 auto;
        min-width: 0;
    }
    /* super-admin.css hides .nav-links under 640px. Keep the section links visible. */
    .nav-links {
        display: flex;
        flex: 1 1 100%;
        order: 2;
        gap: 0.75rem 1.25rem;
        flex-wrap: wrap;
    }
    .nav-actions {
        flex: 0 1 auto;
        margin-left: auto;
        order: 1;
    }
}

.theme-toggle-fixed {
    position: fixed;
    top: 0.75rem;
    right: 1.25rem;
    z-index: 30;
}

.theme-toggle svg {
    width: 1.15rem;
    height: 1.15rem;
    display: block;
}

.theme-toggle .yy-hole {
    fill: var(--toggle-face);
}

.theme-toggle:hover {
    border-color: var(--text-muted);
}

.theme-toggle:focus {
    outline: none;
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}

[data-theme="dark"] .super-nav {
    background: var(--surface);
    border-bottom-color: var(--border);
}

[data-theme="dark"] .nav-brand,
[data-theme="dark"] .card-name,
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] .empty-state h2,
[data-theme="dark"] .attach-head h2,
[data-theme="dark"] .attach-view h2 {
    color: var(--text);
}

[data-theme="dark"] a:not(.btn) {
    color: var(--link);
}

[data-theme="dark"] a:not(.btn):visited {
    color: var(--link);
}

[data-theme="dark"] a:not(.btn):hover {
    color: var(--link-hover);
}

[data-theme="dark"] .nav-links a,
[data-theme="dark"] .nav-links a:visited {
    color: var(--text-muted);
}

[data-theme="dark"] .nav-links a:hover,
[data-theme="dark"] .nav-links a.active {
    color: var(--text);
}

[data-theme="dark"] .tenant-card,
[data-theme="dark"] .empty-state,
[data-theme="dark"] .login-box {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .tenant-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}

[data-theme="dark"] .card-meta,
[data-theme="dark"] .toggle,
[data-theme="dark"] .empty-state p,
[data-theme="dark"] .hint,
[data-theme="dark"] .attach-count,
[data-theme="dark"] .log-summary-meta,
[data-theme="dark"] .slider-scale,
[data-theme="dark"] .field-hint {
    color: var(--text-muted);
}

[data-theme="dark"] .form label,
[data-theme="dark"] .field-label,
[data-theme="dark"] fieldset.impact-field legend,
[data-theme="dark"] .up-meta,
[data-theme="dark"] .log-summary-label {
    color: var(--text-secondary);
}

[data-theme="dark"] .slug {
    background: var(--sunken);
    color: var(--text-secondary);
}

[data-theme="dark"] .status.active {
    color: var(--accent);
}

[data-theme="dark"] .status.inactive {
    color: var(--text-faint);
}

[data-theme="dark"] .filter-bar input[type="text"],
[data-theme="dark"] .form input[type="text"],
[data-theme="dark"] .form input[type="password"],
[data-theme="dark"] .form input[type="file"],
[data-theme="dark"] .form textarea,
[data-theme="dark"] .form select,
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background: var(--surface);
    color: var(--text);
    border-color: var(--control-border);
    caret-color: var(--text);
}

[data-theme="dark"] select option {
    background: var(--surface);
    color: var(--text);
}

[data-theme="dark"] ::placeholder {
    color: var(--placeholder);
    opacity: 1;
}

[data-theme="dark"] .filter-bar input:focus,
[data-theme="dark"] .form input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
[data-theme="dark"] .form textarea:focus,
[data-theme="dark"] .form select:focus,
[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(95, 211, 160, 0.28);
}

[data-theme="dark"] input[type="checkbox"],
[data-theme="dark"] input[type="radio"] {
    accent-color: var(--accent);
}

[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] textarea:-webkit-autofill {
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
    box-shadow: 0 0 0 1000px var(--surface) inset;
}

[data-theme="dark"] .btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    border-color: transparent;
}

[data-theme="dark"] .btn-primary:hover {
    background: var(--accent-hover);
    color: var(--accent-ink);
}

[data-theme="dark"] .btn-outline {
    background: transparent;
    color: var(--text);
    border-color: var(--control-border);
}

[data-theme="dark"] .btn-outline:hover {
    background: #3A3F45;
    color: var(--text);
}

[data-theme="dark"] .btn:focus-visible,
[data-theme="dark"] a:focus-visible,
[data-theme="dark"] button:focus-visible,
[data-theme="dark"] summary:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

[data-theme="dark"] .message.error,
[data-theme="dark"] .attach-error,
[data-theme="dark"] .message[style*="fef2f2"] {
    background: var(--danger-bg) !important;
    color: var(--danger-text) !important;
    border-color: var(--danger-border) !important;
}

[data-theme="dark"] .message.success,
[data-theme="dark"] .message[style*="f0fdf4"] {
    background: var(--success-bg) !important;
    color: var(--success-text) !important;
    border-color: var(--success-border) !important;
}

[data-theme="dark"] .generated-password {
    background: var(--sunken);
    color: var(--text);
    border-color: var(--success-border);
}

[data-theme="dark"] .logo-preview,
[data-theme="dark"] .thumb,
[data-theme="dark"] .shot,
[data-theme="dark"] .log-block,
[data-theme="dark"] .log-details {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="dark"] .urgency-badge {
    color: #10241C;
}

[data-theme="dark"] .urgency-low { background: #5FD3A0; }
[data-theme="dark"] .urgency-medium { background: #FBBF24; color: #1A1408; }
[data-theme="dark"] .urgency-high { background: #FB923C; color: #1C0E04; }
[data-theme="dark"] .urgency-critical { background: #F87171; color: #2A0A0A; }

[data-theme="dark"] .md-tabs button {
    color: var(--text-muted);
}

[data-theme="dark"] .md-tabs button.active {
    background: var(--sunken);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .md-preview,
[data-theme="dark"] .md-body {
    color: var(--text);
}

[data-theme="dark"] .md-preview {
    background: var(--surface);
    border-color: var(--border);
}

[data-theme="dark"] .md-empty {
    color: var(--text-faint);
}

[data-theme="dark"] .md-preview pre.md-code,
[data-theme="dark"] .md-body pre.md-code,
[data-theme="dark"] .log-pre {
    background: var(--code-bg);
    color: var(--text);
}

[data-theme="dark"] .form textarea.log-text {
    background: var(--sunken);
    color: var(--text);
}

[data-theme="dark"] .dropzone {
    background: var(--surface);
    border-color: var(--control-border);
    color: var(--text-muted);
}

[data-theme="dark"] .dropzone.dragover {
    border-color: var(--accent);
    background: #1E3330;
    color: var(--text);
}

[data-theme="dark"] .thumb-remove {
    background: #F4F7F8;
    color: #1A1E22;
}

[data-theme="dark"] .bar-track {
    background: #4A4F55;
}

[data-theme="dark"] .bar {
    background: var(--accent);
}

[data-theme="dark"] .up-fail {
    color: var(--danger);
}

[data-theme="dark"] .shot-dialog {
    background: var(--surface);
    color: var(--text);
}

[data-theme="dark"] .shot-dialog::backdrop {
    background: rgba(10, 12, 14, 0.72);
}

[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#ffffff"],
[data-theme="dark"] [style*="background: white"] {
    background: var(--surface) !important;
}

[data-theme="dark"] ::selection {
    background: #5FD3A0;
    color: #10241C;
}
