:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --surface-2: #f8f9f7;
  --border: #e3e6e1;
  --text: #1c211e;
  --muted: #6b736d;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --accent-soft: #e4f2ea;
  --warn: #a8640a;
  --warn-soft: #fbf0dc;
  --danger: #b4322b;
  --danger-soft: #fae6e4;
  --info: #2d5fa8;
  --info-soft: #e5edf9;
  --bubble-in: #ffffff;
  --bubble-out: #e4f2ea;
  --bubble-staff: #e5edf9;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 2px 8px rgba(20, 30, 25, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --surface: #1a1e1c;
    --surface-2: #202522;
    --border: #2c322f;
    --text: #e6ebe7;
    --muted: #919a94;
    --accent: #3fae78;
    --accent-ink: #0d1510;
    --accent-soft: #1d3328;
    --warn: #e0a548;
    --warn-soft: #3a2e17;
    --danger: #ef7a72;
    --danger-soft: #3d1f1d;
    --info: #7aa6ea;
    --info-soft: #1d2a3e;
    --bubble-in: #232825;
    --bubble-out: #1d3328;
    --bubble-staff: #1d2a3e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- каркас ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 228px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 16px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--text);
  font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .count { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px;
  padding: 1px 7px; font-weight: 700; }
.side .foot { margin-top: auto; padding: 10px; font-size: 13px; color: var(--muted); }
.side .foot a { color: var(--muted); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.status-dot.on { background: var(--accent); }
.status-dot.off { background: var(--danger); }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; max-width: 1180px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.head .sp { flex: 1; }
.topbar, .tabbar { display: none; }

/* ---------- карточки и сетка ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card .card-head h2 { margin: 0; }
.card .card-head .sp { flex: 1; }
.grid { display: grid; gap: 16px; align-items: start; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g21 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }

.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin: 10px 0 6px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.warn > span { background: var(--warn); }

/* ---------- кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none !important; white-space: nowrap; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
form.inline { display: inline; }
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 5px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface);
  color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.tall { min-height: 360px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; margin-bottom: 10px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }

/* ---------- таблицы и списки ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.dim td { opacity: .55; }
.list > a, .list > div { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
.list > a:hover { background: var(--surface-2); text-decoration: none; }
.list > :last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid;
  place-items: center; font-weight: 700; flex: none; font-size: 14px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.tag.green { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.blue { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot-badge { background: var(--accent); color: var(--accent-ink); border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 6px 12px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 13.5px; font-weight: 500; }
.tabs a.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs a:hover { text-decoration: none; }

.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; background: var(--accent-soft); color: var(--accent); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; font-size: 14px; }
.notice a { color: inherit; text-decoration: underline; }

/* ---------- мини-график ---------- */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 6px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: flex-end; }
.bars .stackbar { width: 100%; max-width: 38px; position: relative; border-radius: 6px 6px 3px 3px; background: var(--accent-soft); }
.bars .stackbar > span { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); border-radius: 6px 6px 3px 3px; }
.bars .lbl { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars .val { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- переписка ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; }
.chat-wrap .card { margin-bottom: 0; }
.thread { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; box-shadow: var(--shadow); }
.msg.in { align-self: flex-start; background: var(--bubble-in); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg.staff { background: var(--bubble-staff); }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { min-height: 44px; height: 44px; max-height: 160px; }
.chat-side .kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.chat-side .kv:last-child { border-bottom: 0; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 28px; }

pre.listing { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  font: 13.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin: 0; max-height: 420px; overflow: auto; }

/* ---------- телефон ---------- */
@media (max-width: 900px) {
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .side { display: none; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 5; background: var(--surface);
    border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .topbar .sp { flex: 1; }
  .topbar a { color: var(--text); }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; background: var(--surface);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted);
    padding: 4px 0; position: relative; }
  .tabbar a.on { color: var(--accent); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar svg.i { width: 22px; height: 22px; }
  .tabbar .count { position: absolute; top: 0; left: 55%; background: var(--danger); color: #fff; border-radius: 10px;
    font-size: 10px; padding: 0 5px; font-weight: 700; }
  .main { padding: 16px 16px 90px; }
  .g2, .g3, .g21 { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 20px; }
  .hide-m { display: none !important; }
  th, td { padding: 9px 10px; }
  .msg { max-width: 88%; }
  .chat-wrap { height: calc(100vh - 210px); }
  .stat .v { font-size: 24px; }
}
@media (min-width: 761px) { .show-m { display: none !important; } }
input[type=file] { font: inherit; font-size: 14px; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; padding: 7px 12px; margin-right: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
