/*
 * Design tokens. Every page reads these, not color or shadow literals.
 *
 * Layout of this file:
 *   1. Dark theme   color and elevation tokens (the default)
 *   2. Light theme  the same tokens, light values, in the same order
 *   3. Bootstrap    Bootstrap 5.3 variables remapped onto the tokens
 *   4. Scales       spacing, radius, type, motion, z-index (theme independent)
 *   5. Base         body and heading rhythm
 *
 * The theme is the data-bs-theme attribute on <html>, set by _Host.cshtml and wwwroot/js/theme.js. Any element can opt into a theme
 * with its own data-bs-theme (the top bar and sidebar are always dark). A token that differs per theme is defined in both blocks;
 * add new ones to both, in the same section. Spacing sits on the 4px grid.
 */

/* ===== 1. Dark theme ===== */
:root,
[data-bs-theme="dark"] {
    color-scheme: dark;

    /* Surfaces, text and strokes follow Microsoft Teams dark mode (Fluent teamsDarkTheme grey ramp). The accent is the original
       FRAIT blue. Status colors are our own, kept vivid. */
    --surface-0: #1f1f1f;  /* page background, inputs */
    --surface-1: #292929;  /* cards, header */
    --surface-2: #333333;  /* card headers, hover rows */
    --surface-3: #3d3d3d;  /* raised or selected */
    --surface-nav: #1a1a1a;  /* sidebar: a step darker than the header bar */
    --border: #3d3d3d;

    --text-1: #ebebeb;
    --text-2: #c8c8c8;
    --text-3: #a0a0a0;

    /* The accent marks titles, section headers, active states and focus. Primary is a deeper shade of it. */
    --primary: #4a8fac;
    --primary-hover: #6bb2ce;
    --on-primary: #ffffff;
    --accent: #6bb2ce;
    --accent-fill: #6bb2ce;  /* buttons */
    --link: var(--accent);  /* text links */
    --info: #38bdf8;  /* chart marks and labels, not the brand accent */
    --info-text: #7dd3fc;

    /* Status. -soft is a badge or alert fill, -border its edge, -tint a stronger hover or active fill. */
    --success: #3fb950;
    --warn: #d29922;
    --danger: #f85149;
    --on-status: #001016;  /* text on a solid status fill */
    --success-soft: rgb(63 185 80 / 0.12);
    --success-border: rgb(63 185 80 / 0.3);
    --success-tint: color-mix(in srgb, var(--success) 20%, transparent);
    --warn-soft: rgb(210 153 34 / 0.12);
    --warn-border: rgb(210 153 34 / 0.3);
    --warn-tint: color-mix(in srgb, var(--warn) 20%, transparent);
    /* Medium Risk decision. Separate from --warn so general warnings stay amber. */
    --risk-medium: #d29922;
    --risk-medium-soft: rgb(210 153 34 / 0.12);
    --risk-medium-border: rgb(210 153 34 / 0.3);
    --danger-soft: rgb(248 81 73 / 0.12);
    --danger-border: rgb(248 81 73 / 0.3);
    --danger-tint: color-mix(in srgb, var(--danger) 20%, transparent);
    --accent-soft: rgb(107 178 206 / 0.12);
    --accent-border: color-mix(in srgb, var(--accent) 30%, transparent);
    --accent-tint: color-mix(in srgb, var(--accent) 20%, transparent);
    --info-soft: color-mix(in srgb, var(--info) 15%, transparent);

    /* Fills for elements that show their parent through: a faint lift (tint-1, tint-2) or a faint shade (tint-shade). */
    --tint-1: rgb(255 255 255 / 0.04);
    --tint-2: rgb(255 255 255 / 0.08);
    --tint-shade: rgb(0 0 0 / 0.25);
    --overlay: rgb(0 0 0 / 0.55);  /* behind a modal */

    /* Elevation. Dark separates layers by surface step alone, so cards, buttons and inputs carry no extra shadow or ring. */
    --shadow-sm: 0 0 2px rgb(0 0 0 / 0.24), 0 2px 4px rgb(0 0 0 / 0.28);
    --shadow-md: 0 0 2px rgb(0 0 0 / 0.24), 0 4px 8px rgb(0 0 0 / 0.28);
    --shadow-lg: 0 0 2px rgb(0 0 0 / 0.24), 0 8px 16px rgb(0 0 0 / 0.28);
    --elev-card: none;                 /* cards, panels, tables on a card */
    --elev-hero: var(--shadow-lg);     /* the one primary card on a page */
    --elev-btn: none;                  /* buttons at rest */
    --elev-btn-pressed: none;
    --elev-input: none;                /* text inputs at rest */
    --elev-pop: var(--shadow-lg);      /* dropdowns, popovers, flyouts, tooltips */
    --ring-focus: 0 0 0 0.2rem var(--accent-soft);  /* input focus glow */

    /* Components */
    --btn-bg: var(--surface-3);  /* button fill */
    --btn-edge-mix: white;       /* the color a hovered button border mixes toward */
    --card-title: var(--text-1);  /* card header title and icon */
    --card-icon: var(--text-2);
    --table-head-bg: var(--accent-soft);  /* column header row of a data table */
    --table-head-text: var(--text-2);
    --table-foot-text: var(--accent);  /* "load more" bar */
    --row-hover-bg: var(--accent-soft);
    --divider: var(--border);  /* lines between rows */
    --dropzone-bg: var(--accent-soft);  /* file drop area */
    --dropzone-border: var(--accent-soft);
    --nav-group-active-bg: transparent;  /* a collapsed sidebar group that holds the current page */
    --nav-group-text: var(--text-2);
    --nav-hover-bg: var(--surface-2);
    --nav-active-bg: var(--accent-soft);  /* current page link */
    --nav-active-text: var(--accent);

    /* Sentinel signal type dots. Each type keeps its own vivid hue in both themes. */
    --signal-reject: var(--danger);
    --signal-floor: #ff6f00;
    --signal-boost: #eab308;
    --signal-warning: #a855f7;
    --signal-ignore: #9ca3af;
    --signal-ring: none;
}

