/* ═══════════════════════════════════════════════════════════════
   Expediente — layout por vistas (no sidebar apretado)
   Patrón: Lista → Ficha → Documento (progressive disclosure)
   ═══════════════════════════════════════════════════════════════ */
:root {
  /* Light theme (default) */
  --bg: #f4f7f6;
  --bg-elev: #ffffff;
  --bg-soft: #e8f0ee;
  --ink: #0f1f1c;
  --ink-2: #3d524e;
  --muted: #6b7f7a;
  --line: #d5e2de;
  --teal: #0f766e;
  --teal-2: #0d9488;
  --teal-soft: #ccfbf1;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --rose: #be123c;
  --rose-soft: #ffe4e6;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --sky: #0369a1;
  --sky-soft: #e0f2fe;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 12px 32px rgba(15, 31, 28, 0.1);
  --shadow-sm: 0 2px 10px rgba(15, 31, 28, 0.06);
  --topbar-h: 60px;
  --page-max: 1100px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --touch: 44px;
  --topbar-bg: rgba(255, 255, 255, 0.96);
  --search-bg: var(--bg);
  --search-focus-bg: #ffffff;
  color-scheme: light;
}

/* Soft dark — slate/teal charcoal, not pure black */
html[data-theme="dark"] {
  --bg: #1a211f;
  --bg-elev: #242c2a;
  --bg-soft: #2c3633;
  --ink: #e6eeeb;
  --ink-2: #b5c4bf;
  --muted: #8a9b95;
  --line: #3a4542;
  --teal: #2dd4bf;
  --teal-2: #5eead4;
  --teal-soft: #1a3d38;
  --amber: #fbbf24;
  --amber-soft: #3d3420;
  --rose: #fb7185;
  --rose-soft: #3f1d28;
  --violet: #c4b5fd;
  --violet-soft: #2e2640;
  --sky: #7dd3fc;
  --sky-soft: #1a3344;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.22);
  --topbar-bg: rgba(36, 44, 42, 0.94);
  --search-bg: #1e2624;
  --search-focus-bg: #2a3330;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.sm { font-size: 0.875rem; }
.eyebrow {
  margin: 0 0 0.15rem;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
}

/* ── App shell ─────────────────────────────────────────────────── */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ───────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: max(0.4rem, var(--safe-t)) max(1rem, var(--safe-r)) 0.4rem max(1rem, var(--safe-l));
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--teal), #115e59);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
}
.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
}
.tagline {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
}
@media (max-width: 720px) {
  .tagline { display: none; }
  .topbar { flex-wrap: wrap; }
  .global-search {
    order: 3;
    flex: 1 1 100%;
    max-width: none !important;
  }
}

/* Global search — center of top bar */
.global-search {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 auto;
  position: relative;
}
.global-search__icon {
  position: absolute;
  left: 0.75rem;
  color: var(--muted);
  pointer-events: none;
}
.global-search__input {
  flex: 1;
  min-height: 42px;
  padding: 0.5rem 0.75rem 0.5rem 2.4rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--search-bg);
  color: var(--ink);
  font-size: 16px;
  outline: none;
  width: 100%;
}
.global-search__input:focus {
  border-color: var(--teal-2);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
  background: var(--search-focus-bg);
}
.global-search__input::placeholder {
  color: var(--muted);
}
.global-search__btn { flex-shrink: 0; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  margin-left: auto;
}
.account-settings-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-elev);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}
.account-settings-btn:hover { border-color: var(--teal); color: var(--teal); }
.account-settings-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ── Views (only one primary visible) ──────────────────────────── */
.view { display: none; flex: 1; min-height: 0; }
.app[data-view="list"] .view-list { display: block; }
.app[data-view="chart"] .view-chart { display: block; }
.app[data-view="reader"] .view-reader { display: flex; }

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 1.25rem clamp(0.85rem, 3vw, 1.5rem) 2.5rem;
}
.page--chart { max-width: 960px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.page-title {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 1.75rem);
  font-weight: 800;
}
.page-sub { margin: 0.2rem 0 0; font-size: 0.9rem; }
.page-head__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.directory-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* ── Directory (patient list full width) ───────────────────────── */
.directory {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* Table-like header on desktop */
.dir-head {
  display: none;
  grid-template-columns: 1.4fr 1fr 1.2fr 0.7fr 40px;
  gap: 0.75rem;
  padding: 0.65rem 1.1rem;
  background: var(--bg-soft);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
@media (min-width: 720px) {
  .dir-head { display: grid; }
}

.dir-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.9rem 1.1rem;
  min-height: 64px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  color: var(--ink);
}
.dir-row:last-child { border-bottom: none; }
.dir-row:hover { background: var(--bg-soft); }
.dir-row:active { background: var(--teal-soft); }

.dir-row__name {
  margin: 0;
  font-weight: 750;
  font-size: 1rem;
}
.dir-row__cedula {
  margin: 0.15rem 0 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}
.dir-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.dir-row__chev {
  color: var(--muted);
  font-size: 1.25rem;
  grid-column: 2;
  grid-row: 1 / span 2;
}
.dir-row__cell { display: none; }

@media (min-width: 720px) {
  .dir-row {
    grid-template-columns: 1.4fr 1fr 1.2fr 0.7fr 40px;
    gap: 0.75rem;
  }
  .dir-row__primary { grid-column: 1; }
  .dir-row__cell {
    display: block;
    font-size: 0.88rem;
    color: var(--ink-2);
  }
  .dir-row__meta { display: none; }
  .dir-row__chev {
    grid-column: 5;
    grid-row: auto;
    justify-self: end;
  }
}

.mini-tag {
  font-size: 0.7rem;
  font-weight: 650;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.mini-tag--doc {
  background: var(--sky-soft);
  border-color: #bae6fd;
  color: var(--sky);
}

/* ── Chart (patient detail) ────────────────────────────────────── */
.crumb {
  margin-bottom: 0.75rem;
}
.crumb__back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 40px;
  padding: 0.35rem 0.5rem 0.35rem 0.15rem;
  font-weight: 700;
  color: var(--teal);
  border-radius: 10px;
}
.crumb__back:hover { background: var(--teal-soft); }

.chart-hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}
.chart-hero h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3.5vw, 1.7rem);
}
.cedula-line {
  margin: 0.3rem 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-2);
}
.patient-sub {
  margin: 0.3rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.chart-hero__actions {
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
}

.alert-row {
  background: var(--amber-soft);
  border: 1px solid #fde68a;
  color: var(--amber);
  border-radius: 12px;
  padding: 0.65rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 650;
  margin-bottom: 0.85rem;
}

/* Action bar — primary work */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.action-bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 48px;
  padding: 0.55rem 1.1rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink-2);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}
