/* ==========================================================
   ESTILOS BASE Y LAYOUT
   ========================================================== */
:root {
  --primary-color: #007bff; /* Azul primario */
  --secondary-color: #6c757d; /* Gris secundario */
  --success-color: #28a745; /* Verde para éxito/salud */
  --danger-color: #dc3545; /* Rojo para peligro/caries */
  --warning-color: #ffc107; /* Amarillo para advertencia */
  --info-color: #17a2b8; /* Azul claro para info */
  --light-bg: #f8f9fa; /* Fondo claro de la aplicación */
  --dark-text: #343a40; /* Texto oscuro */
  --card-bg: white;
  --border-color: #e9ecef;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", sans-serif;
  background-color: var(--light-bg);
  color: var(--dark-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* --- Header --- */
header {
  background-color: var(--primary-color);
  color: white;
  padding: 15px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

/* --- Botones Genéricos --- */
.btn {
  padding: 10px 15px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition:
    background-color 0.2s,
    box-shadow 0.2s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.primary-btn {
  background-color: var(--primary-color);
  color: white;
}

.primary-btn:hover {
  background-color: #0056b3;
}

.secondary-btn {
  background-color: var(--secondary-color);
  color: white;
}

.secondary-btn:hover {
  background-color: #5a6268;
}

.danger-btn {
  background-color: var(--danger-color);
  color: white;
}

.danger-btn:hover {
  background-color: #c82333;
}

.success-btn {
  background-color: var(--success-color);
  color: white;
}

.success-btn:hover {
  background-color: #1e7e34;
}

.warning-btn {
  background-color: var(--warning-color);
  color: #212529;
}

.warning-btn:hover {
  background-color: #e0a800;
}

.info-btn {
  background-color: var(--info-color);
  color: white;
}

.info-btn:hover {
  background-color: #117a8b;
}

/* --- Mensajes de Feedback --- */
.message-box {
  padding: 10px;
  border-radius: 6px;
  margin-top: 15px;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.message-box.info {
  background-color: #d1ecf1;
  color: #0c5460;
  border-color: #bee5eb;
}

.message-box.success {
  background-color: #d4edda;
  color: #155724;
  border-color: #c3e6cb;
}

.message-box.expired {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

.message-box.expired {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

.message-box.error {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

.info-message {
  padding: 15px;
  background-color: var(--light-bg);
  border: 1px dashed var(--border-color);
  border-radius: 6px;
  color: var(--secondary-color);
  text-align: center;
}

/* ==========================================================
   AUTENTICACIÓN
   ========================================================== */
#auth-screen,
#verify-email-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 70px); /* Ajuste para el header */
  padding: 20px;
}

#verify-email-screen .auth-card {
  text-align: center;
}

#verify-email-screen .btn {
  width: 100%;
}

.auth-card {
  background-color: var(--card-bg);
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.auth-card hr {
  margin: 20px 0;
  border: 0;
  border-top: 1px solid var(--border-color);
}

/* ==========================================================
   APLICACIÓN PRINCIPAL (LAYOUT)
   ========================================================== */
.app-screen {
  display: flex;
  min-height: calc(100vh - 70px);
}

/* --- Sidebar (Navegación) --- */
.sidebar {
  width: 250px;
  background-color: var(--card-bg);
  padding: 20px 0;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

.tab-btn {
  background: none;
  border: none;
  text-align: left;
  padding: 15px 20px;
  color: var(--dark-text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition:
    background-color 0.2s,
    color 0.2s;
}

.tab-btn:hover {
  background-color: var(--light-bg);
}

.tab-btn.active {
  background-color: var(--primary-color);
  color: white;
  font-weight: 600;
}

.tab-btn.active:hover {
  background-color: var(--primary-color);
  color: white;
}

/* --- Área de Contenido --- */
.content-area {
  flex-grow: 1;
  padding: 30px;
  overflow-y: auto;
}

.tab-content h2 {
  margin-bottom: 25px;
  font-size: 1.8rem;
  color: var(--primary-color);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

/* ==========================================================
   FORMULARIOS Y LISTAS
   ========================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.form-card {
  background-color: var(--card-bg);
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
}

.form-card h3,
.form-card h4 {
  margin-top: 0;
  margin-bottom: 15px;
  color: var(--dark-text);
  font-size: 1.3rem;
}

label {
  display: block;
  margin-top: 10px;
  margin-bottom: 5px;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus,
textarea:focus {
  border-color: var(--primary-color);
  outline: none;
}

textarea {
  resize: vertical;
}

.list-container {
  margin-top: 20px;
}

.list-container h3 {
  margin-bottom: 15px;
  font-size: 1.5rem;
  color: var(--dark-text);
}

.data-list {
  list-style: none;
  padding: 0;
}

.data-list-item {
  background-color: var(--card-bg);
  padding: 15px 20px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: box-shadow 0.2s;
  position: relative; /* Para el menú de acciones */
}

.data-list-item:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.item-details {
  flex-grow: 1;
}

.item-details strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 5px;
  color: var(--primary-color);
}

.item-details span {
  display: inline-block;
  margin-right: 15px;
  font-size: 0.9rem;
  color: var(--secondary-color);
}

.item-details .notes {
  font-size: 0.9rem;
  color: #666;
  margin-top: 5px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.divider-v {
  width: 1px;
  height: 25px;
  background-color: var(--border-color);
  margin: 0 5px;
}

/* --- Tags de Estado --- */
.status-tag {
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-tag.suspended {
  background-color: var(--secondary-color);
  color: white;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  background: white;
  border-radius: 8px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.admin-controls {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.admin-search-box {
  flex-grow: 1;
  min-width: 300px;
  margin-bottom: 0 !important;
}

.admin-table th {
  background-color: var(--light-bg);
  color: var(--primary-color);
  font-weight: 600;
}

.info-tag {
  background-color: var(--info-color);
  color: white;
}
.success-tag {
  background-color: var(--success-color);
  color: white;
}
.danger-tag {
  background-color: var(--danger-color);
  color: white;
}
.warning-tag {
  background-color: var(--warning-color);
  color: #856404;
}

/* --- Menú de Citas (Acciones) --- */
.action-menu-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--secondary-color);
  padding: 8px 10px;
  border-radius: 50%;
}

.status-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  min-width: 200px;
  overflow: hidden;
  margin-top: 5px;
}

.status-menu a {
  display: block;
  padding: 10px 15px;
  text-decoration: none;
  color: var(--dark-text);
  font-size: 0.95rem;
  transition: background-color 0.2s;
}

.status-menu a:hover {
  background-color: var(--light-bg);
}

.status-menu a.danger-btn {
  color: var(--danger-color);
}

.status-menu .divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 5px 0;
}

/* ==========================================================
   HISTORIAL CLÍNICO Y PAGOS (SPLIT VIEW)
   ========================================================== */
.split-view {
  display: flex;
  gap: 20px;
}

.patient-selector-sidebar {
  width: 280px;
  flex-shrink: 0;
  background-color: var(--card-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
}

.patient-selector-sidebar h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 1.3rem;
  color: var(--primary-color);
}

.patient-selector-list {
  max-height: 600px;
  overflow-y: auto;
}

.patient-selector-item {
  padding: 10px;
  margin-bottom: 5px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition:
    background-color 0.2s,
    border-color 0.2s;
}

.patient-selector-item strong {
  display: block;
  font-weight: 600;
  color: var(--dark-text);
}

.patient-selector-item span {
  font-size: 0.85rem;
  color: var(--secondary-color);
}

.patient-selector-item:hover {
  background-color: var(--light-bg);
}

.patient-selector-item.selected-patient {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.patient-selector-item.selected-patient strong,
.patient-selector-item.selected-patient span {
  color: white;
}

.patient-record-details {
  flex-grow: 1;
}

/* --- Balance Card --- */
.balance-card {
  background-color: var(--card-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  border-left: 5px solid var(--primary-color);
}

.balance-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
}

.balance-summary span:first-child {
  font-size: 2rem;
  font-weight: 700;
  color: var(--dark-text);
}

/* --- Content Split (Records, Payments, New Record) --- */
.content-split-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 300px; /* 3 columnas: 1/3, 1/3, 1/3 más pequeño para el formulario */
  gap: 20px;
  margin-top: 20px;
}

.content-split-3 .list-container {
  margin-top: 0;
}

/* Asegura que el formulario se muestre como un solo bloque en la columna 1 */
.content-split-3 > .form-grid {
  display: block;
  gap: 0;
  margin-bottom: 0;
}

/* Asegura que el formulario de Nuevo Registro ocupe su columna completa */
.content-split-3 #new-record-form {
  grid-column: 3 / 4;
}

/* ==========================================================
   FICHA DENTAL (ODONTOGRAMA)
   ========================================================== */
.dental-chart-details {
  flex-grow: 1;
}

/* ==========================================================
   ODONTOGRAMA (Adultos / Niño, herramientas de estado, notas)
   ========================================================== */
:root {
  --st-caries: #dc3545;
  --st-filling: #0d6efd;
  --st-endodontics: #7c3aed;
  --st-crown: #4338ca;
  --st-fracture: #fd7e14;
  --st-abscess: #ffd60a;
  --st-extraction: #6c757d;
  --st-missing: #adb5bd;
}

#dental-chart-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* ---- Barra de herramientas ---- */
.odonto-toolbar {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.odonto-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.dentition-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #eaeff4;
  border-radius: 10px;
}
.dentition-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  color: var(--secondary-color);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dentition-tab:hover { color: var(--dark-text); }
.dentition-tab.active {
  background: #fff;
  color: var(--primary-color);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}
.dentition-count {
  background: var(--primary-color);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
}
.dentition-count[hidden] { display: none; }

#selected-tooth-status {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--dark-text);
}
.odonto-tools-label {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--secondary-color);
  margin-bottom: -6px;
}

#tooth-state-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}
.state-btn {
  --c: #6c757d;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1.5px solid var(--border-color);
  border-radius: 999px;
  background: #fff;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--dark-text);
  cursor: pointer;
  transition: all 0.15s;
}
.state-btn:hover {
  border-color: var(--c);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}
.state-btn .swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--c);
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.state-btn i { color: var(--c); }
.state-btn.active {
  background: var(--c);
  border-color: var(--c);
  color: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
}
.state-btn.active i { color: #fff; }
.state-btn.active .swatch { background: #fff; border-color: #fff; }

.state-btn.state-select { --c: #0d6efd; }
.state-btn.state-healthy { --c: #198754; }
.state-btn.state-caries { --c: var(--st-caries); }
.state-btn.state-filling { --c: var(--st-filling); }
.state-btn.state-endodontics { --c: var(--st-endodontics); }
.state-btn.state-crown { --c: var(--st-crown); }
.state-btn.state-fracture { --c: var(--st-fracture); }
.state-btn.state-abscess { --c: #e0b400; }
.state-btn.state-abscess.active { color: #3b2f00; }
.state-btn.state-abscess.active .swatch { background: #ffd60a; }
.state-btn.state-extraction { --c: var(--st-extraction); }
.state-btn.state-missing { --c: #868e96; }
.state-btn.state-clear { --c: #495057; margin-left: auto; }

/* Nota breve de la pieza */
.tooth-note-row {
  display: none;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #f8fafc;
  border: 1px dashed #c7d3de;
  border-radius: 10px;
  padding: 8px 10px;
}
.tooth-note-row.visible { display: flex; }
.tooth-note-row label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
.tooth-note-row input {
  flex: 1;
  min-width: 170px;
  margin: 0;
}
.tooth-note-row .btn { width: auto; margin: 0; }

/* ---- Lienzo del odontograma ---- */
.odontograma-scroll-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  border-radius: 14px;
}
.odontograma {
  --tool-color: #0d6efd;
  width: max-content;      /* no se comprime: si no cabe, scrollea el contenedor */
  min-width: 100%;
  padding: 18px 16px 14px;
  background: linear-gradient(180deg, #fbfdff 0%, #f1f6fa 100%);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(15, 40, 80, 0.06);
  box-sizing: border-box;
}
.arch-set { margin: 0 auto; width: max-content; max-width: none; }
.arch-set[hidden] { display: none; }

.arch { display: flex; justify-content: center; }
.quadrant { display: flex; gap: 4px; padding: 0 10px; }
.quadrant-1, .quadrant-4, .quadrant-5, .quadrant-8 { border-right: 2px solid #c9d6e2; justify-content: flex-end; }
.quadrant-2, .quadrant-3, .quadrant-6, .quadrant-7 { justify-content: flex-start; }

.arch-split {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--secondary-color);
  opacity: 0.7;
}
.arch-split::before, .arch-split::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #d5dee7;
}

/* ---- Pieza dental ---- */
.tooth-btn {
  --tooth-fill: #ffffff;
  --tooth-stroke: #aebccb;
  --root-fill: #f1f4f8;
  --root-stroke: #c3cfda;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 44px;
  padding: 3px 0 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  flex-shrink: 0;
}
.tooth-num {
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1;
  color: var(--secondary-color);
}
.tooth-svg {
  width: 38px;
  height: 57px;
  display: block;
  overflow: visible;
  transition: filter 0.15s;
}
.jaw-lower .tooth-svg { transform: scaleY(-1); }

.tooth-svg .t-crown {
  fill: var(--tooth-fill);
  stroke: var(--tooth-stroke);
  stroke-width: 1.6;
  stroke-linejoin: round;
}
.tooth-svg .t-root {
  fill: var(--root-fill);
  stroke: var(--root-stroke);
  stroke-width: 1.4;
  stroke-linejoin: round;
}
.tooth-svg .t-detail { fill: none; stroke: rgba(0, 0, 0, 0.15); stroke-width: 1.3; stroke-linecap: round; }
.tooth-svg .t-endo,
.tooth-svg .t-crack,
.tooth-svg .t-pus,
.tooth-svg .t-x { display: none; fill: none; }

.tooth-btn:hover { transform: translateY(-2px); }
.tooth-btn:hover .tooth-num { color: var(--tool-color); }
.tooth-btn:hover .tooth-svg { filter: drop-shadow(0 3px 5px rgba(15, 40, 80, 0.25)); }
.tooth-btn:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 1px; }

.tooth-btn.selected-tooth {
  background: rgba(13, 110, 253, 0.1);
  box-shadow: 0 0 0 2px var(--primary-color);
}
.tooth-btn.selected-tooth .tooth-num { color: var(--primary-color); }

/* Indicador de nota */
.tooth-note-dot {
  display: none;
  position: absolute;
  top: 14px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0d6efd;
  border: 2px solid #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}
.tooth-btn.has-note .tooth-note-dot { display: block; }

/* ---- Estados clínicos ---- */
.tooth-btn.state-caries { --tooth-fill: var(--st-caries); --tooth-stroke: #a11d2b; --root-fill: #f6d4d8; }
.tooth-btn.state-filling { --tooth-fill: var(--st-filling); --tooth-stroke: #0a4fb3; }
.tooth-btn.state-endodontics {
  --tooth-fill: var(--st-endodontics);
  --tooth-stroke: #5b21b6;
  --root-fill: #c4b5fd;
  --root-stroke: #6d28d9;
}
.tooth-btn.state-endodontics .t-endo { display: block; stroke: #3b0f8c; stroke-width: 3.2; stroke-linecap: round; }
.tooth-btn.state-crown { --tooth-fill: var(--st-crown); --tooth-stroke: #2c2689; }
.tooth-btn.state-crown .t-detail { stroke: rgba(255, 255, 255, 0.6); }
.tooth-btn.state-fracture { --tooth-fill: var(--st-fracture); --tooth-stroke: #b45309; }
.tooth-btn.state-fracture .t-crack { display: block; stroke: #4a1f00; stroke-width: 2; stroke-linejoin: round; }
.tooth-btn.state-abscess {
  --tooth-fill: var(--st-abscess);
  --tooth-stroke: #b58900;
  --root-fill: #ffe98a;
  --root-stroke: #d97706;
}
.tooth-btn.state-abscess .t-pus { display: block; fill: #d9480f; stroke: #fff; stroke-width: 1.5; }
.tooth-btn.state-extraction { --tooth-fill: #dee2e6; --tooth-stroke: #6c757d; --root-fill: #e9ecef; }
.tooth-btn.state-extraction .t-x { display: block; stroke: #c1121f; stroke-width: 4; stroke-linecap: round; }
.tooth-btn.state-missing .tooth-svg { opacity: 0.3; }
.tooth-btn.state-missing .t-crown,
.tooth-btn.state-missing .t-root { fill: transparent; stroke-dasharray: 3 3; }
.tooth-btn.state-missing .tooth-num { text-decoration: line-through; opacity: 0.6; }

/* ---- Leyenda ---- */
.odonto-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.8rem;
  color: var(--secondary-color);
  padding: 0 4px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.3);
}
.note-dot-demo {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0d6efd;
  border: 2px solid #fff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

@media (max-width: 768px) {
  .state-btn.state-clear { margin-left: 0; }
  .tooth-note-row input { min-width: 100%; }
}

/* ==========================================================
   REPORTES
   ========================================================== */
/* ==========================================================
   REPORTES - ESTILOS ADICIONALES
   ========================================================== */

.report-card {
  padding: 25px;
  border-radius: 8px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.report-card h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--primary-color);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.report-card .dashboard-grid {
  margin: 20px 0;
}

.report-card .content-split-3 {
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

.report-card .data-list {
  max-height: 300px;
  overflow-y: auto;
}

.report-card .data-list-item {
  padding: 10px 12px;
  margin-bottom: 5px;
}

@media (max-width: 992px) {
  .report-card .content-split-3 {
    grid-template-columns: 1fr;
  }
}

#export-csv-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

/* Mensaje de configuración de índices */
.index-config-message {
  background: #d1ecf1;
  border: 1px solid #bee5eb;
  border-radius: 6px;
  padding: 15px;
  margin: 15px 0;
}

.index-config-message ol {
  margin-left: 20px;
  font-size: 0.85rem;
}

.index-config-message code {
  display: block;
  margin: 10px 0;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 4px;
  font-size: 0.8rem;
  overflow-x: auto;
}

/* --- Estilos para Gráficos en Reportes --- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-top: 30px;
}

.chart-card {
  background: white;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  min-height: 350px;
}

.chart-card h4 {
  text-align: center;
  margin-bottom: 20px;
  color: var(--secondary-color);
}
/* ==========================================================
   DASHBOARD
   ========================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.summary-card {
  background-color: var(--card-bg);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  color: white; /* Texto blanco para las tarjetas de resumen */
  transition: transform 0.2s;
}

.summary-card:hover {
  transform: translateY(-5px);
}

.summary-card h3 {
  font-size: 1.1rem;
  margin-bottom: 5px;
  font-weight: 500;
  color: white; /* Asegurar color blanco */
}

.summary-card p {
  font-size: 2.5rem;
  font-weight: 700;
  margin-top: 10px;
}

.summary-card i {
  font-size: 1.8rem;
  float: right;
  opacity: 0.8;
}

/* Background Colors for Summary Cards (Reutilizando variables) */
.summary-card.primary-bg {
  background-color: var(--primary-color);
}
.summary-card.success-bg {
  background-color: var(--success-color);
}
.summary-card.danger-bg {
  background-color: var(--danger-color);
}
.summary-card.info-bg {
  background-color: var(--info-color);
}

/* La tarjeta de "Soporte Técnico" en Ayuda usa .info-bg sobre .form-card,
   no sobre .summary-card, así que necesita su propia regla de fondo para
   que el texto blanco sea legible (antes no tenía fondo y el texto blanco
   quedaba invisible sobre el fondo blanco de la tarjeta). */
.form-card.info-bg {
  background-color: var(--info-color);
  color: white;
}

.form-card.info-bg h3 {
  color: white;
}

/* Asegura que la lista en el dashboard ocupe todo el ancho */
.list-container.full-width {
  grid-column: 1 / -1; /* Ocupa todas las columnas en la cuadrícula */
}

/* --- Media Queries (Responsividad) --- */
@media (max-width: 992px) {
  .content-split-3 {
    grid-template-columns: 1fr;
  }

  .content-split-3 .list-container {
    margin-top: 30px;
  }

  .content-split-3 #new-record-form {
    grid-column: 1 / -1;
    margin-top: 20px;
  }
}

@media (max-width: 768px) {
  .app-screen {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    padding: 10px;
    justify-content: flex-start;
  }

  .tab-btn {
    padding: 10px 15px;
    white-space: nowrap;
  }

  .content-area {
    padding: 20px;
  }

  .split-view {
    flex-direction: column;
  }

  .patient-selector-sidebar {
    width: 100%;
  }

  /* Mostrar aviso de scroll solo en móviles */
  .mobile-odontograma-info {
    display: block !important;
  }

}

/* ==========================================================
   SISTEMA DE CALENDARIO TIPO AGENDA - VERSIÓN RESPONSIVA
   ========================================================== */

/* Mini Calendar (Dashboard) - Oculto en móvil */
.mini-calendar-container {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
}

.mini-calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.mini-calendar-header h4 {
  margin: 0;
  color: var(--primary-color);
  font-size: 1.1rem;
}

.mini-calendar-header .btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.mini-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-size: 0.75rem;
}

/* Full Calendar (Appointments section) */
.calendar-container {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.calendar-header h3 {
  margin: 0;
  color: var(--primary-color);
  font-size: 1.5rem;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 2px;
}

.weekday {
  padding: 10px 5px;
  text-align: center;
  font-weight: 600;
  background: var(--primary-color);
  color: white;
  border-radius: 4px;
  font-size: 0.9rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

/* Día del calendario - Base */
.calendar-day {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  min-height: 120px;
  padding: 8px;
  position: relative;
  cursor: pointer;
  transition: all 0.2s;
  overflow: hidden;
}

.calendar-day:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.calendar-day.empty {
  background: transparent;
  border: none;
  cursor: default;
}

.calendar-day.today {
  background: #e3f2fd;
  border-color: var(--primary-color);
  border-width: 2px;
}

.day-number {
  font-weight: 600;
  color: var(--dark-text);
  margin-bottom: 3px;
}

/* Contenedor de citas en cada día */
.day-appointments {
  margin-top: 5px;
}

/* Cita individual */
.appointment-item {
  font-size: 0.75rem;
  padding: 4px 6px;
  margin: 2px 0;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid;
  background: #f8f9fa;
  position: relative;
}

.appointment-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.appointment-item.status-pendiente {
  border-left-color: var(--info-color);
}
.appointment-item.status-confirmada {
  border-left-color: var(--warning-color);
}
.appointment-item.status-completada {
  border-left-color: var(--success-color);
}
.appointment-item.status-cancelada {
  border-left-color: var(--secondary-color);
  opacity: 0.6;
}

/* Insignia de estado dentro de la tarjeta móvil del "Calendario de Citas".
   Antes no tenía color propio (solo el borde izquierdo lo tenía), por eso
   se veía en texto plano en vez del mismo mostaza que usa la lista de arriba. */
.apt-status {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.apt-status.status-pendiente {
  background-color: var(--info-color);
  color: white;
}
.apt-status.status-confirmada {
  background-color: var(--warning-color);
  color: #856404;
}
.apt-status.status-completada {
  background-color: var(--success-color);
  color: white;
}
.apt-status.status-cancelada {
  background-color: var(--secondary-color);
  color: white;
}

.appointment-item .apt-time {
  font-weight: 600;
  color: var(--dark-text);
  margin-bottom: 1px;
}

.appointment-item .apt-patient {
  font-weight: 500;
  color: var(--primary-color);
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appointment-item .apt-service {
  font-size: 0.7rem;
  color: var(--secondary-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Menú contextual de citas */
.calendar-context-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  min-width: 180px;
  display: none;
}

.calendar-context-menu.active {
  display: block;
}

.calendar-context-menu .menu-item {
  display: block;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.calendar-context-menu .menu-item:hover {
  background: var(--light-bg);
}

.calendar-context-menu .menu-item.danger {
  color: var(--danger-color);
}

/* Botón flotante en móvil para alternar vista */
.mobile-view-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: var(--primary-color);
  color: white;
  padding: 12px 15px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  border: none;
  font-size: 1.2rem;
}

/* ==========================================
   RESPONSIVE - TABLET (768px - 992px)
   ========================================== */
@media (max-width: 992px) {
  .calendar-weekdays,
  .calendar-grid {
    grid-template-columns: repeat(7, 1fr);
  }

  .calendar-day {
    min-height: 100px;
    padding: 5px;
  }

  .appointment-item {
    font-size: 0.65rem;
    padding: 2px 4px;
  }

  .weekday {
    font-size: 0.8rem;
    padding: 8px 2px;
  }
}

/* ==========================================
   RESPONSIVE - SMARTPHONE (< 768px)
   ========================================== */
@media (max-width: 768px) {
  /* Ocultar mini calendario en dashboard */
  .mini-calendar-container {
    display: none;
  }

  /* Esta sección "Agenda del Mes" está pensada para el mini-calendario de
     escritorio (arriba). En móvil ya se oculta la cajita, pero el título
     se quedaba solo, viéndose como si faltara contenido. La ocultamos
     completa en móvil; las citas del mes ya se ven en la pestaña Citas. */
  #dashboard-agenda-section {
    display: none;
  }

  /* Convertir calendario full a lista */
  .calendar-weekdays {
    display: none; /* Ocultar nombres de días */
  }

  .calendar-grid {
    grid-template-columns: 1fr; /* Una sola columna */
    gap: 10px;
  }

  .calendar-day {
    min-height: auto;
    max-height: 200px;
    padding: 10px;
    cursor: default;
  }

  /* Las tarjetas de día en vista lista (móvil) NO deben heredar el límite
     de 200px de arriba (eso era para las celdas chiquitas del grid de
     escritorio). Por eso se cortaban citas y se veía el texto incompleto
     cuando había más de 2 citas en el mismo día. */
  .calendar-day.mobile-day-card {
    max-height: none;
    overflow: visible;
  }

  .calendar-day.empty {
    display: none; /* Ocultar días vacíos */
  }

  .day-number {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--primary-color);
  }

  .day-appointments {
    max-height: 150px;
    overflow-y: auto;
  }

  .appointment-item {
    font-size: 0.8rem;
    padding: 6px 8px;
    margin: 3px 0;
  }

  .appointment-item .apt-service {
    display: block; /* Mostrar servicio en móvil */
    margin-top: 2px;
  }

  /* Botón flotante */
  /* Este botón flotante nunca quedó conectado a ninguna acción (no tiene
     "escuchador de clic" en el código) — por eso no hacía nada al tocarlo.
     Se oculta por ahora para no confundir; se puede conectar a una función
     real (por ejemplo, ir directo a "Nueva cita") en otro momento. */
  .mobile-view-toggle {
    display: none;
  }

  /* Ajustar header del calendario */
  .calendar-header {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .calendar-header .btn {
    width: 100%;
    margin: 5px 0;
  }
}

/* Tooltip para citas */
.appointment-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  z-index: 1001;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  max-width: 250px;
  white-space: normal;
}

.appointment-tooltip.active {
  opacity: 1;
}

/* Loading state */
.calendar-loading {
  text-align: center;
  padding: 40px;
  color: var(--secondary-color);
}

.calendar-loading i {
  font-size: 2rem;
  margin-bottom: 10px;
}

/* ==========================================================
   AGREGADO PARA EL BUSCADOR DE PACIENTES EN HISTORIAL Y DENTAL
   ========================================================== */
.patient-search-input {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px; /* Separación de la lista */
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.patient-search-input:focus {
  border-color: var(--primary-color);
  outline: none;
}

/* ==========================================================
   SECCIÓN DE AJUSTES DE CONFIGURACIÓN
   ========================================================== */

.settings-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  margin-top: 20px;
}

.settings-sidebar {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 15px;
  height: fit-content;
}

.settings-menu-item {
  padding: 12px 15px;
  margin-bottom: 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-weight: 500;
}

.settings-menu-item:hover {
  background-color: var(--light-bg);
  border-color: var(--primary-color);
}

.settings-menu-item.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.settings-content {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 25px;
}

.settings-panel {
  display: none;
}

.settings-panel h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--primary-color);
  font-size: 1.4rem;
}

/* Formulario de Horario */
.horario-grid {
  display: grid;
  gap: 15px;
}

.dia-item {
  display: grid;
  /* Col 1: Checkbox, Col 2: Label, Col 3-5: Horarios */
  grid-template-columns: auto 1fr 1fr auto 1fr;
  align-items: center;
  gap: 15px; /* Aumentamos el espacio para un look más limpio */
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: #fff; /* Fondo blanco para destacar */
  transition: box-shadow 0.2s;
}

.dia-item:hover {
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08); /* Sombra sutil al pasar el mouse */
}

.dia-item .dia-checkbox {
  justify-self: center; /* Centra el checkbox en su celda */
  width: 18px; /* Tamaño consistente */
  height: 18px;
}

.dia-item label {
  margin: 0;
  font-weight: 600;
}

.dia-item input[type="time"] {
  padding: 8px;
  margin: 0;
  width: 100%;
}

/* Formulario de WhatsApp */
#whatsapp-status {
  padding: 15px;
}

/* Plantillas de Mensajes */
.plantilla-item {
  margin-bottom: 20px;
}

.plantilla-item label {
  font-weight: 600;
  margin-bottom: 8px;
}

.plantilla-item textarea {
  margin-bottom: 5px;
}

.plantilla-item small {
  display: block;
  color: var(--secondary-color);
  font-size: 0.85rem;
  margin-top: 5px;
}

/* Toggle Switches */
.toggle-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px;
  margin-bottom: 10px;
  background: var(--light-bg);
  border-radius: 6px;
}

.toggle-info {
  flex-grow: 1;
}

.toggle-info p {
  margin: 5px 0 0 0;
  font-size: 0.9rem;
  color: var(--secondary-color);
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: var(--success-color);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.slider.round {
  border-radius: 24px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Vista Previa de Plantillas */
.template-preview {
  background: #e8f4fd;
  border: 1px solid var(--primary-color);
  border-radius: 6px;
  padding: 15px;
  margin-top: 10px;
}

/* Responsive */
@media (max-width: 992px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-sidebar {
    display: flex;
    overflow-x: auto;
    padding: 10px;
  }

  .settings-menu-item {
    white-space: nowrap;
    margin-bottom: 0;
    margin-right: 8px;
  }

  .dia-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .dia-item .dia-checkbox {
    justify-self: start; /* En móvil, alineado a la izquierda igual que el texto */
  }
}

/* ==========================================================
   ESTILOS PARA VIDEOS TUTORIALES
   ========================================================== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px;
  margin-top: 15px;
}

.video-container {
  position: relative;
  padding-bottom: 56.25%; /* Proporción 16:9 */
  height: 0;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  background-color: #000; /* Fondo negro mientras carga */
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Mejora visual para el formulario de clínica */
#clinica-form .form-card h3 {
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 10px;
  margin-bottom: 20px;
}

#clinica-form h4 {
  color: var(--secondary-color);
  margin: 25px 0 15px 0;
  font-size: 1.2rem;
}

/* Botón de WhatsApp */
#whatsapp-button-container {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: 6px;
  padding: 15px;
  margin-top: 15px;
}

#send-whatsapp-btn {
  background: #25d366; /* Color oficial de WhatsApp */
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

#send-whatsapp-btn:hover {
  background: #128c7e;
}

/* --- Galería de Archivos --- */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 15px;
  margin-top: 15px;
}

.file-card {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  transition: transform 0.2s;
}

.file-card:hover {
  transform: scale(1.05);
}

.file-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 8px;
  cursor: pointer;
}

/* Mensaje de advertencia cuando no hay teléfono */
.message-box.warning {
  background-color: #fff3cd;
  color: #856404;
  border-color: #ffeaa7;
}

/* --- Estilos Ayuda --- */
.help-list {
  list-style: none;
  padding: 0;
}

.help-list li {
  margin-bottom: 12px;
  padding-left: 25px;
  position: relative;
  font-size: 0.95rem;
}

.help-list li i,
.help-list li::before {
  position: absolute;
  left: 0;
  top: 4px;
  color: var(--primary-color);
}

/* ==========================================================
   ESTILOS DE IMPRESIÓN (PARA REPORTES PDF)
   ========================================================== */
@media print {
  header,
  .sidebar,
  .btn,
  .form-grid,
  .message-box,
  .mobile-view-toggle,
  .patient-selector-sidebar {
    display: none !important;
  }

  body {
    background-color: white !important;
  }

  .content-area {
    padding: 0 !important;
    margin: 0 !important;
  }

  .report-card {
    box-shadow: none !important;
    border: none !important;
    width: 100% !important;
  }

  .report-header-print {
    display: flex !important;
  }

  .report-controls {
    display: none !important;
  }

  .charts-grid {
    grid-template-columns: 1fr !important; /* Una gráfica debajo de otra en el PDF */
  }
}

/* ==========================================================
   PACIENTES: CABECERA + MODALES (formulario y expediente)
   ========================================================== */
.patients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.patients-header h2 { margin: 0; }
.patients-count {
  font-size: 0.9rem;
  color: var(--secondary-color);
  font-weight: 400;
}

body.app-modal-open { overflow: hidden; }

.app-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.app-modal.open { display: flex; }
.app-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(33, 37, 41, 0.55);
}
.app-modal-box {
  position: relative;
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.app-modal-box h3 { margin-top: 0; padding-right: 36px; }
.app-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--secondary-color);
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 2;
}
.app-modal-close:hover { background: var(--light-bg); }

/* Formulario de paciente */
.app-modal-sm .btn { width: 100%; }

/* ---- Expediente ---- */
.exp-box {
  max-width: 1100px;
  height: 92vh;
  max-height: 92vh;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* el scroll vive en .exp-body */
}
.exp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 60px 8px 24px;
  position: relative;
}
.exp-header .app-modal-close { top: 14px; right: 16px; }
.exp-heading h3 { margin: 0; padding: 0; font-size: 1.35rem; }
.exp-heading small { color: var(--secondary-color); }

.exp-tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 2px solid var(--border-color);
}
.exp-tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--secondary-color);
  cursor: pointer;
}
.exp-tab:hover { color: var(--dark-text); }
.exp-tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

#expediente-message { margin: 10px 24px 0; }

.exp-body {
  flex: 1;
  min-height: 0;          /* permite que el flex hijo haga scroll */
  overflow-y: auto;
  overflow-x: hidden;     /* el scroll horizontal es solo del odontograma */
  padding: 16px 24px 24px;
  -webkit-overflow-scrolling: touch;
}
.exp-pane { min-width: 0; }
.exp-subtitle { margin: 0 0 12px; font-size: 1.05rem; }

.exp-forms-row,
.exp-lists-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}
.exp-forms-row > .form-grid { display: block; margin: 0; }
.exp-forms-row .form-card { height: 100%; }
.exp-lists-row .list-container { margin-top: 0; min-width: 0; }
.exp-box .data-list { max-height: 320px; overflow-y: auto; }

/* El odontograma conserva su propio scroll horizontal */
#exp-pane-dental #dental-chart-container { min-width: 0; }
#exp-pane-dental .odontograma-scroll-container {
  max-width: 100%;
  overflow-x: auto;
}

@media (max-width: 768px) {
  .app-modal { padding: 0; align-items: stretch; }
  .app-modal-box { max-width: 100%; max-height: 100%; border-radius: 0; padding: 20px 16px; }
  .exp-box { height: 100%; max-height: 100%; }
  .exp-header { padding: 14px 52px 6px 16px; }
  .exp-tabs { padding: 0 8px; }
  .exp-tab { flex: 1; padding: 10px 6px; font-size: 0.9rem; }
  .exp-body { padding: 12px 12px 20px; }
  #expediente-message { margin: 8px 12px 0; }
  .exp-forms-row,
  .exp-lists-row { grid-template-columns: 1fr; }
  .patients-header .btn { width: 100%; }
}

/* ==========================================================
   DOCTORES Y SILLONES (Configuraciones) + RECURSOS EN CITAS
   ========================================================== */
.team-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 20px;
  align-items: start;
}
.team-grid .list-container { margin-top: 0; min-width: 0; }
.color-input {
  width: 64px;
  height: 38px;
  padding: 2px;
  cursor: pointer;
  margin-bottom: 15px;
}
.color-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: -1px;
  border: 1px solid rgba(0, 0, 0, 0.3);
}
.data-list-item.is-inactive { opacity: 0.6; }
.doctor-item .item-actions,
.chair-item .item-actions { flex-wrap: wrap; justify-content: flex-end; }
.doctor-item .btn,
.chair-item .btn { width: auto; margin: 0; }
#doctor-cancel-btn,
#chair-cancel-btn { margin-top: 8px; }

.resources-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.resources-row > div { min-width: 0; }

.apt-resources { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.apt-resource { display: inline-flex; align-items: center; font-size: 0.85rem; }
.apt-resource.muted { color: var(--secondary-color); font-style: italic; }
.apt-resources:empty { display: none; }

@media (max-width: 768px) {
  .team-grid { grid-template-columns: 1fr; }
  .resources-row { grid-template-columns: 1fr; gap: 0; }
}

/* ==========================================================
   LISTAS: BUSCADOR + FILTRO DE ESTADO (Pacientes / Servicios)
   ========================================================== */
.list-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  align-items: center;
}
.list-toolbar input { flex: 1; min-width: 0; margin-bottom: 0; }
.status-filter-select {
  width: auto;
  min-width: 130px;
  margin: 0;
  padding: 8px 10px;
}
.inactive-tag { margin-left: 6px; font-size: 0.7rem; vertical-align: middle; }
.data-list-item.is-inactive .item-details strong { text-decoration: none; }
.patient-item .item-actions,
.service-item .item-actions { flex-wrap: wrap; justify-content: flex-end; }
.service-item .item-actions .btn { width: auto; margin: 0; }

@media (max-width: 768px) {
  .list-toolbar { flex-wrap: wrap; }
  .status-filter-select { flex: 1 1 100%; }
}

/* ==========================================================
   PRESUPUESTOS (pestaña del expediente + editor + lista)
   ========================================================== */
.budgets-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.budgets-toolbar .exp-subtitle { margin: 0; }
.budgets-toolbar .btn { width: auto; margin: 0; }

.budget-item .item-actions { flex-wrap: wrap; justify-content: flex-end; }
.budget-item .item-actions .btn { width: auto; margin: 0; }
.budget-total-text { font-weight: 700; color: var(--dark-text); }
.budget-status-select {
  width: auto;
  min-width: 112px;
  margin: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
}

/* ---- Editor (submodal sobre el expediente) ---- */
.budget-box { max-width: 920px; }
.budget-head-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0 14px;
}
.budget-head-grid > div { min-width: 0; }
.budget-head-grid input[readonly] { background: #f1f4f8; color: var(--secondary-color); }

.budget-items-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 8px;
}
.budget-items-title h4 { margin: 0; }
.budget-items-title small { color: var(--secondary-color); }

