/* =====================================================================
   Sistema de citas · Consultorio Dr. Alexi García
   Archivo con eje de ancho: titulares semi-expandidos, cifras tabulares.
   Teal = consulta / acción · Dorado = preferencial · Violeta = turno movido
   ===================================================================== */
:root {
  --ink: #10201C;
  --ink-2: #3E4F49;
  --muted: #66766F;
  --line: #D9E0DB;
  --line-2: #E8EDE9;
  --bg: #F1F4F1;
  --paper: #FFFFFF;
  --teal: #1D6B58;
  --teal-2: #155444;
  --teal-soft: #DCEBE3;
  --gold: #A8730A;
  --gold-soft: #F7EACB;
  --violet: #5A4E93;
  --violet-soft: #E8E4F5;
  --red: #B3261E;
  --red-soft: #F8E1DE;
  --blue: #3A5675;
  --blue-soft: #E2E9F1;
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-card: 14px;
  --r-ctl: 9px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--teal) 55%, transparent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- tipografía ---------- */
h1, h2, h3 { margin: 0; font-stretch: 112%; letter-spacing: -0.015em; line-height: 1.12; }
h1 { font-size: clamp(26px, 5.4vw, 36px); font-weight: 700; }
h2 { font-size: 21px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 650; }
p { margin: 0 0 10px; }
.lead { color: var(--ink-2); font-size: 16.5px; max-width: 60ch; }
.small { font-size: 13.5px; color: var(--muted); }
.num { font-stretch: 118%; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- estructura ---------- */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 10px 18px; min-height: 58px; }
.brand { display: flex; flex-direction: column; line-height: 1.15; margin-right: auto; text-decoration: none; color: inherit; }
.brand b { font-stretch: 115%; font-weight: 700; font-size: 16.5px; }
.brand span { font-size: 12.5px; color: var(--muted); }
.who { font-size: 13.5px; color: var(--muted); text-align: right; line-height: 1.2; }
.who b { display: block; color: var(--ink); font-weight: 600; }

.nav { max-width: 1180px; margin: 0 auto; display: flex; gap: 4px; overflow-x: auto; padding: 0 12px; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: 0 0 auto; padding: 9px 12px 10px; color: var(--muted); text-decoration: none; font-weight: 550; font-size: 14.5px;
  border-bottom: 2.5px solid transparent; white-space: nowrap;
}
.nav a[aria-current="page"] { color: var(--ink); border-color: var(--teal); }
.nav a .badge { margin-left: 6px; }

.main { max-width: 1180px; margin: 0 auto; padding: 22px 18px 110px; }
.main.narrow { max-width: 660px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.head p { margin: 6px 0 0; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* barra inferior del paciente en móvil */
.tabbar { display: none; }
@media (max-width: 760px) {
  .is-paciente .nav-wrap { display: none; }
  .is-paciente .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30;
    background: var(--paper); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
  }
  .tabbar a { text-align: center; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 0; }
  .tabbar a svg { display: block; margin: 0 auto 2px; width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--teal); }
}

