/* ============================================================
   TBOT — десктопный веб-клиент (локальная сеть).
   Отдельный интерфейс: боковая навигация, широкие таблицы,
   плотная компоновка. Тёмная тема, индиго-акцент.
   ============================================================ */
:root {
  --bg: #0b0d12;
  --bg-2: #0f121a;
  --panel: #141824;
  --panel-2: #1a1f2e;
  --panel-3: #232a3d;
  --line: rgba(255,255,255,.07);
  --line-2: rgba(255,255,255,.13);
  --tx-1: #eef1f7;
  --tx-2: #a7adc0;
  --tx-3: #6b7186;
  --brand: #6c5ce7;
  --brand-2: #8b7bef;
  --brand-soft: rgba(108,92,231,.15);
  --ok: #2fbf71;
  --warn: #f2a33c;
  --crit: #ff5a5a;
  --info: #4c8dff;
  --up: #34d399;
  --down: #f87171;
  --flat: #9aa0af;
  --r: 12px;
  --r-s: 9px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:#eceef3; --bg-2:#f3f4f8; --panel:#fff; --panel-2:#f4f5f9; --panel-3:#e7e9f0;
    --line:rgba(0,0,0,.09); --line-2:rgba(0,0,0,.16);
    --tx-1:#171922; --tx-2:#525868; --tx-3:#878da0;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--tx-1);
  font: 14px/1.5 -apple-system, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
a { color: var(--brand-2); }
button { font: inherit; color: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- боковая панель ---------- */
#sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 14px;
}
.logo { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.logo .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(145deg, var(--brand), #4c3fd0);
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 16px;
}
.logo b { display: block; letter-spacing: .14em; font-size: 14px; }
.logo span { display: block; font-size: 10.5px; color: var(--tx-3); letter-spacing: .04em; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
#nav button {
  display: flex; align-items: center; gap: 11px;
  border: 0; background: none; color: var(--tx-2);
  padding: 9px 10px; border-radius: var(--r-s); text-align: left;
  font-size: 13.5px;
}
#nav button svg { width: 17px; height: 17px; flex: 0 0 17px; stroke: currentColor; fill: none; stroke-width: 1.8; }
#nav button:hover { background: var(--panel); color: var(--tx-1); }
#nav button.on { background: var(--brand-soft); color: var(--brand-2); font-weight: 600; }
.side-foot { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.mode-chip {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 8px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line-2);
  font-size: 12.5px; font-weight: 600;
}
.mode-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 8px; }
.side-link { border: 1px solid var(--line-2); background: var(--panel); border-radius: var(--r-s); padding: 8px 12px; font-size: 12.5px; color: var(--tx-2); }
.side-link:hover { color: var(--tx-1); }

/* ---------- основная колонка ---------- */
#main { min-width: 0; display: flex; flex-direction: column; }
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
#crumb { font-size: 17px; font-weight: 700; }
#crumb small { display: block; font-size: 11.5px; font-weight: 400; color: var(--tx-3); margin-top: 1px; }
.tb-right { display: flex; align-items: center; gap: 12px; }
.health { display: flex; gap: 12px; font-size: 12px; color: var(--tx-2); }
.health .h { display: inline-flex; align-items: center; gap: 6px; }
.health .d { width: 7px; height: 7px; border-radius: 50%; background: var(--flat); }
.health .d.ok { background: var(--ok); } .health .d.warn { background: var(--warn); } .health .d.crit { background: var(--crit); }
.health .age { color: var(--tx-3); }
.health .age.stale { color: var(--warn); }
.ic-btn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--panel);
  display: grid; place-items: center; font-size: 15px; position: relative;
}
.ic-btn:hover { background: var(--panel-2); }
.ic-btn #notifDot, .ic-btn span.dot2 { position: absolute; top: -4px; right: -4px; width: 9px; height: 9px; border-radius: 50%; background: var(--crit); }
#ctxbar { padding: 0 28px; }
#ctxbar:not(:empty) { padding: 10px 28px; background: var(--brand-soft); color: var(--brand-2); font-size: 12.5px; border-bottom: 1px solid var(--line); }
#view { padding: 24px 28px 60px; max-width: 1280px; width: 100%; }

/* ---------- панели / сетка ---------- */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 1100px) { .g-3, .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } body { grid-template-columns: 200px 1fr; } }
@media (max-width: 820px) { .g-2, .g-3, .g-4 { grid-template-columns: 1fr; } }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
}
.panel > h3 {
  margin: 0 0 12px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--tx-3);
  display: flex; justify-content: space-between; align-items: center;
}
.panel > h3 a { font-size: 11.5px; text-transform: none; letter-spacing: 0; }
.panel.pad-0 { padding: 0; }
.panel.pad-0 > h3 { padding: 16px 18px 12px; margin: 0; }