.action-bar__btn--main {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  flex: 1;
  min-width: min(100%, 180px);
}
.action-bar__btn--consultation {
  background: #e4f4ed;
  border-color: #a8d7c7;
  color: #17624f;
}
.action-bar__btn--consultation:hover {
  background: #d5ede3;
  border-color: #78bea7;
}
.action-bar__btn:active { transform: scale(0.98); }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}
@media (min-width: 560px) {
  .stat-strip { grid-template-columns: repeat(4, 1fr); }
}
.stat-strip__item {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
}
.stat-strip__label {
  display: block;
  font-size: 0.68rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.stat-strip__item strong {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--teal);
}
.stat-strip__sm {
  font-size: 0.95rem !important;
  font-weight: 700 !important;
  color: var(--ink) !important;
  word-break: break-word;
}

/* Tabs */
.ptabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg-soft);
  border-radius: 14px;
  margin-bottom: 1rem;
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
}
.ptab {
  flex: 1;
  min-height: 42px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}
.ptab.is-active {
  background: var(--bg-elev);
  color: var(--teal);
  box-shadow: var(--shadow-sm);
}
.ptab-badge {
  font-size: 0.7rem;
  background: var(--teal-soft);
  color: var(--teal);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-weight: 750;
}
.ptab-panel { display: none; }
.ptab-panel.is-active { display: block; }

