:root {
  --navy: #233d4d;
  --navy-2: #2f5064;
  --blue: #5fa8d3;
  --blue-soft: #e8f3fa;
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #1d2b34;
  --muted: #6b7c88;
  --line: #dde3e8;
  --ok: #1f8a4c;
  --ok-soft: #e6f5ec;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --bad: #c62f2f;
  --bad-soft: #fdecec;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 40, 55, .06), 0 2px 8px rgba(20, 40, 55, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--navy-2); }
h1 { font-size: 1.45rem; margin: 0; color: var(--navy); }
h2 { font-size: 1.05rem; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: .95rem; margin: 16px 0 8px; color: var(--navy); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 8px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--navy); font-weight: 700; }
.brand img { height: 34px; }
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav a { padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--navy); font-weight: 500; }
#nav a:hover { background: var(--bg); }
#nav a.active { background: var(--blue-soft); }
#nav a.nav-cta { background: var(--navy); color: #fff; }
#nav a.nav-cta.active, #nav a.nav-cta:hover { background: var(--navy-2); }
.who { display: flex; gap: 10px; align-items: center; font-size: .85rem; color: var(--muted); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---------- cards & layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card > h2:first-child { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.booking-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.sticky { position: sticky; top: 76px; }
@media (max-width: 960px) {
  .booking-layout { grid-template-columns: 1fr; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky { position: static; }
}
@media (max-width: 600px) {
  main { padding: 16px; }
  .topbar { padding: 8px 16px; gap: 10px; flex-wrap: wrap; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600; color: var(--navy); }
label.f .hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.req::after { content: " *"; color: var(--bad); }
input, select, textarea { font: inherit; font-size: .95rem; padding: 9px 11px; border: 1px solid #c5ced5; border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input[readonly] { background: var(--bg); }
.field-error input, .field-error select, .field-error textarea, .field-error .chips { border-color: var(--bad); background: var(--bad-soft); }
.err-msg { color: var(--bad); font-size: .8rem; font-weight: 500; }
label.f { position: relative; }
/* Overlays the label line so it never pushes the page down mid-click */
.fixed-note { position: absolute; left: 0; top: calc(100% + 1px); z-index: 2; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ok); background: var(--ok-soft); border-radius: 4px; padding: 1px 6px; font-size: .74rem; font-weight: 500; pointer-events: none; }
.money { position: relative; }
.money::before { content: "£"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 400; }
.money input { padding-left: 24px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px; border-radius: 6px; border: 1px solid transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid #c5ced5; border-radius: 999px; background: #fff; cursor: pointer; font-weight: 500; font-size: .88rem; color: var(--text); user-select: none; }
.chip input { display: none; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; cursor: pointer; }
.check input { width: auto; margin-top: 3px; }

/* ---------- buttons ---------- */
button, .btn { font: inherit; font-weight: 600; font-size: .92rem; border: 1px solid transparent; border-radius: 6px; padding: 9px 16px; cursor: pointer; background: var(--navy); color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--navy-2); }
button:disabled { opacity: .55; cursor: wait; }
.secondary { background: #fff; color: var(--navy); border-color: #c5ced5; }
.secondary:hover { background: var(--bg); }
.danger { background: #fff; color: var(--bad); border-color: #e5b4b4; }
.danger:hover { background: var(--bad-soft); }
button.link { background: none; color: var(--navy-2); padding: 0; border: none; font-weight: 500; text-decoration: underline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.big { padding: 13px 22px; font-size: 1rem; width: 100%; justify-content: center; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--blue-soft); color: var(--navy-2); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8fafb; }
tr.cancelled td { opacity: .5; text-decoration: line-through; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type=search] { flex: 1; min-width: 220px; }

/* ---------- customer search ---------- */
.search-box { position: relative; }
.results { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20, 40, 55, .14); max-height: 420px; overflow-y: auto; }
.result { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.result:hover, .result.focus { background: var(--blue-soft); }
.result .name { font-weight: 600; color: var(--navy); }
.result.new { color: var(--navy-2); font-weight: 600; }
.selected-customer { display: flex; justify-content: space-between; gap: 16px; padding: 14px 16px; border-radius: var(--radius); background: var(--blue-soft); border: 1px solid #c9e2f1; }
.selected-customer .name { font-size: 1.1rem; font-weight: 700; color: var(--navy); }

/* ---------- summary panel ---------- */
.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 1.15rem; font-weight: 700; color: var(--navy); padding-top: 8px; border-top: 1px solid var(--line); }
.margin-ok { color: var(--ok); }
.margin-bad { color: var(--bad); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: .92rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; white-space: pre-line; min-width: 0; overflow-wrap: anywhere; }

/* ---------- activity ---------- */
.events { list-style: none; padding: 0; margin: 0; font-size: .88rem; }
.events li { display: grid; grid-template-columns: 22px 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.events .ico { font-weight: 700; }
.events .ok .ico { color: var(--ok); }
.events .fail .ico { color: var(--bad); }
.events .skip .ico { color: var(--warn); }
.events .when { color: var(--muted); font-size: .78rem; }

/* ---------- alerts, modal, toast ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: .92rem; }
.alert.warn { background: var(--warn-soft); border: 1px solid #f1d29b; }
.alert.bad { background: var(--bad-soft); border: 1px solid #efb9b9; }
.alert.ok { background: var(--ok-soft); border: 1px solid #b5e0c5; }
.alert.info { background: var(--blue-soft); border: 1px solid #c9e2f1; }

.modal-bg { position: fixed; inset: 0; background: rgba(20, 35, 45, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; max-width: 680px; width: 100%; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal h2 { font-size: 1.2rem; }
.modal .btn-row { margin-top: 20px; justify-content: flex-end; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast .t { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); margin-top: 8px; font-weight: 500; }
#toast .t.bad { background: var(--bad); }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 10vh auto; text-align: center; }
.login img { height: 70px; margin-bottom: 16px; }
.login .card { text-align: left; }

/* iPhone/iPad: 16px inputs stop Safari zooming in on tap; respect the notch */
@media (max-width: 900px) {
  input, select, textarea { font-size: 16px; }
  .topbar { padding-top: max(8px, env(safe-area-inset-top)); }
  #nav a { padding: 8px 10px; }
  .brand span { display: none; }
  td, th { padding: 8px 6px; }
}
.code-input { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

#summary dl.facts dd { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- phones: compact header, tables become stacked cards ---------- */
@media (max-width: 600px) {
  .topbar { gap: 6px 12px; padding-bottom: 6px; }
  .brand img { height: 28px; }
  #nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #nav a { white-space: nowrap; padding: 7px 10px; font-size: .9rem; }
  .who { margin-left: auto; }
  .who-link > span:last-child { display: none; }
  .page-head h1 { font-size: 1.25rem; }
  .page-head .btn, .page-head button { padding: 8px 12px; }
  #csv { display: none; }
  .stack table, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack thead { display: none; }
  .stack tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .stack td { border: none; padding: 2px 0; text-align: left !important; }
  .filters input, .filters select { flex: 1 1 45%; min-width: 0; }
  .card { padding: 16px; }
}

/* ---------- staff ---------- */
.avatar { border-radius: 50%; object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; }
.avatar.initials { background: var(--blue-soft); color: var(--navy); font-weight: 700; }
.who-link { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--navy); font-weight: 500; }
.staff-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.staff-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.staff-card .n { font-weight: 700; color: var(--navy); }
.staff-card.off { opacity: .55; }
.photo-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }

/* ---------- photo cropper ---------- */
.crop-stage { position: relative; margin: 0 auto; border-radius: 8px; overflow: hidden; background: #e8edf1; touch-action: none; }
.crop-stage canvas { display: block; cursor: grab; touch-action: none; }
.crop-stage canvas:active { cursor: grabbing; }
.crop-ring { position: absolute; inset: 0; pointer-events: none; border-radius: 50%; box-shadow: 0 0 0 999px rgba(20, 35, 45, .55); outline: 2px solid #fff; outline-offset: -2px; }

/* ---------- signature box ---------- */
.sig-wrap { position: relative; border: 1px dashed #9fb0bc; border-radius: 8px; background: #fbfcfd; }
.sig-canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.sig-line { position: absolute; left: 16px; right: 16px; bottom: 34px; border-bottom: 1px solid #c5ced5; pointer-events: none; }
.sig-hint { position: absolute; left: 18px; bottom: 40px; color: #9fb0bc; font-size: .85rem; pointer-events: none; }
.sig-saved { max-height: 70px; max-width: 100%; display: block; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }

/* ---------- instructor registration ---------- */
.join-wrap { max-width: 640px; margin: 0 auto; }
.join-logo { height: 54px; display: block; margin: 8px auto 16px; }
.join-progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.join-progress div { height: 100%; background: var(--navy); transition: width .3s; }
.upload-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.upload-box .n { font-weight: 600; color: var(--navy); }
.agreement-box { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: #fbfcfd; font-size: .9rem; }
.agreement-box h4 { margin: 14px 0 6px; color: var(--navy); }
.agreement-box .ag-item { margin-left: 22px; }
.chips input[type=radio] { display: none; }