.budget-items-table { border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; }
.budget-item-row {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(0, 0.9fr) minmax(0, 0.7fr) minmax(0, 1.1fr) minmax(0, 1.2fr) 40px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
}
.budget-item-row:last-child { border-bottom: 0; }
.budget-item-header {
  background: #eef3f8;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--secondary-color);
}
.budget-item-row input { margin: 0; width: 100%; min-width: 0; }
.bi-subtotal-value { display: block; text-align: right; font-weight: 600; white-space: nowrap; }
.bi-remove-btn { width: 34px; height: 34px; padding: 0; margin: 0; }
.budget-add-btn { width: auto; margin: 10px 0 0; }

.budget-totals { width: min(100%, 360px); margin: 16px 0 12px auto; }
.budget-total-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 4px;
}
.budget-discount-inputs { display: inline-flex; gap: 6px; margin-left: auto; }
.budget-discount-inputs select { width: 90px; margin: 0; padding: 5px 6px; }
.budget-discount-inputs input { width: 90px; margin: 0; padding: 5px 6px; }
.budget-grand-total {
  border-top: 2px solid var(--dark-text);
  margin-top: 6px;
  padding-top: 8px;
  font-size: 1.15rem;
}
.budget-print-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 14px;
  font-weight: 600;
  cursor: pointer;
}
.budget-print-check input { width: auto; margin: 0; }
.budget-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.budget-actions .btn { width: auto; flex: 1 1 160px; margin: 0; }

