:root {
  --bg: #09090a; --panel: #111113; --panel-2: #18181b; --panel-3: #202024; --line: #2b2b31; --line-2: #3a3a42;
  --text: #ece9e1; --muted: #a09c92; --gold: #c9a24a; --gold-2: #e2c273; --gold-dim: #6d5a2a;
  --valid: #4cc38a; --review: #e5a93d; --invalid: #ee5d54; --info: #7aa7d9;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: .01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
a { color: var(--gold-2); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--gold); color: #000; padding: 6px 10px; border-radius: 6px; }

/* shell */
.app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; height: 100dvh; }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: linear-gradient(135deg, var(--gold-2), var(--gold-dim)); color: #000; display: grid; place-items: center; font-weight: 800; }
.brand b { display: block; letter-spacing: .12em; font-size: 13px; } .brand small { color: var(--muted); font-size: 11px; }
.nav a, .nav .disabled { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; border: 1px solid transparent; }
.nav a:hover { color: var(--text); background: var(--panel-2); }
.nav a[aria-current="page"] { color: var(--gold-2); background: var(--panel-2); border-color: var(--line); box-shadow: inset 2px 0 0 var(--gold); }
.nav .disabled { opacity: .45; cursor: not-allowed; } .nav .tag { font-size: 10px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 6px; }
.nav-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }
.main { overflow: auto; position: relative; }
.page { padding: 24px 28px 48px; max-width: 1400px; } .page.full { max-width: none; padding: 0; height: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; } .gap { gap: 18px; }
.muted { color: var(--muted); } .mono { font-family: var(--mono); font-size: 12.5px; } .right { text-align: right; }

/* controls */
.btn { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 6px; padding: 7px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; color: var(--text); }
.btn:hover:not(:disabled) { border-color: var(--gold-dim); background: var(--panel-3); }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #15110a; border-color: var(--gold); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.danger { border-color: #5a2724; color: #ff9b94; } .btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; } .icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 2px rgba(201,162,74,.25); }
input[type=checkbox] { accent-color: var(--gold); width: 16px; height: 16px; padding: 0; }
.field { display: grid; gap: 4px; } .field-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; } .hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; } .chip { border: 1px solid var(--line-2); background: transparent; border-radius: 16px; padding: 3px 11px; cursor: pointer; color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-2); background: rgba(201,162,74,.1); }

