:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --text: #16181d;
  --muted: #5f6673;
  --line: #e1e4ea;
  --accent: #2f55d4;
  --accent-ink: #ffffff;
  --accent-soft: #e8edfc;
  --ok: #1e7a4c;
  --ok-soft: #e4f4ec;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --code-bg: #eef0f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --line: #2a2f3a;
    --accent: #7d9bff;
    --accent-ink: #0d1020;
    --accent-soft: #1f2842;
    --ok: #5fd39a;
    --ok-soft: #15302a;
    --bad: #ff8a80;
    --bad-soft: #3a1d1c;
    --warn: #f3c669;
    --warn-soft: #362b12;
    --code-bg: #232833;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 17px; margin: 0 0 12px; }
h4 { font-size: 14px; margin: 18px 0 8px; color: var(--muted); font-weight: 600; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono, code, pre, textarea#iid-input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- раскладка ---------- */
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.page { max-width: 880px; margin: 0 auto; padding: 20px 16px 40px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.foot { text-align: center; padding: 0 16px 24px; }

/* ---------- шапка ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { max-width: 880px; margin: 0 auto; padding: 12px 16px 6px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-lg { font-size: 22px; margin-bottom: 8px; }
.mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: var(--accent) url("/static/favicon.svg") center / 100% no-repeat;
}
.top-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 4px 8px; border-radius: 8px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); }
.menu summary:hover { background: var(--surface-2); }
.menu-pop { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; min-width: 170px; }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 8px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.menu-pop button:hover { background: var(--surface-2); }

.tabs { max-width: 880px; margin: 0 auto; padding: 0 12px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 10px 10px 9px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- формы ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label > input, label > select { margin-top: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; margin-bottom: 10px; display: block; }
#iid-input { font-size: 15px; letter-spacing: .3px; }
.search { width: 180px; padding: 7px 10px; }
.form-error { color: var(--bad); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.loading::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.file-btn { cursor: pointer; margin: 0; font-size: 15px; color: var(--text); }

/* ---------- IID: группы ---------- */
.groups { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; min-height: 0; }
.groups:empty { margin: 0; }
.grp { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 3px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.grp.ok { background: var(--ok-soft); color: var(--ok); }
.grp.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.drag-over { outline: 2px dashed var(--accent); outline-offset: 4px; }

/* ---------- результаты ---------- */
.result { border-left: 4px solid var(--accent); }
.result.ok { border-left-color: var(--ok); }
.result.bad { border-left-color: var(--bad); }
.result.warn { border-left-color: var(--warn); }
.rich { white-space: pre-wrap; word-wrap: break-word; }
.rich code, .kv code, .copyable {
  background: var(--code-bg); padding: 1px 6px; border-radius: 5px; font-size: 13.5px;
  cursor: pointer; word-break: break-all;
}
.rich code:hover, .copyable:hover { outline: 1px solid var(--accent); }
.guide summary { cursor: pointer; font-weight: 600; }
.guide[open] summary { margin-bottom: 12px; }

.cid-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.cid-big {
  font: 600 19px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px;
  background: var(--code-bg); border-radius: 10px; padding: 12px 14px; word-break: break-all; cursor: pointer;
}
.cid-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.cid-cell { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; text-align: center; }
.cid-cell:hover { border-color: var(--accent); }
.cid-cell b { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.cid-cell span { font: 600 15px ui-monospace, SFMono-Regular, Menlo, monospace; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; margin: 6px 0 12px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.note { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin-top: 10px; }

.drop {
  display: flex; align-items: center; justify-content: center; text-align: center;
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 22px; margin-bottom: 10px;
  cursor: pointer; color: var(--muted); font-size: 14px;
}
.drop:hover, .drop.drag-over { border-color: var(--accent); color: var(--accent); outline: none; }
.downloads { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* ---------- таблицы и списки ---------- */
.table-wrap { overflow-x: auto; margin: 10px -20px -20px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 20px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 20px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.off td { opacity: .5; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.own { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.hist { display: grid; grid-template-columns: 108px 1fr; gap: 4px 14px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.hist:last-child { border-bottom: 0; }
.hist .when { color: var(--muted); font-size: 13px; }
.hist .what { min-width: 0; }
.hist .inp { color: var(--muted); font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .lbl { color: var(--muted); font-size: 13px; }
.tile .val { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile .val.low { color: var(--warn); }
.tile .val.zero { color: var(--bad); }
.tile button { margin-top: 6px; }

/* ---------- диалоги ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 12, 18, .45); }
.dlg { padding: 22px; }
.wide-dlg { width: min(640px, calc(100vw - 32px)); }
dialog:has(.wide-dlg) { width: min(640px, calc(100vw - 32px)); }
.cred { background: var(--code-bg); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; font-size: 14px; margin: 0 0 16px; user-select: all; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 14px; margin: 4px 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.inline-form { display: flex; gap: 6px; }
.inline-form input { width: 90px; padding: 6px 10px; }
.scroll { max-height: 280px; overflow-y: auto; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.login-card .btn { margin: 4px 0 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 50; max-width: calc(100vw - 32px);
}

@media (max-width: 640px) {
  .page { padding: 14px 16px 32px; }
  .card { padding: 16px; }
  .table-wrap { margin: 10px -16px -16px; }
  .table th, .table td { padding: 8px 12px; }
  .cid-grid { grid-template-columns: repeat(2, 1fr); }
  .cid-big { font-size: 16px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
  .search { width: 120px; }
  .hist { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv dd { margin-bottom: 8px; }
  #balance-pill { display: none; }
}
