/* =====================================================================
   Bioexelixis — app interface styling on top of Pico.css.
   One system with the printed PDF (config/report_template.html):
   same teal (#168b96), same tri-colour gradient spine, same status
   colours, same type (IBM Plex Sans for text, IBM Plex Mono for numbers).
   Fonts are self-hosted in static/vendor/fonts/ — fully offline.
   ===================================================================== */

/* ---- IBM Plex Sans: all text, incl. Greek. Latin + Greek per weight ---- */
@font-face{font-family:"IBM Plex Sans";font-weight:400;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-latin-400.woff2") format("woff2");
  unicode-range:U+0000-024F,U+2000-206F,U+2100-214F;}
@font-face{font-family:"IBM Plex Sans";font-weight:400;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-greek-400.woff2") format("woff2");
  unicode-range:U+0370-03FF,U+1F00-1FFF;}
@font-face{font-family:"IBM Plex Sans";font-weight:500;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-latin-500.woff2") format("woff2");
  unicode-range:U+0000-024F,U+2000-206F,U+2100-214F;}
@font-face{font-family:"IBM Plex Sans";font-weight:500;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-greek-500.woff2") format("woff2");
  unicode-range:U+0370-03FF,U+1F00-1FFF;}
@font-face{font-family:"IBM Plex Sans";font-weight:600;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-latin-600.woff2") format("woff2");
  unicode-range:U+0000-024F,U+2000-206F,U+2100-214F;}
@font-face{font-family:"IBM Plex Sans";font-weight:600;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-greek-600.woff2") format("woff2");
  unicode-range:U+0370-03FF,U+1F00-1FFF;}
@font-face{font-family:"IBM Plex Sans";font-weight:700;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-latin-700.woff2") format("woff2");
  unicode-range:U+0000-024F,U+2000-206F,U+2100-214F;}
@font-face{font-family:"IBM Plex Sans";font-weight:700;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-sans-greek-700.woff2") format("woff2");
  unicode-range:U+0370-03FF,U+1F00-1FFF;}
