/* ============================================================
   Calendario Médico - Estilos principales
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:         #F8FAFC;
  --color-surface:    #FFFFFF;
  --color-border:     #E2E8F0;
  --color-text:       #1E293B;
  --color-muted:      #64748B;
  --color-primary:    #6366F1;
  --color-primary-h:  #4F46E5;
  --color-danger:     #EF4444;
  --color-success:    #10B981;
  --color-warning:    #F59E0B;
  --radius:           8px;
  --shadow:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:        0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  font-size: 14px;
}

/* ---- Layout ---- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo svg { width: 22px; height: 22px; }

.sidebar-section { padding: 12px 12px 0; }
.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  padding: 0 8px 6px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: 13.5px;
  transition: background .15s;
}
.sidebar-nav a:hover  { background: #F1F5F9; }
.sidebar-nav a.active { background: #EEF2FF; color: var(--color-primary); font-weight: 600; }

/* .sidebar-filters reemplazado por .sidebar-context en JS */

/* ---- Main ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
}

.topbar-nav {
  display: flex;
  gap: 4px;
}

.topbar-nav button {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-muted);
  transition: all .15s;
}
.topbar-nav button:hover       { background: #F1F5F9; color: var(--color-text); }
.topbar-nav button.active      { background: var(--color-primary); color: white; border-color: var(--color-primary); }

.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity .15s;
}
.btn:hover   { opacity: .88; }
.btn-primary { background: var(--color-primary); color: white; }
.btn-danger  { background: var(--color-danger);  color: white; }
.btn-ghost   { background: none; border: 1px solid var(--color-border); color: var(--color-text); }

.calendar-wrap {
  flex: 1;
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}
#calendar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

/* ---- Calendar grids ---- */
.cal-header-grid {
  display: grid;
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* Semana */
.cal-week-grid {
  display: grid;
  grid-template-columns: 52px repeat(7, 1fr);
}

.cal-week-header {
  display: grid;
  grid-template-columns: 52px repeat(7, 1fr);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky; top: 0; z-index: 10;
}
.cal-week-header .col-time { padding: 8px; font-size: 11px; color: var(--color-muted); }
.cal-week-header .col-day {
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted);
  border-left: 1px solid var(--color-border);
}
.cal-week-header .col-day.today { color: var(--color-primary); }
.cal-week-header .col-day .day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 2px;
}
.cal-week-header .col-day.today .day-number {
  background: var(--color-primary);
  color: white;
}

/* Cuerpo scrollable semana/día */
.cal-scroll-body {
  display: flex;
  overflow-y: auto;
  flex: 1;
}
.time-col-body {
  width: 52px;
  flex-shrink: 0;
  background: var(--color-surface);
  z-index: 5;
}
.time-slot {
  height: 60px;
  padding: 2px 6px 0 0;
  font-size: 11px;
  color: var(--color-muted);
  text-align: right;
  border-top: 1px solid var(--color-border);
}

/* Columnas de días */
.days-cols {
  display: flex;
  flex: 1;
}
.day-col-body {
  flex: 1;
  position: relative;   /* eventos se posicionan aquí */
  border-left: 1px solid var(--color-border);
  min-width: 0;
}

