/* Clash Marker Field Map — neutral dark greys, floating glass panels over a full-bleed plan. */
:root {
  --canvas: #121214;
  --dot: #222226;
  --surface: rgba(30, 30, 33, .82);
  --surface-solid: #1e1e21;
  --raised: #28282c;
  --hover: rgba(255, 255, 255, .06);
  --press: rgba(255, 255, 255, .1);
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .14);
  --text: #ececef;
  --muted: #a0a0a8;
  --faint: #6c6c74;

  --accent: #3BA0E6;            /* Clash Marker blue — selection and focus only */
  --accent-soft: rgba(59, 160, 230, .16);
  --done: #4cc26b;  --done-soft: rgba(76, 194, 107, .14);
  --issue: #f0b545; --issue-soft: rgba(240, 181, 69, .16);
  --danger: #e5534b;
  --ctrl: #00E676;              /* control lines */
  --gridline: #7FB2FF;          /* grids, when a level has no control lines */
  --dimln: #ff5ca8;             /* dimension leaders */
  --plan-ink: #111;  --halo: #fff;

  --r-sm: 8px; --r: 10px; --r-lg: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .3);
  --blur: saturate(140%) blur(18px);
  --hit: 36px;
  --gap: 12px;
  font: 13.5px/1.4 "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Inter, system-ui, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
  color-scheme: dark;
  -webkit-font-smoothing: antialiased;
}
@media (pointer: coarse) { :root { --hit: 44px; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--canvas); color: var(--text); overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.sm { width: 14px; height: 14px; }

.glass { background: var(--surface); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); }