/* ===== 2. Light theme =====
 * The primary surface is an off-white page (blue-tinted) with grey elements on it. Light mode has no brightness steps to separate
 * layers the way dark does, so hierarchy comes from contrast and elevation: each layer is a clear step darker, borders are darker
 * than in dark, and cards, buttons, inputs and popovers carry layered shadows. Status fills are opaque pastels (not translucent) so
 * the text on them has a fixed contrast, and the accent and status text colors are darkened to hold at least 4.5:1 on the surfaces.
 */
:root[data-bs-theme="light"],
[data-bs-theme="light"] {
    color-scheme: light;

    --surface-0: #eef2f7;  /* page background: the blue-tinted off-white primary */
    --surface-1: #dfe2e8;  /* cards, header: a clear step darker than the page */
    --surface-2: #cdd2da;  /* card headers, hover rows */
    --surface-3: #c4cad4;  /* raised or selected */
    --border: #8f98a7;

    --text-1: #121a24;
    --text-2: #333d4b;
    --text-3: #424c5b;

    --primary: #155474;
    --primary-hover: #0f4259;
    --on-primary: #ffffff;
    --accent: #155474;
    --accent-fill: #155474;
    --link: #0961a8;  /* text links: brighter than the navy accent, 4.9:1 on cards */
    --info: #0b6aa6;
    --info-text: #07517f;

    --success: #145c28;
    --warn: #6f4800;
    --danger: #9c141e;
    --on-status: #ffffff;
    --success-soft: #c3e0cd;
    --success-border: #7fb08f;
    --success-tint: #a9d1b8;
    --warn-soft: #ecd8a6;
    --warn-border: #c0a04c;
    --warn-tint: #e0c682;
    --risk-medium: #6f4800;
    --risk-medium-soft: #ecd8a6;
    --risk-medium-border: #c0a04c;
    --danger-soft: #f0c3c6;
    --danger-border: #d78a90;
    --danger-tint: #e8a9ae;
    --accent-soft: #bcd5e3;
    --accent-border: #6f9db6;
    --accent-tint: #a3c5d8;
    --info-soft: #b8d6ea;

    --tint-1: #eceff3;
    --tint-2: #e6e9ee;
    --tint-shade: #cdd2da;
    --overlay: rgb(16 26 42 / 0.45);

    /* Blue-tinted shadows (the ink color, not pure black) so they read as shade on the blue off-white, not as grey dirt. */
    --shadow-sm: 0 1px 2px rgb(16 28 48 / 0.12), 0 1px 3px rgb(16 28 48 / 0.10);
    --shadow-md: 0 1px 2px rgb(16 28 48 / 0.10), 0 4px 10px rgb(16 28 48 / 0.12);
    --shadow-lg: 0 2px 4px rgb(16 28 48 / 0.10), 0 10px 24px rgb(16 28 48 / 0.16);
    --elev-card: 0 1px 2px rgb(16 28 48 / 0.14), 0 4px 12px rgb(16 28 48 / 0.10);
    --elev-hero: 0 2px 4px rgb(16 28 48 / 0.14), 0 12px 32px rgb(16 28 48 / 0.20);
    --elev-btn: 0 1px 2px rgb(16 28 48 / 0.16), inset 0 1px 0 rgb(255 255 255 / 0.7);
    --elev-btn-pressed: inset 0 2px 3px rgb(16 28 48 / 0.22);
    --elev-input: inset 0 1px 2px rgb(16 28 48 / 0.12);
    --elev-pop: var(--shadow-lg), 0 0 0 1px var(--border);
    --ring-focus: 0 0 0 3px rgb(21 84 116 / 0.32);

    /* Components */
    --btn-bg: #f3f5f8;  /* lighter than the card, so a button stands off it */
    --btn-edge-mix: black;
    --card-title: var(--accent);  /* accent blue: the level above body text */
    --card-icon: var(--accent);
    --table-head-bg: #eef0f4;  /* lighter than the card body and the card header above it, so the three bands read as separate levels */
    --table-head-text: var(--text-1);
    --table-foot-text: var(--accent);
    --row-hover-bg: var(--surface-2);
    --divider: #bfc5d0;  /* softer than --border so rows are not a stack of heavy lines */
    --dropzone-bg: var(--tint-1);  /* pale, so a drop area is not a solid blue block */
    --dropzone-border: var(--accent-border);

    /* The sidebar is always dark (data-bs-theme="dark" on it), so the --nav-* tokens and --surface-nav have no light value. */

    /* Signal dots keep the same vivid hues; a thin dark ring holds them against a grey card. */
    --signal-reject: #e11d2e;
    --signal-floor: #ff6f00;
    --signal-boost: #eab308;
    --signal-warning: #a855f7;
    --signal-ignore: #9ca3af;
    --signal-ring: 0 0 0 1px rgb(16 28 48 / 0.5);
}