/* ---------- superficies ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.note { background: var(--teal-soft); border-radius: 10px; padding: 12px 14px; font-size: 14.5px; color: var(--teal-2); }
.note.gold { background: var(--gold-soft); color: #6E4B05; }
.note.red { background: var(--red-soft); color: var(--red); }
.note.violet { background: var(--violet-soft); color: var(--violet); }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.pre { white-space: pre-line; }

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 16px;
  border-radius: var(--r-ctl); border: 1px solid var(--teal); background: var(--teal); color: #fff; font-weight: 650;
  text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--teal-2); border-color: var(--teal-2); }
.btn.ghost { background: transparent; color: var(--teal); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--teal); background: var(--paper); }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.btn.gold:hover { background: #8D6008; }
.btn.danger { background: transparent; color: var(--red); border-color: #E6C4C0; }
.btn.danger:hover { border-color: var(--red); }
.btn.sm { min-height: 34px; padding: 5px 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--teal); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.field > small { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; background: var(--paper); border: 1px solid #C5CFC9;
  border-radius: var(--r-ctl); font-size: 16px;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--teal); outline: 2px solid var(--teal-soft); }
.code-input { letter-spacing: .5em; font-size: 26px !important; text-align: center; font-stretch: 118%; font-weight: 700; }

.choice { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); cursor: pointer; margin-bottom: 10px; }
.choice input { margin-top: 4px; accent-color: var(--teal); width: 18px; height: 18px; flex: 0 0 auto; }
.choice:has(input:checked) { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.choice b { display: block; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.tag.teal { background: var(--teal-soft); color: var(--teal-2); }
.tag.gold { background: var(--gold-soft); color: #7A5306; }
.tag.violet { background: var(--violet-soft); color: var(--violet); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.blue { background: var(--blue-soft); color: var(--blue); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: #fff; font-size: 12px; font-weight: 700; }

/* ---------- pasos del asistente para agendar ---------- */
.steps { display: flex; gap: 6px; margin: 0 0 20px; padding: 0; list-style: none; }
.steps li { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.steps li.on { background: var(--teal); }
.step-label { font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.wz-nav { display: flex; gap: 10px; margin-top: 22px; }
.wz-nav .btn:last-child { flex: 1; }

/* ---------- días ---------- */
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.day {
  text-align: left; border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 12px 13px;
  display: flex; flex-direction: column; gap: 2px; min-height: 92px;
}
.day .dw { font-size: 13px; color: var(--muted); text-transform: capitalize; }
.day .dn { font-size: 26px; font-stretch: 118%; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.day .ds { font-size: 13px; font-weight: 600; color: var(--teal); margin-top: auto; }
.day.is-pref .ds { color: var(--gold); }
.day.is-full, .day.is-off { background: transparent; }
.day.is-full .ds, .day.is-off .ds { color: var(--muted); }
.day[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

/* ---------- rejilla de turnos (elemento central) ---------- */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.slot {
  position: relative; border-radius: 10px; border: 1.5px solid var(--teal); background: var(--paper); padding: 10px 8px 9px;
  text-align: center; min-height: 72px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.slot b { font-size: 21px; font-stretch: 118%; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.slot small { font-size: 12px; font-weight: 600; color: var(--teal); }
.slot:hover:not([disabled]) { background: var(--teal-soft); }
.slot.pref {
  border-color: var(--gold); color: #6E4B05;
  background: repeating-linear-gradient(135deg, var(--gold-soft) 0 7px, #FBF3DE 7px 14px);
}
.slot.pref small { color: var(--gold); }
.slot.pref:hover:not([disabled]) { background: var(--gold-soft); }
.slot[disabled] { border: 1px dashed #C9D2CC; background: transparent; color: #A3AEA8; cursor: default; }
.slot[disabled] small { color: #A3AEA8; }
.slot[aria-pressed="true"] { background: var(--teal); color: #fff; }
.slot[aria-pressed="true"] small { color: #CFE6DC; }
.slot.pref[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #fff; }
.slot.pref[aria-pressed="true"] small { color: #FBEFD2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; border: 1.5px solid var(--teal); }
.legend i.p { border-color: var(--gold); background: var(--gold-soft); }
.legend i.o { border: 1px dashed #C9D2CC; }

/* ---------- tarjeta de cita del paciente ---------- */
.appt { display: grid; grid-template-columns: 76px 1fr; gap: 14px; }
.appt-date { text-align: center; border-right: 1px solid var(--line-2); padding-right: 12px; }
.appt-date .m { font-size: 12.5px; color: var(--muted); text-transform: capitalize; }
.appt-date .d { font-size: 34px; font-stretch: 118%; font-weight: 700; line-height: 1; }
.appt-date .h { font-size: 17px; font-weight: 700; font-stretch: 112%; margin-top: 6px; color: var(--teal); }
.appt.pref .appt-date .h { color: var(--gold); }
.appt-body .tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 8px; }
.appt-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- agenda del doctor ---------- */
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; margin-bottom: 8px; scrollbar-width: thin; }
.strip .day { flex: 0 0 118px; min-height: 86px; }
.meter { height: 4px; background: var(--line-2); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--teal); }
.meter i.full { background: var(--gold); }

.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--line-2); }
.tl li:last-child { border-bottom: 0; }
.tl .t { font-size: 19px; font-stretch: 118%; font-weight: 700; letter-spacing: -0.02em; }
.tl .t small { display: block; font-size: 11.5px; font-weight: 600; color: var(--violet); font-stretch: 100%; letter-spacing: 0; }
.tl .who-p b { font-weight: 650; }
.tl .who-p .sub { font-size: 13.5px; color: var(--muted); }
.tl .who-p .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.tl .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tl li.free .t { color: #A3AEA8; }
.tl li.free .who-p { color: var(--muted); font-size: 14px; }
.tl li.pref { background: linear-gradient(90deg, var(--gold-soft), transparent 55%); box-shadow: inset 4px 0 0 var(--gold); }
.tl li.moved:not(.pref) { box-shadow: inset 4px 0 0 var(--violet); }
.tl li.done .who-p b { color: var(--teal-2); }
.tl li.noshow .who-p b { color: var(--muted); text-decoration: line-through; }
.tl li.ext .t { color: var(--gold); }
@media (max-width: 640px) {
  .tl li { grid-template-columns: 62px minmax(0, 1fr); }
  .tl .acts { grid-column: 1 / -1; justify-content: flex-start; }
}

.stats { list-style: none; margin: 0; padding: 0; }
.stats li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line-2); font-size: 14.5px; }
.stats li:last-child { border-bottom: 0; }
.stats li b { font-stretch: 112%; }
.stats li.hl b { color: var(--gold); }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tfoot td { font-weight: 700; border-top: 1px solid var(--line); }

/* ---------- modal / hoja ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(16, 32, 28, .42); display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal { background: var(--paper); border-radius: 16px; width: 100%; max-width: 560px; max-height: calc(100vh - 36px); overflow-y: auto; box-shadow: 0 30px 60px -20px rgba(16, 32, 28, .45); }
.modal.wide { max-width: 760px; }
.modal-h { position: sticky; top: 0; background: var(--paper); display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line-2); z-index: 1; }
.modal-b { padding: 18px; }
.x { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--muted); width: 40px; height: 40px; border-radius: 8px; }
.x:hover { background: var(--bg); }
@media (max-width: 640px) {
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); animation: up .22s ease-out; }
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 14.5px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(88px + var(--safe-b)); transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14.5px; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .4); animation: up .2s ease-out; }
.toast.err { background: var(--red); }

/* ---------- autenticación ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-side { background: var(--teal); color: #EAF4EF; padding: 44px 46px; display: flex; flex-direction: column; gap: 22px; }
.auth-side h1 { color: #fff; font-size: clamp(30px, 4vw, 46px); font-stretch: 115%; }
.auth-side .hours { border-top: 1px solid rgba(255, 255, 255, .25); padding-top: 18px; display: grid; gap: 12px; max-width: 420px; }
.auth-side .hours div { display: grid; grid-template-columns: 1fr auto; gap: 10px; font-size: 15px; }
.auth-side .hours b { font-stretch: 115%; color: #fff; }
.auth-side .mini { margin-top: auto; font-size: 13.5px; color: #BFDCD0; }
.auth-form { padding: 44px 30px; display: flex; flex-direction: column; justify-content: center; max-width: 470px; width: 100%; margin: 0 auto; }
.auth-form h2 { font-size: 26px; margin-bottom: 6px; }
.auth-form .lead { margin-bottom: 22px; }
.auth-alt { margin-top: 18px; font-size: 14.5px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 820px) {
  .auth { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 22px 24px; }
  .auth-side .mini { display: none; }
  .auth-form { padding: 26px 20px 50px; }
}

.loading { padding: 50px 0; text-align: center; color: var(--muted); }
.spin { display: inline-block; width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -5px; margin-right: 8px; }
@keyframes sp { to { transform: rotate(360deg); } }
.hide { display: none !important; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
