/* ═══════════════════════════════════════════════════════════════
   ehr_base.css — Resets, variables, typography, body
   Load order: 1
   ═══════════════════════════════════════════════════════════════ */

/* ==========================================================================
   HOW THIS FILE IS ORGANIZED

   Tokens (data-theme goes on <html>: "derby", "dark", "light"; none = main)
     1. CONSTANTS       Never change per theme (layout, type, fixed colors, shadows)
     2. RELATIONSHIPS   var() links that hold in every theme. They re-resolve on
                        their own when a theme changes the token they point at.
     3. MAIN            The default (navy) theme. Brand + neutrals + semantic.
     4. THEMES          derby, dark, light: ONLY what differs from main.

   Then: reset, base elements, shared tables, utilities.

   Why plain :root works for all of it: the active :root[data-theme="..."]
   block sits on the same <html> element, so every var() resolves against the
   theme's values. This breaks if data-theme ever moves off <html>.

   Component CSS should use semantic/component tokens (surface, text, border,
   action, table-*), not the brand palette tokens directly.
   Adding a "custom" theme = one more block in section 4.
   ========================================================================== */

/* === Reset === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-size: 100%; /* Respects user device text size settings */
    scroll-behavior: smooth;
    text-size-adjust: 100%; /* was "none", which blocks user text scaling in some mobile browsers */
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

html, body {
    overscroll-behavior: none;
}


/* ==========================================================================
   1. CONSTANTS
   ========================================================================== */