/* ===== 3. Bootstrap ===== */
/* Bootstrap 5.3 reads [data-bs-theme]; these override its per-theme values with the tokens above. */
:root, [data-bs-theme] {
    --bs-body-bg: var(--surface-0);
    --bs-body-color: var(--text-1);
    --bs-secondary-color: var(--text-2);
    --bs-tertiary-bg: var(--surface-2);
    --bs-emphasis-color: var(--text-1);
    --bs-border-color: var(--border);
    --bs-link-color: var(--text-1);
    --bs-link-hover-color: var(--text-1);
    --bs-code-color: var(--text-1);
    --bs-card-bg: var(--surface-1);
    --bs-card-cap-bg: var(--surface-2);
    --bs-card-border-color: var(--border);
    --bs-form-control-bg: var(--surface-0);
    --bs-dropdown-bg: var(--surface-1);
    --bs-dropdown-border-color: var(--border);
    --bs-dropdown-link-color: var(--text-1);
    --bs-dropdown-link-hover-bg: var(--surface-2);
    --bs-table-color: var(--text-1);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--border);
}

:root {
    --bs-body-font-family: var(--font-sans);
    --bs-body-font-size: var(--text-sm);
    --bs-body-line-height: 1.5;
    --bs-border-radius: var(--radius-sm);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-md);
    --bs-border-radius-xl: var(--radius-lg);
    --bs-border-radius-pill: var(--radius-pill);
    --bs-box-shadow-sm: var(--shadow-sm);
    --bs-box-shadow: var(--shadow-md);
    --bs-box-shadow-lg: var(--shadow-lg);
}