.btn-icon { position: relative; display: inline-grid; place-items: center; width: var(--hit); height: var(--hit); border-radius: var(--r-sm); color: var(--text); transition: background .12s, color .12s; }
.btn-icon:hover, .btn:hover { background: var(--hover); }
.btn-icon:active, .btn:active { background: var(--press); }
.btn-icon[aria-pressed=true], .btn-icon[aria-expanded=true] { background: var(--accent-soft); color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--hit); padding: 0 14px;
  border-radius: var(--r-sm); background: var(--raised); border: 1px solid var(--border); font-weight: 500; white-space: nowrap; transition: background .12s, transform .06s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.done { background: var(--done); border-color: transparent; color: #0b1a10; }
.btn.warn { background: var(--issue); border-color: transparent; color: #241900; }
.btn.primary:hover, .btn.done:hover, .btn.warn:hover { filter: brightness(1.08); background-blend-mode: normal; }
.badge { position: absolute; top: 3px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 16px; }
kbd { font: 11px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--faint); border: 1px solid var(--border-strong); border-radius: 5px; padding: 3px 5px; }

/* ---------- canvas ---------- */
.canvas { position: fixed; inset: 0; background: var(--canvas);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 22px 22px; }
#plan { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#plan:active { cursor: grabbing; }
#plan.nopaper { --plan-ink: #ececef; --halo: #1e1e21; }
#plan * { vector-effect: non-scaling-stroke; }
#plan text { vector-effect: none; }
#plan .sheetbg { filter: drop-shadow(0 6px 28px rgba(0, 0, 0, .55)); }
#plan .paper { fill: #fff; }
#plan.nopaper .paper { fill: var(--surface-solid); stroke: var(--border-strong); stroke-width: 1; }
#plan .grid { fill: none; stroke: #2a2a2f; stroke-width: 1; }
#plan .ctrl .under { stroke: rgba(0, 0, 0, .5); stroke-width: 4.5; }
#plan .ctrl .over { stroke: var(--ctrl); stroke-width: 2; }
#plan .ctrl .tag rect { fill: var(--ctrl); stroke: rgba(0, 0, 0, .35); stroke-width: 1; }
#plan .ctrl .tag text { fill: #04210f; font-weight: 700; letter-spacing: .02em; }
#plan .ctrl .gridline.over { stroke: var(--gridline); stroke-width: 1.6; }
#plan .ctrl .gridline.under { stroke-width: 3.5; }
#plan .ctrl .tag.gridline rect { fill: var(--gridline); }
#plan .ctrl .tag.gridline text { fill: #0b1830; }
#plan .outside { fill: rgba(16, 16, 18, .55); }
#plan .dims line { stroke: var(--dimln); stroke-width: 1.5; }
#plan .dims circle { fill: var(--dimln); }
#plan .dims text { fill: var(--dimln); font-weight: 700; paint-order: stroke; stroke: var(--halo); stroke-width: .32em; stroke-linejoin: round; }
#plan .labels text { fill: var(--plan-ink); font-weight: 600; paint-order: stroke; stroke: var(--halo); stroke-width: .3em; stroke-linejoin: round; pointer-events: none; }
#plan .sleeve { cursor: pointer; }
#plan .sleeve .shape { fill: #fff; stroke: #18181b; stroke-width: 2; transition: stroke .1s; }
#plan .sleeve:hover .shape { stroke: var(--accent); }
#plan .sleeve.st-done .shape { fill: var(--done); stroke: #0e3a1c; }
#plan .sleeve.st-issue .shape { fill: var(--issue); stroke: #4a3200; stroke-width: 2.5; }
#plan .sleeve .halo { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; display: none; }
#plan .sleeve.sel .halo { display: inline; }
#plan .sleeve.sel .shape { stroke: var(--accent); stroke-width: 2.5; }
#plan .sleeve .hit { fill: transparent; stroke: none; }

/* ---------- top bar ---------- */
.topbar { position: fixed; top: max(var(--gap), env(safe-area-inset-top)); left: var(--gap); right: var(--gap); z-index: 6;
  display: flex; align-items: center; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.grow { flex: 1; pointer-events: none !important; }
.brand { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 14px 0 12px; min-width: 0; }
.logo { height: 16px; width: auto; display: block; opacity: .95; }
.vr { width: 1px; height: 22px; background: var(--border-strong); flex: none; }
.proj { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.proj b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.proj small { color: var(--muted); font-size: 11.5px; }
.picker { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 12px; color: var(--text); text-align: left; transition: background .12s; }
.picker:hover { background: var(--raised); }
.picker .i:first-child { color: var(--muted); }
.picked { display: flex; flex-direction: column; line-height: 1.2; }
.picked b { font-weight: 600; }
.picked small { color: var(--muted); font-size: 11.5px; }
.progress { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 14px 0 8px; }
.ring { width: 32px; height: 32px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
.ring .track { stroke: var(--border-strong); }
.ring .fill { stroke: var(--done); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .4s ease; }
.progress div { display: flex; flex-direction: column; line-height: 1.2; }
.progress b { font-weight: 600; }
.progress small { color: var(--muted); font-size: 11.5px; }
.progress small.has-issues { color: var(--issue); }
.sync { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.sync.ok::before { background: var(--done); box-shadow: 0 0 0 3px var(--done-soft); }
.sync.waiting::before { background: var(--issue); box-shadow: 0 0 0 3px var(--issue-soft); animation: pulse 1.6s infinite; }
.sync.err::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .4; } }
#menuBtn { width: 48px; height: 48px; border-radius: var(--r-lg); }

/* ---------- side panel ---------- */
.side { position: fixed; z-index: 5; top: calc(max(var(--gap), env(safe-area-inset-top)) + 60px); left: var(--gap); bottom: var(--gap);
  width: 360px; display: flex; flex-direction: column; overflow: hidden; }
.grab { display: none; }
.side-top { display: flex; gap: 6px; padding: 12px 12px 8px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; height: var(--hit); padding: 0 10px; border-radius: var(--r-sm);
  background: var(--raised); border: 1px solid var(--border); color: var(--muted); transition: border-color .12s; }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); }
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { filter: invert(.6); }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; margin: 0 12px 8px; padding: 3px; border-radius: var(--r-sm); background: rgba(0, 0, 0, .25); }
.tabs button { height: 30px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 12.5px; white-space: nowrap; transition: background .12s, color .12s; }
.tabs button span { color: var(--faint); font-size: 11.5px; margin-left: 2px; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected=true] { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.tabs button[aria-selected=true] span { color: var(--muted); }

.filter-panel { padding: 4px 12px 8px; border-top: 1px solid var(--border); display: grid; gap: 10px; max-height: 40vh; overflow-y: auto; }
.filter-panel h4 { margin: 6px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--border-strong);
  color: var(--muted); font-size: 12.5px; transition: all .12s; }
.chip:hover { color: var(--text); border-color: var(--faint); }
.chip[aria-pressed=true] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chips.active { padding: 0 12px 8px; }
.chips.active .chip { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chips.active .chip .i { width: 12px; height: 12px; }

.list-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted); }
.list-head span:first-child { flex: 1; }
.bar { width: 72px; height: 4px; border-radius: 2px; background: var(--border-strong); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--done); border-radius: 2px; transition: width .3s; }

