/* The desktop Волна CPS as Windows 11 draws it: the same palette (Themes/Light.xaml, Dark.xaml), sizes and spacing */
:root {
  --bg: #F3F3F3; --sidebar: #EBEBEB; --surface: #FFFFFF; --surface2: #F9F9F9; --field: #FFFFFF;
  --ink: #1B1B1B; --muted: #5D5D5D; --line: #E3E3E3; --line-strong: #CFCFCF;
  --accent: #0078D4; --accent-hover: #106EBE; --accent-soft: #EDEDED; --on-accent: #FFFFFF; --nav: #E0E0E0;
  --ok: #1E7A4C; --danger: #B42318; --danger-soft: #F7DEDA; --warn: #8A5A00; --warn-soft: #F6EBCF;
  --hover: rgba(0, 0, 0, .04); --selection: #99C9EE; --selection-ink: #1B1B1B;
  --btn: #FBFBFB; --btn-hover: #F6F6F6; --btn-edge: rgba(0, 0, 0, .06); --btn-bottom: rgba(0, 0, 0, .16);
  --field-bottom: #868686;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202020; --sidebar: #1B1B1B; --surface: #2B2B2B; --surface2: #323232; --field: #2D2D2D;
    --ink: #FFFFFF; --muted: #C2C2C2; --line: #3A3A3A; --line-strong: #4A4A4A;
    --accent: #0078D4; --accent-hover: #1A86D9; --accent-soft: #383838; --on-accent: #FFFFFF; --nav: #353535;
    --ok: #5CC98F; --danger: #F07167; --danger-soft: #3A2321; --warn: #E8B44C; --warn-soft: #362D1A;
    --hover: rgba(255, 255, 255, .06); --selection: #115990; --selection-ink: #FFFFFF;
    --btn: #2D2D2D; --btn-hover: #323232; --btn-edge: rgba(255, 255, 255, .07); --btn-bottom: rgba(255, 255, 255, .05);
    --field-bottom: #9A9A9A;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.43 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 26px; font-weight: 600; margin: 0; line-height: 1.25; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.hidden-file { display: none; }

/* ---- shell */
.shell { display: grid; grid-template-columns: 224px 1fr; grid-template-rows: 1fr auto; height: 100vh; height: 100dvh; }
.sidebar {
  grid-row: 1 / 3; background: var(--sidebar); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; min-height: 0;
}
.brand { padding: 0 0 18px 6px; }
.brand-name { display: flex; align-items: center; font-size: 15px; }
.brand-name .mark { display: inline-flex; margin-right: 10px; }
.brand-name b { font-weight: 600; }
.chip { display: flex; align-items: center; gap: 8px; margin: 10px 0 0 1px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.nav { flex: 1; overflow-y: auto; min-height: 0; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; margin: 1px 0;
  padding: 10px 12px 10px 14px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--nav); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 2px; background: var(--accent);
}
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-caption { font-size: 12px; color: var(--muted); margin: 18px 0 6px 14px; }
.side-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }
.file-row { display: flex; gap: 2px; }
.file-row .btn { padding: 10px 6px; }
.page { overflow: auto; min-width: 0; min-height: 0; }
.status {
  grid-column: 2; display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 10px 28px; border-top: 1px solid var(--line); background: var(--bg); font-size: 13px; color: var(--muted);
}
.status progress { width: 220px; flex: none; accent-color: var(--accent); }

