/* Pulse — стили. Тёмная тема по умолчанию, светлая через data-theme="light". */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #0d0d0d;            /* page plane */
  --surface: #1a1a19;       /* карточки */
  --surface-2: #232322;     /* вложенные элементы */
  --surface-3: #2c2c2a;
  --line: #2c2c2a;          /* hairline */
  --line-strong: #383835;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-soft: rgba(57,135,229,.16);
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-soft: rgba(12,163,12,.16); --warning-soft: rgba(250,178,25,.16); --serious-soft: rgba(236,131,90,.18); --critical-soft: rgba(208,59,59,.18);
  --neutral: #6b6a64;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px -18px rgba(0,0,0,.8);
  --radius: 14px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f4f1; --surface: #fcfcfb; --surface-2: #f2f2ee; --surface-3: #e9e8e2;
  --line: #e1e0d9; --line-strong: #c3c2b7;
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
  --accent: #2a78d6; --accent-soft: rgba(42,120,214,.12);
  --good: #0a8a0a; --warning: #b57a00; --serious: #c9582a; --critical: #c93434;
  --good-soft: rgba(12,163,12,.12); --warning-soft: rgba(250,178,25,.18); --serious-soft: rgba(236,131,90,.18); --critical-soft: rgba(208,59,59,.12);
  --neutral: #a8a69e;
  --shadow: 0 1px 2px rgba(11,11,11,.04), 0 8px 24px -16px rgba(11,11,11,.2);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- шапка ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: color-mix(in oklab, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -.02em; white-space: nowrap; }
.brand-sub { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); transition: background .15s, color .15s; }
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--accent)); }
.chip .n { font-size: 11px; opacity: .7; }
.chip.active .n { opacity: .8; }
.tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; height: 34px; color: var(--muted); }
.search input { background: transparent; border: 0; outline: 0; width: 160px; color: var(--text); }
.search input::placeholder { color: var(--muted); }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface-2); cursor: pointer; font-weight: 500; font-size: 13px; transition: background .15s, transform .05s; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn.busy svg { animation: spin 1s linear infinite; }
.btn.xs { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 40px; min-width: 240px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; padding: 6px; box-shadow: 0 16px 40px -12px rgba(0,0,0,.6); display: flex; flex-direction: column; z-index: 30; }
.menu-list button { text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- контент ---------- */
main { max-width: 1440px; margin: 0 auto; padding: 18px 20px 40px; }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-height: 88px; display: flex; flex-direction: column; gap: 4px; cursor: default; position: relative; overflow: hidden; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 28px; font-weight: 600; letter-spacing: -.03em; line-height: 1.1; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: 0; margin-left: 4px; }
.kpi .sub { font-size: 12px; color: var(--text-2); }
.kpi.tone-critical .value { color: var(--critical); }
.kpi.tone-serious .value { color: var(--serious); }
.kpi.tone-warning .value { color: var(--warning); }
.kpi.tone-good .value { color: var(--good); }
.kpi::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--tone, transparent); opacity: .9; }
.kpi.tone-critical { --tone: var(--critical); } .kpi.tone-serious { --tone: var(--serious); } .kpi.tone-warning { --tone: var(--warning); } .kpi.tone-good { --tone: var(--good); }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-width: 0; }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head .muted { font-size: 12px; }
.card-tools { display: flex; gap: 12px; align-items: baseline; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; font-size: 13px; }
.refreshing .card, .refreshing .kpis { opacity: .72; transition: opacity .2s; }