/* ---- IBM Plex Mono: numbers, units, codes, dates (Latin/digits only) ---- */
@font-face{font-family:"IBM Plex Mono";font-weight:500;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-mono-latin-500.woff2") format("woff2");}
@font-face{font-family:"IBM Plex Mono";font-weight:600;font-style:normal;font-display:swap;
  src:url("vendor/fonts/ibm-plex-mono-latin-600.woff2") format("woff2");}

:root {
  /* Teal — one enforced ramp (canonical #168b96 matches the PDF). */
  --teal-deep: #0f6a72;
  --teal:      #168b96;
  --teal-head: #1b98a2;
  --teal-soft: #e4f3f4;
  --teal-wash: #f4fafb;
  /* Orange — the single accent. */
  --orange:      #e07b39;
  --orange-soft: #fdefe3;
  /* Online/digital appointments — a deliberate secondary semantic (in-person
     is teal, online is violet). Used for join buttons + online chips only. */
  --online:      #5b3fb0;
  --online-soft: #e7e0fb;
  /* Status — identical to scoring.py + PDF. Never drift. */
  --st-high:    #e8455e;
  --st-concern: #f2922e;
  --st-mild:    #efb52b;
  --st-ok:      #2cb673;
  --st-na:      #9aa0a6;
  /* Ink, neutrals, hairlines. */
  --ink:        #1a1a1a;
  --ink-soft:   #5a6b6e;
  --grey:       #777;
  --line:       #cfe0e5;   /* teal-tinted hairline (from the PDF) */
  --line-plain: #e2e2e2;
  --danger:     #c0392b;   /* app errors / delete only — never a finding */
  /* Type. */
  --sans: "IBM Plex Sans", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  /* Radius scale. */
  --r-sm: 6px; --r-md: 8px; --r-lg: 10px; --r-pill: 999px;

  /* Spacing — one 4px-based scale. Every gap/padding maps to a step. */
  --space-1: 0.25rem;  /* 4  */
  --space-2: 0.5rem;   /* 8  */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.5rem;   /* 24 */
  --space-6: 2rem;     /* 32 */

  /* Type — one 6-step scale (see --sans/--mono for family). */
  --text-xs:   0.75rem;    /* captions, tags, table headers */
  --text-sm:   0.8125rem;  /* labels, secondary text */
  --text-base: 0.9375rem;  /* body, inputs, table cells */
  --text-md:   1rem;       /* sub-sections, primary buttons */
  --text-lg:   1.125rem;   /* section / card headers */
  --text-xl:   1.5rem;     /* page title */

  /* Bright teal — small highlights only; the enforced teal stays #168b96
     so the screen matches the printed PDF exactly. */
  --teal-bright: #2aafaf;

  /* Bind Pico to the system. */
  --pico-font-family: var(--sans);
  --pico-primary: var(--teal);
  --pico-primary-hover: var(--teal-deep);
  --pico-primary-focus: rgba(22, 139, 150, 0.28);
  --pico-form-element-focus-color: rgba(22, 139, 150, 0.45);
  /* Pico v2 fills buttons from *-background (not --pico-primary), so bind these
     too — otherwise every plain submit button renders Pico's default blue. */
  --pico-primary-background: var(--teal);
  --pico-primary-hover-background: var(--teal-deep);
  --pico-primary-border: var(--teal);
  --pico-primary-hover-border: var(--teal-deep);
  --pico-primary-inverse: #fff;
}
/* Pico scopes its palette to :root:not([data-theme=dark]), which outranks a
   plain :root — so re-bind the button colours at matching specificity, or every
   default submit button falls back to Pico's blue. */
:root:not([data-theme="dark"]), [data-theme="light"] {
  --pico-primary: var(--teal);
  --pico-primary-hover: var(--teal-deep);
  --pico-primary-background: var(--teal);
  --pico-primary-hover-background: var(--teal-deep);
  --pico-primary-border: var(--teal);
  --pico-primary-hover-border: var(--teal-deep);
  --pico-primary-inverse: #fff;
}

body { font-family: var(--sans); color: var(--ink); background: var(--teal-wash); margin: 0; }
main.container { background: var(--teal-wash); }

/* Pico "secondary" buttons → calm teal outline (distinct from the orange
   primary actions, which are reserved for Generate / Finalise). */
.secondary:not(.generate) {
  background: #fff; border-color: var(--teal); color: var(--teal);
}
.secondary:not(.generate):hover {
  background: var(--teal); border-color: var(--teal); color: #fff;
}
button:disabled, .secondary:disabled, .generate:disabled, [type="submit"]:disabled {
  opacity: 0.5; cursor: not-allowed;
}

/* ===================================================================
   Shared components — one of each (used across every screen).
   =================================================================== */

/* Empty state: an invitation to act, not a dead end. */
.empty-state {
  text-align: center; padding: var(--space-6) var(--space-4);
  color: var(--ink-soft); display: flex; flex-direction: column;
  align-items: center; gap: var(--space-3);
}
.empty-state .es-ic { font-size: 2rem; line-height: 1; opacity: 0.6; }
.empty-state .es-msg { margin: 0; font-size: var(--text-base); }
.empty-state .es-sub { margin: 0; font-size: var(--text-sm); color: var(--grey); }
.empty-state button { width: auto; margin: 0; }

/* Alert / inline message: info · error · warn · success (one look each). */
.alert {
  padding: var(--space-3) var(--space-4); border-radius: var(--r-md);
  font-size: var(--text-sm); border: 1px solid transparent;
  margin: var(--space-3) 0; line-height: 1.4;
}
.alert-error { background: #fdeceb; border-color: #f1c7c1; color: var(--danger); }
.alert-warn  { background: #fff6e0; border-color: #f0d98a; color: #8a6d0b; }
.alert-info  { background: var(--teal-wash); border-color: var(--teal-soft); color: var(--teal-deep); }
.alert-ok    { background: #e8f7ef; border-color: #bfe6cf; color: #1c7a4a; }

/* Inline loading indicator (spinner + text) for async waits. */
.loading-inline {
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--ink-soft); font-size: var(--text-sm); font-weight: 600;
}
.loading-inline::before {
  content: ""; width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid var(--teal-soft); border-top-color: var(--teal);
  animation: spin 0.7s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Native file-input button → the secondary (teal outline) look, everywhere. */
input[type="file"]::file-selector-button {
  background: #fff; color: var(--teal); border: 1px solid var(--teal);
  border-radius: var(--r-sm); padding: 0.35rem 0.9rem; margin-right: var(--space-3);
  font-weight: 600; font-size: var(--text-sm); cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--teal); color: #fff; }

/* Numbers everywhere read like a calibrated instrument. */
.num, .code, .unit,
.finding .input-cell input,
input[type="date"], input[type="number"] {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ---- Gradient spine — shared with every PDF page ---- */
.gradient-bar {
  height: 4px;
  background: linear-gradient(90deg, #19a6a0, #3e78c9, #7b46bc);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1.2rem;
  padding-bottom: 0.4rem;
}
.app-header h1 { color: var(--teal); margin: 0; font-size: 1.55rem; font-weight: 700; letter-spacing: -0.01em; }
.app-header p { margin: 0.15rem 0 0; }
.muted { color: var(--ink-soft); }

.entered-counter {
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.entered-counter .num { font-weight: 600; }

/* ---- Status legend ---- */
.legend { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-2) 0 var(--space-5); }
.legend .chip {
  color: #fff; font-weight: 600; font-size: var(--text-xs);
  padding: 0.3rem 0.85rem; border-radius: var(--r-pill);
}

/* ---- Category blocks (mirror the PDF sections) ---- */
.category { margin-bottom: 1.6rem; border: 1px solid var(--teal-soft); border-radius: var(--r-lg); overflow: hidden; background: #fff; }
.category > h2 {
  background: var(--teal); color: #fff; margin: 0;
  padding: 0.65rem 1rem; font-size: 1.02rem; font-weight: 600;
  display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem;
}
.category > h2 .en { opacity: 0.8; font-weight: 400; font-size: 0.8rem; }
.category-body { padding: 0.5rem 1rem 0.8rem; }

/* ---- Finding rows ---- */
.finding {
  display: grid;
  grid-template-columns: 1fr 12rem 8.5rem;
  gap: 0.6rem 1rem;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid #eef4f4;
}
.finding:last-child { border-bottom: none; }
.finding .label { font-weight: 600; line-height: 1.25; }
.finding .label .en { display: block; font-weight: 400; font-size: 0.8rem; color: var(--grey); }
.finding .label .hint { display: block; font-style: italic; font-size: 0.78rem; color: var(--grey); }

/* Device reference code — a small mono tag under the field name. Internal
   only (never printed on the patient PDF); a quick lookup during the exam. */
.label .code-tag {
  display: inline-block; margin-top: 3px;
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 0.72rem; font-weight: 500; letter-spacing: 0.02em;
  color: var(--teal); background: var(--teal-soft);
  padding: 1px 7px; border-radius: 4px; user-select: all;
}
.label .fname { display: block; }

/* Previous-visit value hint, shown under a field's name during entry. */
.label .prev-hint {
  display: inline-block; margin-top: 3px; font-size: 0.75rem; font-weight: 600;
  color: var(--teal-deep); background: #eef7f8; border: 1px solid var(--teal-soft);
  padding: 0px 6px; border-radius: 4px; font-variant-numeric: tabular-nums;
}
.prev-note { font-size: 0.82rem; color: var(--ink-soft); margin: 0.2rem 0 0.6rem; }

/* Per-field measurement history: subtle 🕒 button + popup */
.label { position: relative; }
.hist-btn {
  position: absolute; top: 50%; right: 0; transform: translateY(-50%);
  width: auto; margin: 0;
  background: none; border: none; padding: 2px 3px; cursor: pointer;
  line-height: 1; opacity: 0.5; display: inline-flex; align-items: center; gap: 2px;
}
.hist-btn:hover:not(:disabled) { opacity: 1; }
.hist-btn:disabled { opacity: 0.12; cursor: default; }
.hist-btn .hist-ic { font-size: 0.85rem; }
.hist-btn .hist-trend { font-size: 0.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hist-trend.up { color: var(--teal); }
.hist-trend.down { color: var(--orange); }
.hist-trend.eq { color: var(--grey); }
.hist-pop {
  position: absolute; z-index: 1200; background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: 0 8px 28px rgba(0,0,0,.18);
  padding: 0.5rem 0.65rem; min-width: 15rem; max-width: 22rem; max-height: 60vh;
  overflow-y: auto; font-size: 0.85rem;
}
.hist-pop-title { font-weight: 700; color: var(--teal); border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem; margin-bottom: 0.3rem; }
.hist-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.9rem; padding: 0.2rem 0; }
.hist-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.hist-arw { margin-left: 0.35rem; font-size: 0.85rem; }
.hist-arw.up { color: var(--teal); } .hist-arw.down { color: var(--orange); } .hist-arw.eq { color: var(--grey); }
.hist-when { color: var(--ink-soft); font-size: 0.78rem; white-space: nowrap; }
.hist-empty { color: var(--ink-soft); font-style: italic; }

.finding .input-cell { display: flex; align-items: center; gap: 0.4rem; }
.finding .input-cell input {
  font-size: 1.1rem; font-weight: 500; padding: 0.45rem 0.55rem; margin: 0; height: auto;
  text-align: center; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
}
.finding .input-cell input:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px rgba(22,139,150,0.15);
}
.finding .unit { color: var(--ink-soft); font-size: 0.9rem; white-space: nowrap; }

/* NO / YES / segmented buttons */
.seg { display: inline-flex; border: 1px solid var(--teal); border-radius: var(--r-sm); overflow: hidden; }
.seg button {
  margin: 0; border: none; border-radius: 0; background: #fff; color: var(--teal);
  padding: 0.4rem 0.7rem; font-size: 0.9rem; width: auto; cursor: pointer; font-weight: 500;
}
.seg button.active { background: var(--teal); color: #fff; }

/* Multiselect chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; grid-column: 2 / -1; }
.chips button {
  margin: 0; padding: 0.3rem 0.7rem; font-size: 0.85rem; width: auto; cursor: pointer;
  background: #fff; color: var(--teal); border: 1px solid var(--teal); border-radius: var(--r-pill);
}
.chips button.active { background: var(--teal); color: #fff; }

/* Live status pill */
.pill {
  justify-self: start; color: #fff; font-weight: 600; font-size: 0.8rem;
  padding: 0.32rem 0.8rem; border-radius: var(--r-pill); min-width: 4rem; text-align: center;
  visibility: hidden;
}
.pill.show { visibility: visible; }

/* ---- Actions ---- */
.form-actions { margin: 1.5rem 0 3rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; }
button.generate {
  background: var(--orange); border-color: var(--orange); color: #fff;
  font-weight: 600; width: auto; padding: 0.7rem 1.5rem;
}
button.generate:hover { background: #cf6e30; border-color: #cf6e30; }
.lang-select { display: inline-flex; align-items: center; gap: 0.5rem; }
.lang-select select { width: auto; display: inline-block; margin: 0; }
.save-msg { margin: 0; font-weight: 600; color: var(--st-ok); }
.save-msg.error { color: var(--danger); }

/* ---- Report editor / preview ---- */
.editor { margin: var(--space-4) 0 var(--space-6); padding: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.editor::before { content: ""; display: block; height: 4px; background: linear-gradient(90deg, #168b96, #3e78c9, #7b46bc); }
.editor > h3 { color: var(--teal); margin: 0; padding: var(--space-4) var(--space-5) var(--space-1); font-size: var(--text-lg); font-weight: 700; }
.editor > .muted { padding: 0 var(--space-5); font-size: var(--text-sm); }
.editor details { border: 1px solid var(--teal-soft); border-radius: var(--r-md); margin: var(--space-3) var(--space-5); padding: var(--space-1) var(--space-3); }
.editor summary { cursor: pointer; font-weight: 600; color: var(--teal); padding: var(--space-2) 0; font-size: var(--text-md); }
.rows { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0; }
/* Base row = [content, ✕] (e.g. a lifestyle recommendation). */
.edrow { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; align-items: start; }
/* Rows with a titled lead (Κύρια Ευρήματα, Σημειώσεις) = [title, text, ✕]. */
.edrow:has(.lead-in) { grid-template-columns: minmax(8rem, 1fr) 2fr auto; }
/* Device header = [name, label, ✕]. */
.edcard > .edrow { grid-template-columns: 1fr 1fr auto; }
.edrow.supp { grid-template-columns: 1fr 1fr 1fr 1.4fr 1.4fr auto; }
.edrow.prog { grid-template-columns: 1fr 1fr 1fr auto; }
.edrow input, .edrow textarea { margin: 0; font-size: var(--text-base); padding: var(--space-2) var(--space-2); }
.edrow textarea { min-height: 3.2rem; line-height: 1.4; }
.edrow .lead-in { font-weight: 600; }
/* Findings & recommendations: [ finding label + value/status ] over [ recommendation ] */
.section-hint { margin: var(--space-1) 0 var(--space-2); font-size: var(--text-sm); }
.edrow.finding-rec { display: block; border-left: 3px solid var(--teal-soft); padding-left: var(--space-3); }
.finding-rec .fr-info { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); margin-bottom: var(--space-1); }
.finding-rec .fr-label { font-weight: 600; }
.finding-rec .fr-val { font-family: var(--mono); color: var(--teal); font-size: var(--text-sm); white-space: nowrap; }
.finding-rec textarea.fr-rec { width: 100%; min-height: 2.6rem; }
/* Subtle icon button: destructive on hover (the one delete look everywhere). */
.editor .del, .icon-btn-del { background: transparent; color: var(--ink-soft); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: var(--space-1) var(--space-2); width: auto; margin: 0; cursor: pointer;
  line-height: 1; transition: color .12s, border-color .12s, background .12s; }
.editor .del:hover, .icon-btn-del:hover { color: var(--danger); border-color: #e0b4ae; background: #fdeceb; }
.addbtn { background: var(--teal-soft); color: var(--teal); border: 1px dashed var(--teal); border-radius: var(--r-sm); padding: var(--space-2) var(--space-3); width: auto; margin: var(--space-1) 0; cursor: pointer; font-weight: 600; font-size: var(--text-sm); }
.addbtn.small { font-size: var(--text-xs); padding: var(--space-1) var(--space-2); }
.edcard { border: 1px solid var(--teal-soft); border-radius: var(--r-md); padding: var(--space-2); margin-bottom: var(--space-2); }
.edcard .dev-desc { margin: 0.4rem 0; width: 100%; }
.progs { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.3rem 0; }
/* Bulk import (patient history from Excel) */
.imp-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.3rem; }
.imp-head h3 { margin: 0; color: var(--teal); }
.imp-upload { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin: 0.8rem 0; }
.imp-upload input[type=file] { margin: 0; flex: 1 1 16rem; }
.imp-upload button { width: auto; margin: 0; flex: 0 0 auto; }
.imp-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem 1.2rem; margin-bottom: 1rem; }
.imp-card > header { margin-bottom: 0.5rem; }
.imp-req { color: var(--danger); }
.imp-hint { font-size: 0.82rem; margin: 0.2rem 0 0.6rem; }
.imp-bad-inline { color: var(--danger); font-weight: 600; }
.imp-visit { display: flex; align-items: center; gap: 0.8rem; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.imp-visit input[type=date] { margin: 0; width: auto; }
.imp-visit.bad { background: #fdeceb; border-radius: var(--r-sm); }
.imp-visit.bad input[type=date] { border-color: var(--danger); }
.imp-visit-info { font-size: 0.9rem; }
.imp-warnings { margin: 0; padding-left: 1.2rem; font-size: 0.88rem; }
.imp-warnings li { margin: 0.15rem 0; }
.imp-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-top: 0.8rem; }
.imp-actions button { width: auto; margin: 0; }
.imp-report { margin: 0.4rem 0 0.8rem; padding-left: 1.2rem; }
.imp-report li { margin: 0.2rem 0; }

/* View titles — one prominent teal heading per full-page view. */
#admin-view > h3, .manage-body > h3, .imp-head h3 {
  color: var(--teal); font-size: var(--text-xl); font-weight: 700;
  letter-spacing: -0.01em; margin: 0;
}

/* Admin area */
#admin-view article { margin-bottom: var(--space-4); }
.admin-user-row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--teal-soft); flex-wrap: wrap; }
.admin-user-row.inactive { opacity: 0.55; }
.au-acts { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.au-acts .link { font-size: var(--text-sm); }
.au-acts select { margin: 0; padding: var(--space-1) var(--space-2); font-size: var(--text-sm); width: auto; }
.au-last { font-size: var(--text-xs); color: var(--ink-soft); }
.admin-newuser { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; margin-top: var(--space-2); }
.admin-newuser input, .admin-newuser select { margin: 0; width: auto; flex: 1 1 8rem; }
.admin-newuser button { width: auto; margin: 0; }
.admin-temppw { background: var(--teal-soft); padding: var(--space-2) var(--space-3); border-radius: var(--r-sm); margin-top: var(--space-2); }
.admin-temppw code { background: #fff; padding: 0.1rem 0.4rem; border-radius: var(--r-sm); font-weight: 700; }
.admin-backup-list, .admin-log { margin-top: var(--space-2); max-height: 240px; overflow-y: auto; font-size: var(--text-sm); }
.admin-backup-item, .admin-log-row { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--teal-soft); }
.admin-log-row .ev { display: inline-block; min-width: 6.5rem; font-weight: 600; font-size: var(--text-xs); }
.ev-failed, .ev-locked { color: var(--danger); }
.ev-login { color: var(--teal); }
#admin-backup-now { width: auto; margin: 0.3rem 0; }

/* Report version history & undo (Feature C) */
.versions-panel #undo-version-btn { width: auto; margin: 0.2rem 0 0.6rem; }
.versions-list { display: flex; flex-direction: column; gap: 0.3rem; }
.version-row { display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-2) var(--space-3); background: var(--teal-wash);
  border: 1px solid var(--teal-soft); border-radius: var(--r-sm); font-size: var(--text-sm); }
.version-row button.link { flex: 0 0 auto; }
.version-row button.link:disabled { opacity: 0.5; cursor: default; text-decoration: none; }

.editor-actions { margin: var(--space-4) var(--space-5) var(--space-5); display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.editor-actions button { width: auto; margin: 0; }
#finalize-result { display: flex; flex-wrap: wrap; gap: var(--space-3); width: 100%; }

/* ---- Patient history ---- */
.history { margin: 0.4rem 0 1rem; font-size: 0.9rem; }
.history .hist { background: var(--teal-soft); color: var(--teal); border: 1px solid var(--teal); border-radius: var(--r-pill); padding: 0.25rem 0.7rem; margin: 0 0.3rem 0.3rem 0; cursor: pointer; width: auto; font-size: 0.85rem; }
.history .hist:hover { background: var(--teal); color: #fff; }

/* ---- Workbook tabs (Excel-style, bottom) ---- */
.tab-bar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 2px;
  background: var(--teal-wash); border-top: 2px solid var(--teal);
  /* right room so the floating save bar never sits over a tab button */
  padding: 6px 12rem 6px 0; margin-top: 1rem; z-index: 5;
}
@media (max-width: 520px) { .tab-bar { padding-right: 6.5rem; } }
.tabbtn {
  background: var(--teal-soft); color: var(--teal); border: 1px solid var(--teal-soft);
  border-radius: var(--r-sm) var(--r-sm) 0 0; padding: 0.42rem 0.75rem; width: auto; margin: 0;
  cursor: pointer; font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.tabbtn:hover { background: #d4ecee; }
.tabbtn.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.tabbtn.summary-tab { background: var(--orange); color: #fff; border-color: var(--orange); margin-left: auto; }

.tab-header { color: var(--teal); border-bottom: 2px solid var(--teal-soft); padding-bottom: 3px; margin: 1.2rem 0 0.5rem; font-size: 1rem; font-weight: 600; }
.tab-fields { min-height: 45vh; }
.txt-field { display: flex; flex-direction: column; gap: 0.2rem; margin: 0.5rem 0; }
.txt-field .label { font-size: 1rem; font-weight: 600; }
.txt-field input { font-size: 1.05rem; padding: 0.5rem 0.6rem; margin: 0; }
.food-field { display: grid; grid-template-columns: 1fr auto; gap: 0.6rem; align-items: center; padding: 0.35rem 0; border-bottom: 1px solid #eef4f4; }
.food-field .label { font-size: 0.95rem; }
.food-seg button { font-size: 0.85rem; padding: 0.35rem 0.7rem; }

/* ---- Summary tab ---- */
.ai-summary { border: 1px solid var(--teal-soft); background: var(--teal-wash);
  border-radius: var(--r-md); padding: var(--space-4); margin-bottom: var(--space-5); }
.ai-summary-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.ai-summary-head strong { color: var(--teal); font-size: var(--text-md); }
.ai-summary-text { white-space: pre-wrap; line-height: 1.5; font-size: var(--text-base); }
.ai-summary-text.error { color: var(--danger); }
.sum-heading { margin: 0 0 var(--space-1); font-size: var(--text-sm); color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.sum-prevnote { font-size: var(--text-xs); margin: 0 0 var(--space-4); color: var(--ink-soft); }
.summary .sum-tab { margin-bottom: var(--space-5); }
.summary .sum-tab h3 { color: var(--teal); border-bottom: 2px solid var(--teal-soft);
  padding-bottom: var(--space-1); margin-bottom: var(--space-2);
  font-size: var(--text-lg); font-weight: 600; }
.sum-header { background: var(--teal-soft); color: var(--teal); font-weight: 700; text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.04em; padding: 3px 8px; border-radius: 3px; margin: 0.4rem 0 0.2rem; }
.sum-row { display: grid; grid-template-columns: 1fr auto; gap: 1rem; padding: 0.28rem 0.4rem; border-bottom: 1px solid #eef4f4; font-size: 0.9rem; }
.sum-row .sum-val { font-weight: 600; color: var(--teal); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sum-row.blank { background: var(--teal-wash); }
.sum-row.blank .sum-val { color: #8a6d0b; }
.sum-counts { text-transform: none; letter-spacing: 0; font-weight: 400; }

/* Σύνοψη clinical overview table */
.sum-table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
.sum-table thead th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--ink-soft); font-weight: 600; padding: var(--space-2) var(--space-2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: #fff; }
.sum-table th:nth-child(2), .sum-table th:nth-child(3), .sum-table td.s-val, .sum-table td.s-prev { white-space: nowrap; }
.sum-table td { padding: var(--space-2); border-bottom: 1px solid var(--teal-soft); vertical-align: baseline; }
.sum-table .s-lab { width: 55%; }
.sum-table .s-val { font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--teal); }
.sum-table .s-val.flag { font-weight: 800; }
.sum-table tr.sum-empty .s-val, .sum-table .s-prev.muted { color: var(--grey); font-weight: 400; }
.sum-table tr.sum-empty { background: #fcfcfa; }
.sum-table .s-prev { color: var(--ink-soft); font-family: var(--mono); }
.sum-table .s-arw.up { color: var(--teal); font-weight: 700; }
.sum-table .s-arw.down { color: var(--orange); font-weight: 700; }
.sum-table .s-arw.eq { color: var(--grey); }
.sum-table tr.sum-subhead td { background: var(--teal-soft); color: var(--teal); font-weight: 700;
  text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.03em; padding: 0.3rem 0.5rem; }
.s-pill { display: inline-block; color: #fff; font-weight: 700; font-size: 0.72rem;
  padding: 1px 8px; border-radius: var(--r-pill); white-space: nowrap; }

/* Consistent floating save bar */
/* Reserve space at the bottom so the floating bar never covers page controls
   (e.g. the measurement tab bar / report buttons). */
main.container { padding-bottom: 5.5rem; }
.save-bar { position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 1100;
  display: flex; align-items: center; gap: 0.7rem; background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  box-shadow: 0 6px 22px rgba(0,0,0,.16); padding: 0.45rem 0.55rem 0.45rem 1rem; }
.save-bar .save-state { font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.save-bar .save-state.dirty { color: var(--orange); }
.save-bar .save-state.ok { color: var(--teal); }
.save-bar .save-state.err { color: var(--danger); }
.save-bar .save-btn { width: auto; margin: 0; padding: 0.45rem 1.1rem; border-radius: var(--r-pill);
  font-weight: 700; background: var(--teal); color: #fff; border: none; cursor: pointer; }
.save-bar .save-btn:hover { background: var(--teal-deep); }
.save-bar .save-btn:disabled { opacity: 0.6; cursor: default; }
@media (max-width: 520px) { .save-bar { right: 0.6rem; bottom: 0.6rem; } .save-bar .save-state { display: none; } }

/* ---- Patient view ---- */
#patient-view > article > header strong { font-size: var(--text-lg); font-weight: 600; }
.patient-results { margin-top: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.patient-item {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  width: 100%; text-align: left; margin: 0; padding: var(--space-3) var(--space-4);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  color: inherit; cursor: pointer; transition: border-color .12s, background .12s;
}
.patient-item:hover { background: var(--teal-wash); border-color: var(--teal); }
.patient-item strong { font-size: var(--text-md); }
.patient-item .code {
  flex: 0 0 auto;
  background: var(--teal-soft); color: var(--teal); font-weight: 600;
  padding: var(--space-1) var(--space-3); border-radius: var(--r-pill);
  font-size: var(--text-xs); letter-spacing: 0.02em;
}
.np-error { color: var(--danger); font-size: var(--text-sm); font-weight: 600;
  background: #fdeceb; border: 1px solid #f1c7c1; border-radius: var(--r-md);
  padding: var(--space-3) var(--space-4); margin: var(--space-3) 0; }
.patient-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.patient-actions button { width: auto; margin: 0; }

/* Solid-teal primary action (the main affirmative action of a screen).
   Orange (.generate) stays reserved for the AI / finalize milestones. */
button.primary { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--teal-deep); border-color: var(--teal-deep); }

/* Show-archived toggle: a calm inline control, no stray rule. */
.show-archived { display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--ink-soft); margin: var(--space-2) 0 var(--space-3); }
.show-archived input { flex: 0 0 auto; width: 1.1rem; height: 1.1rem; margin: 0; }
.im-summary {
  background: var(--teal-wash); border: 1px solid var(--teal-soft); border-radius: var(--r-sm);
  padding: 0.6rem 0.9rem; margin: 0.6rem 0; font-size: 0.9rem;
}
.im-dobnote { color: #8a6d0b; margin-top: 0.3rem; font-size: 0.85rem; }

.patient-banner {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3) var(--space-4); flex-wrap: wrap;
  background: var(--teal-soft); border-left: 4px solid var(--teal);
  padding: var(--space-3) var(--space-4); border-radius: var(--r-md); margin-bottom: var(--space-4);
}
.patient-banner > div:first-child { flex: 1 1 16rem; }
.patient-banner strong { font-size: var(--text-md); }
button.link {
  background: none; border: none; color: var(--teal); width: auto;
  padding: 0.2rem 0.4rem; margin: 0; font-weight: 600; cursor: pointer;
}

/* ---- Previous-visits viewer (modal) ---- */
.banner-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.modal {
  position: fixed; inset: 0; background: rgba(20, 40, 45, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 3vh 1rem; z-index: 1000; overflow-y: auto;
}
.modal-box {
  background: #fff; border-radius: var(--r-lg); width: 100%; max-width: 46rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25); padding: var(--space-5) var(--space-5) var(--space-5); overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-3); margin-bottom: var(--space-4); }
.modal-head strong { font-size: var(--text-lg); font-weight: 600; color: var(--teal); }
.hm-sessions { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1rem; }
.hm-row {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  flex-wrap: wrap; padding: 0.5rem 0.7rem; background: var(--teal-wash);
  border: 1px solid var(--teal-soft); border-radius: var(--r-sm);
}
.hm-btns { display: flex; gap: 0.4rem; }
.hm-title { font-weight: 700; color: var(--teal); margin: 0.4rem 0 0.6rem; }
.hm-content { max-height: 55vh; overflow-y: auto; }

/* ---- Email screen (send report to patient) ---- */
/* The recipient banner deliberately repeats who the report is going to — the
   send-safety rule. It stays the most prominent thing in the dialog. */
.em-recipient {
  display: flex; flex-direction: column; gap: 2px; padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4);
  background: var(--teal-soft); border: 2px solid var(--teal); border-radius: var(--r-md);
}
.em-recipient .em-to { font-size: var(--text-xs); color: var(--teal-deep); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.em-recipient .em-name { font-size: var(--text-lg); font-weight: 600; color: var(--ink); }
.em-recipient .em-email { font-size: var(--text-md); font-weight: 600; color: var(--teal-deep); word-break: break-all; font-family: var(--mono); }
.em-attach {
  background: var(--teal-wash); border: 1px dashed var(--teal-soft); border-radius: var(--r-sm);
  padding: var(--space-2) var(--space-3); margin: var(--space-2) 0 var(--space-3); font-size: var(--text-sm);
}
.em-actions { display: flex; gap: var(--space-3); margin-top: var(--space-3); }
.em-actions button { width: auto; margin: 0; }
.em-save-addr {
  background: #fff6e0; border: 1px solid #f0d98a; color: #8a6d0b; border-radius: var(--r-md);
  padding: var(--space-2) var(--space-3); margin: var(--space-2) 0; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: var(--text-sm);
}
#email-hint { font-size: var(--text-sm); margin-top: var(--space-2); }

/* history rows with email actions */
.hist-row2 {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  border: 1px solid var(--teal-soft); border-radius: var(--r-sm); padding: 0.35rem 0.5rem;
}
.hist-main {
  display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 10rem;
  text-align: left; margin: 0; padding: 0.3rem 0.4rem; background: transparent; border: none;
  color: inherit; cursor: pointer; border-radius: var(--r-sm);
}
.hist-main:hover { background: var(--teal-soft); }
.hist-email { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; font-size: 0.82rem; }
.hist-email .sent-ok { color: #1c7a4a; }
.hist-email .sent-fail { color: var(--danger); }

/* ---- Auto-save indicator ---- */
.header-status { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.user-chip { font-size: 0.82rem; color: var(--ink-soft); display: flex; gap: 0.5rem; align-items: center; }
.user-chip #user-name { font-weight: 600; color: var(--teal); }
.user-chip a { color: var(--danger); text-decoration: none; }
.user-chip a:hover { text-decoration: underline; }

/* Forced password-change overlay (first login) */
.pw-overlay { position: fixed; inset: 0; background: rgba(20,40,45,.55); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 1rem; }
.pw-box { background: #fff; border-radius: var(--r-lg); padding: 1.6rem; max-width: 24rem; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.pw-box h2 { color: var(--teal); margin: 0 0 0.4rem; font-size: 1.15rem; }
.pw-box label { display: block; font-size: 0.85rem; margin-top: 0.6rem; }
.pw-box input { width: 100%; margin: 0.2rem 0 0; }
.pw-box button { margin-top: 1rem; width: 100%; }
.autosave { font-size: 0.8rem; font-weight: 600; }
.autosave.saving { color: var(--ink-soft); }
.autosave.saved { color: #1c7a4a; }
.autosave.error { color: var(--danger); }

/* ---- Manage measurement fields (global editor) ---- */
/* ---- App management (left menu) ---- */
.manage-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
@media (min-width: 760px) { .manage-layout { grid-template-columns: 15rem 1fr; } }
.manage-menu { display: flex; flex-direction: column; gap: 0.4rem; padding: 0.8rem;
  background: var(--teal-soft); border: 1px solid var(--line); border-radius: var(--r-lg); }
.manage-title { color: var(--teal); margin-bottom: 0.2rem; }
.manage-item { width: 100%; margin: 0; text-align: left; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.6rem 0.8rem; cursor: pointer; font-weight: 600; }
.manage-item:hover { border-color: var(--teal); color: var(--teal); }
.manage-body h3 { color: var(--teal); margin-top: 0; }
.manage-help { margin: 0.6rem 0 0; padding-left: 1.1rem; color: var(--ink-soft); font-size: 0.9rem; }
.manage-help li { margin: 0.3rem 0; }

/* ---- Section (tab) management in the fields editor ---- */
.fe-addtab { background: var(--teal-soft); color: var(--teal); border-style: dashed; }
.fe-tab-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin-top: 0.5rem; padding: 0.5rem 0.6rem; background: #fafcfc; border: 1px solid var(--line); border-radius: var(--r-sm); }
.fe-tabname-lbl { font-weight: 600; color: var(--ink-soft); font-size: 0.85rem; }
.fe-tabname { flex: 1 1 12rem; min-width: 9rem; margin: 0; padding: 0.3rem 0.5rem; height: auto; font-size: 0.9rem; }
.fe-tab-actions .mini { flex: 0 0 auto; }
.fe-del-tab { background: #fff; color: var(--danger); border-color: #e0b4ae; }

.fe-list { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.6rem; }
.fe-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--teal-soft); border-radius: var(--r-sm);
  padding: 0.4rem 0.5rem;
}
.fe-row.fe-header-row { background: var(--teal-soft); font-weight: 700; }
.fe-moves { display: flex; flex-direction: column; gap: 1px; }
.fe-moves button {
  width: auto; margin: 0; padding: 0 0.4rem; line-height: 1.2; font-size: 0.8rem;
  background: var(--teal-wash); border: 1px solid var(--teal-soft); color: var(--teal); cursor: pointer;
}
.fe-moves button:disabled { opacity: 0.35; cursor: default; }
.fe-type {
  flex: 0 0 auto; width: auto; min-width: 6.5rem; margin: 0; padding: 0.25rem 0.4rem;
  font-size: 0.8rem; font-weight: 600; color: var(--teal-deep); height: auto;
}
.fe-label { flex: 1; min-width: 12rem; margin: 0; }
.fe-range-inner { display: inline-flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.fe-scale { width: auto; margin: 0; min-width: 8rem; }
.fe-custom { display: inline-flex; gap: 0.25rem; }
.fe-custom input { width: 4.5rem; margin: 0; }
.fe-custom .fe-un { width: 5rem; }
.fe-del {
  width: auto; margin: 0; padding: 0.25rem 0.55rem; background: #fff; color: var(--danger);
  border: 1px solid #e0b4ae; border-radius: var(--r-sm); cursor: pointer;
}
.fe-actions { display: flex; align-items: center; gap: 0.6rem; margin: 1rem 0 3rem; flex-wrap: wrap; }
.fe-actions button { width: auto; margin: 0; }

/* ---- Report language choice (finalize stage) ---- */
.report-lang-choice {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; width: 100%;
  margin-bottom: var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid var(--teal-soft);
}
.rlc-label { font-weight: 600; color: var(--ink-soft); font-size: var(--text-sm); }
.lang-seg button { min-width: 6rem; }

/* ---- Edit-lock warning ---- */
.lock-warning {
  background: #fff3cd; color: #8a6d0b; border: 1px solid #f0d98a;
  border-radius: var(--r-sm); padding: 0.6rem 0.9rem; margin: 0.9rem 1.2rem 0;
  font-size: 0.9rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
}

/* ---- Top nav ---- */
.main-nav { display: flex; justify-content: flex-start; flex-wrap: wrap;
  gap: var(--space-2); margin-bottom: var(--space-4); }
.navbtn {
  width: auto; margin: 0; background: #fff; color: var(--teal);
  border: 1px solid var(--teal-soft); border-radius: var(--r-sm);
  padding: 0.4rem 0.9rem; font-weight: 600; cursor: pointer;
}
.navbtn.active { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ---- Appointments ---- */
.appt-toolbar {
  display: flex; flex-wrap: wrap; gap: 0.6rem 1rem; align-items: center;
  justify-content: space-between; margin-bottom: 1rem;
}
.appt-range { display: flex; align-items: center; gap: 0.5rem; }
.appt-range button { width: auto; margin: 0; }
.appt-range #appt-title { min-width: 12rem; text-align: center; }
.appt-mode { display: flex; gap: 0.3rem; }
#new-appt-btn { width: auto; margin: 0; }
#new-appt-form {
  background: #fff; border: 1px solid var(--teal-soft); border-radius: var(--r-md);
  padding: 1rem; margin-bottom: 1rem;
}
.appt-pat-mode { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.appt-pat-mode .navbtn { flex: 1; }
.appt-patient-results { display: flex; flex-direction: column; gap: 0.25rem; margin: 0.3rem 0; }
.appt-pat-opt {
  width: 100%; text-align: left; margin: 0; background: var(--teal-wash);
  border: 1px solid var(--teal-soft); border-radius: var(--r-sm); padding: 0.4rem 0.7rem;
  cursor: pointer; color: inherit;
}
.appt-pat-opt:hover { background: var(--teal-soft); }
.chosen { font-weight: 600; color: var(--teal); margin: 0.3rem 0; }
.appt-list { display: flex; flex-direction: column; gap: var(--space-2); }
.next-appt {
  background: var(--teal-wash); border: 1px dashed var(--teal-soft); border-radius: var(--r-sm);
  padding: 0.6rem 0.9rem; margin-top: 0.6rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.appt-row {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--space-3) var(--space-4);
}
.appt-time {
  font-weight: 700; color: var(--teal); background: var(--teal-soft);
  padding: var(--space-1) var(--space-3); border-radius: var(--r-sm);
  font-family: var(--mono); font-variant-numeric: tabular-nums;
}
.appt-day-h { margin: var(--space-3) 0 var(--space-1); color: var(--teal); font-size: var(--text-md); font-weight: 600; }
.appt-pat { flex: 1; min-width: 8rem; }
.appt-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.appt-actions .join-btn { background: var(--online); color: #fff; border-color: var(--online); }

/* Reminders modal */
.rm-controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; margin-bottom: 0.3rem; }
.rm-controls label { margin: 0; }
.rm-list { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.6rem 0; max-height: 50vh; overflow-y: auto; }
.rm-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.5rem; border: 1px solid var(--line); border-radius: var(--r-sm); }
.rm-info { flex: 1 1 auto; font-size: 0.9rem; }
.rm-email { font-size: 0.82rem; }
.rm-row .mini { flex: 0 0 auto; }
.rm-status { flex: 0 0 auto; font-size: 0.82rem; min-width: 5rem; text-align: right; }
.rm-status.ok { color: var(--ok, #2cb673); }
.rm-status.err { color: var(--danger); }
.rm-actions { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.4rem; }
.rm-actions .generate { width: auto; margin: 0; }

/* appointment type/category tags */
.tag {
  display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 0.05rem 0.5rem;
  border-radius: var(--r-pill); vertical-align: middle;
}
.tag-inperson { background: #e4f3f4; color: var(--teal-deep); }
.tag-online { background: var(--online-soft); color: var(--online); }
.tag-cat { background: #fdeecf; color: #8a6d0b; }

/* ---- Month calendar ---- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.cal-h { background: var(--teal-soft); color: var(--teal-deep); font-weight: 700; text-align: center; padding: 0.4rem 0; font-size: 0.85rem; }
.cal-cell { background: #fff; min-height: 5.5rem; padding: 0.3rem; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.cal-cell:hover { background: var(--teal-wash); }
.cal-cell.other { background: #f7fafb; }
.cal-cell.other .cal-num { color: #b7c5c8; }
.cal-cell.today { outline: 2px solid var(--teal); outline-offset: -2px; }
.cal-num { font-weight: 700; font-size: 0.85rem; color: var(--ink-soft); }
.cal-cell.today .cal-num { color: var(--teal); }
.cal-appt { font-size: 0.72rem; background: var(--teal-soft); color: var(--teal-deep); border-radius: 4px; padding: 1px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-appt.online { background: var(--online-soft); color: var(--online); }
.cal-more { font-size: 0.7rem; color: var(--ink-soft); }

@media (max-width: 720px) {
  .cal-cell { min-height: 3.5rem; }
  .cal-appt { display: none; }
  .cal-cell:not(.other) .cal-num::after { content: ""; }
}
.mini {
  width: auto; margin: 0; padding: 0.3rem 0.7rem; font-size: var(--text-sm); font-weight: 600;
  background: var(--teal-soft); color: var(--teal); border: 1px solid var(--teal);
  border-radius: var(--r-sm); cursor: pointer; white-space: nowrap;
}
.mini.danger { background: #fff; color: var(--danger); border-color: #e0b4ae; }
.fld-toggle.on { background: var(--teal); color: #fff; }

/* ---- Per-patient field editing (during the exam) ---- */
.tab-fields.editing .fld-edit { border: 1px dashed #cdd8d8; border-radius: var(--r-sm);
  padding: 0.4rem 0.6rem 0.6rem; margin-bottom: 0.6rem; background: #fafcfc; }
.fld-edit-bar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.fld-rename { flex: 1 1 12rem; min-width: 9rem; margin: 0; padding: 0.25rem 0.5rem;
  font-size: 0.85rem; height: auto; }
.fld-hdr-name { flex: 1 1 auto; font-weight: 700; }
.fld-hide { width: auto; margin: 0; padding: 0.25rem 0.6rem; font-size: 0.78rem; font-weight: 600;
  background: #fff; color: var(--danger); border: 1px solid #e0b4ae; border-radius: var(--r-sm); cursor: pointer; }
.fld-add { display: flex; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap;
  border: 1px solid var(--teal); border-radius: var(--r-sm); padding: 0.7rem; background: var(--teal-soft); margin-top: 0.4rem; }
.fld-add input, .fld-add select { margin: 0; padding: 0.3rem 0.5rem; font-size: 0.85rem; height: auto; }
.fld-add-title { flex: 1 1 12rem; min-width: 9rem; }
.fld-add-type { flex: 0 0 auto; width: auto; min-width: 8rem; }
.fld-add-range { flex: 1 1 auto; display: inline-flex; align-items: center; }
.fld-add-range[hidden] { display: none; }
.fld-add-mn, .fld-add-mx { flex: 0 0 5rem; width: 5rem; }
.fld-add-un { flex: 0 0 8rem; width: 8rem; }
.fld-add-btn { width: auto; margin: 0; padding: 0.3rem 0.8rem; font-size: 0.85rem; }
.fld-add-err { flex-basis: 100%; color: var(--danger); font-size: 0.82rem; }
.fld-add-hint { flex-basis: 100%; margin: 0.2rem 0 0; font-size: 0.78rem; }

/* ---- Email templates editor ---- */
.et-pick { display: flex; gap: 0.8rem; align-items: end; flex-wrap: wrap; }
.et-pick label { flex: 1 1 16rem; margin: 0; }
.et-pick #et-new { flex: 0 0 auto; width: auto; margin: 0; }
#emails-view textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9rem; }
.et-ph { margin: 0.4rem 0 0.8rem; font-size: 0.85rem; color: var(--ink-soft); }
.et-ph-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.et-chip { width: auto; margin: 0; padding: 0.2rem 0.55rem; font-size: 0.8rem;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; cursor: pointer;
  background: var(--teal-soft); color: var(--teal); border: 1px solid var(--teal); border-radius: var(--r-sm); }

/* ---- Patient list extras ---- */
.patient-item .visit { display: block; font-size: var(--text-sm); margin-top: 2px; }

/* ---- Update banner ---- */
.update-banner { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  background: #fff6e0; border: 1px solid #e6c65a; color: #6b5411;
  border-radius: var(--r-sm); padding: 0.5rem 0.9rem; margin: 0 0 0.8rem; font-size: 0.9rem; }
.update-banner .update-btn { width: auto; margin: 0; padding: 0.3rem 0.9rem; font-size: 0.85rem;
  font-weight: 600; background: var(--teal); color: #fff; border: 1px solid var(--teal);
  border-radius: var(--r-sm); cursor: pointer; }
.update-banner .update-btn:disabled { opacity: 0.6; cursor: default; }

/* ---- Birth-date picker (Day / Month / Year dropdowns) ---- */
/* Each dropdown keeps a minimum width so the month name is never clipped; in a
   narrow column they wrap onto the next line instead of squishing. */
.dob-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.15rem; }
.dob-picker select { margin: 0; padding: 0.4rem 0.4rem; }
.dob-picker .dob-d { flex: 1 1 3.5rem; min-width: 3.5rem; }
.dob-picker .dob-m { flex: 2 1 7.5rem; min-width: 7rem; }
.dob-picker .dob-y { flex: 1 1 4.5rem; min-width: 4.5rem; }

/* ---- Patient card ---- */
.card-cols { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
@media (min-width: 900px) { .card-cols { grid-template-columns: 1fr 1fr; } }
/* ---- AI assistant view (saved conversations) ---- */
.asst-layout { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
@media (min-width: 820px) { .asst-layout { grid-template-columns: 17rem 1fr; } }
.asst-list { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0.6rem; background: #fff; }
.asst-list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.asst-conversations { display: flex; flex-direction: column; gap: 0.3rem; max-height: 60vh; overflow-y: auto; }
.asst-conv { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; text-align: left;
  width: 100%; margin: 0; padding: 0.45rem 0.6rem; background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-sm); cursor: pointer; }
.asst-conv:hover { border-color: var(--teal); }
.asst-conv.active { background: var(--teal-soft); border-color: var(--teal); }
.asst-conv-title { font-weight: 600; font-size: 0.9rem; }
.asst-conv-sub { font-size: 0.75rem; }
.asst-empty { padding: 0.4rem; }
.asst-main { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0.8rem; background: #fff; }
.asst-meta { margin: 0 0 0.5rem; font-weight: 600; color: var(--teal); }
.asst-log { display: flex; flex-direction: column; gap: 0.5rem; min-height: 40vh; max-height: 62vh; overflow-y: auto; margin-bottom: 0.6rem; }
.asst-msg { padding: 0.5rem 0.75rem; border-radius: var(--r-sm); font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; }
.asst-msg.user { align-self: flex-end; background: var(--teal); color: #fff; max-width: 85%; }
.asst-msg.bot { align-self: flex-start; background: var(--teal-soft); color: var(--ink); max-width: 95%; }
.asst-msg.pending { opacity: 0.7; font-style: italic; }
.asst-msg.error { background: #fdeceb; color: var(--danger); }
.asst-msg .md-h { font-weight: 700; color: var(--teal); margin: 0.5rem 0 0.15rem; }
.asst-msg .md-h:first-child { margin-top: 0; }
.asst-msg ul { margin: 0.15rem 0 0.35rem; padding-left: 1.1rem; }
.asst-msg li { margin: 0.1rem 0; }
.asst-input { display: flex; gap: 0.4rem; }
.asst-input input { margin: 0; }
.asst-input .mini { flex: 0 0 auto; }
.asst-note { margin: 0.5rem 0 0; font-size: 0.75rem; }

.ai-report-card { display: flex; flex-direction: column; }
.ai-report-card header { display: flex; align-items: center; gap: 0.4rem; }
.air-meta { margin: 0.2rem 0 0.6rem; font-size: 0.85rem; }
.air-log { display: flex; flex-direction: column; gap: 0.5rem; max-height: 320px; overflow-y: auto;
  padding: 0.2rem; margin-bottom: 0.6rem; }
.air-msg { padding: 0.5rem 0.7rem; border-radius: var(--r-sm); font-size: 0.9rem; line-height: 1.45; white-space: pre-wrap; }
.air-msg.user { align-self: flex-end; background: var(--teal); color: #fff; max-width: 85%; }
.air-msg.bot { align-self: flex-start; background: var(--teal-soft); color: var(--ink); max-width: 95%; }
.air-msg.pending { opacity: 0.7; font-style: italic; }
.air-msg.error { background: #fdeceb; color: var(--danger); }
/* structured AI answers (headings / bullets) */
.air-msg .md-h { font-weight: 700; color: var(--teal); margin: 0.5rem 0 0.15rem; }
.air-msg .md-h:first-child { margin-top: 0; }
.air-msg ul { margin: 0.15rem 0 0.35rem; padding-left: 1.1rem; }
.air-msg li { margin: 0.1rem 0; }
.air-msg > div + div { margin-top: 0.2rem; }
.air-actions { margin-bottom: 0.5rem; }
.air-chat { display: flex; gap: 0.4rem; }
.air-chat input { margin: 0; }
.air-chat .mini { flex: 0 0 auto; }
.air-note { margin: 0.5rem 0 0; font-size: 0.75rem; }

/* Patient file attachments (Feature B) */
.files-note { margin: 0 0 0.6rem; font-size: 0.8rem; }
.attach-form { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.6rem; }
.attach-form input[type=file] { margin: 0; flex: 1 1 200px; font-size: 0.85rem; }
.attach-form input[type=text] { margin: 0; flex: 1 1 160px; }
.attach-form button { width: auto; margin: 0; flex: 0 0 auto; }
.attach-list { display: flex; flex-direction: column; gap: 0.35rem; }
.attach-row { display: flex; align-items: baseline; gap: 0.3rem; flex-wrap: wrap;
  padding: 0.4rem 0.55rem; background: var(--teal-soft); border-radius: var(--r-sm); }
.attach-name { font-weight: 600; word-break: break-word; }
.attach-meta { font-size: 0.8rem; }
.attach-del { margin-left: auto; font-size: 0.8rem; color: var(--danger); flex: 0 0 auto; }

.card-actions { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-actions button { width: auto; margin: 0; }
.archived-tag {
  background: #fff3cd; color: #8a6d0b; font-weight: 600; font-size: 0.75rem;
  padding: 0.1rem 0.5rem; border-radius: var(--r-pill);
}
/* One card treatment for all four patient-card cards. */
.details-card, .history-card, .ai-report-card, .files-card { margin-bottom: var(--space-4); }
.details-card > header, .history-card > header,
.ai-report-card > header, .files-card > header {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
}
.details-card > header strong, .history-card > header strong,
.ai-report-card > header strong, .files-card > header strong {
  font-size: var(--text-lg); font-weight: 600;
}
.details-list { margin: 0; }
.details-list .drow {
  display: grid; grid-template-columns: 11rem 1fr; gap: var(--space-2);
  padding: var(--space-2) 0; border-bottom: 1px solid var(--teal-soft);
}
.details-list .drow:last-child { border-bottom: none; }
.details-list dt { color: var(--ink-soft); font-weight: 600; }
.details-list dd { margin: 0; white-space: pre-wrap; }
.rename-hint { font-size: 0.82rem; color: #8a6d0b; }
.card-history { display: flex; flex-direction: column; gap: 0.4rem; }
.hist-row {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; text-align: left; margin: 0; padding: 0.55rem 0.85rem;
  background: #fff; border: 1px solid var(--teal-soft); border-radius: var(--r-sm);
  color: inherit; cursor: pointer;
}
.hist-row:hover { background: var(--teal-soft); }
.hist-status {
  font-size: 0.78rem; font-weight: 600; padding: 0.12rem 0.6rem; border-radius: var(--r-pill);
}
.hist-status.final { background: #d9f0e3; color: #1c7a4a; }
.hist-status.draft { background: #fdeecf; color: #8a6d0b; }

@media (max-width: 720px) {
  .finding { grid-template-columns: 1fr; }
  .pill { justify-self: start; }
  .details-list .drow { grid-template-columns: 1fr; gap: 0.1rem; }
}

/* ---- Login page (server-rendered; shares the app tokens, no Pico) ---- */
.login-wrap { min-height: calc(100vh - 4px); display: flex; align-items: center; justify-content: center;
  padding: var(--space-5); box-sizing: border-box; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--space-6); max-width: 24rem; width: 100%; box-shadow: 0 6px 28px rgba(22,139,150,.10);
  text-align: center; }
.login-logo { width: 76px; height: 76px; object-fit: contain; display: block; margin: 0 auto var(--space-3); }
.login-card h1 { font-size: var(--text-lg); color: var(--teal); margin: 0 0 var(--space-1); font-weight: 700; letter-spacing: -0.01em; }
.login-sub { color: var(--ink-soft); margin: 0 0 var(--space-4); font-size: var(--text-sm); }
.login-label { display: block; text-align: left; font-size: var(--text-sm); color: var(--ink-soft);
  margin: 0 0 var(--space-3); font-weight: 600; }
.login-label input { width: 100%; margin-top: var(--space-1); padding: 0.6rem 0.7rem; font-size: var(--text-md);
  border: 1px solid var(--line); border-radius: var(--r-sm); box-sizing: border-box;
  font-family: var(--sans); color: var(--ink); background: #fff; }
.login-label input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(22,139,150,.15); }
.login-submit { width: 100%; margin-top: var(--space-2); padding: 0.65rem; font-size: var(--text-md);
  font-weight: 600; border-radius: var(--r-sm); cursor: pointer; border: 1px solid var(--teal);
  background: var(--teal); color: #fff; font-family: var(--sans); }
.login-submit:hover { background: var(--teal-deep); border-color: var(--teal-deep); }
.login-card .alert { text-align: left; margin: 0 0 var(--space-3); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
