:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2229;
  --line: #262d36;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #6e7681;
  --accent: #2f81f7;
  --accent-dim: #1f6feb33;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --tg: #29a8e0;
  --mail: #d29922;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- вход ---------- */
#login {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; flex-direction: column; gap: 16px;
}
#login .card { width: 320px; }

/* ---------- каркас ---------- */
#app { display: none; grid-template-columns: 220px 1fr; min-height: 100vh; }
#app.on { display: grid; }

aside {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  font-weight: 650; font-size: 15px; letter-spacing: .2px;
  padding: 4px 10px 16px; color: var(--text);
}
.brand span { color: var(--dim); font-weight: 400; display: block; font-size: 11px; margin-top: 2px; }

nav button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; background: none; border: 0;
  padding: 8px 10px; border-radius: 8px; color: var(--muted);
  cursor: pointer; transition: .12s;
}
nav button:hover { background: var(--panel-2); color: var(--text); }
nav button.active { background: var(--accent-dim); color: var(--text); }
nav .badge {
  background: var(--accent); color: #fff; border-radius: 20px;
  padding: 0 7px; font-size: 11px; font-weight: 600; min-width: 20px; text-align: center;
}
nav .badge.zero { display: none; }

.side-foot { margin-top: auto; padding: 10px; font-size: 11px; color: var(--dim); }
.side-foot .row { display: flex; justify-content: space-between; margin-bottom: 4px; }

main { padding: 24px 28px 60px; max-width: 1180px; }
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 24px 0 10px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }

/* ---------- элементы ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.stat { padding: 14px 16px; }
.stat .n { font-size: 24px; font-weight: 600; letter-spacing: -.5px; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 2px; }

input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; font-family: inherit; }
textarea.mono { font-family: var(--mono); font-size: 13px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 5px; }
.field { margin-bottom: 12px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline label { margin: 0; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; transition: .12s; white-space: nowrap;
}
.btn:hover { border-color: var(--dim); background: #222932; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4c94f8; }
.btn.danger { color: var(--err); border-color: #5a2222; }
.btn.danger:hover { background: #2d1717; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--panel);
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: var(--panel-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 11px;
  border: 1px solid var(--line); color: var(--muted); background: var(--bg);
}
.pill.ok { color: var(--ok); border-color: #1f4429; }
.pill.warn { color: var(--warn); border-color: #4a3a15; }
.pill.err { color: var(--err); border-color: #5a2222; }
.pill.tg { color: var(--tg); border-color: #14425c; }
.pill.mail { color: var(--mail); border-color: #4a3a15; }
.pill.accent { color: var(--accent); border-color: #1c3a63; }

.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.bar { height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--warn); }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--dim); }
.dot.err { background: var(--err); }

/* ---------- модалка ---------- */
.overlay {
  position: fixed; inset: 0; background: #000a; display: none;
  align-items: flex-start; justify-content: center; padding: 40px 20px; z-index: 50;
  overflow-y: auto;
}
.overlay.on { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  width: 100%; max-width: 720px; padding: 20px;
}
.modal h3 { margin: 0 0 4px; font-size: 16px; }
.modal .close { float: right; background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: 18px; line-height: 1; }

/* ---------- инбокс ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .inbox { grid-template-columns: 1fr; } }
.thread-list { border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); max-height: 72vh; overflow-y: auto; }
.thread-item { padding: 11px 13px; border-bottom: 1px solid var(--line); cursor: pointer; }
.thread-item:hover { background: var(--panel-2); }
.thread-item.active { background: var(--accent-dim); }
.thread-item .who { font-weight: 550; display: flex; justify-content: space-between; gap: 8px; }
.thread-item .snip { color: var(--muted); font-size: 12px; margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; flex: none;
  align-self: center; }

.chat { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  display: flex; flex-direction: column; max-height: 72vh; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chat-body { padding: 14px; overflow-y: auto; flex: 1; display: flex;
  flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 12px; white-space: pre-wrap;
  word-break: break-word; font-size: 13px; }
.msg.in { background: var(--panel-2); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.out { background: #1b3a5f; align-self: flex-end; border-bottom-right-radius: 3px; }
.msg .meta { font-size: 10px; color: var(--dim); margin-top: 5px; }
.chat-foot { padding: 12px 14px; border-top: 1px solid var(--line); display: flex;
  gap: 8px; align-items: flex-end; }
.chat-foot textarea { min-height: 44px; max-height: 160px; }

/* ---------- лог ---------- */
.log { font-family: var(--mono); font-size: 12px; max-height: 340px; overflow-y: auto; }
.log div { padding: 3px 0; border-bottom: 1px solid #1b2027; display: flex; gap: 10px; }
.log .t { color: var(--dim); flex: none; }
.log .warn { color: var(--warn); }
.log .error { color: var(--err); }

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 18px;
  border-radius: 8px; display: none; z-index: 100; box-shadow: 0 8px 30px #0008;
}
#toast.err { border-color: var(--err); color: var(--err); }
#toast.on { display: block; }

.empty { padding: 40px; text-align: center; color: var(--dim); }
.hint { font-size: 12px; color: var(--dim); margin-top: 5px; line-height: 1.5; }
.warnbox { background: #2d2312; border: 1px solid #4a3a15; color: #e3b341;
  padding: 10px 12px; border-radius: 8px; font-size: 12px; margin-bottom: 14px; }
