/* =========================================================================
   Spirit — root theme stylesheet
   -------------------------------------------------------------------------
   All colors are defined as CSS custom properties (variables) so components
   can theme themselves without Bootstrap. Light is the default; dark applies
   either automatically (OS preference) or explicitly via [data-theme="dark"].
   ========================================================================= */

/* ---- Light theme (default) ---------------------------------------------- */
:root {
    color-scheme: light;

    /* Surfaces */
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --surface-hover: #eef2f9;

    /* Text */
    --text: #1f2733;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;

    /* Borders & lines */
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Brand / accent */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-contrast: #ffffff;
    --primary-soft: rgba(37, 99, 235, 0.12);

    --danger: #dc2626;
    --success: #059669;

    /* Sidebar */
    --sidebar-bg: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    --sidebar-text: #cbd5e1;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.14);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.07);
    --sidebar-brand: #ffffff;
    --sidebar-header-bg: rgba(0, 0, 0, 0.25);

    /* Top bar */
    --topbar-bg: rgba(255, 255, 255, 0.8);
    --topbar-border: var(--border);

    /* Effects */
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.12);

    /* Shape & motion */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --transition: 0.15s ease;
}

/* ---- Dark theme overrides ----------------------------------------------- */
/* Applied automatically when the OS prefers dark and the user hasn't forced
   light, OR explicitly when data-theme="dark" is set. */
:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #1b2740;
    --surface-hover: #1f2c47;

    --text: #e6edf6;
    --text-muted: #9aa7bd;
    --text-faint: #6b7a93;

    --border: #243149;
    --border-strong: #33425f;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-contrast: #0b1120;
    --primary-soft: rgba(59, 130, 246, 0.18);

    --danger: #f87171;
    --success: #34d399;

    --sidebar-bg: linear-gradient(180deg, #0f1830 0%, #070c18 100%);
    --sidebar-text: #aab6cc;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.12);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
    --sidebar-brand: #ffffff;
    --sidebar-header-bg: rgba(0, 0, 0, 0.35);

    --topbar-bg: rgba(19, 28, 46, 0.8);
    --topbar-border: var(--border);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg: #0b1120;
        --surface: #131c2e;
        --surface-2: #1b2740;
        --surface-hover: #1f2c47;

        --text: #e6edf6;
        --text-muted: #9aa7bd;
        --text-faint: #6b7a93;

        --border: #243149;
        --border-strong: #33425f;

        --primary: #3b82f6;
        --primary-hover: #60a5fa;
        --primary-contrast: #0b1120;
        --primary-soft: rgba(59, 130, 246, 0.18);

        --danger: #f87171;
        --success: #34d399;

        --sidebar-bg: linear-gradient(180deg, #0f1830 0%, #070c18 100%);
        --sidebar-text: #aab6cc;
        --sidebar-text-hover: #ffffff;
        --sidebar-active-bg: rgba(255, 255, 255, 0.12);
        --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
        --sidebar-brand: #ffffff;
        --sidebar-header-bg: rgba(0, 0, 0, 0.35);

        --topbar-bg: rgba(19, 28, 46, 0.8);
        --topbar-border: var(--border);

        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
    }
}

/* ---- Base reset & typography -------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--transition), color var(--transition);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text);
    line-height: 1.25;
    font-weight: 650;
    margin: 0 0 0.5em;
}

h1:focus {
    outline: none;
}

p {
    margin: 0 0 1rem;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

code {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    background: var(--surface-2);
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
    font-size: 0.875em;
}

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 550;
    line-height: 1.2;
    padding: 0.5rem 0.95rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:hover {
    background: var(--surface-hover);
}

.btn:active {
    transform: translateY(1px);
}

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

.btn-primary {
    background: var(--primary);
    color: var(--primary-contrast);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* ---- Forms -------------------------------------------------------------- */
input,
select,
textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--success);
}

.invalid {
    outline: 1px solid var(--danger);
}

.validation-message {
    color: var(--danger);
}

/* ---- Tables ------------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table th,
.table td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
}

.table thead th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background: var(--surface-hover);
}

/* ---- Blazor error UI ---------------------------------------------------- */
.blazor-error-boundary {
    background: var(--danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: var(--radius-sm);
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* ---- Scrollbars --------------------------------------------------------- */
* {
    scrollbar-color: var(--border-strong) transparent;
    scrollbar-width: thin;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: content-box;
}
