/* SpliceOp Recipe Finder
   Layout: instrument-panel tool. Header strip with library source, tab bar, one working surface per tab.
   Left/right pickers mirror the splicer's L/R fiber holders. Windows-native faces so it works offline. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --sunken: #edf0f4;
  --ink: #131820;
  --muted: #586273;
  --line: #d8dde5;
  --accent: #1a56d6;
  --accent-ink: #ffffff;
  --accent-weak: #e5ecfc;
  --glass: #cdd6e2;
  --glass-edge: #a8b5c6;
  --arc: #f2a516;
  --good: #1d7f55; --good-weak: #e0f2e9;
  --warn: #946006; --warn-weak: #fbefd6;
  --bad: #b3362b; --bad-weak: #fbe5e2;
  --j-sm: #e2bd2f; --j-mm: #e07b2c; --j-pm: #3c6fd8; --j-re: #2aa58f; --j-other: #8a93a3;
  --f-display: "Bahnschrift", "Segoe UI Semibold", "DIN Alternate", "Arial Narrow", system-ui, sans-serif;
  --f-body: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --f-mono: "Cascadia Mono", "Cascadia Code", Consolas, ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --sunken: #1c212a; --ink: #e6e9ef; --muted: #98a1b0; --line: #2a313c;
    --accent: #6f9bff; --accent-ink: #0b1020; --accent-weak: #1a2541; --glass: #2b3442; --glass-edge: #45526a; --arc: #ffbf3c;
    --good: #4cc18c; --good-weak: #12291f; --warn: #e2a63b; --warn-weak: #2c2310; --bad: #ef7a6e; --bad-weak: #33181a;
    --j-sm: #e9c84a; --j-mm: #f0904a; --j-pm: #6f9bff; --j-re: #3fc0a8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --sunken: #1c212a; --ink: #e6e9ef; --muted: #98a1b0; --line: #2a313c;
  --accent: #6f9bff; --accent-ink: #0b1020; --accent-weak: #1a2541; --glass: #2b3442; --glass-edge: #45526a; --arc: #ffbf3c;
  --good: #4cc18c; --good-weak: #12291f; --warn: #e2a63b; --warn-weak: #2c2310; --bad: #ef7a6e; --bad-weak: #33181a;
  --j-sm: #e9c84a; --j-mm: #f0904a; --j-pm: #6f9bff; --j-re: #3fc0a8;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.5; }
[hidden] { display: none !important; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; font-weight: 600; }
h1 { font-size: 27px; letter-spacing: 0.01em; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
p { margin: 0; }
.num, td.n, .mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-family: var(--f-display); font-size: 11.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* header */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; padding-bottom: 14px; }
.top .sub { color: var(--muted); margin-top: 2px; }
.source { display: grid; gap: 6px; justify-items: end; text-align: right; margin-left: auto; font-size: 12.5px; color: var(--muted); }
.source b { color: var(--ink); font-family: var(--f-mono); font-weight: 500; }
.source .row { justify-content: flex-end; }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab { appearance: none; border: 0; background: none; padding: 10px 14px; font: 600 14.5px var(--f-display); color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; letter-spacing: 0.02em; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; padding: 10px 14px; border-radius: var(--r); background: var(--warn-weak); margin-bottom: 16px; font-size: 13px; }
.banner b { color: var(--warn); }

/* controls */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 500 13px var(--f-body); padding: 7px 12px; border-radius: var(--r); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--glass-edge); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); padding-inline: 6px; }
.btn:disabled { opacity: 0.5; cursor: default; }
label.f { display: grid; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
input, select { font: 14px var(--f-body); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; width: 100%; min-width: 0; }
input[type="number"] { font-family: var(--f-mono); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="range"] { padding: 0; border: 0; accent-color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.pad { padding: 16px; }
.stack { display: grid; gap: 16px; }
.stack > *, .cols > *, .pair > * { min-width: 0; }

/* finder */
.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: stretch; }
.picker { padding: 14px; display: grid; gap: 10px; align-content: start; }
.picker .side { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pf { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pf .wide { grid-column: span 2; }
.picker .meta { font-size: 12px; color: var(--muted); }
.picker .meta b { font-family: var(--f-mono); font-weight: 500; color: var(--ink); }
.combo { position: relative; }
.combo input { padding-right: 30px; }
.combo-toggle { position: absolute; right: 1px; top: 1px; bottom: 1px; width: 28px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 0 var(--r) var(--r) 0; font-size: 12px; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 6; margin: 0; padding: 4px 0; list-style: none; max-height: 320px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--glass-edge); border-radius: var(--r); box-shadow: 0 8px 24px rgba(0, 0, 0, .14); }
.combo-list [role=option] { display: grid; gap: 1px; padding: 6px 10px; cursor: pointer; }
.combo-list [role=option][aria-selected=true], .combo-list [role=option]:hover { background: var(--accent-weak); }
.combo-list .o-name { font-size: 13.5px; color: var(--ink); overflow-wrap: anywhere; }
.combo-list .o-spec { font-size: 11.5px; color: var(--muted); font-family: var(--f-mono); overflow-wrap: anywhere; }
.combo-list .o-none { padding: 8px 10px; font-size: 12.5px; color: var(--muted); }
.mid { display: grid; gap: 8px; align-content: center; justify-items: center; padding: 8px 0; }
.mid label.f { width: 110px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--sunken); color: var(--ink); white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--j-other); display: inline-block; }
.filters { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 13px; padding: 10px 14px; margin-top: 12px; }
.filters label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

