/* CHARTWELL · clinical calm — white + teal + slate.
   Three voices, one job each: Source Sans fills the forms, Source Serif names
   the patient, IBM Plex Mono types the data (MRNs, dates, classifications). */

/* ── ground rules ─────────────────────────────────────────── */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

:root {
  --paper:      #FBFDFD;   /* clinical white — barely cool */
  --field:      #F2F6F7;   /* wash for wells and the gate */
  --ink:        #25313A;   /* deep slate, never black */
  --slate-600:  #576873;
  --slate-400:  #8CA0AB;
  --line:       #DFE7EA;
  --teal:       #0F6E68;   /* wayfinding teal */
  --teal-deep:  #0A5450;
  --teal-wash:  #DFEDEB;
  --teal-line:  #B9D6D3;   /* the record spine */
  --claret:     #8C3A38;   /* errors only */

  --sans:  "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --mono:  "IBM Plex Mono", "SF Mono", Consolas, monospace;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1 0 auto; width: 100%; }
img, svg { max-width: 100%; }

:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
::selection { background: var(--teal-wash); }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 30;
  background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 0.75rem;
  padding: 0.5em 1em;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* overline label — the form vernacular used across the app */
.ovl, .field label, .bf-label, .ds-tag {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--slate-400);
}

/* ── masthead ─────────────────────────────────────────────── */
.mast {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  max-width: 66rem; margin: 0 auto; width: 100%;
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: baseline; gap: 0.55rem;
  text-decoration: none; color: var(--ink);
}
.brand-mark {
  align-self: center;
  width: 16px; height: 16px; border-radius: 3px;
  background:
    radial-gradient(circle 2.2px at 6px 4.5px, var(--paper) 98%, transparent) ,
    radial-gradient(circle 2.2px at 6px 11.5px, var(--paper) 98%, transparent),
    linear-gradient(90deg, transparent 5px, var(--paper) 5px, var(--paper) 7px, transparent 7px),
    var(--teal);
}
.brand-word { font-family: var(--serif); font-weight: 600; font-size: 1.22rem; letter-spacing: 0.01em; }
.brand-sub { font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--slate-400); }
.mast-nav { display: flex; gap: 1rem; margin-left: auto; }
.mast-nav a {
  font-size: 0.92rem; font-weight: 600; color: var(--slate-600);
  text-decoration: none; padding: 0.2rem 0.1rem;
  border-bottom: 2px solid transparent;
}
.mast-nav a:hover { color: var(--ink); }
.mast-nav a[aria-current="page"] { color: var(--teal); border-bottom-color: var(--teal); }
.who { display: flex; align-items: center; }
.who-box { display: flex; align-items: center; gap: 0.7rem; }
.who-name { font-size: 0.9rem; font-weight: 600; color: var(--slate-600); }

/* ── buttons & links ──────────────────────────────────────── */
.btn {
  display: inline-block;
  font-family: var(--sans); font-size: 0.92rem; font-weight: 600;
  padding: 0.5rem 1rem; border-radius: 3px;
  border: 1px solid transparent; cursor: pointer;
  text-decoration: none; text-align: center;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-deep); }
.btn-primary:disabled { background: var(--slate-400); cursor: default; }
.btn-quiet { background: transparent; color: var(--slate-600); border-color: var(--line); padding: 0.35rem 0.8rem; }
.btn-quiet:hover { color: var(--teal); border-color: var(--teal-line); }
.btn-ghost { background: transparent; color: var(--teal); border-color: var(--teal-line); }
.btn-ghost:hover { background: var(--teal-wash); }
.btn-wide { width: 100%; }
.linklike {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--teal);
  text-decoration: underline; text-underline-offset: 2px;
}
.backlink {
  display: inline-block; margin-bottom: 1.4rem;
  font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.08em;
  color: var(--slate-600); text-decoration: none;
}
.backlink::before { content: "←\00a0"; }
.backlink:hover { color: var(--teal); }

/* ── view scaffolding ─────────────────────────────────────── */
.view { max-width: 66rem; margin: 0 auto; padding: 2rem 1.5rem 3.5rem; width: 100%; }
.view-narrow { max-width: 50rem; }
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.vh-h { font-family: var(--serif); font-weight: 600; font-size: 1.65rem; line-height: 1.2; margin: 0; }
.vh-sub { margin: 0.3rem 0 0; font-size: 0.9rem; color: var(--slate-600); }

