:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1c1a;
  --muted: #6d6a64;
  --line: #d9d6cf;
  --accent: #1f5fd1;
  --accent-ink: #ffffff;
  --sold: #c8413b;
  --sold-soft: #f7dcda;
  --reserved: #d99a1c;
  --reserved-soft: #fbecc9;
  --blocked: #8d8a84;
  --free: #ffffff;
  --free-line: #9bb89a;
  --ok: #2f8a4c;
  --danger: #b3322d;
  --stage: #2b2a27;
  --radius: 10px;
  --seat: clamp(15px, calc((100vw - 40px) / 25), 30px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1f1f1d;
    --surface-2: #2a2927;
    --text: #ecebe7;
    --muted: #a09d96;
    --line: #3b3a37;
    --accent: #5b8ff0;
    --sold: #d9544e;
    --sold-soft: #4a2523;
    --reserved: #e3a832;
    --reserved-soft: #4a3a17;
    --blocked: #6b6964;
    --free: #262624;
    --free-line: #5f8a5e;
    --stage: #3a3936;
    color-scheme: dark;
  }
}
body.zoom { --seat: 32px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
}
body.busy { cursor: progress; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
  min-height: 38px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.sold-btn { background: var(--sold); border-color: var(--sold); color: #fff; }
.btn.reserved-btn { background: var(--reserved); border-color: var(--reserved); color: #1d1c1a; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.linkbtn { background: none; border: 0; padding: 4px; cursor: pointer; color: var(--text); text-decoration: underline dotted; }
.icon { background: none; border: 0; font-size: 18px; cursor: pointer; padding: 4px 8px; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
label { display: block; margin: 10px 0; font-size: 13.5px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 15px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input { width: auto; margin: 0; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; }
.login-brand { text-align: center; margin-bottom: 10px; }
.login-brand h1 { font-size: 20px; margin: 14px 0 2px; }
.login-brand p { margin: 0; }
.login-stage { background: var(--stage); color: #fff; letter-spacing: .3em; font-size: 11px; padding: 6px; border-radius: 6px 6px 40% 40% / 6px 6px 14px 14px; }
.alert { background: var(--sold-soft); color: var(--text); border-left: 3px solid var(--sold); padding: 8px 12px; border-radius: 6px; margin: 12px 0; }
.setup-note { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 320px; min-width: 0; }
.brand strong { white-space: nowrap; font-size: 15px; }
.brand select { max-width: 340px; padding: 6px 10px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.tab { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.me { display: flex; align-items: center; gap: 6px; }
.live { color: var(--ok); font-size: 12px; }
.live.off { color: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

main { padding: 12px 16px 24px; max-width: 1180px; margin: 0 auto; }
body.has-panel main { padding-bottom: 260px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.toolbar input[type=search] { width: 230px; padding: 6px 10px; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }
.stat b { font-variant-numeric: tabular-nums; font-size: 16px; }
.stat.sold b { color: var(--sold); }
.stat.reserved b { color: var(--reserved); }
.stat.blocked b { color: var(--blocked); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; margin-bottom: 10px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .seat { width: 16px; height: 16px; font-size: 0; pointer-events: none; }
.legend .hint { margin-left: auto; }

/* ---------- seat map ---------- */
.mapwrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px 18px; -webkit-overflow-scrolling: touch; }
.map { width: max-content; margin: 0 auto; }
.stage {
  background: var(--stage); color: #fff; text-align: center; letter-spacing: .35em;
  font-size: 12px; padding: 8px; margin: 0 calc(var(--seat) * 1.2) 16px;
  border-radius: 6px 6px 50% 50% / 6px 6px 18px 18px;
}
.grid {
  display: grid;
  grid-template-columns: calc(var(--seat) * 1.1) repeat(var(--cols), var(--seat)) calc(var(--seat) * 1.1);
  grid-auto-rows: var(--seat);
  gap: max(2px, calc(var(--seat) * .12));
}
.seat {
  width: 100%; height: 100%; padding: 0; margin: 0;
  display: grid; place-items: center;
  font-size: calc(var(--seat) * .42); font-weight: 600; font-variant-numeric: tabular-nums;
  border-radius: 28% 28% 18% 18%;
  border: 1.5px solid var(--free-line); background: var(--free); color: var(--muted);
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform .08s;
}
.seat:hover { transform: scale(1.12); }
.seat.sold { background: var(--sold); border-color: var(--sold); color: #fff; }
.seat.reserved { background: var(--reserved); border-color: var(--reserved); color: #1d1c1a; }
.seat.blocked {
  background: repeating-linear-gradient(45deg, var(--blocked) 0 3px, transparent 3px 6px);
  border-color: var(--blocked); color: var(--text);
}
.seat.hl { outline: 2px dashed var(--text); outline-offset: 1px; }
.seat.hit { box-shadow: 0 0 0 3px #19c37d; }
.seat.sel { outline: 3px solid var(--accent); outline-offset: 1px; z-index: 1; position: relative; }
.seat.free.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.noseat { background: repeating-linear-gradient(-45deg, var(--line) 0 1px, transparent 1px 5px); border-radius: 3px; opacity: .8; }
.rowlbl {
  border: 0; background: none; padding: 0; cursor: pointer;
  font-weight: 700; font-size: max(10px, calc(var(--seat) * .5)); color: var(--muted);
}
.rowlbl:hover { color: var(--accent); }
.ruler { font-size: max(9px, calc(var(--seat) * .36)); color: var(--muted); text-align: center; align-self: center; font-variant-numeric: tabular-nums; }
.aisle {
  display: flex; justify-content: space-between; align-items: center;
  font-size: max(10px, calc(var(--seat) * .38)); color: var(--muted); text-transform: uppercase; letter-spacing: .12em;
  border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); padding: 0 4px;
}
.empty { padding: 40px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- selection panel ---------- */
.panel {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 30;
  width: min(640px, calc(100vw - 16px)); max-height: 55vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .18); padding: 12px 14px 14px;
}
.p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.p-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.bcard { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 8px; display: grid; gap: 3px; }
.bcard-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.notes { white-space: pre-wrap; font-style: italic; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); text-transform: capitalize; font-weight: 600; }
.badge.sold { background: var(--sold-soft); color: var(--sold); }
.badge.reserved { background: var(--reserved-soft); color: color-mix(in srgb, var(--reserved) 70%, var(--text)); }

/* ---------- tables / cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 { font-size: 17px; margin: 0; }
.card p { margin: 6px 0 10px; font-size: 13.5px; }
.tablewrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
#view-bookings .tablewrap { border: 1px solid var(--line); border-radius: var(--radius); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
table.list tfoot td { font-weight: 600; border-bottom: 0; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .actions { text-align: right; white-space: nowrap; }
#bkTable tbody tr { cursor: pointer; }
#bkTable tbody tr:hover { background: var(--surface-2); }
.notes-cell { max-width: 260px; white-space: pre-wrap; }
tr.inactive td { opacity: .55; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; width: min(440px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgb(0 0 0 / .3);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog p { margin: 0 0 6px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.seg { border: 0; padding: 0; margin: 12px 0 0; display: flex; gap: 8px; }
.seg label { flex: 1; margin: 0; display: flex; align-items: center; gap: 8px; justify-content: center; padding: 9px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--text); }
.seg input { width: auto; margin: 0; }
.seg label:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dot.sold { background: var(--sold); }
.dot.reserved { background: var(--reserved); }

/* ---------- toast ---------- */
#toast {
  position: fixed; top: 64px; left: 50%; transform: translate(-50%, -20px); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: min(520px, calc(100vw - 24px)); opacity: 0; pointer-events: none; transition: .2s;
  white-space: pre-line; font-size: 14px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
#toast.ok { background: var(--ok); color: #fff; }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  :root { --seat: calc((100vw - 74px) / 24.2); }
  body:not(.zoom) .seat { font-size: 0; }
  body:not(.zoom) .seat.sel, body:not(.zoom) .seat.hl { outline-width: 2px; }
  body:not(.zoom) .grid { gap: 2px; }
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand { flex: 1 1 0; }
  .brand strong { display: none; }
  .brand select { max-width: none; flex: 1; min-width: 0; }
  .tabs { order: 3; flex-basis: 100%; }
  .tab { flex: 1; padding: 6px 8px; }
  main { padding: 10px 8px 20px; }
  .stats { font-size: 13px; gap: 4px 10px; }
  .toolbar input[type=search] { width: 100%; }
  .toolbar-right { flex: 1; }
  .legend { font-size: 12px; gap: 4px 10px; }
  .legend .hint { display: none; }
  .mapwrap { padding: 10px 4px 12px; }
  .stage { margin-bottom: 10px; padding: 5px; font-size: 10px; }
  .panel { bottom: 0; border-radius: 14px 14px 0 0; width: 100vw; }
  .me .linkbtn { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .toolbar-right, .panel, #toast, .legend .hint, .tabs { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .mapwrap, .card, #view-bookings .tablewrap { border: 0; }
  #bkTable tbody tr { break-inside: avoid; }
}
