﻿:root {
  /* Paleta tomada del logo "Upright Medical Group":
     azul marino del emblema (#152369) y cian del texto (#00aeef) */
  --bg: #f3f5fa;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #6b7280;
  --line: #e3e7ef;
  --primary: #162977;
  --primary-dark: #0f1c56;
  --accent: #00aeef;
  --accent-dark: #0093c9;
  --danger: #c0392b;
  --success: #1e8e5a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  /* Zonas seguras de iPhone (notch / home indicator) */
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%; /* evita el zoom de texto en iOS al rotar */
}

/* Ninguna imagen debe desbordar su contenedor (clave en móvil) */
img {
  max-width: 100%;
  height: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- Topbar (blanca, para que el logo se lea correctamente) --- */
.topbar {
  background: #fff;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(21, 35, 105, 0.06);
  padding-top: env(safe-area-inset-top, 0px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 max(20px, var(--safe-l)) 0 max(20px, var(--safe-r));
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { height: 38px; width: auto; display: block; }
.nav { display: flex; gap: 20px; flex: 1; }
.nav a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 2px;
  border-bottom: 2px solid transparent;
}
.nav a:hover, .nav a:active { color: var(--accent); border-bottom-color: var(--accent); }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 0.9rem; color: var(--muted); }

/* --- Layout --- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px max(20px, var(--safe-l)) calc(60px + var(--safe-b)) max(20px, var(--safe-r));
}
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head.with-back { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.footer {
  text-align: center; color: var(--muted); font-size: 0.85rem;
  padding: 20px 20px calc(20px + var(--safe-b));
}

/* --- Cards --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card-title { margin: 0 0 14px; font-size: 1.05rem; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head .card-title { margin: 0; }
.count { font-size: 0.85rem; }
.form-card { max-width: 520px; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* --- Forms --- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  align-items: end;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; min-width: 0; }
.field span { color: var(--muted); font-weight: 500; }
/* --- Interruptor (activo / inactivo) --- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  min-height: 44px; /* objetivo táctil */
  -webkit-tap-highlight-color: transparent;
}
/* El checkbox real se oculta, pero sigue siendo accesible por teclado */
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #c3cad9;
  flex-shrink: 0;
  transition: background 0.18s ease;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.3);
  transition: transform 0.18s ease;
}
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(22px); }
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.switch-text { font-weight: 600; font-size: 0.92rem; }
/* El texto cambia según el estado, sin necesidad de JavaScript */
.switch-text .on { display: none; color: var(--success); }
.switch-text .off { color: var(--muted); }
.switch input:checked ~ .switch-text .on { display: inline; }
.switch input:checked ~ .switch-text .off { display: none; }

input, select, button {
  font-family: inherit;
}
/* OJO: se excluyen checkbox y radio. La regla lleva `appearance: none`, que
   les borraría la palomita y dejaría un cuadro vacío imposible de interpretar. */
input:not([type="checkbox"]):not([type="radio"]), select {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  /* 16px evita que Safari en iOS haga zoom automático al enfocar el campo */
  font-size: 16px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 16px;
  min-height: 44px; /* objetivo táctil recomendado por Apple */
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  background: #eef1f5;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; min-height: 38px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.inline { display: inline; }

/* --- Search bar --- */
.search-fields {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 14px;
  align-items: end;
}
.users-filters { grid-template-columns: 2fr 1fr 1fr auto; }
.search-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Selector de orden para móvil (oculto en escritorio) */
.mobile-sort { display: none; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.table th {
  font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--muted);
}
.table tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.88rem; }
/* Descripciones de items: respetan los saltos de línea del texto original */
.desc { white-space: pre-line; overflow-wrap: anywhere; }
.actions { white-space: nowrap; }
.actions > * { margin-left: 6px; }

/* Encabezados ordenables */
.sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 4px 0;
}
.sort-link:hover, .sort-link.is-active { color: var(--primary); }
.sort-link .arrow { font-size: 0.7em; }

