:root {
  --bg: #07090c;
  --surface: #0e1218;
  --surface-2: #141a23;
  --surface-3: #1a2230;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #e9eef4;
  --text-2: #c3ccd8;
  --muted: #8592a3;
  --gold-1: #fff1c2;
  --gold-2: #f2c35b;
  --gold-3: #b07a22;
  --gold-ink: #2a1d04;
  --accent: #34d399;
  --accent-2: #22d3ee;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 16px;
  --display: "Unbounded", "Manrope", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14.5px/1.55 "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { background: radial-gradient(50% 30% at 85% -5%, rgba(242, 195, 91, 0.07), transparent 70%), var(--bg); background-attachment: fixed; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; text-wrap: balance; }
h2 { font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: -0.02em; margin: 0; }
h3 { font-size: 15px; font-weight: 700; letter-spacing: 0.01em; }
p, li, td { text-wrap: pretty; }
[hidden] { display: none !important; }
::selection { background: rgba(242, 195, 91, 0.35); }

.i { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }

.muted { color: var(--muted); }
.error { color: var(--bad); }
.ok { color: var(--accent); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* Карточки и сетки */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.section { margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { color: var(--muted); margin: 6px 0 0; max-width: 70ch; }

/* Плитки показателей */
.kpi { position: relative; overflow: hidden; display: grid; gap: 2px; align-content: start; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .label .i { width: 30px; height: 30px; padding: 7px; border-radius: 10px; background: rgba(34, 211, 238, 0.08); color: var(--accent-2); }
.kpi .value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 10px; line-height: 1.15; }
.kpi .delta { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.kpi .delta .i { width: 14px; height: 14px; }
.kpi.gold { background: linear-gradient(150deg, #241b0a, var(--surface) 60%); border-color: rgba(242, 195, 91, 0.22); }
.kpi.gold .label .i { background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 50%, var(--gold-3)); color: var(--gold-ink); }
.up { color: var(--accent); }
.down { color: var(--bad); }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text); border-radius: 10px;
  padding: 9px 15px; font: inherit; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s, transform .15s;
}
.btn:hover { border-color: rgba(242, 195, 91, 0.5); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn .i { width: 16px; height: 16px; }
.btn.primary {
  color: var(--gold-ink); border: 0; font-weight: 700;
  background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 45%, #d9a03c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 6px 18px rgba(242, 195, 91, 0.18);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.3); }
.btn.danger:hover { background: rgba(248, 113, 113, 0.08); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn.icon-only { padding: 7px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Поля */
input, textarea, select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line-2); border-radius: 10px;
  padding: 10px 12px; font: inherit; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold-2); box-shadow: 0 0 0 3px rgba(242, 195, 91, 0.15); }
label { display: block; color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 14px; }
label > input, label > textarea, label > select { margin-top: 6px; font-weight: 500; }
.check { display: flex; gap: 10px; align-items: center; color: var(--text-2); font-size: 14.5px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--gold-2); margin: 0; }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); }
.seg button { background: transparent; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface-3); color: var(--gold-2); box-shadow: inset 0 0 0 1px rgba(242, 195, 91, 0.25); }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--text); }
th.sort .i { width: 12px; height: 12px; color: var(--gold-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: rgba(255, 255, 255, 0.025); }
.thumb { width: 42px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--surface-3); display: block; border: 1px solid var(--line); }
.title-cell { min-width: 220px; max-width: 340px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Графики и полосы */
.chart-box { position: relative; height: 270px; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 190px 1fr 70px; gap: 12px; align-items: center; font-size: 14px; }
.bar-row > div { background: rgba(255, 255, 255, 0.03); border-radius: 7px; }
.bar { height: 24px; border-radius: 7px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); min-width: 2px; }
.heat { display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; }
.heat div { aspect-ratio: 1; border-radius: 6px; background: var(--surface-2); font-size: 10px; font-weight: 700; display: grid; place-items: center; color: var(--muted); }
.heat-labels { display: grid; grid-template-columns: repeat(24, 1fr); gap: 4px; font-size: 10px; color: var(--muted); text-align: center; margin-top: 6px; }

