/* SPDX-License-Identifier: GPL-3.0-or-later */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #1c232b;
  --strong: #1c232b;
  --muted: #555e68;
  --dim: #858d96;
  --border: #e1e5ea;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --accent-soft: #e6f0fb;
  --err: #b00020;
  --err-soft: #fdecee;
  --warn: #9a5800;
  --warn-soft: #fff4e2;
  --ok: #1a7f37;
  --dynamic: #0066cc;
  --tx: #22863a;
  --rx: #0366d6;
  --rxtx: #6f42c1;
  --internal: #6e7781;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 52px;
  --status-h: 30px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1115;
    --surface: #161a20;
    --surface-2: #1b2027;
    --text: #e4e7eb;
    --strong: #eef0f2;
    --muted: #b4bbc3;
    --dim: #8b939c;
    --border: #2a3038;
    --accent: #4ea1ff;
    --accent-text: #08121e;
    --accent-soft: #15283d;
    --err: #ff6b6b;
    --err-soft: #3a1a1d;
    --warn: #ffc78a;
    --warn-soft: #3a2a14;
    --ok: #56d364;
    --dynamic: #7cc4ff;
    --tx: #7ee787;
    --rx: #79c0ff;
    --rxtx: #d2a8ff;
    --internal: #a8a8a8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  min-height: 100vh;
  padding-bottom: var(--status-h);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { line-height: 1.25; margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.strong { color: var(--strong); font-weight: 600; }
.small { font-size: 12.5px; }
.err { color: var(--err); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.ok { color: var(--ok); }
.italic { font-style: italic; font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- buttons & inputs --------------------------------------------------- */
.btn {
  font: inherit; font-weight: 550;
  padding: 6px 12px; min-height: 32px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--dim); opacity: 1; }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { padding: 10px 18px; font-size: 15px; }
.btn.attention:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .nav-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

input[type=text], input[type=number], input[type=password], select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; min-height: 32px;
  max-width: 100%;
}
input[type=number] { width: 9.5em; font-family: var(--mono); }
input[type=text], input[type=password] { width: 14em; }
select { max-width: 100%; width: 22em; }
input:disabled, select:disabled { opacity: .55; }
input.invalid, select.invalid, .editor.invalid { border-color: var(--err); background: var(--err-soft); }
input.warn { border-color: var(--warn); background: var(--warn-soft); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; vertical-align: -3px; }
textarea { width: 100%; resize: vertical; line-height: 1.4; }

/* --- top bar -------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { color: var(--accent); display: inline-flex; }
.brand-name { font-weight: 700; }
.brand-version { color: var(--dim); font-size: 12px; }
.doc { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.doc-name { font-family: var(--mono); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unsaved-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.actions { display: flex; gap: 6px; }

/* --- layout --------------------------------------------------------------- */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h) - var(--status-h)); }
.layout:has(.sidebar[hidden]) { grid-template-columns: minmax(0, 1fr); }
.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h) - var(--status-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 8px 24px;
}
.nav-select-wrap { display: none; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-group { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--dim); padding: 14px 10px 4px; min-height: 8px; }
.nav-item {
  font: inherit; text-align: left;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--text);
  padding: 6px 10px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.dirty::after { content: " \2022"; color: var(--warn); font-weight: 700; }
.main { min-width: 0; padding: 20px 24px 40px; }

/* --- pages ---------------------------------------------------------------- */
.page { max-width: 1400px; }
.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 20px; margin-bottom: 4px; }
.page-head p { margin: 2px 0; }
.raw { font-size: 12.5px; word-break: break-all; }
.page-foot {
  position: sticky; bottom: var(--status-h); z-index: 5;
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 14px; padding: 10px 0;
  background: linear-gradient(transparent, var(--bg) 35%);
}

