/* ─────────────────────────────────────────────────────────────────────────
   CureAI — "Clinical Intelligence" design system
   Loaded AFTER styles.css so these token values win. Every component rule
   already in styles.css (cards, buttons, badges, tables, nav) reads these
   variables, so re-pointing them re-skins the whole app at once.

   Palette: Deep Slate (authority) · Cyan (AI / active) · Emerald (health
   outcomes) on tiered blue-grey neutrals. Semantic colours are desaturated
   so they read clinical rather than alarming.
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* ── Clinical Intelligence tokens ── */
  --primary:            #091426;
  --on-primary:         #ffffff;
  --primary-container:  #1e293b;
  --on-primary-container:#8590a6;
  --primary-fixed:      #d8e3fb;
  --primary-fixed-dim:  #bcc7de;

  --secondary:          #00687a;   /* cyan — AI, active states */
  --on-secondary:       #ffffff;
  --secondary-container:#57dffe;   /* bright cyan accent */
  --on-secondary-container:#006172;
  --secondary-fixed:    #acedff;
  --secondary-fixed-dim:#4cd7f6;

  --tertiary:           #00190e;   /* emerald family — health outcomes */
  --tertiary-container: #00301e;
  --on-tertiary-container:#00a472;
  --tertiary-fixed:     #6ffbbe;
  --tertiary-fixed-dim: #4edea3;

  --error:              #ba1a1a;
  --on-error:           #ffffff;
  --error-container:    #ffdad6;
  --on-error-container: #93000a;

  --background:              #f8f9ff;
  --surface-bright:          #f8f9ff;
  --surface-container-lowest:#ffffff;
  --surface-container-low:   #eff4ff;
  --surface-container:       #e5eeff;
  --surface-container-high:  #dce9ff;
  --surface-container-highest:#d3e4fe;
  --surface-dim:             #cbdbf5;
  --on-surface:              #0b1c30;
  --on-surface-variant:      #45474c;
  --outline:                 #75777d;
  --outline-variant:         #c5c6cd;
  --inverse-surface:         #213145;
  --inverse-on-surface:      #eaf1ff;

  /* ── Legacy aliases ──────────────────────────────────────────────────
     The app has ~200 var(--teal) / var(--navy) references and 333 lines of
     Bootstrap overrides written against these names. Re-pointing them here
     migrates every one of those surfaces to the new palette without
     touching a single template. (--cream/--ink-mid/--ink-soft were
     referenced but never defined — they now resolve.)                    */
  --navy:      var(--primary);
  --navy-hi:   var(--primary-container);
  --navy-lo:   #050d18;
  --teal:      var(--secondary);
  --teal-deep: var(--on-secondary-container);
  --teal-hi:   var(--secondary-fixed-dim);
  --bg:        var(--background);
  --surface:   var(--surface-container-lowest);
  --surface-2: var(--surface-container-low);
  --cream:     var(--surface-container-low);
  --cream-2:   var(--surface-container);

  --ink:       var(--on-surface);
  --ink-mid:   rgba(11, 28, 48, 0.72);
  --ink-soft:  rgba(11, 28, 48, 0.55);
  --body:      rgba(11, 28, 48, 0.82);
  --muted:     rgba(11, 28, 48, 0.58);
  --faint:     rgba(11, 28, 48, 0.42);
  --line:      rgba(117, 119, 125, 0.22);
  --line-soft: rgba(117, 119, 125, 0.12);

  --teal-05:  rgba(0, 104, 122, 0.05);
  --teal-08:  rgba(0, 104, 122, 0.08);
  --teal-12:  rgba(0, 104, 122, 0.12);
  --teal-16:  rgba(0, 104, 122, 0.16);
  --navy-06:  rgba(9, 20, 38, 0.06);
  --navy-08:  rgba(9, 20, 38, 0.08);
  --navy-12:  rgba(9, 20, 38, 0.12);

  --grad-brand:   linear-gradient(135deg, #091426 0%, #00687a 100%);
  --grad-navy:    linear-gradient(135deg, #091426 0%, #1e293b 100%);
  --grad-surface: linear-gradient(180deg, #ffffff 0%, #f8f9ff 100%);

  /* Shape — "Soft-Precise": 8px everywhere, larger only on big surfaces */
  --radius-sm: .25rem;
  --radius:    .5rem;
  --radius-md: .75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;

  /* Elevation — soft, diffused, tinted with primary */
  --shadow-card:  0 4px 20px rgba(9, 20, 38, .04);
  --shadow-hover: 0 8px 28px rgba(0, 104, 122, .10);
  --shadow-nav:   0 2px 12px rgba(9, 20, 38, .06);

  /* Bootstrap bridge */
  --bs-body-bg:        var(--background);
  --bs-body-color:     var(--body);
  --bs-emphasis-color: var(--on-surface);
  --bs-border-color:   var(--line);
  --bs-primary:        var(--primary);
  --bs-link-color:     var(--secondary);
  --bs-link-hover-color: var(--on-secondary-container);
  --bs-border-radius:  var(--radius);
}

/* ── Typography ─────────────────────────────────────────────────────────
   Plus Jakarta Sans carries headings (tight tracking, editorial); Inter is
   the workhorse for clinical data. Labels get uppercase + wide tracking so
   metadata never competes with body copy.                                */
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--background);
  color: var(--body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6, .navbar-brand, .display-1, .display-2, .display-3,
.display-4, .display-5, .display-6 {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  color: var(--primary);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1, .display-4, .display-5 { letter-spacing: -0.02em; }
.text-uppercase.small, .form-label.small, .label-caps {
  letter-spacing: .05em;
  font-weight: 600;
}
.fw-bold, .fw-semibold { font-family: inherit; }

/* Digits that sit in columns should line up. */
table, .tabular, .metric-value { font-variant-numeric: tabular-nums; }

/* ── Surfaces & depth ───────────────────────────────────────────────── */
.card {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-card) !important;
  background: var(--surface-container-lowest);
}
.card-header { background: var(--surface-bright) !important; }
.rounded-4, .rounded-4.card { border-radius: var(--radius-lg) !important; }
.modal-content { border-radius: var(--radius-xl) !important; }

/* Card layer that reacts to focus — used for diagnostic panels. */
.diagnostic-card { transition: border-color .2s, box-shadow .2s, transform .2s; }
.diagnostic-card:hover {
  border-color: var(--secondary) !important;
  box-shadow: var(--shadow-hover) !important;
  transform: translateY(-2px);
}

/* Glass — reserved for AI-generated insight only, so "machine-written"
   is legible at a glance and never confused with recorded patient data. */
.glass-panel {
  background: rgba(255, 255, 255, .80);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(197, 198, 205, .5);
  border-radius: var(--radius-lg);
}

/* ── Inputs: filled at rest, cyan ring on focus ───────────────────────── */
.form-control, .form-select {
  background: var(--surface-container-low);
  border: 1px solid transparent;
  border-radius: var(--radius) !important;
  color: var(--on-surface);
}
.form-control:focus, .form-select:focus {
  background: #fff;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(0, 104, 122, .15);
}

/* Visible keyboard focus everywhere — previously missing. */
:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}

/* ── Sparkline draw-on ────────────────────────────────────────────────── */
.sparkline {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: ci-draw 1.6s ease-out forwards;
}
@keyframes ci-draw { to { stroke-dashoffset: 0; } }

/* ── Trend chips (direction is encoded in shape + icon, not colour alone) */
.trend-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .02em;
  border: 1px solid transparent; white-space: nowrap;
}
.trend-up      { background: var(--error-container); color: var(--on-error-container); border-color: rgba(186,26,26,.2); }
.trend-down    { background: rgba(111,251,190,.28); color: var(--tertiary-container); border-color: rgba(0,164,114,.25); }
.trend-flat    { background: var(--surface-container); color: var(--on-surface-variant); border-color: var(--line); }
.trend-good    { background: rgba(111,251,190,.28); color: var(--tertiary-container); border-color: rgba(0,164,114,.25); }
.trend-watch   { background: rgba(87,223,254,.20); color: var(--on-secondary-container); border-color: rgba(0,104,122,.22); }

