/* ==========================================================================
   ambulyn.css — Ambulyn custom design language
   Layered on top of Pico CSS. These two files are the ONLY stylesheets.
   See AMBULYN_STYLE.md. Do not add Bootstrap, Tailwind, a build step, or npm.
   ========================================================================== */

:root {
  /* Brand */
  --color-ambulyn-primary: #0f4c81;
  --color-ambulyn-light:   #e8f1fb;

  /* Clinical color semantics — used everywhere consistently */
  --color-success: #2d8a4e;   /* green  — complete, current, good, progress      */
  --color-warning: #b45309;   /* amber  — attention needed, approaching stale     */
  --color-danger:  #b91c1c;   /* red    — clinical danger ONLY                    */
  --color-empty:   #9ca3af;   /* grey   — not started, empty state               */
  --color-info:    #1d4ed8;   /* blue   — informational, no action needed        */

  /* Staleness flag backgrounds (light versions for readability) */
  --color-stale-amber-bg: #fef3c7;
  --color-stale-red-bg:   #fee2e2;

  /* Typography */
  --font-emergency-body:     1.1rem;
  --font-emergency-critical: 1.4rem;

  /* Map Pico's primary onto the Ambulyn brand colour */
  --pico-primary:                   var(--color-ambulyn-primary);
  --pico-primary-background:        var(--color-ambulyn-primary);
  --pico-primary-border:            var(--color-ambulyn-primary);
}

.ambulyn-brand {
  color: var(--color-ambulyn-primary);
  text-decoration: none;
}

/* --------------------------------------------------------------------------
   Vault completeness indicator — 5 blocks, green = complete, grey = empty.
   "Emergency ready" (3 of 5) is the milestone to celebrate.
   -------------------------------------------------------------------------- */
.vault-block {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  margin-right: 4px;
  background-color: var(--color-empty);
  vertical-align: middle;
}
.vault-block.complete {
  background-color: var(--color-success);
}
.vault-label {
  margin-left: 0.5rem;
  font-weight: 600;
  color: var(--color-success);
  vertical-align: middle;
}

/* --------------------------------------------------------------------------
   Staleness flags — amber = attention, red = clinical danger.
   Prominent banners, not small icons (see Emergency Provider View rules).
   -------------------------------------------------------------------------- */
.staleness-amber {
  background-color: var(--color-stale-amber-bg);
  border-left: 4px solid var(--color-warning);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
}
.staleness-red {
  background-color: var(--color-stale-red-bg);
  border-left: 4px solid var(--color-danger);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: bold;
}

/* --------------------------------------------------------------------------
   Emergency Provider View — speed + clarity. Large, high-contrast text.
   -------------------------------------------------------------------------- */
.emergency-view {
  font-size: var(--font-emergency-body);
  color: #111;
}
.emergency-view .critical {
  font-size: var(--font-emergency-critical);
  font-weight: 700;
}

/* Allergy severity — red = severe/anaphylactic, amber = moderate, grey = mild. */
.allergy-severe   { color: var(--color-danger);  font-weight: 700; }
.allergy-moderate { color: var(--color-warning); font-weight: 600; }
.allergy-mild     { color: var(--color-empty); }

/* Always-visible emergency session timer. */
.session-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--color-info);
}

/* Emergency view layout components */
.emergency-section {
  margin-block: 1.25rem;
}
.emergency-section h2,
.emergency-section h3 {
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-ambulyn-primary);
  border-bottom: 2px solid var(--color-ambulyn-light);
  padding-bottom: 0.25rem;
  margin-bottom: 0.5rem;
}
.emergency-section h3 {
  font-size: 1rem;
}
.bloodtype-value {
  display: inline-block;
  background: var(--color-ambulyn-light);
  color: var(--color-ambulyn-primary);
  padding: 0.2rem 0.9rem;
  border-radius: 8px;
}
.alert-card {
  margin: 0;
  padding: 0.75rem 1rem;
}
.emergency-list {
  list-style: none;
  padding-left: 0;
}
.emergency-list li {
  list-style: none;   /* Pico sets a marker on <li> directly; override it here, not on the <ul> */
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--pico-muted-border-color, #e5e7eb);
}
.empty-note {
  color: var(--color-empty);
}
/* De-emphasised text — resolved problems, discontinued meds, discharge summaries. */
.muted {
  color: var(--color-empty);
}

