/* Cabinet La Bibliothèque — sistema de diseño v1.1
   Paleta: Encre #2C3E50 · Forêt #2D5A38 · Crème #F5EFE6 · Chêne #8B6340
   Tipografía: Cormorant Garamond (display) + DM Sans (interfaz)
   Dirección: herramienta clínica calma y precisa — mucho aire, jerarquía
   tipográfica clara, una sola capa de sombra, bordes finos cálidos. */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,500&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --encre: #23282E;
  --encre-soft: #4A525C;
  --azur: #05B6F3;
  --azur-hover: #0398CE;
  --azur-ink: #04769F;
  --azur-tint: #E4F5FD;
  --papier: #F7F3EC;
  --papier-deep: #EFE8DB;
  --chene: #8E8272;
  --chene-soft: #B3A996;
  --nuit: #191D22;
  --blanc: #FFFFFF;
  --borde: #E8E1D4;
  --borde-suave: #F1ECE1;
  --alerta: #C0452C;
  --alerta-bg: #FBEEEA;
  --ambar: #B07514;
  --ambar-bg: #FAF1DF;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, 'Segoe UI', sans-serif;

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --sombra: 0 1px 2px rgba(25, 29, 34, 0.04), 0 5px 18px rgba(25, 29, 34, 0.05);
  --transicion: 160ms ease;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--papier);
  color: var(--nuit);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; color: var(--encre); }
h1 {
  font-family: var(--font-display);
  font-size: 34px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.15;
}
h2 { font-family: var(--font-display); font-size: 24px; font-weight: 600; }
h3 { font-family: var(--font-body); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

.eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--chene); margin-bottom: 6px;
}

a { color: var(--azur); }

::selection { background: var(--azur); color: var(--blanc); }

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

/* ============ Layout del panel ============ */
.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: 232px;
  background: var(--blanc);
  border-right: 1px solid var(--borde-suave);
  color: var(--encre);
  display: flex;
  flex-direction: column;
  padding: 22px 12px 16px;
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 11px;
  padding: 2px 10px 22px; margin-bottom: 14px;
  border-bottom: 1px solid rgba(245,239,230,0.14);
}
.mark {
  width: 42px; height: 42px;
  background: var(--blanc);
  border: 1px solid var(--borde);
  border-radius: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  line-height: 1;
  color: var(--encre);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(25,29,34,0.06);
}
.mark img { width: 24px; height: auto; display: block; }
.sidebar-logo .name {
  font-family: var(--font-display); font-size: 17px; line-height: 1.2; font-weight: 500;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-sm);
  cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--encre-soft);
  border: none; background: none; width: 100%; text-align: left;
  font-family: var(--font-body);
  transition: background var(--transicion), color var(--transicion);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--papier); color: var(--encre); }
.nav-item.active { background: var(--azur-tint); color: var(--encre); position: relative; }
.nav-item.active::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--azur); }
.nav-item:focus-visible { outline: 2px solid var(--azur); outline-offset: -2px; }
.nav-spacer { flex: 1; }
.nav-item.nav-logout { color: var(--chene); }

.nav-badge {
  margin-left: auto; background: var(--azur); color: var(--blanc);
  font-size: 11px; min-width: 20px; text-align: center;
  padding: 1px 6px; border-radius: 10px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.main-content {
  flex: 1; padding: 40px 48px 72px; max-width: 1080px; width: 100%;
}

/* ============ Componentes ============ */
.card {
  background: var(--blanc);
  border: 1px solid var(--borde);
  border-radius: var(--r-md);
  box-shadow: var(--sombra);
}
.card-pad { padding: 22px 26px; }

.btn {
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  padding: 10px 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  line-height: 1.2; white-space: nowrap;
  transition: background var(--transicion), border-color var(--transicion), color var(--transicion), transform var(--transicion);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--azur); outline-offset: 2px; }
.btn-primary { background: var(--encre); color: var(--blanc); }
.btn-primary:hover { background: var(--nuit); }
.btn-secondary { background: var(--azur-tint); color: var(--azur-ink); }
.btn-secondary:hover { background: #D3EEFB; }
.btn-ghost { background: transparent; color: var(--encre-soft); border-color: var(--borde); }
.btn-ghost:hover { background: var(--papier); border-color: var(--chene-soft); color: var(--encre); }
.btn-danger { background: transparent; color: var(--alerta); border-color: transparent; }
.btn-danger:hover { background: var(--alerta-bg); }
.btn-sm { padding: 6px 12px; font-size: 13px; font-weight: 500; }

input, select, textarea {
  font-family: var(--font-body); font-size: 15px;
  padding: 10px 13px; border: 1px solid var(--borde);
  border-radius: var(--r-sm); background: var(--blanc); color: var(--nuit);
  width: 100%;
  transition: border-color var(--transicion), box-shadow var(--transicion);
}
input:hover, select:hover, textarea:hover { border-color: var(--chene-soft); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--azur);
  box-shadow: 0 0 0 3px rgba(45, 90, 56, 0.14);
}
textarea { resize: vertical; min-height: 76px; }
label { font-size: 13px; font-weight: 600; color: var(--encre); display: block; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-row > .field { min-width: 0; }
.field input, .field select, .field textarea { max-width: 100%; box-sizing: border-box; }

.check-inline {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; font-weight: 500; color: var(--nuit); cursor: pointer;
}
.check-inline input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--azur); flex-shrink: 0; }