/* ── Progress ring (AI confidence / completion) ───────────────────────── */
.ring-track { stroke: var(--surface-container-high); }
.ring-value { stroke: var(--secondary); transition: stroke-dashoffset 1s ease-out; }

/* ── Data tables: quiet rules, loud headers ───────────────────────────── */
.table > thead th {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600; color: var(--on-surface-variant);
  background: var(--surface-bright); border-bottom: 1px solid var(--line);
}
.table > tbody > tr { border-color: var(--line-soft); }
.table-hover > tbody > tr:hover > * { background: var(--surface-container-low); }

/* Wide content scrolls inside its own box, never the page. */
.table-responsive, .scroll-x { overflow-x: auto; }

/* ── Brand mark: always live ───────────────────────────────────────────────
   The structure stays solid and readable; a dashed copy of the same geometry
   runs over it so a signal appears to travel the network, and the nodes
   pulse on staggered delays. Colour comes from the parent via currentColor. */
.cureai-mark { display: block; overflow: visible; }
.cureai-mark .lg-edges { opacity: .38; }
.cureai-mark .lg-flow {
  opacity: .95;
  stroke-dasharray: 5 62;              /* short pulse, long gap */
  animation: lg-flow 2.6s linear infinite;
}
.cureai-mark .lg-node {
  animation: lg-pulse 2.6s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes lg-flow  { to { stroke-dashoffset: -67; } }
@keyframes lg-pulse {
  0%, 100% { opacity: .55; transform: scale(.82); }
  45%      { opacity: 1;   transform: scale(1.12); }
}
/* Wordmark sits with the mark */
.cureai-word {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  font-weight: 800; letter-spacing: -0.02em; line-height: 1;
  color: inherit;
}

/* ── Motion respects the reader ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .sparkline { stroke-dashoffset: 0; }
  .cureai-mark .lg-flow { display: none; }        /* keep the solid mark only */
  .cureai-mark .lg-node { opacity: 1; transform: none; }
}
