/* ─────────────────────────────────────────────────────────────
   Sistema de diseño — CRM OTR
   Molde replicable: para otro cliente solo se cambia --accent.

   Principios, tomados de los CRM que la gente usa a diario
   (Linear, Attio, Pipedrive):
   · Neutros de verdad, no azulados. La interfaz no compite con los datos.
   · Un solo acento, y se usa poco: si todo resalta, nada resalta.
   · Densidad alta pero legible — se leen listas largas todo el día.
   · Bordes antes que sombras. Las sombras solo para lo que flota.
   ───────────────────────────────────────────────────────────── */

:root {
  /* Neutros cálidos: menos clínicos que un gris azulado */
  --n-0:   #FFFFFF;
  --n-25:  #FAFBFA;
  --n-50:  #F4F7F5;
  --n-100: #ECF0EE;
  --n-150: #E2E8E4;
  --n-200: #D4DCD7;
  --n-300: #B8C2BC;
  --n-400: #8D9892;
  --n-500: #6C7771;
  --n-600: #505A54;
  --n-700: #38413C;
  --n-800: #252C28;
  --n-900: #151C18;

  --bg:          #EDF2EF;
  --surface:     var(--n-0);
  --surface-alt: var(--n-25);
  --border:      var(--n-150);
  --border-soft: var(--n-100);
  --border-strong: var(--n-200);

  --text:        var(--n-900);
  --text-muted:  var(--n-600);
  --text-faint:  var(--n-400);

  /* Acento: verde profundo, sobrio. Lo único con color en toda la interfaz. */
  --accent:      #0e8fa8;
  --accent-dark: #0b7285;
  --accent-soft: #E1F4F8;
  --accent-ring: rgba(14, 143, 168, .18);

  --ok:          #2F6B57;
  --ok-soft:     #EAF2EE;
  --warn:        #8A5A16;
  --warn-soft:   #FBF2E4;
  --danger:      #A33A32;
  --danger-soft: #FAECEA;

  --radius:      14px;
  --radius-sm:   10px;
  --radius-lg:   20px;

  /* Casi imperceptibles: el borde hace el trabajo */
  --shadow:     0 1px 2px rgba(22, 43, 34, .04), 0 6px 22px rgba(22, 43, 34, .05);
  --shadow-md:  0 2px 6px rgba(22, 43, 34, .05), 0 10px 28px rgba(22, 43, 34, .08);
  --shadow-lg:  0 12px 40px rgba(22, 43, 34, .16);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-w: 224px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

::selection { background: var(--accent-ring); }

/* ── Estructura ──────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 0 8px 16px; margin-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.brand-name { font-weight: 640; font-size: 15px; letter-spacing: -.01em; display: block; }
.brand-sub {
  font-size: 10.5px; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: .09em; margin-top: 3px; font-weight: 560;
}

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover { background: var(--n-50); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--n-100); color: var(--text); font-weight: 600; }
.nav .count {
  font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums;
  background: var(--n-100); border-radius: 20px; padding: 1px 7px;
}
.nav a.on .count { background: var(--n-0); }

.nav-grupo {
  font-size: 10.5px; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: .08em; font-weight: 600; padding: 14px 10px 4px;
}
.sidebar { overflow-y: auto; }

.sidebar-foot {
  margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border-soft);
  font-size: 11.5px; color: var(--text-faint);
}

.main { flex: 1; padding: 24px 28px 56px; min-width: 0; max-width: 1560px; }

/* ── Encabezado de página ────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1, .page-title {
  font-size: 22px; font-weight: 640; letter-spacing: -.02em; margin: 0;
}
.page-sub { color: var(--text-muted); font-size: 13px; margin: 3px 0 0; }

/* ── Tarjetas ────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-pad { padding: 16px 18px; }
.card-head {
  padding: 13px 18px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h2, .card-title {
  font-size: 14px; font-weight: 620; margin: 0; letter-spacing: -.01em;
}

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ── Indicadores ─────────────────────────────────────────── */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-label {
  font-size: 10.5px; color: var(--text-faint); text-transform: uppercase;
  letter-spacing: .08em; font-weight: 600; margin-bottom: 6px;
}
.stat-value {
  font-size: 26px; font-weight: 640; letter-spacing: -.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ── Tablas ──────────────────────────────────────────────── */
table, .tabla { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 10.5px; font-weight: 620; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .07em;
  padding: 9px 18px; border-bottom: 1px solid var(--border-soft);
  background: var(--surface-alt); white-space: nowrap;
}
td {
  padding: 10px 18px; border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px; vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--n-25); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: -.02em; }

/* ── Botones ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550; font-family: inherit;
  cursor: pointer; transition: background .12s ease, border-color .12s ease;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--n-50); border-color: var(--n-300); text-decoration: none; }
.btn:active { background: var(--n-100); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--n-100); color: var(--text); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Formularios ─────────────────────────────────────────── */
input[type=text], input[type=search], input[type=email], input[type=number],
input[type=password], input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 7px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text); font-size: 13.5px; font-family: inherit;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea { resize: vertical; min-height: 76px; line-height: 1.55; }
label {
  display: block; font-size: 12px; font-weight: 580; color: var(--text-muted);
  margin: 12px 0 5px;
}
label:first-child { margin-top: 0; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: 5px; line-height: 1.45; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row > .shrink { flex: 0 0 auto; }

/* ── Etiquetas ───────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 560;
  background: var(--n-100); color: var(--text-muted);
  border: 1px solid transparent; white-space: nowrap;
}
.chip-ok      { background: var(--ok-soft);     color: var(--ok); }
.chip-warn    { background: var(--warn-soft);   color: var(--warn); }
.chip-danger  { background: var(--danger-soft); color: var(--danger); }
.chip-accent  { background: var(--accent-soft); color: var(--accent); }
a.chip:hover { text-decoration: none; background: var(--n-150); }
a.chip.chip-accent:hover { background: var(--accent-soft); filter: brightness(.97); }

/* ── Avisos ──────────────────────────────────────────────── */
.alert {
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px;
  margin-bottom: 16px; border: 1px solid;
}
.alert-ok  { background: var(--ok-soft);   border-color: rgba(47,107,87,.2);  color: var(--ok); }
.alert-err { background: var(--danger-soft); border-color: rgba(163,58,50,.2); color: var(--danger); }
.alert-warn{ background: var(--warn-soft); border-color: rgba(138,90,22,.22); color: var(--warn); }

/* ── Estados vacíos ──────────────────────────────────────── */
.empty { text-align: center; padding: 40px 24px; color: var(--text-faint); }
.empty-title { font-weight: 600; color: var(--text-muted); margin-bottom: 4px; font-size: 14px; }

/* ── Barras de progreso ──────────────────────────────────── */
.bar {
  height: 6px; background: var(--n-100); border-radius: 4px;
  overflow: hidden; display: flex;
}
.bar span { display: block; height: 100%; border-radius: 4px; transition: width .3s ease; }

/* ── Búsqueda global ─────────────────────────────────────── */
.buscador { position: relative; margin-bottom: 14px; }
.buscador input { padding-left: 32px; background: var(--n-50); border-color: transparent; }
.buscador input:focus { background: var(--surface); }
.buscador::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-52%);
  color: var(--text-faint); font-size: 15px; pointer-events: none;
}
.buscador kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  font-family: var(--font); font-size: 10.5px; color: var(--text-faint);
  background: var(--n-0); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; pointer-events: none;
}

