@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #f4f6f9; --fg: #18202c; --muted: #677284; --card: #ffffff; --line: #e1e6ed; --soft: #eef1f5;
  --accent: #f26b1d; --accent-soft: #fff1e8; --bar: #121821; --bar-fg: #f2f4f7;
  --danger: #d23c3c; --ok: #1f9d55; --blue: #3e7bfa; --red: #e5484d;
  --radius: 12px; --shadow: 0 1px 2px #10182808, 0 4px 16px #1018280d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --fg: #e8ebf0; --muted: #98a1b0; --card: #171d26; --line: #273040; --soft: #1d2430;
    --accent-soft: #3a2416; --shadow: 0 1px 2px #0006;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --fg: #e8ebf0; --muted: #98a1b0; --card: #171d26; --line: #273040; --soft: #1d2430;
  --accent-soft: #3a2416; --shadow: 0 1px 2px #0006;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 Inter, system-ui, "Segoe UI", sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.pad { margin: 0 12px; }
button, .btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }
.primary, .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.primary:hover { filter: brightness(1.05); }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--soft); border-color: transparent; }
.danger { color: var(--danger); }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.bar { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; background: var(--bar); color: var(--bar-fg); }
.brand { font-weight: 800; color: var(--accent); text-decoration: none; letter-spacing: .4px; display: flex; align-items: center; gap: 8px; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; }
.title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 6px; }
.bar .actions button { background: transparent; color: var(--bar-fg); border-color: #364051; padding: 5px 10px; }
.bar .actions button:hover { border-color: var(--accent); }
.bar .actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ============ dashboard ============ */
.dash main { padding: 20px 16px 48px; max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head p { margin: 2px 0 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat .hint { color: var(--muted); font-size: 12px; }
.stat .value.small-value { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 10px; }
.meter { height: 6px; background: var(--soft); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.meter > div { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--card); }
.seg button.active { background: var(--soft); color: var(--accent); }

.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: visible; }
table.models { width: 100%; border-collapse: collapse; }
table.models th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); }
table.models th:first-child { border-top-left-radius: var(--radius); }
table.models th:last-child { border-top-right-radius: var(--radius); }
table.models td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.models tr:last-child td { border-bottom: 0; }
table.models tr:hover td { background: color-mix(in srgb, var(--soft) 55%, transparent); }
.model-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.model-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.model-name { font-weight: 600; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--soft); color: var(--fg); font-size: 12px; font-weight: 500; }
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.chip.warn { background: var(--accent-soft); color: var(--accent); }
.chip-btn { padding: 2px 10px; border-radius: 999px; font-size: 12px; border-color: var(--accent); color: var(--accent); background: transparent; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.row-actions button, .row-actions .btn { padding: 6px 10px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.mcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.mcard .top { display: flex; gap: 12px; }
.mcard .qr { width: 84px; height: 84px; background: #fff; border-radius: 8px; padding: 4px; flex: none; border: 1px solid var(--line); }

.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 200px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px #0002; padding: 6px; display: flex; flex-direction: column; }
.menu-list button, .menu-list a { border: 0; justify-content: flex-start; width: 100%; padding: 8px 10px; background: transparent; border-radius: 6px; color: var(--fg); text-decoration: none; display: flex; gap: 8px; }
.menu-list button:hover, .menu-list a:hover { background: var(--soft); }
.menu-list .danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

.empty { text-align: center; padding: 48px 16px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .big { font-size: 40px; }

.drop { display: block; border: 2px dashed var(--line); border-radius: 12px; padding: 26px 16px; text-align: center; cursor: pointer; background: var(--soft); }
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select { color: var(--fg); font-weight: 400; }

.topnav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.topnav button { background: transparent; color: #aab4c3; border: 0; padding: 7px 12px; border-radius: 8px; }
.topnav button:hover { color: #fff; background: #ffffff14; }
.topnav button.active { color: #fff; background: #ffffff1f; }
.badge-inline { background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 4px; }
.chip-btn.red { border-color: var(--red); color: var(--red); }
.value.danger, b.danger { color: var(--danger); }
.proj { gap: 12px; }
.proj-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.proj-stats div { background: var(--soft); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; }
.proj-stats b { font-size: 18px; }
.gallery-admin { display: flex; flex-direction: column; gap: 8px; }
.media-row { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 6px; }
.media-row img, .media-row video { width: 96px; height: 60px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
table.issues select { padding: 4px 6px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--bar); color: var(--bar-fg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px #0003; z-index: 60; max-width: calc(100vw - 32px); }

/* ============ modal (shared) ============ */
.modal { position: fixed; inset: 0; background: #0009; display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--card); border-radius: 14px; width: min(380px, 100%); max-height: calc(100vh - 32px); overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 14px; box-shadow: 0 20px 60px #0004; }
.modal-card.wide { width: min(560px, 100%); }
.modal-body { padding: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px; align-items: center; }
.modal-card .qr { background: #fff; margin: 0 12px; padding: 8px; border-radius: 8px; }
.modal-card > input, .modal-card > button { margin: 0 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.x { border: 0; background: transparent; font-size: 22px; line-height: 1; padding: 0 4px; }

/* ============ viewer ============ */
.viewer { display: flex; flex-direction: column; overflow: hidden; height: 100vh; height: 100dvh; }
.title-wrap { flex: 1; min-width: 0; line-height: 1.2; }
.subtitle { font-size: 12px; color: #9aa4b2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .ghost-dark { background: transparent; color: var(--bar-fg); border-color: #364051; width: 34px; justify-content: center; padding: 6px 0; }
.stage { flex: 1; min-height: 0; display: flex; position: relative; }
.rail { width: 78px; flex: none; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; overflow-y: auto; z-index: 12; }
.rail button { flex-direction: column; gap: 2px; border: 0; background: transparent; padding: 7px 2px; font-size: 11px; color: var(--muted); position: relative; justify-content: center; white-space: normal; text-align: center; line-height: 1.15; }
.rail button i { font-style: normal; font-size: 18px; color: var(--fg); line-height: 1.1; }
.rail button:hover { background: var(--soft); }
.rail button.active { background: var(--accent-soft); color: var(--accent); }
.rail button.active i { color: var(--accent); }
.badge { position: absolute; top: 3px; right: 6px; background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; line-height: 16px; }
#canvas { flex: 1; min-height: 0; min-width: 0; position: relative; touch-action: none; }
#canvas canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.status { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--card); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center; z-index: 40; }
.pick-hint { position: fixed; left: 50%; top: 68px; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 20; max-width: calc(100vw - 32px); }
.an-status { position: fixed; right: 12px; bottom: 30px; font-size: 12px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.an-status:empty { display: none; }
.credit { position: fixed; right: 12px; bottom: 6px; font-size: 11px; color: var(--muted); pointer-events: none; }
.panel { position: absolute; top: 12px; bottom: 12px; width: min(370px, calc(100vw - 32px)); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; box-shadow: 0 6px 24px #0002; z-index: 10; }
.panel.right { right: 12px; }
.panel.left { left: 90px; }
.help-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.help-grid div { display: flex; flex-direction: column; gap: 2px; background: var(--soft); border-radius: 10px; padding: 10px; }
.issue-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.issue-item { display: flex; gap: 8px; align-items: flex-start; text-align: left; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--card); white-space: normal; }
button.issue-item:hover { border-color: var(--accent); }
.issue-item .grow { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.issue-item .grow > * { overflow-wrap: anywhere; }
.linkish { border: 0; background: transparent; padding: 0; text-align: left; white-space: normal; display: flex; flex-direction: column; align-items: stretch; gap: 2px; cursor: pointer; }
.st { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.st-open { background: var(--red); } .st-progress { background: #f5a524; } .st-closed { background: var(--ok); }
.form { display: flex; flex-direction: column; gap: 10px; }
.form textarea, .comment-form textarea, .anchor textarea { font: inherit; resize: vertical; }
.chip-line { display: block; margin: 6px 0; }
button.chip-line { border: 1px dashed var(--line); background: var(--soft); border-radius: 8px; padding: 6px 8px; text-align: left; white-space: normal; font-size: 12px; }
.chip.pr-critical { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.chip.pr-high { background: #fdf0d9; color: #a35f00; }
.chip.pr-low { color: var(--muted); }
.issue-head h3 { margin: 8px 0 2px; font-size: 16px; }
.issue-head p { margin: 0 0 8px; }
.issue-body { white-space: normal; background: var(--soft); border-radius: 8px; padding: 8px 10px; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.back { padding: 4px 0; margin-bottom: 4px; }
.panel h4 { margin: 14px 0 6px; font-size: 13px; }
.comments { display: flex; flex-direction: column; gap: 8px; }
.comment { background: var(--soft); border-radius: 8px; padding: 6px 10px; }
.comment p { margin: 2px 0 0; }
.comment-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.pick-inline { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 6px 10px; font-weight: 600; }
.clash-sum { display: flex; gap: 6px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.issue-item.clash.crit { border-left: 4px solid var(--danger); }
.issue-item.clash.warn { border-left: 4px solid #f5a524; }
.dot-inline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot-inline.red { background: var(--red); } .dot-inline.blue { background: var(--blue); }
.seg.wrap { display: flex; flex-wrap: wrap; }
.seg.wrap button { flex: 1; }
.sched-tot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.sched-tot div { background: var(--soft); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; }
.sched-tot b { font-size: 16px; }
.sched-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.panel table.sched th { width: auto; position: sticky; top: 0; background: var(--soft); padding: 6px; }
.panel table.sched td { padding: 5px 6px; border-top: 1px solid var(--line); }
.panel table.sched td:not(:first-child), .panel table.sched th:not(:first-child) { text-align: right; white-space: nowrap; }
table.sched tr[data-k] { cursor: pointer; }
table.sched tr[data-k]:hover td { background: var(--accent-soft); }
details.mat { margin: 6px 0; }
.row-actions.pad { padding: 0 12px; }
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.media-tile { position: relative; padding: 0; border-radius: 10px; overflow: hidden; display: block; aspect-ratio: 16 / 10; background: #000; }
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 8px; font-size: 11px; color: #fff; background: linear-gradient(transparent, #000b); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-tile .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 26px; text-shadow: 0 2px 8px #000; }
.media-full { width: 100%; border-radius: 10px; background: #000; display: block; }
.media-title { margin: 6px 0; font-size: 15px; }
.panel-body { overflow: auto; padding: 8px 12px; flex: 1; }
.panel-tools { display: flex; gap: 6px; padding: 8px 12px 0; }
.panel-tools input { flex: 1; }
.panel-foot { border-top: 1px solid var(--line); padding: 8px 12px; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; }
.tabs button { flex: 1; justify-content: center; font-size: 12px; padding: 6px 8px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.tree summary { list-style: none; cursor: pointer; }
.tree summary::-webkit-details-marker { display: none; }
.tree details > summary .row::before { content: "▸"; color: var(--muted); width: 10px; display: inline-block; }
.tree details[open] > summary .row::before { content: "▾"; }
.tree details.fam { margin-left: 16px; }
.tree .tree-cat { font-weight: 600; }
.tree .tree-fam { padding-left: 2px; }
.tree > .tree-fam, .tree details > .tree-fam { margin-left: 18px; }
.tree .tree-type { margin-left: 34px; color: var(--muted); }
.count { font-size: 11px; color: var(--muted); background: var(--soft); border-radius: 999px; padding: 0 7px; }
.iso { border: 0; background: transparent; padding: 0 4px; color: var(--muted); font-size: 13px; }
.iso:hover { color: var(--accent); }
table.props { width: 100%; border-collapse: collapse; font-size: 13px; }
.panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.panel th { text-align: left; color: var(--muted); font-weight: 500; padding: 3px 8px 3px 0; vertical-align: top; width: 42%; word-break: break-word; }
.panel td { padding: 3px 0; word-break: break-word; }
.panel details { margin-top: 8px; }
.panel summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.anchor { display: flex; flex-direction: column; gap: 10px; }
.anchor p { margin: 0; }
.slot { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.slot-head { display: flex; align-items: center; gap: 8px; }
.dot { width: 22px; height: 22px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.dot.red { background: var(--red); } .dot.blue { background: var(--blue); }
.section { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; width: min(420px, calc(100vw - 32px)); z-index: 10; }
.section input { width: 100%; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 12px; }
.choices button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px; }
.ar-stage { margin: 0 12px; height: 320px; border-radius: 10px; overflow: hidden; background: var(--bg); position: relative; }
.ar-stage model-viewer { width: 100%; height: 100%; }
.ar-stage .go { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--accent); color: #fff; border: 0; padding: 8px 14px; }
.ar-overlay { position: fixed; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; z-index: 100; }
.ar-info { margin: 12px; padding: 10px 12px; border-radius: 10px; background: #000a; color: #fff; font-size: 14px; }
.ar-pad { margin: 12px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.ar-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ar-row button { justify-content: center; padding: 10px 4px; font-size: 13px; background: #000b; color: #fff; border-color: #fff5; }
.ar-row .ar-exit { background: var(--danger); border-color: var(--danger); }
.vr-help { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line); padding: 8px 12px; border-radius: 10px; }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .bar .actions button { padding: 5px 9px; font-size: 13px; flex: none; }
  .stage { flex-direction: column; }
  .rail { order: 2; width: auto; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; padding: 4px; gap: 0; }
  .rail button { min-width: 62px; padding: 6px 2px; }
  .panel, .panel.left, .panel.right { top: auto; bottom: 8px; height: 58%; left: 8px; right: 8px; width: auto; }
  .section { bottom: 86px; }
  .toast { bottom: 90px; }
  .credit, .an-status { display: none; }
  .help-grid { grid-template-columns: repeat(2, 1fr); }
  .topnav { justify-content: flex-start; overflow-x: auto; }
  .topnav button { padding: 6px 8px; font-size: 13px; }
  .proj-stats { grid-template-columns: repeat(2, 1fr); }
  .dash .bar .title, .dash .bar .hide-sm { display: none; }
  .fields { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  table.models thead { display: none; }
  table.models, table.models tbody, table.models tr, table.models td { display: block; width: 100%; }
  table.models tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.models td { border: 0; padding: 4px 14px; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
}