@media (max-width: 768px) {
  .budget-item-header { display: none; }
  .budget-item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding: 12px 10px;
  }
  .bi-name { grid-column: 1 / -1; }
  .bi-cell[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--secondary-color);
    margin-bottom: 2px;
  }
  .bi-subtotal-value { text-align: left; }
  .bi-remove { grid-column: 1 / -1; }
  .bi-remove-btn { width: 100%; }
  .budget-totals { width: 100%; }
}
@media (max-width: 480px) {
  .exp-tab { font-size: 0.78rem; }
  .exp-tab i { display: none; }
}

/* ---- Desplegable de servicios del editor de presupuestos ---- */
.budget-suggest {
  position: fixed;
  z-index: 5;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 40, 80, 0.22);
  overflow-y: auto;
}
.budget-suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f2f5;
}
.budget-suggest-item:last-child { border-bottom: 0; }
.budget-suggest-item:hover,
.budget-suggest-item.active { background: #e7f1ff; }
.bs-name { font-weight: 600; color: var(--dark-text); min-width: 0; overflow-wrap: anywhere; }
.bs-price { color: var(--primary-color); font-weight: 700; white-space: nowrap; }

/* ==========================================================
   REPORTES: FILTROS, TABLAS, PRODUCCIÓN Y COMISIONES
   ========================================================== */
.report-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 14px;
  align-items: end;
}
.report-filter label { margin-bottom: 4px; font-size: 0.85rem; }
.report-filter input,
.report-filter select { margin-bottom: 0; }
.report-filter-actions .btn { width: 100%; margin: 0; }
#report-loading { grid-column: 1 / -1; }
.report-note {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--secondary-color);
  min-height: 1em;
}
.report-note:empty { display: none; }