/* ---------- статусы ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--neutral); flex: none; }
.s-ok { --sc: var(--good); --ss: var(--good-soft); }
.s-warning { --sc: var(--warning); --ss: var(--warning-soft); }
.s-serious { --sc: var(--serious); --ss: var(--serious-soft); }
.s-critical, .s-expired, .s-down { --sc: var(--critical); --ss: var(--critical-soft); }
.s-off, .s-unknown { --sc: var(--neutral); --ss: transparent; }
.dot.s-ok, .dot.s-warning, .dot.s-serious, .dot.s-critical, .dot.s-expired, .dot.s-down, .dot.s-off, .dot.s-unknown { background: var(--sc); }
.dot.s-down, .dot.s-critical, .dot.s-expired { box-shadow: 0 0 0 3px var(--ss); }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--ss, var(--surface-3)); color: var(--sc, var(--text-2)); white-space: nowrap; line-height: 1.5; }
.badge.neutral { background: var(--surface-3); color: var(--text-2); font-weight: 500; }
.badge.src-cookie { background: var(--warning-soft); color: var(--warning); }
.badge.src-api { background: var(--accent-soft); color: var(--accent); }
.badge.src-manual, .badge.src-probe { background: var(--surface-3); color: var(--text-2); }

/* ---------- строки таймлайна ---------- */
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 22px minmax(170px, 1.7fr) minmax(150px, 1.4fr) minmax(110px, 1fr) 92px 96px 90px 30px; align-items: center; gap: 10px; padding: 9px 6px; border-top: 1px solid var(--line); min-height: 46px; border-radius: 8px; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row .name { font-weight: 500; display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .name .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name .k { color: var(--muted); font-size: 13px; flex: none; }
.row .sub { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .days { font-weight: 600; text-align: right; color: var(--sc, var(--text)); font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .days .auto { display: block; font-size: 10.5px; font-weight: 500; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.row .date, .row .cost { color: var(--text-2); font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .act { display: flex; justify-content: flex-end; }
.row .act button { opacity: 0; }
.row:hover .act button, .row:focus-within .act button { opacity: 1; }
.row.dim { opacity: .55; }
.bar { height: 6px; border-radius: 4px; background: var(--surface-3); position: relative; overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--sc, var(--accent)); min-width: 4px; }
.bar.expired > i { width: 100% !important; background: repeating-linear-gradient(135deg, var(--critical) 0 6px, transparent 6px 10px); opacity: .7; }
.flag { font-size: 14px; line-height: 1; }
.group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 6px 4px; }

/* ---------- балансы ---------- */
.bal { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 4px; border-top: 1px solid var(--line); }
.bal:first-child { border-top: 0; }
.bal .name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.bal .amount { font-size: 22px; font-weight: 600; letter-spacing: -.02em; grid-column: 1; }
.bal .amount small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 6px; letter-spacing: 0; }
.bal .fc { text-align: right; align-self: end; font-size: 12.5px; color: var(--text-2); }
.bal .fc b { display: block; font-size: 15px; color: var(--sc, var(--text)); font-weight: 600; }
.bal .spark { grid-column: 1 / -1; height: 40px; margin-top: 2px; }
.bal .deps { grid-column: 1 / -1; font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.bal .deps span { background: var(--surface-2); border-radius: 6px; padding: 1px 7px; }
.spark svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* ---------- ноды ---------- */
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.node { background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 10px 11px; display: flex; flex-direction: column; gap: 6px; min-height: 84px; }
.node .head { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; min-width: 0; }
.node .head .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .ip { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.node .stat { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-top: auto; }
.node .stat b { color: var(--text); font-weight: 600; }
.node.s-down { border-color: var(--critical); background: var(--critical-soft); }
.node.s-off { opacity: .55; }
.svc { display: flex; align-items: center; gap: 10px; padding: 10px 4px 2px; font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--line); margin-top: 10px; }
.svc b { color: var(--text); }

/* ---------- аптайм ---------- */
.up { display: grid; grid-template-columns: minmax(110px, 160px) 1fr 58px; gap: 12px; align-items: center; padding: 9px 4px; border-top: 1px solid var(--line); }
.up:first-child { border-top: 0; }
.up .name { font-weight: 500; display: flex; align-items: center; gap: 8px; min-width: 0; }
.up .name .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up .name small { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.up .pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.up .pct small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.bars { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; height: 22px; }
.bars i { border-radius: 3px; background: var(--surface-3); display: block; }
.bars i.ok { background: var(--good); opacity: .8; }
.bars i.part { background: var(--warning); }
.bars i.bad { background: var(--critical); }

/* ---------- источники ---------- */
.src { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; padding: 9px 4px; border-top: 1px solid var(--line); }
.src:first-child { border-top: 0; }
.src .name { font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.src .info { grid-column: 2; color: var(--muted); font-size: 12px; }
.src .err { grid-column: 2 / -1; color: var(--serious); font-size: 12px; background: var(--serious-soft); border-radius: 8px; padding: 6px 9px; margin-top: 2px; }
.src .err.auth { color: var(--warning); background: var(--warning-soft); }
.src .act { display: flex; gap: 6px; }

/* ---------- журнал ---------- */
.ev { display: grid; grid-template-columns: 9px 1fr auto; gap: 10px; align-items: start; padding: 7px 4px; border-top: 1px solid var(--line); font-size: 13px; }
.ev:first-child { border-top: 0; }
.ev .dot { margin-top: 5px; }
.ev .ts { color: var(--muted); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev .tg { color: var(--accent); margin-left: 6px; }
.foot { margin-top: 18px; color: var(--muted); font-size: 12px; display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }

/* ---------- диалоги ---------- */
dialog { border: 1px solid var(--line-strong); border-radius: 16px; background: var(--surface); color: var(--text); padding: 0; width: min(680px, calc(100vw - 24px)); box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); }
dialog.wide-dialog { width: min(1200px, calc(100vw - 24px)); padding: 16px 18px; }
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
.form { padding: 16px 18px 14px; }
.form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 12px; margin-top: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text-2); font-weight: 400; font-size: 13px; grid-column: span 3; }
.form-grid input:not([type=checkbox]), .form-grid select, .form-grid textarea { height: 36px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); padding: 0 10px; color: var(--text); outline: 0; }
.form-grid textarea { height: auto; padding: 8px 10px; resize: vertical; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid input:disabled, .form-grid select:disabled { opacity: .5; }
.form-foot { display: flex; gap: 8px; align-items: center; margin-top: 14px; }
.grow { flex: 1; }
.proj-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.proj { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 8px; align-items: center; }
.proj input[type=color] { width: 34px; height: 34px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.proj input[type=text], #projNewName { height: 34px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); padding: 0 10px; color: var(--text); outline: 0; min-width: 0; }
#projNewName { flex: 1; }
.proj .cnt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.table-wrap { overflow: auto; max-height: 75vh; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500; z-index: 50; box-shadow: 0 10px 30px -10px rgba(0,0,0,.6); max-width: 90vw; }

/* ---------- адаптив ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span-4, .span-5, .span-7, .span-8 { grid-column: span 12; }
  .row { grid-template-columns: 22px minmax(150px, 1.7fr) minmax(120px, 1.3fr) minmax(90px, 1fr) 88px 92px 30px; }
  .row .cost { display: none; }
}
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand-sub, .btn span, .search { display: none; }
  .chips { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tools { margin-left: auto; }
  main { padding: 12px 12px 32px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi .value { font-size: 24px; }
  .row { grid-template-columns: 18px 1fr 64px 26px; grid-template-areas: "d n days act" ". sub sub sub" ". bar bar date"; gap: 4px 8px; padding: 10px 4px; }
  .row .dot { grid-area: d; } .row .name { grid-area: n; } .row .sub { grid-area: sub; } .row .bar { grid-area: bar; } .row .days { grid-area: days; } .row .date { grid-area: date; } .row .act { grid-area: act; } .row .cost { display: none; }
  .row .act button { opacity: 1; }
  .row .days { font-size: 13px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid label.check { grid-column: span 2; }
  .up { grid-template-columns: 1fr auto; gap: 6px 10px; }
  .up .bars { grid-column: 1 / -1; height: 18px; }
  .up .pct small { display: inline; margin-left: 4px; }
  .nodes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