.rows { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 1.05fr) minmax(180px, 1.9fr) minmax(90px, .85fr) minmax(80px, .8fr) minmax(130px, 1.2fr);
  gap: 4px 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.row.head {
  position: sticky; top: var(--topbar-h); z-index: 4;
  border-top: 0; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface-2);
  font-weight: 650; color: var(--strong); font-size: 12.5px;
  padding-top: 8px; padding-bottom: 8px;
}
.cell { min-width: 0; overflow-wrap: anywhere; }
.cell.name { font-weight: 650; color: var(--strong); }
.cell.range, .cell.default { font-size: 13px; }
.cell.note { font-size: 13px; }
.editor { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.vfile { font-family: var(--mono); font-size: 12.5px; }
.flow { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.computed { font-family: var(--mono); font-weight: 700; color: var(--dynamic); }
.desc { grid-column: 1 / -1; max-width: 820px; color: var(--muted); font-size: 13px; }
.desc b { color: var(--strong); }
.desc [style*="#c00"] { color: var(--err) !important; }
.dynamic { color: var(--dynamic); }
.badge { font-family: var(--mono); font-weight: 700; font-size: 12px; }
.badge.tx { color: var(--tx); } .badge.rx { color: var(--rx); } .badge.rxtx { color: var(--rxtx); } .badge.internal { color: var(--internal); }
.row.dep-disabled .cell.name, .row.dep-disabled .cell.current, .row.dep-disabled .cell.range,
.row.dep-disabled .cell.default, .row.dep-disabled .desc { color: var(--dim); }
.row.dep-disabled .desc b { color: var(--dim); }
.extra { padding: 10px 14px; border-top: 1px solid var(--border); }
.extra ul { margin: 4px 0 0; }

/* --- summary ---------------------------------------------------------------- */
.field-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
.name-input { font-family: var(--mono); font-weight: 600; width: 16em !important; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 20px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.notes-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.notes { font-size: 13px; }
.preview {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin: 0; font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-all;
}

/* --- welcome ---------------------------------------------------------------- */
.welcome { max-width: 680px; margin: 7vh auto 0; }
.welcome h1 { font-size: 28px; margin-bottom: 10px; }
.welcome .lead { font-size: 16px; color: var(--muted); margin: 0 0 24px; }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.drop-hint { margin: 10px 0 28px; }
.points { padding: 0; list-style: none; display: grid; gap: 10px; margin: 0 0 24px; }
.points li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }

/* --- status bar, drop overlay, dialogs ------------------------------------- */
.statusbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: var(--status-h);
  display: flex; align-items: center;
  padding: 0 16px;
  background: var(--surface); border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
.status { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.err { color: var(--err); } .status.warn { color: var(--warn); font-weight: 600; } .status.ok { color: var(--ok); }
.drop-overlay {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 3px dashed var(--accent);
  align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--accent);
  pointer-events: none;
}
.dragging .drop-overlay { display: flex; }
.modal {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
  padding: 20px 22px; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(10, 14, 20, .5); }
.modal h2 { font-size: 17px; margin-bottom: 10px; }
.modal-body p { margin: 0 0 10px; }
.modal .big { font-size: 18px; font-weight: 700; padding: 6px 10px; background: var(--surface-2); border-radius: 6px; word-break: break-all; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* --- narrow screens ----------------------------------------------------------- */
@media (max-width: 1100px) {
  .row { grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(170px, 1.6fr) minmax(110px, 1fr); }
  .row.head .cell:nth-child(5), .row.head .cell:nth-child(6) { display: none; }
  .cell.default::before, .cell.note:not(:empty)::before { content: attr(data-label) ": "; color: var(--dim); font-size: 12px; }
  .cell.name, .cell.current, .cell.editor { grid-row: span 2; }
  .cell.default { grid-column: 4; }
  .cell.note { grid-column: 1 / -1; }
  .cell.note:empty { display: none; }
}
@media (max-width: 820px) {
  :root { --topbar-h: 96px; }
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding: 8px 16px; gap: 6px 12px; align-content: center; }
  .doc { order: 3; flex-basis: 100%; }
  .actions { margin-left: auto; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: var(--topbar-h); z-index: 10; height: auto; overflow: visible; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 16px; }
  .nav { display: none; }
  .nav-select-wrap { display: block; }
  .nav-select-wrap select { width: 100%; }
  .main { padding: 16px 16px 40px; }
  .row.head { display: none; }
  .row { grid-template-columns: 1fr 1fr; padding: 12px; }
  .cell.name, .cell.current, .cell.editor { grid-row: auto; }
  .cell.name, .cell.editor, .cell.note, .desc { grid-column: 1 / -1; }
  .cell.current, .cell.range, .cell.default { grid-column: auto; }
  .cell.current::before, .cell.range::before, .cell.default::before, .cell.note:not(:empty)::before {
    content: attr(data-label); display: block; color: var(--dim); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  }
  .cell.current { order: 3; } .cell.editor { order: 2; } .cell.range { order: 4; } .cell.default { order: 5; } .cell.note { order: 6; } .desc { order: 7; }
  input[type=text], input[type=password], select { width: 100%; }
  .brand-version { display: none; }
}
@media (max-width: 420px) {
  .actions .btn { padding: 6px 9px; }
  #btn-about { display: none; }
}