/* Комментарии и черновики */
.comment { display: grid; grid-template-columns: 48px 1fr; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.comment:first-child { padding-top: 0; }
.comment:last-child { border-bottom: 0; padding-bottom: 0; }
.comment .who { font-weight: 700; }
.comment .replies { margin: 10px 0 0; padding: 8px 0 0 12px; border-left: 2px solid rgba(242, 195, 91, 0.35); font-size: 14px; color: var(--text-2); display: grid; gap: 4px; }
.comment .actions { margin-top: 10px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.tag.green { color: var(--accent); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.06); }
.tag.red { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.06); }
.tag.gold { color: var(--gold-2); border-color: rgba(242, 195, 91, 0.35); background: rgba(242, 195, 91, 0.06); }

/* Директ */
.direct { display: grid; grid-template-columns: 300px 1fr; gap: 12px; min-height: 540px; }
.threads { overflow-y: auto; max-height: 72vh; padding: 6px; }
.thread-item { padding: 12px; border-radius: 12px; cursor: pointer; }
.thread-item + .thread-item { margin-top: 2px; }
.thread-item:hover { background: var(--surface-2); }
.thread-item.on { background: var(--surface-3); box-shadow: inset 2px 0 0 var(--gold-2); }
.chat { display: flex; flex-direction: column; }
.msgs { flex: 1; overflow-y: auto; max-height: 60vh; display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.msg { max-width: 75%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg.in { background: var(--surface-3); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.out { background: linear-gradient(160deg, #11352b, #0f2c2f); align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Каркас: боковое меню */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.nav { background: rgba(14, 18, 24, 0.7); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 1px; position: sticky; top: 0; height: 100vh; overflow-y: auto; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 800; }
.brand small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: var(--gold-ink); background: linear-gradient(160deg, var(--gold-1), var(--gold-2) 45%, var(--gold-3)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 6px 18px rgba(242, 195, 91, 0.2); }
.brand-mark .i { width: 20px; height: 20px; }
.nav-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #5e6a7a; padding: 16px 10px 6px; }
.nav a, .nav-logout { display: flex; align-items: center; gap: 11px; color: var(--muted); padding: 8px 10px; border-radius: 10px; font-weight: 600; text-decoration: none; position: relative; }
.nav a:hover, .nav-logout:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.on { color: var(--text); background: var(--surface-3); }
.nav a.on .i { color: var(--gold-2); }
.nav a.on::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold-2); }
.nav-count { margin-left: auto; font-size: 11px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; display: grid; place-items: center; background: var(--gold-2); color: var(--gold-ink); }
.nav-logout { margin-top: auto; border: 0; background: none; font: inherit; font-weight: 600; cursor: pointer; width: 100%; }
.main { padding: 28px 32px 48px; max-width: 1320px; width: 100%; min-width: 0; }

/* Вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(40% 40% at 50% 40%, rgba(242, 195, 91, 0.08), transparent 70%), var(--bg); }
.login-card { width: 100%; max-width: 300px; display: grid; gap: 10px; }
.login-card input { padding: 13px 14px; background: var(--surface); }
.login-card.fail input { border-color: var(--bad); }
.login-btn { padding: 12px; }
.login-btn .i { width: 20px; height: 20px; }

/* Окно и уведомления */
.modal { position: fixed; inset: 0; background: rgba(3, 5, 8, 0.72); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { width: 100%; max-width: 780px; max-height: 90vh; overflow-y: auto; position: relative; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); }
.modal-close { position: absolute; top: 14px; right: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.modal-close:hover { color: var(--text); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-3); border: 1px solid rgba(242, 195, 91, 0.3); padding: 11px 18px; border-radius: 12px; z-index: 20; max-width: calc(100% - 32px); font-weight: 600; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); }

.empty { color: var(--muted); padding: 28px; text-align: center; }
.log-detail { color: var(--muted); font-size: 13px; word-break: break-word; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { position: sticky; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); z-index: 5; gap: 2px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .brand, .nav-group { display: none; }
  .nav a, .nav-logout { white-space: nowrap; flex: none; width: auto; padding: 8px 11px; }
  .nav a.on::before { display: none; }
  .nav-logout { margin: 0 0 0 auto; }
  .main { padding: 18px 16px 40px; }
  .two { grid-template-columns: 1fr; }
  .direct { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 56px; }
  .heat div { font-size: 0; }
  .kpi .value { font-size: 26px; }
}