.statement {
  padding: 1.4rem 0 1.6rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}
.st-h { font-family: var(--serif); font-weight: 600; font-size: 2.1rem; line-height: 1.15; margin: 0 0 0.7rem; }
.st-lede { max-width: 44rem; margin: 0; color: var(--slate-600); font-size: 1.02rem; }

/* status lines: quiet mono sentences while data is on its way */
.state { padding: 1.2rem 0; }
.status-line { font-family: var(--mono); font-size: 0.8rem; color: var(--slate-400); margin: 0; }
.state-err { font-size: 0.95rem; color: var(--claret); margin: 0 0 0.7rem; }

/* empty states: an invitation, not a mood */
.empty {
  border: 1px dashed var(--line); border-radius: 4px;
  padding: 1.6rem 1.5rem; margin: 0.5rem 0;
  background: var(--field);
}
.empty strong { display: block; font-family: var(--serif); font-size: 1.08rem; font-weight: 600; margin-bottom: 0.3rem; }
.empty p { margin: 0 0 0.9rem; color: var(--slate-600); font-size: 0.95rem; max-width: 34rem; }
.empty .btn { margin-top: 0.1rem; }
.empty > :last-child { margin-bottom: 0; }

/* ── chips (directory filter) ─────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0 0 1.2rem; }
.chips button {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.05em;
  padding: 0.3rem 0.7rem; border-radius: 2px; cursor: pointer;
  background: var(--paper); color: var(--slate-600); border: 1px solid var(--line);
}
.chips button:hover { border-color: var(--teal-line); color: var(--teal); }
.chips button[aria-pressed="true"] {
  background: var(--teal-wash); border-color: var(--teal); color: var(--teal-deep);
}

/* ── directory rows ───────────────────────────────────────── */
.dir-list { border-top: 1px solid var(--line); }
.prov {
  display: grid;
  /* fixed end track so every row resolves identical columns */
  grid-template-columns: minmax(11rem, 1.3fr) minmax(8rem, 1fr) minmax(11rem, 1.4fr) 12.5rem;
  gap: 0.35rem 1.5rem; align-items: baseline;
  padding: 0.95rem 0.25rem;
  border-bottom: 1px solid var(--line);
}
.pv-name { font-family: var(--serif); font-weight: 600; font-size: 1.06rem; margin: 0; }
.pv-spec { font-size: 0.9rem; color: var(--slate-600); margin: 0; }
.pv-clinic { font-size: 0.9rem; color: var(--slate-600); margin: 0; }
.pv-clinic small { display: block; font-size: 0.8rem; color: var(--slate-400); }
.pv-open { justify-self: end; }
.badge {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.09em; text-transform: uppercase;
  padding: 0.22rem 0.55rem; border-radius: 2px; white-space: nowrap;
}
.badge-open { background: var(--teal-wash); color: var(--teal-deep); }
.badge-closed { background: var(--field); color: var(--slate-400); border: 1px solid var(--line); }

/* ── roster rows ──────────────────────────────────────────── */
.roster { border-top: 1px solid var(--line); }
.p-row {
  display: grid;
  /* fixed MRN and date tracks keep the columns ruled straight across rows */
  grid-template-columns: minmax(12rem, 1.4fr) 9rem minmax(7rem, 1fr) 12rem;
  gap: 0.3rem 1.5rem; align-items: baseline;
  width: 100%; text-align: left;
  padding: 1rem 0.25rem;
  border: 0; border-bottom: 1px solid var(--line);
  background: none; cursor: pointer; font-family: inherit;
  color: inherit; text-decoration: none;
}
.p-row:hover .pr-name { color: var(--teal); }
.pr-name { font-family: var(--serif); font-weight: 600; font-size: 1.12rem; margin: 0; }
.pr-mrn { font-family: var(--mono); font-size: 0.78rem; color: var(--slate-600); margin: 0; }
.pr-bio { font-size: 0.9rem; color: var(--slate-600); margin: 0; }
.pr-since { font-size: 0.8rem; color: var(--slate-400); margin: 0; justify-self: end; }

