/*
 * SysTime theme tokens. One palette for the whole app, two modes:
 *   dark  (default) - the navy of the home screen (#1f2f45).
 *   light           - white surfaces with the slate palette the light screens already used.
 * <html data-st-theme="dark|light|system"> is rendered by App.razor from the `systime_theme` cookie and
 * changed live by window.systimeTheme (IThemeService). "system" follows prefers-color-scheme.
 * Any element can force a mode for its subtree with the same attribute (e.g. a section that must stay dark), and
 * data-st-theme="page" brings a subtree back to the page's mode (an opaque card inside a glass panel).
 *
 * Surface roles: every screen takes its background from exactly one of these three, never a mix.
 *   1. Glass  - panels that float over the map: login and register, inbox, notifications, traffic light, the avatar
 *               menu (Settings), profile, authorization. The glass is IDENTICAL in both modes (same tint and blur),
 *               and so is everything drawn straight on it (titles, icons, borders, translucent fills): the panel root
 *               carries data-st-theme="dark". Only its OPAQUE surfaces (a white card, the options box of Settings, a
 *               solid pill) follow the mode: they carry data-st-theme="page".
 *               background: var(--st-glass-surface); backdrop-filter: blur(var(--st-glass-blur));
 *   2. Chrome - the frame of the app: the NavMenu, the frame around the map, the home chat, the service-center
 *               selector and every side panel that slides in from the left or the right (LeftSidebar, RightSidebar and
 *               their consumers, the notification rule and template drawers, the forms "how it works" drawer, the
 *               valuation panel). The navy (--st-app-frame) is IDENTICAL in both modes, like the avatar menu: the root
 *               carries data-st-theme="dark", so its title, close button and footer stay light on navy. What changes
 *               with the mode is the content box inside (the body with the options, the list, the form): it carries
 *               data-st-theme="page" and class st-chrome-box (or its own rule with the same look). A token family
 *               derived from --st-* on an ancestor (--dfs-*, --jscb-*) must be declared again inside that box.
 *   3. Screen - the center screens (Reports, Configuration and Company, Calendar, Integration, SysColor, Documentation,
 *               Platform): solid --st-surface / --st-canvas, they change with the mode. No border around the screen.
 *   Modal backdrops (.st-blurred-backdrop in app.css) dim whatever is behind with --st-backdrop-tint; that token is the
 *   veil of a modal, not the background of a panel.
 *
 * Rules:
 *   - Neutral colors (surfaces, text, borders, soft status tints) always come from these tokens.
 *   - Each token keeps the exact value the light screens used in light mode and the exact value the
 *     navy screens used in dark mode, so each screen looks as before in its original mode.
 *   - Colors with meaning stay literal and identical in both modes: brand magenta/gold, traffic light,
 *     work levels, process and lane colors, and previews that imitate another app (WhatsApp, SMS, email).
 *   - Text on a solid accent background stays #fff (--st-on-accent).
 */

/* Chrome (surface role 2): the navy of the NavMenu, the frame around the map and every side panel, the same in
   both modes. */
:root {
    --st-app-frame: #1f2f45;
    /* Width of the collapsed NavMenu: the panels, the map frame and the top bar start where it ends. */
    --st-sidebar-collapsed-w: 72px;
    /* Navy left above and below the map frame and the center screens. The floating UI goes 10px inside it. */
    --st-frame-gap-y: 4px;
}

/* Phones keep their own layout. */
@media (max-width: 768px) {
    :root {
        --st-frame-gap-y: 10px;
    }
}

/* The content box of a chrome panel: the ONE part of it that follows the mode (the light canvas in light, a darker
   navy in dark), like the options box of the avatar menu. Put it on an element with data-st-theme="page". */