/* ---- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 32px;
  padding: 5px 12px; border: 1px solid var(--btn-edge); border-bottom-color: var(--btn-bottom); border-radius: 4px;
  background: var(--btn); color: var(--ink); cursor: pointer; white-space: nowrap; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:active:not(:disabled) { opacity: .8; }
.btn:disabled { color: var(--muted); opacity: .6; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.primary:disabled { background: var(--surface2); border-color: var(--line); color: var(--muted); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--hover); }
.btn.wide { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.icon-btn { padding: 5px 8px; min-width: 36px; }

.field {
  width: 100%; min-height: 32px; padding: 5px 11px; background: var(--field); color: var(--ink);
  border: 1px solid var(--line); border-bottom-color: var(--field-bottom); border-radius: 4px; outline: none;
}
.field:focus { border-bottom: 2px solid var(--accent); padding-bottom: 4px; }
.field:disabled { opacity: .6; }
.field.invalid { border-color: var(--danger); }
select.field { padding-right: 28px; }
.label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.label.first { margin-top: 12px; }
.label.gap { margin-top: 14px; }
.caption { font-size: 12px; color: var(--muted); margin: 0; }
.caption.body { font-size: 14px; }
.caption.top { margin-top: 6px; }
.problem { font-size: 12px; color: var(--danger); margin: 4px 0 0; }
.radios { display: flex; gap: 24px; }
.radios label, .check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check { margin: 4px 0; }
input[type=radio], input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }

/* ---- pages */
.page-pad { padding: 26px 28px 28px; }
.page-pad.narrow { max-width: 744px; }
.page-pad.fill { height: 100%; display: flex; flex-direction: column; padding-bottom: 22px; }
.lead { color: var(--muted); margin: 6px 0 0; max-width: 720px; }
.lead.wide { max-width: 900px; margin-bottom: 16px; }
.big { font-size: 20px; font-weight: 600; }
.radio-card { display: flex; gap: 20px; align-items: flex-start; margin-top: 24px; padding: 24px; }
.radio-badge {
  width: 64px; height: 64px; border-radius: 14px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex: none;
}
.radio-card .caption { margin-top: 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.facts { list-style: none; margin: 0; padding: 0; color: var(--muted); line-height: 24px; }

/* ---- channels */
.channels { flex: 1; min-height: 0; display: grid; grid-template-columns: 160px minmax(260px, 1fr) 300px; gap: 12px; }
.networks { padding: 8px; display: flex; flex-direction: column; min-height: 0; }
.netlist { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.netlist li { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-radius: 4px; cursor: pointer; }
.netlist li:hover { background: var(--hover); }
.netlist li.selected { background: var(--selection); color: var(--selection-ink); }
.net-icon { width: 16px; height: 16px; display: inline-flex; color: var(--muted); flex: none; }
.net-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-size: 12px; color: var(--muted); }
.net-actions { display: flex; flex-direction: column; gap: 6px; padding: 8px 4px 4px; }
.net-actions .pair { gap: 6px; }
.middle { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.net-card { margin-bottom: 12px; }
.net-fields { display: flex; gap: 10px; align-items: flex-end; }
.net-fields .grow { flex: 1; }
.net-fields .label { margin-top: 0; }
.net-id { width: 110px; }
.net-fields .icon-btn { min-height: 32px; padding: 5px 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.menu-anchor { position: relative; }
.menu-scrim { position: fixed; inset: 0; z-index: 9; }
.menu {
  position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; min-width: 260px; list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 16px rgba(0, 0, 0, .14);
}
.menu li { padding: 8px 12px; border-radius: 4px; cursor: pointer; }
.menu li:hover { background: var(--hover); }
.search { position: relative; margin-bottom: 8px; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .field { padding-left: 32px; }
.table-wrap { flex: 1; min-height: 120px; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; outline: none; }
.table-wrap:focus-visible { border-color: var(--accent); }
.grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 600;
  padding: 6px 4px; border-bottom: 1px solid var(--line-strong); border-right: 1px solid var(--line);
}
.grid td { padding: 6px 4px; height: 33px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid tbody tr { cursor: default; }
.grid tbody tr:hover { background: var(--hover); }
.grid tbody tr.selected { background: var(--accent); color: var(--on-accent); }
.w-mode { width: 60px; }
.w-mhz { width: 84px; }
.w-name { width: 30%; }
.editor { padding: 0; min-height: 0; display: flex; }
.editor-scroll { overflow-y: auto; padding: 8px 20px 20px; width: 100%; }
.empty { margin: auto; padding: 24px; text-align: center; }

/* ---- dialogs */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .3); display: grid; place-items: center; padding: 16px; }
.dialog {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 16px 32px rgba(0, 0, 0, .24); padding: 24px;
}
.dialog-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-icon { display: inline-flex; color: var(--accent); }
.dialog-icon.warning { color: var(--warn); }
.dialog-icon.error { color: var(--danger); }
.dialog-text { white-space: pre-line; margin: 0 0 16px; }
.dialog-list { margin-bottom: 16px; }
.dialog-list summary { cursor: pointer; font-weight: 600; }
.dialog-list-body { white-space: pre-line; margin-top: 8px; color: var(--muted); max-height: 240px; overflow: auto; }
.dialog-buttons { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-buttons .btn { min-width: 110px; }
.picker { width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; height: min(520px, 100%); }
.picker h2 { margin: 0; }
.pick-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.pick-list li { display: flex; gap: 12px; padding: 6px 10px; cursor: pointer; }
.pick-list li .muted { margin-left: auto; }
.pick-list li:hover { background: var(--hover); }
.pick-list li.selected { background: var(--selection); color: var(--selection-ink); }

/* ---- narrow screens: a phone or a small tablet */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; }
  .sidebar, .page, .status { min-width: 0; }
  .sidebar { grid-row: 1; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
  .brand { padding: 0 0 8px 4px; display: flex; justify-content: space-between; align-items: center; }
  .chip { margin: 0; }
  .nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav-item { width: auto; flex: none; padding: 8px 12px; }
  .nav-item.active::before { left: 12px; right: 12px; top: auto; bottom: 2px; width: auto; height: 3px; }
  .nav-caption { display: none; }
  .side-actions { flex-direction: row; flex-wrap: wrap; }
  .side-actions .btn.wide { width: auto; flex: 1; }
  .status { grid-column: 1; padding: 8px 16px; }
  .page-pad { padding: 16px; }
  .page-pad.fill { height: auto; }
  .two { grid-template-columns: 1fr; }
  .channels { grid-template-columns: minmax(0, 1fr); }
  .net-fields { flex-wrap: wrap; }
  .net-fields .grow { flex-basis: 100%; }
  .networks { max-height: 220px; }
  .table-wrap { min-height: 300px; }
  .w-name { width: 40%; }
}

.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
#blazor-error-ui { position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; padding: 12px 20px; background: var(--warn-soft); color: var(--ink); }
#blazor-error-ui[hidden] { display: none; }
#blazor-error-ui .reload { color: var(--accent); margin-left: 8px; }

/* ---- table pages: contacts, book, keys */
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }
.toolbar-card { display: flex; justify-content: space-between; gap: 8px; padding: 12px 14px 6px; margin-bottom: 14px; }
.toolbar.wrap { flex-wrap: wrap; align-items: center; gap: 0 8px; margin: 0; }
.toolbar.wrap > * { margin-bottom: 6px; }
.inline-label { margin: 0 0 6px 8px; }
.field.fixed { width: 210px; }
.fixed-search { width: 220px; flex: none; margin: 0 0 6px; }
.grid.edit td { padding: 2px 4px; height: 37px; }
.grid td.num { padding-left: 8px; color: var(--muted); }
.grid tbody tr.selected td.num { color: var(--on-accent); }
.cell {
  width: 100%; min-height: 30px; padding: 4px 6px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--ink); outline: none;
}
.cell:hover { border-color: var(--line); }
.cell:focus { border-color: var(--accent); background: var(--field); }
.cell.invalid { border-color: var(--danger); }
.grid tbody tr.selected .cell { color: var(--on-accent); }
.grid tbody tr.selected .cell:focus { color: var(--ink); }
.grid tbody tr.selected select.cell option { color: var(--ink); }