/* ── the chart ────────────────────────────────────────────── */
.chart-cap { margin-bottom: 2rem; }
.cc-name { font-family: var(--serif); font-weight: 600; font-size: 2rem; line-height: 1.15; margin: 0 0 1rem; }

/* patient banner — a printed form row; 1px grid gaps paint the rules */
.banner {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.bf { background: var(--paper); padding: 0.6rem 0.85rem 0.7rem; }
.bf-label { display: block; margin-bottom: 0.15rem; }
.bf-value { font-size: 0.97rem; font-weight: 600; }
.bf-value.mono { font-family: var(--mono); font-weight: 500; font-size: 0.88rem; }

.record-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin: 0 0 0.4rem;
}
.rh-h { font-family: var(--serif); font-weight: 600; font-size: 1.3rem; margin: 0; }
.rh-count { font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.06em; color: var(--slate-400); }

/* the add-entry fold */
.fold { border: 1px solid var(--line); border-radius: 3px; margin: 0.8rem 0 2.2rem; background: var(--field); }
.fold summary {
  cursor: pointer; list-style: none;
  padding: 0.7rem 1rem;
  font-weight: 600; font-size: 0.95rem; color: var(--teal);
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::before { content: "+"; font-family: var(--mono); margin-right: 0.55rem; color: var(--teal); }
.fold[open] summary::before { content: "–"; }
.fold[open] summary { border-bottom: 1px solid var(--line); }
.fold-body { padding: 1.1rem 1rem 1.2rem; background: var(--paper); border-radius: 0 0 3px 3px; }

/* ═══ the record timeline — Chartwell's signature ═══ */
.record { margin-top: 0.6rem; }
.entry {
  display: grid;
  grid-template-columns: 4.6rem 1.4rem 1fr;
  column-gap: 0.6rem;
}
.e-date {
  text-align: right;
  font-family: var(--mono);
  padding-top: 0.1rem;
}
.ed-day { display: block; font-size: 0.82rem; font-weight: 500; color: var(--slate-600); }
.ed-year { display: block; font-size: 0.68rem; color: var(--slate-400); }
.e-spine { position: relative; }
.e-spine::before {
  content: ""; position: absolute; top: 0.45rem; bottom: -0.45rem; left: 50%;
  width: 1px; background: var(--teal-line);
}
.entry:last-child .e-spine::before { bottom: auto; height: 1.4rem; }
.e-spine::after {
  content: ""; position: absolute; top: 0.42rem; left: 50%;
  width: 9px; height: 9px; border-radius: 50%;
  transform: translateX(-50%);
  background: var(--teal);
  box-shadow: 0 0 0 3px var(--paper);
}
.e-body { padding: 0 0 2.3rem 0.2rem; min-width: 0; }
.e-type {
  display: inline-block;
  font-family: var(--mono); font-size: 0.66rem; font-weight: 500;
  letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--teal-deep); background: var(--teal-wash);
  padding: 0.16rem 0.5rem; border-radius: 2px;
}
.e-time { font-family: var(--mono); font-size: 0.68rem; color: var(--slate-400); margin-left: 0.55rem; }
.e-summary { font-size: 1.06rem; font-weight: 600; line-height: 1.45; margin: 0.45rem 0 0.25rem; }
.e-details { font-size: 0.97rem; color: var(--slate-600); margin: 0 0 0.5rem; white-space: pre-wrap; overflow-wrap: break-word; }
.e-meta { font-size: 0.83rem; color: var(--slate-400); margin: 0; }
.e-meta b { color: var(--slate-600); font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
  .record .entry { animation: entry-in 320ms ease-out backwards; }
  .record .entry:nth-child(2) { animation-delay: 60ms; }
  .record .entry:nth-child(3) { animation-delay: 120ms; }
  .record .entry:nth-child(n+4) { animation-delay: 180ms; }
  @keyframes entry-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
  }
}

