/* ====================================================================
   Analogos · Lab Dies — Sistema de diseño del rediseño
   ====================================================================

   AESTHETIC: Clínica, calma, confianza.
   Inspirado en herramientas operativas (Linear, Height) aplicado a un
   contexto de laboratorio dental. Densidad alta sin ser ruidosa.

   Tipo: IBM Plex Sans (UI) + IBM Plex Mono (códigos)
   Color base: warm neutrals + un teal medical (sin azul corporativo)
   ==================================================================== */

:root {
  /* === COLORES === */
  --bg-app:        #fafaf7;
  --bg-surface:    #ffffff;
  --bg-sunken:     #f3f2ed;
  --bg-hover:      #f6f5f0;

  --border:        #e8e6e0;
  --border-strong: #d3d0c7;

  --text-1:        #0e1115;
  --text-2:        #4d5159;
  --text-3:        #8a8d93;
  --text-disabled: #b8b9bd;

  --accent:        oklch(0.48 0.06 200);   /* teal medical */
  --accent-hover:  oklch(0.42 0.07 200);
  --accent-soft:   oklch(0.95 0.02 200);
  --accent-on:     #ffffff;

  --warn:          oklch(0.65 0.14 65);    /* amber */
  --warn-soft:     oklch(0.96 0.05 80);
  --warn-text:     oklch(0.35 0.10 60);

  --danger:        oklch(0.55 0.18 25);
  --danger-soft:   oklch(0.96 0.04 25);
  --danger-text:   oklch(0.38 0.15 25);

  --ok:            oklch(0.55 0.11 150);
  --ok-soft:       oklch(0.95 0.04 150);
  --ok-text:       oklch(0.32 0.10 150);

  --info-soft:     oklch(0.95 0.03 240);
  --info-text:     oklch(0.35 0.10 240);

  /* === ESPACIO Y RADIO === */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(12, 16, 20, 0.04);
  --shadow-md: 0 4px 14px rgba(12, 16, 20, 0.06), 0 1px 3px rgba(12, 16, 20, 0.04);
  --shadow-lg: 0 16px 40px rgba(12, 16, 20, 0.10), 0 4px 10px rgba(12, 16, 20, 0.05);

  /* === TIPO === */
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

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

/* ============== APP SHELL ============== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  background: var(--bg-app);
}
.app.compact { grid-template-columns: 64px 1fr; }
.app.mobile  { grid-template-columns: 1fr; }

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.brand {
  padding: 20px 20px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--text-1);
  color: var(--bg-surface);
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.5px;
}
.brand-text { line-height: 1.15; }
.brand-text .name { font-weight: 600; font-size: 14px; }
.brand-text .sub  { font-size: 11px; color: var(--text-3); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 1px; }
.nav-section { padding: 14px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer; user-select: none;
  font-weight: 500;
  font-size: 13.5px;
  border: none; background: none;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-1); }
.nav-item.active {
  background: var(--bg-sunken);
  color: var(--text-1);
  font-weight: 600;
}
.nav-item .ico { width: 18px; height: 18px; flex: none; opacity: 0.85; }
.nav-item .badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--r-pill);
  min-width: 18px; text-align: center;
}
.nav-item .badge.warn { background: var(--warn); }
.nav-item .badge.muted { background: var(--bg-sunken); color: var(--text-2); }

.sidebar .quick-actions {
  margin-top: auto;
  padding: 14px 14px 16px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}

/* ============== MAIN ============== */
.main {
  overflow-y: auto;
  overflow-x: hidden;
}
.topbar {
  height: 56px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .crumbs { color: var(--text-3); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.topbar .crumbs .sep { opacity: 0.5; }
.topbar .crumbs .here { color: var(--text-1); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 12px;
  width: 320px;
  color: var(--text-3);
  font-size: 13px;
}
.topbar .search:focus-within { border-color: var(--border-strong); }
.topbar .search input {
  border: none; background: none; outline: none; flex: 1;
  color: var(--text-1);
}
.topbar .kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-3);
}

.page { padding: 28px 32px 80px; max-width: 1280px; }
.page-title { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-sub { color: var(--text-2); margin: 0 0 24px; font-size: 13.5px; }

/* ============== BUTTON ============== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-1);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-weight: 500;
  font-size: 13.5px;
  transition: background 80ms ease, border-color 80ms ease, transform 80ms ease;
  text-decoration: none;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--text-1); color: var(--bg-surface); border-color: var(--text-1); }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); color: var(--accent-on); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg-hover); }
.btn.danger { color: var(--danger-text); border-color: oklch(0.85 0.05 25); background: var(--danger-soft); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.lg { padding: 10px 18px; font-size: 14px; }
.btn.block { width: 100%; justify-content: center; }
.btn .ico { width: 14px; height: 14px; }

/* ============== CARD ============== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-head .sub { color: var(--text-3); font-size: 12.5px; }
.card-body { padding: 16px 18px; }
.card-body.tight { padding: 0; }

/* ============== STATS ============== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat .label { font-size: 12px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat .delta { font-size: 12px; color: var(--text-2); }
.stat .delta.up { color: var(--ok-text); }
.stat .delta.down { color: var(--danger-text); }

/* ============== TABLE ============== */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl th {
  font-weight: 500;
  color: var(--text-3);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* ============== PILL / TAG / BADGE ============== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-size: 11.5px;
  font-weight: 500;
  background: var(--bg-sunken);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.danger { background: var(--danger-soft); color: var(--danger-text); border-color: oklch(0.88 0.04 25); }
.pill.warn   { background: var(--warn-soft);   color: var(--warn-text);   border-color: oklch(0.90 0.04 70); }
.pill.ok     { background: var(--ok-soft);     color: var(--ok-text);     border-color: oklch(0.88 0.04 150); }
.pill.info   { background: var(--info-soft);   color: var(--info-text);   border-color: oklch(0.90 0.03 240); }
.pill.dot::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ============== INPUTS ============== */
.fld { display: flex; flex-direction: column; gap: 5px; }
.fld label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.input, .select, textarea.input {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 7px 11px;
  font-size: 13.5px;
  color: var(--text-1);
  outline: none;
  width: 100%;
  transition: border-color 80ms ease, box-shadow 80ms ease;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.lg { padding: 10px 14px; font-size: 15px; }

/* ============== KBD SHORTCUTS ============== */
.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-3);
}

/* ============== EMPTY STATE ============== */
.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty .ico { font-size: 28px; margin-bottom: 8px; opacity: 0.6; }

/* ============== UTILS ============== */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-20 { gap: 20px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; } .mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.flex { display: flex; } .grid { display: grid; }
.muted { color: var(--text-3); }
.dim   { color: var(--text-2); }
.bold  { font-weight: 600; }
.small { font-size: 12px; }
.center { text-align: center; }
.right  { text-align: right; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.tnum { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ============== ANIMACIÓN ============== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 200ms ease both; }

/* ============== SCROLL ============== */
.main::-webkit-scrollbar { width: 10px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.main::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============== MOBILE ============== */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 16px; height: 52px; }
  .topbar .search { width: 0; flex: 1; }
  .page { padding: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .value { font-size: 22px; }
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 8px 10px; }
}

/* ============== LOGIN ============== */
.login-bg {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #fafaf7 0%, #f1efe9 100%);
}
.login-card {
  width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 32px 28px;
  box-shadow: var(--shadow-md);
}
.pin-box {
  width: 56px; height: 64px;
  font-size: 28px; text-align: center;
  font-family: var(--font-mono); font-weight: 600;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg-surface);
  color: var(--text-1);
  outline: none;
  transition: border-color 100ms ease;
}
.pin-box:focus, .pin-box:not(:placeholder-shown) { border-color: var(--accent); }

/* ============== FLASH ============== */
.flash-zone { padding: 12px 28px 0; }
.flash {
  padding: 10px 14px;
  border-radius: var(--r-md);
  margin-bottom: 10px;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
}
.flash.ok    { background: var(--ok-soft);     color: var(--ok-text);     border-color: oklch(0.88 0.04 150); }
.flash.error { background: var(--danger-soft); color: var(--danger-text); border-color: oklch(0.88 0.04 25);  }
.flash.info  { background: var(--info-soft);   color: var(--info-text);   border-color: oklch(0.90 0.03 240); }

/* ============== GLOBAL SEARCH DROPDOWN ============== */
.search { position: relative; }
.search-dropdown {
  position: absolute; top: 100%; left: 0; right: 0;
  margin-top: 6px; z-index: 50;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  max-height: 480px; overflow-y: auto;
  color: var(--text-1);
}
.search-section-title {
  padding: 8px 14px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-3); font-weight: 600;
}
.search-result {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 14px;
  text-decoration: none; color: var(--text-1);
  cursor: pointer;
  border: none; background: transparent;
  width: 100%; text-align: left;
  font-family: inherit; font-size: inherit;
}
.search-result:hover, .search-result.is-focused { background: var(--bg-hover); }
.search-result .label { font-size: 13px; font-weight: 600; }
.search-result .meta  { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result .grow  { flex: 1; min-width: 0; }
.search-footer {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-3);
}

