:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --text: #171717;
  --muted: #6d6a65;
  --line: #ded9d0;
  --busy: #bd3d3d;
  --busy-dark: #9f3030;
  --locked: #e6e2dc;
  --selected: #1f7768;
  --selected-soft: #d7eee9;
  --shadow: 0 12px 32px rgba(0,0,0,.08);
  --radius: 18px;
  --slot-h: 48px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(31,119,104,.35);
  outline-offset: 2px;
}


/* =========================
   PORTADA
   ========================= */

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.brand {
  display: inline-flex;
  flex-direction: column;
  line-height: .82;
  letter-spacing: .05em;
  user-select: none;
}

.brand__gloria {
  font-weight: 950;
  font-size: 27px;
}

.brand__estudios {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .34em;
  margin-top: 7px;
}

.brand--landing {
  transform: scale(1.7);
  transform-origin: center;
}


/* =========================
   APLICACIÓN
   ========================= */

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 120px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 2px 18px;
}

.group-badge {
  background: #111;
  color: #fff;
  border-radius: 999px;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .02em;
}


/* =========================
   TARJETA CALENDARIO
   ========================= */

.calendar-card {
  background: var(--surface);
  border: 1px solid rgba(0,0,0,.055);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 9px;
}

.week-title-wrap {
  text-align: center;
}

.week-title-wrap h1 {
  margin: 0;
  font-size: clamp(18px, 3vw, 25px);
  line-height: 1.1;
}

.icon-btn,
.duration-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  min-width: 44px;
  height: 44px;
  font-size: 27px;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: .28;
  cursor: default;
}

.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--selected);
  padding: 5px 8px;
  margin-top: 3px;
  font-weight: 750;
  font-size: 12px;
  cursor: pointer;
}

.quota-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 12px 9px;
}

.quota-pill {
  background: #f1eee8;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 750;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 11px;
  padding: 0 12px 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  display: inline-block;
  background: #fff;
}

.legend-dot--busy {
  background: var(--busy);
  border-color: var(--busy);
}

.legend-dot--locked {
  background: var(--locked);
  border-color: var(--locked);
}


/* =========================
   GRID CALENDARIO
   ========================= */

.calendar-scroll {
  overflow: auto;
  overscroll-behavior-inline: contain;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
}

.calendar-grid {
  --time-col: 64px;
  display: grid;
  grid-template-columns: var(--time-col) repeat(7, minmax(88px, 1fr));
  min-width: 750px;
  position: relative;
}

.grid-corner,
.day-head,
.time-label {
  background: var(--surface);
  z-index: 3;
}

.grid-corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 6;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-height: 60px;
}

.day-head {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 60px;
  display: grid;
  place-items: center;
  text-align: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
}

.day-head__dow {
  display: block;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .06em;
}

.day-head__date {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 900;
}

.day-head--today .day-head__date {
  width: 31px;
  height: 31px;
  line-height: 31px;
  border-radius: 50%;
  background: #111;
  color: #fff;
  margin-inline: auto;
}

.time-label {
  position: sticky;
  left: 0;
  z-index: 4;
  height: var(--slot-h);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 5px 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.slot {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  height: var(--slot-h);
  background: #fff;
  cursor: pointer;
  position: relative;
  touch-action: manipulation;
}

.slot:hover:not(:disabled) {
  background: #f7fbfa;
}

.slot--busy {
  background: var(--busy);
  cursor: not-allowed;
}

.slot--busy:hover {
  background: var(--busy-dark);
}

.slot--locked {
  background: var(--locked);
  cursor: not-allowed;
}

.slot--selected {
  background: var(--selected-soft);
  box-shadow: inset 0 0 0 2px var(--selected);
  z-index: 2;
}

.slot--selected::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 8px;
  background: rgba(31,119,104,.08);
}

.slot[disabled] {
  opacity: 1;
}

.calendar-hint {
  margin: 0;
  padding: 12px 14px 15px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}


/* =========================
   SELECCIÓN / RESERVA
   ========================= */

.selection-card {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(720px, calc(100% - 24px));
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: #111;
  color: #fff;
  border-radius: 17px;
  padding: 12px;
  box-shadow: 0 18px 44px rgba(0,0,0,.26);
}

.selection-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.selection-label {
  color: #aaa;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 3px;
}

#selectionText {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
}

.clear-btn {
  border: 0;
  background: transparent;
  color: #bbb;
  font-size: 11px;
  cursor: pointer;
  padding: 8px;
}

.duration-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.duration-btn {
  min-width: 38px;
  width: 38px;
  height: 38px;
  color: #fff;
  border-color: #444;
  background: #262626;
}

#durationText {
  min-width: 32px;
  text-align: center;
  font-weight: 850;
  font-size: 13px;
}

.reserve-btn {
  border: 0;
  border-radius: 12px;
  background: var(--selected);
  color: #fff;
  font-weight: 850;
  min-height: 44px;
  padding: 0 17px;
  cursor: pointer;
}

.reserve-btn:disabled {
  opacity: .55;
  cursor: wait;
}


/* =========================
   INDICADOR DE CARGA
   NO BLOQUEA LA INTERFAZ
   ========================= */

.loading {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  background: #111;
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 750;
  box-shadow: 0 8px 25px rgba(0,0,0,.18);

  /* Nunca debe impedir usar la web */
  pointer-events: none;
}

.loading .spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}


/* =========================
   MODAL
   ========================= */

.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.48);
}

.modal__dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px));
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 25px 65px rgba(0,0,0,.24);
}

.modal__icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--selected-soft);
  color: var(--selected);
  font-weight: 950;
  font-size: 26px;
}

.modal__dialog h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.modal__dialog p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.4;
}

.modal__dialog .reserve-btn {
  width: 100%;
}


/* =========================
   ERRORES
   ========================= */

.error-screen {
  min-height: 70vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px;
}

.error-screen h1 {
  margin-bottom: 7px;
}

.error-screen p {
  color: var(--muted);
  max-width: 500px;
}


/* =========================
   RESPONSIVE
   ========================= */

@media (max-width: 720px) {
  :root {
    --slot-h: 50px;
  }

  .app {
    padding: 12px 10px 132px;
  }

  .topbar {
    margin-bottom: 12px;
  }

  .brand__gloria {
    font-size: 23px;
  }

  .group-badge {
    font-size: 11px;
    padding: 7px 10px;
  }

  .calendar-card {
    border-radius: 14px;
  }

  .calendar-toolbar {
    padding-top: 13px;
  }

  .calendar-grid {
    min-width: 735px;
  }

  .calendar-hint {
    text-align: left;
  }

  .selection-card {
    grid-template-columns: 1fr auto;
    gap: 9px;
  }

  .selection-main {
    grid-column: 1 / -1;
  }

  .reserve-btn {
    min-width: 125px;
  }

  .loading {
    top: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
  }
}

@media (max-width: 420px) {
  .legend {
    gap: 9px;
    justify-content: flex-start;
    padding-left: 14px;
  }

  .quota-row {
    justify-content: flex-start;
  }

  .selection-card {
    width: calc(100% - 16px);
  }
}


/* =========================
   UTILIDADES
   ========================= */

[hidden] {
  display: none !important;
}