/* KWAN.ACS — цвета как на экране тестера (вариант A): тёмно-серый фон, оранжевый акцент */
:root {
  --bg: #24272b; --panel: #373c42; --panel-2: #2e3237; --track: #1c1e21; --line: #4b5058;
  --text: #f0f0f0; --muted: #969ca2; --acc: #ff8000; --acc-ink: #1e2023;
  --green: #32d78c; --red: #ff4858; --blue: #46a0ff; --yellow: #ffc23a;
  --r: 10px; --gap: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
h2 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* шапка */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(36, 39, 43, 0.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--track); }
.brand { text-decoration: none; font-weight: 800; font-size: 18px; letter-spacing: 0.04em; }
.brand-dot, .brand-acs { color: var(--acc); }
.tabs { display: none; gap: 4px; }
.tabs a { text-decoration: none; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; }
.tabs a.on { background: var(--panel); color: var(--text); }
.tabs a:hover { color: var(--text); }
.conn { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(50, 215, 140, 0.15); }
.dot.connecting { background: var(--yellow); animation: blink 1s infinite; }
.dot.offline { background: var(--red); }
@keyframes blink { 50% { opacity: 0.35; } }
.bottom-tabs { position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  background: #1f2225; border-top: 1px solid var(--track); padding-bottom: env(safe-area-inset-bottom); }
.bottom-tabs a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 9px; text-decoration: none; font-size: 11px; color: var(--muted); }
.bottom-tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.bottom-tabs a.on { color: var(--acc); }
@media (min-width: 900px) {
  .tabs { display: flex; }
  .bottom-tabs { display: none; }
  body { padding-bottom: 24px; }
}

main { max-width: 1240px; margin: 0 auto; padding: 16px; outline: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.page-head .grow { flex: 1; }
.back { text-decoration: none; color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.back:hover { color: var(--text); }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.acc { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn.acc:hover { filter: brightness(1.08); }
.btn.red { background: transparent; border-color: rgba(255, 72, 88, 0.6); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 0 11px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .seg button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
input[type=text], input[type=password], input[type=email], input[type=datetime-local], input[type=number], select {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--track); }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.seg { display: inline-flex; background: var(--track); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; color: var(--muted); cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--panel); color: var(--text); }
.seg.acc button.on { background: var(--acc); color: var(--acc-ink); }

/* сводка */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.sum { background: var(--panel); border-radius: var(--r); padding: 10px 12px; }
.sum b { display: block; font-size: 22px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sum span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* карточки устройств */
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--panel); border-radius: var(--r); padding: 12px 14px; text-decoration: none; display: block; position: relative; border: 1px solid transparent; }
a.card:hover { border-color: var(--line); }
.card.offline { opacity: 0.72; }
.card-top { display: flex; align-items: center; gap: 8px; }
.card-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-id { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 20px; background: var(--track); white-space: nowrap; }
.status.online { color: var(--green); } .status.connecting { color: var(--yellow); } .status.offline { color: var(--muted); }
.volt { display: flex; align-items: baseline; gap: 4px; margin: 10px 0 6px; }
.volt b { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 38px; font-weight: 500; letter-spacing: -0.03em; line-height: 1; }
.volt i { font-style: normal; color: var(--acc); font-weight: 700; font-size: 18px; }
.volt.low b { color: var(--red); }
.volt.none b { color: var(--line); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }
.tag { padding: 2px 8px; border-radius: 6px; background: var(--track); color: var(--muted); font-weight: 600; }
.tag.dis { background: rgba(255, 128, 0, 0.16); color: var(--acc); }
.tag.chg { background: rgba(70, 160, 255, 0.16); color: var(--blue); }
.tag.rec { background: rgba(255, 72, 88, 0.15); color: var(--red); }
.tag.rec::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--red); margin-right: 5px; vertical-align: 1px; animation: blink 1s infinite; }
.tag.lim { background: var(--red); color: #fff; }
.meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.add-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 150px; border: 1.5px dashed var(--line); background: transparent;
  color: var(--muted); cursor: pointer; border-radius: var(--r); font-weight: 600; }