/* ── forms ────────────────────────────────────────────────── */
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.3rem; }
.field input, .field select, .field textarea {
  width: 100%;
  font-family: var(--sans); font-size: 0.97rem; color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 3px;
  padding: 0.5rem 0.65rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--teal); outline-offset: 0; border-color: var(--teal);
}
.field textarea { resize: vertical; line-height: 1.55; }
.mono-input { font-family: var(--mono) !important; font-size: 0.88rem !important; letter-spacing: 0.03em; }
.field-help { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--slate-400); line-height: 1.5; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-err { color: var(--claret); font-size: 0.9rem; margin: 0 0 0.9rem; }
.reg-form { max-width: 32rem; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.gf-wide { grid-column: 1 / -1; }

/* ── the gate ─────────────────────────────────────────────── */
.gate { display: flex; justify-content: center; padding: 2.5rem 0 1.5rem; }
.gate-card {
  width: 100%; max-width: 26.5rem;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 4px;
  border-top: 3px solid var(--teal);
  padding: 1.8rem 1.7rem 1.6rem;
}
.gc-eyebrow {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--slate-400); margin: 0 0 0.6rem;
}
.gc-h { font-family: var(--serif); font-weight: 600; font-size: 1.5rem; margin: 0 0 0.5rem; }
.gc-lede { font-size: 0.92rem; color: var(--slate-600); margin: 0 0 1.3rem; }
.gc-note {
  font-size: 0.9rem; color: var(--teal-deep);
  background: var(--teal-wash); border-radius: 3px;
  padding: 0.55rem 0.8rem; margin: 0 0 1rem;
}
.demo-slot {
  margin: 1.3rem 0 0; padding: 0.9rem 1rem 1rem;
  background: var(--field); border: 1px solid var(--line); border-radius: 3px;
}
.ds-tag { margin: 0 0 0.5rem; }
.ds-rows { margin: 0 0 0.8rem; }
.ds-rows div { display: flex; gap: 0.8rem; align-items: baseline; padding: 0.12rem 0; }
.ds-rows dt {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--slate-400); min-width: 4.6rem;
}
.ds-rows dd { margin: 0; font-family: var(--mono); font-size: 0.82rem; color: var(--ink); }
.gc-alt { margin: 1.2rem 0 0.8rem; font-size: 0.92rem; color: var(--slate-600); }

/* ── toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  z-index: 40; max-width: min(92vw, 30rem);
  background: var(--ink); color: var(--paper);
  font-size: 0.9rem; line-height: 1.45;
  padding: 0.65rem 1.1rem; border-radius: 3px;
}
.toast--err { background: var(--claret); }

/* ── footer ───────────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--line);
  max-width: 66rem; margin: 0 auto; width: 100%;
  padding: 1.2rem 1.5rem 1.6rem;
}
.foot p { margin: 0; font-size: 0.85rem; color: var(--slate-600); }
.foot-dim { margin-top: 0.25rem !important; font-size: 0.78rem !important; color: var(--slate-400) !important; }

/* ── small screens ────────────────────────────────────────── */
@media (max-width: 760px) {
  .mast { gap: 0.6rem 1rem; padding: 0.8rem 1rem; }
  .brand-sub { display: none; }
  .view { padding: 1.5rem 1rem 3rem; }
  .st-h { font-size: 1.7rem; }
  .cc-name { font-size: 1.65rem; }
  .prov { grid-template-columns: 1fr auto; }
  .pv-spec { grid-column: 1; }
  .pv-clinic { grid-column: 1 / -1; }
  .pv-open { grid-row: 1; grid-column: 2; }
  .p-row { grid-template-columns: 1fr auto; }
  .pr-bio { grid-column: 1; }
  .pr-since { grid-row: 1; grid-column: 2; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .grid-form { grid-template-columns: 1fr; }

  /* the banner refolds to two ruled columns; the last field takes the full row */
  .banner { grid-template-columns: 1fr 1fr; }
  .bf:last-child { grid-column: 1 / -1; }

  /* the date gutter folds into a date line above each entry */
  .entry { grid-template-columns: 1.4rem 1fr; column-gap: 0.5rem; }
  .e-date { grid-column: 2; text-align: left; display: flex; gap: 0.45rem; align-items: baseline; padding-top: 0; }
  .e-spine { grid-row: 1 / 3; }
  .e-body { grid-column: 2; padding-top: 0.35rem; }
}
