/* ---- Shared theme tokens -------------------------------------------------
   Loaded by BOTH layouts (_Layout and _LayoutLogin) before their own stylesheet.
   Dark is the default. The layout sets data-theme="light" on <html> (from the
   "theme" cookie) to switch to the warm light palette below. Use these variables
   instead of hardcoded colors so both themes stay in sync. */
:root {
    color-scheme: dark;

    /* ---- Shared design scales (theme independent; new CSS should use these) ----
       Spacing is a 4px rhythm; radius/motion/control sizes replace one-off values. */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    --dur-fast: 120ms;   /* hover / press feedback */
    --dur-base: 200ms;   /* dropdowns, color shifts */
    --dur-slow: 320ms;   /* panels, entrances */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

    --control-h-sm: 2.1rem;  /* compact pill buttons (goal / photo / chips) */
    --control-h-md: 2.6rem;  /* standard form buttons */
    --control-h-touch: 44px; /* minimum target on coarse pointers (WCAG 2.5.8 / platform guidance) */

    /* Keyboard focus has its own colour (violet), so it never looks like a state colour: green income /
       accent, red expense, amber warning, blue balance. 7.4:1 on --bg-surface in dark, 7.3:1 in light. */
    --focus-color: #b197fc;
    --focus-glow: rgba(177, 151, 252, 0.28);
    /* Scrollbars (dark): cool slate pill on a faint track; the green accent under the pointer */
    --scroll-track: rgba(255, 255, 255, 0.04);
    --scroll-thumb: #3a4654;
    --scroll-thumb-hover: color-mix(in srgb, var(--color-accent) 75%, #3a4654);
    --scroll-thumb-active: var(--color-accent);
    --focus-ring: 2px solid var(--focus-color);
    --focus-offset: 2px;

    /* Elevation. Dark relies on borders + a deeper shadow; light uses a soft warm shadow (overridden below). */
    --elev-1: 0 1px 2px rgba(0, 0, 0, 0.30);
    --elev-2: 0 6px 16px rgba(0, 0, 0, 0.32);
    --elev-3: 0 18px 44px rgba(0, 0, 0, 0.42);

    /* Card edge: a hairline border plus a faint top highlight so surfaces separate from the dark page. */
    --card-border: rgba(255, 255, 255, 0.07);
    --card-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.04);

    --bg-body: #12161d;
    --bg-sidebar: #12161d;
    --bg-navbar: #12161d;

    /* Page background decoration (used by body.e-bigger in site.css) */
    --bg-glow: rgba(101, 218, 65, 0.17);  /* soft accent glow behind the top of the content */
    --bg-glow-2: rgba(42, 161, 255, 0.11); /* faint cool second glow, bottom right */
    --bg-dot: rgba(255, 255, 255, 0.10);   /* dot-grid texture */
    --bg-surface: #1a222b; /* widgets, grid body */
    --bg-surface-2: #222b33; /* grid header, summary icon block */
    --bg-accent-panel: #212b36; /* decorative panel on create/edit forms */
    --bg-pager-active: #31373d;

    --text-primary: #ffffff;
    --text-secondary: #adb5bd;
    --text-menu: rgb(171, 163, 152);
    --text-empty: #8795a5; /* was #6c7a89 (3.66:1); now 5.26:1 on --bg-surface */
    --icon-empty: #3a4652;

    --border-sidebar: rgba(75, 82, 85, 0.24);
    --hover-bg: #48545f14;
    --profile-bg: rgba(72, 84, 95, 0.12);
    --widget-shadow: none;

    --color-income: #65da41;
    --color-expense: #ff4e48;
    --color-balance: #2aa1ff;
    --color-warning: #ffc107; /* budget "near limit" */
    --color-accent: #65da41;
    --accent-bg: rgba(101, 218, 65, 0.12);
    --budget-track: rgba(255, 255, 255, 0.10); /* empty part of a progress bar */

    --env-dev-fg: #ffc107;
    --env-dev-bg: rgba(255, 193, 7, 0.18);
    --env-prd-fg: #ff4e48;
    --env-prd-bg: rgba(255, 78, 72, 0.18);

    --rbt-bg: rgb(34 43 51);
    --rbt-border: #ffffff;
    --rbt-text: #ffffff;
    --rbt-checked-bg: #ffffff;
    --rbt-checked-text: #212b36;
}

/* Warm light palette: cream backgrounds, brown-tinted text and borders, and an
   amber/terracotta accent instead of the cool grays and bright green of the dark theme. */