/* ---- group tree */
.tree-page { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; }
.tree-col { display: flex; flex-direction: column; min-height: 0; }
.tree { flex: 1; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 4px; outline: none; }
.node { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 4px; cursor: default; }
.node:hover { background: var(--hover); }
.node.selected { background: var(--selection); color: var(--selection-ink); }
.node.leaf { padding-left: 52px; }
.node-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node b { font-weight: 600; }
.twisty { display: inline-flex; color: var(--muted); cursor: pointer; }
.accent-icon { display: inline-flex; color: var(--accent); }
.count { margin-left: 16px; }
.side { display: flex; flex-direction: column; min-height: 0; padding: 16px 18px; overflow: auto; }
.side-title { margin: 22px 0 4px; }
.new-group { display: grid; grid-template-columns: 100px 1fr; gap: 8px; }
.top8 { margin-top: 8px; }
.pick-list.grow { flex: 1; min-height: 160px; margin-top: 10px; }
.two-line { flex-direction: column; gap: 0 !important; }
.two-line .muted { margin-left: 0 !important; }
.small { font-size: 12px; }
.pick-list li.selected .muted { color: inherit; }
@media (max-width: 900px) {
  .tree-page { grid-template-columns: minmax(0, 1fr); }
  .tree { min-height: 260px; }
}
.field.fixed.wider { width: 230px; }
label.btn.disabled { opacity: .6; pointer-events: none; }