/* --- Detail --- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.meta { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }

/* --- Badges / status --- */
.badge {
  display: inline-block;
  font-size: 0.72rem; text-transform: uppercase; padding: 3px 9px;
  border-radius: 999px; font-weight: 700; letter-spacing: 0.03em;
}
.badge-admin { background: #fde68a; color: #92400e; }
.badge-nurse { background: #bfdbfe; color: #1e3a8a; }
.status {
  display: inline-block;
  font-size: 0.8rem; padding: 3px 10px; border-radius: 999px;
  background: #e5e7eb; color: #374151;
}
.status-paid, .status-active { background: #d1fae5; color: #065f46; }
.status-unpaid, .status-inactive, .status-void { background: #fee2e2; color: #991b1b; }
.status-draft, .status-sent { background: #dbeafe; color: #1e40af; }

/* --- Alerts / misc --- */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: 0.9rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.note { color: var(--muted); font-size: 0.82rem; margin-top: 10px; }
.muted { color: var(--muted); }

/* --- Editor de horarios --- */
.schedule-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.schedule-row {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.schedule-row:last-child { border-bottom: 0; }
.schedule-day { min-width: 190px; }
.schedule-day-name { font-weight: 600; font-size: 0.95rem; }
.schedule-times { display: flex; gap: 14px; flex: 1; }
.schedule-times .field { flex: 1; max-width: 150px; }
/* Los días apagados se ven atenuados, pero siguen siendo editables */
.schedule-row:has(input[type="checkbox"]:not(:checked)) .schedule-times { opacity: 0.45; }
.custom-schedule { border-left: 3px solid var(--accent); padding-left: 14px; margin: 4px 0 8px; }

.alert-info {
  background: #e0f2fe; color: #075985; border: 1px solid #bae6fd;
}
.alert-info a { color: inherit; font-weight: 600; }

/* --- Modal de fin de horario --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 26px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.28);
}
.modal-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; }
.modal h2 { margin: 0 0 10px; font-size: 1.2rem; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 0.94rem; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }

/* Aviso de tiempo adicional */
.grace-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + var(--safe-b));
  background: #92400e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  z-index: 90;
}
.grace-banner[hidden] { display: none; }

/* --- Pantalla de fuera de horario --- */
.out-of-hours { max-width: 460px; text-align: center; }
.oh-icon { font-size: 2.6rem; margin-bottom: 6px; }
.oh-message { color: var(--muted); }
.oh-schedule { text-align: left; margin: 20px 0; }
.oh-schedule h2 { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; }
.oh-table td { padding: 8px 0; }
.oh-table tr.is-today { font-weight: 700; }
.oh-today {
  background: var(--accent); color: #fff; font-size: 0.68rem;
  padding: 1px 7px; border-radius: 999px; margin-left: 6px;
  text-transform: uppercase; font-weight: 700;
}

/* --- Login --- */
.login-wrap { display: flex; justify-content: center; padding-top: 5vh; }
.login-card { width: 100%; max-width: 390px; }
/* El logo es horizontal (~3.7:1); "Upright" se forma con el emblema + el texto,
   por eso NO debe partirse en dos líneas. */
.login-logo { display: block; width: 260px; max-width: 88%; height: auto; margin: 2px auto 18px; }
.login-title { margin: 0 0 4px; text-align: center; font-size: 1.15rem; }
.login-sub { margin: 0 0 22px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* --- Error page --- */
.error-page { display: flex; justify-content: center; padding-top: 5vh; }
.error-page .card { max-width: 460px; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* ==========================================================
   MÓVIL / TABLET  (iPhone, iPad en vertical)
   ========================================================== */
@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
  .search-fields, .users-filters { grid-template-columns: 1fr; }
  .search-actions .btn { flex: 1; }
}

@media (max-width: 640px) {
  .container { padding-top: 16px; }
  .page-head h1 { font-size: 1.25rem; }

  /* Topbar compacta */
  .topbar-inner { min-height: 54px; padding-top: 8px; padding-bottom: 6px; gap: 12px; }
  .brand img { height: 30px; }
  .nav { order: 3; width: 100%; gap: 18px; border-top: 1px solid var(--line); padding-top: 6px; }
  .user-box { margin-left: auto; }
  .user-name { font-size: 0.78rem; }

  /* Mostrar el selector de orden */
  .mobile-sort { display: block; }

  /* Tablas apiladas: cada fila se convierte en una tarjeta */
  .table.stacked { border-collapse: separate; border-spacing: 0; }
  .table.stacked thead { display: none; }
  .table.stacked tbody, .table.stacked tr, .table.stacked td { display: block; width: 100%; }
  .table.stacked tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 12px;
    margin-bottom: 12px;
    background: #fff;
  }
  .table.stacked tr:last-child { margin-bottom: 0; }
  .table.stacked td {
    border: 0;
    border-bottom: 1px solid #f1f3f5;
    padding: 9px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    text-align: right;
  }
  .table.stacked td:last-child { border-bottom: 0; }
  /* Etiqueta de la columna a la izquierda */
  .table.stacked td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }
  .table.stacked td[data-label=""]::before { content: none; }
  .table.stacked td[data-label=""] { justify-content: stretch; }
  .table.stacked td[data-label=""] .btn { width: 100%; }

  /* Acciones en columna dentro de la tarjeta */
  .actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
  .actions > * { margin-left: 0; }

  .meta { grid-template-columns: 1fr; gap: 2px; }
  .meta dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
  .meta dd { margin-bottom: 10px; }

  .form-card { max-width: none; }
  .form-actions .btn { flex: 1; }

  /* Horarios: cada día en bloque, entrada y salida lado a lado */
  .schedule-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0; }
  .schedule-day { min-width: 0; }
  .schedule-times .field { max-width: none; }
}

/* Modo standalone (instalada como PWA en iOS/Android) */
@media all and (display-mode: standalone) {
  .footer { padding-bottom: calc(28px + var(--safe-b)); }
}