/* "One tap away" Layer 2 expander in the provider emergency view. */
.layer2-details {
  margin-top: 1.5rem;
  border-top: 2px solid var(--color-ambulyn-light);
  padding-top: 0.75rem;
}
.layer2-details > summary {
  cursor: pointer;
  color: var(--color-ambulyn-primary);
  padding: 0.4rem 0;
}

/* Inline staleness tag (per-record) — amber/red echo the banner colours. */
.stale-tag {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.8rem;
  color: var(--color-empty);
}
.stale-tag.amber {
  color: var(--color-warning);
  font-weight: 600;
}
.stale-tag.red {
  color: var(--color-danger);
  font-weight: 700;
}

/* Provider emergency-access flow */
.candidate-photo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-ambulyn-light);
  color: var(--color-ambulyn-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.candidate-photo.large { width: 88px; height: 88px; font-size: 1.6rem; }
.confidence-high   { color: var(--color-success); font-weight: 600; }
.confidence-medium { color: var(--color-warning); font-weight: 600; }
.confidence-low    { color: var(--color-empty); }
.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--color-ambulyn-light);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
}
.access-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
  text-align: center;
}
.access-summary article {
  margin: 0;
  padding: 0.75rem;
}
.access-summary strong {
  font-size: 1.6rem;
  color: var(--color-ambulyn-primary);
}
.close-form {
  margin: 0;
}
.close-form button {
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
.extend-form {
  margin-bottom: 1rem;
}
.extend-form label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* ==========================================================================
   APP SHELL — product chrome layered on Pico. Three shells share one top bar:
     • public   — landing / login / register / privacy   (top bar only)
     • patient  — portal, mobile-first                   (top bar + bottom tabs)
     • provider — emergency desktop                       (top nav + left sidebar)
   ========================================================================== */
:root {
  --amb-accent:       #7ec8f4;
  --amb-primary-dark: #0a3560;
  --amb-surface:      #f8f9fb;
  --amb-border:       #e2e8f0;
  --amb-text:         #1a1a2e;
  --amb-muted:        #5f6b7a;
  --amb-topbar-h:     3.5rem;
}

/* Pico scales the root font up on wider viewports (up to ~21px); pin it back
   to a conventional 16px so the whole app reads at a calmer density. */
html { font-size: 16px; }
body {
  background: var(--amb-surface);
  color: var(--amb-text);
  overflow-wrap: break-word; /* break long unbreakable tokens (emails, URLs) instead of overflowing */
}

/* --------------------------------------------------------------------------
   Top bar — shared by all three shells
   -------------------------------------------------------------------------- */
.app-topbar {
  background: var(--color-ambulyn-primary);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Patient shell wraps the top bar + section nav in ONE sticky unit. iOS-safe:
   a single sticky element (not two stacked), and the sticky element is not
   itself a horizontal scroll container — both of which break sticky on Safari. */
.app-stickyhead { position: sticky; top: 0; z-index: 100; }
.app-stickyhead .app-topbar { position: static; }
.app-topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  height: var(--amb-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
}
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
}
.app-brand:hover { text-decoration: none; }
.app-brand .mark { width: 26px; height: 26px; flex-shrink: 0; display: block; }
.app-brand-word {
  color: #fff;
  font-size: 1.08rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}
.app-brand-word .accent { color: var(--amb-accent); }

/* Right-hand area of the top bar (links and/or account) */
.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}
.app-topbar-right a {
  color: #b8d8f0;
  font-size: 0.87rem;
  text-decoration: none;
}
.app-topbar-right a:hover { color: #fff; text-decoration: none; }
.app-topbar-right .accent-link { color: var(--amb-accent); font-weight: 500; }

.app-account { display: flex; align-items: center; gap: 0.9rem; }
.app-account .who { color: #cfe3f5; font-size: 0.85rem; }
.app-logout {
  margin: 0;
  display: inline;
}
.app-logout button {
  margin: 0;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  font-size: 0.8rem;
  padding: 0.3rem 0.85rem;
  border-radius: 7px;
  width: auto;
}
.app-logout button:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.55);
}

/* Centered content column for public + patient shells */
.app-main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 2.5rem;
  overflow-x: clip;   /* contain any stray-wide content here, not on <body> — keeps the
                         fixed bottom tab bar and sticky top bar free of clipping */
}

/* --------------------------------------------------------------------------
   App footer
   -------------------------------------------------------------------------- */
.app-footer {
  border-top: 0.5px solid var(--amb-border);
  padding: 1.1rem 1.25rem;
  text-align: center;
  background: #fff;
}
.app-footer small { font-size: 0.78rem; color: var(--amb-muted); }
.app-footer a { color: var(--color-ambulyn-primary); }

