/* OptoCRM design system — tokens + components derived from the design prototype. */
:root {
  --header-bg: #0c2a2b;
  --brand: #0e7c7b;
  --accent: #12b3ab;
  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --page-bg: #f4f6f7;
  --card-bg: #ffffff;
  --border: #dfe6e9;
  --border-strong: #94a3b8;
  --border-soft: #eef2f4;
  --border-line: #f2f5f6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(12, 42, 43, .07), 0 1px 2px rgba(12, 42, 43, .04);
  --shadow-lg: 0 24px 60px rgba(12, 42, 43, .22);
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  background: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { letter-spacing: -.01em; }
.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
@keyframes optoFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Header ---------- */
.app-header {
  height: 56px; flex: 0 0 auto; background: var(--header-bg); color: #eaf3f2;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  position: sticky; top: 0; z-index: 30;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #04201f; font-size: 15px;
}
.brand-logo { display: flex; align-items: center; gap: 10px; cursor: pointer; color: #eaf3f2; font-weight: 600; }
.brand-logo:hover { text-decoration: none; }
.brand-version { font-size: 10px; font-weight: 500; opacity: .45; align-self: flex-end; padding-bottom: 3px; margin-left: -5px; }
.tenant-brand {
  display: flex; align-items: center; gap: 8px; color: #eaf3f2; font-weight: 600;
  font-size: 13.5px; padding-left: 16px; border-left: 1px solid rgba(255,255,255,.18);
  white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.tenant-brand img { height: 28px; max-width: 96px; object-fit: contain; border-radius: 6px; }
.header-search { flex: 1; max-width: 520px; position: relative; }
.header-search input {
  width: 100%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14);
  color: #eaf3f2; border-radius: var(--radius-sm); padding: 8px 12px 8px 32px; font: inherit; font-size: 13px;
}
.header-search input::placeholder { color: rgba(234,243,242,.55); }
.header-search .search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); opacity: .5; }
.store-badge {
  display: flex; align-items: center; gap: 7px; background: rgba(18,179,171,.12);
  border: 1px solid rgba(18,179,171,.3); padding: 4px 6px 4px 10px; border-radius: var(--radius-sm);
  color: #eaf3f2; font-size: 12.5px;
}
.store-badge select { background: transparent; border: none; color: #eaf3f2; font: inherit; font-size: 12px; cursor: pointer; }
.store-badge select option { color: #0f172a; }
.user-chip { display: flex; align-items: center; gap: 8px; padding-left: 4px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #04201f;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex: 0 0 auto;
}

/* ---------- Nav (two-level: top modules + submodule dropdowns) ---------- */
.app-nav {
  flex: 0 0 auto; background: #fff; border-bottom: 1px solid var(--border);
  padding: 0 14px; display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  position: sticky; top: 56px; z-index: 20;
}
.app-nav .nav-top {
  border: none; background: transparent; font-size: 13px; font-weight: 500; color: #5b6b74;
  padding: 14px 13px 12px; border-bottom: 2.5px solid transparent; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 3px;
}
.app-nav .nav-top:hover { color: var(--brand); text-decoration: none; }
.app-nav .nav-top.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }

/* Submodule dropdown */
.nav-group { position: relative; display: inline-flex; }
.nav-group.active > .nav-top { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }
.nav-caret { font-size: 9px; opacity: .55; transition: transform .12s ease; }
.nav-group:hover .nav-caret, .nav-group:focus-within .nav-caret { transform: translateY(1px); opacity: .9; }
.nav-menu {
  position: absolute; top: 100%; left: 6px; min-width: 200px; z-index: 40;
  display: none; flex-direction: column; padding: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20, 40, 50, .14);
}
.nav-group:hover > .nav-menu, .nav-group:focus-within > .nav-menu { display: flex; }
.nav-menu a {
  padding: 8px 11px; font-size: 12.5px; font-weight: 500; color: #37474f;
  border-radius: 7px; white-space: nowrap; border: none;
}
.nav-menu a:hover { background: var(--surface-2, #eef4f3); color: var(--brand); text-decoration: none; }
.nav-menu a.active { background: var(--surface-2, #eef4f3); color: var(--brand); font-weight: 600; }

/* ---------- Home (branded, money-free) ---------- */
.home-hero {
  display: flex; align-items: center; gap: 16px; padding: 22px 24px; margin-bottom: 18px;
  background: linear-gradient(120deg, var(--brand, #0f766e), #0b8f7d);
  color: #eafaf6; border-radius: 14px;
}
.home-logo {
  width: 58px; height: 58px; flex: 0 0 auto; border-radius: 14px;
  display: grid; place-items: center; font-size: 28px; font-weight: 800;
  background: rgba(255, 255, 255, .16); color: #fff;
}
.home-brand { font-size: 22px; font-weight: 700; line-height: 1.1; }
.home-hero .page-sub { color: rgba(255, 255, 255, .82); text-transform: capitalize; }

.shortcut-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.shortcut {
  display: flex; align-items: center; gap: 11px; padding: 13px 14px;
  background: #fff; border: 1px solid var(--border); border-radius: 11px; color: inherit;
  transition: border-color .12s ease, transform .12s ease, box-shadow .12s ease;
}
.shortcut:hover {
  text-decoration: none; border-color: var(--brand); transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(20, 40, 50, .09);
}
.shortcut-icon { font-size: 21px; flex: 0 0 auto; }
.shortcut-txt { display: flex; flex-direction: column; line-height: 1.25; }

/* ---------- Main ---------- */
main { flex: 1; overflow: auto; }
.container { margin: 0 auto; padding: 22px 24px 48px; animation: optoFade .28s ease; }
.container-narrow { max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted-2); }
.page-title { font-size: 24px; font-weight: 700; margin-top: 3px; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { color: var(--muted); }

/* ---------- Cards ---------- */
.card { background: var(--card-bg); border: 1px solid var(--border-soft); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 12px; border-bottom: 1px solid var(--border-soft); }
.card-head h2, .card-head h3 { font-size: 14px; font-weight: 600; margin: 0; }
.card-body { padding: 14px 16px; }
.card-row { display: grid; align-items: center; gap: 14px; padding: 11px 16px; border-top: 1px solid var(--border-line); }
.card-row:first-child { border-top: none; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }
.grid-main { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }

/* ---------- Customer detail ---------- */
.customer-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 16px;
  align-items: start;
}
.customer-workspace, .customer-sidebar { min-width: 0; }
.customer-tabs { padding: 0 8px; }
.customer-workspace-body { min-width: 0; }
.customer-summary-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.customer-avatar { width: 42px; height: 42px; font-size: 15px; }
.customer-title { min-width: 0; }
.customer-title h1 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.18;
  overflow-wrap: anywhere;
}
.customer-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}
.customer-tags .chip { margin: 0; }
.customer-fields {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.customer-fields > div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px;
}
.customer-fields span:last-child { overflow-wrap: anywhere; }
/* Discreet clinical/commercial alert: shows only the red pill header;
   the text unfolds on hover or keyboard focus (tabindex on the section). */
.customer-alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  background: #fdf2f4;
  border: 1px solid #f4c2ce;
  color: #b3384e;
  cursor: default;
}
.customer-alert-title {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.customer-alert-body {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin-top: 0;
  transition: max-height .25s ease, opacity .2s ease, margin-top .25s ease;
}
.customer-alert:hover .customer-alert-body,
.customer-alert:focus .customer-alert-body,
.customer-alert:focus-within .customer-alert-body {
  max-height: 300px;
  opacity: 1;
  margin-top: 6px;
}
.customer-balance-amount {
  font-size: 23px;
  font-weight: 700;
  margin: 4px 0;
}
.customer-balance-amount.is-due { color: #b45309; }
.customer-balance-amount.is-clear { color: #067a52; }
.customer-primary-action {
  justify-content: center;
  width: 100%;
  text-align: center;
}
.prescription-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.prescription-toolbar .callout { flex: 1 1 auto; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 14px 15px; box-shadow: var(--shadow); }
.kpi .label { font-size: 11.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-family: var(--mono); font-size: 23px; font-weight: 600; margin-top: 8px; letter-spacing: -.03em; white-space: nowrap; }
.kpi .delta { font-size: 11px; margin-top: 5px; font-weight: 500; color: var(--muted); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border-soft); }
.table td { padding: 11px 12px; border-top: 1px solid var(--border-line); }
.table tbody tr:hover { background: #f9fbfb; }
.table .right { text-align: right; }
.data-list { width: 100%; }
.row-link { cursor: pointer; }

/* Sortable table headers */
.table th.th-sort { padding: 0; }
.th-sort-link { display: flex; align-items: center; gap: 5px; width: 100%; padding: 10px 12px; color: var(--muted-2); font-weight: 600; }
.th-sort-link:hover { color: var(--brand); text-decoration: none; }
.table th.th-sorted .th-sort-link { color: var(--ink-2); }
.sort-caret { flex: 0 0 auto; }
.sort-idle { opacity: 0; transition: opacity .12s; }
.th-sort-link:hover .sort-idle { opacity: .45; }
.saldo-due { color: #c0392b; font-weight: 600; }
.alert-flag { color: #c0392b; vertical-align: -1px; margin-right: 4px; }
/* Filter chips (quick lists): clickable, with an active state */
a.chip { margin-right: 6px; }
a.chip:hover { text-decoration: none; background: #e2eeec; }
a.chip.chip-on { background: var(--brand); color: #fff; }

/* ---------- Badges (6-category status system) ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-draft { background: #eef1f4; color: #64748b; }
.badge-deposit { background: #fef3e2; color: #b45309; }
.badge-workshop { background: #e6f0fb; color: #1e5aa8; }
.badge-paid { background: #e3f5ec; color: #067a52; }
.badge-overdue { background: #fdecea; color: #c0392b; }
.badge-clinical { background: #efeefc; color: #5b53c9; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: #eef4f4; color: #35606a; }
/* Clasificación clínica de la pérdida media auditiva (audiometría) */
.chip.loss-ok { background: #e8f5ec; color: #1e7d3c; }
.chip.loss-mild { background: #fff8ec; color: #8a5a10; }
.chip.loss-moderate { background: #fdf0e0; color: #b06a12; }
.chip.loss-mod-severe { background: #fce9dd; color: #b3501e; }
.chip.loss-severe { background: #fbe5e0; color: #c0392b; }
.chip.loss-profound { background: #f6dcdc; color: #8e1f1f; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; font-family: inherit; font-size: 13px; font-weight: 600; padding: 9px 15px; border-radius: 9px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #0a6362; color: #fff; }
.btn-secondary { background: #fff; color: var(--ink-2); border-color: var(--border); }
.btn-secondary:hover { background: #f7fafa; }
.btn-accent { background: var(--accent); color: #04201f; }
.btn-danger { background: #fff; color: #c0392b; border-color: #f0c8c2; }
.btn-danger:hover { background: #fdf1ef; }
.btn-ghost { background: transparent; color: var(--brand); border-color: transparent; padding: 9px 8px; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
kbd { font-family: var(--mono); font-size: 10.5px; background: #eef2f4; border: 1px solid #dbe3e5; border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: #47606a; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 11px; color: #475569; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px; }
.field-input, .field select, .field textarea, input.field-input, select.field-input, textarea.field-input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; font: inherit; font-size: 13.5px; color: var(--ink); background: #fff;
}
.field-input::placeholder, .field textarea::placeholder { color: var(--muted-2); }
.field-input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,123,.12); }
.field-hint { font-size: 11.5px; margin-top: 4px; }
.field-error { color: #c0392b; }
.field-ok { color: #067a52; }
/* Width-adaptive: columns multiply with available space (2 on a 640px card,
   5-6 on a wide monitor) while each field keeps a usable 210-320px. auto-fill
   (not auto-fit) keeps sparse rows from stretching fields to comic widths. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .full :is(input, select, textarea) { max-width: 680px; }
/* Fixed pairing (e.g. OD/OS) that must stay side by side even in a narrow sidebar. */
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
/* Long-text rows (motivo, observaciones…): wide tracks so they pair up on big
   screens instead of one capped input per row. min() avoids phone overflow. */
.form-grid-wide { grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); }

/* ---------- Alerts / callouts ---------- */
.callout { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; line-height: 1.5; }
.callout-warn { background: #fff8ec; border: 1px solid #f6e2bd; color: #8a5a10; }
.callout-clinical { background: #f6f5fe; border: 1px solid #e0dcf7; color: #4b45a8; }
.callout-info { background: #eef6f6; border: 1px solid #d5e7e7; color: #35606a; }
.messages { margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-soft); overflow-x: auto; }
.tabs a { padding: 11px 14px; font-size: 13px; font-weight: 500; color: #5b6b74; border-bottom: 2.5px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--brand); text-decoration: none; }
.tabs a.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }
.tabs a.clinical { color: #5b53c9; }

/* ---------- Modal / drawer ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(12,42,43,.42); animation: optoFade .15s ease; display: flex; }
.modal { width: 640px; max-width: 92vw; margin: 80px auto auto; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; animation: optoFade .18s ease; align-self: flex-start; }
.drawer { margin-left: auto; width: 460px; max-width: 94vw; height: 100%; background: #fff; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: optoFade .18s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-soft); }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- OD/OS clinical grid ---------- */
.rx-grid-scroll { width: 100%; overflow-x: auto; }
.rx-grid { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
.rx-grid th { background: #fafbfc; font-family: var(--sans); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); padding: 6px 10px; text-align: center; }
.rx-grid td { padding: 7px 10px; text-align: center; border-top: 1px solid var(--border-soft); }
.rx-grid .eye { font-family: var(--sans); font-weight: 700; color: var(--brand); }
/* Shaded clinical panel: lifts an OD/OS grid off the white card so the values
   stand out (feedback: "destaca los campos en un tono sombreado", morado). */
.clinical-panel { background: #f7f6fd; border: 1px solid #e9e6f8; border-radius: var(--radius-sm); padding: 4px 8px; }
.clinical-panel .rx-grid th { background: transparent; }
.protected { display: flex; align-items: center; gap: 8px; }
/* Editable OD/OS entry: a 12-column <table> can only clip or scroll when the
   viewport shrinks, so the form renders one block per eye whose cells wrap.
   Each cell carries its own mini-label; both eyes share the same auto-fill
   tracks, so their columns stay aligned at any width. */
.rx-entry { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 6px 12px; align-items: start; }
.rx-entry + .rx-entry { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.rx-entry-eye { font-weight: 700; color: var(--brand); font-size: 12.5px; line-height: 1.25; padding-top: 17px; }
.rx-entry-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px 8px; min-width: 0; }
.rx-cell label { display: block; font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted-2); text-align: center; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rx-cell .field-input { text-align: center; padding: 7px 5px; font-size: 13px; font-family: var(--mono); }
/* Narrow cells for dense numeric rows (audiogram: 11 frequencies per ear). */
.rx-entry-fields.rx-cells-sm { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); }
/* Read-only receta grid: keep the 12 columns of an eye on ONE line (auto-fill
   wrapped A.V./DNP onto a second row on low-res screens — Carlos). Fixed 12
   tracks that shrink to fit; on a viewport too narrow for 46px/column the row
   scrolls horizontally instead of wrapping or clipping. */
.rx-entry-fields.rx-cells-12 { grid-template-columns: repeat(12, minmax(46px, 1fr)); overflow-x: auto; }
/* Narrow columns → let the mini-labels wrap to two lines instead of clipping
   (both eyes wrap identically, so their columns stay aligned). */
.rx-entry-fields.rx-cells-12 .rx-cell label { white-space: normal; overflow: visible; line-height: 1.1; }
/* Read-only value cell (detail views) — same wrap behaviour, no input chrome. */
.rx-cell .rx-val { font-family: var(--mono); font-size: 13px; text-align: center; padding: 4px 2px; }
/* Banded form sections (audiometría): four look-alike grids of tiny inputs in
   a row, so alternating shades make each block read as one unit ("gris oscuro /
   gris más claro" — Carlos), and the block being edited lights up. */
.form-band {
  border: 1px solid #cbd5db; border-radius: var(--radius-sm); padding: 10px 12px 12px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.form-band-dark { background: #e1e6e9; }
.form-band-light { background: #f1f4f5; }
.form-band > .field-label { color: var(--ink-2); font-weight: 700; }
.form-band:focus-within {
  border-color: var(--brand);
  box-shadow: inset 4px 0 0 var(--brand), 0 0 0 2px rgba(14, 124, 123, .14);
}
.form-band .rx-entry + .rx-entry { border-top-color: rgba(15, 23, 42, .08); }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.spacer { flex: 1; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mb-16 { margin-bottom: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.divider { height: 1px; background: var(--border-soft); margin: 12px 0; }
@media (max-width: 1000px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-main, .customer-detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .customer-workspace-body { padding: 12px; }
  .customer-fields > div { grid-template-columns: 80px minmax(0, 1fr); }
  .customer-tabs a { padding: 10px 12px; }
  .prescription-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .prescription-toolbar .btn { justify-content: center; }
  .rx-grid { min-width: 680px; }
  .rx-entry { grid-template-columns: 1fr; }
  .rx-entry-eye { padding-top: 0; }
}

/* Print: any app page prints just its main content (nav, sidebar, forms and
   buttons are screen chrome). Standalone documents/* pages have their own CSS. */
.print-only { display: none; }
@media print {
  .app-header, .app-nav, .messages, .breadcrumb, .btn, form, details,
  .customer-sidebar, .customer-tabs { display: none !important; }
  .print-only { display: block; font-weight: 700; font-size: 16px; margin-bottom: 12px; }
  body { background: #fff; }
  .card { box-shadow: none; }
  .container { max-width: none; padding: 0; }
  .customer-detail-grid { display: block; }
}

/* ---------- Espacio de trabajo (mostrador): pestañas de tareas ---------- */
/* El shell ocupa el alto disponible bajo la cabecera+nav; la pila de iframes
   rellena y hace scroll interno (no la página). Cadena flex (no alturas en %)
   porque <body> usa min-height:100vh, con la que height:100% no resolvería. */
main:has(> .ws-container) { display: flex; flex-direction: column; min-height: 0; }
.container.ws-container { max-width: none; margin: 0; padding: 0; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.ws-shell { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

.ws-tabstrip {
  flex: 0 0 auto; display: flex; align-items: stretch; gap: 2px;
  padding: 6px 10px 0; background: #eef2f4; border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.ws-tab {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 8px 10px 8px 14px; border: 1px solid transparent; border-bottom: none;
  border-radius: 9px 9px 0 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; white-space: nowrap; max-width: 240px;
}
.ws-tab:hover { color: var(--ink-2); background: #e3eaec; }
.ws-tab.active {
  background: #fff; color: var(--ink); border-color: var(--border);
  box-shadow: 0 -1px 0 var(--brand) inset;
}
.ws-tab-label { overflow: hidden; text-overflow: ellipsis; }
.ws-tab-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0; border: 0; border-radius: 5px;
  background: transparent; color: var(--muted-2); cursor: pointer; flex: 0 0 auto;
}
.ws-tab-close:hover { background: #dbe3e5; color: #c0392b; }

.ws-launcher { display: inline-flex; align-items: center; gap: 4px; padding: 0 4px 6px; align-self: center; }
.ws-open {
  border: 1px dashed var(--border-strong); background: #fff; color: var(--ink-2);
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 6px 11px;
  border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.ws-open:hover { border-color: var(--brand); color: var(--brand); border-style: solid; }

.ws-panes { position: relative; flex: 1 1 auto; min-height: 0; background: #fff; }
.ws-pane { position: absolute; inset: 0; }
.ws-pane iframe { width: 100%; height: 100%; border: 0; display: block; }
.ws-empty { position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; text-align: center;
  padding: 24px; color: var(--muted); }
.ws-empty p { max-width: 460px; margin: 0; }

/* ---------- Agenda: rejilla tipo Google Calendar ---------- */
.cal-card { padding: 0; overflow: hidden; }
.cal-toolbar { align-items: center; }
.cal-viewtoggle { display: inline-flex; gap: 2px; margin-left: 8px; }

.cal-headrow {
  display: grid; grid-template-columns: 56px repeat(var(--cal-cols), 1fr);
  border-bottom: 1px solid var(--border); background: #fff;
}
.cal-dayhead {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 8px 4px; color: var(--ink-2); border-left: 1px solid var(--border);
}
/* Las cabeceras siguen el tinte de su columna (corner + días: el nth-child
   par coincide con el de .cal-day, que va tras .cal-axis). */
.cal-dayhead:nth-child(even) { background: #f4f7f8; }
.cal-dayhead:hover { text-decoration: none; background: #eaf1f1; }
.cal-dayname { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cal-daynum { font-size: 18px; font-weight: 600; line-height: 1.2; }
.cal-dayhead.today .cal-dayname { color: var(--brand); }
.cal-dayhead.today .cal-daynum {
  background: var(--brand); color: #fff; border-radius: 50%;
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
}

.cal-scroll { overflow-y: auto; max-height: calc(100vh - 250px); }
.ws-embedded .cal-scroll { max-height: calc(100vh - 195px); }
.cal-grid {
  display: grid; grid-template-columns: 56px repeat(var(--cal-cols), 1fr);
  position: relative; margin-bottom: 14px;
}
.cal-axis { position: relative; }
.cal-hourlabel {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-family: var(--mono); font-size: 10.5px; color: var(--muted-2);
}
/* Sombreado alterno de filas y columnas ("que no se vea un fondo plano
   blanco" — Carlos, misma pauta que las bandas de audiometría). Las filas se
   pintan con un gradiente repetido cuya altura viene de la plantilla
   (--cal-hour = PX_PER_HOUR de grid.py), así no se desalinea con las líneas
   de hora. La rejilla empieza siempre a hora en punto, luego el periodo de
   2 horas casa con las bandas. */
.cal-day {
  position: relative; border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(15, 23, 42, .028) 0 var(--cal-hour, 66px),
    transparent var(--cal-hour, 66px) calc(var(--cal-hour, 66px) * 2)
  );
}
.cal-day:nth-child(even) { background-color: #f4f7f8; }
.cal-day.today { background-color: rgba(18, 179, 171, .055); }
.cal-hourline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border-line); }

.cal-closed {
  position: absolute; left: 0; right: 0; z-index: 1;
  background: repeating-linear-gradient(-45deg, #eceff1 0 8px, #e6eaec 8px 16px);
  color: var(--muted-2); font-size: 11px; font-weight: 600;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 4px;
  overflow: hidden; user-select: none;
}

.cal-slot { position: absolute; left: 0; right: 0; z-index: 2; border-radius: 4px; }
.cal-slot span {
  display: none; font-size: 11px; font-weight: 600; color: var(--brand);
  padding: 1px 6px; pointer-events: none;
}
.cal-slot:hover { background: rgba(14, 124, 123, .08); text-decoration: none; }
.cal-slot:hover span { display: inline-block; }

.cal-appt {
  position: absolute; z-index: 3; display: flex; flex-direction: column; gap: 0;
  border-radius: 6px; padding: 3px 6px; overflow: hidden; font-size: 11.5px;
  line-height: 1.25; color: var(--ink); border-left: 3px solid var(--muted);
  background: #eef2f4; box-shadow: 0 1px 2px rgba(12, 42, 43, .12);
}
.cal-appt:hover { text-decoration: none; filter: brightness(.97); z-index: 4; }
.cal-appt-time { font-family: var(--mono); font-size: 10px; color: inherit; opacity: .75; }
.cal-appt-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-appt-type { font-size: 10.5px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-appt.type-exam { background: #e0f2f1; border-left-color: #0e7c7b; }
.cal-appt.type-contact_lens { background: #ede7f6; border-left-color: #7e57c2; }
.cal-appt.type-pickup { background: #e3f2fd; border-left-color: #1e88e5; }
.cal-appt.type-adjustment { background: #fff3e0; border-left-color: #fb8c00; }
.cal-appt.type-other { background: #eceff1; border-left-color: #78909c; }
.cal-appt.st-completed { opacity: .55; }
.cal-appt.st-no_show { background: #fdecea; border-left-color: #c0392b; }
.cal-appt.st-cancelled { opacity: .4; }
.cal-appt.st-cancelled .cal-appt-name { text-decoration: line-through; }

.cal-now { position: absolute; left: 0; right: 0; z-index: 5; border-top: 2px solid #e53935; pointer-events: none; }
.cal-now::before {
  content: ""; position: absolute; left: -5px; top: -6px;
  width: 10px; height: 10px; border-radius: 50%; background: #e53935;
}

/* Autocompletado de cliente (formulario de cita) */
.ac-wrap { position: relative; }
.ac-results { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; }
.ac-list {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); margin-top: 4px; overflow: hidden; max-height: 320px; overflow-y: auto;
}
.ac-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; padding: 8px 12px; border: 0; background: transparent;
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.ac-item:hover { background: #f0f6f6; }
.ac-item + .ac-item { border-top: 1px solid var(--border-line); }
.ac-empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

/* Horario y tramos */
.hours-table td { vertical-align: middle; }
.hours-table input[type="time"] { width: 108px; }

/* La primera etiqueta de hora sobresale media línea por encima de la rejilla. */
.cal-grid { margin-top: 10px; }
/* Citas de un tramo corto: una sola línea (hora + nombre) para que quepa el nombre. */
.cal-appt--xs { flex-direction: row; gap: 5px; align-items: baseline; padding-top: 2px; }
.cal-appt--xs .cal-appt-time { flex: 0 0 auto; }

/* Vista previa de un envío masivo: respeta los saltos de línea del mensaje
   tal y como los recibirá el cliente, sin desbordar la tarjeta. */
.preview-body { margin: 6px 0 0; padding: 12px; background: #f7fafa; border: 1px solid #e2eeec; border-radius: var(--radius-sm); font-family: inherit; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow-y: auto; }

/* Iconos SVG en línea ({% icon %}). El reset pone svg{display:block}, y un
   bloque no se centra con text-align ni se alinea a la línea base del texto
   que acompaña: esto lo devuelve al flujo. */
.icon { display: inline-block; vertical-align: -0.14em; flex: none; }