.sv-ink { fill: var(--ink); } .sv-muted { fill: var(--muted); } .sv-glass { fill: var(--glass); stroke: var(--glass-edge); stroke-width: 1; }
.sv-core { fill: var(--accent); opacity: 0.85; } .sv-core-mm { fill: var(--accent); opacity: 0.35; }
.sv-arc { fill: var(--arc); opacity: 0.22; } .sv-elec { fill: var(--muted); } .sv-arcline { stroke: var(--arc); stroke-width: 1.5; stroke-dasharray: 3 3; }
.sv-axis { stroke: var(--line); stroke-width: 1; }
svg text { font-family: var(--f-body); } svg text.m { font-family: var(--f-mono); }

.view { padding: 12px 16px 4px; }
.viewtabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); }
.viewtab { appearance: none; border: 0; background: none; padding: 7px 12px; font: 600 13px var(--f-display); letter-spacing: 0.02em; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.viewtab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.view.geo { overflow-x: auto; padding-bottom: 8px; }
.view.geo svg { display: block; width: 100%; min-width: 560px; max-width: 1100px; margin: 0 auto; height: auto; }
.lv-controls { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; padding-bottom: 6px; }
.lvchip { appearance: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 3px 10px; font: 12.5px var(--f-mono); cursor: pointer; }
.lvchip i, .lv-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lvchip.on { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.lvseg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lvseg button { appearance: none; border: 0; background: var(--surface); color: var(--ink); padding: 3px 11px; font: 12.5px var(--f-mono); cursor: pointer; }
.lvseg button + button { border-left: 1px solid var(--line); }
.lvseg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.lvseg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.lv-sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.lv-num { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.lv-num input[type=number] { width: 84px; padding: 3px 6px; }
.lv-num input[type=range] { width: 110px; }
.lv-draw { overflow-x: auto; }
.lv-draw svg { display: block; width: 100%; min-width: 560px; max-width: 1100px; margin: 0 auto; height: auto; }
.lv-core { fill: none; stroke: var(--glass-edge); stroke-dasharray: 4 3; stroke-width: 1; }
.lv-profB { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 5 3; }
.lv-below { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 12px 24px; padding: 8px 0 12px; align-items: start; }
.lv-prof svg { display: block; width: 100%; height: auto; }
.lv-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.lv-legend span { display: inline-flex; gap: 6px; align-items: center; }
.lv-legend i.dash { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed var(--ink); }
.lv-facts { display: grid; gap: 8px; align-content: start; }
.lv-big { display: grid; gap: 2px; }
.lv-big .v { font-family: var(--f-mono); font-size: 22px; }
.lv-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.warnword { color: var(--warn); font-weight: 600; }
@media (max-width: 700px) { .lv-below { grid-template-columns: 1fr; } .lv-sep { display: none; } }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.stat { padding: 12px 16px; border-left: 1px solid var(--line); display: grid; gap: 2px; align-content: start; }
.stat:first-child { border-left: 0; }
.stat .v { font-family: var(--f-mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--muted); }
.q { display: inline-block; font: 600 12px var(--f-display); letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; }
.q.high { background: var(--good-weak); color: var(--good); }
.q.good { background: var(--accent-weak); color: var(--accent); }
.q.fair { background: var(--warn-weak); color: var(--warn); }
.q.low { background: var(--bad-weak); color: var(--bad); }

.notes { display: grid; gap: 6px; padding: 0; margin: 0; list-style: none; }
.notes li { display: grid; grid-template-columns: 4px 1fr; gap: 10px; font-size: 13.5px; }
.notes li::before { content: ""; border-radius: 2px; background: var(--accent); }
.notes li.warn::before { background: var(--warn); }
.notes li.bad::before { background: var(--bad); }

.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th { text-align: left; font: 600 11.5px var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.n, th.n { text-align: right; white-space: nowrap; }
td .rel { display: inline-block; margin-top: 3px; }
tr:last-child td { border-bottom: 0; }
.sweep { display: inline-flex; gap: 4px; }
.sweep span { padding: 1px 6px; border-radius: 4px; background: var(--sunken); white-space: nowrap; }
.sweep span.mid { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.start { font-weight: 600; font-size: 15px; }
.rel { font: 600 10.5px var(--f-display); letter-spacing: 0.05em; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.rel.fiber { background: var(--good-weak); color: var(--good); }
.rel.typical { background: var(--sunken); color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; width: 70px; display: inline-block; vertical-align: middle; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.dim td { color: var(--muted); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--sunken); }

.cols { display: grid; grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.cols.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.nb { display: grid; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.nb:last-child { border-bottom: 0; }
.nb .t { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.nb .t b { font-weight: 600; min-width: 0; }
.tag { font: 600 10.5px var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; white-space: nowrap; }
details > summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 14px; font-size: 12.5px; padding-top: 6px; }
.kv span b { font-family: var(--f-mono); font-weight: 500; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty h3 { color: var(--ink); }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 6px; font-size: 13px; z-index: 20; max-width: calc(100% - 32px); }
.err { color: var(--bad); }
.ok { color: var(--good); }

.method p, .method li { max-width: 70ch; }
.method ol { padding-left: 20px; display: grid; gap: 8px; margin: 0; }
.wts { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 20px; }
.wts label { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.wts input[type="range"] { grid-column: 1 / -1; }

/* buttons */
.btn.danger, .btn.danger-outline { color: var(--bad); }
.btn.danger-outline { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
textarea { font: 13.5px var(--f-body); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 9px; width: 100%; min-width: 0; resize: vertical; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.toast.bad { background: var(--bad); color: #fff; }

/* overlay sheet */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--ink) 38%, transparent); display: grid; place-items: start center; overflow-y: auto; z-index: 10; padding: 28px 16px; }
.sheet { width: min(760px, 100%); background: var(--surface); border-radius: 8px; border: 1px solid var(--line); padding: 20px; display: grid; gap: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.sheet.wide { width: min(980px, 100%); }
.sheet .foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; padding-top: 4px; border-top: 1px solid var(--line); padding-top: 12px; }
.edgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 12px; }
.edgrid .span2 { grid-column: span 2; }
input:disabled { background: var(--sunken); color: var(--muted); }

/* sign-in and users */
.login { max-width: 420px; margin: 48px auto; padding: 24px; }
.login .btn.primary { justify-content: center; padding-block: 9px; }
.usermenu { gap: 4px 8px; }
.rolechip { font: 600 10.5px var(--f-display); letter-spacing: 0.06em; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; background: var(--sunken); color: var(--muted); }
.rolechip.editor { background: var(--accent-weak); color: var(--accent); }
.rolechip.admin { background: var(--warn-weak); color: var(--warn); }
table.grid.audit td { white-space: normal; }
table.grid.audit td:last-child { min-width: 280px; }

/* database tab */
.dblayout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.dbside { padding-bottom: 8px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.tbl-btn { appearance: none; display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: none; color: var(--ink); font: 13.5px var(--f-body); padding: 7px 12px; cursor: pointer; border-left: 3px solid transparent; }
.tbl-btn:hover { background: var(--sunken); }
.tbl-btn.on { background: var(--accent-weak); border-left-color: var(--accent); }
.dbmain { min-width: 0; }
.dbgridwrap { max-height: calc(100vh - 230px); overflow: auto; border-top: 1px solid var(--line); }
table.grid { font-size: 12.5px; }
table.grid th { position: sticky; top: 0; background: var(--surface); z-index: 1; font-family: var(--f-mono); text-transform: none; letter-spacing: 0; font-weight: 500; }
table.grid th.sortable { cursor: pointer; }
table.grid td { white-space: nowrap; padding: 5px 10px; }
table.grid td.fkcell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
table.grid.dbgrid thead { position: sticky; top: 0; z-index: 2; }
table.grid.dbgrid th { position: static; }
table.grid.dbgrid tr.cfrow th { padding: 0 4px 6px; border-bottom: 1px solid var(--line); cursor: default; }
table.grid.dbgrid .cf { width: 100%; min-width: 72px; max-width: 220px; box-sizing: border-box; padding: 3px 6px; font: 12px var(--f-mono); border: 1px solid var(--line); border-radius: 6px; background: var(--bg, var(--surface)); color: var(--ink); }
table.grid.dbgrid .cf.on { border-color: var(--accent); background: var(--accent-weak); }
table.grid.dbgrid .cf:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
table.grid.dbgrid td.gridmsg { white-space: normal; padding: 18px 12px; }
#dbGrid.busy tbody { opacity: .55; transition: opacity .15s .1s; }
.chip .x { appearance: none; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 0 0 4px; line-height: 1; }

@media (max-width: 960px) {
  .dblayout { grid-template-columns: 1fr; }
  .dbside { position: static; max-height: none; }
  .cols, .cols.even { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 700px) {
  .pair { grid-template-columns: 1fr; }
  .mid { grid-auto-flow: column; justify-content: start; align-items: end; }
  .pf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .source { justify-items: start; text-align: left; }
  .source .row { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
