:root {
  --bg: #0b0d12;
  --bg-2: #0f1218;
  --surface: #141821;
  --surface-2: #1a1f2a;
  --surface-3: #222836;
  --border: #262c3a;
  --border-2: #323a4c;
  --text: #e8ebf2;
  --text-2: #b4bccc;
  --muted: #7d879b;
  --accent: #ffb020;
  --accent-2: #ffd37a;
  --accent-ink: #1a1203;
  --accent-soft: rgba(255, 176, 32, .12);
  --cyan: #3dd6d0;
  --cyan-soft: rgba(61, 214, 208, .12);
  --ok: #3ddc84;
  --ok-soft: rgba(61, 220, 132, .12);
  --warn: #ffb020;
  --bad: #ff5d6c;
  --bad-soft: rgba(255, 93, 108, .12);
  --info: #6ea8ff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --top-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { overflow-x: hidden; }
body {
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 80% -10%, rgba(255, 176, 32, .06), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(61, 214, 208, .05), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-feature-settings: 'zero'; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.spacer { flex: 1; }

/* ---------- boot / login ---------- */
.boot { height: 100vh; display: grid; place-items: center; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; background: url('/favicon.svg') center/cover; flex: none; }
.boot .logo-mark { width: 56px; height: 56px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.94); } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; margin: 16px 0 4px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 22px; color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text); cursor: pointer; white-space: nowrap;
  font-weight: 500; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-3); border-color: #3d475c; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: .01em; }
.input, select.input, textarea.input {
  height: 38px; width: 100%; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border-2);
  background: var(--bg-2); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 120px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { letter-spacing: .02em; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--accent-soft); color: var(--accent); }
