/* Genba — site viewer. Layout: top bar / left list / 3D stage / right inspector; stacks on phones.
   Palette: drafting-paper neutrals with a cedar accent for selection and a blueprint blue for drawing links. */
:root {
  --bg: #e9ebee; --panel: #ffffff; --panel-2: #f3f4f6; --line: #d3d7dd; --fg: #1c2127; --fg-2: #5a6472; --fg-3: #8a93a0;
  --accent: #b8472a; --accent-soft: #f6e0d8; --blue: #2d5fb3; --blue-soft: #dde7f7; --green: #2f7d4f; --amber: #b7791f;
  --stage: #dfe3e8; --shadow: 0 1px 2px rgba(20,30,40,.08), 0 8px 24px rgba(20,30,40,.08);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 6px; --topbar: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --panel: #1e2227; --panel-2: #252a30; --line: #343a42; --fg: #e8eaed; --fg-2: #a7afba; --fg-3: #737d89;
    --accent: #e0714f; --accent-soft: #3d2520; --blue: #7aa6e8; --blue-soft: #22304a; --green: #6cc08b; --amber: #e0b35a;
    --stage: #1a1e23; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --panel: #1e2227; --panel-2: #252a30; --line: #343a42; --fg: #e8eaed; --fg-2: #a7afba; --fg-3: #737d89;
  --accent: #e0714f; --accent-soft: #3d2520; --blue: #7aa6e8; --blue-soft: #22304a; --green: #6cc08b; --amber: #e0b35a;
  --stage: #1a1e23; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
}
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 13px/1.45 var(--font); overflow: hidden; }
* { box-sizing: border-box; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-2); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- frame */
#app { display: grid; height: 100%; grid-template-rows: var(--topbar) 1fr; grid-template-columns: 300px 1fr 360px;
  grid-template-areas: "top top top" "left stage right"; }
#topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
#left { grid-area: left; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#stage { grid-area: stage; position: relative; background: var(--stage); min-width: 0; min-height: 0; }
#right { grid-area: right; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
canvas#c { display: block; width: 100%; height: 100%; outline: none; }
#stage.split canvas#c { position: absolute; left: 50%; width: 50%; }
.brand { display: flex; flex-direction: column; line-height: 1.1; margin-right: 6px; }
.brand b { font-size: 14px; letter-spacing: .02em; }
.brand span { font-size: 11px; color: var(--fg-2); }
.tabs { display: flex; gap: 2px; background: var(--panel-2); border-radius: var(--radius); padding: 2px; }
.tabs button { border: 0; background: transparent; padding: 5px 11px; border-radius: 4px; color: var(--fg-2); font-weight: 500; }
.tabs button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
#search { flex: 1; min-width: 120px; max-width: 460px; position: relative; }
#search input { width: 100%; padding: 7px 10px 7px 30px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); outline: none; }
#search input:focus { border-color: var(--blue); }
#search .ico { position: absolute; left: 9px; top: 8px; color: var(--fg-3); pointer-events: none; }
#results { position: absolute; top: 36px; left: 0; right: 0; max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 30; }
#results .grp { padding: 6px 10px 2px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3); }
#results .hit { padding: 6px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#results .hit:hover, #results .hit.on { background: var(--blue-soft); }
#results .hit .k { font-family: var(--mono); font-size: 12px; color: var(--blue); white-space: nowrap; }
#results .hit .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vswitch { display: flex; gap: 2px; background: var(--panel-2); border-radius: var(--radius); padding: 2px; }
.vswitch button { border: 0; background: transparent; padding: 5px 9px; border-radius: 4px; color: var(--fg-2); font-size: 12px; }
.vswitch button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.iconbtn { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 5px 9px; color: var(--fg-2); font-size: 12px; }
.iconbtn:hover { color: var(--fg); border-color: var(--fg-3); }
.iconbtn.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- panels */
.panel-head { padding: 10px 14px 8px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-2); font-weight: 600; flex: 1; }
.panel-body { flex: 1; overflow: auto; min-height: 0; padding: 8px 0; }
.panel-body.pad { padding: 10px 14px; }
.tree .node { display: flex; align-items: center; gap: 6px; padding: 3px 10px 3px calc(10px + var(--d, 0) * 14px); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .node:hover { background: var(--panel-2); }
.tree .node.on { background: var(--blue-soft); }
.tree .node .tw { width: 12px; color: var(--fg-3); font-size: 10px; flex: none; }
.tree .node input { margin: 0; flex: none; }
.tree .node .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tree .node .cnt { color: var(--fg-3); font-family: var(--mono); font-size: 11px; }
.sw { width: 10px; height: 10px; border-radius: 2px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.list .row { padding: 7px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .row:hover { background: var(--panel-2); }
.list .row.on { background: var(--blue-soft); }
.list .row .t { font-weight: 500; }
.list .row .m { color: var(--fg-2); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: 11px; color: var(--fg-2); font-family: var(--mono); cursor: pointer; }
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.filters { display: flex; gap: 6px; padding: 8px 14px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.filters select, .filters input { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); font-size: 12px; min-width: 0; }
.filters input { flex: 1; }

/* ---------- inspector */
.insp h3 { margin: 0 0 2px; font-size: 15px; font-weight: 600; text-wrap: balance; }
.insp .sub { color: var(--fg-2); font-size: 12px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: minmax(90px, 36%) 1fr; gap: 3px 10px; font-size: 12px; margin: 6px 0 10px; }
.kv dt { color: var(--fg-2); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; word-break: break-word; }
.sec { margin: 12px 0 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.sec::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.dcard { display: grid; grid-template-columns: 64px 1fr; gap: 8px; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); margin: 6px 0; cursor: pointer; background: var(--panel); }
.dcard:hover { border-color: var(--blue); }
.dcard img { width: 64px; height: 48px; object-fit: cover; border-radius: 3px; background: #fff; }
.dcard .t { font-weight: 500; font-size: 12px; line-height: 1.3; }
.dcard .m { color: var(--fg-2); font-size: 11px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: var(--radius); padding: 5px 10px; font-size: 12px; }
.btn:hover { border-color: var(--fg-3); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
table.tk { width: 100%; border-collapse: collapse; font-size: 11.5px; font-variant-numeric: tabular-nums; }
table.tk th { text-align: left; color: var(--fg-2); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.tk td { padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tk td.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.tablewrap { overflow: auto; max-height: 320px; border: 1px solid var(--line); border-radius: var(--radius); }
.note-text { white-space: pre-wrap; font-size: 12.5px; line-height: 1.5; background: var(--panel-2); border-radius: var(--radius); padding: 8px 10px; margin: 4px 0 8px; }
.note-text .ref { background: var(--blue-soft); color: var(--blue); border-radius: 3px; padding: 0 3px; cursor: pointer; font-family: var(--mono); font-size: 11.5px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.photo-grid img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 4px; cursor: pointer; border: 2px solid transparent; }
.photo-grid img.on { border-color: var(--accent); }
.insp img.big { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); cursor: zoom-in; background: #fff; }

/* ---------- stage overlays */
#hud { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 3; }
#legend { position: absolute; right: 10px; bottom: 10px; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; font-size: 11px; display: grid; grid-template-columns: auto auto; gap: 3px 14px; z-index: 3; max-height: 40%; overflow: auto; }
#legend div { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; font-size: 12px; box-shadow: var(--shadow); z-index: 4; max-width: 320px; }
#timebar { position: absolute; left: 10px; right: 10px; bottom: 10px; background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; z-index: 3; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
#timebar input[type=range] { width: 100%; }
#timebar .ticks { position: relative; height: 26px; }
#timebar .ticks i { position: absolute; bottom: 0; width: 2px; height: 10px; background: var(--fg-3); border-radius: 1px; }
#timebar .ticks i.in { background: var(--accent); height: 16px; }
#timebar .ticks i.note { background: var(--blue); }
#timebar .lab { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
#status { position: absolute; left: 10px; bottom: 10px; font-size: 11px; color: var(--fg-2); background: color-mix(in srgb, var(--panel) 80%, transparent); padding: 3px 8px; border-radius: 4px; z-index: 3; }
#modal { position: fixed; inset: 0; background: rgba(10,12,16,.82); z-index: 50; display: flex; flex-direction: column; }
#modal .bar { display: flex; align-items: center; gap: 10px; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); color: #fff; background: rgba(0,0,0,.4); }
#modal .bar .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modal .bar button { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 5px 10px; border-radius: 4px; }
#modal .view { flex: 1; overflow: hidden; position: relative; cursor: grab; touch-action: none; }
#modal .view img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; max-width: none; }
#compare { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; z-index: 2; pointer-events: none; }
#compare .hint { align-self: end; justify-self: center; margin-bottom: 72px; pointer-events: auto; background: color-mix(in srgb, var(--panel) 90%, transparent); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; font-size: 12px; display: flex; gap: 8px; align-items: center; }
#compare .ph { background: #000; display: flex; align-items: center; justify-content: center; pointer-events: auto; position: relative; }
#compare .ph img { max-width: 100%; max-height: 100%; object-fit: contain; }
#compare .ph .cap { position: absolute; left: 8px; bottom: 8px; color: #fff; font-size: 12px; background: rgba(0,0,0,.5); padding: 3px 8px; border-radius: 4px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.pill.v1 { background: var(--blue-soft); color: var(--blue); }
.pill.v2 { background: var(--accent-soft); color: var(--accent); }
.pill.both { background: var(--panel-2); color: var(--fg-2); }
.empty { padding: 20px 14px; color: var(--fg-2); font-size: 12.5px; }
.ok { color: var(--green); }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--fg-2); z-index: 9; background: var(--stage); font-size: 13px; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; background: var(--panel-2); }

/* ---------- phone */
#mobiletabs { display: none; }
@media (max-width: 860px) {
  #app { grid-template-rows: auto 1fr auto; grid-template-columns: 1fr; grid-template-areas: "top" "stage" "panels"; }
  #topbar { flex-wrap: wrap; height: auto; padding-block: 6px; gap: 6px 8px; }
  .brand { flex: 1 1 100%; } .brand b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tabs button { padding: 5px 8px; font-size: 12px; }
  #search { flex: 1 1 160px; max-width: none; order: 5; }
  .vswitch { order: 6; } #mobiletabs { order: 7; }
  #left, #right { border: 0; border-top: 1px solid var(--line); height: 42vh; }
  #left { grid-area: panels; } #right { grid-area: panels; }
  #left.off, #right.off { display: none; }
  #mobiletabs { display: flex; }
  .brand span { display: none; }
  #legend { display: none; }
  #hud { gap: 4px; } #hud .iconbtn { padding: 4px 7px; font-size: 11px; }
  #right { padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