.consultation-panel { overflow: hidden; }
.consultation-head { align-items: flex-start; }
.consultation-head h3, .consultation-head p { margin: 0; }
.consultation-head p { margin-top: 0.2rem; }
.consultation-list { display: grid; gap: 0.7rem; }
.consultation-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.18s ease, transform 0.18s ease;
}
.consultation-card:hover { border-color: color-mix(in srgb, var(--teal) 42%, var(--line)); transform: translateY(-1px); }
.consultation-card.is-annulled { opacity: 0.66; background: var(--bg-soft); }
.consultation-card__open {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  min-width: 0;
  padding: 0.9rem;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.consultation-card__open:focus-visible, .consultation-card__export:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.consultation-card__date { display: grid; gap: 0.18rem; color: var(--ink-3); font-size: 0.75rem; }
.consultation-card__date strong { color: var(--teal); font-size: 0.86rem; }
.consultation-card__body { min-width: 0; }
.consultation-card__body strong { display: block; margin-bottom: 0.25rem; font-size: 0.9rem; }
.consultation-card__body p { margin: 0; color: var(--ink-3); font-size: 0.8rem; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.consultation-card__actions { display: flex; align-items: center; gap: 0.45rem; padding: 0.9rem 0.9rem 0.9rem 0; }
.consultation-card__state { padding: 0.22rem 0.48rem; border-radius: 999px; background: var(--teal-soft); color: var(--teal); font-size: 0.67rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.consultation-card__export { min-height: 30px; padding: 0.3rem 0.6rem; border: 1px solid color-mix(in srgb, var(--teal) 38%, var(--line)); border-radius: 9px; background: transparent; color: var(--teal); font: inherit; font-size: 0.72rem; font-weight: 800; cursor: pointer; white-space: nowrap; }
.consultation-card__export:hover { background: var(--teal-soft); }
.consultation-card.is-annulled .consultation-card__state { background: color-mix(in srgb, var(--rose) 10%, var(--bg-soft)); color: var(--rose); }
.consultation-empty { padding: 2rem 1rem; text-align: center; }
.consultation-empty strong { display: block; }
.consultation-empty p { margin: 0.35rem 0 1rem; }
.consultation-form-body { display: grid; gap: 0.8rem; }
.consultation-form-body textarea { resize: vertical; min-height: 5.5rem; line-height: 1.45; }
.consultation-date { margin: 0; padding: 0.6rem 0.7rem; border-radius: 10px; background: var(--bg-soft); color: var(--ink-3); font-size: 0.78rem; }
.consultation-vitals { margin: 0; padding: 0; border: 0; min-width: 0; }
.consultation-vitals legend { margin-bottom: 0.5rem; padding: 0; color: var(--ink); font-size: 0.82rem; font-weight: 800; }
.consultation-vitals-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.consultation-vitals-grid .field { min-width: 0; }
.consultation-vitals-grid .field span { display: flex; align-items: baseline; justify-content: space-between; gap: 0.35rem; }
.consultation-vitals-grid .field small { color: var(--ink-3); font-size: 0.65rem; font-weight: 650; }
.consultation-vitals-grid .input { min-width: 0; padding-inline: 0.65rem; }
.consultation-modal-foot { align-items: center; }
.modal-foot-spacer { flex: 1; }

.chart-grid {
  display: grid;
  gap: 0.85rem;
}
@media (min-width: 720px) {
  .chart-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 0.75rem;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}
.panel-head h3 { margin: 0; font-size: 1rem; }
.panel-hint { margin: 0.4rem 0 0; font-size: 0.86rem; }

.disease-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.disease-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem 0.4rem 0.7rem;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.82rem;
  font-weight: 650;
  border: 1px solid #fde68a;
}
.disease-tag[data-status="controlada"] {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: #99f6e4;
}
.disease-tag[data-status="resuelta"] {
  background: var(--bg-soft);
  color: var(--muted);
  border-color: var(--line);
}
.disease-tag .remove-disease {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.disease-meta { font-size: 0.72rem; opacity: 0.9; }

.meta-list { margin: 0; display: grid; gap: 0.5rem; }
.meta-list--cards {
  grid-template-columns: 1fr;
}
@media (min-width: 520px) {
  .meta-list--cards { grid-template-columns: 1fr 1fr; }
}
.meta-list--cards > div {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}
.meta-list--cards .meta-full { grid-column: 1 / -1; }
.meta-list dt {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
}
.meta-list dd { margin: 0; word-break: break-word; }

.drop-zone {
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1rem;
  text-align: center;
  background: var(--bg-elev);
  margin-bottom: 0.85rem;
  outline: none;
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone.is-drag {
  border-color: var(--teal-2);
  background: var(--teal-soft);
}
.drop-zone__title { margin: 0 0 0.25rem; font-weight: 750; }
.drop-zone p { margin: 0.15rem 0; }

.docs-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.filter-chips--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
}
.filter-chips--scroll::-webkit-scrollbar { display: none; }
.chip {
  padding: 0.4rem 0.75rem;
  min-height: 36px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
  background: var(--bg-soft);
  color: var(--ink-2);
  border: 1px solid transparent;
  flex-shrink: 0;
}
.chip.is-active {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: #99f6e4;
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.doc-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  text-align: left;
  padding: 0.8rem 0.9rem;
  min-height: 64px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
}
.doc-row:hover { border-color: var(--teal); background: var(--bg-soft); }
.doc-row.is-active {
  border-color: var(--teal);
  background: var(--teal-soft);
}
.doc-row__icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 800;
  flex-shrink: 0;
}
.doc-row__body { flex: 1; min-width: 0; }
.doc-row__title {
  margin: 0;
  font-weight: 750;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-row__meta {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.doc-row__chev { color: var(--muted); font-size: 1.2rem; }

.type-historia { background: var(--violet-soft); color: var(--violet); }
.type-laboratorio { background: var(--sky-soft); color: var(--sky); }
.type-receta { background: var(--teal-soft); color: var(--teal); }
.type-imagen { background: var(--amber-soft); color: var(--amber); }
.type-informe { background: #f3e8ff; color: #7c3aed; }
.type-foto_archivo { background: #fce7f3; color: #9d174d; }
.type-otro { background: var(--bg-soft); color: var(--muted); }

/* ── Reader full-screen ────────────────────────────────────────── */
.view-reader {
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #0b1412;
  color: #e7f0ed;
}
.reader-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.reader-head {
  flex-shrink: 0;
  padding: max(0.65rem, var(--safe-t)) 1rem 0.65rem;
  border-bottom: 1px solid #1f2e2a;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  background: #0d1614;
}
.reader-head .btn-ghost {
  background: #1a2824;
  border-color: #2d403a;
  color: #e7f0ed;
}
.reader-title-block {
  flex: 1;
  min-width: 140px;
}
.reader-title-block h3 {
  margin: 0;
  font-size: 1rem;
  color: #fff;
}
.reader .muted { color: #94a3a0; }
.reader-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
}
.reader-controls .icon-btn {
  width: 40px;
  height: 40px;
  color: #e7f0ed;
  background: #1a2824;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}
.zoom-label, .page-label {
  font-size: 0.75rem;
  min-width: 3rem;
  text-align: center;
  color: #94a3a0;
  font-family: var(--mono);
}

/* Desktop: preview + side data panel */
.reader-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .reader-layout {
    grid-template-columns: 1fr min(340px, 36vw);
  }
  .reader-tabs--mobile,
  .reader-mobile-data,
  .reader-foot--mobile {
    display: none !important;
  }
}
@media (max-width: 899px) {
  .reader-side,
  .reader-tabs--main {
    display: none !important;
  }
  .reader-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .reader-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
}

.reader-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.reader-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #1f2e2a;
  flex-shrink: 0;
}
.reader-tab {
  padding: 0.45rem 0.9rem;
  min-height: 40px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 700;
  color: #94a3a0;
}
.reader-tab.is-active {
  background: #134e4a;
  color: #5eead4;
}
.reader-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #0f1a17;
}
.reader-pane { width: 100%; }
#pdfCanvas {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
#imgPreview {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.reader-side {
  border-left: 1px solid #1f2e2a;
  background: #0d1614;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  padding: 0.85rem;
}
.reader-side__title {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5eead4;
}
.reader-side__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px solid #1f2e2a;
}
.reader-side__actions .btn-ghost {
  background: #1a2824;
  border-color: #2d403a;
  color: #e7f0ed;
}
.reader-side__actions .btn-danger-ghost { color: #fda4af; }
.reader-side__actions a.btn { text-decoration: none; }

.reader-mobile-data {
  flex: 1;
  overflow: auto;
  padding: 0.75rem;
  background: #0d1614;
}
.reader-foot--mobile {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem calc(0.55rem + var(--safe-b));
  border-top: 1px solid #1f2e2a;
  background: #0d1614;
}
.reader-foot--mobile .btn-ghost {
  background: #1a2824;
  border-color: #2d403a;
  color: #e7f0ed;
}
.reader-foot--mobile .btn-danger-ghost { color: #fda4af; }
.reader-foot--mobile a.btn { text-decoration: none; }

.extracted-panel { font-size: 0.9rem; color: #e7f0ed; }
.extract-dl { margin: 0 0 0.85rem; display: grid; gap: 0.35rem; }
.extract-dl > div {
  display: grid;
  grid-template-columns: minmax(90px, 38%) 1fr;
  gap: 0.35rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #1f2e2a;
}
.extract-dl dt { margin: 0; color: #94a3a0; font-size: 0.72rem; font-weight: 700; }
.extract-dl dd { margin: 0; word-break: break-word; }
.extract-h {
  margin: 0.65rem 0 0.35rem;
  font-size: 0.75rem;
  color: #5eead4;
  text-transform: uppercase;
}
.extract-labs, .extract-lines {
  margin: 0;
  padding-left: 1.1rem;
  color: #cbd5d1;
}
.ocr-text {
  margin: 0;
  padding: 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  color: #d1e0db;
}

/* ── Buttons / inputs ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border-radius: 12px;
  font-weight: 650;
  font-size: 0.92rem;
  border: 1px solid transparent;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-2); }
.btn-ghost {
  background: var(--bg-elev);
  border-color: var(--line);
  color: var(--ink-2);
}
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger-ghost { color: var(--rose); min-height: 40px; padding: 0.4rem 0.75rem; }
.btn-danger-ghost:hover { background: var(--rose-soft); }
.btn-sm { min-height: 36px; padding: 0.35rem 0.75rem; font-size: 0.84rem; }
.btn-lg { min-height: 48px; padding: 0.7rem 1.25rem; }
.icon-btn {
  width: var(--touch);
  height: var(--touch);
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-size: 1.35rem;
}
.icon-btn:hover { background: var(--bg-soft); }
.link-btn {
  color: var(--teal);
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0.15rem;
  background: none;
  border: none;
  cursor: pointer;
}

.input {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--ink);
  outline: none;
  font-size: 16px;
}
.input:focus {
  border-color: var(--teal-2);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}
.input-sm { min-height: 40px; padding: 0.45rem 0.65rem; font-size: 0.9rem; }
.select-sm { width: auto; min-width: 130px; }

.api-pill {
  font-size: 0.7rem;
  font-weight: 750;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}
.api-pill.is-ok {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: #99f6e4;
}
.api-pill.is-err {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: #fecdd3;
}

.error-msg {
  color: var(--rose);
  background: var(--rose-soft);
  border: 1px solid #fecdd3;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
  margin: 0 0 0.65rem;
}
.status-msg {
  color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #99f6e4;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
  margin: 0 0 0.65rem;
  font-weight: 650;
}

/* Empty */
.empty-state {
  display: grid;
  place-items: center;
  padding: 2rem 0.5rem;
  min-height: 40vh;
}
.empty-card {
  max-width: 380px;
  text-align: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.75rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.empty-card h3 { margin: 0 0 0.4rem; }

/* Modals */
.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  width: min(520px, calc(100vw - 1rem));
  max-height: min(92dvh, 740px);
  box-shadow: var(--shadow);
  background: var(--bg-elev);
  color: var(--ink);
  margin: auto;
}
.modal::backdrop {
  background: rgba(15, 31, 28, 0.5);
  backdrop-filter: blur(3px);
}
.modal-form {
  display: flex;
  flex-direction: column;
  max-height: min(92dvh, 740px);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; }
.modal-body {
  padding: 0.85rem 1rem;
  overflow-y: auto;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  padding: 0.75rem 1rem calc(0.75rem + var(--safe-b));
  border-top: 1px solid var(--line);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}
@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-section {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.84rem;
  font-weight: 650;
  color: var(--ink-2);
}
.field em { color: var(--rose); font-style: normal; }
.field--full { grid-column: 1 / -1; }
.field .input { font-weight: 400; color: var(--ink); }

.cedula-scan-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem;
  border: 1px solid color-mix(in srgb, var(--teal) 28%, var(--line));
  border-radius: 14px;
  background: color-mix(in srgb, var(--teal) 7%, var(--bg-elev));
}
.cedula-scan-card__copy { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.cedula-scan-card__copy > span:last-child { display: grid; gap: 0.16rem; }
.cedula-scan-card__copy strong { font-size: 0.88rem; color: var(--ink); }
.cedula-scan-card__copy small { color: var(--ink-3); line-height: 1.3; }
.cedula-scan-card__icon {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--teal);
  color: white;
  font-size: 1.15rem;
}
.btn-scan { white-space: nowrap; color: var(--teal); border-color: color-mix(in srgb, var(--teal) 40%, var(--line)); }
.scan-modal { width: min(440px, calc(100vw - 1rem)); }
.scan-kicker { margin: 0 0 0.12rem; color: var(--teal); font-size: 0.66rem; font-weight: 850; letter-spacing: 0.09em; text-transform: uppercase; }
.scan-body { padding: 1.1rem; }
.scan-step { text-align: center; }
.scan-intro, .scan-step > p { margin: 0 auto 1rem; max-width: 34ch; color: var(--ink-3); line-height: 1.5; }
.scan-step h4 { margin: 0.9rem 0 0.35rem; font-size: 1.05rem; }
.scan-qr-wrap {
  width: min(250px, 70vw);
  margin: 0 auto 0.8rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: var(--shadow-sm);
}
.scan-qr-wrap img { display: block; width: 100%; aspect-ratio: 1; }
.scan-status { display: flex; justify-content: center; align-items: center; gap: 0.45rem; color: var(--ink-2); font-size: 0.83rem; font-weight: 700; }
.scan-status span { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--teal); animation: scanPulse 1.4s ease-in-out infinite; }
.scan-status b { font: inherit; }
.scan-link { display: inline-block; margin-top: 0.9rem; color: var(--teal); font-size: 0.78rem; font-weight: 700; }
.scan-id-card { position: relative; width: 190px; height: 118px; margin: 0.2rem auto 1rem; border: 2px solid var(--teal); border-radius: 14px; background: color-mix(in srgb, var(--teal) 7%, var(--bg-elev)); }
.scan-id-card span { position: absolute; left: 16px; top: 25px; width: 43px; height: 49px; border-radius: 50% 50% 42% 42%; background: color-mix(in srgb, var(--teal) 28%, var(--line)); }
.scan-id-card i, .scan-id-card b { position: absolute; left: 75px; right: 15px; height: 7px; border-radius: 5px; background: color-mix(in srgb, var(--teal) 24%, var(--line)); }
.scan-id-card i { top: 33px; }
.scan-id-card b { top: 53px; right: 42px; }
.scan-reading, .scan-ready { padding: 2rem 0 1.4rem; }
.scan-review { text-align: left; }
.scan-review > .scan-check { margin-bottom: 0.55rem; }
.scan-review > h4, .scan-review > p { text-align: center; }
.scan-review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; margin-top: 1rem; }
.scan-review-warning { margin: 0.75rem 0 0 !important; padding: 0.65rem 0.75rem; max-width: none !important; border: 1px solid color-mix(in srgb, var(--rose) 45%, var(--line)); border-radius: 10px; background: color-mix(in srgb, var(--rose) 8%, var(--bg-elev)); color: var(--rose) !important; font-size: 0.78rem; font-weight: 700; text-align: left !important; }
.scan-review-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.scan-spinner { display: block; width: 2.8rem; height: 2.8rem; margin: auto; border: 4px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: scanSpin 0.8s linear infinite; }
.scan-check { display: grid; place-items: center; width: 3.2rem; height: 3.2rem; margin: auto; border-radius: 50%; background: color-mix(in srgb, var(--teal) 14%, var(--bg-elev)); color: var(--teal); font-size: 1.7rem; font-weight: 900; }
.scan-error { margin-top: 0.8rem; text-align: center; }
@keyframes scanPulse { 50% { opacity: 0.3; transform: scale(0.75); } }
@keyframes scanSpin { to { transform: rotate(360deg); } }
@media (max-width: 520px) {
  .cedula-scan-card { align-items: stretch; flex-direction: column; }
  .btn-scan { width: 100%; }
  .scan-review-grid { grid-template-columns: 1fr; }
  .scan-review-actions { flex-direction: column-reverse; }
  .scan-review-actions .btn { width: 100%; }
  .consultation-card { grid-template-columns: 1fr; }
  .consultation-card__open { grid-template-columns: 1fr; gap: 0.45rem; padding-bottom: 0.5rem; }
  .consultation-card__date { display: flex; align-items: baseline; gap: 0.45rem; }
  .consultation-card__actions { justify-content: flex-end; padding: 0 0.9rem 0.9rem; }
  .consultation-head { align-items: stretch; flex-direction: column; }
  .consultation-head .btn { width: 100%; }
  .consultation-modal-foot { flex-wrap: wrap; }
  .consultation-modal-foot .modal-foot-spacer { display: none; }
  #btnAnnulConsultation { width: 100%; margin-right: 0; }
  .consultation-vitals-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: #0f1f1c;
  color: #fff;
  padding: 0.75rem 1.15rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 650;
  box-shadow: var(--shadow);
  max-width: min(92vw, 400px);
  text-align: center;
}
.toast.is-error { background: var(--rose); }

/* ── Auth gate ─────────────────────────────────────────────────── */
.auth-gate {
  min-height: 100dvh;
  background: #f4f7f6;
  color: #10201d;
}
.welcome {
  --welcome-ink: #10201d;
  --welcome-muted: #60736e;
  --welcome-line: #d4e2de;
  --welcome-paper: #ffffff;
  --welcome-soft: #e8f2ef;
  --welcome-teal: #0f766e;
  --welcome-teal-bright: #0d9488;
  --welcome-serif: Georgia, "Times New Roman", serif;
  overflow-x: hidden;
}
.welcome button,
.welcome a { -webkit-tap-highlight-color: transparent; }
.welcome-wrap {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}
.welcome-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--welcome-line);
  backdrop-filter: blur(16px);
}
.welcome-nav__inner {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.welcome-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--welcome-ink);
  text-decoration: none;
}
.welcome-brand__mark {
  width: 40px;
  height: 40px;
  object-fit: cover;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(145deg, var(--welcome-teal), #115e59);
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.2);
  font: 800 1rem/1 var(--font);
}
.welcome-brand strong,
.welcome-brand small { display: block; }
.welcome-brand strong { font-size: 1rem; letter-spacing: -0.02em; }
.welcome-brand small { margin-top: 0.05rem; color: var(--welcome-muted); font-size: 0.7rem; }
.welcome-nav__links { display: flex; align-items: center; gap: 0.45rem; }
.welcome-nav__links > a {
  color: #405550;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 650;
}
.welcome-nav__links > a:hover { background: var(--welcome-soft); }
.welcome-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: 10px;
  font: 750 0.88rem/1 var(--font);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.welcome-btn:active { transform: scale(0.98); }