.rows { flex: 1; overflow-y: auto; padding: 6px; scrollbar-width: thin; scrollbar-color: var(--raised) transparent; }
.row { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 8px 6px 4px; border-radius: var(--r-sm); cursor: pointer; transition: background .1s; }
.row:hover { background: var(--hover); }
.row.sel { background: var(--accent-soft); }
.tick { display: grid; place-items: center; width: var(--hit); height: var(--hit); flex: none; border-radius: 50%; }
.tick::before { content: ""; grid-area: 1 / 1; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--faint); transition: all .15s; }
.tick:hover::before { border-color: var(--done); }
.tick .i { grid-area: 1 / 1; width: 14px; height: 14px; stroke-width: 3; color: #0b1a10; opacity: 0; transform: scale(.6); transition: all .15s; }
.row.st-done .tick::before { background: var(--done); border-color: var(--done); }
.row.st-done .tick .i { opacity: 1; transform: none; }
.row.st-issue .tick::before { background: var(--issue); border-color: var(--issue); }
.row.st-issue .tick .i { opacity: 1; transform: none; color: #241900; }
.row .main { flex: 1; min-width: 0; }
.row .l1 { display: flex; align-items: baseline; gap: 8px; }
.row .tag { font-weight: 650; font-size: 14px; }
.row .spec { color: var(--text); opacity: .85; }
.row .l2 { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .note { display: block; margin-top: 2px; color: var(--issue); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .by { color: var(--faint); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.row.st-done .tag, .row.st-done .spec { opacity: .65; }
.pill-warn { font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: rgba(229, 83, 75, .18); color: #ff8a84; }
.empty { display: grid; place-items: center; gap: 4px; padding: 40px 16px; color: var(--muted); text-align: center; }
.empty b { color: var(--text); font-weight: 600; }

/* ---------- map controls ---------- */
.controls { position: fixed; z-index: 5; right: var(--gap); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; padding: 4px; }
.controls .hr { height: 1px; margin: 4px 6px; background: var(--border); }
.btn-icon.labelled { height: auto; padding: 8px 0 6px; gap: 2px; }
.btn-icon.labelled small { font-size: 10px; font-weight: 600; color: var(--muted); }

/* ---------- inspector ---------- */
.inspector { position: fixed; z-index: 7; left: calc(var(--gap) + 360px + var(--gap)); right: calc(var(--gap) + 64px); bottom: var(--gap);
  margin: 0 auto; max-width: 640px; padding: 14px; animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.ins-head { display: flex; align-items: flex-start; gap: 12px; }
.ins-dot { width: 12px; height: 12px; margin-top: 6px; border-radius: 50%; border: 2px solid var(--faint); flex: none; }
.ins-dot.st-done { background: var(--done); border-color: var(--done); }
.ins-dot.st-issue { background: var(--issue); border-color: var(--issue); }
.ins-title { flex: 1; min-width: 0; }
.ins-title b { font-size: 17px; font-weight: 650; margin-right: 8px; }
.ins-title span { color: var(--muted); }
.ins-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; color: var(--muted); font-size: 12px; }
.ins-meta .dim { color: var(--dimln); font-weight: 600; }
.ins-status { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 10px; border-radius: var(--r-sm); background: rgba(0, 0, 0, .22); font-size: 12.5px; color: var(--muted); }
.ins-status.st-done { color: var(--done); background: var(--done-soft); }
.ins-status.st-issue { color: var(--issue); background: var(--issue-soft); }
.ins-status .i { width: 15px; height: 15px; }
.ins-status q { color: var(--text); quotes: "“" "”"; }
.ins-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ins-actions .sep { flex: 1; }
.ins-actions .sm { display: none; }

/* ---------- popovers ---------- */
.popover { position: fixed; z-index: 20; min-width: 260px; max-width: calc(100vw - 24px); max-height: 70vh; overflow-y: auto; padding: 6px; background: rgba(30, 30, 33, .94); animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.lvl { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; width: 100%; padding: 10px 12px; border-radius: var(--r-sm); text-align: left; }
.lvl:hover { background: var(--hover); }
.lvl.on { background: var(--accent-soft); }
.lvl b { font-weight: 600; }
.lvl small { color: var(--muted); font-size: 11.5px; }
.lvl .bar { grid-column: 1 / -1; width: 100%; }
.areas { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.menu button { display: grid; grid-template-columns: 20px 1fr; align-items: center; column-gap: 12px; width: 100%; padding: 10px 12px; border-radius: var(--r-sm); text-align: left; font-weight: 500; }
.menu button:hover { background: var(--hover); }
.menu button .i { grid-row: span 2; color: var(--muted); }
.menu button small { grid-column: 2; color: var(--faint); font-weight: 400; font-size: 11.5px; }
.menu-info { padding: 10px 12px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.menu-info b { display: block; color: var(--text); font-size: 13.5px; margin-bottom: 2px; }
.menu-foot { margin-top: 4px; padding: 10px 12px 6px; border-top: 1px solid var(--border); color: var(--faint); font-size: 11px; }

/* ---------- legal ---------- */
.legal { position: fixed; z-index: 4; right: var(--gap); bottom: 6px; padding: 3px 8px; border-radius: 6px; background: rgba(18, 18, 20, .72);
  color: var(--muted); font-size: 11px; pointer-events: none; transition: opacity .15s; }
body.has-sel .legal { opacity: 0; }

/* ---------- dialogs ---------- */
dialog { width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border-strong); border-radius: 16px;
  background: var(--surface-solid); color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, .6); }
dialog[open] { animation: pop .16s ease-out; }
dialog::backdrop { background: rgba(0, 0, 0, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog form { display: flex; flex-direction: column; gap: 12px; padding: 22px; }
dialog h2 { margin: 0; font-size: 17px; font-weight: 650; }
dialog p { margin: 0; color: var(--muted); }
dialog input, dialog textarea { width: 100%; padding: 10px 12px; min-height: var(--hit); border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--raised); color: var(--text); outline: 0; }
dialog input:focus, dialog textarea:focus { border-color: var(--accent); }
#initialsInput { font-size: 20px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- loading / error screen ---------- */
.screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 24px; background: var(--canvas);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 22px 22px; }
.screen-card { max-width: 420px; text-align: center; }
.screen-logo { width: 220px; height: auto; margin-bottom: 28px; opacity: .95; }
.screen h1 { margin: 0 0 8px; font-size: 19px; font-weight: 600; }
.screen p { margin: 0 0 16px; color: var(--muted); }
.loader { width: 160px; height: 3px; margin: 8px auto 0; border-radius: 2px; background: var(--border-strong); overflow: hidden; }
.loader i { display: block; width: 40%; height: 100%; background: var(--accent); border-radius: 2px; animation: load 1.1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

.toast { position: fixed; z-index: 40; left: 50%; top: 76px; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px;
  background: var(--surface-solid); border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-weight: 500; max-width: calc(100vw - 32px); animation: pop .16s ease-out; }

/* ---------- tablet: narrower panel ---------- */
@media (max-width: 1100px) {
  .side { width: 320px; }
  .inspector { left: calc(var(--gap) + 320px + var(--gap)); }
  .sync span, .proj small { display: none; }
}
@media (max-width: 960px) { .sync { display: none; } }

/* ---------- phone: list becomes a bottom sheet ---------- */
@media (max-width: 767px) {
  :root { --gap: 8px; }
  .brand { height: 44px; padding: 0 10px; gap: 10px; flex: 1; }
  .proj b { max-width: none; }
  .picker { height: 44px; padding: 0 10px; }
  .picker .i:first-child { display: none; }
  .progress, .sync, .grow { display: none !important; }
  .ins-actions { display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; gap: 6px; }
  .ins-actions .sep, .ins-actions .lg { display: none; }
  .ins-actions .sm { display: inline; }
  .ins-actions .btn { padding: 0 8px; }
  #menuBtn { width: 44px; height: 44px; }
  .topbar { flex-wrap: wrap; }
  .side { top: auto; left: 0; right: 0; bottom: 0; width: auto; border-radius: 18px 18px 0 0; border-bottom: 0;
    height: var(--sheet-h, 46vh); transition: height .22s cubic-bezier(.2, .8, .2, 1); padding-bottom: calc(env(safe-area-inset-bottom) + 18px); }
  .side.dragging { transition: none; }
  .grab { display: block; flex: none; height: 22px; width: 100%; touch-action: none; }
  .grab::before { content: ""; display: block; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--border-strong); }
  .side-top { padding-top: 2px; }
  .controls { top: auto; bottom: calc(var(--sheet-h, 46vh) + 10px); transform: none; transition: bottom .22s; }
  .inspector { left: var(--gap); right: var(--gap); bottom: calc(var(--sheet-h, 46vh) + 10px); max-width: none; }
  body.has-sel .controls { display: none; }
  .legal { right: 0; left: 0; bottom: max(2px, env(safe-area-inset-bottom)); text-align: center; z-index: 6; }
  .toast { top: 64px; }
}
