:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0da;
  --accent: #2b59c3;
  --accent-ink: #ffffff;
  --sel: #ff7a00;
  --error: #b3261e;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --panel: #1e1e22; --ink: #ececef; --muted: #9a9aa2;
    --line: #2f2f35; --accent: #6f95ff; --accent-ink: #0b0b0c; --error: #ff8a80;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary, form.login-card button { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type=text], input[type=search], input[type=password], input[type=number], select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; width: 100%;
}
.muted { color: var(--muted); }
.error { color: var(--error); }
.small { font-size: 12px; }

/* login */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; display: grid; gap: 10px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }

/* app shell */
.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
header.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
header.top h1 { font-size: 16px; margin: 0; white-space: nowrap; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px;
}
nav.tabs a.active { background: var(--bg); color: var(--ink); font-weight: 600; }
header.top .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
header.top .right a { color: var(--accent); }
.status-line { font-size: 12px; color: var(--muted); }

main { min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: grid; }

/* model view */
#view-model { grid-template-columns: 260px 1fr 300px; }
.side {
  background: var(--panel); border-right: 1px solid var(--line); overflow: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 14px;
}
.side.right { border-right: 0; border-left: 1px solid var(--line); }
.side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.ctrl { display: grid; gap: 6px; }
.ctrl .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ctrl label { font-size: 13px; }
.ctrl input[type=range] { width: 100%; }
.slider-head { display: flex; justify-content: space-between; font-size: 13px; }
.slider-head output { font-variant-numeric: tabular-nums; color: var(--muted); }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btns button { font-size: 13px; padding: 4px 10px; }
#canvasWrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#canvasWrap canvas { display: block; }
#hover {
  position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; display: none; white-space: nowrap;
}
.board-label {
  font-size: 10px; background: rgba(255,255,255,.85); color: #222; padding: 1px 4px; border-radius: 4px;
  pointer-events: none; white-space: nowrap;
}
.empty-note {
  position: absolute; inset: auto 16px 16px 16px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px;
}
.legend { display: grid; gap: 4px; font-size: 12px; max-height: 220px; overflow: auto; }
.legend span.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }

/* detail panel */
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }
.detail h3 { margin: 0 0 8px; font-size: 18px; }

/* list view */
#view-list, #view-exhibitors { grid-template-rows: auto 1fr; }
.toolbar { display: flex; gap: 8px; padding: 10px 16px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line); background: var(--panel); }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.scroll { overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--bg); cursor: pointer; user-select: none; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel); }
tr.sel { outline: 2px solid var(--sel); outline-offset: -2px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding: 16px; align-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card .ids { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.card .ids a { text-decoration: none; }

/* admin */
.admin { max-width: 860px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.admin section { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.admin h2 { margin: 0; font-size: 17px; }
.admin .grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.admin pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; font-size: 12px; max-height: 240px; }

/* phones / small screens: stack panels */
@media (max-width: 900px) {
  #view-model { grid-template-columns: 1fr; grid-template-rows: auto 55vh auto; overflow: auto; }
  #view-model.active { display: grid; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .side.right { border-left: 0; }
  .view { overflow: auto; }
}