.welcome-btn--primary {
  color: #fff;
  background: linear-gradient(135deg, var(--welcome-teal), var(--welcome-teal-bright));
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.18);
}
.welcome-btn--primary:hover { box-shadow: 0 10px 26px rgba(15, 118, 110, 0.28); }
.welcome-btn--ghost { color: var(--welcome-ink); background: var(--welcome-paper); border-color: var(--welcome-line); }
.welcome-btn--ghost:hover { background: var(--welcome-soft); }
.welcome-btn--large { min-height: 50px; padding: 0.8rem 1.3rem; font-size: 0.95rem; }
.welcome-btn--light { color: var(--welcome-teal); background: #fff; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.15); }

.welcome-hero {
  position: relative;
  padding: clamp(3.5rem, 8vw, 6.5rem) 0 clamp(4rem, 8vw, 6rem);
  overflow: hidden;
  background:
    radial-gradient(900px 450px at 10% 0%, rgba(153, 246, 228, 0.52), transparent 68%),
    linear-gradient(180deg, #fbfdfc, #f4f7f6);
}
.welcome-hero::after {
  content: "";
  position: absolute;
  width: 360px;
  height: 360px;
  right: -140px;
  top: 35%;
  border: 1px solid rgba(15, 118, 110, 0.12);
  border-radius: 50%;
  box-shadow: 0 0 0 70px rgba(15, 118, 110, 0.035), 0 0 0 140px rgba(15, 118, 110, 0.02);
}
.welcome-hero__grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(390px, 0.95fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 5rem);
}
.welcome-eyebrow {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1.1rem;
  padding: 0.38rem 0.72rem;
  border: 1px solid #bce8de;
  border-radius: 999px;
  color: var(--welcome-teal);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}
.welcome-eyebrow span { width: 7px; height: 7px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12); }
.welcome-hero h1 {
  max-width: 700px;
  margin: 0;
  color: var(--welcome-ink);
  font-family: var(--welcome-serif);
  font-size: clamp(2.65rem, 5.6vw, 5rem);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.05em;
}
.welcome-hero h1 em { color: var(--welcome-teal); font-style: italic; font-weight: 500; }
.welcome-hero__lead { max-width: 580px; margin: 1.4rem 0 0; color: #405550; font-size: clamp(1rem, 2vw, 1.15rem); line-height: 1.7; }
.welcome-hero__actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1.7rem; }
.welcome-assurances { display: flex; flex-wrap: wrap; gap: 0.65rem 1.2rem; margin-top: 1.35rem; color: var(--welcome-muted); font-size: 0.78rem; }
.welcome-assurances span::before { content: "✓"; margin-right: 0.35rem; color: var(--welcome-teal); font-weight: 900; }