/* ============== AUTO-DISMISS FLASH ============== */
.flash-auto { transition: opacity 400ms ease; }

/* ============== STEPPER ============== */
.stepper {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
}
.stepper .step {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px;
  border: none; background: none; cursor: pointer;
  font-size: inherit;
  text-align: left; font-family: inherit;
}
.stepper .step .num {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  background: var(--bg-sunken); color: var(--text-2);
  border: 1px solid var(--border);
}
.stepper .step.active .num   { background: var(--text-1); color: #fff; border-color: var(--text-1); }
.stepper .step.done .num     { background: var(--ok); color: #fff; border-color: var(--ok); }
.stepper .step .lbl          { color: var(--text-3); font-weight: 500; }
.stepper .step.active .lbl   { color: var(--text-1); font-weight: 600; }
.stepper .step.done .lbl     { color: var(--text-2); font-weight: 500; }
.stepper .conn               { height: 1px; flex: 1; background: var(--border); }
.stepper .conn.done          { background: var(--ok); }

/* ============== SEGMENTED ============== */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 6px; overflow: hidden;
}
.segmented > * {
  padding: 5px 12px; font-size: 12.5px;
  border: none; background: transparent;
  cursor: pointer; color: var(--text-2);
  font-weight: 500; font-family: inherit;
  text-decoration: none;
}
.segmented > *:hover { background: var(--bg-hover); }
.segmented > *.active { background: var(--bg-sunken); color: var(--text-1); font-weight: 600; }

/* ============== URGENCY GROUP HEADER ============== */
.urgency-head {
  display: flex; align-items: center; gap: 8px;
  padding-left: 4px; margin-bottom: 8px; font-size: 13.5px; font-weight: 600;
}

/* ============== PICK CARD ============== */
.pick-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px;
  border: 1.5px solid var(--ok);
  background: var(--ok-soft);
  border-radius: 8px;
}
.pick-card.warn {
  border-color: var(--warn);
  background: var(--warn-soft);
}
.pick-card .label { font-size: 12px; color: var(--text-3); }
.pick-card .value { font-weight: 600; }

