/* Shared explorer skeleton — structural + typographic rules common to every
   FHIR explorer built on this template (terminal-window chrome, the
   two-column layout, cards/buttons/inputs/bracket-tags, autocomplete
   dropdown, results list, detail view).

   This file defines NO color values of its own for the brand accent —
   every such reference is var(--accent) / var(--accent-dark) /
   var(--accent-tint), left undefined here on purpose. Each explorer's own
   styles.css supplies those three (plus anything app-specific) and is
   linked after this file. Neutral tokens (ink, borders, backgrounds,
   status colors, font stacks) are defined here since they're part of the
   shared look, not the per-app brand. */

:root {
  --bg: #FCFCFA;
  --panel: #FFFFFF;
  --ink: #1A1A1A;
  --ink-soft: #5A5A55;
  --border: #DAD9D2;
  --border-strong: #C4C3BA;

  --ok: #0F6E56;
  --down: #B23B2E;

  --mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, SFMono-Regular,
    Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  /* Reserve the scrollbar's width up front so pages that grow tall enough
     to need one don't shift horizontally when it appears. */
  scrollbar-gutter: stable;
}

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); }

/* Inline code snippets — monospace pill, used in the subtitle and the
   reset note. One rule so every <code> on the page looks the same. */
code {
  font-family: var(--mono);
  background: var(--accent-tint);
  padding: 1px 5px;
  border-radius: 2px;
  color: var(--accent-dark);
}

.wrap {
  /* Generous cap for very wide monitors only — not a single-column
     reading-width constraint. The two-column layout below should use the
     available viewport width, with breathing room from the edges coming
     from padding rather than a narrow centered box. */
  max-width: 1500px;
  margin: 0 auto;
  padding: 32px 36px 96px;
}

/* ---- two-column layout ----
   Left: sidebar (terminal-window info block, fixed narrow width).
   Right: main working area (search, results, detail view), flexible. */

.layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.layout > .terminal {
  flex: 0 0 300px;
  width: 300px;
}

.layout > .main {
  flex: 1 1 0%;
  min-width: 0;
}

.layout > .main > .section {
  margin-top: 0;
}

/* ---- terminal-window chrome ---- */

.terminal {
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel);
  overflow: hidden;
}

.terminal__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  background: var(--accent-tint);
  border-bottom: 1px solid var(--border);
}

.terminal__path {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--accent-dark);
  letter-spacing: 0.02em;
}

.terminal__body {
  padding: 22px 20px;
}

.terminal__title {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.terminal__subtitle {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 14px;
}

/* Mobile-only collapse affordance for the sidebar's details — inert on
   desktop, where .terminal__details is always shown (see media query). */
.terminal__toggle {
  display: none;
}

.terminal__details {
  display: block;
}

/* ---- stat row ---- */

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stat {
  flex: 1 1 160px;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px 14px;
  background: var(--bg);
}

.stat__label {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.stat__value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
}

.stat__value small {
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-soft);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
}

.status__led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: none;
}

.status[data-state="up"] .status__led { background: var(--ok); }
.status[data-state="down"] .status__led { background: var(--down); }
.status[data-state="up"] { color: var(--ok); }
.status[data-state="down"] { color: var(--down); }

.reset-note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---- section ---- */

.section {
  margin-top: 34px;
}

.section__head {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 16px;
}

/* ---- tags ---- */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-dark);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 2px 4px;
  white-space: pre;
}

/* Muted variant — a record identifier isn't a category, so it skips the
   accent-colored treatment other tags get. Used as a suffix right after
   a name (e.g. on the patient card), hence the left margin. */
.tag--id {
  margin-left: 8px;
  color: var(--ink-soft);
  border-color: var(--border);
}

/* ---- search ---- */

.search {
  display: flex;
  gap: 8px;
}

.search__field {
  position: relative;
  flex: 1;
}