.welcome-preview { border: 1px solid var(--welcome-line); border-radius: 18px; background: var(--welcome-paper); box-shadow: 0 26px 70px rgba(16, 32, 29, 0.14); overflow: hidden; transform: rotate(0.8deg); }
.welcome-preview__bar { min-height: 46px; display: flex; align-items: center; gap: 6px; padding: 0 0.85rem; border-bottom: 1px solid var(--welcome-line); background: #edf3f1; }
.welcome-preview__bar i { width: 9px; height: 9px; border-radius: 50%; background: #9fb3ae; }
.welcome-preview__bar i:first-child { background: #fb7185; }
.welcome-preview__bar i:nth-child(2) { background: #fbbf24; }
.welcome-preview__bar i:nth-child(3) { background: #34d399; }
.welcome-preview__bar span { flex: 1; margin-left: 0.45rem; padding: 0.3rem 0.55rem; border-radius: 6px; color: #70847f; background: #fff; font-family: var(--mono); font-size: 0.66rem; }
.welcome-preview__body { padding: 1.15rem; }
.welcome-preview__search { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.65rem 0.75rem; border: 1px solid var(--welcome-line); border-radius: 10px; color: #7b8e89; background: #f8faf9; font-size: 0.78rem; }
.welcome-preview__search b { padding: 0.42rem 0.65rem; border-radius: 7px; color: #fff; background: var(--welcome-teal); font-size: 0.7rem; }
.welcome-preview__patient { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.7rem; margin-top: 0.8rem; padding: 0.9rem; border: 1px solid #b9e7dc; border-radius: 12px; background: #eaf8f4; }
.welcome-preview__avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; color: #fff; background: var(--welcome-teal); font-weight: 800; font-size: 0.8rem; }
.welcome-preview__patient strong, .welcome-preview__patient small { display: block; }
.welcome-preview__patient strong { font-size: 0.86rem; }
.welcome-preview__patient small { margin-top: 0.12rem; color: var(--welcome-muted); font-size: 0.68rem; }
.welcome-preview__status { padding: 0.25rem 0.48rem; border-radius: 999px; color: #047857; background: #d1fae5; font-size: 0.62rem; font-weight: 800; }
.welcome-preview__docs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; margin-top: 0.65rem; }
.welcome-preview__docs article { padding: 0.8rem; border: 1px solid var(--welcome-line); border-radius: 11px; background: #fafcfb; }
.welcome-preview__docs article > span { display: inline-block; margin-bottom: 0.45rem; padding: 0.2rem 0.35rem; border-radius: 5px; color: var(--welcome-teal); background: #dff5ef; font-size: 0.58rem; font-weight: 900; }
.welcome-preview__docs strong, .welcome-preview__docs small { display: block; }
.welcome-preview__docs strong { font-size: 0.78rem; }
.welcome-preview__docs small { margin-top: 0.15rem; color: var(--welcome-muted); font-size: 0.65rem; }

.welcome-trust { padding: 1.2rem 0; border-block: 1px solid var(--welcome-line); background: var(--welcome-paper); }
.welcome-trust__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.welcome-trust__grid span { color: var(--welcome-muted); text-align: center; font-size: 0.8rem; }
.welcome-trust__grid b { color: var(--welcome-teal); font-family: var(--welcome-serif); font-size: 1.2rem; }
.welcome-section { padding: clamp(4rem, 8vw, 6.5rem) 0; }
.welcome-section__head { max-width: 670px; margin: 0 auto 2.6rem; text-align: center; }
.welcome-section__head p { margin: 0 0 0.5rem; color: var(--welcome-teal); font-size: 0.7rem; font-weight: 850; letter-spacing: 0.09em; text-transform: uppercase; }
.welcome-section__head h2 { margin: 0; font-family: var(--welcome-serif); font-size: clamp(2rem, 4vw, 3.15rem); line-height: 1.08; letter-spacing: -0.035em; }
.welcome-section__head span { display: block; margin-top: 0.85rem; color: var(--welcome-muted); line-height: 1.65; }
.welcome-feature-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; }
.welcome-feature-grid article { min-height: 230px; padding: 1.3rem; border: 1px solid var(--welcome-line); border-radius: 15px; background: var(--welcome-paper); box-shadow: 0 8px 24px rgba(16, 32, 29, 0.04); }
.welcome-feature-grid article > b { display: block; color: #84a59d; font-family: var(--mono); font-size: 0.68rem; }
.welcome-feature-grid h3 { margin: 2.3rem 0 0.55rem; font-family: var(--welcome-serif); font-size: 1.3rem; }
.welcome-feature-grid p { margin: 0; color: var(--welcome-muted); font-size: 0.84rem; line-height: 1.6; }

.welcome-pricing { border-block: 1px solid var(--welcome-line); background: #fff; }
.welcome-price-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.9rem; align-items: stretch; }
.welcome-plan { position: relative; display: flex; flex-direction: column; padding: 1.45rem; border: 1px solid var(--welcome-line); border-radius: 16px; background: #f7faf9; }
.welcome-plan--featured { color: #fff; border-color: #0f766e; background: linear-gradient(150deg, #0f766e, #115e59); box-shadow: 0 18px 42px rgba(15, 118, 110, 0.22); transform: translateY(-8px); }
.welcome-plan > i { position: absolute; top: -0.65rem; right: 1rem; padding: 0.25rem 0.55rem; border-radius: 999px; color: #075e56; background: #ccfbf1; font-size: 0.62rem; font-style: normal; font-weight: 850; text-transform: uppercase; }
.welcome-plan > p { margin: 0; color: var(--welcome-teal); font-size: 0.72rem; font-weight: 850; letter-spacing: 0.06em; text-transform: uppercase; }
.welcome-plan--featured > p { color: #99f6e4; }
.welcome-plan h3 { margin: 0.45rem 0 0.15rem; font-family: var(--welcome-serif); font-size: 2.35rem; letter-spacing: -0.04em; }
.welcome-plan h3 small { color: inherit; opacity: 0.72; font: 500 0.85rem/1 var(--font); }
.welcome-plan > span { color: var(--welcome-muted); font-size: 0.8rem; }
.welcome-plan--featured > span { color: rgba(255,255,255,0.72); }
.welcome-plan ul { flex: 1; display: grid; gap: 0.6rem; margin: 1.25rem 0 1.4rem; padding: 0; list-style: none; }
.welcome-plan li { font-size: 0.82rem; }
.welcome-plan li::before { content: "✓"; margin-right: 0.42rem; color: var(--welcome-teal); font-weight: 900; }
.welcome-plan--featured li::before { color: #99f6e4; }
.welcome-plan .welcome-btn { width: 100%; }
.welcome-plan--featured .welcome-btn--primary { color: var(--welcome-teal); background: #fff; }

.welcome-cta { padding: clamp(3.5rem, 7vw, 5.5rem) 0; }
.welcome-cta__card { display: flex; align-items: center; justify-content: space-between; gap: 2rem; padding: clamp(2rem, 5vw, 3.5rem); border-radius: 22px; color: #fff; background: linear-gradient(135deg, #0f766e, #0d5d56); box-shadow: 0 24px 60px rgba(15, 118, 110, 0.22); }
.welcome-cta p { margin: 0 0 0.45rem; color: #99f6e4; font-size: 0.7rem; font-weight: 850; letter-spacing: 0.08em; text-transform: uppercase; }
.welcome-cta h2 { max-width: 650px; margin: 0; font-family: var(--welcome-serif); font-size: clamp(1.8rem, 3.5vw, 2.8rem); line-height: 1.08; }
.welcome-footer { padding: 1.5rem 0 max(1.5rem, var(--safe-b)); border-top: 1px solid var(--welcome-line); color: var(--welcome-muted); background: #fff; font-size: 0.75rem; }
.welcome-footer .welcome-wrap { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.welcome-footer button { color: var(--welcome-teal); font-weight: 750; }

.auth-dialog {
  width: min(460px, calc(100% - 1.5rem));
  max-height: min(92dvh, 760px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: transparent;
  overflow: visible;
}
.auth-dialog::backdrop { background: rgba(8, 25, 21, 0.68); backdrop-filter: blur(6px); }
.auth-dialog .auth-card { max-height: min(92dvh, 760px); overflow-y: auto; }
.auth-close { position: absolute; top: 0.7rem; right: 0.7rem; z-index: 2; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); font-size: 1.3rem; }
.auth-close:hover { color: var(--ink); background: var(--bg-soft); }

@media (max-width: 900px) {
  .welcome-nav__links > a { display: none; }
  .welcome-hero__grid { grid-template-columns: 1fr; }
  .welcome-preview { width: min(620px, 100%); margin-inline: auto; transform: none; }
  .welcome-feature-grid { grid-template-columns: repeat(2, 1fr); }
  .welcome-price-grid { grid-template-columns: 1fr; max-width: 560px; margin-inline: auto; }
  .welcome-plan--featured { transform: none; }
}
@media (max-width: 620px) {
  .welcome-wrap { width: min(100% - 1.2rem, 1120px); }
  .welcome-nav__inner { min-height: 62px; display: grid; grid-template-columns: auto max-content; gap: 0.5rem; }
  .welcome-brand { flex: 0 0 auto; gap: 0.5rem; }
  .welcome-brand__mark { width: 36px; height: 36px; border-radius: 9px; }
  .welcome-brand span { display: none; }
  .welcome-nav__links { flex: 0 0 auto; min-width: max-content; gap: 0.3rem; }
  .welcome-nav__links .welcome-btn { min-height: 38px; padding-inline: 0.68rem; font-size: 0.78rem; }
  .welcome-hero { padding-top: 3rem; }
  .welcome-hero h1 { font-size: clamp(2.55rem, 13vw, 3.6rem); }
  .welcome-hero__actions { display: grid; }
  .welcome-assurances { display: grid; gap: 0.45rem; }
  .welcome-trust__grid { grid-template-columns: 1fr; gap: 0.45rem; }
  .welcome-feature-grid { grid-template-columns: 1fr; }
  .welcome-feature-grid article { min-height: 190px; }
  .welcome-feature-grid h3 { margin-top: 1.4rem; }
  .welcome-preview__patient { grid-template-columns: auto 1fr; }
  .welcome-preview__status { display: none; }
  .welcome-preview__docs { grid-template-columns: 1fr; }
  .welcome-cta__card { display: grid; }
  .welcome-footer .welcome-wrap { flex-direction: column; text-align: center; }
}
@media (max-width: 380px) {
  .welcome-nav__links { gap: 0.25rem; }
  .welcome-nav__links .welcome-btn { min-height: 36px; padding-inline: 0.54rem; font-size: 0.72rem; border-radius: 8px; }
}
.auth-card {
  width: min(420px, 100%);
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.5rem 1.25rem 1.25rem;
  box-shadow: var(--shadow);
}
.auth-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.15rem;
}
.auth-brand h1, .auth-brand h2 { margin: 0; font-size: 1.25rem; }
.auth-brand p { margin: 0.15rem 0 0; font-size: 0.85rem; }
.auth-google {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
.auth-google:hover {
  border-color: var(--teal-2);
  color: var(--teal);
}
.auth-google__mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fff;
  color: #1a73e8;
  border: 1px solid #d7dce2;
  font: 800 0.9rem/1 Arial, sans-serif;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.85rem 0;
  color: var(--muted);
  font-size: 0.75rem;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}
.auth-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg-soft);
  border-radius: 12px;
  margin-bottom: 1rem;
}
.auth-tab {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  font-weight: 700;
  color: var(--ink-2);
}
.auth-tab.is-active {
  background: var(--bg-elev);
  color: var(--teal);
  box-shadow: var(--shadow-sm);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.auth-demo {
  margin: 0.35rem 0 0;
  text-align: center;
}
.auth-demo code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--bg-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.doctor-chip {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink-2);
}

.brand-settings-body { display: grid; gap: 1rem; }
.brand-settings-intro { margin: 0; color: var(--muted); font-size: 0.88rem; }
.brand-settings-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.brand-logo-panel {
  display: grid;
  justify-items: center;
  gap: 0.65rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
  text-align: center;
}
.brand-logo-panel small { color: var(--muted); font-size: 0.7rem; line-height: 1.35; }
.brand-logo-preview {
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed color-mix(in srgb, var(--teal) 45%, var(--line));
  border-radius: 16px;
  background: var(--bg-elev);
  color: var(--teal);
  font-size: 1.15rem;
  font-weight: 850;
}
.brand-logo-preview img { width: 100%; height: 100%; object-fit: contain; padding: 0.35rem; }
.brand-logo-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.45rem; }
.brand-logo-remove { color: var(--rose); font-size: 0.75rem; }
.brand-profile-fields { min-width: 0; }
.brand-color-controls { display: grid; grid-template-columns: 52px minmax(0, 180px); gap: 0.65rem; align-items: center; }
.brand-color-controls input[type="color"] {
  width: 52px;
  height: var(--touch);
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  cursor: pointer;
}
.brand-color-controls input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.brand-color-controls input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.brand-color-controls input[type="color"]::-moz-color-swatch { border: 0; border-radius: 8px; }
.brand-profile-fields .field > small { color: var(--muted); font-size: 0.7rem; line-height: 1.35; }
.brand-pdf-preview {
  --pdf-accent: #0f766e;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elev);
}
.brand-pdf-preview__label {
  display: block;
  margin-bottom: 0.65rem;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.brand-pdf-preview__header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 68px;
  padding-bottom: 0.65rem;
  border-bottom: 2px solid var(--pdf-accent);
}
.brand-pdf-preview__header > div:last-child { min-width: 0; display: grid; gap: 0.12rem; }
.brand-pdf-preview__header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-pdf-preview__header span, .brand-pdf-preview__header small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-pdf-preview__logo {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 10px;
  background: color-mix(in srgb, var(--pdf-accent) 10%, var(--bg-elev));
  color: var(--pdf-accent);
  font-weight: 850;
}
.brand-pdf-preview__logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
@media (max-width: 620px) {
  .brand-settings-grid { grid-template-columns: 1fr; }
  .brand-logo-panel { grid-template-columns: auto 1fr; justify-items: start; text-align: left; }
  .brand-logo-preview { grid-row: 1 / 3; width: 76px; height: 76px; }
  .brand-logo-actions { justify-content: flex-start; align-self: end; }
  .brand-logo-panel small { align-self: start; }
}
@media (max-width: 720px) {
  .doctor-chip { display: none; }
  #btnLogout { padding: 0.4rem 0.55rem; }
}

/* ── Plan / billing ────────────────────────────────────────────── */
.plan-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink-2);
  letter-spacing: 0.02em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.plan-pill:hover { border-color: var(--teal); color: var(--teal); }
.plan-pill.is-pro {
  background: linear-gradient(135deg, #0f766e, #0d9488);
  border-color: transparent;
  color: #ecfdf8;
}
.plan-pill.is-pro:hover { filter: brightness(1.06); color: #fff; }
html[data-theme="dark"] .plan-pill.is-pro {
  background: linear-gradient(135deg, #134e4a, #0f766e);
}

.modal--wide {
  width: min(720px, calc(100vw - 1rem));
}
.billing-lead { margin: 0 0 1rem; line-height: 1.5; }
.billing-status {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal);
  font-weight: 650;
  font-size: 0.9rem;
}
.pricing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
@media (min-width: 640px) {
  .pricing-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 920px) {
  .pricing-grid { grid-template-columns: repeat(3, 1fr); }
}
.price-card {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.price-card--pro {
  border-color: var(--teal);
  box-shadow: var(--shadow-sm);
}
.price-card__badge {
  position: absolute;
  top: -0.55rem;
  right: 0.75rem;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--teal);
  color: #fff;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}
.price-card h4 { margin: 0; font-size: 1rem; }
.price-card__amount {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--teal);
}
.price-card__list {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--ink-2);
  flex: 1;
}
.price-card__list li { margin: 0.25rem 0; }
.billing-email-field { margin-bottom: 0.75rem; }
.billing-actions { margin-top: 0.5rem; }
.billing-hint-code {
  font-family: var(--mono);
  font-size: 0.85em;
}

/* ── Site footer ───────────────────────────────────────────────── */
.site-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding: 1rem max(1rem, var(--safe-r)) calc(1rem + var(--safe-b)) max(1rem, var(--safe-l));
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  text-align: center;
}
.site-footer__text {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
.site-footer__sep {
  margin: 0 0.35rem;
  opacity: 0.7;
}
.site-footer__link {
  color: var(--teal);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s, color 0.15s;
}
.site-footer__link:hover {
  border-bottom-color: var(--teal);
  color: var(--teal-2);
}
/* Full-screen document view: no footer clutter */
.app[data-view="reader"] .site-footer {
  display: none;
}

/* ── Theme toggle ──────────────────────────────────────────────── */
.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-2);
  flex-shrink: 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.theme-toggle:hover {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: var(--teal);
}
.theme-toggle__icon {
  display: grid;
  place-items: center;
  line-height: 0;
}
/* Light mode: show moon (click to go dark) */
html:not([data-theme="dark"]) .theme-toggle__icon--sun { display: none; }
html:not([data-theme="dark"]) .theme-toggle__icon--moon { display: grid; }
/* Dark mode: show sun (click to go light) */
html[data-theme="dark"] .theme-toggle__icon--moon { display: none; }
html[data-theme="dark"] .theme-toggle__icon--sun { display: grid; }

html[data-theme="dark"] .brand-mark {
  background: linear-gradient(145deg, #0d9488, #134e4a);
}
html[data-theme="dark"] .btn-primary {
  background: #0f766e;
  color: #ecfdf8;
}
html[data-theme="dark"] .btn-primary:hover {
  background: #0d9488;
}
html[data-theme="dark"] .action-bar__btn--main {
  background: #0f766e;
  border-color: #0f766e;
  color: #ecfdf8;
}
html[data-theme="dark"] .action-bar__btn--consultation {
  background: #164e45;
  border-color: #2b7565;
  color: #e6fff7;
}
html[data-theme="dark"] .action-bar__btn--consultation:hover {
  background: #1b5f53;
  border-color: #3b8f7b;
}
html[data-theme="dark"] .mini-tag {
  background: var(--bg-soft);
}
html[data-theme="dark"] .modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
.feature-hidden {
  display: none !important;
}
