/* Общие стили: переменные темы, элементы управления, диалоги */
:root {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f7f8fa; --text: #161b26; --muted: #5a6475; --border: #dde2ea;
  --accent: #1d4ed8; --accent-hover: #1a43bd; --on-accent: #ffffff; --accent-soft: #e7eeff;
  --danger: #c62828; --danger-soft: #fdecec; --warn: #8f5f00; --warn-soft: #fff4d4; --ok: #1a7a3c; --ok-soft: #e4f5e9;
  --bubble: #e7eeff; --shadow: 0 8px 28px rgba(16, 24, 40, .14); --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b24; --surface-2: #1d222d; --text: #e7eaf0; --muted: #98a2b4; --border: #2b3241;
  --accent: #6b98ff; --accent-hover: #86abff; --on-accent: #0b1120; --accent-soft: #1a2848;
  --danger: #ff7b72; --danger-soft: #3b1c1c; --warn: #e3b341; --warn-soft: #382d10; --ok: #56d364; --ok-soft: #14301c;
  --bubble: #1a2848; --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { width: 18px; height: 18px; flex: none; display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; text-decoration: none;
  color: var(--text); white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border); }
.btn.sm { min-height: 30px; padding: 3px 9px; font-size: 13px; }
.btn.icon-only { padding: 6px; min-width: 36px; }
.btn.sm.icon-only { padding: 4px; min-width: 30px; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input, select.input, textarea.input { width: 100%; min-height: 36px; padding: 6px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; }
textarea.input { resize: vertical; min-height: 72px; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.mono { font-family: var(--mono); font-size: 13px; }
label.field { display: block; }
label.field > span, .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
label.field > small, .help { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; font-weight: 400; }
label.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
label.check input { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  width: min(680px, 94vw); max-height: 92vh; padding: 0; box-shadow: var(--shadow); }
dialog.wide { width: min(1000px, 96vw); }
dialog::backdrop { background: rgba(10, 14, 22, .5); }
dialog > form, dialog > .dlg { display: flex; flex-direction: column; max-height: 92vh; }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: 17px; flex: 1; }
.dlg-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border);
  flex-wrap: wrap; }
.dlg-foot .left { margin-right: auto; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.alert.error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.alert.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

#toasts { position: fixed; top: 62px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column;
  gap: 8px; align-items: center; width: max-content; max-width: min(520px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: var(--shadow);
  font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }

.menu { position: fixed; z-index: 900; min-width: 190px; padding: 4px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); }
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: 0; background: none;
  border-radius: 6px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr:hover td { background: var(--surface-2); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.empty-note { padding: 28px 16px; text-align: center; color: var(--muted); }

/* вход */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 21px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 30px; height: 30px; }