/* --- Tags de estado --- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.01em;
  padding: 3px 11px; border-radius: 999px; white-space: nowrap;
}
.tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag-pendiente { background: var(--alerta-bg); color: var(--alerta); }
.tag-completo { background: var(--azur-tint); color: var(--azur-ink); }
.tag-seguimiento { background: #E9EEF6; color: #33507E; }
.tag-espera { background: var(--ambar-bg); color: var(--ambar); }
.tag-neutro { background: var(--papier-deep); color: var(--chene); }
.tag-neutro::before, .tag-espera::before { opacity: 0.7; }

/* --- Tablas --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r-md); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--chene); padding: 12px 16px;
  border-bottom: 1px solid var(--borde);
  background: #FDFBF7;
}
td { padding: 14px 16px; border-bottom: 1px solid var(--borde-suave); font-size: 14px; vertical-align: middle; }
tbody tr { transition: background var(--transicion); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #FBF7EF; }
td .btn { margin-right: 4px; }

/* --- Barra de búsqueda / filtros de sección --- */
.toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search-box svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--chene-soft); pointer-events: none;
}
.search-box input { padding-left: 36px; font-size: 14px; }

.pill-tabs { display: inline-flex; gap: 4px; background: var(--papier-deep); padding: 4px; border-radius: 999px; }
.pill-tab {
  padding: 6px 15px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; background: transparent; color: var(--chene);
  font-family: var(--font-body);
  transition: background var(--transicion), color var(--transicion);
}
.pill-tab:hover { color: var(--encre); }
.pill-tab.active { background: var(--blanc); color: var(--encre); box-shadow: 0 1px 3px rgba(44,62,80,0.12); }