/* ============== AUTOCOMPLETE (inputs) ============== */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; left: 0; right: 0; top: 100%;
  margin-top: 4px; z-index: 30;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-height: 280px; overflow-y: auto;
}
.ac-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 14px; cursor: pointer;
  border: none; background: transparent;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px; font-family: inherit; color: var(--text-1);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.is-focused { background: var(--bg-hover); }
.ac-item .meta { color: var(--text-3); font-size: 12px; }
.ac-add {
  background: var(--warn-soft);
  color: var(--warn-text);
  font-weight: 500;
}
.ac-empty {
  padding: 10px 14px; color: var(--text-3); font-size: 12.5px; font-style: italic;
}

/* ============== RESULT LIST (catálogo / dueños en wizard) ============== */
.res-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 0;
}
.res-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-surface);
}
.res-row:last-child { border-bottom: none; }
.res-row:hover { background: var(--bg-hover); }
.res-row.selected { background: var(--accent-soft); }
.res-row .radio {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center; flex: none;
}
.res-row.selected .radio {
  background: var(--accent);
  border-color: var(--accent);
}
.res-row.selected .radio::after {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: #fff;
}
.res-row .grow { flex: 1; min-width: 0; }
.res-row .meta { color: var(--text-3); font-size: 12px; }

/* Sidebar mejorada: brand as anchor */
.brand { color: inherit; text-decoration: none; }
.brand:hover { text-decoration: none; }
