:root {
  --ink: #14181f;
  --ink-2: #3c4552;
  --muted: #6b7482;
  --line: #e3e6ea;
  --bg: #f4f5f7;
  --card: #ffffff;
  --navy: #1d3b53;
  --navy-2: #2a5577;
  --pending: #e8a317;
  --pending-bg: #fff4d6;
  --pending-ink: #7a5200;
  --confirmed: #1f8a4c;
  --confirmed-bg: #e3f5ea;
  --confirmed-ink: #135c32;
  --declined: #9aa1ab;
  --declined-bg: #f0f1f3;
  --danger: #b42318;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
a { color: var(--navy-2); }

/* ---------- Buttons & inputs ---------- */
.btn {
  font: inherit; font-weight: 500; font-size: 14px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f7f8fa; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.success { background: var(--confirmed); border-color: var(--confirmed); color: #fff; }
.btn.danger { background: #fff; border-color: #f1c4bf; color: var(--danger); }
.btn.danger:hover { background: #fdf0ee; }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.link { border: 0; background: none; color: var(--navy-2); padding: 8px 0; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 14px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 15px; color: var(--ink);
  padding: 9px 11px; border: 1px solid #cfd4db; border-radius: 8px; background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0e0; outline-offset: 0; border-color: var(--navy-2); }
label.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; color: var(--ink); }
label.check input { width: auto; margin: 0; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; }
.auth-card .brand { margin-bottom: 22px; color: var(--navy); }
.auth-card .muted { margin: 0 0 18px; }
.code-input { font-size: 26px; letter-spacing: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.auth-msg { min-height: 1em; margin: 12px 0 0; font-size: 14px; color: var(--danger); }
.auth-msg.ok { color: var(--confirmed); }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-mark { font-size: 20px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  background: var(--navy); color: #fff; padding: 10px 20px;
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button {
  font: inherit; font-size: 14px; font-weight: 500; color: #c9d6e2; background: none; border: 0;
  padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: #fff; background: rgba(255,255,255,.08); }
.tabs button.active { color: #fff; background: rgba(255,255,255,.16); }
.badge { display: inline-block; min-width: 20px; padding: 1px 6px; margin-left: 4px; border-radius: 10px; background: var(--pending); color: #2b1d00; font-size: 12px; font-weight: 700; text-align: center; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar .btn.primary { background: #fff; color: var(--navy); border-color: #fff; }
.topbar .btn.primary:hover { background: #e9eef3; }
.user-menu { position: relative; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 0; background: #3c6a90; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.menu { position: absolute; right: 0; top: 44px; min-width: 230px; background: #fff; color: var(--ink); border-radius: 10px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 6px; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: grid; gap: 2px; font-size: 14px; }
.menu-head .muted { font-size: 12px; word-break: break-all; }
.menu button { display: block; width: 100%; text-align: left; font: inherit; font-size: 14px; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--bg); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.tab-panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }

/* ---------- Calendar ---------- */
.cal-toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.lg-pending::before { background: var(--pending-bg); border: 2px solid var(--pending); }
.lg-confirmed::before { background: var(--confirmed); border: 2px solid var(--confirmed); }
.lg-pencil::before { background: #fff; border: 2px dashed var(--ink-2); }
.lg-declined::before { background: var(--declined-bg); border: 2px solid var(--declined); }
.filters { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.filters select { width: auto; margin: 0; padding: 6px 10px; font-size: 14px; }

#calendar { --fc-border-color: var(--line); --fc-today-bg-color: #eef4fa; --fc-button-bg-color: #fff; --fc-button-text-color: var(--ink); --fc-button-border-color: var(--line); --fc-button-hover-bg-color: #f3f5f7; --fc-button-hover-border-color: var(--line); --fc-button-active-bg-color: var(--navy); --fc-button-active-border-color: var(--navy); }
#calendar .fc-toolbar-title { font-size: 19px; }
#calendar .fc-button { font-size: 13px; font-weight: 500; box-shadow: none !important; }
#calendar .fc-button-active { color: #fff; }
#calendar .fc-daygrid-day { cursor: pointer; }
.fc-event.bk { border-width: 2px; border-radius: 5px; padding: 1px 3px; font-size: 12.5px; cursor: pointer; }
.fc-event.bk .fc-event-main { color: inherit; }
.bk-PENDING   { background: var(--pending-bg) !important; border-color: var(--pending) !important; color: var(--pending-ink) !important; }
.bk-CONFIRMED { background: var(--confirmed) !important; border-color: var(--confirmed) !important; color: #fff !important; }
.bk-DECLINED  { background: var(--declined-bg) !important; border-color: var(--declined) !important; color: #6b7280 !important; text-decoration: line-through; }
.bk-PENCIL    { border-style: dashed !important; }
.bk-CONFIRMED.bk-PENCIL { background: #4aa874 !important; border-color: #0f5a30 !important; }
.ev-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-tag { font-weight: 700; margin-right: 3px; }
.fc-list-event.bk td { background: transparent; }

/* ---------- Lists ---------- */
.list { display: grid; gap: 10px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; align-items: center; border: 1px solid var(--line); border-left-width: 5px; border-radius: 8px; padding: 12px 14px; cursor: pointer; background: #fff; }
.item:hover { background: #fafbfc; }
.item.st-PENDING { border-left-color: var(--pending); }
.item.st-CONFIRMED { border-left-color: var(--confirmed); }
.item.st-DECLINED, .item.st-WITHDRAWN { border-left-color: var(--declined); opacity: .8; }
.item-title { font-weight: 600; }
.item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item-desc { font-size: 14px; color: var(--ink-2); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-actions { display: flex; gap: 6px; }
.empty { padding: 30px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pill.PENDING { background: var(--pending-bg); color: var(--pending-ink); }
.pill.CONFIRMED { background: var(--confirmed-bg); color: var(--confirmed-ink); }
.pill.DECLINED, .pill.WITHDRAWN, .pill.INACTIVE { background: var(--declined-bg); color: #555c66; }
.pill.ACTIVE { background: var(--confirmed-bg); color: var(--confirmed-ink); }
.pill.PENCIL { background: #fff; border: 1px dashed var(--ink-2); color: var(--ink-2); }
.pill.HARD { background: #e8eef4; color: var(--navy); }
.pill.ADMIN { background: #e8eef4; color: var(--navy); }

/* ---------- Tables ---------- */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.inline-form input { flex: 1 1 180px; width: auto; margin: 0; }
.table-wrap { overflow-x: auto; margin-top: 14px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td input { margin: 0; padding: 6px 8px; font-size: 14px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn { margin-left: 6px; }
#calendar .fc-list-event-time, #calendar .fc-list-event-graphic { display: none; }

/* ---------- Modals ---------- */
.modal { border: 0; padding: 0; border-radius: 14px; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.small { width: min(420px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15,23,34,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.modal-head h2 { margin: 0; }
.x { font-size: 26px; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 16px 22px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 20px; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subfields { background: #f6f8fa; border-radius: 8px; padding: 12px 12px 0; margin: -6px 0 14px; }
fieldset.seg { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.seg legend { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
fieldset.seg label { display: inline-block; margin: 0 6px 0 0; }
fieldset.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
fieldset.seg span { display: inline-block; padding: 8px 14px; border: 1px solid #cfd4db; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; background: #fff; }
fieldset.seg input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; }
fieldset.seg input:focus-visible + span { outline: 2px solid #9cc0e0; }
.notice { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.notice.warn { background: var(--pending-bg); color: var(--pending-ink); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0; }

.detail { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; margin: 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.notes-box { margin-top: 14px; padding: 10px 12px; background: #f3f6f9; border-left: 4px solid var(--navy-2); border-radius: 4px; font-size: 14px; white-space: pre-wrap; }
.notes-box .muted { display: block; font-size: 12px; margin-bottom: 2px; }
.admin-box { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .topbar .brand-name { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
  main { padding: 12px; }
  .tab-panel { padding: 14px; }
  #calendar .fc-toolbar { flex-wrap: wrap; gap: 8px; }
  #calendar .fc-toolbar-title { font-size: 16px; }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .detail { grid-template-columns: 1fr; gap: 2px; }
  .detail dd { margin-bottom: 8px; }
  .item { grid-template-columns: 1fr; }
}

/* =========================================================
   Mobile & touch refinements
   ========================================================= */
html { -webkit-text-size-adjust: 100%; background: var(--navy); }
body { padding-bottom: env(safe-area-inset-bottom); min-height: 100vh; min-height: 100dvh; }


/* Modals: header and buttons stay put; the middle scrolls */
.modal[open] > form, .modal[open] > div { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal .modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-head, .modal-foot { flex-shrink: 0; }
#dlg-detail .modal-body + .modal-body { overflow: visible; }

@media (max-width: 760px) {
  /* 16px stops iPhone Safari zooming in when a field is tapped */
  input, select, textarea, .code-input { font-size: 16px; }
  .code-input { font-size: 26px; }

  /* Bigger touch targets */
  .btn { padding: 11px 16px; font-size: 15px; }
  .btn.sm { padding: 8px 12px; font-size: 14px; }
  fieldset.seg span { padding: 11px 16px; font-size: 15px; }
  fieldset.seg label { margin-bottom: 6px; }
  .tabs button { padding: 10px 12px; }
  label.check { padding: 6px 0; font-size: 15px; }
  label.check input { width: 20px; height: 20px; }
  .menu button { padding: 12px 10px; font-size: 15px; }

  .tabs { scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }

  /* Modals become full-screen sheets */
  .modal, .modal.small { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .modal[open] > form, .modal[open] > div { height: 100dvh; max-height: 100dvh; }
  .modal-head { padding: 14px 16px 12px; border-bottom: 1px solid var(--line); }
  .modal-body { padding: 14px 16px 4px; flex: 1; }
  #dlg-detail .modal-body + .modal-body { flex: 0 0 auto; }
  .modal-foot { padding: 12px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fff; }
  .modal-foot .btn { flex: 1 1 auto; }
  .modal-foot .spacer { display: none; }
  .x { font-size: 30px; padding: 4px 8px; }

  /* Filters stack neatly */
  .cal-toolbar { gap: 10px; }
  .filters { width: 100%; }
  .filters select { flex: 1 1 100%; }

  /* List items: actions on their own row */
  .item-actions { flex-wrap: wrap; }
  #review-list .item-actions .btn { flex: 1 1 40%; }

  /* Admin tables become cards */
  .inline-form input, .inline-form .btn { flex: 1 1 100%; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px; }
  .table td { border: 0; padding: 6px 0; display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; }
  .table td::before { content: attr(data-label); font-size: 12px; color: var(--muted); }
  .table td:not([data-label]) { display: block; }
  .table td.actions { text-align: left; white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
  .table td.actions .btn { margin: 0; flex: 1 1 auto; }

  /* Calendar month view on a phone */
  #calendar .fc-daygrid-event { font-size: 11px; }
  #calendar .fc-col-header-cell-cushion { font-size: 12px; }
  #calendar .fc-list-day-cushion { padding: 8px 10px; }
  #calendar .fc-list-event td { padding: 10px; }
  .toast { bottom: max(20px, env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  .filters select, .table td input { font-size: 16px; }
  .table td .pill { justify-self: start; }
}
#calendar .fc-daygrid-day-number { text-decoration: none; color: var(--ink-2); }

/* ---------- Logo ---------- */
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { display: block; width: 170px; max-width: 60%; height: auto; margin: 0 auto 10px; }
.auth-app { font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--navy-2); }
.brand-logo { height: 30px; width: auto; display: block; }
@media (max-width: 760px) { .brand-logo { height: 28px; } }

/* ---------- Busy buttons ---------- */
.btn.is-busy { cursor: progress; opacity: .9; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:disabled.is-busy { opacity: .9; }
.spinner { width: 16px; height: 16px; flex: 0 0 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

/* ---------- Admin fields on the booking form ---------- */
.admin-box-form { background: #eef3f8; border: 1px solid #d6e2ee; border-radius: 8px; padding: 12px 12px 4px; margin-bottom: 14px; }
.admin-box-form label { margin-bottom: 8px; }
.admin-box-form .muted.small { margin: 0 0 8px; }

/* ---------- Booking type help ---------- */
fieldset.seg .help-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; margin-left: 2px; vertical-align: middle; border-radius: 50%; border: 1px solid #b8c3cf; background: #fff; color: var(--navy-2); font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
fieldset.seg .help-btn:hover, fieldset.seg .help-btn[aria-expanded="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.help-pop { margin-top: 10px; padding: 10px 12px; background: #eef3f8; border: 1px solid #d6e2ee; border-radius: 8px; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.help-pop p { margin: 0 0 8px; }
.help-pop p:last-child { margin: 0; }
@media (max-width: 760px) { fieldset.seg .help-btn { width: 34px; height: 34px; font-size: 17px; } }