/* ---- keys */
.keys-page { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 640px) 300px; gap: 24px; align-items: start; }
.table-wrap.keys { max-height: 100%; }
.grid td.ink { color: var(--ink); }
.hints p + p { margin-top: 12px; }
.tall { line-height: 22px; }
@media (max-width: 900px) { .keys-page { grid-template-columns: minmax(0, 1fr); } }

/* ---- settings */
.settings-page { height: 100%; display: flex; flex-direction: column; }
.settings-head { padding: 26px 28px 18px; margin: 0; }
.settings-body { flex: 1; overflow: auto; padding: 0 28px 30px; }
.setting-card { max-width: 760px; margin-bottom: 16px; padding: 16px 20px 8px; }
.setting { display: flex; align-items: center; gap: 24px; min-height: 52px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting-text { flex: 1; }
.setting-text .caption { margin-top: 2px; }
.field.choice { width: 240px; }
.number { display: flex; align-items: center; gap: 6px; }
.number .field { width: 76px; text-align: center; }
.btn.step { width: 38px; padding: 0; }
.unit { width: 56px; margin-left: 4px; font-size: 13px; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; border-radius: 11px; background: var(--line-strong); transition: background .15s; }
.switch .track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 900px) {
  .settings-head { padding: 16px; }
  .settings-body { padding: 0 16px 16px; }
  .setting { flex-wrap: wrap; gap: 8px 16px; }
}

/* ---- calibration */
.warn-card { display: flex; gap: 16px; margin: 14px 0; }
.warn-icon { color: var(--warn); display: inline-flex; flex: none; margin-top: 2px; }
.warn-card .caption { margin: 0; }
.cal-page { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 620px) 300px; gap: 20px; align-items: start; margin-top: 4px; }
.table-wrap.cal { max-height: 100%; }
.cal-grid td.cell-selected { background: var(--accent); }
.cal-grid td.cell-selected .cell { color: var(--on-accent); }
.cal-side { display: flex; flex-direction: column; gap: 14px; }
.cal-side .card { display: flex; flex-direction: column; align-items: flex-start; }
.first-label { margin: 0 0 6px; }
.sel-value { margin: 4px 0 10px; font-size: 13px; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.steps .btn { min-width: 48px; }
h2.tight { margin-bottom: 6px; }
.osc-note { font-size: 13px; margin-bottom: 10px; }
.top6 { margin-top: 6px; }
@media (max-width: 900px) { .cal-page { grid-template-columns: minmax(0, 1fr); } }

/* ---- firmware */
.top24 { margin-top: 24px; }
.top16 { margin-top: 16px; }
.small13 { font-size: 13px; }
.with-icon { display: flex; gap: 16px; }
.ok-icon { color: var(--ok); display: inline-flex; flex: none; margin-top: 2px; }
.action-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
a.btn { text-decoration: none; }
.changes { color: var(--muted); line-height: 22px; }
.changes .heading { color: var(--ink); font-weight: 600; }
.changes .gap { height: 12px; }
.tree { background: transparent; border: 0; padding: 0; }
.tree .node-name { flex: 0 1 auto; }
.tree .count { margin-left: 16px; }
.node { position: relative; }
.node.selected { background: var(--tree-sel); color: var(--ink); }
.node.selected::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 2px; background: var(--accent); }
:root { --tree-sel: rgba(0, 0, 0, .06); }
@media (prefers-color-scheme: dark) { :root { --tree-sel: rgba(255, 255, 255, .08); } }