#paleta {
  position: fixed; inset: 0; background: rgba(26, 26, 22, .28);
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 14vh; z-index: 90; backdrop-filter: blur(2px);
}
#paleta.abierta { display: flex; }
.paleta-caja {
  width: min(560px, 92vw); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.paleta-caja input {
  border: none; border-bottom: 1px solid var(--border-soft); border-radius: 0;
  padding: 14px 16px; font-size: 15px;
}
.paleta-caja input:focus { box-shadow: none; border-color: var(--border-soft); }
.paleta-lista { max-height: 340px; overflow-y: auto; padding: 6px; }
.paleta-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 11px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
}
.paleta-item:hover, .paleta-item.sel { background: var(--n-100); }
.paleta-item small { color: var(--text-faint); font-size: 11.5px; }
.paleta-vacio { padding: 22px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ── Móvil ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--border); padding: 12px;
  }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { white-space: nowrap; }
  .nav-grupo { display: none; }
  .sidebar-foot { display: none; }
  .main { padding: 18px 16px 48px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  th, td { padding-left: 12px; padding-right: 12px; }
}

/* ── Módulos clínicos ────────────────────────────────────── */
.alertas { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-alerta { background: var(--danger-soft); color: var(--danger); font-weight: 620; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  padding: 8px 14px; font-size: 13.5px; color: var(--text-muted); font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.nota { border-bottom: 1px solid var(--border-soft); padding: 14px 18px; }
.nota:last-child { border-bottom: none; }
.nota-cab { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.nota dl { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 8px 0 0; font-size: 13.5px; }
.nota dt { color: var(--text-faint); font-size: 12px; font-weight: 600; padding-top: 2px; }
.nota dd { margin: 0; white-space: pre-wrap; }
.adenda { margin: 10px 0 0 14px; padding-left: 12px; border-left: 2px solid var(--border-strong); }
.fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding: 16px; }
.foto { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--n-50); }
.foto img { width: 100%; height: 140px; object-fit: cover; display: block; }
.foto div { padding: 6px 8px; font-size: 11.5px; color: var(--text-muted); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.check-grid label, label.check {
  display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 500; color: var(--text); font-size: 13px;
}
.check-grid input, label.check input { width: auto; margin: 0; }
.panel-lateral { position: sticky; top: 16px; }
.cifra { font-variant-numeric: tabular-nums; }
.btn-grabar.on { background: var(--danger); border-color: var(--danger); color: #fff; }
.respuesta { white-space: pre-wrap; line-height: 1.6; font-size: 14px; }
.respuesta h3 { font-size: 14px; margin: 14px 0 4px; }
@media print {
  .sidebar, .no-print, .alert { display: none !important; }
  .main { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
  body { background: #fff; }
}