:root {
  /* Structural */
  --ehr-sidebar-width: 250px;
  --ehr-header-height: 52px;
  --ehr-mobile-bar-height: 48px;
  --ehr-transition: 0.25s ease;
  --ehr-font: var(--hp-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  --ehr-font-size: 14px;
  --ehr-line-height: 1.5;

  /* Fixed colors (used by .ehr-on-light / .ehr-on-dark and highlight scopes) */
  --ehr-text-on-light: #000000;
  --ehr-text-always-light: #e0e0e0;
  --ehr-highlight-bg: #fff3a3;

  /* Shadows */
  --ehr-shadow-color: rgba(0, 0, 0, 0.5);
  --ehr-shadow-soft-color: rgba(0, 0, 0, 0.15);
  --ehr-table-box-shadow: 0 1px 8px var(--ehr-shadow-color);
}


/* ==========================================================================
   2. RELATIONSHIPS
   ========================================================================== */
:root {
  /* Foregrounds */
  --ehr-surface-text: var(--ehr-text-primary);
  --ehr-text-on-dark: var(--ehr-theme-on-brand);

  /* Wrapper and sidebar */
  --ehr-wrapper-bg: var(--ehr-theme-base);
  --ehr-sidebar-bg: var(--ehr-wrapper-bg);
  --ehr-sidebar-text: var(--ehr-theme-on-brand);
  --ehr-sidebar-hover-bg: var(--ehr-sidebar-text);
  --ehr-sidebar-active-bg: var(--ehr-sidebar-text);

  /* Mobile navigation */
  --ehr-mobile-bar-bg: var(--ehr-theme-base);
  --ehr-mobile-sub-bg: var(--ehr-theme-raised);

  /* Buttons: primary = accent fill, secondary = strong fill */
  --ehr-button-primary-bg: var(--ehr-theme-accent);
  --ehr-button-primary-text: var(--ehr-theme-on-accent);
  --ehr-button-secondary-bg: var(--ehr-theme-strong);
  --ehr-button-secondary-text: var(--ehr-theme-on-brand);

  /* Tabs */
  --ehr-tabbar-bg: var(--ehr-theme-strong);
  --ehr-tabbar-text: var(--ehr-theme-on-brand);

  /* Tables and cards */
  --ehr-table-row-bg: var(--ehr-surface-bg);
  --ehr-table-row-alt-bg: color-mix(in srgb, var(--ehr-theme-accent) 17%, transparent);
  --ehr-card-primary-header-bg: var(--ehr-table-header-bg);
  --ehr-card-primary-header-text: var(--ehr-table-header-text);
  --ehr-card-primary-body-text: var(--ehr-text-primary);

  /* Surface rows: full color by default; themes only change the mix */
  --hp-row-mix:     100%;
  --hp-row-mix-off: 100%;

  --hp-row-dirt:     color-mix(in srgb, var(--hp-dirt-light)     var(--hp-row-mix),     var(--ehr-surface-bg));
  --hp-row-turf:     color-mix(in srgb, var(--hp-turf-light)     var(--hp-row-mix),     var(--ehr-surface-bg));
  --hp-row-poly:     color-mix(in srgb, var(--hp-poly-light)     var(--hp-row-mix),     var(--ehr-surface-bg));
  --hp-row-dirtoff:  color-mix(in srgb, var(--hp-dirt-off-light) var(--hp-row-mix-off), var(--ehr-surface-bg));
  --hp-row-turfoff:  color-mix(in srgb, var(--hp-turf-off-light) var(--hp-row-mix-off), var(--ehr-surface-bg));
  --hp-row-turfyld:  color-mix(in srgb, var(--hp-turf-yld-light) var(--hp-row-mix-off), var(--ehr-surface-bg));
  --hp-row-polyoff:  color-mix(in srgb, var(--hp-poly-off-light) var(--hp-row-mix-off), var(--ehr-surface-bg));
  --hp-row-sprint:   color-mix(in srgb, var(--hp-sprint)         var(--hp-row-mix),     var(--ehr-surface-bg));
  --hp-row-route:    color-mix(in srgb, var(--hp-route)          var(--hp-row-mix),     var(--ehr-surface-bg));
  --hp-row-off:      color-mix(in srgb, var(--hp-off)            var(--hp-row-mix),     var(--ehr-surface-bg));
}


/* ==========================================================================
   3. MAIN / DEFAULT (navy)
   Everything a theme changes lives in the "Brand" block. Everything else is
   shared across themes unless a theme block says otherwise.
   ========================================================================== */
:root {
  color-scheme: light;

  /* ---- Brand (the values a theme overrides) ---- */
  --ehr-theme-base: #131a26;     /* sidebar, detail panel, dark buttons */
  --ehr-theme-raised: #273650;   /* sub-nav, pills, inner panels */
  --ehr-theme-strong: #415a77;   /* tab bar, table header bands */
  --ehr-theme-accent: #9dbde5;   /* active underline, icons, focus ring, primary buttons */
  --ehr-theme-tint: color-mix(in srgb, var(--ehr-theme-strong) 20%, var(--ehr-surface-bg));

  /* Text that sits ON brand colors */
  --ehr-theme-on-brand: #f5f5f5;           /* on base, raised, strong */
  --ehr-theme-on-brand-muted: color-mix(in srgb, var(--ehr-theme-on-brand) 75%, transparent);
  --ehr-theme-on-accent: var(--ehr-theme-base); /* white fails contrast on accent */
  --ehr-theme-on-tint: var(--ehr-theme-base);

  --ehr-theme-gradient: linear-gradient(180deg, var(--ehr-theme-base) 30%, var(--ehr-theme-raised) 100%);

  /* ---- Neutrals (shared) ---- */
  --ehr-page-bg: #d3d3d3;
  --ehr-surface-bg: #ffffff;
  --ehr-text-primary: #111111;
  --ehr-text-secondary: #555555;
  --ehr-text-muted: #646464;
  --ehr-text-dark: var(--ehr-theme-base);  /* link/title colour: brand colour on light themes (dark and light override below) */
  --ehr-border: #b2b2b2;
  --ehr-border-on-brand: color-mix(in srgb, var(--ehr-theme-on-brand) 15%, transparent);

  /* ---- Semantic (shared) ---- */
  --ehr-link: #16789a;
  --ehr-action: #dfa01f;         /* gold CTA fill AND gold labels on dark panels */
  --ehr-on-action: var(--ehr-text-primary);      /* text on an action fill */

  /* ---- Tables ---- */
  --ehr-table-header-bg: var(--ehr-theme-raised);
  --ehr-table-header-text: var(--ehr-theme-on-brand);
  --ehr-table-header-alt-bg: var(--ehr-theme-strong);
  --ehr-table-header-alt-text: var(--ehr-theme-on-brand);
  --ehr-table-hover-bg: var(--ehr-hover-bg);
  --ehr-surface-subtle: #e8e8d0;   /* quiet fill: column-head bands, filter pills, inset panels */
  --ehr-border-strong: #c8c8a0;
  --ehr-hover-bg: #f0f0f0;
  --ehr-row-divider: #ffffff;    /* line between status-tinted rows */
}


/* ==========================================================================
   4. THEMES
   ========================================================================== */

/* ---- DERBY (green) ---- */
:root[data-theme="derby"] {
  --ehr-theme-base: #0f280f;
  --ehr-theme-raised: #1c461c;
  --ehr-theme-strong: #316b31;
  --ehr-theme-accent: #a4d19b;

  --ehr-theme-on-brand: #f5f5f5;

  --ehr-link: #1f7a1f;

  /* Optional: restore the old derby gradient (brighter green to dark green).
     Leave commented to inherit base -> strong from :root. */
  /* --ehr-theme-gradient: linear-gradient(135deg, #1a5e1a 30%, #0c420c 100%); */
}

/* ---- DARK ---- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --ehr-theme-base: #121212;
  --ehr-theme-raised: #2a2a2b;
  --ehr-theme-strong: #3c3c3c;
  --ehr-theme-accent: #626262;
  --ehr-theme-on-accent: #f5f5f5;

  --ehr-theme-on-brand: #f5f5f5;


  --ehr-page-bg: #171717;
  --ehr-surface-bg: var(--ehr-theme-base);
  --ehr-text-primary: #f5f5f5;
  --ehr-text-secondary: #bdbdbd;
  --ehr-text-muted: #9a9a9a;
  --ehr-border: #3c3839;

  --ehr-link: #38BDF8;
  --ehr-action: #38BDF8;
  --ehr-on-action: var(--ehr-theme-base);

  --ehr-table-header-bg: var(--ehr-theme-base);
  --ehr-table-header-text: var(--ehr-theme-on-brand);
  --ehr-hover-bg: #2e2e2e;
  --ehr-surface-subtle: color-mix(in srgb, #e8e8d0 5%, var(--ehr-surface-bg));
  --ehr-border-strong: color-mix(in srgb, #c8c8a0 25%, var(--ehr-surface-bg));
  --ehr-row-divider: color-mix(in srgb, #000000 50%, transparent);
 
  /* dark block: softer surface rows */
  --hp-row-mix:     18%;
  --hp-row-mix-off: 30%;
}