.pill.cyan { background: var(--cyan-soft); color: var(--cyan); }
.pill.src-ofl { background: rgba(110, 168, 255, .14); color: var(--info); }
.pill.src-gdtf { background: var(--cyan-soft); color: var(--cyan); }
.pill.src-custom, .pill.src-csv, .pill.src-upload { background: var(--accent-soft); color: var(--accent); }
.pill.src-ma2lib { background: rgba(255, 210, 120, .12); color: #ffd278; }
.pill.src-ma2 {background: rgba(255, 210, 120, .12); color: #ffd278; }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: rgba(11, 13, 18, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; font-size: 16px; color: var(--text); }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { display: flex; gap: 2px; margin-left: 14px; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); }
.proj-name { min-width: 0; max-width: 340px; height: 34px; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 0 10px; font-weight: 600; font-size: 15px; }
.proj-name:hover { border-color: var(--border-2); }
.proj-name:focus { border-color: var(--accent); background: var(--bg-2); outline: none; }
.save-state { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.save-state.saving::before { background: var(--accent); animation: pulse 1s infinite; }
.save-state.error::before { background: var(--bad); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 20px 80px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.03em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 18px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 0 0 10px; }

/* projects */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.proj-card { padding: 18px; cursor: pointer; transition: border-color .15s, transform .15s, background .15s; position: relative; display: flex; flex-direction: column; gap: 14px; min-height: 150px; }
.proj-card:hover { border-color: var(--border-2); background: var(--surface-2); transform: translateY(-2px); }
.proj-card h3 { font-size: 16px; margin: 0; padding-right: 30px; word-break: break-word; }
.proj-card .meta { display: flex; gap: 16px; margin-top: auto; }
.proj-card .meta b { display: block; font-size: 18px; font-family: var(--mono); }
.proj-card .meta span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.proj-card .menu { position: absolute; top: 10px; right: 10px; }
.proj-new { border-style: dashed; display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.proj-new:hover { color: var(--accent); border-color: var(--accent); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 18px; margin: 0 0 6px; }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; max-width: 1600px; margin: 0 auto; padding: 18px 20px 40px; }
.editor-main { min-width: 0; }
.side { position: sticky; top: calc(var(--top-h) + 18px); align-self: start; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - var(--top-h) - 36px); overflow: auto; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; width: fit-content; margin-bottom: 14px; }
.tabs button { height: 32px; padding: 0 14px; border-radius: 8px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 7px; }
.tabs button svg { width: 16px; height: 16px; }
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-2); }
.tabs .count { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--bad-soft); color: var(--bad); font-weight: 700; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { position: relative; flex: 1; min-width: 180px; max-width: 360px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search .input { padding-left: 34px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.tile .v { font: 600 24px/1.1 var(--mono); letter-spacing: -.02em; }
.tile .l { font-size: 11.5px; color: var(--muted); margin-top: 6px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.tile .s { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.tile.accent .v { color: var(--accent); }
.tile.cyan .v { color: var(--cyan); }
.tiles.wide { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

/* patch table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.patch { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.patch th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: default; user-select: none; }
table.patch th.sortable { cursor: pointer; }
table.patch th.sortable:hover { color: var(--text); }
table.patch th .arrow { color: var(--accent); }
table.patch td { padding: 3px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.patch tr:last-child td { border-bottom: 0; }
table.patch tr:hover td { background: rgba(255, 255, 255, .02); }
table.patch tr.sel td { background: var(--accent-soft); }
table.patch tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: rgba(61, 214, 208, .35); } }
table.patch td.c, table.patch th.c { text-align: center; width: 36px; }
table.patch .swatch { width: 4px; padding: 0; }
table.patch .swatch i { display: block; width: 4px; height: 26px; border-radius: 3px; }
.cell { width: 100%; height: 30px; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 0 6px; outline: none; min-width: 0; }
.cell:hover { border-color: var(--border-2); }
.cell:focus { border-color: var(--accent); background: var(--bg-2); }
.cell.mono { font-family: var(--mono); font-size: 13px; }
.cell.w-fid { width: 70px; }
.cell.w-addr { width: 84px; }
.cell.w-name { min-width: 140px; }
.cell.w-layer { width: 110px; }
.fx-name { display: flex; flex-direction: column; line-height: 1.2; padding: 3px 4px; max-width: 280px; }
.fx-name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.fx-name span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.conf { color: var(--bad); display: inline-flex; cursor: help; }
.conf svg { width: 17px; height: 17px; }

.bulkbar { position: sticky; top: calc(var(--top-h) + 8px); z-index: 20; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; margin-bottom: 12px; background: var(--surface-3); border: 1px solid var(--accent); border-radius: 11px; box-shadow: var(--shadow); }
.bulkbar b { color: var(--accent); margin-right: 6px; }

/* mobile cards */
.cards { display: none; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 12px 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center; position: relative; overflow: hidden; }
.pcard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--sw, var(--border)); }
.pcard.sel { border-color: var(--accent); background: var(--accent-soft); }
.pcard .fid { font: 600 17px var(--mono); min-width: 46px; }
.pcard .nm { min-width: 0; }
.pcard .nm b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .nm span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .ad { text-align: right; font-family: var(--mono); }
.pcard .ad b { display: block; font-size: 16px; }
.pcard .ad span { font-size: 11.5px; color: var(--muted); }
.pcard .conf { position: absolute; right: 8px; top: 6px; }

/* universe map */
.umap { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.ucard { padding: 14px; }
.ucard header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.ucard header h3 { margin: 0; font-size: 15px; }
.ucard header .mono { font-size: 12px; color: var(--muted); }
.ugrid { display: grid; grid-template-columns: repeat(32, 1fr); gap: 1px; background: var(--bg); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.ugrid i { aspect-ratio: 1; background: var(--surface-2); display: block; position: relative; cursor: pointer; }
.ugrid i.used { background: hsl(var(--h) 70% 52% / .78); }
.ugrid i.start { box-shadow: inset 3px 0 0 rgba(0, 0, 0, .75); }
.ugrid i.res { background: repeating-linear-gradient(45deg, #2a3040 0 3px, #1b2029 3px 6px); }
.ugrid i.bad { background: var(--bad) !important; }
.ugrid i.hl { outline: 2px solid #fff; z-index: 1; }
.fillbar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.fillbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--accent)); border-radius: 99px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: hsl(var(--h) 70% 52%); }

/* calculator */
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fit-list { display: flex; flex-direction: column; }
.fit { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px; }
.fit:last-child { border-bottom: 0; }
.fit:hover { background: var(--surface-2); }
.fit .dot { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; }
.fit .dot svg { width: 13px; height: 13px; }
.fit.ok .dot { background: var(--ok-soft); color: var(--ok); }
.fit.no .dot { background: var(--bad-soft); color: var(--bad); }
.fit .nm { font-weight: 500; }
.fit .why { font-size: 12px; color: var(--muted); }
.fit.no .nm { color: var(--text-2); }
.fit.best { background: var(--ok-soft); box-shadow: inset 0 0 0 1px rgba(61, 220, 132, .35); }
.fit.chosen .nm::after { content: 'TARGET'; margin-left: 8px; font-size: 10px; font-weight: 700; letter-spacing: .08em; color: var(--accent); }
.unv-bars { display: flex; flex-direction: column; gap: 8px; }
.unv-bars .r { display: grid; grid-template-columns: 52px 1fr 76px; gap: 10px; align-items: center; font-size: 12.5px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 6px; border-bottom: 1px solid var(--border); font-weight: 600; }
table.simple td { padding: 7px 6px; border-bottom: 1px solid var(--border); }
table.simple tr:last-child td { border-bottom: 0; }
table.simple td.n { text-align: right; font-family: var(--mono); }

/* export */
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.xcard { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.xcard .head { display: flex; align-items: center; gap: 12px; }
.xcard .badge { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font: 700 13px var(--mono); flex: none; }
.xcard p { margin: 0; color: var(--text-2); font-size: 13px; flex: 1; }
.xcard ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.warnings { display: flex; flex-direction: column; gap: 6px; }
.warn-row { display: flex; gap: 8px; padding: 9px 12px; border-radius: 9px; font-size: 13px; align-items: flex-start; }
.warn-row svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.warn-row.error { background: var(--bad-soft); color: #ffb3ba; }
.warn-row.warn { background: var(--accent-soft); color: var(--accent-2); }
.warn-row.info { background: rgba(110, 168, 255, .1); color: #b9d3ff; }
.warn-row.ok { background: var(--ok-soft); color: #a9f2c9; }

/* modal / sheet */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(4, 6, 10, .66); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: var(--shadow); animation: pop .18s ease-out; }
.modal.wide { max-width: 980px; }
.modal.mid { max-width: 720px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal > header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal > header h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal > .body { padding: 18px; overflow: auto; flex: 1; min-height: 0; }
.modal > footer { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* add fixture */
.addfx { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; min-height: 460px; }
.results { display: flex; flex-direction: column; gap: 4px; max-height: 56vh; overflow: auto; margin-top: 10px; padding-right: 2px; }
.res { padding: 10px 12px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.res:hover { background: var(--surface-2); }
.res.active { background: var(--accent-soft); border-color: rgba(255, 176, 32, .4); }
.res .t { display: flex; align-items: center; gap: 8px; }
.res .t b { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .m { font-size: 12px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modes { display: flex; flex-wrap: wrap; gap: 6px; }
.mode-chip { border: 1px solid var(--border-2); background: var(--bg-2); border-radius: 9px; padding: 7px 11px; cursor: pointer; text-align: left; }
.mode-chip b { display: block; font-size: 13px; font-weight: 600; }
.mode-chip span { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.mode-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.mode-chip.active span { color: var(--accent-2); }
.preview { border-radius: 10px; padding: 12px; background: var(--bg-2); border: 1px solid var(--border); font-size: 13px; }
.preview b { color: var(--accent); }
.qty { display: flex; align-items: stretch; }
.qty .input { border-radius: 0; text-align: center; font-family: var(--mono); }
.qty .btn { border-radius: 0; height: 38px; }
.qty .btn:first-child { border-radius: 9px 0 0 9px; }
.qty .btn:last-child { border-radius: 0 9px 9px 0; }
.chlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 14px; font-size: 12.5px; max-height: 220px; overflow: auto; padding: 8px 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; }
.chlist div { display: flex; gap: 8px; color: var(--text-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chlist div i { font-style: normal; color: var(--muted); font-family: var(--mono); min-width: 24px; text-align: right; }
.chlist div.fine { color: var(--muted); }
.back-btn { display: none; }

/* library */
.lib-list { display: flex; flex-direction: column; }
.lib-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; align-items: center; }
.lib-row:last-child { border-bottom: 0; }
.lib-row:hover { background: var(--surface-2); }
.lib-row b { font-weight: 600; }
.lib-row .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dropzone { border: 1.5px dashed var(--border-2); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.mode-edit { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg-2); }

/* toast */
#toast-root { position: fixed; z-index: 200; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-3); border: 1px solid var(--border-2); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; animation: pop .2s ease-out; pointer-events: auto; display: flex; gap: 12px; align-items: center; }
.toast.error { border-color: var(--bad); color: #ffc2c8; }
.toast.ok { border-color: rgba(61, 220, 132, .5); }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; }

/* dropdown menu */
.menu-pop { position: fixed; z-index: 150; min-width: 200px; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 11px; box-shadow: var(--shadow); padding: 5px; animation: pop .12s ease-out; }
.menu-pop button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 11px; border: 0; background: transparent; border-radius: 7px; cursor: pointer; text-align: left; color: var(--text); }
.menu-pop button:hover { background: var(--surface-3); }
.menu-pop button.danger { color: var(--bad); }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-pop svg { width: 16px; height: 16px; color: var(--muted); }

/* mobile bottom nav + fab */
.bottomnav { display: none; }
.fab { display: none; }
.readonly-banner { background: var(--cyan-soft); color: var(--cyan); text-align: center; padding: 8px 16px; font-size: 13px; font-weight: 500; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 860px) {
  .calc-grid { grid-template-columns: 1fr; }
  .umap { grid-template-columns: minmax(0, 1fr); }
  .addfx { grid-template-columns: 1fr; min-height: 0; }
  .addfx.picked .pick-col { display: none; }
  .addfx:not(.picked) .cfg-col { display: none; }
  .back-btn { display: inline-flex; }
}
@media (max-width: 760px) {
  :root { --top-h: 56px; }
  body { font-size: 15px; }
  .topbar { padding: 0 10px; gap: 6px; }
  .nav { display: none; }
  .brand small, .hide-m { display: none !important; }
  .proj-name { max-width: none; flex: 1; font-size: 15px; padding: 0 6px; }
  .topbar .proj-name ~ .spacer { display: none; }
  .page { padding: 20px 16px 100px; }
  .page-head h1 { font-size: 22px; }
  .editor { padding: 12px 12px calc(90px + var(--safe-b)); }
  .editor > .editor-main > .tabs { display: none; }
  .table-wrap.patch-table { display: none; }
  .cards { display: flex; flex-direction: column; gap: 8px; }
  .toolbar .search { max-width: none; min-width: 0; flex-basis: 100%; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; z-index: 40; left: 0; right: 0; bottom: 0;
    padding: 6px 6px calc(6px + var(--safe-b)); background: rgba(15, 18, 24, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--border);
  }
  .bottomnav button { background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; padding: 6px 0; border-radius: 10px; position: relative; }
  .bottomnav button svg { width: 22px; height: 22px; }
  .bottomnav button.active { color: var(--accent); background: var(--accent-soft); }
  .bottomnav .count { position: absolute; top: 2px; right: calc(50% - 22px); background: var(--bad); color: #fff; border-radius: 99px; font-size: 10px; padding: 0 5px; line-height: 16px; }
  .fab { display: grid; place-items: center; position: fixed; z-index: 41; right: 16px; bottom: calc(78px + var(--safe-b)); width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 10px 30px rgba(255, 176, 32, .35); }
  .fab svg { width: 26px; height: 26px; }
  .overlay { padding: 0; align-items: end; }
  .modal, .modal.wide, .modal.mid { max-width: none; max-height: 92vh; border-radius: 18px 18px 0 0; border-bottom: 0; animation: slideup .22s ease-out; }
  .modal.full-m { max-height: 100vh; height: 100vh; border-radius: 0; }
  .modal > footer { padding-bottom: calc(14px + var(--safe-b)); }
  .modal > footer .btn { flex: 1; }
  @keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .bulkbar { position: fixed; top: auto; bottom: calc(72px + var(--safe-b)); left: 10px; right: 10px; margin: 0; z-index: 42; }
  .ugrid { grid-template-columns: repeat(16, 1fr); }
  .tiles.wide { grid-template-columns: 1fr 1fr; }
  .input, select.input { height: 42px; font-size: 16px; }
  textarea.input { font-size: 16px; }
  .results { max-height: none; }
  .proj-grid { grid-template-columns: 1fr; }
}

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; color: #000; font-size: 10.5px; }
  #app, #modal-root, #toast-root { display: none !important; }
  #print-root { display: block; }
  .pr h1 { font-size: 18px; margin: 0 0 2px; }
  .pr .sub { color: #555; margin-bottom: 10px; }
  .pr h2 { font-size: 13px; margin: 16px 0 6px; border-bottom: 2px solid #000; padding-bottom: 3px; break-after: avoid; }
  .pr table { width: 100%; border-collapse: collapse; }
  .pr th, .pr td { border: 1px solid #bbb; padding: 3px 5px; text-align: left; }
  .pr th { background: #eee; }
  .pr td.n { text-align: right; font-family: var(--mono); }
  .pr .sum { display: flex; gap: 18px; margin: 8px 0 4px; }
  .pr .sum b { font-size: 15px; display: block; }
  .pr .ug { display: grid; grid-template-columns: repeat(32, 1fr); border: 1px solid #999; margin-bottom: 4px; }
  .pr .ug i { height: 9px; border-right: 1px solid #ddd; border-bottom: 1px solid #ddd; }
  .pr .ug i.used { background: #bbb; }
  .pr .ug i.start { background: #444; }
  .pr .uwrap { break-inside: avoid; margin-bottom: 8px; }
  .pr .page-break { break-before: page; }
}