.search input {
  width: 100%;
  font-family: var(--mono);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--panel);
  color: var(--ink);
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- autocomplete dropdown ----
   Shared by any text input that wants type-ahead suggestions — an
   explorer adds more of these (see Erebor's condition field) by pairing
   its own input with a `.suggest` dropdown; no extra CSS needed. */

.suggest {
  position: absolute;
  z-index: 20;
  top: calc(100% + 3px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  max-height: 320px;
  overflow-y: auto;
}

.suggest__item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.suggest__item:last-child { border-bottom: 0; }
.suggest__item:hover,
.suggest__item.is-active { background: var(--accent-tint); }

.suggest__name {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13.5px;
}

.suggest__meta {
  margin-left: auto;
  color: var(--ink-soft);
  font-size: 12.5px;
  white-space: nowrap;
}

.suggest__msg {
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-style: italic;
}

.search > button:not(.clear-btn) {
  font-family: var(--mono);
  font-size: 13px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.search > button:not(.clear-btn):hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.search > button:not(.clear-btn):disabled { opacity: 0.5; cursor: default; }

/* Reset/trash icon — same border, font and corners as the rest of the
   search UI, but understated (outline only) since it's a destructive,
   secondary action next to the primary search button. */
.clear-btn {
  flex: none;
  width: 38px;
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
}

.clear-btn:hover { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); }

.hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  min-height: 1.4em;
}

/* ---- results list ---- */

.results {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.results:empty { display: none; }

.result {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.result:last-child { border-bottom: 0; }
.result:hover { background: var(--accent-tint); }

.result__name {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
}

.result__meta {
  color: var(--ink-soft);
  font-size: 13px;
}

.result__id {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--border-strong);
}

/* ---- detail view ---- */

.detail {
  margin-top: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  overflow: hidden;
}

.detail__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--accent-tint);
  border-bottom: 1px solid var(--border);
}

.detail__name {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 16px;
}

.detail__meta {
  font-size: 13px;
  color: var(--accent-dark);
}

.detail__back {
  font-family: var(--mono);
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--accent-dark);
}

.detail__back:hover { background: #fff; }

.detail__body { padding: 6px 16px 16px; }

.detail__group { margin-top: 16px; }

.detail__group h3 {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin: 0 0 8px;
}

.entry {
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
}

.entry:last-child { border-bottom: 0; }

/* List-item title — monospace, matching .result__name / .suggest__name /
   .detail__name. */
.entry__title {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
}

/* Secondary attribute line — sans, matching .result__meta / .detail__meta. */
.entry__sub {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ---- fact grid ----
   Label/value pairs below a record's name — e.g. a patient's age, DOB,
   sex, marital status, and so on. */

.fact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px 18px;
  margin-top: 4px;
}

.fact__label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin-bottom: 3px;
}

.fact__value {
  font-size: 14px;
}

/* ---- collapsible ----
   Generic smooth-height expand/collapse: animating a grid track (rather
   than max-height, which needs a guessed cap, or display, which can't
   transition) so any amount of content grows/shrinks cleanly. Toggled by
   JS adding/removing .is-open; the direct child needs overflow hidden +
   min-height 0 so it clips during the animation instead of reflowing. */

.collapsible {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.collapsible.is-open {
  grid-template-rows: 1fr;
}

.collapsible > * {
  overflow: hidden;
  min-height: 0;
}

/* ---- file drawer ----
   A dashed "pull tab" at the bottom of a record card; clicking it expands
   a .collapsible drawer directly beneath, holding that record's full
   history (see .timeline-* below). */

.file-drawer__tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 18px;
  padding: 9px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
}

.file-drawer__tab:hover { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); }
.file-drawer__tab:disabled { cursor: default; opacity: 0.55; }
.file-drawer__tab:disabled:hover { background: transparent; border-color: var(--border-strong); color: var(--ink-soft); }

.file-drawer__tab-icon {
  display: inline-block;
  font-size: 11px;
}

.file-drawer__body {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--border);
}

/* ---- timeline (merged, year-grouped history) ---- */

.timeline-year {
  margin-top: 14px;
}

.timeline-year:first-child {
  margin-top: 0;
}

.timeline-year__head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 4px;
  margin: 0 -4px;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.timeline-year__head:hover { background: var(--accent-tint); }

.timeline-year__icon {
  display: inline-block;
  font-size: 10px;
  color: var(--ink-soft);
}

.timeline-year__label {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
}

.timeline-year__count {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* The dashed separator lives on the wrapper (row + its optional detail
   panel below), not the row itself, so it reads as one unit whether or
   not that unit is expanded. */
.timeline-entry-wrap {
  border-bottom: 1px dashed var(--border);
}

.timeline-entry-wrap:last-child { border-bottom: 0; }

/* flex-wrap (not a breakpoint) is what gives narrow rows their two-line
   layout: .timeline-entry__meta is a nowrap unit that never breaks apart,
   and .timeline-entry__desc (flex: 1 1 200px, see below) shares its line
   whenever there's actually room and drops to its own full-width line
   the moment there isn't — self-adjusting to the row's real width rather
   than a guessed viewport size. */
.timeline-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 8px 4px;
}