/* ===== 4. Scales (theme independent) ===== */
:root {
    /* Spacing, 4px base. Matches Bootstrap utilities: 1=4, 2=8, 3=16, 4=24, 5=48 (rem equivalents). */
    --space-0: 0;
    --space-1: 0.25rem;  /*  4 */
    --space-2: 0.5rem;   /*  8 */
    --space-3: 0.75rem;  /* 12 */
    --space-4: 1rem;     /* 16 */
    --space-5: 1.25rem;  /* 20 */
    --space-6: 1.5rem;   /* 24 */
    --space-8: 2rem;     /* 32 */
    --space-10: 2.5rem;  /* 40 */
    --space-12: 3rem;    /* 48 */
    --space-16: 4rem;    /* 64 */

    /* Radius */
    --radius-sm: 0.25rem; /*  4 */
    --radius-md: 0.5rem;  /*  8 */
    --radius-lg: 0.75rem; /* 12 */
    --radius-pill: 999px;

    /* Type ramp: size / line-height, all line-heights on the 4px grid at 16px root. */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif; /* page titles: the Carrier Search font */
    --text-xs: 0.75rem;   /* 12 / 16 */
    --text-sm: 0.875rem;  /* 14 / 20 */
    --text-base: 1rem;    /* 16 / 24 */
    --text-lg: 1.125rem;  /* 18 / 28 */
    --text-xl: 1.25rem;   /* 20 / 28 */
    --text-2xl: 1.5rem;   /* 24 / 32 */
    --text-3xl: 2rem;     /* 32 / 40 */
    --leading-xs: 1rem;
    --leading-sm: 1.25rem;
    --leading-base: 1.5rem;
    --leading-lg: 1.75rem;
    --leading-2xl: 2rem;
    --leading-3xl: 2.5rem;
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;

    /* Motion */
    --duration-fast: 150ms;
    --duration-base: 250ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* Layering */
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-overlay: 1040;
    --z-drawer: 1050;
    --z-toast: 1080;
}

/* ===== 5. Base ===== */
body {
    background-color: var(--surface-0);
    color: var(--text-1);
}

h1, .h1 { font-size: var(--text-2xl); line-height: var(--leading-2xl); }
h2, .h2 { font-size: var(--text-xl);  line-height: var(--leading-lg); }
h3, .h3 { font-size: var(--text-lg);  line-height: var(--leading-lg); }
h4, .h4 { font-size: var(--text-base); line-height: var(--leading-base); }
h5, .h5 { font-size: var(--text-sm);  line-height: var(--leading-sm); }
h6, .h6 { font-size: var(--text-xs);  line-height: var(--leading-xs); }
/* Margin 0: the pages were built with Tailwind's reset, which zeroed heading margins. Spacing comes from layout or mb-* classes. */
h1, h2, h3, h4, h5, h6 { font-weight: var(--weight-semibold); margin: 0; }

small, .small { font-size: var(--text-sm); }
