/* OpenLEO Explorer */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel2: #f0f2f5;
  --text: #1c2330;
  --muted: #677386;
  --border: #d9dee5;
  --accent: #2f7dd1;
  --accent-bg: #e3eefb;
  --warn: #b7791f;
  --warn-bg: #fdf3dc;
  --danger: #c9404a;
  --danger-bg: #fbe5e7;
  --ok: #2f9e5b;
  --ok-bg: #e2f5ea;
  --code-bg: #f3f5f8;
  --sig-l: 82%;
  --sig-s: 70%;
  --sig-text: #1c2330;
  --hatch: rgba(120, 130, 145, 0.18);
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 4px 16px rgba(20, 30, 50, .06);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 50px;
  --common: #0d7f86;
  --pair: #c56f1c;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12161c; --panel: #1a2029; --panel2: #222a35; --text: #e3e8ef; --muted: #8e9aac; --border: #2f3947;
  --accent: #5ea3ee; --accent-bg: #1d3350; --warn: #e3b34c; --warn-bg: #3a2f17; --danger: #ef6f78; --danger-bg: #3d1e22;
  --ok: #58c98a; --ok-bg: #173323; --code-bg: #151a21; --sig-l: 32%; --sig-s: 45%; --sig-text: #eef2f7; --hatch: rgba(160, 170, 185, 0.14);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --common: #4cc3c9; --pair: #f0a35a;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c; --panel: #1a2029; --panel2: #222a35; --text: #e3e8ef; --muted: #8e9aac; --border: #2f3947;
    --accent: #5ea3ee; --accent-bg: #1d3350; --warn: #e3b34c; --warn-bg: #3a2f17; --danger: #ef6f78; --danger-bg: #3d1e22;
    --ok: #58c98a; --ok-bg: #173323; --code-bg: #151a21; --sig-l: 32%; --sig-s: 45%; --sig-text: #eef2f7; --hatch: rgba(160, 170, 185, 0.14);
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --common: #4cc3c9; --pair: #f0a35a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 1.35rem; margin: .2em 0 .4em; }
h3 { font-size: 1.1rem; margin: 1.2em 0 .5em; }
h4 { margin: .6em 0 .3em; }
code, kbd, pre { font-family: var(--mono); font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: .93em; }
h2.mono { font-size: 1.35rem; }
h2 .mono, h3 .mono, h4 .mono { font-size: 1em; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.err { color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 50; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); white-space: nowrap; font-size: 15px; }
.brand:hover { text-decoration: none; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.tabs a:hover { background: var(--panel2); color: var(--text); text-decoration: none; }
.tabs a.active { background: var(--accent-bg); color: var(--accent); }
.searchbox { position: relative; flex: 1; min-width: 160px; max-width: 420px; }
.searchbox input { width: 100%; }
.search-dd { position: absolute; top: 36px; left: 0; right: 0; min-width: 360px; max-height: 70vh; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 60; }
.sr { display: grid; grid-template-columns: 56px minmax(0, auto) minmax(0, 1fr); gap: 8px; align-items: baseline; padding: 6px 10px; color: var(--text); border-bottom: 1px solid var(--border); }
.sr:hover, .sr.sel { background: var(--accent-bg); text-decoration: none; }
.sr-label { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.sr-kind { font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.sr-all { display: block; color: var(--accent); }
.topctl { display: flex; align-items: center; gap: 6px; }
.status { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; max-width: 380px; overflow: hidden; }
.iconbtn { border: 1px solid var(--border); background: var(--panel); color: var(--text); width: 30px; height: 30px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.iconbtn:hover { background: var(--panel2); text-decoration: none; }

/* ---------- forms ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]), select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; min-height: 30px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; font-family: var(--mono); font-size: 12.5px; }
.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 5px 11px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 2px 8px; font-size: 12px; min-height: 24px; }
.btn.danger { color: var(--danger); }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 1px 0; }
.lbl-block { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 3px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.seg-ctl { display: flex; gap: 8px; font-size: 12px; margin-top: 4px; flex-wrap: wrap; }
.seg-ctl label { display: flex; align-items: center; gap: 3px; }
.rawin { width: 110px; }
.physin { width: 140px; }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11px; line-height: 1.5; padding: 0 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel2); color: var(--muted); white-space: nowrap; margin-right: 3px; vertical-align: middle; }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
.src-badge { border-color: var(--c); color: var(--c); background: transparent; font-weight: 600; }
.badge-unreleased { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); font-weight: 600; }
.badge-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.badge-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.badge-ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.badge-alt { background: #f3e8ff; border-color: #9b5de5; color: #7b2cbf; }
:root[data-theme="dark"] .badge-alt { background: #2d1f45; color: #c9a7ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-alt { background: #2d1f45; color: #c9a7ff; } }
.badge-multi { border-color: var(--accent); color: var(--accent); }
.badge-link { color: var(--muted); }
.badge-bus { color: var(--text); }
.badge-period { font-family: var(--mono); }
.type-can { color: #2f7dd1; border-color: #2f7dd1; }
.type-can-tp { color: #d9822b; border-color: #d9822b; }
.type-van { color: #2fa66a; border-color: #2fa66a; }
.type-lin { color: #b04ad9; border-color: #b04ad9; }
.proto-can { color: #2f7dd1; } .proto-van { color: #2fa66a; } .proto-lin { color: #b04ad9; }
.badge-common { color: var(--common); border-color: var(--common); background: color-mix(in srgb, var(--common) 10%, transparent); font-weight: 600; }
.badge-pair { color: var(--pair); border-color: var(--pair); background: transparent; font-family: var(--mono); }
.badge-pair.guessed { border-style: dashed; }
.count { font-size: 11px; color: var(--muted); background: var(--panel2); border-radius: 8px; padding: 0 5px; }

/* ---------- generic layout ---------- */
.view { min-height: calc(100vh - var(--topbar-h)); }
.page { max-width: 1280px; margin: 0 auto; padding: 16px 20px 60px; }
.page.wide { max-width: none; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; }
.cards .card { margin: 0; }
.card h3 { margin-top: 0; }
.notice { border-left: 3px solid var(--accent); background: var(--accent-bg); padding: 6px 10px; border-radius: 4px; margin: 8px 0; }
.notice.warn { border-color: var(--warn); background: var(--warn-bg); }
.notice.danger { border-color: var(--danger); background: var(--danger-bg); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 12px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.subtabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); margin: 10px 0 12px; }
.subtabs a { padding: 6px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.subtabs a:hover { color: var(--text); text-decoration: none; }
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pills { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.pills a { border: 1px solid var(--border); border-radius: 14px; padding: 2px 12px; color: var(--muted); }
.pills a.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.tablewrap { overflow-x: auto; margin: 8px 0; }
.tbl { border-collapse: collapse; width: 100%; background: var(--panel); }
.tbl th, .tbl td { border-bottom: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel2); position: sticky; top: 0; white-space: nowrap; }
.tbl tr:hover td { background: var(--panel2); }
.tbl tr.muted td { color: var(--muted); }
.tbl tr.flagged td { background: var(--warn-bg); }
.tbl tr.inactive td { opacity: .5; }
.tbl tr.hl td { background: var(--accent-bg); }
.tbl.compact td, .tbl.compact th { padding: 3px 6px; }
.st-added td:first-child { border-left: 3px solid var(--ok); }
.st-removed td:first-child { border-left: 3px solid var(--danger); }
.st-changed td:first-child, .st-renamed td:first-child { border-left: 3px solid var(--warn); }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: hsl(var(--h) var(--sig-s) var(--sig-l)); border: 1px solid hsl(var(--h) 45% 45%); margin-right: 6px; vertical-align: -1px; }
.vals { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; }
.val code { color: var(--muted); }
.lvl-error b { color: var(--danger); }
.lvl-warning b { color: var(--warn); }
.lvl-info b { color: var(--muted); }

/* ---------- frames view ---------- */
.frames-layout { display: grid; grid-template-columns: 230px minmax(420px, 1fr) 0; grid-template-rows: minmax(0, 1fr); height: calc(100vh - var(--topbar-h)); }
.frames-layout.has-detail { grid-template-columns: 220px minmax(300px, 360px) minmax(0, 1fr); }
.sidebar { border-right: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 8px 12px 30px; }
.sidebar select, .sidebar input[type=search], .sidebar input:not([type]) { width: 100%; }
.fgroup { margin-top: 12px; }
.fgroup-h { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 3px; }
.fgroup .chk { font-size: 13px; }
.flist { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--border); background: var(--panel); }
.flist-top { display: flex; align-items: center; padding: 6px 10px; gap: 8px; border-bottom: 1px solid var(--border); }
.flist-body { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.vrow { position: absolute; left: 0; right: 0; }
.frow { display: grid; grid-template-columns: 62px minmax(120px, 1.4fr) 76px 34px 88px minmax(100px, 1.3fr) minmax(40px, auto); gap: 8px; align-items: center; height: 100%; padding: 0 10px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; white-space: nowrap; }
.frow > span { overflow: hidden; text-overflow: ellipsis; }
a.frow:hover { background: var(--panel2); text-decoration: none; }
.frow.selected { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.frow.inherited { opacity: .8; }
.frow.fhead { height: 30px; font-size: 11.5px; color: var(--muted); font-weight: 600; background: var(--panel2); cursor: default; }
.fhead .sortable { cursor: pointer; }
.fhead .sorted { color: var(--accent); }
.c-id { font-weight: 600; }
.c-bus, .c-per, .c-nodes { color: var(--muted); font-size: 12px; }
.c-badges { text-align: right; }
.has-detail .frow { grid-template-columns: 50px minmax(100px, 1fr) 64px minmax(40px, auto); }
.has-detail .frow .c-len, .has-detail .frow .c-per, .has-detail .frow .c-nodes { display: none; }
.fdetail { overflow-y: auto; background: var(--bg); min-width: 0; container-type: inline-size; }
.frames-layout:not(.has-detail) .fdetail { display: none; }
.fdetail-inner { padding: 12px 18px 60px; }
.fdetail-placeholder { padding: 40px; color: var(--muted); }
.fd-head { display: flex; gap: 14px; align-items: flex-start; }
.fd-id { font-size: 26px; font-weight: 700; color: var(--accent); background: var(--accent-bg); padding: 4px 10px; border-radius: 8px; }
.fd-title { flex: 1; min-width: 0; }
.fd-title h2 { margin: 0; font-family: var(--mono); font-size: 18px; word-break: break-all; }
.badges { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 3px; }
.close-detail { display: none; }
.fd-comment { margin: 8px 0 4px; }
.fd-obs { margin: 4px 0; color: var(--muted); }
.fd-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 6px 0; font-size: 13px; }
.srcswitch, .altbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.srcswitch .btn { border-color: var(--c); }
details.issues { margin: 8px 0; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; }
details.issues summary { cursor: pointer; }
details.issues ul { margin: 6px 0; padding-left: 18px; font-size: 12.5px; }
.pairs { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; padding: 6px 10px; background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--pair); border-radius: 6px; font-size: 13px; }
.pair { display: flex; gap: 4px 10px; align-items: baseline; flex-wrap: wrap; }
.pair > span:last-child { flex: 1; min-width: 0; }
.pair .btn { margin-left: 4px; }
.pair-k { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--pair); min-width: 52px; }
.pair-id { font-weight: 700; }
details.family { margin: 8px 0; background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--common); border-radius: 6px; padding: 5px 10px; font-size: 13px; }
details.family summary { cursor: pointer; }
.family-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 1px 14px; margin: 6px 0 2px; max-height: 260px; overflow: auto; }
.family-list a { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 1px 2px; border-radius: 3px; }
.family-list a:hover { background: var(--panel2); text-decoration: none; }
.filters-toggle { display: none; }
.muxbar { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0 10px; padding: 6px 10px; background: var(--panel); border: 1px dashed var(--border); border-radius: 6px; }

