:root {
  --bg: #f5f5f3; --surface: #ffffff; --surface-2: #f0efec; --text: #1a1a1d; --muted: #6c6c75; --line: #e3e2de;
  --accent: #e63956; --accent-soft: #fde8ec; --ok: #2f9e44; --warn: #e8590c; --danger: #c92a2a; --shadow: 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111114; --surface: #1a1a1f; --surface-2: #232329; --text: #efeff2; --muted: #9d9da8; --line: #2d2d35;
    --accent: #ff4d6d; --accent-soft: #3a1c24; --ok: #51cf66; --warn: #ff922b; --danger: #ff6b6b; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 26px; margin: 0 0 18px; } h2 { font-size: 17px; margin: 0; }
button { font: inherit; cursor: pointer; color: inherit; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 18px; }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 600; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; font-size: 13px; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 4px 8px; }

.logo-mark { font-size: 20px; letter-spacing: -2px; color: var(--accent); }
.logo-mark.sm { font-size: 14px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 22px; }
.err { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 14px; }

/* layout */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 10px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 8px; }
.brand { font-weight: 800; display: flex; gap: 8px; align-items: center; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-label { display: flex; justify-content: space-between; align-items: center; margin: 14px 10px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.side-foot { margin-top: auto; }
.main { padding: 26px 28px 110px; min-width: 0; }
.topbar { display: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat .v { font-size: 28px; font-weight: 800; } .stat .l { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.status { display: inline-flex; align-items: center; gap: 6px; }
.warn { color: var(--warn); }

/* booth page */
.booth-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.booth-head h1 { margin: 0; }
.sub { color: var(--muted); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.pair { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.code { font: 800 30px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .18em; margin-top: 4px; }
.pair-help { flex: 1; min-width: 220px; font-size: 14px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { left: 21px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 16px; }
.tabs button { background: none; border: 0; padding: 10px 14px; border-bottom: 2px solid transparent; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.pill { background: var(--surface-2); border-radius: 999px; padding: 1px 8px; font-size: 12px; }

.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.set-form { display: flex; flex-direction: column; gap: 14px; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 16px; margin: 0; background: var(--surface); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
legend { font-weight: 700; padding: 0 6px; }
fieldset .full { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-size: 14px; }
label.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.range-row { display: flex; gap: 10px; align-items: center; } .range-row input { padding: 0; accent-color: var(--accent); } .range-row output { min-width: 38px; color: var(--text); font-variant-numeric: tabular-nums; }
.logo-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.logo-row img { max-height: 54px; max-width: 150px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }

.preview-col { position: sticky; top: 16px; }
.pv-box { background: var(--surface-2); border-radius: 10px; padding: 12px; display: flex; justify-content: center; overflow: auto; max-height: 70vh; }
.pv-box img { max-width: 100%; height: auto; display: block; box-shadow: 0 4px 16px rgba(0,0,0,.18); background: #fff; }
.pv-box.vertical img { max-height: 64vh; width: auto; }
.pv-box.thermal img { image-rendering: pixelated; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.savebar { position: fixed; left: 250px; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 28px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; z-index: 5; }
.savebar.dirty #saveState { color: var(--warn); font-weight: 600; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

.sess-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.sess { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.sess .th { background: #222; aspect-ratio: 4 / 3; padding: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sess .th img { width: 100%; height: 100%; object-fit: contain; }
.sess .meta { padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.sess .meta a { color: var(--accent); text-decoration: none; font-weight: 600; }
.sess .del { background: none; border: 0; color: var(--muted); font-size: 13px; }
.sess .del:hover { color: var(--danger); }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 16px; align-items: center; }
.empty { color: var(--muted); padding: 24px; text-align: center; grid-column: 1 / -1; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--surface); border-radius: 16px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-card h2 { font-size: 20px; }
.modal-card p { margin: 0; }
.modal fieldset { display: flex; flex-direction: column; gap: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.targets { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translate(-50%, 30px); opacity: 0; background: #222; color: #fff; padding: 10px 18px; border-radius: 10px; transition: .25s; z-index: 50; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

.only-mobile { display: none; }
@media (max-width: 1100px) { .settings-layout { grid-template-columns: 1fr; } .preview-col { position: static; order: -1; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { transform: none; }
  .only-mobile { display: initial; }
  .topbar { display: flex; align-items: center; gap: 10px; margin: -10px 0 12px; }
  .main { padding: 18px 16px 150px; }
  .savebar { left: 0; padding: 10px 16px; }
  fieldset { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
}