/* --------------------------------------------------------------------------
   Patient shell — section nav as a sticky row under the header (all sizes).
   Always visible at the top; scrolls horizontally only if it ever overflows.
   -------------------------------------------------------------------------- */
.tabbar {
  display: flex;
  justify-content: center;
  background: #fff;
  border-bottom: 0.5px solid var(--amb-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tabbar a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0.8rem 0.9rem;
  color: var(--amb-muted);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabbar a svg { width: 17px; height: 17px; flex-shrink: 0; }
.tabbar a.active {
  color: var(--color-ambulyn-primary);
  font-weight: 600;
  border-bottom-color: var(--color-ambulyn-primary);
}
.tabbar a.active svg { stroke: var(--color-ambulyn-primary); }
.tabbar a:hover { color: var(--color-ambulyn-primary); }

.patient-shell .app-main { padding-bottom: 2.5rem; }

/* --------------------------------------------------------------------------
   Provider shell — top nav + left sidebar (desktop dashboard)
   -------------------------------------------------------------------------- */
.provider-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: calc(100vh - var(--amb-topbar-h));
  align-items: start;
}
.provider-side {
  background: #fff;
  border-right: 0.5px solid var(--amb-border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: var(--amb-topbar-h);
  align-self: stretch;
}
.provider-side h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--amb-muted);
  margin: 0 0 0.75rem 0.6rem;
  font-weight: 600;
}
.provider-side nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  color: var(--amb-text);
  font-size: 0.9rem;
  text-decoration: none;
  margin-bottom: 2px;
}
.provider-side nav a:hover { background: var(--color-ambulyn-light); text-decoration: none; }
.provider-side nav a.active {
  background: var(--color-ambulyn-light);
  color: var(--color-ambulyn-primary);
  font-weight: 600;
}
.provider-side nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
.provider-side-note {
  margin-top: 1.25rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--color-ambulyn-light);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--amb-muted);
}
.provider-main {
  padding: 1.75rem 2rem 2.5rem;
  max-width: 920px;
  width: 100%;
  min-width: 0;   /* CRITICAL: the shell is a grid; without this the 1fr track grows to a
                     wide table's min-content and stretches the whole view past the viewport */
}

@media (max-width: 767px) {
  .provider-shell { grid-template-columns: 1fr; }
  .provider-side {
    position: static;
    border-right: none;
    border-bottom: 0.5px solid var(--amb-border);
    padding: 0.75rem 1rem;
  }
  .provider-side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .provider-side nav a { margin-bottom: 0; padding: 0.45rem 0.7rem; }
  .provider-side h2, .provider-side-note { display: none; }
  .provider-main { padding: 1.25rem 1rem 2rem; }
}

/* --------------------------------------------------------------------------
   Content helpers — page header, stat cards, generic card, action rows
   -------------------------------------------------------------------------- */
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { font-size: 1.45rem; margin: 0 0 0.35rem; }
.page-head p { color: var(--amb-muted); font-size: 0.95rem; line-height: 1.6; margin: 0; }

.card {
  background: #fff;
  border: 0.5px solid var(--amb-border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
}
.card > h2, .card > h3 { margin-top: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: #fff;
  border: 0.5px solid var(--amb-border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.stat-card .stat-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-ambulyn-primary);
  line-height: 1.15;
}
.stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--amb-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-card.is-empty .stat-num { color: var(--color-empty); }

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.action-grid a[role="button"] { margin: 0; }

/* Celebratory "emergency ready" banner — green = good/progress (never red). */
.ready-banner {
  background: var(--color-success);
  color: #fff;
  border-radius: 10px;
  padding: 0.9rem 1.15rem;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-top: 1rem;
}

/* --------------------------------------------------------------------------
   Public entry (landing) — choose-your-path cards
   -------------------------------------------------------------------------- */
.entry-hero {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}
.entry-hero h1 { font-size: 1.7rem; margin: 0 0 0.6rem; }
.entry-hero p { color: var(--amb-muted); font-size: 1rem; line-height: 1.65; max-width: 34rem; margin: 0 auto; }
.entry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}
.entry-card {
  background: #fff;
  border: 0.5px solid var(--amb-border);
  border-radius: 14px;
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.entry-card .entry-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--color-ambulyn-light);
  color: var(--color-ambulyn-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.entry-card .entry-icon svg { width: 22px; height: 22px; }
.entry-card h2 { font-size: 1.15rem; margin: 0; }
.entry-card p { color: var(--amb-muted); font-size: 0.9rem; line-height: 1.6; flex: 1; margin: 0; }
.entry-card a[role="button"] { margin: 0.4rem 0 0; }

/* --------------------------------------------------------------------------
   Portal content — section titles, card titles with counts, inline add-forms
   -------------------------------------------------------------------------- */
.section-title {
  font-size: 1.2rem;
  margin: 2rem 0 0.2rem;
  color: var(--color-ambulyn-primary);
}
.section-hint {
  color: var(--amb-muted);
  font-size: 0.86rem;
  line-height: 1.6;
  margin: 0 0 1rem;
}
.card-title {
  font-size: 1rem;
  margin: 0 0 0.85rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.card-title .count { color: var(--amb-muted); font-weight: 400; font-size: 0.85rem; }

/* Row lists inside cards: name on the left, compact actions on the right. */
.row-list { list-style: none; padding: 0; margin: 0; }
.row-list > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--amb-border);
}
.row-list > li:last-child { border-bottom: none; }
.row-list .row-main { min-width: 0; }
.row-list .row-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.row-list .row-actions form { margin: 0; display: inline-flex; gap: 0.4rem; align-items: center; }
.row-list .row-actions button {
  margin: 0;
  width: auto;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
}
.row-list .row-actions input {
  margin: 0;
  width: auto;
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
}

