:root {
  --primary: #1565C0;
  --primary-light: #1E88E5;
  --primary-lighter: #42A5F5;
  --accent: #FFFFFF;
  --bg: #FFFFFF;
  --bg-soft: #F0F7FF;
  --text: #1A1A2E;
  --text-muted: #546E7A;
  --success: #2E7D32;
  --warning: #F57F17;
  --danger: #C62828;
  --border: #BBDEFB;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}

header {
  background: var(--primary);
  color: var(--accent);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  margin: 0;
}

button {
  background: var(--primary);
  color: var(--accent);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: var(--primary-light);
}

input, select, textarea {
  text-transform: uppercase;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F8FBFF;
}

.login-panel {
  display: grid;
  grid-template-columns: 280px 1fr;
  width: min(100%, 900px);
  background: var(--accent);
  border-radius: 24px;
  box-shadow: 0 30px 60px rgba(21, 101, 192, 0.12);
  overflow: hidden;
}

.login-side {
  background: var(--primary);
  color: var(--accent);
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
}

.login-side h1 {
  margin: 0;
  font-size: 2rem;
}

.login-logo {
  width: 100%;
  max-width: 170px;
  object-fit: contain;
  margin-bottom: 0.5rem;
}

.login-side p {
  margin: 0;
  color: #ffffff;
  font-size: 1.15rem;
}

.sidebar-logo {
  width: 100%;
  max-width: 150px;
  object-fit: contain;
  margin-bottom: 0.25rem;
}

.login-form-card {
  padding: 3rem;
}

.login-form-card h2 {
  margin: 0 0 1rem;
}

.login-form-card label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-form-card input {
  margin-bottom: 1rem;
  background-color: var(--primary);
  color: var(--accent);
  border: 2px solid var(--primary-light);
  font-size: 12px;
}

.login-form-card input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.login-form-card input:focus {
  outline: none;
  border: 2px solid var(--primary-lighter);
  background-color: var(--primary-light);
}

.form-message {
  margin-top: 1rem;
  color: var(--danger);
  min-height: 1.2rem;
}

button,
input[type="submit"] {
  font-family: inherit;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

th {
  background: var(--bg-soft);
  cursor: pointer;
}

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: var(--bg);
  padding: 1.25rem 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-content h2 {
  color: var(--text);
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

.modal-content label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-weight: 500;
}

.close {
  float: right;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--text);
}

form div {
  margin-bottom: 0.65rem;
}

/* Terapias - lista compacta con tooltip */
.therapy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.therapy-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
  flex: 1;
  margin: 0;
}

.therapy-label input[type="checkbox"] {
  width: auto;
  padding: 0;
  border: none;
  background: none;
  margin: 0;
  accent-color: var(--primary-lighter);
}

.therapy-info-btn {
  cursor: help;
  color: var(--primary-lighter);
  font-size: 0.85rem;
  font-style: normal;
  border: 1px solid var(--primary-lighter);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.therapy-info-btn::after {
  content: attr(data-tip);
  position: absolute;
  right: 1.5rem;
  top: -0.25rem;
  background: #1A1A2E;
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.78rem;
  width: 200px;
  white-space: normal;
  line-height: 1.4;
  z-index: 9999;
  display: none;
  pointer-events: none;
}

.therapy-info-btn:hover::after {
  display: block;
}

label {
  display: block;
  margin-bottom: 0.5rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
}

/* Estilos para inputs en modales */
.modal-content input,
.modal-content select,
.modal-content textarea {
  background-color: var(--primary);
  color: var(--accent);
  border: 2px solid var(--primary-light);
  font-size: 12px;
}

.modal-content input::placeholder,
.modal-content textarea::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.modal-content input:focus,
.modal-content select:focus,
.modal-content textarea:focus {
  outline: none;
  border: 2px solid var(--primary-lighter);
  background-color: var(--primary-light);
}

/* Datalist para autocompletar */
.datalist-container {
  position: relative;
  display: inline-block;
  width: 100%;
}

#patientResults,
#aptSearchResults,
#docResults,
#diagResults {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--primary);
  border: 2px solid var(--primary-light);
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 1000;
  max-height: 200px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 0.75rem;
  color: var(--accent);
  cursor: pointer;
  border-bottom: 1px solid var(--primary-light);
  font-size: 12px;
}

