:root {
  --ink: #14241f;
  --ink-soft: #3d524a;
  --paper: #f3f6f2;
  --panel: #ffffff;
  --line: #d5e0d9;
  --teal: #0f6b5c;
  --teal-deep: #0a4a40;
  --mint: #b7e0d2;
  --sand: #e8d5a8;
  --amber: #c47a1a;
  --danger: #9b2c2c;
  --ok: #1f6b3a;
  --shadow: 0 18px 50px rgba(20, 36, 31, 0.12);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Figtree", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  min-height: 100vh;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(183, 224, 210, 0.55), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(232, 213, 168, 0.4), transparent 55%),
    linear-gradient(180deg, #eef4ef 0%, #f7f5ef 45%, #e9f0ec 100%);
}

a { color: var(--teal-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.1rem 5vw;
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  background: rgba(243, 246, 242, 0.86);
  border-bottom: 1px solid rgba(213, 224, 217, 0.8);
  z-index: 20;
}

.brand, .brand-compact {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.7rem;
  background:
    linear-gradient(145deg, var(--teal) 0%, var(--teal-deep) 55%, #1a7a68 100%);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 28% 40%;
  background: var(--sand);
  border-radius: 2px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
}
.brand-text small { color: var(--ink-soft); font-size: 0.78rem; }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  align-items: center;
}
.nav a { color: var(--ink-soft); font-weight: 500; text-decoration: none; }
.nav a:hover { color: var(--teal-deep); }
.nav-cta {
  background: var(--teal);
  color: #fff !important;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
}
.nav-cta:hover { background: var(--teal-deep); text-decoration: none; }

.hero {
  min-height: calc(100vh - 5.5rem);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2rem;
  align-items: end;
  padding: 4rem 5vw 3rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--amber);
  font-weight: 700;
  margin: 0 0 0.75rem;
}

.brand-hero {
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 8vw, 6.5rem);
  line-height: 0.95;
  margin: 0 0 1rem;
  letter-spacing: -0.03em;
  animation: rise 0.8s ease both;
}

.lede {
  font-size: 1.15rem;
  max-width: 34rem;
  color: var(--ink-soft);
  margin: 0 0 1.75rem;
  animation: rise 0.9s 0.08s ease both;
}

.cta-row { display: flex; flex-wrap: wrap; gap: 0.75rem; animation: rise 1s 0.14s ease both; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 0.75rem 1.2rem;
  border-radius: 999px;
  text-decoration: none;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-deep); text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--teal-deep);
  box-shadow: inset 0 0 0 1.5px var(--teal);
}
.btn-ghost:hover { background: rgba(15, 107, 92, 0.08); text-decoration: none; }

.hero-visual {
  min-height: 420px;
  border-radius: 28px 28px 0 0;
  background:
    linear-gradient(160deg, rgba(15, 107, 92, 0.15), rgba(20, 36, 31, 0.35)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='800' viewBox='0 0 1200 800'%3E%3Cdefs%3E%3ClinearGradient id='g' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop stop-color='%230f6b5c'/%3E%3Cstop offset='1' stop-color='%231a3d36'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='1200' height='800' fill='url(%23g)'/%3E%3Ccircle cx='280' cy='180' r='120' fill='%23b7e0d2' opacity='.25'/%3E%3Ccircle cx='920' cy='520' r='180' fill='%23e8d5a8' opacity='.18'/%3E%3Cpath d='M0 560 C220 500 380 620 600 580 C820 540 980 470 1200 520 L1200 800 L0 800 Z' fill='%23f3f6f2' opacity='.2'/%3E%3C/svg%3E")
    center/cover no-repeat;
  position: relative;
  overflow: hidden;
  animation: fade-in 1.1s ease both;
}

.hero-panel {
  position: absolute;
  left: 1.5rem;
  right: 1.5rem;
  bottom: 1.5rem;
  background: rgba(243, 246, 242, 0.92);
  border-radius: 18px;
  padding: 1.25rem 1.4rem;
  backdrop-filter: blur(8px);
}
.hero-panel .hero-label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--amber);
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.hero-panel strong {
  font-family: var(--font-display);
  font-size: 1.4rem;
}
.hero-panel p { margin: 0.4rem 0 0; color: var(--ink-soft); }

.strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  padding: 0 5vw 4rem;
}
.strip article {
  padding: 1.4rem 0;
  border-top: 2px solid var(--teal);
}
.strip h2 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  margin: 0 0 0.4rem;
}
.strip p { margin: 0; color: var(--ink-soft); }

.page-narrow, .page-narrow-app {
  width: min(720px, 92vw);
  margin: 2.5rem auto 4rem;
}
.page-head h1, .panel-page > .page-head h1, .auth-card h1 {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.8rem);
  margin: 0 0 0.4rem;
  letter-spacing: -0.02em;
}
.page-head p { color: var(--ink-soft); margin: 0 0 1.5rem; }
.row-between { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }

.form-stack { display: grid; gap: 1rem; }
.form-stack label, .filters label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; }
.form-stack input, .form-stack select, .form-stack textarea,
.filters select, .form-inline input {
  font: inherit;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.form-stack fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.2rem;
  margin: 0;
  background: rgba(255,255,255,0.7);
}
.form-stack legend {
  font-family: var(--font-display);
  padding: 0 0.35rem;
  font-weight: 600;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.form-inline { display: flex; gap: 0.75rem; align-items: end; margin-bottom: 1.5rem; }
.form-inline .grow { flex: 1; display: grid; gap: 0.35rem; font-weight: 600; }

.detail-list {
  display: grid;
  gap: 0.75rem;
  margin: 1.5rem 0;
  padding: 1.25rem;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.detail-list div { display: grid; grid-template-columns: 8rem 1fr; gap: 0.75rem; }
.detail-list dt { color: var(--ink-soft); font-weight: 600; }
.detail-list dd { margin: 0; }

.code-pill {
  display: inline-block;
  font-family: ui-monospace, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  background: var(--mint);
  color: var(--teal-deep);
  padding: 0.55rem 1rem;
  border-radius: 12px;
}

.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: lowercase;
  background: #e5ece8;
  color: var(--ink);
}
.badge-solicitada, .badge-recibida { background: #f3e2bd; color: #7a4f00; }
.badge-confirmada, .badge-en_tramite { background: #cfe8f5; color: #0d4a66; }
.badge-atendida, .badge-respondida, .badge-cerrada { background: #d5edd9; color: var(--ok); }
.badge-cancelada, .badge-no_asistio { background: #f3d4d4; color: var(--danger); }

.prio { font-weight: 700; text-transform: uppercase; font-size: 0.75rem; }
.prio-alta { color: var(--danger); }
.prio-media { color: var(--amber); }
.prio-baja { color: var(--ink-soft); }

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--mint);
}
.timeline li {
  padding: 0 0 1.1rem 1.1rem;
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 0.35rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--teal);
}
.timeline span { display: block; color: var(--ink-soft); font-size: 0.85rem; }
.timeline p { margin: 0.25rem 0 0; }
.subhead { font-family: var(--font-display); font-size: 1.35rem; margin: 2rem 0 0.75rem; }
.empty { color: var(--ink-soft); padding: 1rem 0; }

.flash {
  margin: 0.75rem 5vw 0;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  font-weight: 600;
}
.flash-success { background: #d5edd9; color: var(--ok); }
.flash-error { background: #f3d4d4; color: var(--danger); }
.app-main .flash { margin: 1rem 1.5rem 0; }

.site-footer {
  padding: 2rem 5vw 3rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}
.site-footer p { margin: 0.2rem 0; }

.auth-screen {
  min-height: calc(100vh - 6rem);
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.auth-card {
  width: min(440px, 100%);
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 2rem;
  box-shadow: var(--shadow);
  animation: rise 0.6s ease both;
}
.hint {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: #eef6f2;
  border-radius: 14px;
  font-size: 0.9rem;
}
.hint ul { margin: 0.4rem 0; padding-left: 1.1rem; }
.hint code { background: #fff; padding: 0.1rem 0.35rem; border-radius: 6px; }

.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #e8f1ec 0%, #f5f3ec 100%);
}
.sidebar {
  background: var(--teal-deep);
  color: #e8f4ef;
  padding: 1.4rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar .brand { color: #fff; font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; }
.sidebar .brand-mark { box-shadow: none; }
.sidebar-user { margin: 0; font-size: 0.92rem; opacity: 0.9; }
.sidebar-user span { opacity: 0.7; font-size: 0.8rem; }
.side-nav { display: grid; gap: 0.35rem; }
.side-nav a {
  color: #d7ebe4;
  text-decoration: none;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-weight: 500;
}
.side-nav a:hover { background: rgba(255,255,255,0.1); text-decoration: none; }

.panel-page { padding: 1.5rem 1.75rem 3rem; }
.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}
.metric {
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
}
.metric span { display: block; color: var(--ink-soft); font-size: 0.85rem; }
.metric strong {
  font-family: var(--font-display);
  font-size: 1.9rem;
  color: var(--teal-deep);
}
.split-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
}
.section-head h2 { font-family: var(--font-display); margin: 0; font-size: 1.35rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.data-table th {
  background: #e7f0eb;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.filters { margin-bottom: 1rem; max-width: 220px; }
.mt { margin-top: 2rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; min-height: auto; padding-top: 2.5rem; }
  .hero-visual { min-height: 320px; }
  .strip { grid-template-columns: 1fr; }
  .split-panels { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; }
  .side-nav { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .detail-list div { grid-template-columns: 1fr; gap: 0.15rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}

/* —— Módulo clínico: exámenes y fórmulas —— */
.badge-normal { background: #d5edd9; color: var(--ok); }
.badge-alto, .badge-activa { background: #f3e2bd; color: #7a4f00; }
.badge-bajo { background: #cfe8f5; color: #0d4a66; }
.badge-critico, .badge-anulada { background: #f3d4d4; color: var(--danger); }
.badge-pendiente, .badge-vencida { background: #e5ece8; color: var(--ink-soft); }
.badge-dispensada { background: #d5edd9; color: var(--ok); }
.muted { color: var(--ink-soft); margin: 0.15rem 0 0.55rem; font-size: 0.9rem; }

.exam-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
}
.exam-board.dense { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.exam-tile {
  display: block;
  text-decoration: none;
  color: inherit;
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  transition: transform .18s ease, box-shadow .18s ease;
  animation: rise .5s ease both;
}
.exam-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); text-decoration: none; }
.exam-tile header { display: flex; justify-content: space-between; gap: .5rem; align-items: start; }
.exam-tile header strong { font-size: .95rem; }
.exam-tile.estado-normal { border-color: #9dcea8; }
.exam-tile.estado-alto, .exam-tile.estado-bajo { border-color: #e0c27a; }
.exam-tile.estado-critico { border-color: #d98a8a; box-shadow: 0 0 0 1px rgba(155,44,44,.12); }

.exam-gauge { margin: .7rem 0 .35rem; }
.exam-gauge.large { margin: 1rem 0; }
.exam-gauge-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #7eb6d9 0%, #7eb6d9 18%, #8fca9a 18%, #8fca9a 82%, #e0a35a 82%, #e0a35a 100%);
  overflow: visible;
}
.exam-gauge-band {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 0; bottom: 0;
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.exam-gauge-marker {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--teal-deep);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(20,36,31,.35);
  transition: left .25s ease;
}
.exam-gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: .72rem;
  color: var(--ink-soft);
  margin-top: .35rem;
}
.exam-value { margin: .35rem 0 0; color: var(--ink-soft); }
.exam-value em {
  font-style: normal;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: var(--teal-deep);
  margin-right: .2rem;
}
.exam-value.xl em { font-size: 2.6rem; }
.exam-hero {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: 1.25rem;
  align-items: center;
  padding: 1.4rem 1.5rem;
  border-radius: 22px;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  margin-bottom: 1rem;
}
.exam-hero.estado-critico { background: linear-gradient(135deg, #fff5f5, #fff); }
.exam-hero.estado-normal { background: linear-gradient(135deg, #f3faf4, #fff); }
.ref-range { color: var(--ink-soft); margin: .35rem 0 0; }
.exam-preview {
  margin-top: .75rem;
  padding: 1rem;
  border-radius: 16px;
  background: #eef6f2;
  border: 1px dashed var(--line);
}
.exam-preview-head { display: flex; justify-content: space-between; margin-bottom: .5rem; font-weight: 600; }
.exam-preview.estado-critico { background: #fff1f1; }
.exam-preview.estado-alto, .exam-preview.estado-bajo { background: #fff8ea; }
.exam-preview.estado-normal { background: #eef8f0; }

.rx-list { display: grid; gap: .7rem; }
.rx-list.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.rx-mini {
  display: grid;
  gap: .2rem;
  padding: .95rem 1rem;
  border-radius: 14px;
  background: rgba(255,255,255,.88);
  border: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  transition: transform .15s ease;
}
.rx-mini:hover { transform: translateY(-2px); text-decoration: none; }
.rx-mini p { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.rx-code {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  color: var(--teal-deep);
  background: var(--mint);
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 8px;
  width: fit-content;
  font-size: .85rem;
}

.rx-items { display: grid; gap: 1rem; margin-bottom: .85rem; }
.rx-item-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  background: #fff;
  position: relative;
}
.rx-item-card header {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-family: var(--font-display);
  margin-bottom: .75rem;
}
.rx-num {
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--teal); color: #fff; font-size: .85rem; font-weight: 700;
}
.rx-remove {
  margin-left: auto;
  border: none; background: #f3d4d4; color: var(--danger);
  width: 1.8rem; height: 1.8rem; border-radius: 50%; cursor: pointer; font-size: 1.1rem;
}

.rx-sheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1.5rem 1.6rem 2rem;
  box-shadow: var(--shadow);
}
.rx-sheet-head {
  display: flex; justify-content: space-between; gap: 1rem; align-items: start;
  border-bottom: 2px solid var(--teal);
  padding-bottom: 1rem; margin-bottom: 1.1rem;
}
.rx-brand { font-family: var(--font-display); font-size: 1.6rem; display: block; }
.rx-patient-block {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.rx-patient-block span { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.rx-patient-block strong { display: block; margin-top: .15rem; }
.rx-patient-block small { color: var(--ink-soft); }
.rx-med-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .85rem; }
.rx-med-list li {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  gap: .85rem;
  padding: 1rem;
  border-radius: 16px;
  background: linear-gradient(180deg, #f7fbf8, #fff);
  border: 1px solid var(--line);
}
.rx-med-order {
  width: 2.2rem; height: 2.2rem; border-radius: 12px;
  background: var(--teal-deep); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.rx-med-body h3 { margin: 0 0 .55rem; font-family: var(--font-display); font-size: 1.2rem; }
.rx-med-body dl {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: .55rem;
  margin: 0;
}
.rx-med-body dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.rx-med-body dd { margin: .1rem 0 0; font-weight: 600; }
.rx-item-note { margin: .65rem 0 0; color: var(--ink-soft); font-size: .92rem; }
.rx-general {
  margin-top: 1.2rem;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  background: #fff8ea;
  border: 1px solid #e8d5a8;
}
.rx-general p { margin: .35rem 0 0; }
.rx-sign { margin-top: 2.5rem; text-align: center; }
.rx-sign-line { width: min(240px, 60%); height: 1px; background: var(--ink); margin: 0 auto .6rem; }
.clinica-split { align-items: start; }
.tl-examen::before { background: #0d4a66 !important; }
.tl-formula::before { background: var(--amber) !important; }

@media (max-width: 960px) {
  .exam-hero, .rx-patient-block { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .cta-row, .flash { display: none !important; }
  .app-shell { display: block; }
  .rx-sheet { box-shadow: none; border: none; }
}
