/* Admin panel. */

body.admin { background: var(--ivory); }

/* Login ------------------------------------------------------------------ */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--sand), var(--ivory) 55%);
}

.login-card { width: min(400px, 100%); padding: 34px 30px; text-align: center; }
.login-card h1 { font-family: var(--serif); font-size: 1.6rem; margin-top: 12px; }
.login-card .field, .login-card .error { text-align: start; }
.login-card .hint { margin-bottom: 22px; }

.brand-mark {
  width: 48px; height: 48px;
  margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--mocha), var(--rose));
  color: #fff;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
}

/* Header ----------------------------------------------------------------- */

.admin-header {
  background: var(--shell);
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 60;
  min-height: 64px;
}

.admin-brand { display: flex; align-items: center; gap: 11px; }
.admin-brand .brand-mark { width: 36px; height: 36px; font-size: 1.15rem; margin: 0; }
.admin-brand strong { display: block; font-size: .98rem; letter-spacing: .05em; line-height: 1.2; }
.admin-brand small { color: var(--ink-faint); font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-inline-end: auto; }

.tab {
  border: none;
  background: none;
  padding: 9px 15px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: .92rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab:hover { background: var(--sand); color: var(--ink); }
.tab.is-active { background: var(--ink); color: #fff; }

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
}
.tab.is-active .badge { background: var(--rose); }

.admin-header-right { display: flex; align-items: center; gap: 4px; }

/* Layout ----------------------------------------------------------------- */

.admin-main { max-width: 1240px; margin: 0 auto; padding: 26px 22px 60px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-head h2 { font-family: var(--serif); font-size: 1.5rem; margin: 0; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="search"] {
  width: 260px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--shell);
}
.filters select { width: auto; border-radius: 999px; padding: 9px 34px 9px 14px; }

/* Stats ------------------------------------------------------------------ */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.stat {
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat b { display: block; font-size: 1.7rem; font-family: var(--serif); line-height: 1.1; }
.stat span { font-size: .82rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.stat.is-alert { border-color: var(--warn); background: var(--warn-bg); }
.stat.is-alert b { color: var(--warn); }

/* Bookings --------------------------------------------------------------- */

.booking-list { display: grid; gap: 10px; }

.booking {
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 18px;
  display: grid;
  grid-template-columns: 108px 1fr auto;
  gap: 16px;
  align-items: center;
}
@media (max-width: 720px) { .booking { grid-template-columns: 1fr; } }

.booking.is-pending { border-inline-start: 4px solid var(--warn); }
.booking.is-approved { border-inline-start: 4px solid var(--ok); }
.booking.is-declined, .booking.is-cancelled { border-inline-start: 4px solid var(--line); opacity: .85; }
.booking.is-completed { border-inline-start: 4px solid var(--info); }

.booking-when { text-align: center; }
.booking-when .b-date { font-weight: 700; font-size: .95rem; }
.booking-when .b-time { color: var(--ink-soft); font-size: .88rem; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) { .booking-when { text-align: start; } }

.booking-main h3 { font-size: 1.02rem; margin: 0 0 3px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.booking-meta { color: var(--ink-soft); font-size: .88rem; display: flex; gap: 14px; flex-wrap: wrap; }
.booking-meta a { color: var(--ink-soft); text-decoration: none; }
.booking-meta a:hover { color: var(--mocha-dark); }
.booking-note {
  margin-top: 8px;
  padding: 8px 11px;
  background: var(--sand);
  border-radius: var(--radius-sm);
  font-size: .87rem;
  color: var(--ink-soft);
}
.booking-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.ref { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: .76rem; color: var(--ink-faint); }

/* Tables ----------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--line); }
.table th {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  background: var(--sand);
  white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FDFAF8; }
.table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table .muted-row td { opacity: .55; }

/* Calendar --------------------------------------------------------------- */

.cal-layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) { .cal-layout { grid-template-columns: 1fr; } }

.admin-calendar { padding: 16px; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head strong { font-size: 1.05rem; }

.cal-nav {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: var(--shell);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--ink-soft);
}
.cal-nav:hover { background: var(--sand); color: var(--ink); }

.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays {
  margin-bottom: 6px;
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
}

.cal-day {
  aspect-ratio: 1 / 1;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: .9rem;
  position: relative;
}
.cal-day.is-empty { visibility: hidden; cursor: default; }
.cal-day:hover:not(.is-empty) { background: var(--sand); }
.cal-day.is-selected { background: var(--mocha); color: #fff; }
.cal-day.is-closed { background: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--sand) 4px, var(--sand) 8px); color: var(--ink-faint); }
.cal-day.is-past { opacity: .4; }
.cal-day.is-today { box-shadow: inset 0 0 0 1.5px var(--mocha); font-weight: 700; }

.day-counts { display: flex; gap: 3px; font-size: .66rem; font-weight: 700; }
.count-approved { color: var(--ok); }
.count-pending  { color: var(--warn); }
.cal-day.is-selected .count-approved,
.cal-day.is-selected .count-pending { color: #fff; }

/* Day panel -------------------------------------------------------------- */

.day-panel { padding: 18px; min-height: 380px; }
.day-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.timeline { display: grid; gap: 8px; margin-top: 6px; }

.tl-item {
  display: grid;
  grid-template-columns: 118px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--shell);
}
@media (max-width: 620px) { .tl-item { grid-template-columns: 1fr; } }

.tl-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; color: var(--ink-soft); }
.tl-item.is-pending { background: var(--warn-bg); border-color: #EBD7A9; }
.tl-item.is-approved { background: var(--ok-bg); border-color: #C6DFD1; }
.tl-item.is-block { background: var(--sand); border-style: dashed; }
.tl-item.is-cancelled, .tl-item.is-declined { opacity: .6; }
.tl-name { font-weight: 600; }
.tl-sub { font-size: .85rem; color: var(--ink-soft); }

.window-note {
  font-size: .88rem;
  color: var(--ink-soft);
  background: var(--sand);
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.window-note.is-closed { background: var(--danger-bg); color: var(--danger); }

.spots-panel { margin-bottom: 16px; }
.spots-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.spots-head strong { font-size: .92rem; }
.spot-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.spot-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 11px;
  border: 1px solid var(--ok);
  border-radius: 999px;
  background: var(--ok-bg);
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
}
.spot-chip.is-taken { border-color: var(--line); background: var(--sand); color: var(--ink-faint); }
.spot-chip button {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 999px;
}
.spot-chip button:hover { background: rgba(0, 0, 0, .06); }
.spot-rows { display: grid; gap: 8px; }
.spot-row { display: flex; gap: 8px; align-items: center; }
.spot-row input { flex: 1; }
.spot-dot {
  position: absolute;
  top: 5px;
  inset-inline-end: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}
.cal-day.is-selected .spot-dot { background: #fff; }

/* Hours ------------------------------------------------------------------ */

.hours-card { padding: 6px 18px; }

.hours-day {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 14px;
  align-items: start;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.hours-day:last-child { border-bottom: none; }
@media (max-width: 640px) { .hours-day { grid-template-columns: 1fr; } }

.hours-day > strong { padding-top: 8px; }
.hours-windows { display: grid; gap: 8px; }
.hours-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hours-row input[type="time"] { width: 130px; }
.hours-closed { color: var(--ink-faint); font-size: .9rem; padding-top: 9px; }
.hours-save { margin-top: 18px; }

/* WhatsApp's own green, so the action is recognisable at a glance. */
.btn-wa { background: #25D366; color: #08301A; }
.btn-wa:hover:not(:disabled) { background: #1DA851; color: #fff; }

.settings-card code {
  background: var(--sand);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .85em;
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--shell);
  border-radius: 8px;
  width: 32px; height: 32px;
  cursor: pointer;
  color: var(--ink-faint);
  font-size: 1.05rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

/* Settings --------------------------------------------------------------- */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 18px;
  align-items: start;
}
.settings-card { padding: 24px; }
.settings-card h2 { font-family: var(--serif); font-size: 1.3rem; }

.switch { display: flex; align-items: center; gap: 10px; font-size: .93rem; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--mocha); }

/* Modal ------------------------------------------------------------------ */

.modal { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(46, 39, 35, .45); }

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2 { font-family: var(--serif); font-size: 1.4rem; padding-inline-end: 24px; }

.modal-x {
  position: absolute;
  top: 10px; inset-inline-end: 12px;
  border: none; background: none;
  font-size: 1.6rem; line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
}
.modal-x:hover { color: var(--ink); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

.empty { color: var(--ink-faint); font-size: .93rem; padding: 20px 0; text-align: center; }

.slot-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 7px; max-height: 190px; overflow-y: auto; padding: 2px; }
.slot-picker button {
  padding: 8px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--shell);
  cursor: pointer;
  font-size: .87rem;
  font-variant-numeric: tabular-nums;
}
.slot-picker button:hover { border-color: var(--mocha); }
.slot-picker button.is-selected { background: var(--mocha); color: #fff; border-color: var(--mocha); }

/* Touch sizing — see the note in base.css. */
@media (pointer: coarse) {
  .cal-nav { width: 44px; height: 44px; font-size: 1.3rem; }
  .icon-btn { width: 44px; height: 44px; font-size: 1.25rem; }
  .tab { min-height: 44px; }
  .admin-header-right .btn { min-height: 44px; }

  .badge { font-size: .8rem; padding: 2px 8px; }
  /* Overrides the 18px set for the desktop layout further up. */
  /* flex: none stops the checkbox being squeezed by its label. */
  .switch input { width: 22px; height: 22px; flex: none; }
  .modal-x { width: 44px; height: 44px; top: 6px; inset-inline-end: 6px; }
  /* A bare tel: link is only as tall as its text. */
  .booking-meta a { display: inline-block; padding: 9px 0; }
  .settings-card code { font-size: .9em; }
  .day-counts { font-size: .75rem; }
  .cal-weekdays { font-size: .8rem; }
  .admin-brand small { font-size: .8rem; }
  .ref { font-size: .82rem; }

  /* Stack each booking's buttons full-width rather than cramming a row. */
  .booking-actions { gap: 8px; }
  .table .row-actions { gap: 8px; }
}

/* On a phone the admin header is most of the screen — tighten it up. */
@media (max-width: 620px) {
  .admin-header { padding: 8px 14px; gap: 10px; }
  .tabs { width: 100%; order: 3; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; }
  .admin-main { padding: 18px 14px 48px; }
  .filters { width: 100%; }
  .filters input[type="search"] { width: 100%; }
  .section-head h2 { font-size: 1.3rem; }
  .booking-actions .btn { flex: 1 1 auto; }

  /* The counters are context, not the task. Keep them to two compact rows so
     the first appointment request is visible without scrolling. */
  .stat-row { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
  .stat { padding: 11px 13px; }
  .stat b { font-size: 1.35rem; }
  .stat span { font-size: .75rem; letter-spacing: .02em; }
}

@media (max-width: 430px) {
  .admin-calendar { padding: 12px; }
  .cal-weekdays, .cal-grid { gap: 3px; }
}

/* Layout helpers that used to be inline `style` attributes. They moved here so
   the Content-Security-Policy can refuse inline styles outright. */
.btn-full { width: 100%; }
.btn-spaced { margin-top: 18px; }
.section-head-spaced { margin-top: 36px; }
.settings-heading { margin-top: 22px; }

/* The accounts table sits in a narrow settings column, so its buttons wrap
   rather than pushing the table into a horizontal scroll. */
#users-table .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

#users-table .row-actions .btn { padding: 5px 10px; }

/* `btn-ghost` sets dark text and `btn-danger` a red ground, which together are
   barely legible. For a destructive action in a table row a quiet red on the
   card is both clearer and less shouty than a solid block. */
#users-table .btn-ghost.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

#users-table .btn-ghost.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}
#users-table th:last-child, #users-table td:last-child { text-align: right; }