/* ---- LIGHT ---- */
:root[data-theme="light"] {
  color-scheme: light;

  --ehr-theme-base: #e4e4e4;
  --ehr-theme-raised: #f6f6f6;
  --ehr-theme-strong: #cccccc;
  --ehr-theme-accent: #5c5c5c;   /* ~6:1 on white; a lighter gray makes icons and underlines vanish */

  --ehr-theme-on-brand: #000000;

  --ehr-page-bg: #f0f0f0;

  --ehr-action: #000000;
  --ehr-on-action: #f5f5f5;

  --ehr-table-header-bg: var(--ehr-theme-base);
  --ehr-table-header-text: var(--ehr-theme-on-brand);
  --ehr-table-hover-bg: #f0f0f0;
}

/* --ehr-text-dark is the brand colour in main/derby but plain body text in dark/light. */
:root[data-theme="dark"],
:root[data-theme="light"] {
  --ehr-text-dark: var(--ehr-text-primary);
  --ehr-theme-on-tint: var(--ehr-text-primary);
}


/* ==========================================================================
   BASE ELEMENTS
   ========================================================================== */
body {
    font-family: var(--ehr-font);
    font-size: var(--ehr-font-size);
    font-weight: 500;
    line-height: var(--ehr-line-height);
    color: var(--ehr-text-primary);
    background: var(--ehr-page-bg);
    margin: 0;
    padding: 0;
    font-optical-sizing: auto;
}

p {
    font-size: 1.1em;
    line-height: 1.7; /* unitless so children recompute from their own font-size */
    color: var(--ehr-text-primary);
    margin-bottom: 1em;
}

a {
    color: var(--ehr-link);
    text-decoration: none;
    transition: color 0.3s, background-color 0.3s;
}
a:hover,
a:active {
    text-decoration: none;
}

/* Visible keyboard focus on every theme. Two tones (ring + halo in opposite
   colors) so one of them contrasts on light content AND on dark chrome. */
:focus-visible {
    outline: 2px solid var(--ehr-text-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--ehr-surface-bg);
}

ul, ol {
    list-style: none;
}

input, button, textarea, select {
    font: inherit; /* Inherits system font stack automatically */
    font-size: 1rem; /* Strictly 16px to prevent iOS auto-zoom on focus */
    border: none;
    background: transparent;
}

