:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #d9dee5;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0f7;
  --err: #b42318;
  --err-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff6db;
  --ok: #1a7f37;
  --ok-soft: #e7f5ec;
  --radius: 8px;
  --input-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --card: #1a2028;
    --text: #e4e8ee;
    --muted: #98a2b3;
    --line: #2f3946;
    --accent: #5aa3d6;
    --accent-ink: #0d1117;
    --accent-soft: #1d3346;
    --err: #ff8a80;
    --err-soft: #3a1f1f;
    --warn: #f2c14e;
    --warn-soft: #362d14;
    --ok: #6fcf8a;
    --ok-soft: #173224;
    --input-bg: #11161d;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

/* шапка */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in { display: flex; align-items: center; gap: 16px; padding-top: 12px; padding-bottom: 8px; flex-wrap: wrap; }
.brand-title { font-size: 18px; font-weight: 650; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding-top: 16px; padding-bottom: 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }
h3 { font-size: 15px; margin: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.head-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.head-row h2 { margin: 0; }
.line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0; }
.line.end { justify-content: flex-end; }

/* поля */
.grid { display: grid; gap: 10px 14px; margin-bottom: 8px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: 180px 180px minmax(0, 1fr); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span { font-size: 12.5px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input-bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }
input.bad, select.bad { border-color: var(--err); background: var(--err-soft); }
input.warnf { border-color: var(--warn); background: var(--warn-soft); }
button.bad { outline: 2px solid var(--err); }
.w-auto { width: 240px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin: 4px 0; }
.with-btn { display: flex; gap: 6px; }

/* кнопки */
.btn, .btn-link, .btn-mini, .icon-btn { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
.btn-link:hover { text-decoration: underline; }
.danger { color: var(--err) !important; }
.btn-mini { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 2px 10px; font-size: 12.5px; }
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 4px 8px; border-radius: 4px; }
.icon-btn:hover { color: var(--err); background: var(--err-soft); }
.file-btn { position: relative; }

/* протоколы */
.protocol { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.org-line { display: flex; align-items: center; gap: 8px; min-height: 33px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); border-radius: 99px; padding: 3px 4px 3px 10px; font-size: 12.5px; max-width: 100%; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 6px; }
.chip button:hover { color: var(--err); }
.prog-picker { position: relative; max-width: 640px; }
.prog-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 10; max-height: 320px; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
}
.prog-opt { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--text); padding: 7px 10px; cursor: pointer; font: inherit; font-size: 13px; border-bottom: 1px solid var(--line); }
.prog-opt:hover, .prog-opt:focus { background: var(--accent-soft); }
.prog-empty { padding: 8px 10px; color: var(--muted); }
.quick { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0 8px; font-size: 12.5px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }

/* таблицы */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 6px; }
.grid-table { border-collapse: collapse; width: 100%; min-width: 900px; }
.grid-table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); background: var(--bg); padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table td { padding: 3px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table input { padding: 5px 6px; }
.grid-table td.num { color: var(--muted); text-align: right; width: 36px; padding-top: 9px; }
.grid-table td.c { text-align: center; padding-top: 9px; width: 50px; }
.grid-table .idcell { min-width: 150px; }
.grid-table .idcell input + input { margin-top: 3px; }
.grid-table.compact { min-width: 0; }
.grid-table.compact td { padding: 5px 6px; font-size: 13px; }
.map-table { min-width: 640px; }
.map-table td { padding: 5px 6px; }
.map-table td:first-child { white-space: nowrap; font-weight: 500; }
.sample { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.map-top { margin-top: 8px; }

/* импорт */
.import-box > summary { list-style: none; }
.import-box > summary::-webkit-details-marker { display: none; }
.import-box[open] { flex-basis: 100%; order: 10; }
.import-box[open] > summary { margin-bottom: 8px; }
.import-panel { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; background: var(--bg); }

/* панель действий */
.actionbar {
  position: sticky; bottom: 0; z-index: 15; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
}
.counts { font-size: 13px; color: var(--muted); }
.counts b { color: var(--text); }

/* ошибки */
.issues { margin-top: 12px; }
.issue-head { margin-bottom: 6px; }
.tag { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.tag.err { color: var(--err); background: var(--err-soft); }
.tag.warn { color: var(--warn); background: var(--warn-soft); }
.tag.ok { color: var(--ok); background: var(--ok-soft); }
.issue-list { list-style: none; margin: 8px 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--card); max-height: 420px; overflow: auto; }
.issue-list li { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.issue-list li:last-child { border-bottom: 0; }
.issue-list li.err { border-left: 3px solid var(--err); }
.issue-list li.warn { border-left: 3px solid var(--warn); }
.issue-list li[data-issue] { cursor: pointer; }
.issue-list li[data-issue]:hover { background: var(--bg); }
.go { color: var(--accent); white-space: nowrap; }
.ok-box, .bad-box, .warn-box { padding: 10px 14px; border-radius: 6px; }
.ok-box { background: var(--ok-soft); color: var(--ok); }
.bad-box { background: var(--err-soft); color: var(--err); }
.warn-box { background: var(--warn-soft); color: var(--warn); }

/* проверка XML */
.drop {
  display: flex; align-items: center; justify-content: center; min-height: 120px; border: 2px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); cursor: pointer; text-align: center; padding: 16px;
}
.drop.over, .drop:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }

/* справка */
.prose { max-width: 960px; }
.prose li { margin-bottom: 6px; }
.prose h3 { margin: 18px 0 8px; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* диалог и уведомления */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 0; width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
.dlg { padding: 16px; }
.dlg h3 { margin-bottom: 6px; }
.dlg textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--err); color: #fff; }

@media (max-width: 760px) {
  .top { position: static; }
  .actionbar { padding: 8px 10px; gap: 6px; }
  .actionbar .counts { flex-basis: 100%; }
  .actionbar .spacer { display: none; }
  .actionbar .btn { padding: 6px 10px; }
  .chip { text-align: left; }
}

@media print {
  .top, .actionbar, .row-actions, .import-box { display: none !important; }
}
