* { box-sizing: border-box; }
:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1f2328; --muted: #6a737d; --line: #dfe3e8;
  --accent: #1c7ed6; --accent-soft: #e7f1fc; --warn: #e8590c; --ok: #2f9e44; --bad: #c92a2a;
}
body { margin: 0; font: 14px/1.45 system-ui, "Noto Sans", sans-serif; color: var(--ink); background: var(--bg); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 11px; }
button:hover { border-color: #b8c0c8; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:disabled { background: #a5c8ea; border-color: #a5c8ea; cursor: default; }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { cursor: default; opacity: .6; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 17px; } h3 { font-size: 14px; }

#top { display: flex; align-items: center; gap: 14px; padding: 8px 18px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
#top .brand { font-weight: 700; }
#top nav { display: flex; gap: 2px; margin-left: 8px; }
#top nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; }
#top nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#top .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 99px; background: #f1f3f5; font-size: 12px; white-space: nowrap; }
.pill.ok::before, .pill.bad::before, .pill.warn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.pill.ok::before { background: var(--ok); } .pill.bad::before { background: var(--bad); } .pill.warn::before { background: var(--warn); }
.pill.round { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding: 16px 18px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* login */
.login { max-width: 360px; margin: 60px auto; display: grid; gap: 10px; }
.login input { padding: 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }

/* home */
.home { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 16px; }
.round-card { display: flex; flex-direction: column; min-height: 0; }
.round-card h2 { font-size: 22px; }
.home-side { display: flex; flex-direction: column; gap: 16px; min-height: 0; overflow: auto; }
.progress { height: 10px; background: #e9ecef; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--accent); }
.big-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.big-actions button { padding: 8px 16px; font-size: 15px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.home .photo { flex: 1; min-height: 120px; display: flex; justify-content: center; align-items: flex-start; margin-top: 4px; }
.home .photo canvas { border-radius: 6px; display: block; }

/* setup */
.setup { display: flex; min-height: 360px; }
.stage-col { flex: 1; min-width: 300px; display: flex; flex-direction: column; }
.stage-fit { flex: 1; min-height: 0; display: flex; align-items: flex-start; justify-content: center; }
.split { flex: none; width: 14px; cursor: col-resize; position: relative; }
.split::after { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 4px; border-radius: 4px; background: var(--line); }
.split:hover::after { background: var(--accent); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.live { font-variant-numeric: tabular-nums; }
.live.on::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #e03131; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.stage { position: relative; background: #222; border-radius: 8px; overflow: hidden; user-select: none; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage.drawing svg { cursor: crosshair; }
.stage .hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: rgba(0,0,0,.75); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: 13px; pointer-events: none; }
svg .box { fill: transparent; stroke-width: 2; cursor: move; vector-effect: non-scaling-stroke; }
svg .box.sel { stroke-width: 3.5; fill: rgba(255,255,255,.18); }
svg .box.new { stroke-dasharray: 6 3; }
svg .box.hl { fill: rgba(255,230,0,.35); }
svg .lbl { font: 600 13px system-ui, sans-serif; paint-order: stroke; stroke: rgba(255,255,255,.9); stroke-width: 3px; pointer-events: none; }
svg .handle { fill: #fff; stroke: #000; stroke-width: 1.5; cursor: nwse-resize; vector-effect: non-scaling-stroke; }
svg .marquee { fill: rgba(28,126,214,.12); stroke: var(--accent); stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.help { margin: 8px 2px 0; }
kbd { border: 1px solid #ccd; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 11px; background: #fafafa; }

.panel { flex: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; height: 100%; min-height: 0; }
.panel .head { padding: 12px 14px 8px; border-bottom: 1px solid var(--line); }
.panel .body { overflow: auto; padding: 6px 14px 10px; flex: 1; min-height: 0; }
.panel .foot { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.tier-h { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cup-row { display: flex; align-items: center; gap: 5px; padding: 3px 0; }
.cup-code { width: 74px; text-align: left; padding: 3px 6px; font-weight: 600; border: 1px solid transparent; background: none; }
.cup-code span { font-weight: 400; font-size: 11px; color: var(--muted); }
.cup-code.sel { background: var(--accent-soft); border-color: #a5c8ea; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); background: #fff; }
.chip i { width: 8px; height: 8px; border-radius: 50%; }
.chip.missing { border-style: dashed; color: var(--muted); background: transparent; }
.chip.sel { outline: 2px solid var(--accent); }
.chip.dup { border-color: var(--warn); color: var(--warn); }
.chip.new-box { border-style: dashed; }
.msg { margin: 8px 0; padding: 8px 10px; border-radius: 6px; background: #edf7ed; color: #1e5b2a; font-size: 13px; }
.msg.warn { background: #fff4e6; color: #8a3c00; }

/* context menu */
.ctx { position: fixed; z-index: 50; background: #fff; border: 1px solid #cfd5db; border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 10px; width: 270px; font-size: 13px; }
.ctx h4 { margin: 0 0 8px; font-size: 14px; }
.ctx .lab { font-size: 11px; color: var(--muted); text-transform: uppercase; margin: 8px 0 4px; letter-spacing: .04em; }
.ctx .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.ctx .grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ctx .grid3 button, .ctx .grid4 button { padding: 4px 0; font-size: 12px; }
.ctx button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.ctx button.has { border-color: #adb5bd; background: #f1f3f5; }
.ctx .acts { display: grid; gap: 2px; margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.ctx .acts button { border: 0; text-align: left; padding: 5px 6px; }
.ctx .acts button:hover { background: #f1f3f5; }
.ctx label { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.ctx .note { color: var(--warn); font-size: 11px; margin-top: 3px; }

/* results */
.res-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs { display: inline-flex; gap: 4px; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.res-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
/* separate borders: collapsed borders are lost on sticky cells */
table.bm { border-collapse: separate; border-spacing: 0; background: #fff; font-size: 12px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
table.bm th, table.bm td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 5px; text-align: center; }
/* the whole header block sticks just under the top bar (its height is measured in app.js) */
table.bm thead { position: sticky; top: var(--top-h, 0px); z-index: 2; }
table.bm thead th { background: #f8f9fa; }
table.bm td.h { font-weight: 600; width: 38px; }
table.bm td.cell { cursor: zoom-in; position: relative; padding: 2px; }
table.bm td.cell:hover { background: var(--accent-soft); }
table.bm td.cell canvas { display: block; }
table.bm td.future { color: #ced4da; background: #fbfbfc; }
table.bm td.hint { box-shadow: inset 3px 0 0 var(--warn); }
table.bm td.hint .dot { position: absolute; right: 2px; top: 1px; font-size: 10px; color: var(--warn); font-weight: 700; }
table.bm tr.now td.h { color: var(--accent); }
table.bm .ev { position: absolute; left: 2px; top: 0; font-size: 10px; color: var(--accent); }
.side { position: sticky; top: 64px; display: grid; gap: 12px; }
table.hints { border-collapse: collapse; width: 100%; font-size: 13px; }
table.hints td, table.hints th { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }

/* lightbox */
.lb { position: fixed; inset: 0; background: rgba(15,18,22,.82); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lb .box { background: #fff; border-radius: 12px; padding: 16px; max-width: 96vw; max-height: 94vh; overflow: auto; }
.lb .pair { display: flex; gap: 14px; align-items: flex-start; margin-top: 10px; }
.lb figure { margin: 0; }
.lb figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.lb canvas { border-radius: 6px; display: block; }

/* events */
.events { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
.ev-list { background: #fff; border: 1px solid var(--line); border-radius: 10px; max-height: calc(100vh - 130px); overflow: auto; position: sticky; top: 64px; }
.ev-filter { padding: 10px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px; }
.ev-filter button { padding: 2px 8px; font-size: 12px; }
.ev-filter button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.ev-item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev-item:hover { background: #f8f9fa; }
.ev-item.on { background: var(--accent-soft); }
.ev-item .t { font-weight: 600; }
.ev-item .chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.ev-item.all .t::after { content: " ⚠"; color: var(--warn); }
.ev-view .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.ev-view canvas { width: 100%; border-radius: 6px; display: block; }
.ev-view figure { margin: 0; }
.ev-view figcaption { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* download */
.dl { max-width: 760px; display: grid; gap: 10px; }
.dl .card { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* admin */
.admin { display: grid; gap: 16px; max-width: 1300px; }
table.list { border-collapse: collapse; width: 100%; background: #fff; }
table.list th, table.list td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.list th { background: #f8f9fa; font-weight: 600; }
.upd { font-size: 12px; }
.bar-sm { display: inline-block; width: 70px; height: 6px; background: #e9ecef; border-radius: 99px; vertical-align: middle; margin-left: 6px; overflow: hidden; }
.bar-sm i { display: block; height: 100%; background: var(--accent); }

dialog { border: 0; border-radius: 12px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); max-width: 480px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog ul { padding-left: 18px; }
dialog input { padding: 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #212529; color: #fff; padding: 8px 16px; border-radius: 8px; z-index: 90; }

/* event photos: a coloured label on the picture says which one it is */
.ev-view .pair { grid-template-columns: 1fr 1fr; }
.shot { position: relative; margin: 0; border: 3px solid transparent; border-radius: 8px; overflow: hidden; }
.shot.before { border-color: #1c7ed6; } .shot.after { border-color: #e8590c; }
.shot canvas { display: block; width: 100%; height: auto; }
.badge { position: absolute; left: 0; top: 0; padding: 4px 10px; font-weight: 700; font-size: 15px; color: #fff; border-bottom-right-radius: 8px; }
.badge span { font-weight: 400; font-size: 13px; }
.badge.before { background: #1c7ed6; } .badge.after { background: #e8590c; }
.blink-wrap { display: flex; justify-content: center; margin-top: 10px; }
.shot.blink canvas { width: auto; max-width: 100%; max-height: calc(100vh - 380px); }
.shot.blink .badge { font-size: 22px; padding: 6px 14px; }
.shot.blink .badge span { font-size: 16px; }
.film { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 2px; }
.film .frame { flex: none; padding: 3px; border: 2px solid var(--line); border-radius: 6px; background: #fff; }
.film .frame canvas { display: block; width: 128px; height: 96px; border-radius: 3px; }
.film .frame.before { border-color: #1c7ed6; } .film .frame.after { border-color: #e8590c; }
.film .frame.event { background: #fff9db; }
.film .cap { font-size: 11px; margin-top: 2px; display: flex; gap: 4px; justify-content: center; align-items: center; }
.film .tag { color: #fff; border-radius: 3px; padding: 0 4px; font-size: 10px; }
.film .tag.before { background: #1c7ed6; } .film .tag.after { background: #e8590c; }

/* warnings on the device page */
.warns { margin-top: 8px; padding: 8px 12px; border-radius: 6px; background: #fff4e6; color: #8a3c00; font-size: 13px; }
.warns ul { margin: 4px 0 0; padding-left: 18px; }
.warns li { margin: 3px 0; }
.warns li.dev { color: var(--bad); }

/* real site only */
#top select { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; }
.login .err { color: var(--bad); font-size: 13px; min-height: 1em; }
.stage img { display: block; width: 100%; height: 100%; object-fit: fill; }
.stage .empty { color: #ccc; padding: 40px; text-align: center; }
.home .photo img { border-radius: 6px; display: block; max-width: 100%; }
.admin input, .admin select { font: inherit; padding: 5px; border: 1px solid var(--line); border-radius: 6px; }
.password { font: 600 16px ui-monospace, monospace; background: #fff9db; padding: 6px 10px; border-radius: 6px; user-select: all; }
.ev-view img, .shot img { display: block; width: 100%; height: auto; }
.film .frame img { display: block; width: 128px; height: 96px; object-fit: cover; border-radius: 3px; }
.lb img { border-radius: 6px; display: block; }
.empty-card { max-width: 640px; }
