:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #222;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --text-dim: #888;
  --accent: #6c63ff;
  --accent-dim: #3d3866;
  --hot: #ff6b6b;
  --ok: #4caf72;
  --warn: #f5a623;
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  min-height: 100vh;
  overscroll-behavior: none;
}

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 12px;
  z-index: 200;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.topbar-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
}

/* ─── Burger button ──────────────────────────────────────── */
.burger-btn {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 4px;
  border-radius: 10px;
}

.burger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .25s, opacity .2s, width .2s;
  transform-origin: center;
}

/* Анимация → крест */
.burger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.burger-btn.open span:nth-child(2) { opacity: 0; width: 0; }
.burger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ─── Overlay ────────────────────────────────────────────── */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(2px);
  z-index: 290;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.menu-overlay.open { opacity: 1; pointer-events: all; }

/* ─── Side menu ──────────────────────────────────────────── */
.side-menu {
  position: fixed;
  top: 0; right: 0;
  width: min(280px, 85vw);
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 300;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  overflow-y: auto;
}
.side-menu.open { transform: translateX(0); }

.side-menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.side-menu-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.side-menu-name { font-size: 15px; font-weight: 700; }
.side-menu-sub  { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.close-btn {
  margin-left: auto;
  background: var(--surface2);
  border: none;
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}

.side-menu-links {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.side-menu-links li { margin-bottom: 4px; }

.side-menu-links a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 12px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.side-menu-links a span { font-size: 20px; width: 24px; text-align: center; }
.side-menu-links a:hover,
.side-menu-links a.active {
  background: var(--accent-dim);
  color: var(--text);
}
.side-menu-links a.active { color: #a09fff; font-weight: 600; }

/* ─── Page content ───────────────────────────────────────── */
.page-content {
  padding: calc(var(--topbar-h) + var(--safe-top) + 16px) 16px 32px;
  max-width: 600px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.subtitle { color: var(--text-dim); font-size: 13px; }

/* ─── Card ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}
.card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ─── Stats ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat-item { text-align: center; }
.stat-val { font-size: 22px; font-weight: 700; }
.stat-val.accent { color: var(--accent); }
.stat-val.hot { color: var(--hot); }
.stat-key { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.stat-footer { font-size: 12px; color: var(--text-dim); margin-top: 8px; }

/* ─── Insight ────────────────────────────────────────────── */
.insight-text { font-size: 14px; line-height: 1.6; }

/* ─── Services ───────────────────────────────────────────── */
.services-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.service-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.service-row .ms  { color: var(--text-dim); font-size: 11px; }
.service-row .err { color: var(--hot); font-size: 11px; }

/* ─── Badge ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  background: var(--hot);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 6px;
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  cursor: pointer;
  flex: 1;
}
.btn-primary:active, .btn-secondary:active { opacity: .8; }
.action-row { display: flex; gap: 8px; margin-top: 8px; }

/* ─── Mode tabs ──────────────────────────────────────────── */
.mode-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab {
  flex: 1;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  text-align: center;
}
.tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }

/* ─── Agent chips ────────────────────────────────────────── */
.agent-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
}
.chip.active { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }

/* ─── Chat ───────────────────────────────────────────────── */
.chat-window {
  height: calc(100dvh - 340px);
  min-height: 200px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { max-width: 90%; }
.msg.user      { align-self: flex-end; }
.msg.agent     { align-self: flex-start; }
.msg.synthesis { align-self: flex-start; border-left: 3px solid var(--accent); }
.msg-label { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.msg-body {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg.user .msg-body      { background: var(--accent); color: #fff; }
.msg.agent .msg-body     { background: var(--surface2); }
.msg.synthesis .msg-body { background: var(--accent-dim); }
.msg.thinking .msg-body  { color: var(--text-dim); font-style: italic; }

.chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  resize: none;
  font-family: inherit;
}
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  font-size: 18px;
  cursor: pointer;
}

.board-hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px;
  background: var(--surface2);
  border-radius: 10px;
  margin-top: 8px;
}

/* ─── Alerts ─────────────────────────────────────────────── */
.alert-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}
.alert-row.active   { border-color: var(--hot); }
.alert-row.resolved { opacity: .6; }
.alert-target { font-weight: 600; margin-bottom: 4px; }
.alert-msg  { font-size: 13px; color: var(--text-dim); }
.alert-time { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ─── Reports ────────────────────────────────────────────── */
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}
.report-meta { font-size: 11px; color: var(--text-dim); margin-bottom: 8px; }
.report-body { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
