/* ── Admin layout base ────────────────────────────────────── */
body.admin-layout {
  margin: 0;
  background: #f1f5f9;
  font-family: 'Inter', system-ui, sans-serif;
  padding-top: 0;
}

/* Sidebar */
#admin-sidebar {
  position: fixed;
  top: 0; left: 0;
  width: 240px;
  height: 100vh;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}

#admin-sidebar.collapsed {
  transform: translateX(-240px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid #1e293b;
  color: #f1f5f9;
  font-weight: 700;
  font-size: 1rem;
}

.sidebar-brand .sidebar-logo {
  height: 32px;
  filter: brightness(0) invert(1);
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: .5rem 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: .75rem 1.25rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: .875rem;
  transition: background .15s, color .15s;
}

.sidebar-nav li a:hover,
.sidebar-nav li.active a {
  background: #1e293b;
  color: #f8fafc;
}

.sidebar-nav li.active a {
  color: #60a5fa;
}

.sidebar-nav li a i {
  width: 18px;
  text-align: center;
}

.sidebar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  margin-left: auto;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: #ef4444;
  border-radius: 999px;
  box-shadow: 0 0 0 2px #0f172a, 0 0 6px rgba(239, 68, 68, .65);
}

.sidebar-nav li.sidebar-section-label {
  padding: 1.25rem 1.25rem .25rem;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
  cursor: default;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #94a3b8;
  font-size: .8rem;
  overflow: hidden;
  text-decoration: none;
  transition: color .15s;
}
.sidebar-user:hover, .sidebar-user.active { color: #f8fafc; }

.sidebar-user span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  color: #64748b;
  font-size: 1.1rem;
  transition: color .15s;
}
.sidebar-logout:hover { color: #ef4444; }

/* Toggle button (mobile) */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 300;
  background: #0f172a;
  border: none;
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
}

/* Main content */
#admin-content {
  min-height: 100vh;
}

#admin-content.with-sidebar {
  margin-left: 240px;
}

/* Admin topbar */
#admin-topbar {
  height: 56px;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  #admin-sidebar {
    transform: translateX(-240px);
  }
  #admin-sidebar.open {
    transform: translateX(0);
  }
  #admin-content.with-sidebar {
    margin-left: 0;
  }
  #sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ── Common admin UI ──────────────────────────────────────── */
.admin-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.5rem .75rem;
  flex-wrap: wrap;
  gap: .75rem;
}

.admin-page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}

.admin-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  margin: 0 1.5rem 1.5rem;
  overflow: visible;
}

.admin-card-body { padding: 1.25rem; }

