/* ============================================================================
   FisioCam (base MediCitas) — Hoja de estilos (mobile-first)
   Estrategia: estilos base para móvil; @media (min-width) amplía para
   pantallas medianas y grandes. Variables CSS para el tema.
   ========================================================================== */

:root {
  /* Paleta FisioCam */
  --brand-violet: #6A1FA0;      /* Violeta FisioCam: color principal, botones */
  --brand-violet-text: #5E1B8F; /* Violeta texto: títulos, palabra FISIO */
  --brand-magenta: #A21C96;     /* Magenta movimiento: acentos puntuales */
  --brand-teal: #2BB3B1;        /* Turquesa salud: detalles, íconos */
  --brand-teal-text: #1E9E9B;   /* Turquesa texto: palabra CAM */
  --brand-graphite: #55535C;    /* Grafito: subtítulos y textos */
  --brand-mist: #F6F4F9;        /* Niebla: fondos suaves, tarjetas */

  --primary: var(--brand-violet);
  --primary-dark: #561984;
  --primary-light: #EDE3F5;
  --primary-100: var(--brand-mist);
  --accent: var(--brand-magenta);
  --teal: var(--brand-teal);
  --teal-dark: var(--brand-teal-text);
  --teal-light: #DDF4F3;
  --bg: var(--brand-mist);
  --surface: #ffffff;
  --text: #2B2930;
  --text-muted: var(--brand-graphite);
  --border: #E5E1EB;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --danger-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --info: #1E9E9B;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(43, 41, 48, 0.06), 0 6px 20px rgba(106, 31, 160, 0.06);
  --shadow-lg: 0 12px 40px rgba(43, 41, 48, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Outfit", var(--font);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3 { line-height: 1.25; font-family: var(--font-display); color: var(--brand-violet-text); }
button { font-family: inherit; }

.boot-splash {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
.view { padding: 1.25rem 0 3rem; min-height: 62vh; }
.footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  background: var(--surface);
}

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner { display: flex; align-items: center; gap: 0.75rem; height: 62px; }
.brand {
  display: flex; align-items: center; gap: 0.55rem;
  font-family: var(--font-display); font-weight: 700; font-size: 1.3rem;
  letter-spacing: 0.02em; color: var(--brand-violet-text);
}
.brand-fisio { color: var(--brand-violet-text); }
.brand-cam { color: var(--brand-teal-text); }
.brand:hover { color: var(--brand-violet-text); }
.brand-icon { width: 38px; height: 38px; display: block; }

.nav { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.nav-list { display: flex; gap: 0.2rem; list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: block; padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 600; font-size: 0.92rem;
}
.nav-list a:hover { background: var(--bg); color: var(--text); }
.nav-list a.active { background: var(--primary-light); color: var(--primary-dark); }

.user-menu { display: flex; align-items: center; gap: 0.75rem; }
.user-chip { display: flex; align-items: center; gap: 0.5rem; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 0.82rem;
  flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-meta strong { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.user-meta small { color: var(--text-muted); font-size: 0.72rem; }

.nav-toggle {
  display: none;
  flex-direction: column; justify-content: center; gap: 4px;
  width: 42px; height: 42px; margin-left: auto;
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; padding: 0 9px;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ---------- Encabezados de página ---------- */
.page-head { margin-bottom: 1.25rem; }
.page-head h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.page-head p { margin: 0; color: var(--text-muted); }

.section-title { font-size: 1.08rem; margin: 1.5rem 0 0.75rem; }

/* ---------- Tarjetas y rejillas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
}
.grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 0.9rem;
  cursor: pointer; line-height: 1.3;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); color: #fff; }
.btn-outline-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-light); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.32rem 0.7rem; font-size: 0.82rem; }

/* ---------- Insignias y chips ---------- */
.badge {
  display: inline-flex; align-items: center; padding: 0.18rem 0.6rem;
  border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: #15803d; }
.badge-muted { background: var(--brand-mist); color: var(--text-muted); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
.chip {
  display: inline-block; background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}

/* ---------- Formularios ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.85rem; }
input, select, textarea {
  width: 100%; padding: 0.6rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(106, 31, 160, 0.12);
}
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.field-hint { font-size: 0.76rem; color: var(--text-muted); margin-top: 0.3rem; }

/* ---------- Filtros ---------- */
.filters { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1.25rem; }
.filters .form-group { margin: 0; }

/* ---------- Tarjeta de médico ---------- */
.doctor-card { display: flex; gap: 0.9rem; align-items: flex-start; }
.doctor-avatar {
  flex-shrink: 0; width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 800; font-size: 1.15rem;
}
.doctor-info { flex: 1; min-width: 0; }
.doctor-info h3 { margin: 0 0 0.3rem; font-size: 1.04rem; }
.doctor-bio { margin: 0.55rem 0 0; font-size: 0.85rem; }
.doctor-actions { flex-shrink: 0; align-self: center; }

/* ---------- Tarjeta de cita ---------- */
.appointment-card { display: flex; flex-direction: column; gap: 0.75rem; }
.appt-main { display: flex; gap: 0.9rem; align-items: flex-start; }
.appt-date {
  flex-shrink: 0; width: 56px; text-align: center;
  background: var(--bg); border-radius: var(--radius-sm); padding: 0.45rem 0.2rem;
}
.appt-day { display: block; font-size: 1.35rem; font-weight: 800; line-height: 1; }
.appt-month { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; }
.appt-info { flex: 1; min-width: 0; }
.appt-info h3 { margin: 0; font-size: 1rem; }
.appt-time { margin: 0.2rem 0 0; font-weight: 600; }
.appt-reason { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.87rem; }
.appt-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 0.75rem; }

/* ---------- Selector de fecha y horarios ---------- */
.date-chips { display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.2rem 0 0.6rem; }
.date-chip {
  flex-shrink: 0; padding: 0.45rem 0.65rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 0.8rem;
  text-align: center; min-width: 62px; color: var(--text);
}
.date-chip .dow { display: block; font-size: 0.66rem; color: var(--text-muted); text-transform: capitalize; }
.date-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.date-chip.active .dow { color: #EDE3F5; }
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 0.5rem; }
.slot-btn {
  padding: 0.5rem 0.25rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 0.85rem;
}
.slot-btn:hover { border-color: var(--primary); color: var(--primary); }
.slot-btn.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab-btn {
  padding: 0.55rem 1rem; background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; font-weight: 600;
  color: var(--text-muted); white-space: nowrap;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Tarjetas de estadísticas ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.85rem; margin-bottom: 1.5rem; }
.stat-value { font-size: 1.7rem; font-weight: 800; }
.stat-label { color: var(--text-muted); font-size: 0.83rem; }

/* ---------- Héroe / bienvenida ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(120deg, var(--brand-violet-text) 0%, var(--brand-violet) 50%, var(--brand-magenta) 100%);
  color: #fff; border-radius: var(--radius); padding: 1.4rem; margin-bottom: 1.4rem;
}
/* Arco y puntos turquesa inspirados en el logo */
.hero::before {
  content: ""; position: absolute; right: -60px; top: -70px;
  width: 230px; height: 230px; border-radius: 50%;
  border: 10px solid transparent; border-top-color: var(--brand-teal); border-left-color: var(--brand-teal);
  transform: rotate(-20deg); opacity: 0.9; pointer-events: none;
}
.hero::after {
  content: ""; position: absolute; right: 150px; bottom: 22px;
  width: 10px; height: 10px; border-radius: 50%; background: var(--brand-teal);
  box-shadow: 18px -16px 0 -1px var(--brand-teal), 34px -34px 0 -2px var(--brand-teal);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero h2 { margin: 0 0 0.25rem; color: #fff; }
.hero p { margin: 0; opacity: 0.92; }
.hero .btn { background: #fff; color: var(--primary-dark); margin-top: 0.9rem; }

/* ---------- Tablas (panel admin) ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
tr:last-child td { border-bottom: none; }
th { background: var(--bg); font-weight: 700; color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Autenticación ---------- */
.auth-wrap { max-width: 430px; margin: 1.5rem auto; }
.auth-logo { display: block; width: 190px; max-width: 60%; margin: 0.5rem auto 1.25rem; }
.auth-card { padding: 1.4rem; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.auth-tab {
  flex: 1; padding: 0.6rem; background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; font-weight: 600; color: var(--text-muted);
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-form h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.auth-form > .muted { margin: 0 0 1rem; }
.demo-hint { margin-top: 1.25rem; padding: 0.75rem; background: var(--bg); border-radius: var(--radius-sm); font-size: 0.79rem; color: var(--text-muted); }
.demo-hint code { background: #fff; padding: 0 0.2rem; border-radius: 4px; border: 1px solid var(--border); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: 1rem; left: 1rem; right: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem; z-index: 200;
}
.toast {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--text); color: #fff;
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 0.9rem;
  transform: translateY(8px); opacity: 0; transition: all 0.25s ease;
}
.toast.show { transform: none; opacity: 1; }
.toast-success { background: #15803d; }
.toast-error { background: var(--danger); }
.toast-info { background: var(--teal-dark); }
.toast-icon { font-weight: 800; }

/* ---------- Modales ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(43, 20, 60, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }

/* ---------- Varios ---------- */
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; margin: 2rem auto; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }
.muted { color: var(--text-muted); }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.hidden { display: none !important; }

/* Lista simple (agenda de disponibilidad) */
.sched-list { display: flex; flex-direction: column; gap: 0.5rem; }
.sched-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
}
.sched-row .range { font-weight: 700; }
.sched-row .day { color: var(--text-muted); font-size: 0.82rem; }
.remove-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; line-height: 1; padding: 0.2rem 0.4rem; }

/* ============================================================================
   Puntos de corte: tablet y escritorio
   ========================================================================== */
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .form-row { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .view { padding: 1.5rem 0 3rem; }
}

@media (min-width: 900px) {
  .toasts { left: auto; right: 1rem; max-width: 380px; }
}

/* Menú colapsado en móvil */
@media (max-width: 767px) {
  .nav-toggle { display: flex; }
  .nav {
    position: absolute; top: 62px; left: 0; right: 0;
    flex-direction: column; align-items: stretch;
    background: var(--surface); padding: 0.85rem 1rem 1rem;
    border-bottom: 1px solid var(--border);
    display: none; gap: 0.4rem;
    box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav-list { flex-direction: column; }
  .nav-list a { padding: 0.7rem 0.75rem; }
  .user-menu { flex-direction: row; justify-content: space-between; padding-top: 0.6rem; border-top: 1px solid var(--border); }
}

/* ---------- Calendario de citas (admin) ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.6rem; }
.cal-title { display: flex; align-items: center; gap: 0.6rem; }
.calendar-scroll { overflow-x: auto; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(78px, 1fr)); gap: 4px; min-width: 640px; }
.cal-dow {
  text-align: center; font-size: 0.7rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; padding: 0.25rem 0;
}
.cal-cell {
  min-height: 74px; border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; background: var(--surface);
  display: flex; flex-direction: column; gap: 3px; overflow: hidden;
}
.cal-empty { background: transparent; border-color: transparent; }
.cal-num { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }
.cal-cell.has-appt { background: #f0fdf4; border-color: #86efac; }
.cal-appt { background: #16a34a; color: #fff; border-radius: 6px; padding: 3px 5px; font-size: 0.68rem; line-height: 1.25; }
.cal-appt-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-pay-btn {
  border: none; border-radius: 4px; cursor: pointer;
  font-size: 0.62rem; font-weight: 700; padding: 2px 6px;
  background: rgba(255, 255, 255, 0.92); color: #15803d;
}
.cal-appt .cal-pay-btn { width: 100%; margin-top: 2px; }
.cal-pay-btn.paid { background: #dcfce7; color: #15803d; }

/* ---------- Selector de fecha (crear cita por fecha) ---------- */
.day-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day-dow {
  text-align: center; font-size: 0.68rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; padding: 0.25rem 0;
}
.day-cell {
  aspect-ratio: 1; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; font-weight: 600; color: var(--text);
  display: grid; place-items: center;
}
.day-cell:hover:not(:disabled) { border-color: var(--primary); }
.day-cell.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.day-cell.today { border-color: var(--primary); color: var(--primary); }
.day-cell.today.selected { color: #fff; }
.day-cell.past { opacity: 0.4; cursor: default; }
.day-cell.empty { visibility: hidden; }

/* ---------- Acentos de marca FisioCam ---------- */
.topbar { border-bottom: 3px solid transparent; border-image: linear-gradient(90deg, var(--brand-teal), var(--brand-violet) 55%, var(--brand-magenta)) 1; }
.btn-primary:focus-visible, .btn:focus-visible { outline: 3px solid rgba(43, 179, 177, 0.55); outline-offset: 2px; }
.stat-value { color: var(--brand-violet-text); font-family: var(--font-display); }
::selection { background: rgba(43, 179, 177, 0.3); }