/* The atomic date + type tag + status badge unit — white-space: nowrap
   plus flex: none means it never breaks internally and never shrinks;
   it either fits on the current line whole, or (via the row's
   flex-wrap) the desc that follows it wraps away, never this. */
.timeline-entry__meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex: none;
  white-space: nowrap;
}

/* Only applied when the row actually has an expandable detail behind it
   (see .timeline-entry__detail) — otherwise the row is a plain, inert
   div: no pointer cursor, no dead-end click. */
.timeline-entry--clickable {
  width: 100%;
  font: inherit;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.timeline-entry--clickable:hover { background: var(--accent-tint); }

.timeline-entry__date {
  flex: none;
  width: 54px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
}

/* flex: 1 1 200px — grows to fill whatever space .timeline-entry__meta
   leaves on the line, but won't be squeezed below ~200px; once the line
   can't offer that much it wraps to its own full-width row instead. */
.timeline-entry__desc {
  flex: 1 1 200px;
  min-width: 0;
  font-size: 13px;
}

.timeline-entry__expand-icon {
  margin-left: auto;
  font-size: 10px;
  color: var(--ink-soft);
}

/* Indented to land under .timeline-entry__desc (past the date column's
   54px + the row's 10px gap). */
.timeline-entry__detail {
  padding: 0 4px 10px 64px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* ---- status badge ----
   Neutral/muted, deliberately distinct from the colored bracket type tag
   next to it — e.g. a Condition's clinicalStatus or an Encounter's
   class. */
.badge {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 5px;
  white-space: nowrap;
}

/* Status/prose messages — sans, matching .hint and .terminal__subtitle. */
.empty {
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
}

.error {
  color: var(--down);
  font-size: 13px;
}

.footer {
  margin-top: 40px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

/* Below this, a cramped two-column squeeze doesn't work — collapse back
   to a single stacked column: sidebar info block on top, search/results
   below. The sidebar is a fixed 300px; once it would eat more than
   roughly a third of the viewport, force the stack (300px * 3 = 900px).
   Any explorer-specific stylesheet adding its own mobile rules (e.g. an
   extra filter row) needs to match this same 900px breakpoint. */
@media (max-width: 900px) {
  .layout {
    flex-direction: column;
    /* .layout's align-items: flex-start is a desktop-only cross-axis rule
       (keeps the shorter sidebar from being vertically stretched to match
       the taller main column). Once flex-direction flips to column, the
       cross axis becomes horizontal — flex-start left over from desktop
       would shrink-to-fit each child's width to its content instead of
       the full row. Reset to stretch so every stacked child spans the
       full available width. */
    align-items: stretch;
  }

  .layout > .terminal {
    flex: 1 1 auto;
    width: auto;
  }

  .layout > .main > .section {
    margin-top: 34px;
  }

  /* Small side margins only, not a narrow centered box — same full-width
     treatment as the rest of the page at this width. */
  .wrap {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Sidebar collapse: title + description stay visible; everything else
     is hidden until the toggle expands it. Collapsed is the default —
     .terminal__details simply has no is-expanded ancestor yet. */
  .terminal__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--accent-dark);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 2px;
    padding: 4px 10px;
    cursor: pointer;
  }

  .terminal__toggle:hover {
    background: var(--accent-tint);
  }

  .terminal__toggle-icon {
    display: inline-block;
    transition: transform 0.15s ease;
  }

  .terminal.is-expanded .terminal__toggle-icon {
    transform: rotate(90deg);
  }

  .terminal__details {
    display: none;
    margin-top: 18px;
  }

  .terminal.is-expanded .terminal__details {
    display: block;
  }

  /* Search row: the input stays full-width on its own line (flex-basis
     100% forces the wrap); search + clear then share the next line
     together instead of each stacking as its own full-width row. */
  .search {
    flex-wrap: wrap;
  }

  .search__field {
    flex: 1 1 100%;
  }

  .search > button:not(.clear-btn) {
    flex: 1 1 auto;
  }

  .clear-btn {
    flex: 0 0 44px;
  }
}

@media (max-width: 560px) {
  .result__id { display: none; }
}