.report-card .summary-card p { font-size: 1.7rem; word-break: break-word; }
.report-card .summary-card h3 { font-size: 1rem; }
.summary-card.warning-bg { background-color: #e0a800; }
.summary-card.secondary-bg { background-color: var(--secondary-color); }

.report-section { margin-top: 26px; }
.report-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--dark-text);
}
.report-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.report-section-head h4 { margin: 0; }
.report-sort { display: inline-flex; gap: 6px; }
.report-sort .btn { width: auto; margin: 0; padding: 4px 10px; font-size: 0.8rem; }
.report-sort .btn.active { background: var(--primary-color); color: #fff; border-color: var(--primary-color); }

.report-table-wrap { overflow-x: auto; border: 1px solid var(--border-color); border-radius: 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 560px; }
.report-table th {
  background: #eef3f8;
  text-align: left;
  padding: 9px 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--secondary-color);
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}
.report-table td { padding: 9px 10px; border-bottom: 1px solid #edf0f4; }
.report-table tbody tr:hover { background: #f8fbff; }
.report-table .num { text-align: right; white-space: nowrap; }
.report-table tfoot td { font-weight: 700; background: #f6f8fb; border-top: 2px solid var(--border-color); }
.report-table td .status-tag { margin-left: 6px; }

.report-two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 26px;
}
.report-two-cols .report-section { margin-top: 0; min-width: 0; }
.report-status-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.report-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--light-bg);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
}
.report-chip b { font-size: 1rem; }
.report-controls-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.report-controls-actions .btn { width: auto; margin: 0; }
.report-warning {
  margin: 14px 0;
  padding: 12px 14px;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  font-size: 0.88rem;
}

@media (max-width: 992px) {
  .report-two-cols { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .report-filters { grid-template-columns: 1fr 1fr; }
  .report-filter-actions { grid-column: 1 / -1; }
}

/* ---- Filtro "Con saldo" y etiqueta de deuda en pacientes ---- */
.debt-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.debt-filter input { width: auto; margin: 0; }
.patient-debt-tag { color: var(--danger-color); font-weight: 700; }

/* ---- Reportes: los gráficos se conservan si se imprime la página directamente (Ctrl+P) ---- */
@media print {
  .report-card,
  .chart-card {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .chart-card {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .chart-card canvas {
    max-width: 100% !important;
    height: auto !important;
  }
  .report-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