.st-chrome-box {
    background: var(--st-canvas);
    border: 1px solid var(--st-border-subtle);
    border-radius: 18px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* Blurred backgrounds are the SAME in both modes (only what sits on them follows the theme):
   - the glass role: the ONE material of every panel that floats over the map, and how much it blurs it;
   - the veil of the modal backdrops (.st-blurred-backdrop): the content behind shows through. */
:root {
    --st-glass-surface: #9aa1ab72;
    --st-glass-blur: 16px;
    --st-backdrop-tint: #9aa1ab72;
}

:root,
[data-st-theme="dark"],
[data-st-theme="page"] {
    color-scheme: dark;
    /* 1 in light, 0 in dark: a component mixes its two colors by theme with color-mix(... calc(var(--st-is-light) * 100%) ...). */
    --st-is-light: 0;

    /* Surfaces */
    --st-canvas: #192432;
    --st-surface: #1f2f45;
    --st-surface-raised: #26394f;
    --st-surface-muted: #22344b;
    --st-surface-sunken: #2a3d55;
    --st-surface-strong: #33475f;
    --st-surface-stronger: #415670;
    --st-surface-glass: rgba(31, 47, 69, 0.92);
    /* Small frosted popovers inside the center screens (grid menus, chart filters) */
    --st-glass: rgba(43, 62, 89, 0.75);
    --st-input-bg: #18273a;
    --st-scrollbar-thumb: #596270;
    --st-scrollbar-track: #172232;
    --st-backdrop: rgba(5, 10, 20, 0.7);

    /* Translucent fills over the current surface (hover, chips, wells) */
    --st-fill-1: rgba(255, 255, 255, 0.03);
    --st-fill-2: rgba(255, 255, 255, 0.05);
    --st-fill-3: rgba(255, 255, 255, 0.08);
    --st-fill-4: rgba(255, 255, 255, 0.1);
    --st-fill-5: rgba(255, 255, 255, 0.15);
    --st-fill-6: rgba(255, 255, 255, 0.2);
    --st-fill-7: rgba(255, 255, 255, 0.3);

    /* Text */
    --st-text-strong: #f8fafc;
    --st-text: #f1f5f9;
    --st-text-body: #e2e8f0;
    --st-text-brand: #d5deea;
    --st-text-secondary: #cbd5e1;
    --st-text-subtle: #b0b8c6;
    --st-text-muted: #8b95a6;
    --st-text-faint: #5f7089;
    --st-on-accent: #ffffff;

    /* Borders */
    --st-border-subtle: rgba(255, 255, 255, 0.06);
    --st-border: rgba(255, 255, 255, 0.1);
    --st-border-strong: rgba(255, 255, 255, 0.18);
    --st-border-stronger: rgba(255, 255, 255, 0.3);

    /* Shadows */
    --st-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
    --st-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --st-shadow-lg: 0 20px 40px -10px rgba(0, 0, 0, 0.55);

    /* Soft status tints (badges, alerts) */
    --st-danger-bg: rgba(239, 68, 68, 0.12);
    --st-danger-bg-strong: rgba(239, 68, 68, 0.2);
    --st-danger-border: rgba(239, 68, 68, 0.35);
    --st-danger-fg: #f87171;
    --st-danger-text: #fecaca;

    --st-warning-bg: rgba(245, 158, 11, 0.12);
    --st-warning-bg-strong: rgba(245, 158, 11, 0.2);
    --st-warning-border: rgba(245, 158, 11, 0.35);
    --st-warning-fg: #fbbf24;
    --st-warning-text: #fde68a;

    --st-success-bg: rgba(16, 185, 129, 0.12);
    --st-success-bg-strong: rgba(34, 197, 94, 0.2);
    --st-success-border: rgba(16, 185, 129, 0.35);
    --st-success-fg: #4ade80;
    --st-success-text: #a7f3d0;

    --st-info-bg: rgba(59, 130, 246, 0.12);
    --st-info-bg-strong: rgba(59, 130, 246, 0.2);
    --st-info-border: rgba(59, 130, 246, 0.35);
    --st-info-fg: #60a5fa;
    --st-info-text: #bfdbfe;

    --st-accent-bg: rgba(216, 27, 132, 0.15);
    --st-accent-border: rgba(216, 27, 132, 0.4);
    --st-accent-text: #f9a8d4;

    --st-gold-bg: rgba(229, 185, 0, 0.14);
    --st-gold-border: rgba(229, 185, 0, 0.4);
    --st-gold-text: #fde68a;

    /* Brand (same in both modes) */
    --st-accent: #d81b84;
    --st-accent-hover: #c21875;
    --st-brand-gold: #e5b900;

    /* Icons drawn as white images (img_home/*.svg) keep their color in dark mode */
    --st-icon-image-filter: none;

    /* Secondary button of the side panels (Anular, Terminar): navy in dark, slate in light */
    --st-btn-secondary-bg: #152233;
    --st-btn-secondary-text: #ffffff;
}

[data-st-theme="light"],
:root[data-st-theme="light"] [data-st-theme="page"] {
    color-scheme: light;
    /* 1 in light, 0 in dark: a component mixes its two colors by theme with color-mix(... calc(var(--st-is-light) * 100%) ...). */
    --st-is-light: 1;

    --st-canvas: #f1f5f9;
    --st-surface: #ffffff;
    --st-surface-raised: #ffffff;
    --st-surface-muted: #f8fafc;
    --st-surface-sunken: #f1f5f9;
    --st-surface-strong: #e2e8f0;
    --st-surface-stronger: #cbd5e1;
    --st-surface-glass: rgba(255, 255, 255, 0.92);
    --st-glass: rgba(255, 255, 255, 0.8);
    --st-input-bg: #ffffff;
    --st-scrollbar-thumb: #cbd5e1;
    --st-scrollbar-track: #f1f5f9;
    --st-backdrop: rgba(15, 23, 42, 0.65);

    --st-fill-1: rgba(15, 23, 42, 0.02);
    --st-fill-2: rgba(15, 23, 42, 0.03);
    --st-fill-3: rgba(15, 23, 42, 0.05);
    --st-fill-4: rgba(15, 23, 42, 0.06);
    --st-fill-5: rgba(15, 23, 42, 0.08);
    --st-fill-6: rgba(15, 23, 42, 0.12);
    --st-fill-7: rgba(15, 23, 42, 0.18);

    --st-text-strong: #0f172a;
    --st-text: #1e293b;
    --st-text-body: #334155;
    --st-text-brand: #334d6e;
    --st-text-secondary: #475569;
    --st-text-subtle: #64748b;
    --st-text-muted: #94a3b8;
    --st-text-faint: #cbd5e1;
    --st-on-accent: #ffffff;

    --st-border-subtle: #f1f5f9;
    --st-border: #e2e8f0;
    --st-border-strong: #cbd5e1;
    --st-border-stronger: #94a3b8;

    --st-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --st-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --st-shadow-lg: 0 20px 40px -10px rgba(0, 0, 0, 0.25);

    --st-danger-bg: #fef2f2;
    --st-danger-bg-strong: #fee2e2;
    --st-danger-border: #fecaca;
    --st-danger-fg: #dc2626;
    --st-danger-text: #991b1b;

    --st-warning-bg: #fffbeb;
    --st-warning-bg-strong: #fef3c7;
    --st-warning-border: #fde68a;
    --st-warning-fg: #b45309;
    --st-warning-text: #92400e;

    --st-success-bg: #ecfdf5;
    --st-success-bg-strong: #dcfce7;
    --st-success-border: #a7f3d0;
    --st-success-fg: #15803d;
    --st-success-text: #065f46;

    --st-info-bg: #eff6ff;
    --st-info-bg-strong: #dbeafe;
    --st-info-border: #bfdbfe;
    --st-info-fg: #2563eb;
    --st-info-text: #1e40af;

    --st-accent-bg: #fdf2f8;
    --st-accent-border: #fbcfe8;
    --st-accent-text: #be185d;

    --st-gold-bg: #fbf3d4;
    --st-gold-border: #fde68a;
    --st-gold-text: #92400e;

    /* White icon images become slate on white surfaces */
    --st-icon-image-filter: brightness(0) saturate(100%) invert(22%) sepia(14%) saturate(1500%) hue-rotate(176deg) brightness(92%) contrast(88%);

    --st-btn-secondary-bg: #e2e8f0;
    --st-btn-secondary-text: #1e293b;
}

/* "system" follows the operating system: dark tokens above unless it asks for light. */
@media (prefers-color-scheme: light) {
    [data-st-theme="system"],
    :root[data-st-theme="system"] [data-st-theme="page"] {
        color-scheme: light;
        /* 1 in light, 0 in dark: a component mixes its two colors by theme with color-mix(... calc(var(--st-is-light) * 100%) ...). */
        --st-is-light: 1;

        --st-canvas: #f1f5f9;
        --st-surface: #ffffff;
        --st-surface-raised: #ffffff;
        --st-surface-muted: #f8fafc;
        --st-surface-sunken: #f1f5f9;
        --st-surface-strong: #e2e8f0;
        --st-surface-stronger: #cbd5e1;
        --st-surface-glass: rgba(255, 255, 255, 0.92);
        --st-glass: rgba(255, 255, 255, 0.8);
        --st-input-bg: #ffffff;
        --st-scrollbar-thumb: #cbd5e1;
        --st-scrollbar-track: #f1f5f9;
        --st-backdrop: rgba(15, 23, 42, 0.65);

        --st-fill-1: rgba(15, 23, 42, 0.02);
        --st-fill-2: rgba(15, 23, 42, 0.03);
        --st-fill-3: rgba(15, 23, 42, 0.05);
        --st-fill-4: rgba(15, 23, 42, 0.06);
        --st-fill-5: rgba(15, 23, 42, 0.08);
        --st-fill-6: rgba(15, 23, 42, 0.12);
        --st-fill-7: rgba(15, 23, 42, 0.18);

        --st-text-strong: #0f172a;
        --st-text: #1e293b;
        --st-text-body: #334155;
        --st-text-brand: #334d6e;
        --st-text-secondary: #475569;
        --st-text-subtle: #64748b;
        --st-text-muted: #94a3b8;
        --st-text-faint: #cbd5e1;
        --st-on-accent: #ffffff;

        --st-border-subtle: #f1f5f9;
        --st-border: #e2e8f0;
        --st-border-strong: #cbd5e1;
        --st-border-stronger: #94a3b8;

        --st-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
        --st-shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
        --st-shadow-lg: 0 20px 40px -10px rgba(0, 0, 0, 0.25);

        --st-danger-bg: #fef2f2;
        --st-danger-bg-strong: #fee2e2;
        --st-danger-border: #fecaca;
        --st-danger-fg: #dc2626;
        --st-danger-text: #991b1b;

        --st-warning-bg: #fffbeb;
        --st-warning-bg-strong: #fef3c7;
        --st-warning-border: #fde68a;
        --st-warning-fg: #b45309;
        --st-warning-text: #92400e;

        --st-success-bg: #ecfdf5;
        --st-success-bg-strong: #dcfce7;
        --st-success-border: #a7f3d0;
        --st-success-fg: #15803d;
        --st-success-text: #065f46;

        --st-info-bg: #eff6ff;
        --st-info-bg-strong: #dbeafe;
        --st-info-border: #bfdbfe;
        --st-info-fg: #2563eb;
        --st-info-text: #1e40af;

        --st-accent-bg: #fdf2f8;
        --st-accent-border: #fbcfe8;
        --st-accent-text: #be185d;

        --st-gold-bg: #fbf3d4;
        --st-gold-border: #fde68a;
        --st-gold-text: #92400e;

        --st-icon-image-filter: brightness(0) saturate(100%) invert(22%) sepia(14%) saturate(1500%) hue-rotate(176deg) brightness(92%) contrast(88%);

        --st-btn-secondary-bg: #e2e8f0;
        --st-btn-secondary-text: #1e293b;
    }
}

/* Native form controls follow the theme (selects, date inputs, scrollbars of inner elements). */
input,
select,
textarea {
    color-scheme: inherit;
}

/* Bootstrap 5.3 takes body text, form controls, tables, cards, dropdowns and modals from these variables:
   mapped to the tokens, inherited text and Bootstrap components follow the theme too. Re-declared on every
   [data-st-theme] element so a subtree that forces a mode resolves them with its own tokens. */
:root,
[data-st-theme] {
    --bs-body-color: var(--st-text);
    --bs-body-bg: var(--st-surface);
    --bs-emphasis-color: var(--st-text-strong);
    --bs-secondary-color: var(--st-text-subtle);
    --bs-tertiary-color: var(--st-text-muted);
    --bs-secondary-bg: var(--st-surface-strong);
    --bs-tertiary-bg: var(--st-surface-muted);
    --bs-border-color: var(--st-border);
}


/* Text inherits a COMPUTED color: below a subtree that forces a mode (a navy side panel inside the light theme) the
   inherited text would keep the color of the outer mode (dark slate on navy). The subtree restarts it from its own
   tokens; zero specificity (:where), so any component that sets its own color still wins. */
:where([data-st-theme]:not(:root)) {
    color: var(--st-text);
}

/* The close button (X) of a full panel: one look for every screen, the Calendar's (request of 2026-11-11).
   Rounded square at the right end of the header; red on hover. */
.st-panel-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--st-surface-sunken);
    border: 1px solid var(--st-border-strong);
    border-radius: 8px;
    color: var(--st-text-secondary);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.st-panel-close svg {
    width: 20px;
    height: 20px;
}

.st-panel-close:hover {
    background: var(--st-danger-bg-strong);
    border-color: var(--st-danger-border);
    color: #ef4444;
}

.st-panel-close:focus-visible {
    outline: 2px solid #d81b84;
    outline-offset: 2px;
}