.autocomplete-item:hover {
  background-color: var(--primary-light);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.login-container {
  max-width: 400px;
  margin: 100px auto;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
}

/* Dashboard layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--primary);
  color: var(--accent);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.8rem;
}

.brand p {
  margin: 0.3rem 0 0;
  color: #ffffff;
  font-size: 1rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-nav a {
  color: var(--accent);
  text-decoration: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.sidebar-nav a.active,
.sidebar-nav a:hover {
  background: rgba(255,255,255,0.12);
}

.sidebar-logout {
  margin-top: auto;
  width: 100%;
  background: rgba(255,255,255,0.12);
}

.main-content {
  flex: 1;
  background: #F7FAFC;
  padding: 1.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.topbar h2 {
  margin: 0;
  font-size: 2rem;
}

.subtitle {
  margin: 0.5rem 0 0;
  color: #ffffff;
  font-size: 1.05rem;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--accent);
  padding: 1.25rem;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(21, 101, 192, 0.08);
}

.card span {
  display: block;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.card strong {
  display: block;
  font-size: 2.2rem;
}

.card-primary {
  border-left: 5px solid var(--primary);
}

.card-success {
  border-left: 5px solid var(--success);
}

.card-warning {
  border-left: 5px solid var(--warning);
}

.card-info {
  border-left: 5px solid var(--primary-light);
}

.card-month {
  border-left: 5px solid #7B1FA2;
}

/* Botones de acción en tablas */
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.7rem;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}

.btn-action:hover  { opacity: 0.85; transform: translateY(-1px); }
.btn-action:active { transform: translateY(0); }

.btn-edit    { background: #1565C0; color: #fff; }
.btn-agenda  { background: #2E7D32; color: #fff; }
.btn-history { background: #00838F; color: #fff; }
.btn-delete  { background: #C62828; color: #fff; }

/* Botón TV en sidebar */
.btn-tv {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  width: 100%;
  margin-bottom: 0.5rem;
  transition: background 0.2s;
}
.btn-tv:hover { background: rgba(255,255,255,0.2); }

/* Estilo aeropuerto — Lista del Día */
.dash-row-past td { opacity: 0.38; }
.dash-row-past td:last-child .status-pill { opacity: 0.6; }

@keyframes dash-pulse {
  0%, 100% { background: rgba(245,127,23,0.08); }
  50%       { background: rgba(245,127,23,0.18); }
}
.dash-row-current {
  animation: dash-pulse 2s ease-in-out infinite;
  border-left: 3px solid var(--warning);
}
.dash-row-current td { font-weight: 600; }
.dash-row-upcoming td { opacity: 1; }

/* Línea AHORA */
.dash-now-marker td {
  padding: 0.3rem 0.85rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--warning);
  background: rgba(245,127,23,0.07);
  border-top: 2px solid var(--warning);
  border-bottom: 1px solid rgba(245,127,23,0.25);
}

.dashboard-section {
  margin-bottom: 1.5rem;
}

.panel {
  background: var(--accent);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

.panel-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
}

.panel-header h3 {
  margin: 0;
}

.panel-body {
  padding: 1.25rem;
}

.table-panel {
  overflow-x: auto;
}

#todayTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

#todayTable th,
#todayTable td {
  border: 1px solid var(--border);
  padding: 0.85rem;
  text-align: left;
}

#todayTable th {
  background: #E3F2FD;
}

#todayTable tbody tr:hover {
  background: rgba(33, 150, 243, 0.08);
}

.chart-panel {
  min-height: 320px;
}

.search-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.search-bar input {
  flex: 1;
}