/* Slots de fondo */
.slot-bg {
  height: 60px;
  border-top: 1px solid var(--color-border);
  cursor: pointer;
  transition: background .1s;
}
.slot-bg:hover { background: #EEF2FF; }

/* Evento — posición absoluta DENTRO de .day-col-body */
.cal-event {
  position: absolute;
  left: 3px;
  right: 3px;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  z-index: 2;
  line-height: 1.3;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: filter .15s, box-shadow .15s;
  color: #fff;
}
.cal-event:hover {
  filter: brightness(1.08);
  box-shadow: var(--shadow-md);
  z-index: 3;
}
.cal-event .ev-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event .ev-time  { font-size: 10.5px; opacity: .85; }

/* Mes */
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-month-header-cell {
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky; top: 0; z-index: 10;
}
.cal-month-cell {
  min-height: 110px;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  padding: 6px;
  vertical-align: top;
  cursor: pointer;
  transition: background .1s;
}
.cal-month-cell:hover { background: #F8FAFC; }
.cal-month-cell.other-month { opacity: .45; }
.cal-month-cell.today-cell { background: #EEF2FF; }
.cal-month-cell .cell-day-num {
  font-size: 13px;
  font-weight: 600;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  margin-bottom: 4px;
}
.cal-month-cell.today-cell .cell-day-num {
  background: var(--color-primary); color: white;
}
.cal-month-event {
  font-size: 11px;
  font-weight: 500;
  border-radius: 3px;
  padding: 1px 5px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  cursor: pointer;
}
.more-link {
  font-size: 11px;
  color: var(--color-muted);
  cursor: pointer;
  padding: 1px 4px;
}

/* Día */
.cal-day-view {
  display: grid;
  grid-template-columns: 52px 1fr;
}

/* ---- Estado badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}
.badge-disponible   { background: #10B981; }
.badge-reservado    { background: #3B82F6; }
.badge-confirmado   { background: #6366F1; }
.badge-en_atencion  { background: #F59E0B; }
.badge-completado   { background: #059669; }
.badge-cancelado    { background: #EF4444; }
.badge-ausente      { background: #DC2626; }
.badge-reprogramado { background: #8B5CF6; }
.badge-bloqueado    { background: #6B7280; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--color-surface);
  border-radius: 12px;
  width: 560px;
  max-width: 96vw;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: modalIn .15s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--color-muted); font-size: 18px; padding: 4px;
}
.modal-body  { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---- Form ---- */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.form-row.single { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color .15s;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: white;
}
.form-group textarea { resize: vertical; min-height: 70px; }

/* ---- Filters sidebar ---- */
.filter-group { margin-bottom: 14px; }
.filter-group label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--color-muted);
  display: block; margin-bottom: 4px;
}
.filter-group select,
.filter-group input {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 13px;
  background: white;
}

/* ---- Toast ---- */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #1E293B;
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
.toast.error { background: var(--color-danger); }
.toast.success { background: var(--color-success); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }

/* ============================================================
   MÓDULOS — navegación sidebar
   ============================================================ */
.module-nav {
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
}
.module-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s;
}
.module-nav-item:hover  { background: #F1F5F9; }
.module-nav-item.active { background: #EEF2FF; color: var(--color-primary); font-weight: 600; }

.sidebar-context { flex: 1; display: flex; flex-direction: column; padding: 12px; gap: 4px; }
.sidebar-legend  { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--color-border); }
.legend-item     { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; font-size: 12px; color: var(--color-muted); }
.legend-dot      { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ============================================================
   MÓDULOS — panel general
   ============================================================ */
.module-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.module-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--color-text);
}
.module-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .module-two-col { grid-template-columns: 1fr; } }

.module-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 20px;
}
.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 14px;
}
.module-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  gap: 12px;
  color: var(--color-muted);
}
.module-empty svg { opacity: .4; }
.module-empty p { font-size: 15px; }

/* ============================================================
   MÓDULO DOCTOR — horarios
   ============================================================ */
.horario-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--color-bg);
  margin-bottom: 6px;
  font-size: 13px;
}
.horario-dia   { font-weight: 600; min-width: 80px; }
.horario-rango { color: var(--color-primary); font-weight: 500; min-width: 100px; }
.btn-icon-sm   { background: none; border: none; cursor: pointer; color: var(--color-muted); padding: 2px 6px; border-radius: 4px; margin-left: auto; }
.btn-icon-sm:hover { background: #FEE2E2; color: var(--color-danger); }

.horario-form { border-top: 1px solid var(--color-border); padding-top: 14px; margin-top: 4px; }

.esp-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.esp-tag button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  opacity: .7;
  padding: 0 0 0 2px;
  line-height: 1;
}
.esp-tag button:hover { opacity: 1; }

/* ============================================================
   MÓDULO PACIENTE — booking
   ============================================================ */
.booking-filters {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.tipo-btns { display: flex; gap: 8px; }
.tipo-btn {
  padding: 8px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: white;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all .15s;
}
.tipo-btn:hover  { border-color: var(--color-primary); }
.tipo-btn.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }

.slots-group     { margin-bottom: 20px; }
.slots-doctor-name { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.slots-row       { display: flex; flex-wrap: wrap; gap: 8px; }
.slot-btn {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  transition: all .15s;
}
.slot-btn:hover    { background: #EEF2FF; border-color: var(--color-primary); }
.slot-btn.selected { background: var(--color-primary); color: white; border-color: var(--color-primary); }

.booking-summary {
  background: #EEF2FF;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary);
  margin-bottom: 16px;
}

/* ============================================================
   MÓDULO CONFIG
   ============================================================ */
.code-block {
  display: block;
  background: #1E293B;
  color: #E2E8F0;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

/* ============================================================
   TABLA DE DATOS
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-muted);
  border-bottom: 2px solid var(--color-border);
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:hover td { background: #F8FAFC; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ============================================================
   EXTRAS BOTONES / ALERTS
   ============================================================ */
.btn-icon   { padding: 8px 10px; }
.btn-warning { background: var(--color-warning); color: white; border: none; }
.btn-danger-outline { background: none; border: 1px solid var(--color-danger); color: var(--color-danger); }
.btn-danger-outline:hover { background: var(--color-danger); color: white; }

.alert-warning {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  color: #92400E;
  margin-bottom: 12px;
}

#btns-cancelada { display: flex; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .module-panel { padding: 16px; }
}