/* WILLSELECT_20261104 (run list 567, Will): the open dropdown list is a separate popup and can't be transparent,
   so give options a real background and text color from the theme. */
select option,
select optgroup {
    background-color: var(--ehr-surface-bg);
    color: var(--ehr-text-primary);
}

/* Pointer only on things that act like buttons (text fields keep the I-beam). */
button, select,
input[type="button"], input[type="submit"], input[type="reset"],
input[type="checkbox"], input[type="radio"] {
    cursor: pointer;
}

img {
    display: block;
    max-width: 100%; /* Prevents images from breaking layout widths */
    height: auto;
}

/* 🍞 BREADCRUMB: img { display: block } above stacks inline icon images
   (capper indicators, badge icons) vertically instead of side-by-side.
   TD images are almost always inline icons — reset them to inline-block.
   Using inline-block (not inline) preserves max-width and sizing control. */
td img {
    display: inline-block;
    vertical-align: middle;
}


/* Prevent horizontal scroll at the layout level without breaking media queries.
   NOTE: .ehr-content-frame is not used in all pages — .ehr-main-content is the
   actual AJAX content target, so clip must be applied there too. */
.ehr-page-container,
.ehr-main-content,
.ehr-content-frame {
    overflow-x: clip;
}

.list_container {
  background: var(--ehr-surface-bg);
  /* box-shadow: 0 2px 4px var(--ehr-shadow-soft-color); */
}

/* WILLMERGE_20261017 (Q6, Will 10-17: "I had only touched hot list"): these .list_table rules were also written for
   .pg_table, which restyled the header cells on 33 website pages (padding, 13px, nowrap + ellipsis cut-off). Hot List only. */
/* ==========================================================================
   SHARED TABLES
   ========================================================================== */
.list_table {
  width: 100%;
  border-collapse: collapse;
  background: var(--ehr-surface-bg);
  border: 1px solid var(--ehr-border);
  /* box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); */
}

.list_table > thead {
  background: var(--ehr-table-header-bg);
  color: var(--ehr-table-header-text);
}

.list_table > thead th {
  padding: 8px 6px;
  text-align: left;
  font-weight: bold;
  border-bottom: 1px solid var(--ehr-border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list_table > tbody > tr {
  color: var(--ehr-text-primary);
}

.list_table > tbody > tr:nth-child(4n+1),
.list_table > tbody > tr:nth-child(4n+2) {
    background-color: var(--ehr-table-row-bg);
}

.list_table > tbody > tr:nth-child(4n+3),
.list_table > tbody > tr:nth-child(4n+4) {
    background-color: var(--ehr-table-row-alt-bg);
}

.list_table.list_table--simple > tbody > tr:nth-child(odd) {
    background-color: var(--ehr-table-row-bg);
}

.list_table.list_table--simple > tbody > tr:nth-child(even) {
    background-color: var(--ehr-table-row-alt-bg);
}

.list_table td {
  padding: 8px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  border-bottom: 1px solid var(--ehr-border);
}


/* ==========================================================================
   UTILITIES
   ========================================================================== */
/* A surface that is light in every theme. Text inside stays dark.
   Note: derived tokens (--ehr-surface-text etc.) are resolved on <html>, so
   they must be re-declared here to change inside this scope. */
.ehr-on-light,
a.ehr-highlight {
  --ehr-text-dark:      var(--ehr-text-on-light);
  --ehr-text:           var(--ehr-text-on-light);
  --ehr-text-primary:   var(--ehr-text-on-light);
  --ehr-text-secondary: #555555;
  --ehr-text-muted:     #6e6e6e;  /* passes AA on white and light page backgrounds */
  --ehr-surface-text:   var(--ehr-text-on-light);

  color: var(--ehr-text-on-light);
}

/* STAFFOVERRIDE_20261028 (paste 482): the staff Log in as banner (topwrapper). Fixed to the bottom edge, above the
   page, so the fixed header and side menu never cover it; the body keeps room for it. The same red in every theme. */
.ehr_staffov          { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1300; padding: 6px 16px;
                        background: #b00020; color: #f5f5f5; font-size: 13px; line-height: 1.4; text-align: center;
                        box-shadow: 0 -2px 6px rgba(0, 0, 0, .25); }
.ehr_staffov a        { color: #f5f5f5; font-weight: 700; text-decoration: underline; }
body.ehr_staffov_on   { padding-bottom: 48px; }