.report-form .form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.report-form label {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.reports-grid {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.reports-grid pre {
  background: #F5F7FA;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  overflow-x: auto;
}

.primary-button {
  background: var(--primary);
  color: var(--accent);
  border: none;
  padding: 0.9rem 1.25rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.primary-button:hover {
  background: var(--primary-light);
}

.tab-list {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 999px;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: var(--accent);
}

.calendar-panel {
  min-height: 260px;
  background: #F5F7FA;
  border-radius: 16px;
  padding: 1rem;
}

button,
input[type="submit"] {
  font-family: inherit;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Responsive */
.booking-shell {
  display: flex;
  min-height: 100vh;
}

.booking-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.booking-steps .step {
  background: #E3F2FD;
  color: var(--text);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.95rem;
}

.booking-steps .step.active {
  background: var(--primary);
  color: var(--accent);
}

.booking-form {
  display: grid;
  gap: 1rem;
}

.form-card {
  display: none;
}

.form-card.active {
  display: block;
}

.booking-form small {
  color: var(--text-muted);
}

.therapy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.therapy-card {
  background: #F5F7FA;
  border-radius: 16px;
  padding: 1rem;
}

.therapy-card label {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  cursor: pointer;
}

.therapy-card input {
  width: auto;
}

.form-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.secondary-button {
  background: #F5F7FA;
  color: var(--text);
  border: 1px solid var(--border);
}

/* ── Agenda Day View ─────────────────────────────────────────── */
.day-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.day-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

.nav-btn {
  background: var(--bg-soft);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.nav-btn:hover { background: var(--border); }

.agenda-day-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 650px;
}

.agenda-day-table thead th {
  background: var(--primary);
  color: #fff;
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.agenda-day-table tbody td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  vertical-align: middle;
}

.hour-cell {
  background: #E3F2FD;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  white-space: nowrap;
  width: 80px;
}

/* Row colors by estado */
.row-programada { background: #fff; }
.row-en_curso   { background: rgba(245,127,23,0.08); }
.row-atendida   { background: rgba(46,125,50,0.07); }
.row-cancelada  { background: rgba(198,40,40,0.06); opacity: 0.7; }

/* Inline selects inside the table */
.inline-select {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text);
  width: 100%;
  text-transform: none;
}

.inline-select:focus { outline: none; border-color: var(--primary); }

/* Estado select colors */
.est-programada { color: var(--primary);  border-color: var(--primary-lighter); }
.est-en_curso   { color: var(--warning);  border-color: var(--warning); }
.est-atendida   { color: var(--success);  border-color: var(--success); }
.est-cancelada  { color: var(--danger);   border-color: var(--danger); }

.tv-shell {
  min-height: 100vh;
  background: var(--bg);
  padding: 2rem;
}

.tv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.tv-header h1 {
  margin: 0;
  font-size: 2.5rem;
}

.tv-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 1rem;
}

.tv-card {
  background: var(--accent);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(21, 101, 192, 0.08);
}

.tv-card span {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 600;
}

.tv-card strong {
  display: block;
  margin-top: 0.75rem;
  font-size: 2.5rem;
}

.tv-table-panel {
  background: var(--accent);
  border-radius: 24px;
  padding: 1.5rem;
}

.tv-table-panel table {
  width: 100%;
  border-collapse: collapse;
}

.tv-table-panel th,
.tv-table-panel td {
  border: 1px solid var(--border);
  padding: 1rem;
  text-align: left;
}

.tv-table-panel th {
  background: #E3F2FD;
}

.status-pill {
  display: inline-flex;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-programada {
  background: rgba(21, 101, 192, 0.08);
  color: var(--primary);
}

.status-en_curso {
  background: rgba(245, 127, 23, 0.1);
  color: var(--warning);
}

.status-atendida {
  background: rgba(46, 125, 50, 0.12);
  color: var(--success);
}

@media (max-width: 980px) {
  .app-shell,
  .booking-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .sidebar-logout {
    width: auto;
    margin-top: 0;
  }
  .report-form .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
    gap: 1rem;
  }
  .tv-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .tv-kpis {
    grid-template-columns: 1fr;
  }
}

/* ── Historial Clínico ─────────────────────────────── */
.history-section {
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.history-section-title {
  margin: 0;
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: #fff;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.4rem 1.5rem;
  padding: 0.75rem 1rem;
}
.history-grid .lbl {
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.25rem;
}
#hDiagnostico {
  padding: 0.75rem 1rem;
}

/* Badges de estado */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-blue   { background: rgba(21,101,192,0.12); color: var(--primary); }
.badge-orange { background: rgba(245,127,23,0.15); color: var(--warning); }
.badge-green  { background: rgba(46,125,50,0.12);  color: var(--success); }
.badge-red    { background: rgba(198,40,40,0.12);  color: var(--danger);  }

/* ── PRINT ─────────────────────────────────────────── */
.print-header { display: none; }

@media print {
  /* Ocultar todo excepto el área de impresión */
  body > * { display: none !important; }
  #historyModal { display: block !important; position: static !important; background: none !important; }
  .modal-content { box-shadow: none !important; max-width: 100% !important; padding: 0 !important; }
  .close, .modal-actions { display: none !important; }
  #printArea { display: block !important; }

  /* Encabezado de impresión */
  .print-header {
    display: flex !important;
    align-items: center;
    gap: 1rem;
    border-bottom: 2px solid #1565C0;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
  }
  .print-logo { width: 80px; height: auto; }
  .print-clinic-info { flex: 1; }
  .print-clinic-info h1 { margin: 0; font-size: 1.3rem; color: #1565C0; }
  .print-clinic-info p  { margin: 0.1rem 0; font-size: 0.8rem; color: #555; }
  .print-date-box { text-align: right; font-size: 0.8rem; color: #555; }
  .print-date-box strong { display: block; font-size: 0.95rem; color: #1565C0; }

  /* Evitar cortes de página dentro de secciones */
  .history-section { page-break-inside: avoid; }

  /* Tabla limpia para impresión */
  table { border-collapse: collapse; width: 100%; }
  th, td { border: 1px solid #ccc; padding: 4px 8px; font-size: 0.8rem; }
  th { background: #1565C0 !important; color: #fff !important; -webkit-print-color-adjust: exact; }
}
