﻿:root {
  --bg: #0b1021;
  --surface: #0f172a;
  --card: #111827;
  --border: #1e293b;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
  --radius: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(135deg, #0f172a 0%, #0b1021 50%, #0f172a 100%);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

a { color: inherit; }

.auth-card {
  max-width: 920px;
  margin: 60px auto;
  padding: 32px;
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
}

.eyebrow { text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--muted); margin: 0; }
.muted { color: var(--muted); margin: 0; }
.title { font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  background: #0b1224;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.25);
}
.field-input { background:#0b1224; border:1px solid var(--border); border-radius:10px; padding:10px 12px; color:var(--text); width:100%; }

button { border: none; border-radius: 12px; cursor: pointer; font-weight: 700; }
.primary {
  background: linear-gradient(135deg, var(--primary-strong), #7c3aed);
  color: white;
  padding: 14px 16px;
  box-shadow: 0 12px 25px rgba(99, 102, 241, 0.25);
}
.ghost { background: #111827; color: var(--text); padding: 10px 12px; border: 1px solid var(--border); }

.msg { min-height: 20px; color: var(--danger); font-weight: 600; }

.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.layout { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
  background: rgba(17, 24, 39, 0.9);
  border-right: 1px solid var(--border);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.user { display: flex; gap: 12px; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; color: white; font-size: 20px; }
.nav { display: grid; gap: 8px; }
.nav-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.nav-btn.active { background: rgba(99,102,241,0.15); border-color: var(--primary); color: white; }
.sidebar-footer { margin-top: auto; }

.content { padding: 24px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.toolbar-left h2 { margin: 4px 0; }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.date-nav { display: flex; gap: 8px; align-items: center; background: #0b1224; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--border); }
.date-nav button { padding: 8px 10px; }
.pill { background: rgba(99,102,241,0.15); color: #c7d2fe; padding: 6px 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }

.pane { display: block; }
.card { background: rgba(15, 23, 42, 0.9); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: #0b1224; border: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.responsive-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.calendar-grid .weekday { text-align: center; color: var(--muted); font-weight: 700; }
.day-cell { 
  padding: 10px; 
  background: #0b1224; 
  border: 1px solid var(--border); 
  border-radius: 12px; 
  min-height: 90px; 
  display: flex; 
  flex-direction: column; 
  gap: 6px; 
  cursor: pointer;
  overflow: hidden;
}
.day-cell .date { font-weight: 800; }
.day-cell .status { 
  display: inline-flex; 
  align-items: center; 
  justify-content: flex-start;
  gap: 6px; 
  padding: 4px 8px; 
  border-radius: 999px; 
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.day-cell.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.25); }
.day-cell .count { color: var(--muted); font-size: 12px; }

.timeline { display: grid; gap: 10px; }
.slot { padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: #0b1224; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.slot .info { display: grid; gap: 4px; }
.badge { 
  padding: 6px 10px; 
  border-radius: 999px; 
  font-weight: 700; 
  font-size: 12px; 
  text-transform: uppercase; 
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
}
.badge.Reservado { background: rgba(14,165,233,0.15); color: #38bdf8; }
.badge.Confirmado { background: rgba(34,197,94,0.15); color: #4ade80; }
.badge.Cancelado { background: rgba(239,68,68,0.15); color: #f87171; }
.badge.Reprogramado { background: rgba(245,158,11,0.15); color: #fbbf24; }
.badge.Atendido { background: rgba(99,102,241,0.15); color: #a5b4fc; }
.badge.Ausente { background: rgba(148,163,184,0.15); color: #cbd5e1; }
.badge-dot { background:#ef4444; color:white; font-size:10px; padding:2px 6px; border-radius:999px; margin-left:6px; }

/* Chat badge specific styling */
#chatBadge {
  position: relative;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: auto;
  min-width: 20px;
  text-align: center;
  animation: pulse-badge 2s ease-in-out infinite;
}

#chatBadge:not(.hidden) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@keyframes pulse-badge {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
  }
}

/* WhatsApp indicator */
.wa-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-left: auto;
}

.wa-indicator.connected {
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

.wa-indicator.disconnected {
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3);
}

.slot .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.slot .actions button { padding: 8px 10px; border-radius: 10px; background: #111827; color: var(--text); border: 1px solid var(--border); font-weight: 700; }

.chips .chip { display:inline-flex; align-items:center; gap:6px; padding:6px 10px; border:1px solid var(--border); border-radius:12px; background:#0b1224; color:var(--text); cursor:pointer; }
.chips .chip input { accent-color: var(--primary); }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.table-wrap.compact { max-height: 45vh; }
table { width: 100%; border-collapse: collapse; color: var(--text); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #0b1224; position: sticky; top: 0; z-index: 1; }
tr:hover { background: rgba(99,102,241,0.08); cursor: pointer; }

/* Actions cell in table */
.actions-cell { text-align: center; white-space: nowrap; }
.actions-cell button { padding: 6px 8px; margin: 0 2px; }
.edit-patient-btn { color: var(--primary); border-color: transparent; }
.edit-patient-btn:hover { color: #818cf8; border-color: var(--primary); background: rgba(99,102,241,0.1); }
.edit-prof-btn { color: var(--primary); border-color: transparent; }
.edit-prof-btn:hover { color: #818cf8; border-color: var(--primary); background: rgba(99,102,241,0.1); }

/* Enhanced table for data views */
.data-table-enhanced {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}

.data-table-enhanced thead {
  position: sticky;
  top: 0;
  background: #0b1224;
  z-index: 5;
}

.data-table-enhanced th {
  padding: 12px;
  text-align: left;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table-enhanced td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table-enhanced tbody tr {
  transition: all 0.2s;
  cursor: pointer;
}

.data-table-enhanced tbody tr:hover {
  background: rgba(99, 102, 241, 0.12);
}

.data-table-enhanced tbody tr.selected {
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.18) 0%, rgba(34, 197, 94, 0.06) 100%);
  border-left: 4px solid var(--success);
  position: relative;
}

.data-table-enhanced tbody tr.selected::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.data-table-enhanced tbody tr.selected:hover {
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.22) 0%, rgba(34, 197, 94, 0.08) 100%);
}

.data-table-enhanced tbody tr.selected td:first-child {
  padding-left: 16px;
}

.data-table-enhanced tbody tr.selected td {
  color: #86efac;
  font-weight: 600;
}

.split { 
  display: grid; 
  grid-template-columns: 1fr 280px; 
  gap: 14px; 
}

/* Cuando hay paciente seleccionado: lista pequeña, ficha grande */
.split.patient-selected { 
  grid-template-columns: 220px 1fr; 
}

/* Lista de pacientes cuando hay selección */
.split.patient-selected .table-wrap {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  border-radius: 10px;
}

/* Ocultar columnas extras cuando hay paciente seleccionado */
.split.patient-selected .hide-on-selected {
  display: none;
}

/* Tabla compacta cuando hay paciente seleccionado */
.split.patient-selected .data-table-enhanced th,
.split.patient-selected .data-table-enhanced td {
  padding: 8px 10px;
  font-size: 13px;
}

.split.patient-selected .data-table-enhanced th {
  font-size: 11px;
}

.patient-detail { 
  background: #0b1224; 
  border: 1px solid var(--border); 
  border-radius: 12px; 
  padding: 16px; 
  min-height: 200px;
  overflow-y: auto; 
  max-height: calc(100vh - 200px); 
  display: flex;
  align-items: center;
  justify-content: center;
}

.patient-detail .empty {
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

/* Ficha del paciente expandida - OCUPA TODO EL ESPACIO */
.split.patient-selected .patient-detail {
  padding: 0;
  min-height: calc(100vh - 280px);
  max-height: calc(100vh - 200px);
  align-items: flex-start;
  justify-content: flex-start;
  background: transparent;
  border: none;
  overflow-y: auto;
}

/* Contenedor de la ficha del paciente expandida */
.split.patient-selected .patient-detail-enhanced {
  width: 100%;
}

.patient-detail-compact {
  background: #0b1224;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-height: 400px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  position: sticky;
  top: 24px;
}

.split-view-enhanced {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 1200px) {
  .split-view-enhanced {
    grid-template-columns: 1fr;
  }
  
  .split.patient-selected {
    grid-template-columns: 1fr !important;
  }
}
.empty { color: var(--muted); text-align: center; margin-top: 30px; }
.note { border: 1px solid var(--border); padding: 10px; border-radius: 10px; margin-bottom: 8px; }

.search { display: flex; align-items: center; gap: 8px; background: #0b1224; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); }
.search input { background: transparent; border: none; color: var(--text); outline: none; width: 100%; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 10000; padding: 10px; overflow-y: auto; }
.modal-body { 
  background: #0f172a; 
  border: 1px solid var(--border); 
  border-radius: var(--radius); 
  padding: 18px; 
  width: min(900px, 100%); 
  box-shadow: var(--shadow); 
  max-height: 90vh; 
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.modal-head { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  position: sticky; 
  top: -18px; 
  background: #0f172a; 
  padding: 10px 0; 
  margin: -10px 0 10px 0; 
  z-index: 10;
  flex-shrink: 0;
}
.modal-actions { 
  display: flex; 
  gap: 10px; 
  justify-content: flex-end; 
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Connections Modal specific */
#connectionsModal .modal-body {
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
}

#connectionsContent {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.hidden { display: none !important; }

/* Patient suggestions in appointment modal */
.patient-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #111827;
  border: 2px solid var(--primary);
  border-radius: 12px;
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.5);
}

.suggestion-header {
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.suggestion-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.suggestion-item:hover {
  background: rgba(99, 102, 241, 0.08);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.suggestion-info strong {
  color: var(--text);
  font-size: 14px;
}

.suggestion-info small {
  color: var(--muted);
  font-size: 12px;
  display: block;
}

.insurance-badge {
  display: inline-block;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}

.suggestion-item button {
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}

.toast { 
  position: fixed; 
  bottom: 20px; 
  right: 20px; 
  background: #111827; 
  color: white; 
  padding: 12px 18px; 
  border-radius: 12px; 
  border: 2px solid var(--success); 
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); 
  z-index: 10001;
  animation: slideInToast 0.3s ease-out;
}

@keyframes slideInToast {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Danger button style */
button.danger,
.ghost.danger {
  color: #ef4444 !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
}

button.danger:hover,
.ghost.danger:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: #ef4444 !important;
}

/* Patient detail header actions */
.patient-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.patient-header-actions .ghost {
  padding: 8px;
  min-width: 36px;
}

.patient-header-actions .ghost.danger {
  color: var(--danger);
}

.patient-header-actions .ghost.danger:hover {
  background: rgba(239, 68, 68, 0.15);
}

.inline-actions { display: flex; gap: 8px; }

/* Admin section in profile */
.admin-section {
  background: rgba(239, 68, 68, 0.05);
  border-radius: 12px;
  padding: 16px;
  margin-top: 20px;
}

.admin-section h4 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.prof-modal { width: min(920px, 95vw); max-height: 90vh; overflow: auto; }
.prof-grid { display: grid; grid-template-columns: 280px 1fr; gap: 14px; align-items: start; }
.prof-modal .timeline { max-height: 320px; overflow: auto; }

/* ============================================
   RESPONSIVE - MOBILE FIRST PROFESSIONAL
   ============================================ */

/* Tablet (hasta 1024px) */
@media (max-width: 1024px) {
  html, body {
    overflow-x: hidden;
    overscroll-behavior: none;
  }
  
  .layout { 
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  /* MENÚ INFERIOR COMPACTO - Ajusta a cualquier cantidad de iconos */
  .sidebar { 
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 1000; /* Menor que modales */
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
    height: 56px;
    min-height: 56px;
    max-height: 56px;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: #0f172a;
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Ocultar scrollbar pero mantener funcionalidad */
  .sidebar::-webkit-scrollbar {
    display: none;
  }
  .sidebar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  
  
  .sidebar .user { 
    display: none; 
  }
  
  /* Navegación - flex que se adapta a cualquier cantidad de iconos */
  .sidebar .nav { 
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 100%;
    gap: 2px;
    flex: 1;
    min-width: 0;
  }
  
  .nav-btn {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 1px;
    padding: 4px 6px;
    font-size: 10px;
    border: none;
    background: transparent;
    min-width: 42px;
    max-width: 52px;
    height: 48px;
    text-align: center;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .nav-btn i {
    font-size: 16px;
    line-height: 1;
  }
  
  .nav-btn span {
    font-size: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 44px;
    line-height: 1;
  }
  
  .nav-btn.active {
    background: rgba(99,102,241,0.25);
  }
  
  /* BOTÓN SALIR COMPACTO */
  .sidebar-footer { 
    display: flex !important;
    align-items: center;
    height: 100%;
    margin: 0;
    padding: 0 2px;
    flex-shrink: 0;
  }
  
  .sidebar-footer #logoutBtn {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 4px 6px;
    height: 48px;
    min-width: 42px;
    font-size: 8px;
    border: none;
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-radius: 6px;
  }
  
  .sidebar-footer #logoutBtn i {
    font-size: 16px;
    line-height: 1;
  }
  
  /* Ocultar texto original del botón salir */
  .sidebar-footer #logoutBtn span {
    display: none;
  }
  
  /* Agregar texto "Salir" debajo del icono */
  .sidebar-footer #logoutBtn::after {
    content: 'Salir';
    font-size: 8px;
    font-weight: 600;
    line-height: 1;
  }
  
  .content { 
    padding: 12px; 
    padding-bottom: 70px; /* Espacio para menú fijo */
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  
  .responsive-grid { 
    grid-template-columns: 1fr; 
    gap: 12px;
  }
  
  .split { 
    grid-template-columns: 1fr !important; 
  }
  
  /* CALENDARIO - Se ve completo sin zoom */
  .calendar-card {
    overflow: visible;
  }
  
  .calendar-grid { 
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
  }
  
  .prof-grid { 
    grid-template-columns: 1fr; 
  }
  
  .prof-modal { 
    width: 95vw; 
    max-height: 92vh; 
  }
  
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 0;
  }
  
  .toolbar-left {
    text-align: center;
  }
  
  .toolbar-left .pill {
    display: none;
  }
  
  .toolbar-left h2 {
    font-size: 16px;
    margin: 4px 0;
  }
  
  .filters {
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .filters select {
    font-size: 14px;
    padding: 10px;
    max-width: 200px;
  }
  
  .date-nav {
    justify-content: center;
    padding: 6px 10px;
  }
  
  .date-nav button {
    padding: 8px;
    min-width: 36px;
  }
  
  /* BOTÓN NUEVO TURNO - Visible y compacto en móvil */
  .toolbar-actions {
    width: 100%;
  }
  
  .toolbar-actions #newAptBtn {
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  
  .toolbar-actions #newAptBtn i {
    font-size: 14px;
  }
  
  /* Modal móvil - PANTALLA COMPLETA con botones siempre visibles */
  .modal {
    padding: 0;
    align-items: stretch;
    overflow: hidden;
  }
  
  .modal-body {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0 !important;
    margin: 0;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  /* Header del modal - fijo arriba */
  .modal-body .modal-head {
    position: relative;
    top: 0;
    background: #0f172a;
    z-index: 10;
    padding: 16px;
    margin: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  
  .modal-body .modal-head h3 {
    font-size: 16px;
    margin: 0;
  }
  
  .modal-body .modal-head .muted {
    font-size: 11px;
  }
  
  /* Contenido scrolleable del modal */
  .modal-body .grid-2,
  .modal-body .prof-grid {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    gap: 14px;
    margin: 0;
  }
  
  .modal-body .field {
    margin-bottom: 0;
  }
  
  .modal-body .field span {
    font-size: 13px;
    margin-bottom: 4px;
    display: block;
  }
  
  .modal-body .msg {
    padding: 8px 16px;
    flex-shrink: 0;
    margin: 0;
  }
  
  /* BOTONES DE ACCIÓN - Siempre visibles abajo */
  .modal-body .modal-actions {
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    background: #0f172a;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
    margin: 0;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    gap: 12px;
    z-index: 20;
  }
  
  .modal-body .modal-actions button {
    flex: 1;
    padding: 14px 16px;
    font-size: 14px;
  }
  
  .modal-body .modal-actions .primary {
    order: -1;
  }
  
  .modal-body .modal-actions .ghost {
    background: transparent;
    border: 1px solid var(--border);
  }
}

/* Móvil pequeño (hasta 640px) */
@media (max-width: 640px) {
  html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  
  body {
    font-size: 14px;
    touch-action: manipulation;
  }
  
  .auth-card {
    margin: 16px 10px;
    padding: 20px 16px;
  }
  
  .content {
    padding: 10px;
    padding-bottom: 70px;
  }
  
  /* CALENDARIO COMPACTO - Vista completa sin zoom */
  .calendar-grid { 
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
  }
  
  .calendar-grid .weekday {
    font-size: 10px;
    padding: 4px 2px;
    font-weight: 600;
    text-align: center;
  }
  
  .day-cell {
    padding: 4px 2px;
    min-height: 50px;
    border-radius: 6px;
  }
  
  .day-cell .date {
    font-size: 11px;
    font-weight: 700;
  }
  
  .day-cell .count {
    font-size: 9px;
  }
  
  .day-cell .status {
    padding: 2px 4px;
    font-size: 8px;
    gap: 3px;
  }
  
  /* Abreviar textos largos solo en móvil */
  .day-cell .status-text {
    max-width: 45px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  /* Timeline/slots en móvil */
  .slot {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }
  
  .slot .info {
    width: 100%;
  }
  
  .slot .actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: flex-start;
  }
  
  .slot .actions .badge {
    padding: 5px 10px;
    font-size: 10px;
    flex-shrink: 0;
  }
  
  .slot .actions button {
    padding: 8px 12px;
    font-size: 12px;
    flex: 0 0 auto;
  }
  
  /* Tablas en móvil */
  .table-wrap {
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
  }
  
  th, td {
    padding: 10px 8px;
    font-size: 12px;
  }
  
  .hide-mobile {
    display: none !important;
  }
  
  /* Cards compactas */
  .card {
    padding: 10px;
    border-radius: 10px;
  }
  
  .card-head {
    flex-direction: column;
    gap: 8px;
  }
  
  /* MENÚ INFERIOR - Compacto para muchos iconos */
  .sidebar {
    height: 54px;
    min-height: 54px;
    max-height: 54px;
  }
  
  .nav-btn {
    padding: 3px 4px;
    min-width: 38px;
    max-width: 46px;
    height: 46px;
  }
  
  .nav-btn i {
    font-size: 15px;
  }
  
  .nav-btn span {
    font-size: 7px;
    max-width: 38px;
  }
  
  .sidebar-footer #logoutBtn {
    height: 46px;
    min-width: 38px;
    padding: 3px 5px;
  }
  
  .sidebar-footer #logoutBtn i {
    font-size: 15px;
  }
  
  .sidebar-footer #logoutBtn::after {
    font-size: 7px;
  }
  
  /* Botones */
  .primary {
    padding: 12px 14px;
    font-size: 14px;
    width: 100%;
  }
  
  .ghost {
    padding: 10px 12px;
  }
  
  /* Inputs - evita zoom */
  .field input, 
  .field select, 
  .field textarea {
    padding: 12px;
    font-size: 16px !important;
    border-radius: 8px;
  }
  
  .field-input {
    padding: 12px;
    font-size: 16px !important;
  }
  
  /* Toolbar compacto */
  .toolbar-left h2 {
    font-size: 16px;
  }
  
  .toolbar-left .pill {
    display: none;
  }
  
  .pill {
    padding: 5px 8px;
    font-size: 10px;
  }
  
  /* Badges en móvil - bien centrados */
  .badge {
    padding: 4px 8px;
    font-size: 10px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  .grid-2 {
    grid-template-columns: 1fr;
  }
  
  .inline-actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  
  .inline-actions button {
    flex: 1;
    min-width: 80px;
  }
  
  .patient-detail {
    max-height: none;
    min-height: auto;
    padding: 10px;
  }
  
  .toast {
    left: 10px;
    right: 10px;
    bottom: 80px;
    text-align: center;
  }
  
  .legend {
    justify-content: center;
    gap: 3px;
  }
  
  .legend span {
    padding: 3px 5px;
    font-size: 9px;
  }
  
  .search {
    width: 100%;
  }
  
  .search input {
    font-size: 16px !important;
  }
  
  .toolbar-actions {
    width: 100%;
  }
  
  .toolbar-actions button {
    width: 100%;
  }
}

/* Móvil extra pequeño (hasta 380px) */
@media (max-width: 380px) {
  .content {
    padding: 8px;
    padding-bottom: 60px;
  }
  
  /* Menú ultra compacto para pantallas pequeñas */
  .sidebar {
    height: 52px;
    min-height: 52px;
    max-height: 52px;
    padding: 0 2px;
  }
  
  .nav-btn {
    padding: 2px;
    min-width: 32px;
    max-width: 40px;
    height: 44px;
  }
  
  .nav-btn i {
    font-size: 14px;
  }
  
  .nav-btn span {
    font-size: 6px;
    max-width: 32px;
  }
  
  .sidebar-footer #logoutBtn {
    padding: 2px;
    min-width: 32px;
    height: 44px;
  }
  
  .sidebar-footer #logoutBtn i {
    font-size: 14px;
  }
  
  .sidebar-footer #logoutBtn::after {
    font-size: 6px;
  }
  
  .day-cell {
    min-height: 45px;
    padding: 3px 2px;
  }
  
  .day-cell .date {
    font-size: 10px;
  }
  
  .day-cell .status {
    display: none;
  }
  
  .day-cell .count {
    font-size: 8px;
  }
  
  .toolbar-left h2 {
    font-size: 14px;
  }
  
  .card {
    padding: 8px;
  }
}

/* Landscape móvil */
@media (max-height: 500px) and (orientation: landscape) {
  .sidebar {
    height: 50px;
    min-height: 50px;
    max-height: 50px;
    padding: 0 10px;
  }
  
  .nav-btn {
    flex-direction: row;
    gap: 6px;
    height: 40px;
    padding: 4px 8px;
  }
  
  .nav-btn span {
    display: inline;
    max-width: none;
    font-size: 10px;
  }
  
  .sidebar-footer #logoutBtn {
    flex-direction: row;
    height: 40px;
  }
  
  .sidebar-footer #logoutBtn::after {
    font-size: 10px;
  }
  
  .content {
    padding-bottom: 55px;
  }
  
  .modal-body {
    height: auto;
    max-height: 100vh;
  }
}

/* Mejoras de accesibilidad para touch */
@media (hover: none) and (pointer: coarse) {
  button, 
  .nav-btn,
  .chip,
  .slot .actions button {
    min-height: 44px;
    min-width: 44px;
  }
  
  tr:active {
    background: rgba(99,102,241,0.2);
  }
  
  .nav-btn:active {
    background: rgba(99,102,241,0.4);
  }
  
  button:active {
    opacity: 0.8;
  }
  
  .nav-btn,
  .slot,
  .day-cell,
  .chip {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  .timeline,
  .table-wrap,
  .modal-body,
  .content {
    -webkit-overflow-scrolling: touch;
  }
}

/* Fix para iOS safe areas - Solo afecta padding, NO altura del menú */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 1024px) {
    .sidebar {
      padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    .content {
      padding-bottom: calc(70px + env(safe-area-inset-bottom, 0));
    }
  }
}

/* ============================================
   MEJORAS ADICIONALES MÓVIL
   ============================================ */

/* Prevenir zoom en inputs en iOS */
@media (max-width: 1024px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Contenedor principal */
#app {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* Panes con scroll */
@media (max-width: 1024px) {
  .pane {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  
  body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }
  
  .card {
    overflow-x: hidden;
  }
  
  .card-head {
    position: relative;
    z-index: 2;
  }
  
  .timeline {
    max-height: 60vh;
    overflow-y: auto;
  }
  
  .patient-detail,
  .patient-detail-compact {
    position: relative;
    max-height: 70vh;
    overflow-y: auto;
  }
  
  #notifList {
    max-height: 65vh;
    overflow-y: auto;
  }
}

/* Animaciones suaves */
@media (max-width: 1024px) {
  .pane {
    animation: fadeInPane 0.15s ease-out;
  }
  
  @keyframes fadeInPane {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
}

/* Vista limpia en móvil */
@media (max-width: 640px) {
  .eyebrow {
    font-size: 10px;
  }
  
  .card-head .muted {
    font-size: 11px;
  }
  
  .card-head h3 {
    font-size: 14px;
  }
}

/* ============================================
   MODALES ESPECÍFICOS - SIEMPRE VISIBLES LOS BOTONES
   ============================================ */

/* Modal nuevo turno, nuevo paciente, etc */
@media (max-width: 1024px) {
  /* Asegurar que modales estén por encima de todo */
  .modal {
    z-index: 10000 !important;
  }
  
  #modal .modal-body,
  #newPatientModal .modal-body,
  #config .modal-body,
  #profileModal .modal-body,
  #profManager .modal-body,
  #newProfessionalModal .modal-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    padding: 0;
    border-radius: 0 !important;
  }
  
  /* Header fijo */
  #modal .modal-head,
  #newPatientModal .modal-head,
  #config .modal-head,
  #profileModal .modal-head,
  #profManager .modal-head,
  #newProfessionalModal .modal-head {
    flex-shrink: 0;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: #0f172a;
    margin: 0;
  }
  
  #modal .modal-head h3,
  #newPatientModal .modal-head h3 {
    font-size: 16px;
    margin: 0;
  }
  
  /* Contenido scrolleable */
  #modal .grid-2,
  #newPatientModal .grid-2,
  #config .grid-2,
  #profileModal .grid-2,
  #profManager .prof-grid,
  #newProfessionalModal .grid-2 {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px 16px;
    margin: 0;
  }
  
  /* Mensaje de error */
  #modal .msg,
  #newPatientModal .msg,
  #modalMsg,
  #newPatMsg {
    padding: 4px 16px;
    margin: 0;
    flex-shrink: 0;
  }
  
  /* BOTONES siempre visibles abajo */
  #modal .modal-actions,
  #newPatientModal .modal-actions,
  #config .modal-actions,
  #profileModal .modal-actions,
  #profManager .modal-actions,
  #newProfessionalModal .modal-actions {
    flex-shrink: 0;
    padding: 14px 16px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--border);
    background: #0f172a;
    display: flex;
    gap: 10px;
    margin: 0 !important;
  }
  
  #modal .modal-actions button,
  #newPatientModal .modal-actions button,
  #config .modal-actions button,
  #profileModal .modal-actions button {
    flex: 1;
    min-height: 46px;
    font-size: 14px;
    padding: 12px;
  }
  
  #modal .modal-actions .primary,
  #newPatientModal .modal-actions .primary {
    background: linear-gradient(135deg, var(--primary-strong), #7c3aed);
  }
}
