:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1d2638;
  --text: #e7ecf5;
  --muted: #93a0b8;
  --accent: #5b8cff;
  --ok: #3ddc97;
  --warn: #ffb020;
  --err: #ff5c6c;
  --border: #2a3550;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--accent); }

nav { display: flex; gap: 6px; flex: 1; }
nav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
}
nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
nav a.active { background: var(--panel-2); color: var(--text); }

button, .button {
  display: inline-block;
  background: var(--accent);
  color: #0b1020;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}
button:hover, .button:hover { filter: brightness(1.08); text-decoration: none; }
button.link { background: none; color: var(--muted); padding: 6px; }

main { max-width: 1180px; margin: 0 auto; padding: 28px; }
h1 { margin: 0 0 18px; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 16px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.grid > .card { margin-bottom: 0; }
.wide { grid-column: 1 / -1; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
}
.card p { margin: 8px 0; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td { font-size: 14px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
form button { margin-top: 8px; }
form { margin: 0; }

.error { background: #3a1a22; border: 1px solid var(--err); color: #ffd7dc; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
.success { background: #14352a; border: 1px solid var(--ok); color: #c9ffe8; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }

.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px; }

@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 18px; }
}


/* компании */
.companies { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 18px; }
.company { display: block; background: linear-gradient(160deg, #1b2740, #141b2b); border: 1px solid var(--border); border-radius: 16px; padding: 20px; color: var(--text); }
.company:hover { border-color: var(--accent); text-decoration: none; }
.company-top { display: flex; justify-content: space-between; align-items: center; font-size: 22px; font-weight: 700; }
.company-top .arrow { color: var(--accent); }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.metrics div { background: #111827; border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics b { font-size: 17px; }

.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); margin: 2px 4px 2px 0; }
.pill.ok { color: var(--ok); border-color: #245a45; }
.pill.bad { color: var(--err); border-color: #5a2430; }
.alerts { color: #ffd7dc; background: #3a1a22; border: 1px solid var(--err); border-radius: 10px; padding: 10px 14px 10px 30px; }
.alerts li { margin: 4px 0; }
.bad { color: var(--err); }
.org, .logs { background: #0b1020; border: 1px solid var(--border); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 12.5px; max-height: 320px; overflow: auto; }
.answer { white-space: normal; line-height: 1.6; }

select, textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit;
}
select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
form.upload { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; align-items: end; }
form.upload .check { flex-direction: row; align-items: center; gap: 8px; }
form.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 12px; }
form.filters label { min-width: 140px; }

@media (max-width: 720px) {
  .metrics { grid-template-columns: 1fr; }
}


/* чат с агентом */
h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
.chat-toggle {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 8px 16px; font-weight: 600;
}
.chat-toggle.active { background: var(--accent); color: #0b1020; }
.chat-panel {
  position: fixed; right: 22px; bottom: 22px; width: min(400px, 94vw); height: min(560px, 72vh);
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); display: flex; flex-direction: column; z-index: 100;
}
.chat-panel.hidden { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-head b { flex: 0 0 auto; }
.chat-head select { flex: 1; padding: 6px 8px; }
.chat-head button { background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 9px 11px; border-radius: 11px; white-space: pre-wrap; font-size: 14px; line-height: 1.45; max-width: 92%; }
.msg.user { background: #24345a; align-self: flex-end; }
.msg.assistant { background: #111827; border: 1px solid var(--border); align-self: flex-start; }
.msg.error { background: #3a1a22; color: #ffd7dc; align-self: flex-start; }
.chat-progress { font-size: 12px; color: var(--muted); padding: 8px 14px; max-height: 96px; overflow-y: auto; white-space: pre-wrap; border-top: 1px solid var(--border); }
.chat-progress:empty { display: none; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-form textarea { flex: 1; resize: none; max-height: 120px; }
.chat-form button { align-self: flex-end; }

/* ---------- v3: заголовки страниц, документы, здоровье ---------- */

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }

.live { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(61, 220, 151, .6); animation: pulse 2.4s infinite; }
.live.stale i { background: var(--warn); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 220, 151, .5); } 70% { box-shadow: 0 0 0 7px rgba(61, 220, 151, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 151, 0); } }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.card-head h2 { margin: 0 0 4px; }
.card-head p { margin: 0; font-size: 13px; }

.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-of-type { border-bottom: 0; }
.stat-row span { color: var(--muted); font-size: 13px; }
.stat-row b { font-size: 16px; font-variant-numeric: tabular-nums; }
.card-link { margin: 12px 0 0 !important; font-size: 13px; }
.card.accent { background: linear-gradient(160deg, #1d2c50, #171e2e); border-color: #324a7c; }

/* документы */
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.doc:last-child { border-bottom: 0; }
.doc:hover { background: rgba(91, 140, 255, .04); }
.doc-ext { flex: 0 0 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 700; letter-spacing: .4px; background: #24304a; color: #b9c7e4; }
.doc-ext.ext-pdf { background: #3a1f27; color: #ff9aa8; }
.doc-ext.ext-xls, .doc-ext.ext-csv { background: #16352a; color: #7fe3b0; }
.doc-ext.ext-doc { background: #1d2f52; color: #9db8ff; }
.doc-ext.ext-img { background: #332b16; color: #ffd479; }
.doc-body { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-name a { color: var(--text); }
.doc-name a:hover { color: var(--accent); text-decoration: none; }
.doc-meta { color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; }
.doc-act { display: flex; gap: 6px; flex: 0 0 auto; }
.chip { display: inline-block; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.ghost { background: none; color: var(--muted); }
.chip.ghost:hover { color: var(--text); }
.drive.ok { color: var(--ok); }
.drive.pending { color: var(--warn); }
.drive.bad { color: var(--err); }

.list-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.list-tools input[type="search"] { flex: 1; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.list-tools .count { color: var(--muted); font-size: 12px; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; border: 1px dashed var(--border); border-radius: 12px; }
.empty span { font-size: 24px; display: block; margin-bottom: 6px; opacity: .7; }
.empty p { margin: 0; font-size: 13px; }

.drawer { margin-top: 16px; border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: #131a29; }
.drawer.hidden { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head h3 { margin: 0; }
.drawer-head .close { background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
.drawer-open { margin-top: 12px; }
button.ghost { background: none; border: 1px solid var(--border); color: var(--text); }
button.ghost:hover { border-color: var(--accent); }

table.mini td { padding: 6px 4px; font-size: 13px; }
table.mini td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* здоровье */
.health-hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; border-radius: 16px; padding: 18px 20px; margin-bottom: 16px; border: 1px solid var(--border); background: linear-gradient(120deg, #15342a, #141b2b); }
.health-hero.warn { background: linear-gradient(120deg, #3a2517, #141b2b); border-color: #5a3a1f; }
.hero-main { display: flex; gap: 14px; align-items: center; }
.hero-main b { display: block; font-size: 18px; }
.hero-main span { color: var(--muted); font-size: 13px; }
.hero-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 6px rgba(61, 220, 151, .12); }
.health-hero.warn .hero-dot { background: var(--warn); box-shadow: 0 0 0 6px rgba(255, 176, 32, .12); }
.hero-stats { display: flex; gap: 28px; flex-wrap: wrap; }
.hero-stats div { text-align: right; }
.hero-stats span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.hero-stats b { font-size: 17px; }
.health-grid { margin-bottom: 16px; }

.svc-list { list-style: none; margin: 0; padding: 0; }
.svc-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.svc-list li:last-child { border-bottom: 0; }
.svc-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.svc-dot.ok { background: var(--ok); }
.svc-dot.bad { background: var(--err); }
.svc-list b { font-size: 13.5px; display: block; }
.svc-list em { color: var(--muted); font-size: 11.5px; font-style: normal; }

.meter { margin-bottom: 12px; }
.meter-top { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.meter-top b { color: var(--text); font-weight: 500; }
.bar { height: 7px; border-radius: 99px; background: #0b1020; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #4f7dff, #6fa4ff); }
.bar i.bad { background: linear-gradient(90deg, #ff5c6c, #ff8a5c); }

.cert { text-align: center; padding: 8px 0; }
.cert b { font-size: 44px; display: block; line-height: 1; }
.cert span { color: var(--muted); font-size: 12px; }
.cert p { margin: 8px 0 0; }

/* токены */
.tokens .card-head { margin-bottom: 8px; }
.token-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0 14px; }
.token-total { background: #111827; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.token-total span { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; display: block; }
.token-total b { font-size: 24px; display: block; margin: 3px 0 1px; }
.token-total em { color: var(--muted); font-size: 11.5px; font-style: normal; }
.token-split { display: flex; gap: 2px; height: 10px; border-radius: 99px; overflow: hidden; background: #0b1020; }
.seg { display: block; height: 100%; }
.seg.input { background: #5b8cff; }
.seg.output { background: #3ddc97; }
.seg.cache { background: #8b6cff; }
.token-legend { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 8px; }
.token-legend .dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.token-legend .dot.input { background: #5b8cff; }
.token-legend .dot.output { background: #3ddc97; }
.token-legend .dot.cache { background: #8b6cff; }
.token-bottom { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; margin-top: 18px; align-items: end; }
.token-chart { display: flex; gap: 10px; align-items: flex-end; height: 120px; padding-bottom: 18px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; }
.bar-col i { width: 100%; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #5b8cff, #2c4a8a); min-height: 3px; }
.bar-col span { position: absolute; bottom: -18px; font-size: 10.5px; color: var(--muted); }
.token-top h3 { margin: 0 0 6px; }
.tokens-table { width: 100%; }

.logs-grid { margin-top: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-bottom: 6px; }

#nav-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: linear-gradient(90deg, #5b8cff, #3ddc97); z-index: 999; transition: width .25s ease, opacity .3s; opacity: 0; }
#nav-progress.on { opacity: 1; }

@media (max-width: 820px) {
  .token-bottom { grid-template-columns: 1fr; }
  .doc { flex-wrap: wrap; }
  .doc-body { flex-basis: calc(100% - 56px); }
  .doc-act { margin-left: 56px; }
  .hero-stats div { text-align: left; }
  .page-head { flex-direction: column; gap: 6px; }
}

.hidden { display: none !important; }

.spec-banner { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.spec-banner h2 { margin: 0 0 4px; }
.spec-banner p { margin: 0; color: var(--muted); }
.health-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .health-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) { .health-grid { grid-template-columns: 1fr; } .spec-banner { flex-direction: column; align-items: flex-start; } }