/* ---------- bit grid ---------- */
.gridpane { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: start; }
@container (min-width: 980px) { .gridpane { grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; } .gridside { position: sticky; top: 8px; max-height: calc(100vh - 120px); } }
.gridside { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13px; overflow: auto; min-height: 60px; }
.sigdetails h4 { font-family: var(--mono); margin-top: 2px; word-break: break-all; }
.valtable .vals { flex-direction: column; }
.bitgrid-wrap { overflow-x: auto; }
.bitgrid { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: 100%; min-width: 560px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; }
.bitgrid th { font-size: 11px; color: var(--muted); font-weight: 600; padding: 3px; background: var(--panel2); text-align: center; border-bottom: 1px solid var(--border); }
.bitgrid th.byte { width: 54px; text-align: center; font-family: var(--mono); border-right: 1px solid var(--border); }
.bitgrid .hexcol { width: 44px; text-align: center; color: var(--muted); }
.bitgrid td { height: 40px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0 4px; font-size: 11.5px; position: relative; overflow: hidden; }
.bitgrid.with-values td { height: 46px; }
.bitgrid td.free { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--hatch) 5px 7px); }
.bitgrid td.sig { background: hsl(var(--h) var(--sig-s) var(--sig-l)); color: var(--sig-text); cursor: pointer; box-shadow: inset 0 0 0 1px hsl(var(--h) 40% 50% / .5); }
.bitgrid td.sig.unused { background: repeating-linear-gradient(135deg, hsl(var(--h) 20% var(--sig-l) / .5) 0 5px, var(--hatch) 5px 7px); color: var(--muted); }
.bitgrid td.sig.cont { box-shadow: inset 0 0 0 1px hsl(var(--h) 40% 50% / .25); }
.bitgrid td.sig.hl { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -2px; z-index: 1; }
.bitgrid td.sig.sel { outline: 3px solid var(--accent); outline-offset: -3px; filter: saturate(1.4) brightness(.97); z-index: 2; }
.bitgrid td.sig.flagged { box-shadow: inset 0 0 0 2px var(--danger); }
.seg-in { display: flex; align-items: center; white-space: nowrap; overflow: hidden; }
.seg-name { overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-weight: 600; font-size: 11px; flex: 1; min-width: 0; text-align: center; }
.mark { position: absolute; font-size: 7.5px; line-height: 1.2; font-weight: 700; padding: 0 2px; border-radius: 2px; background: rgba(0, 0, 0, .10); letter-spacing: .02em; opacity: .8; }
.m-msb { top: 1px; left: 1px; }
.m-lsb { bottom: 1px; right: 1px; }