/* Table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.admin-table th {
  background: #f8fafc;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  font-size: .75rem;
  letter-spacing: .04em;
  padding: .75rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
.admin-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  color: #1e293b;
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f8fafc; }
.admin-table a { color: #3b82f6; text-decoration: none; }
.admin-table a:hover { text-decoration: underline; }

/* Status badges */
.badge-estatus {
  display: inline-block;
  padding: .2em .65em;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #e2e8f0;
  color: #475569;
}
.badge-estatus.Operado,
.est-paciente-operado              { background: #dcfce7; color: #16a34a; }
.badge-estatus.Activo,
.est-valoraciones-clinicas,
.est-asesoria-medica               { background: #dbeafe; color: #1d4ed8; }
.badge-estatus.Contacto,
.est-acudio-a-su-primera-cita,
.est-contacto                      { background: #fef9c3; color: #a16207; }
.badge-estatus.Cancelado,
.est-no-candidato,
.est-no-acudio                     { background: #fee2e2; color: #dc2626; }
.badge-estatus.Prospecto,
.est-programacion-quirurgica       { background: #ede9fe; color: #7c3aed; }
.est-en-espera,
.est-cita-programada               { background: #fff7ed; color: #c2410c; }
.est-informacion,
.est-fallido                       { background: #f1f5f9; color: #64748b; }

/* Pagination */
.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  border-top: 1px solid #e2e8f0;
  font-size: .85rem;
  color: #64748b;
  flex-wrap: wrap;
  gap: .5rem;
}
.admin-pagination .pages { display: flex; gap: .25rem; }
.admin-pagination .pages button {
  width: 32px; height: 32px;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: .8rem;
  color: #475569;
  transition: background .15s;
}
.admin-pagination .pages button.active,
.admin-pagination .pages button:hover {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

/* Search / filter bar */
.admin-filters {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  background: #fff;
}
.admin-filters input,
.admin-filters select {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: .45rem .85rem;
  font-size: .875rem;
  color: #1e293b;
  background: #f8fafc;
  outline: none;
  transition: border-color .15s;
}
.admin-filters input:focus,
.admin-filters select:focus { border-color: #3b82f6; background: #fff; }
.admin-filters input { flex: 1; min-width: 180px; }

/* Modal improvements for admin */
body.admin-layout .modal-content {
  border-radius: 12px;
  border: none;
}
body.admin-layout .modal-header {
  background: #0f172a;
  color: #f1f5f9;
  border-radius: 12px 12px 0 0;
}
body.admin-layout .modal-header .btn-close {
  filter: invert(1);
}

/* Loading overlay */
.admin-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: #94a3b8;
  font-size: .875rem;
  gap: .5rem;
}

/* ── Theme toggle button ──────────────────────────────────── */
.sidebar-theme-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 1rem;
  cursor: pointer;
  padding: .25rem .4rem;
  border-radius: 6px;
  transition: color .15s, background .15s;
  line-height: 1;
}
.sidebar-theme-btn:hover { color: #f8fafc; background: #1e293b; }

/* ── Dark mode ────────────────────────────────────────────── */
[data-theme="dark"] body.admin-layout {
  background: #0d1117;
  color: #c9d1d9;
}

/* Content area */
[data-theme="dark"] #admin-content {
  background: #0d1117;
}

/* Page header */
[data-theme="dark"] .admin-page-header h1 { color: #e6edf3; }

/* Cards */
[data-theme="dark"] .admin-card {
  background: #161b22;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

/* Table */
[data-theme="dark"] .admin-table th {
  background: #0d1117;
  color: #8b949e;
  border-bottom-color: #30363d;
}
[data-theme="dark"] .admin-table td {
  color: #c9d1d9;
  border-bottom-color: #21262d;
}
[data-theme="dark"] .admin-table tr:last-child td { border-bottom: none; }
[data-theme="dark"] .admin-table tr:hover td { background: #1c2128; }
[data-theme="dark"] .admin-table a { color: #58a6ff; }

/* Filters bar */
[data-theme="dark"] .admin-filters {
  background: #161b22;
  border-bottom-color: #21262d;
}
[data-theme="dark"] .admin-filters input,
[data-theme="dark"] .admin-filters select {
  background: #0d1117;
  border-color: #30363d;
  color: #c9d1d9;
}
[data-theme="dark"] .admin-filters input:focus,
[data-theme="dark"] .admin-filters select:focus {
  border-color: #58a6ff;
  background: #0d1117;
}

/* Pagination */
[data-theme="dark"] .admin-pagination {
  border-top-color: #21262d;
  color: #8b949e;
}
[data-theme="dark"] .admin-pagination .pages button {
  background: #161b22;
  border-color: #30363d;
  color: #c9d1d9;
}
[data-theme="dark"] .admin-pagination .pages button:hover,
[data-theme="dark"] .admin-pagination .pages button.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
}

/* Bootstrap form controls */
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background-color: #0d1117;
  border-color: #30363d;
  color: #c9d1d9;
}
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background-color: #0d1117;
  border-color: #58a6ff;
  color: #c9d1d9;
  box-shadow: 0 0 0 .2rem rgba(31,111,235,.25);
}
[data-theme="dark"] .form-control::placeholder { color: #484f58; }

/* Iconos nativos del browser (calendario, reloj, flechas) en dark mode */
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"],
[data-theme="dark"] input[type="datetime-local"],
[data-theme="dark"] input[type="month"],
[data-theme="dark"] input[type="week"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] select,
[data-theme="dark"] .form-select {
  color-scheme: dark;
}
[data-theme="dark"] .form-control:disabled,
[data-theme="dark"] .form-select:disabled {
  background-color: #161b22;
  color: #6e7681;
}
[data-theme="dark"] .form-check-input {
  background-color: #0d1117;
  border-color: #30363d;
}
[data-theme="dark"] .form-check-input:checked {
  background-color: #1f6feb;
  border-color: #1f6feb;
}
[data-theme="dark"] .form-label { color: #c9d1d9; }
[data-theme="dark"] .form-text,
[data-theme="dark"] .text-muted  { color: #8b949e !important; }

/* Nav tabs */
[data-theme="dark"] .nav-tabs {
  border-bottom-color: #21262d;
}
[data-theme="dark"] .nav-tabs .nav-link {
  color: #8b949e;
}
[data-theme="dark"] .nav-tabs .nav-link:hover {
  color: #c9d1d9;
  border-color: #30363d #30363d #21262d;
}
[data-theme="dark"] .nav-tabs .nav-link.active {
  background: #161b22;
  border-color: #30363d #30363d #161b22;
  color: #e6edf3;
}

/* Bootstrap modals */
[data-theme="dark"] .modal-content {
  background: #161b22;
  border-color: #30363d;
  color: #c9d1d9;
}
[data-theme="dark"] body.admin-layout .modal-header {
  background: #0d1117;
  border-bottom-color: #30363d;
}
[data-theme="dark"] .modal-footer {
  border-top-color: #30363d;
}
[data-theme="dark"] .modal-body label,
[data-theme="dark"] .modal-body p { color: #c9d1d9; }

/* Alerts */
[data-theme="dark"] .alert-info {
  background: #1c2e4a;
  border-color: #1f6feb;
  color: #79c0ff;
}
[data-theme="dark"] .alert-success {
  background: #1a3a2a;
  border-color: #238636;
  color: #56d364;
}
[data-theme="dark"] .alert-danger {
  background: #3a1a1a;
  border-color: #da3633;
  color: #ff7b72;
}
[data-theme="dark"] .alert-warning {
  background: #2d2208;
  border-color: #9e6a03;
  color: #e3b341;
}

/* Badges */
[data-theme="dark"] .badge-estatus {
  background: #21262d;
  color: #8b949e;
}

/* Buttons — light outline variants */
[data-theme="dark"] .btn-outline-secondary {
  color: #8b949e;
  border-color: #30363d;
}
[data-theme="dark"] .btn-outline-secondary:hover {
  background: #21262d;
  color: #c9d1d9;
}
[data-theme="dark"] .btn-light {
  background: #21262d;
  border-color: #30363d;
  color: #c9d1d9;
}

/* HR */
[data-theme="dark"] hr { border-color: #21262d; }

/* Toggle icon: moon shown in light mode, sun shown in dark mode */
.sidebar-theme-btn .icon-sun  { display: none; }
.sidebar-theme-btn .icon-moon { display: inline; }
[data-theme="dark"] .sidebar-theme-btn .icon-sun  { display: inline; }
[data-theme="dark"] .sidebar-theme-btn .icon-moon { display: none; }


[data-theme="dark"] .table {
    color: #c9d1d9;
}

/* ── Segundo factor ─────────────────────────────────────────── */
.tfa-codigo {
  font-size: 22px;
  letter-spacing: .35em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.mp-tfa-alta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: start;
  max-width: 820px;
}
.mp-tfa-qr {
  background: #fff;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, .1);
  line-height: 0;
}
.mp-tfa-qr svg { display: block; width: 200px; height: 200px; }
.mp-tfa-pasos { margin: 0 0 16px; padding-left: 20px; }
.mp-tfa-pasos li { margin-bottom: 8px; }
.mp-tfa-secreto {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .05);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  letter-spacing: .08em;
  user-select: all;
  word-break: break-all;
}
.mp-tfa-lista {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.mp-tfa-lista li {
  background: rgba(255, 255, 255, .7);
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
  user-select: all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  letter-spacing: .06em;
}
@media (max-width: 700px) {
  .mp-tfa-alta-grid { grid-template-columns: 1fr; justify-items: center; }
}

/* ── Teléfono: barra superior fija ────────────────────────────
   El botón del menú flotaba sobre el contenido y tapaba títulos y botones de
   regreso; ahora vive en una barra, y el menú abre debajo de ella. */
#barra-movil { display: none; }
@media (max-width: 768px) {
  #barra-movil {
    display: flex; align-items: center;
    position: fixed; top: 0; left: 0; right: 0; z-index: 250;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0 64px;
    background: #0f172a; color: #f1f5f9; font-weight: 700; font-size: 1rem;
    box-shadow: 0 1px 0 #1e293b;
  }
  .barra-movil-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #sidebar-toggle { top: calc(8px + env(safe-area-inset-top, 0px)); left: 12px; background: #1e293b; }
  #admin-sidebar {
    top: calc(56px + env(safe-area-inset-top, 0px));
    height: calc(100% - 56px - env(safe-area-inset-top, 0px));
  }
  #admin-content.with-sidebar { padding-top: calc(56px + env(safe-area-inset-top, 0px)); }

  /* Las tablas con etiquetas por celda se vuelven tarjetas (antes solo en Pacientes;
     Contactos y Dispositivos se salían de la pantalla). */
  .admin-table:has(td[data-label]) thead { display: none; }
  .admin-table:has(td[data-label]) tr { display: block; border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: .75rem; }
  .admin-table:has(td[data-label]) td { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid #f1f5f9; overflow-wrap: anywhere; text-align: right; }
  .admin-table:has(td[data-label]) td::before { content: attr(data-label); font-weight: 600; color: #64748b; font-size: .75rem; white-space: nowrap; text-align: left; }
  [data-theme="dark"] .admin-table:has(td[data-label]) tr { border-color: #30363d; }
  [data-theme="dark"] .admin-table:has(td[data-label]) td { border-bottom-color: #21262d; }
}
