:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2027;
  --muted: #687080;
  --border: #e2e5ea;
  --accent: #2b62e3;
  --accent-weak: #e8eefc;
  --accent-text: #ffffff;
  --danger: #c93c3c;
  --danger-weak: #fbeaea;
  --warn: #b86e00;
  --warn-weak: #fdf2df;
  --ok: #1d8a4c;
  --ok-weak: #e3f4ea;
  --chart-1: #2b62e3;
  --chart-2: #e08a1e;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --text: #e6e8ed;
    --muted: #98a1b0;
    --border: #2a2f3a;
    --accent: #5b8cff;
    --accent-weak: #1d2a47;
    --accent-text: #0f1115;
    --danger: #f07171;
    --danger-weak: #3a1d1f;
    --warn: #f0b04f;
    --warn-weak: #3a2c15;
    --ok: #4cc98a;
    --ok-weak: #15301f;
    --chart-1: #5b8cff;
    --chart-2: #f0a24f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 14px 0 6px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
[v-cloak] { display: none; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }

/* --- шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1480px; margin: 0 auto; padding: 0 16px; height: 56px;
  display: flex; align-items: center; gap: 20px;
}
.brand { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; color: var(--text); }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a {
  color: var(--muted); padding: 7px 11px; border-radius: 8px; white-space: nowrap; font-weight: 550;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; }

.page { max-width: 1480px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .row { margin-left: auto; }
.crumb { font-size: 13px; margin-bottom: 6px; display: inline-block; }

/* --- карточки и плитки --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.currency-title { font-weight: 650; margin: 4px 0 8px; color: var(--muted); }

/* --- кнопки и поля --- */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 550; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled, .btn.disabled { opacity: .55; cursor: default; pointer-events: none; }
code { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--accent); padding: 0; font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }
button.small, .btn.small { padding: 4px 9px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { padding: 0; accent-color: var(--accent); }
label.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; padding: 3px 0; }
label.check input { margin-top: 3px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 550; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; border-radius: 0; padding: 6px 10px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-weak); color: var(--accent); }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th {
  font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface);
  position: sticky; top: 0; z-index: 1; white-space: nowrap; user-select: none;
}
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
tr:last-child td { border-bottom: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td, tbody tr:hover td { background: var(--surface-2); }
tr.total td { font-weight: 650; background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
table.result { width: max-content; min-width: 100%; }
table.result td { white-space: nowrap; }
table.result td.dim { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }

/* --- метки --- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.danger { background: var(--danger-weak); color: var(--danger); }
.badge.accent { background: var(--accent-weak); color: var(--accent); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }
.text-ok { color: var(--ok); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-weak); color: var(--warn); margin-bottom: 12px; }
.alert.danger { background: var(--danger-weak); color: var(--danger); }
.alert.info { background: var(--accent-weak); color: var(--accent); }

/* --- загрузка --- */
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 24px 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- график --- */
.chart-box { position: relative; height: 280px; }

/* --- конструктор --- */
.builder { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.builder .panel { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow-y: auto; }
.picker-group { margin-bottom: 6px; }
.picker-group summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.picker-group .items { padding-left: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-weak); color: var(--accent); border-radius: 99px; padding: 2px 4px 2px 10px; font-size: 13px; font-weight: 550; }
.chip button { border: none; background: none; color: inherit; padding: 0 5px; font-size: 15px; line-height: 1; }
.filter-row { border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: grid; gap: 6px; }
.filter-row .opts { max-height: 160px; overflow-y: auto; }
.multi { position: relative; }
.multi .list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; position: sticky; bottom: -16px; background: var(--surface); padding: 12px 0 0; }

/* --- юр. данные --- */
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: min(420px, calc(100vw - 32px));
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); color: #fff; }

/* --- вход --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card form { display: grid; gap: 12px; }

@media (max-width: 960px) {
  .builder { grid-template-columns: 1fr; }
  .builder .panel { position: static; max-height: none; }
  .actions { position: static; }
}
@media (max-width: 640px) {
  .topbar-inner { gap: 6px 10px; height: auto; flex-wrap: wrap; padding: 8px 16px; }
  .nav { order: 3; width: 100%; margin: 0 -11px; }
  .brand { display: none; }
  .user .login-name { display: none; }
  .page-head .row { margin-left: 0; }
  .tile .value { font-size: 17px; }
}