.bitv { display: block; text-align: center; font-family: var(--mono); letter-spacing: .6em; font-size: 12px; font-weight: 700; margin-left: .3em; }
.bitgrid tr.collapsed td { height: 26px; text-align: center; font-style: italic; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 2px 14px; margin-top: 12px; font-size: 12.5px; }
.legend-item { display: flex; align-items: baseline; gap: 5px; padding: 2px 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-item .swatch { flex: none; }
.legend-item .bits { color: var(--muted); }
.legend-item { cursor: pointer; }
.legend-item.hl { background: var(--panel2); }
.legend-item.sel { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.legend-item.sel b { color: var(--accent); }
.pinbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; margin-bottom: 2px; }
.tbl tr[data-sig] { cursor: pointer; }
.tbl tr.sel td { background: var(--accent-bg); }
.tbl tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.legend-item.unused { opacity: .6; }

/* ---------- Simple view ---------- */
.simpleview { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; overflow-x: auto; }
.awp-head { display: flex; gap: 16px; margin-bottom: 16px; }
.awp-id { font-size: 150%; font-weight: 700; }
.awp-line { display: flex; gap: 10px; }
.awp-off { color: var(--muted); width: 26px; text-align: right; padding-top: 1px; }
.awp-structure { position: relative; font-family: var(--mono); font-size: 14px; white-space: nowrap; }
.awp-bits { position: relative; white-space: pre; }
.awp-free { color: var(--muted); }
.awp-unused { color: var(--muted); opacity: .7; }
.awp-letters { background: hsl(var(--h) var(--sig-s) var(--sig-l)); border-radius: 2px; }
.awp-sig { cursor: pointer; }
.awp-sig:hover .awp-letters, .awp-sig.hl .awp-letters { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.awp-sig.sel .awp-letters { outline: 2px solid var(--accent); }
.awp-info { position: absolute; left: 3px; top: 100%; border-left: 1px dotted var(--muted); border-bottom: 1px dotted var(--muted); padding-left: 4px; white-space: nowrap; font-family: var(--sans); font-size: 12.5px; pointer-events: none; }
.awp-sig:hover .awp-info, .awp-sig.hl .awp-info, .awp-sig.sel .awp-info { border-color: var(--accent); border-style: solid; font-weight: 600; z-index: 2; }
.awp-sig.sel .awp-info { color: var(--accent); }
.awp-prose { padding-left: 0; list-style: none; margin-top: 18px; }
.awp-prose li { padding: 4px 0; border-bottom: 1px solid var(--border); }
.awp-prose li { cursor: pointer; }
.awp-prose li.hl { background: var(--panel2); }
.awp-prose li.sel { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.awp-letter { display: inline-block; min-width: 20px; text-align: center; font-family: var(--mono); font-weight: 700; background: hsl(var(--h) var(--sig-s) var(--sig-l)); border-radius: 3px; margin-right: 6px; }
.awp-values { font-size: 12.5px; color: var(--muted); margin-left: 28px; }

/* ---------- decode / encode ---------- */
.decode-grid { margin: 10px 0; }
.lbl { font-weight: 600; }
.flag { display: inline-block; font-size: 10.5px; border-radius: 8px; padding: 0 6px; margin: 1px 2px; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.flag-default { background: var(--panel2); color: var(--muted); border-color: var(--border); }
.flag-invalid, .flag-absent, .flag-truncated { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.encode { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@container (min-width: 900px) { .encode { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.enc-form { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.encrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 5px 0; border-bottom: 1px solid var(--border); align-items: center; }
.encrow > .small { text-align: right; }
.encrow .encinput { grid-column: 1 / -1; }
.encrow label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.encrow.muxsel { background: var(--accent-bg); }
.encinput { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.encinput select { max-width: 100%; }
.payload-out { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.payload-out .big { font-size: 16px; font-weight: 700; color: var(--accent); word-break: break-all; }

/* ---------- code ---------- */
.codeblock { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: 8px 0; background: var(--code-bg); }
.codeblock-bar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--border); background: var(--panel2); font-size: 12px; }
pre.code { margin: 0; padding: 10px 12px; overflow: auto; max-height: 560px; font-size: 12.5px; line-height: 1.45; }
pre { white-space: pre; }

/* ---------- alternatives / compare ---------- */
.altgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 10px; margin-bottom: 12px; }
.altcard { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.altcard.applied { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.altcard .note { font-style: italic; }
.altcard h4 { word-break: break-all; }
.cmp { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px; }

/* ---------- signals cross-reference ---------- */
.sigref-layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: calc(100vh - var(--topbar-h)); }
.sigref-list { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); border-right: 1px solid var(--border); }
.sigref-list-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); }
.sigref-list-head h2 { margin: 0; }
.sigref-list-head > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.sigref-list-head p { margin: 3px 0 8px; }
.sigref-list-head input[type=search] { width: 100%; }
.sigref-list-head .chk { margin-top: 6px; }
.sigref-cols, .sigref-row { display: grid; grid-template-columns: minmax(120px, 1fr) 86px 78px; gap: 8px; align-items: center; padding: 0 12px; }
.sigref-cols { height: 30px; background: var(--panel2); color: var(--muted); border-bottom: 1px solid var(--border); font-size: 11.5px; font-weight: 600; }
.sigref-list-body { flex: 1; min-height: 0; overflow-y: auto; position: relative; }
.sigref-row { height: 100%; color: var(--text); border-bottom: 1px solid var(--border); }
.sigref-row:hover { background: var(--panel2); text-decoration: none; }
.sigref-row.selected { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.sigref-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.sigref-count { color: var(--muted); font-size: 11.5px; white-space: nowrap; text-align: right; }
.sigref-detail { min-width: 0; overflow-y: auto; background: var(--bg); }
.sigref-detail-inner { padding: 16px 20px 60px; }
.sigref-placeholder { padding: 50px 36px; max-width: 620px; color: var(--muted); }
.sigref-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sigref-title h2 { margin: 0; color: var(--accent); word-break: break-all; }
.sigref-close { display: none; }
.sigref-arch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(520px, 100%), 1fr)); gap: 12px; align-items: start; margin-top: 14px; }
.sigref-arch.card { margin: 0; padding: 10px 12px; overflow: hidden; }
.sigref-arch h3 { display: flex; align-items: center; gap: 6px; }
.sigref-arch .tablewrap { margin-bottom: 0; }
.sigref-arch td:first-child { min-width: 210px; }

/* ---------- SVG ---------- */
.svgwrap { overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px; margin: 8px 0; }
svg text { fill: var(--text); font-family: var(--sans); }
.nbox rect { fill: var(--panel2); stroke: var(--accent); stroke-width: 1.3; }
.nbox text { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.nbox.gateway rect { fill: var(--accent-bg); stroke-width: 2; }
.nbox.phantom rect { stroke-dasharray: 4 3; stroke: var(--muted); }
.nbox.unreleased rect { stroke: var(--danger); stroke-dasharray: 5 3; }
.nbox.sender rect { fill: var(--ok-bg); stroke: var(--ok); }
.svglink:hover .nbox rect { stroke-width: 2.5; }
.svglink:hover text { text-decoration: underline; }
.busline { stroke-width: 4; stroke: var(--accent); stroke-linecap: round; }
.busline.proto-van { stroke: #2fa66a; }
.busline.proto-lin { stroke: #b04ad9; stroke-dasharray: 10 4; }
.busline.proto-k-line { stroke: #d9822b; stroke-dasharray: 3 3; }
.stub { stroke: var(--muted); stroke-width: 1.3; }
.stub.gw { stroke: var(--accent); stroke-width: 2; }
.dot { fill: var(--muted); }
.dot.gw { fill: var(--accent); }
.buslabel { font-family: var(--mono); font-weight: 700; font-size: 14px; fill: var(--accent); }
.bussub { font-size: 11.5px; fill: var(--muted); }
.fbox rect { fill: var(--accent-bg); stroke: var(--accent); stroke-width: 2; }
.fbox .fid { font-family: var(--mono); font-weight: 700; font-size: 15px; fill: var(--accent); }
.fbox .fname { font-family: var(--mono); font-size: 11.5px; }
.fbox .fsub { font-size: 10.5px; fill: var(--muted); }
.arrow { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.arrow.faint { opacity: .45; }
.ahead { fill: var(--muted); }

/* ---------- misc views ---------- */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.filterbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0 12px; }
.filterbar input[type=search] { min-width: 240px; }
.checklist li { margin: 3px 0; list-style: none; }
.checklist { padding-left: 4px; }
.checklist input { margin-right: 6px; }
.heat { display: inline-grid; grid-template-columns: repeat(8, 9px); gap: 1px; vertical-align: middle; }
.heat i { width: 9px; height: 9px; border-radius: 1px; background: var(--panel2); display: block; }
.heatbig { display: inline-grid; grid-template-columns: 40px repeat(8, 34px); gap: 2px; font-size: 11px; }
.heatbig span { text-align: center; padding: 3px 0; border-radius: 3px; font-family: var(--mono); }
tr.unknown td { background: var(--warn-bg); }
.loadbar { height: 14px; border-radius: 7px; background: var(--panel2); overflow: hidden; border: 1px solid var(--border); max-width: 520px; }
.loadbar > div { height: 100%; background: var(--ok); }
.loadbar > div.mid { background: var(--warn); }
.loadbar > div.high { background: var(--danger); }
.conv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); gap: 10px; }
.conv-grid .card { margin: 0; }
.conv-grid input { width: 100%; }
.conv-grid input[type=checkbox], .conv-grid input[type=radio] { width: auto; }
.srcrow { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border); }
.srcrow .fields { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.srcrow .fields input:not([type=checkbox]):not([type=color]) { min-width: 120px; }
.srcrow input[type=color] { width: 36px; height: 30px; padding: 1px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.srcrow .fields input.url { min-width: 320px; flex: 1; }
.about p, .about li { max-width: 860px; }
.about table { max-width: 860px; }

/* ---------- loading & toasts ---------- */
.loading { position: fixed; inset: var(--topbar-h) 0 0 0; background: color-mix(in srgb, var(--bg) 88%, transparent); z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.loading-box { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; width: min(520px, 92vw); box-shadow: var(--shadow); }
.loading-box h3 { margin-top: 0; }
.lsrc { margin: 10px 0; }
.progress { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin: 4px 0; }
.progress .bar { height: 100%; background: var(--accent); transition: width .15s; }
.progress .bar.err { background: var(--danger); }
.update-bar { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90; width: min(720px, calc(100vw - 24px)); display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 10px 14px; background: var(--panel); border: 1px solid var(--accent); border-left-width: 4px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; }
.update-bar > span:first-child { flex: 1 1 260px; min-width: 0; }
.update-actions { display: flex; gap: 6px; margin-left: auto; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 6px; }
.toast { background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .5s; }
.toast-error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  /* list and filters hidden: the detail is the only grid item */
  .frames-layout.has-detail { grid-template-columns: minmax(0, 1fr); }
  .frames-layout.has-detail .sidebar, .frames-layout.has-detail .flist { display: none; }
  .close-detail { display: inline-flex; }
  .encode { grid-template-columns: 1fr; }
  .status { display: none; }
  .sigref-layout.has-detail { grid-template-columns: minmax(0, 1fr); }
  .sigref-layout.has-detail .sigref-list { display: none; }
  .sigref-close { display: inline-flex; }
}
@media (max-width: 820px) {
  /* top bar: brand + controls, then the scrollable tabs, then the search (scrolls away with the page) */
  .topbar { position: relative; flex-wrap: wrap; height: auto; padding: 6px 10px; gap: 6px 8px; }
  .brand { order: 1; }
  .topctl { order: 2; margin-left: auto; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -10px; padding: 0 6px; -webkit-overflow-scrolling: touch; }
  .tabs a { padding: 6px 9px; }
  .searchbox { order: 4; max-width: none; flex-basis: 100%; min-width: 0; }
  .search-dd { min-width: 0; top: calc(100% + 4px); max-height: 65vh; }
  .sr { grid-template-columns: 46px minmax(0, 1fr); gap: 0 8px; }
  .sr-sub { grid-column: 2; }
  .loading { inset: 0; }
  /* 16px inputs: no zoom on focus on iOS */
  input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]), select, textarea { font-size: 16px; }
  .iconbtn { width: 34px; height: 34px; }
  .page { padding: 12px 12px 48px; }
  .two-col { grid-template-columns: 1fr; }
  .filterbar input[type=search] { min-width: 0; flex: 1 1 200px; }
  .srcrow { grid-template-columns: 22px minmax(0, 1fr); }
  .srcrow > :last-child { grid-column: 2; }
  .srcrow .fields input.url, .srcrow .fields input:not([type=checkbox]):not([type=color]) { min-width: 0; flex: 1 1 160px; }
  #toasts { left: 12px; right: 12px; bottom: 12px; }

  /* frames: filters behind a button, list with its own scroll, detail full width */
  .frames-layout, .frames-layout.has-detail { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; height: auto; }
  .filters-toggle { display: inline-flex; }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); max-height: none; padding-bottom: 14px; }
  .frames-layout.show-filters:not(.has-detail) .sidebar { display: block; }
  .flist { border-right: 0; }
  .flist-body { height: 72vh; height: calc(100dvh - 90px); min-height: 320px; }
  .frow { grid-template-columns: 44px minmax(0, 1fr) auto auto; gap: 6px; padding: 0 8px; }
  .frow .c-len, .frow .c-per, .frow .c-nodes { display: none; }
  .frow .c-bus { max-width: 72px; }
  .frow .c-badges { max-width: 38vw; }
  .frow .c-badges .badge:not(.badge-common):not(.badge-pair) { display: none; }
  .frow.fhead .c-badges { display: none; }
  /* no query container on phones: it would trap the fixed bottom sheet below */
  .fdetail { container-type: normal; }
  .fdetail-inner { padding: 10px 12px 90px; }
  .fd-head { gap: 10px; }
  .fd-id { font-size: 20px; padding: 3px 8px; }
  .fd-title h2 { font-size: 15px; }
  .close-detail { min-width: 36px; min-height: 32px; justify-content: center; }
  .fd-meta { gap: 4px 12px; }
  .subtabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 8px -12px 10px; padding: 0 8px; -webkit-overflow-scrolling: touch; }
  .subtabs::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .subtabs a { padding: 8px 10px; }

  /* bit grid fits a phone screen */
  .bitgrid { min-width: 330px; }
  .bitgrid th.byte { width: 32px; }
  .bitgrid .hexcol { width: 30px; }
  .bitgrid td { height: 36px; padding: 0 2px; font-size: 10px; }
  .bitgrid.with-values td { height: 42px; }
  .seg-name { font-size: 9.5px; }
  .mark { font-size: 6.5px; }
  .bitv { letter-spacing: .25em; font-size: 11px; margin-left: .12em; }
  .legend { font-size: 12px; }
  .legend-item { padding: 4px; }
  /* signal details: bottom sheet while a signal is selected */
  .gridside.open { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; max-height: 48vh; margin: 0; border-radius: 12px 12px 0 0; border-bottom: 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, .25); padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); }
  .gridside.open .pinbar { position: sticky; top: -10px; background: var(--panel); padding-top: 4px; }

  .simpleview { padding: 10px; }
  .awp-head { flex-wrap: wrap; gap: 8px 14px; }
  .awp-structure { font-size: 13px; }
  .awp-values { margin-left: 4px; }
  .pairs, details.family { font-size: 12.5px; }
  .pair { flex-direction: column; gap: 2px; }
  /* signals cross-reference: same behaviour as the frames list */
  .sigref-layout, .sigref-layout.has-detail { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; height: auto; }
  .sigref-layout:not(.has-detail) .sigref-detail { display: none; }
  .sigref-list { border-right: 0; }
  .sigref-list-body { height: 72vh; height: calc(100dvh - 150px); min-height: 320px; flex: none; }
  .sigref-detail-inner { padding: 12px 12px 60px; }
  pre.code { font-size: 12px; max-height: 70vh; }
}
@media (max-width: 640px) {
  /* callouts: names only, the comments are in the list below */
  .awp-info .muted { display: none; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
  .frow .c-bus { display: none; }
  .frow { grid-template-columns: 42px minmax(0, 1fr) auto; }
}
.badge-inh { border-style: dashed; }
.badge-chg { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.node-link.phantom { text-decoration: underline dotted; }
.node-link.unreleased { color: var(--danger); }
.node-link.pseudo { font-style: italic; }
* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }

/* diagnostic data of one ECU: same list / detail layout as the frames */
.diag-layout { height: calc(100vh - var(--topbar-h) - 150px); min-height: 520px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.frames-layout.has-detail.diag-layout { grid-template-columns: 210px minmax(260px, 340px) minmax(0, 1fr); }
.diag-layout .sidebar h4 { margin: 8px 0 4px; }
.diag-layout .sidebar label { display: block; margin: 6px 0; }
.diag-layout .sidebar label.chk { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.diag-layout .sidebar ul.plain { list-style: none; padding: 0; margin: 0; }
.dgroup { position: sticky; top: 0; z-index: 1; padding: 4px 10px; background: var(--panel2); border-bottom: 1px solid var(--border); font-weight: 600; font-size: 12px; }
.drow { display: grid; grid-template-columns: 40px 64px minmax(0, 1fr); gap: 6px; align-items: center; padding: 4px 10px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; white-space: nowrap; }
.drow > span { overflow: hidden; text-overflow: ellipsis; }
.drow small { margin-left: 2px; font-size: 10px; }
a.drow:hover { background: var(--panel2); text-decoration: none; }
.drow.selected { background: var(--accent-bg); box-shadow: inset 3px 0 0 var(--accent); }
.dk { font-size: 10px; text-transform: uppercase; color: var(--muted); }
.diag-layout .fdetail .card { margin-top: 10px; }
@media (max-width: 900px) {
  .frames-layout.has-detail.diag-layout { grid-template-columns: minmax(0, 1fr); height: auto; }
  .frames-layout.has-detail.diag-layout .sidebar { display: block; }
  .frames-layout.has-detail.diag-layout .flist { display: flex; max-height: 45vh; }
}