html[data-theme="light"] {
    color-scheme: light;

    --focus-color: #6d4bd8;
    --focus-glow: rgba(109, 75, 216, 0.22);

    /* Scrollbars (light): warm sand pill on a cream track; the amber accent under the pointer */
    --scroll-track: rgba(122, 90, 50, 0.07);
    --scroll-thumb: #cdbba3;
    --scroll-thumb-hover: color-mix(in srgb, var(--color-accent) 70%, #cdbba3);
    --scroll-thumb-active: var(--color-accent);

    --elev-1: 0 1px 2px rgba(94, 64, 28, 0.10);
    --elev-2: 0 6px 16px rgba(94, 64, 28, 0.12);
    --elev-3: 0 18px 44px rgba(94, 64, 28, 0.18);

    --card-border: rgba(122, 90, 50, 0.14);
    --card-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.7);

    --bg-body: #f8f2e9;
    --bg-sidebar: #fffaf2;
    --bg-navbar: #f8f2e9;

    --bg-glow: rgba(245, 158, 66, 0.22);
    --bg-glow-2: rgba(180, 83, 9, 0.07);
    --bg-dot: rgba(122, 90, 50, 0.13);
    --bg-surface: #fffdf8;
    --bg-surface-2: #f3eadc;
    --bg-accent-panel: #f1e5d3;
    --bg-pager-active: #ebdfcc;

    --text-primary: #3b2f25;
    --text-secondary: #7a6a5a;
    --text-menu: #7a6a5a;
    --text-empty: #7a6a5a; /* was #9c8c7a (3.2:1); now 5.12:1 on surface, 4.67:1 on body */
    --icon-empty: #d8cbb8;

    --border-sidebar: rgba(122, 90, 50, 0.18);
    --hover-bg: rgba(122, 90, 50, 0.09);
    --profile-bg: rgba(180, 120, 50, 0.08);
    --widget-shadow: 0 1px 3px rgba(94, 64, 28, 0.10), 0 1px 2px rgba(94, 64, 28, 0.06);

    /* Warm, slightly muted accents with enough contrast on cream */
    --color-income: #4d7c0f;
    --color-expense: #c0392b;
    --color-balance: #2f6fa8;
    --color-warning: #92580a; /* was #b7791f (3.58:1, failed as text); now 5.7:1 on surface, 5.21:1 on body */
    --color-accent: #b45309;
    --accent-bg: rgba(180, 83, 9, 0.10);
    --budget-track: rgba(94, 64, 28, 0.12);

    --env-dev-fg: #92580a;
    --env-dev-bg: rgba(217, 119, 6, 0.16);
    --env-prd-fg: #b91c1c;
    --env-prd-bg: rgba(185, 28, 28, 0.10);

    --rbt-bg: #fffdf8;
    --rbt-border: #d9ccba;
    --rbt-text: #3b2f25;
    --rbt-checked-bg: #3b2f25;
    --rbt-checked-text: #fffdf8;
}

/* Bootstrap's .text-muted is a cool gray; use the warm secondary text in light mode. */
html[data-theme="light"] .text-muted {
    color: var(--text-secondary) !important;
}

/* Light/dark toggle button (navbar on app pages, top-right corner on the login page) */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}

    .theme-toggle:hover {
        background-color: var(--hover-bg);
    }

    .theme-toggle:focus-visible {
        outline: 2px solid var(--focus-color);
        outline-offset: 2px;
    }

/* Toggle animation. The page reloads to apply the theme, so it is split in two:
   - on load the new icon spins in (theme-icon-in);
   - on click site.js adds .is-switching, the old icon spins out (theme-icon-out), and the
     reload happens right after it ends.
   Animations (not transitions) are used because the navbar rule "nav.navbar .theme-toggle i"
   sets transform: none and would win over a plain class. */
.theme-toggle i {
    display: inline-block;
    font-size: 1.15rem;
    animation: theme-icon-in 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.theme-toggle:hover i.fa-sun {
    animation: theme-sun-spin 1.2s linear infinite;
}

.theme-toggle:hover i.fa-moon {
    animation: theme-moon-sway 1.4s ease-in-out infinite;
}

.theme-toggle:active {
    transform: scale(0.9);
}

.theme-toggle.is-switching i,
.theme-toggle.is-switching:hover i {
    animation: theme-icon-out 0.28s ease-in forwards;
}

.theme-toggle.is-switching {
    pointer-events: none;
}

@keyframes theme-icon-in {
    from { opacity: 0; transform: rotate(-120deg) scale(0.3); }
    to   { opacity: 1; transform: rotate(0) scale(1); }
}

@keyframes theme-icon-out {
    from { opacity: 1; transform: rotate(0) scale(1); }
    to   { opacity: 0; transform: rotate(120deg) scale(0.3); }
}

@keyframes theme-sun-spin {
    to { transform: rotate(360deg); }
}

@keyframes theme-moon-sway {
    0%, 100% { transform: rotate(0); }
    50%      { transform: rotate(-18deg); }
}

@media (prefers-reduced-motion: reduce) {
    .theme-toggle i,
    .theme-toggle:hover i.fa-sun,
    .theme-toggle:hover i.fa-moon,
    .theme-toggle.is-switching i {
        animation: none;
    }
}

/* ==========================================================================
   RESPONSIVE TOKENS (same breakpoints as site.css)
   Mobile <= 480 · Large mobile 481-767 · Tablet 768-1023 · Laptop 1024-1439.
   Only the shared scales change; colours are the same at every size.
   ========================================================================== */

/* ---- Mobile (<= 480px): slightly tighter spacing and corners ---- */
@media (max-width: 480px) {
    :root {
        --space-5: 1.25rem;
        --space-6: 1.5rem;
        --radius-lg: 14px;
    }

    /* No grey flash when tapping links and buttons */
    a, button, [role="button"], label { -webkit-tap-highlight-color: transparent; }
}

/* ---- Large mobile (481px - 767px) ---- */
@media (min-width: 481px) and (max-width: 767px) {
    :root { --space-6: 1.75rem; }

    a, button, [role="button"], label { -webkit-tap-highlight-color: transparent; }
}

/* ---- Tablet (768px - 1023px): base scales ---- */
@media (min-width: 768px) and (max-width: 1023px) {
}

/* ---- Laptop (1024px - 1439px): base scales ---- */
@media (min-width: 1024px) and (max-width: 1439px) {
}