/* cards, tables, badges */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.stat .num { font-size: 30px; font-weight: 650; color: var(--gold-2); line-height: 1.1; margin-top: 6px; } .card.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.card.later { opacity: .6; border-style: dashed; } .card.warn .num { color: var(--review); } .card.bad .num { color: var(--invalid); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); z-index: 1; }
tbody tr:hover { background: rgba(255,255,255,.025); } tr.click { cursor: pointer; } tr.sel { background: rgba(201,162,74,.09) !important; }
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
.badge { display: inline-block; border-radius: 10px; padding: 1px 8px; font-size: 11.5px; border: 1px solid var(--line-2); white-space: nowrap; }
.badge.valid { color: var(--valid); border-color: #245c42; background: rgba(76,195,138,.08); } .badge.review { color: var(--review); border-color: #6a4f17; background: rgba(229,169,61,.08); }
.badge.invalid { color: var(--invalid); border-color: #6b2622; background: rgba(238,93,84,.09); } .badge.gold { color: var(--gold-2); border-color: var(--gold-dim); }
.badge.info { color: var(--info); border-color: #2c4561; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.notice { border: 1px solid var(--gold-dim); background: rgba(201,162,74,.07); border-radius: 6px; padding: 9px 12px; color: var(--gold-2); font-size: 13px; }
.notice.bad { border-color: #6b2622; background: rgba(238,93,84,.08); color: #ff9b94; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: grid; place-items: start center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; width: min(560px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.6); } .modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); } .modal > :not(.modal-head) { padding: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; padding: 0; }
#toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 80; max-width: 420px; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--panel-3); border: 1px solid var(--line-2); box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast.ok { border-color: #245c42; } .toast.warn { border-color: #6a4f17; } .toast.error { border-color: #6b2622; color: #ff9b94; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--panel); border-left: 1px solid var(--line-2); z-index: 40; overflow: auto; box-shadow: -20px 0 60px rgba(0,0,0,.5); }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; } .drawer section { padding: 16px 18px; border-bottom: 1px solid var(--line); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 0%, rgba(201,162,74,.12), transparent 40%), var(--bg); }
.login-box { width: min(640px, 100%); } .login-grid { display: grid; gap: 10px; margin-top: 18px; }
.user-card { text-align: left; display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; width: 100%; }
.user-card:hover { border-color: var(--gold-dim); }

/* editor */
.editor { display: grid; grid-template-columns: 250px 1fr 340px; grid-template-rows: auto 1fr; height: 100%; }
.editor-bar { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.editor-bar h1 { font-size: 16px; } .palette, .side { background: var(--panel); overflow: auto; min-height: 0; } .palette { border-right: 1px solid var(--line); } .side { border-left: 1px solid var(--line); }
.palette .search { padding: 10px; position: sticky; top: 0; background: var(--panel); z-index: 1; } .pal-group { padding: 6px 10px 2px; }
.pal-item { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 6px 8px; margin: 2px 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: grab; }
.pal-item:hover { border-color: var(--gold-dim); } .pal-item .t { overflow: hidden; } .pal-item .t b { display: block; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } .pal-item .t small { color: var(--muted); }
.canvas-wrap { position: relative; min-width: 0; min-height: 0; background: #0c0c0e; }
.canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; } .canvas.panning { cursor: grabbing; } .canvas.locked { cursor: default; }
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tab { flex: 1; padding: 9px 6px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; } .tab[aria-selected="true"] { color: var(--gold-2); border-color: var(--gold); }
.side .pane { padding: 14px; display: grid; gap: 12px; align-content: start; }
.issue { padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); font-size: 12.5px; cursor: pointer; } .issue.error { border-left: 3px solid var(--invalid); } .issue.warning { border-left: 3px solid var(--review); } .issue.info { border-left: 3px solid var(--info); }
.issue small { color: var(--muted); display: block; margin-bottom: 2px; font-family: var(--mono); }
.legend { position: absolute; left: 10px; bottom: 10px; background: rgba(17,17,19,.92); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 11.5px; display: flex; gap: 10px; flex-wrap: wrap; max-width: 70%; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.zoom { position: absolute; right: 10px; top: 10px; display: grid; gap: 4px; }
.locked-banner { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 2; }
.safety-banner { position: absolute; left: 12px; right: 12px; bottom: 44px; z-index: 2; font-size: 12px; }
.bulk-list { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.bulk-row { padding: 6px 10px; border-bottom: 1px solid var(--line); gap: 10px; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }
.proposal { border: 1px solid var(--gold-dim); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
.prop-item { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); align-items: start; }
.prop-item .quote { color: var(--muted, #a09c92); font-size: 12px; font-style: italic; margin-top: 2px; }

/* ---------- responsive: tablet and phone ---------- */
.fab-row { display: none; position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 5; gap: 8px; justify-content: center; pointer-events: none; }
.fab-row .btn { pointer-events: auto; background: var(--panel-3); box-shadow: 0 6px 20px rgba(0,0,0,.5); border-color: var(--line-2); }
.fab-row .btn[aria-pressed="true"] { border-color: var(--gold); color: var(--gold-2); background: #2a2415; }
.connect-hint { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 4; max-width: 90%; text-align: center; }
.sheet-close { display: none; }
.wh-input { flex: 1; font-size: 18px; padding: 12px 14px; }
.wh-list { display: grid; gap: 10px; margin-top: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.wh-card { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; display: grid; gap: 3px; width: 100%; }
.wh-card:hover { border-color: var(--gold-dim); }
.wh-chips { margin-top: 10px; } .wh-status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip.big, .btn.big { padding: 10px 14px; min-height: 44px; font-size: 15px; justify-content: center; }
.wh-ev { padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
@media (max-width: 1100px) {
  .editor { grid-template-columns: 200px 1fr; }
  .side { position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); z-index: 30; transform: translateX(105%); transition: transform .2s; box-shadow: -20px 0 60px rgba(0,0,0,.6); }
  .side.open { transform: none; }
  .fab-row { display: flex; } .fab-pal { display: none; }
  .sheet-close { display: block; position: sticky; top: 0; z-index: 3; text-align: right; padding: 4px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .main { grid-row: 1; min-height: 0; }
  .nav { grid-row: 2; flex-direction: row; justify-content: space-around; gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
  .brand, .nav-foot, .nav .m-hide, .nav .disabled { display: none; }
  .nav a { flex: 1; justify-content: center; padding: 10px 2px; font-size: 12px; text-align: center; min-height: 46px; border-radius: 8px; box-shadow: none !important; }
  .nav a[aria-current="page"] { box-shadow: inset 0 2px 0 var(--gold) !important; }
  .page { padding: 14px 12px 28px; } h1 { font-size: 19px; }
  .page-head { margin-bottom: 14px; }
  .table-wrap { max-height: none; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 6px 10px; width: auto; background: var(--panel-2); }
  table.stack td { border: 0; padding: 3px 0; display: flex; gap: 10px; justify-content: space-between; align-items: baseline; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; flex: 0 0 34%; text-align: left; }
  table.stack td[data-label=""]::before { content: none; } table.stack td:empty { display: none; }
  .panel table.stack { padding: 0 8px; }
  .overlay { padding: 0; place-items: stretch; }
  .modal, .modal.wide { width: 100%; min-height: 100%; border-radius: 0; border: 0; }
  .drawer { width: 100vw; border-left: 0; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; } .card { padding: 12px; } .card.stat .num { font-size: 24px; }
  #toasts { left: 10px; right: 10px; bottom: 66px; max-width: none; }
  /* editor: toolbar scrolls sideways, palette and details become bottom sheets */
  .editor { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .editor-bar { flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding: 8px 10px; } .editor-bar > * { flex: 0 0 auto; } .editor-bar h1 { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } #counts { display: none; }
  .palette, .side { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 62vh; z-index: 30; border: 0; border-top: 1px solid var(--line-2); border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform .2s; box-shadow: 0 -20px 60px rgba(0,0,0,.6); padding-bottom: env(safe-area-inset-bottom); }
  .palette.open, .side.open { transform: none; }
  .fab-pal { display: inline-flex; }
  .legend { display: none; } .zoom { top: 8px; right: 8px; } .zoom .btn { min-width: 40px; min-height: 40px; justify-content: center; }
  .safety-banner { bottom: 64px; }
  .fab-row { bottom: 10px; }
  .pal-item { padding: 10px; } .pal-item .btn { min-width: 44px; min-height: 40px; justify-content: center; }
}
@media (pointer: coarse) {
  .btn { min-height: 40px; } .btn.small { min-height: 36px; padding: 6px 12px; }
  input, select, textarea { min-height: 40px; font-size: 16px; } input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
  .chip { padding: 6px 13px; min-height: 34px; }
}

.ae-results { display: grid; gap: 6px; max-height: 58vh; overflow: auto; }
.ae-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: left; width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--text); }
.ae-row:hover { border-color: var(--gold-dim); background: var(--panel-3); } .ae-new { border-style: dashed; margin-top: 6px; }
/* Add-equipment results: keep model numbers whole, move the badge + action under the text on narrow screens */
.ae-row .mono { white-space: nowrap; }
.ae-row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.ae-row .btn.small { flex: none; }
.ae-web h3, .ae-results h3 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
@media (max-width: 640px) {
  .ae-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .ae-row > span:last-child { width: 100%; justify-content: space-between; }
  .ae-results { max-height: 52vh; }
}
@media (max-width: 640px) { #inv-search { width: 100%; min-width: 0 !important; } }

/* ---- Studio (premium) ---- */
.pro-tag { display: inline-block; justify-self: start; width: fit-content; font-size: 9.5px; font-weight: 800; letter-spacing: .12em; padding: 2px 6px; border-radius: 4px; background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #15110a; vertical-align: middle; }
.studio-btn { border-color: var(--gold-dim); }
.studio .tabs { position: static; background: none; margin-bottom: 14px; } .studio .tab { flex: 0 0 auto; padding: 9px 16px; }
.studio-info { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.dl-group { display: flex; gap: 10px; flex-wrap: wrap; }
.dl { display: grid; gap: 1px; padding: 8px 14px; border: 1px solid var(--gold-dim); border-radius: 8px; background: var(--panel-2); text-decoration: none; color: var(--text); }
.dl b { color: var(--gold-2); } .dl span { font-size: 12px; color: var(--muted); } .dl:hover { background: var(--panel-3); border-color: var(--gold); }
.paper-wrap { padding: 12px; overflow: auto; background: #1b1b1f; }
.paper { background: #fff; border-radius: 3px; box-shadow: 0 6px 30px rgba(0,0,0,.55); overflow: auto; max-width: 100%; line-height: 0; }
.paper svg { display: block; width: 100%; height: auto; min-width: 640px; }
.rack-card { margin-top: 14px; }
.rack-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; } .rack-head input[aria-label="Rack name"] { width: 150px; }
.rack-body { display: grid; gap: 14px; }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; } .totals div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; } .totals b { font-size: 18px; color: var(--gold-2); } .totals span { font-size: 11.5px; color: var(--muted); }
.issues { margin: 0; padding-left: 18px; display: grid; gap: 4px; } .issues .error { color: var(--invalid); } .issues .warning { color: var(--review); } .issues .info { color: var(--info); }
.studio-form { display: grid; gap: 12px; max-width: 560px; } .studio-form h3 { margin: 6px 0 0; }
.studio-lock { padding: 0; overflow: hidden; margin-top: 14px; background: radial-gradient(1200px 400px at 20% -10%, rgba(201,162,74,.16), transparent), var(--panel); }
.studio-lock-in { padding: 28px; display: grid; gap: 14px; max-width: 780px; } .studio-lock h1 { margin: 0; font-size: 28px; } .studio-lock .lead { margin: 0; font-size: 16px; color: var(--muted); }
.studio-feats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; } .studio-feat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 4px; } .studio-feat b { color: var(--gold-2); } .studio-feat span { color: var(--muted); font-size: 13px; }
@media (max-width: 720px) { .totals { grid-template-columns: repeat(2, 1fr); } .studio-lock-in { padding: 18px; } .dl-group { width: 100%; } .dl { flex: 1; } }

/* ---- accounts ---- */
.auth-box { max-width: 440px; } .auth-box h1 { margin: 22px 0 6px; } .auth-box form { margin-top: 14px; }
#team table { width: 100%; } #team .row input[type=email] { flex: 1 1 220px; }
.page > .panel + .panel { margin-top: 14px; }

/* ---- platform admin ---- */
.support-bar { position: sticky; top: 0; z-index: 60; display: flex; gap: 12px; align-items: center; justify-content: center; padding: 8px 12px; background: #3a2c0b; color: var(--gold-2); border-bottom: 1px solid var(--gold); font-weight: 600; }
#admin td select { max-width: 150px; }