/* ---------- крупные показатели ---------- */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; }
.kpi .l { font-size: 11.5px; color: var(--tx-3); }
.kpi .v { font-size: 24px; font-weight: 750; margin: 5px 0 2px; letter-spacing: -.01em; }
.kpi .s { font-size: 12px; color: var(--tx-2); }
.kpi .v.up { color: var(--up); } .kpi .v.down { color: var(--down); }

/* ---------- строки ключ/значение ---------- */
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--tx-2); }
.kv .v { text-align: right; }

/* ---------- таблицы ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--tx-3); padding: 10px 14px; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
table.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr.clickable:hover { background: var(--panel-2); cursor: pointer; }
table.tbl .r { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- пилюли ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.ok { background: rgba(47,191,113,.15); color: var(--ok); }
.pill.info { background: rgba(76,141,255,.15); color: var(--info); }
.pill.warn { background: rgba(242,163,60,.15); color: var(--warn); }
.pill.crit { background: rgba(255,90,90,.15); color: var(--crit); }
.pill.mut { background: var(--panel-3); color: var(--tx-2); }
.pill.up { background: rgba(52,211,153,.14); color: var(--up); }
.pill.down { background: rgba(248,113,113,.14); color: var(--down); }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--tx-3); }

/* ---------- полосы риска ---------- */
.bar { height: 7px; border-radius: 999px; background: var(--panel-3); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.ok > span { background: var(--ok); } .bar.warn > span { background: var(--warn); } .bar.crit > span { background: var(--crit); }
.gauge { display: flex; align-items: baseline; gap: 10px; }
.gauge .big { font-size: 40px; font-weight: 780; letter-spacing: -.02em; }

/* ---------- формы / кнопки ---------- */
.btn {
  border: 0; border-radius: var(--r-s); background: var(--brand); color: #fff;
  font-weight: 650; font-size: 13.5px; padding: 10px 16px;
}
.btn:hover { background: var(--brand-2); }
.btn.ghost { background: var(--panel-2); color: var(--tx-1); border: 1px solid var(--line-2); }
.btn.ghost:hover { background: var(--panel-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 11.5px; color: var(--tx-3); }
.inp {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--r-s);
  color: var(--tx-1); padding: 9px 12px; font: inherit; width: 100%;
}
.inp:focus { outline: none; border-color: var(--brand); }
.seg { display: inline-flex; background: var(--panel-2); border-radius: var(--r-s); padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; color: var(--tx-2); padding: 7px 14px; border-radius: 7px; font-size: 12.5px; }
.seg button.on { background: var(--panel-3); color: var(--tx-1); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { border: 1px solid var(--line-2); background: var(--panel-2); color: var(--tx-2); border-radius: 999px; padding: 6px 12px; font-size: 12px; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--tx-1); font-weight: 600; }

/* ---------- состояния ---------- */
.state { text-align: center; padding: 40px 20px; color: var(--tx-3); }
.state .em { color: var(--tx-2); font-size: 14px; }
.state.err .em { color: var(--crit); }
.skel { background: linear-gradient(90deg, var(--panel), var(--panel-2), var(--panel)); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: var(--r); height: 90px; margin-bottom: 16px; }
@keyframes sk { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ---------- чат AI ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; margin-bottom: 14px; padding-right: 4px; }
.msg { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; max-width: 78%; }
.msg.q { align-self: flex-end; background: var(--brand-soft); }
.msg.a { align-self: flex-start; background: var(--panel-2); }
.msg .f { font-size: 11px; color: var(--tx-3); margin-top: 6px; }
.fact { font-size: 12.5px; padding: 8px 0 8px 14px; position: relative; border-bottom: 1px solid var(--line); }
.fact:last-child { border-bottom: 0; }
.fact::before { content: ""; position: absolute; left: 0; top: 14px; width: 5px; height: 5px; border-radius: 50%; background: var(--brand); }

/* ---------- нижний лист ---------- */
#sheet-root .bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 50; }
#sheet-root .sheet { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r); padding: 22px; max-width: 460px; width: 90%; }
#sheet-root .sheet h4 { margin: 0 0 12px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel-3); color: var(--tx-1); padding: 11px 18px; border-radius: 10px; font-size: 13px; z-index: 60; border: 1px solid var(--line-2); }