/* The "add new" form at the foot of an editable card. */
.inline-add {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 0.5px solid var(--amb-border);
}
.inline-add > button { margin-top: 0.6rem; margin-bottom: 0; }

/* Success banner (import confirmations) — green = good/progress. */
.success-banner {
  background: var(--color-success);
  color: #fff;
  border-radius: 10px;
  padding: 0.9rem 1.15rem;
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}
.success-banner a { color: #fff; text-decoration: underline; }

/* Access-log summary tiles reuse the stat-card look. */
.access-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  text-align: center;
}
.access-summary article {
  margin: 0;
  padding: 1rem 0.75rem;
  background: #fff;
  border: 0.5px solid var(--amb-border);
  border-radius: 12px;
}
.access-summary article strong {
  font-size: 1.45rem;
  color: var(--color-ambulyn-primary);
  display: block;
}
.access-summary article small { color: var(--amb-muted); font-size: 0.8rem; }

/* Emergency view inside the provider shell: keep the session bar (and its timer)
   pinned while the provider scrolls; offset anchor jumps for the sticky top bar. */
/* Emergency view: pin the session bar (NPI + live timer) to the very top as a SINGLE
   sticky element and let the top bar scroll away — iOS Safari mishandles two stacked
   stickies, which left only the session bar's last line visible. The .emergency-page
   body class is set by Emergency/View.cshtml. */
.emergency-page .app-topbar { position: static; }
.emergency-page .session-bar {
  position: sticky;
  top: 0;
  z-index: 100;
}
.provider-portal .emergency-section { scroll-margin-top: 5rem; }

/* --------------------------------------------------------------------------
   Mobile pass (phones) — reclaim width, fit the header, make tables scroll
   -------------------------------------------------------------------------- */
@media (max-width: 600px) {
  /* More usable width: trim the side gutters and card padding. */
  .app-main { padding-left: 0.9rem; padding-right: 0.9rem; }
  .app-topbar-inner { padding: 0 0.9rem; }
  .card { padding: 1rem 1.05rem; }

  /* Long header text (patient email / provider "Read-only access · logged") forces the
     header wider than the screen — drop it on phones; the brand + button are enough. */
  .app-topbar .who { display: none; }

  /* Provider emergency session bar: compact, wraps cleanly, button fits. */
  .session-bar { flex-wrap: wrap; gap: 0.25rem 0.7rem; padding: 0.5rem 0.75rem; }
  .session-bar > span, .session-timer { font-size: 0.85rem; }
  .extend-form button { width: 100%; white-space: normal; }

  /* Calmer headings on small screens. */
  .page-head h1 { font-size: 1.3rem; }
  .section-title { font-size: 1.05rem; }
  .entry-hero h1 { font-size: 1.5rem; }

  /* Wide read-only tables scroll within their card instead of overflowing it. */
  .card table,
  .emergency-section table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* Row lists: let the action buttons wrap under long text rather than squeeze. */
  .row-list > li { flex-wrap: wrap; gap: 0.35rem 1rem; }

  /* Pico's two-up form grids stack on phones (belt-and-suspenders). */
  .inline-add .grid { grid-template-columns: 1fr; }
}