.add-card:hover { color: var(--acc); border-color: var(--acc); }
.add-card b { font-size: 28px; line-height: 1; font-weight: 400; }

/* панели и детали */
.panel { background: var(--panel); border-radius: var(--r); padding: 14px; margin-bottom: var(--gap); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-bottom: var(--gap); }
.tile { background: var(--panel); border-radius: var(--r); padding: 10px 12px; }
.tile span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.tile b { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; font-size: 20px; }
.hero { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.hero .volt { margin: 0; }
.hero .volt b { font-size: 56px; }
.chart-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head .grow { flex: 1; }
.chart { position: relative; height: 280px; }
.chart.tall { height: 340px; }
.chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px; border-bottom: 1px solid var(--panel-2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t .r { text-align: right; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.cols { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); } .cols > * { min-width: 0; }
@media (min-width: 900px) { .cols.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); } }

/* схема сборки */
.schema { display: flex; gap: 8px; align-items: stretch; overflow-x: auto; padding: 4px 0 8px; }
.grp { display: flex; flex-direction: column; gap: 4px; padding: 6px; border-radius: 8px; background: var(--track); min-width: 92px; }
.grp-h { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.cell { background: var(--panel); border-radius: 6px; padding: 5px 7px; font-size: 12px; border-left: 3px solid var(--line); }
.cell.online { border-left-color: var(--green); } .cell.connecting { border-left-color: var(--yellow); } .cell.offline { border-left-color: var(--red); }
.cell b { display: block; font-family: var(--mono); font-weight: 500; font-size: 14px; }
.plus { align-self: center; color: var(--acc); font-weight: 800; font-size: 18px; }

/* выбор устройств */
.pick { display: grid; gap: 6px; max-height: 46vh; overflow: auto; padding-right: 2px; }
.pick label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--track); cursor: pointer; }
.pick label.sel { outline: 1.5px solid var(--acc); }
.pick input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--acc); }
.pick select { width: auto; min-height: 34px; padding: 4px 8px; margin-left: auto; }
.pick .ord { margin-left: auto; font-family: var(--mono); color: var(--acc); font-weight: 700; }

/* файлы */
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--panel-2); }
.file-row:last-child { border-bottom: 0; }
.file-ic { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-size: 10px; font-weight: 800; background: var(--track); color: var(--muted); flex: none; }
.file-ic.session { color: var(--green); } .file-ic.assembly { color: var(--acc); } .file-ic.device { color: var(--blue); }
.file-main { flex: 1 1 120px; min-width: 0; overflow: hidden; }
.file-main b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code { font-family: var(--mono); font-size: 13px; background: var(--track); border-radius: 8px; padding: 10px 12px; word-break: break-all; white-space: pre-wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* диалог */
dialog { border: 0; padding: 0; border-radius: 14px; background: var(--bg); color: var(--text); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { padding: 18px; display: block; }
dialog h1 { margin-bottom: 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #111315; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: 0.2s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.login { max-width: 420px; margin: 8vh auto 0; }
.skeleton { background: linear-gradient(90deg, var(--panel) 0%, #3f454c 50%, var(--panel) 100%); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: var(--r); min-height: 150px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 520px) {
  main { padding: 12px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .hero .volt b { font-size: 46px; }
  .chart { height: 230px; } .chart.tall { height: 260px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 10px; }
  .grid .card-top { flex-direction: column-reverse; align-items: flex-start; gap: 6px; }
  .grid .card-top > div { width: 100%; }
  .grid .status { margin-left: 0; }
  .volt b { font-size: 28px; } .volt i { font-size: 14px; }
  .card .meta .hide-sm { display: none; }
  .add-card { min-height: 120px; }
}
@media (max-width: 360px) { .grid { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .grid.asm-grid { grid-template-columns: 1fr; } }
.grid > * { min-width: 0; }
.file-row.off { opacity: .55; }
.file-row .row { flex: none; }
@media (max-width: 720px) { .file-row { flex-wrap: wrap; } .file-row .row { width: 100%; padding-left: 46px; } }
