/* =====================================================
   SISTEMA DE GESTIÓN DE PACIENTES - CSS
   Paleta: Blancos, azules pastel, grises suaves
   Tipografía: Inter (Google Fonts)
===================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #4a90d9;
  --primary-dark: #3070b8;
  --primary-light: #e8f2fb;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-main: #2d3748;
  --text-muted: #718096;
  --success: #38a169;
  --success-bg: #f0fff4;
  --danger: #e53e3e;
  --danger-bg: #fff5f5;
  --warning: #d69e2e;
  --warning-bg: #fffff0;
  --done: #805ad5;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0, 0, 0, .07), 0 4px 16px rgba(0, 0, 0, .04);
  --sidebar-w: 240px;
  --transition: .18s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary-light: #1e293b;
  --primary-dark: #60a5fa;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --success-bg: rgba(56, 161, 105, 0.15);
  --danger-bg: rgba(229, 62, 62, 0.15);
  --warning-bg: rgba(214, 158, 46, 0.15);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.6;
}

/* ── LAYOUT ─────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  font-size: 26px;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
}

.brand-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  overflow: hidden;
}

.user-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  font-size: 18px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px;
  border-radius: 6px;
  transition: var(--transition);
}

.logout-btn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.logout-btn:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

/* ── THEME SWITCH ────────────────────────────────── */
.theme-switch-container {
  padding: 12px 16px;
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--border);
}

.theme-switch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  transition: var(--transition);
  width: 100%;
  justify-content: center;
}

.theme-switch-btn:hover {
  border-color: var(--primary);
  background: var(--surface);
}

.theme-switch-btn .icon {
  font-size: 14px;
}

[data-theme="dark"] .theme-switch-btn .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-switch-btn .moon-icon {
  display: none;
}

[data-theme="light"] .theme-switch-btn .sun-icon {
  display: none;
}

[data-theme="light"] .theme-switch-btn .moon-icon {
  display: block;
}

/* ── MAIN CONTENT ───────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
}

/* ── PAGE HEADER ────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── CARD ───────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-main);
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-footer-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.max-card {
  max-width: 780px;
}

/* ── ALERTS ─────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fed7d7;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #c6f6d5;
}

/* ── BUTTONS ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--text-main);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #c53030;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #276749;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-icon:hover {
  background: var(--bg);
}

.text-danger {
  color: var(--danger) !important;
}

.text-success {
  color: var(--success) !important;
}

/* ── FORMS ──────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group-full {
  grid-column: 1 / -1;
}

.form-section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
}

.form-control {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-main);
  transition: border-color var(--transition);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, .15);
}

.form-control[readonly] {
  background: var(--bg);
  color: var(--text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ── SEARCH BAR ─────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

.search-input {
  max-width: 320px;
}

.search-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.search-form .form-group {
  flex: 1;
  min-width: 250px;
}

/* ── TABLE ──────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .04em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tr:last-child td {
  border-bottom: none;
}

.table tr:hover td {
  background: var(--bg);
}

.row-inactive td {
  opacity: .55;
}

.patient-name {
  font-weight: 600;
}

.actions-cell {
  display: flex;
  gap: 4px;
  align-items: center;
}

.table-footer {
  padding: 10px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* ── BADGES ─────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-active {
  background: #c6f6d5;
  color: #276749;
}

.badge-inactive {
  background: #fed7d7;
  color: #c53030;
}

.badge-pending {
  background: #fefcbf;
  color: #975a16;
}

.badge-done {
  background: #e9d8fd;
  color: #553c9a;
}

.badge-vencido {
  background: #edf2f7;
  color: #4a5568;
  border: 1px solid var(--border);
}

.medication-check-box {
  flex-direction: row;
  align-items: flex-start !important;
  gap: 10px;
  margin-top: 15px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--warning-bg);
}

/* ── INFO LIST (detalle paciente) ───────────────── */
.info-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0 40px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.info-row-wide {
  grid-column: 1 / -1;
}

.info-list hr {
  grid-column: 1 / -1;
  width: 100%;
}

.info-row:last-child {
  border-bottom: none;
}

.info-row span {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 12px;
}

.info-row strong {
  text-align: right;
  word-break: break-word;
}

/* ── DETAIL GRID ────────────────────────────────── */
.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* .card-wide {
} */

/* ── VISITAS ────────────────────────────────────── */
.visita-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.visita-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary-light);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.visita-fecha {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.visita-num {
  color: var(--text-muted);
  font-size: 12px;
}

.visita-fecha strong {
  font-weight: 700;
  color: var(--primary);
}

.visita-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.visita-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.visita-field p {
  font-size: 13px;
  color: var(--text-main);
  margin-top: 2px;
}

.visita-vitals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.vital-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

/* ── TURNOS ─────────────────────────────────────── */
.filter-card {
  padding: 14px 20px;
  margin-bottom: 20px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.turnos-dia {
  margin-bottom: 24px;
}

.dia-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-main);
  margin-bottom: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.dia-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: auto;
}

.turnos-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.turno-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px 18px;
  border-left: 4px solid var(--border);
}

.turno-card.estado-pendiente {
  border-left-color: var(--warning);
}

.turno-card.estado-confirmado {
  border-left-color: var(--success);
}

.turno-card.estado-cancelado {
  border-left-color: var(--danger);
  opacity: .7;
}

.turno-card.estado-completado {
  border-left-color: var(--done);
}

.turno-card.estado-vencido {
  border-left-color: var(--text-muted);
  opacity: .6;
}

.turno-card.estado-vencido .turno-hora {
  color: var(--text-muted);
}

.turno-hora {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  min-width: 60px;
  text-align: center;
}

.turno-info {
  flex: 1;
}

.turno-nombre {
  font-weight: 600;
  font-size: 14px;
}

.turno-detalle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.turno-acciones {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.estado-select {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg);
}

/* ── LOGIN ──────────────────────────────────────── */
.login-body {
  background: var(--bg);
  background-image: radial-gradient(circle at 2px 2px, var(--border) 1px, transparent 0);
  background-size: 32px 32px;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="light"] .login-body {
  background: linear-gradient(135deg, #e8f2fb 0%, #f4f7fb 50%, #edf2f7 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
}

[data-theme="light"] .login-card {
  box-shadow: 0 4px 32px rgba(74, 144, 217, .15);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── UTILITIES ──────────────────────────────────── */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

/* ── RESPONSIVE ─────────────────────────────────── */
.mobile-toggle-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 110;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--primary);
  transition: transform var(--transition);
}

.mobile-toggle-btn:active {
  transform: scale(0.92);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  backdrop-filter: blur(2px);
  z-index: 95;
}

@media (max-width: 900px) {
  .mobile-toggle-btn {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 25px rgba(0, 0, 0, 0.1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
    width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    width: 100%;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .search-bar,
  .search-form {
    flex-direction: column;
    align-items: stretch;
  }

  .search-input {
    max-width: 100%;
  }
}