/* --- Estados vacíos y carga --- */
.empty-state { text-align: center; padding: 56px 24px; }
.empty-state .empty-icon { font-size: 26px; margin-bottom: 10px; opacity: 0.5; }
.empty-state h3 { color: var(--encre); font-family: var(--font-display); font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.empty-state p { color: var(--chene); font-size: 14px; margin: 0; }

.skeleton-row {
  height: 52px; border-radius: var(--r-sm); margin-bottom: 10px;
  background: linear-gradient(90deg, var(--papier-deep) 25%, #F6F0E5 50%, var(--papier-deep) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- Toasts --- */
#toast-root { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--encre); color: var(--blanc); padding: 12px 18px;
  border-radius: var(--r-sm); font-size: 14px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(34,40,46,0.25);
  animation: toast-in 180ms ease;
  max-width: 340px;
}
.toast.error { background: var(--alerta); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Dashboard --- */
.dash-greeting { margin-bottom: 28px; }
.dash-greeting .fecha {
  font-size: 13px; color: var(--chene); margin-top: 4px;
  letter-spacing: 0.02em;
}
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.kpi-card {
  background: var(--blanc); border: 1px solid var(--borde); border-radius: var(--r-md);
  padding: 20px 22px 18px; cursor: pointer;
  transition: border-color var(--transicion), box-shadow var(--transicion), transform var(--transicion);
}
.kpi-card:hover { border-color: var(--chene-soft); box-shadow: var(--sombra); transform: translateY(-1px); }
.kpi-card:focus-visible { outline: 2px solid var(--azur); outline-offset: 2px; }
.kpi-value {
  font-family: var(--font-display); font-size: 40px; font-weight: 600;
  color: var(--encre); line-height: 1; font-variant-numeric: tabular-nums;
}
.kpi-value.alert { color: var(--alerta); }
.kpi-value.ok { color: var(--azur-ink); }
.kpi-label { font-size: 13px; color: var(--chene); margin-top: 8px; font-weight: 500; }

/* --- Modales --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(34,40,46,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px; backdrop-filter: blur(2px);
  animation: fade-in 140ms ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal {
  background: var(--blanc); border-radius: var(--r-lg);
  width: 100%; max-width: 580px; max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  padding: 28px 32px 30px;
  animation: modal-in 180ms ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
.modal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 20px;
}
.modal-close {
  background: none; border: none; font-size: 24px; line-height: 1;
  cursor: pointer; color: var(--chene-soft); padding: 2px 6px; border-radius: 6px;
  transition: color var(--transicion), background var(--transicion);
}
.modal-close:hover { color: var(--encre); background: var(--papier); }

/* --- Ficha de paciente --- */
.ficha-tags { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.ficha-actions { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.ficha-section { margin-top: 24px; padding-left: 14px; border-left: 2px solid var(--azur-tint); }
.ficha-section > h3 { margin-bottom: 12px; color: var(--azur); }
.ficha-section:first-of-type { margin-top: 0; }

.checklist-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 2px;
  border-bottom: 1px solid var(--borde-suave); font-size: 14px;
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--azur); cursor: pointer; flex-shrink: 0; }
.checklist-item.done span { color: var(--azur); }
.checklist-item.done span::after { content: ' ✓'; font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
.dato { font-size: 14px; }
.dato .dato-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--chene-soft); margin-bottom: 1px; }

.hint { font-size: 13px; color: var(--chene); margin-top: 4px; }

.section-title-row {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.section-title-row .btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Tareas (tablero) --- */
.tareas-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.tareas-col-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--chene); margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.tareas-col-title .count {
  background: var(--papier-deep); border-radius: 999px; padding: 0 8px;
  font-size: 11px; color: var(--encre-soft); font-variant-numeric: tabular-nums;
}
.tarea-card { margin-bottom: 10px; padding: 15px 17px; }
.tarea-desc { font-size: 14px; font-weight: 500; line-height: 1.45; }
.tarea-meta { font-size: 12px; color: var(--chene); margin-top: 8px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.tarea-meta .sep { opacity: 0.5; }
.tarea-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

/* --- Notas --- */
.nota-card { margin-bottom: 14px; }
.nota-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.nota-paciente { font-size: 16px; font-weight: 600; color: var(--encre); }
.nota-fecha { color: var(--chene); font-size: 13px; margin-left: 10px; }
.nota-body { background: var(--papier); border: 1px solid var(--borde-suave); border-radius: var(--r-sm); padding: 13px 15px; font-size: 13.5px; white-space: pre-wrap; line-height: 1.6; }
.nota-body.personal { background: var(--azur-tint); }

/* --- Login --- */
#login-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#login-card { width: 100%; max-width: 372px; text-align: center; padding: 40px 36px 36px; }
#login-card .mark { width: 52px; height: 52px; font-size: 21px; margin: 0 auto 18px; border-radius: 12px; }
#login-card h1 { font-size: 26px; margin-bottom: 4px; }
#login-card .login-sub { color: var(--chene); font-size: 13px; margin: 0 0 26px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 50;
    flex-direction: row; align-items: center; gap: 4px;
    padding: 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar-logo { padding: 0 8px 0 2px; margin: 0; border: none; }
  .sidebar-logo .name { display: none; }
  .mark { width: 32px; height: 32px; font-size: 13px; border-radius: 8px; }
  .nav-item { padding: 8px 12px; font-size: 13px; width: auto; flex-shrink: 0; }
  .nav-item svg { display: none; }
  .nav-spacer { display: none; }
  .main-content { padding: 22px 16px 60px; }
  h1 { font-size: 27px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 32px; }
  .field-row, .two-col { grid-template-columns: 1fr; }
  .tareas-board { grid-template-columns: 1fr; }
  .modal { padding: 22px 20px 24px; border-radius: var(--r-md); }
  .search-box { max-width: none; }
  #toast-root { left: 16px; right: 16px; bottom: 16px; }
  .toast { max-width: none; }
}

.btn-peligro { background: var(--alerta-bg); color: var(--alerta); }
.btn-peligro:hover { background: #F6DDD5; }

/* Notas colapsables en la ficha */
.export-notas { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.export-notas input[type="date"] { width: auto; padding: 7px 10px; border: 1px solid var(--borde); border-radius: var(--r-sm); font-family: var(--font-body); font-size: 13px; color: var(--encre); background: var(--blanc); }
.nota-item { border: 1px solid var(--borde); border-radius: var(--r-md); margin-bottom: 8px; background: var(--blanc); overflow: hidden; }
.nota-item summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 14px; transition: background var(--transicion); }
.nota-item summary::-webkit-details-marker { display: none; }
.nota-item summary::before { content: '▸'; color: var(--chene); font-size: 12px; transition: transform var(--transicion); flex-shrink: 0; }
.nota-item[open] summary::before { transform: rotate(90deg); }
.nota-item summary:hover { background: var(--papier); }
.nota-item summary strong { flex-shrink: 0; font-size: 14px; }
.nota-preview { flex: 1; min-width: 0; color: var(--chene); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nota-item[open] .nota-preview { visibility: hidden; }
.nota-item summary .tag { flex-shrink: 0; }
.nota-cuerpo { padding: 2px 16px 16px 34px; border-top: 1px solid var(--borde-suave); }
.nota-cuerpo .dato-label { margin-top: 12px; }
.nota-texto { font-size: 13.5px; white-space: pre-wrap; line-height: 1.65; margin: 0; }
