/* ===== Базовые ===== */
* { box-sizing: border-box; }
:root {
  --bg: #0f1420;
  --panel: #161d2e;
  --panel-2: #1c2438;
  --line: #273149;
  --text: #e7ecf5;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --accent-2: #2f6fe0;
  --ok: #2fbf71;
  --err: #ef5f6b;
  --warn: #f0b429;
  --radius: 14px;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.wrap { word-break: break-all; }
.err-text { color: var(--err); }

/* ===== Кнопки ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  background: var(--panel-2); color: var(--text);
  cursor: pointer; text-decoration: none !important; transition: .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-outline { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-danger { background: rgba(239,95,107,.14); color: var(--err); border-color: rgba(239,95,107,.35); }
.btn-small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-xl { padding: 16px 24px; font-size: 18px; border-radius: 14px; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.btn-row form { margin: 0; }

/* ===== Админка: каркас ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 245px; flex: 0 0 245px; background: var(--panel);
  border-right: 1px solid var(--line); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-sub { font-size: 12px; color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  padding: 10px 12px; border-radius: 10px; color: var(--text);
  font-size: 14.5px; font-weight: 500;
}
.sidebar nav a:hover { background: var(--panel-2); text-decoration: none; }
.sidebar nav a.active { background: rgba(79,140,255,.16); color: #cfe0ff; }
.logout { margin-top: auto; }

.content { flex: 1; padding: 26px 30px 60px; max-width: 1280px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 24px; margin: 0; }
.topbar-actions { display: flex; gap: 10px; }

/* ===== Карточки ===== */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.card-narrow { max-width: 720px; }
.card.empty { text-align: center; padding: 44px 20px; }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card h3 { font-size: 15px; margin: 18px 0 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 980px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }

/* ===== Таблицы ===== */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: none; }
.row-off { opacity: .55; }

/* ===== Формы ===== */
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 11px 13px; font-size: 15px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea.mono, textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: 18px; height: 18px; }
.check-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-left: 4px; }
.inbound-group { margin-bottom: 4px; }
.inbound-title { font-weight: 600; color: var(--muted); font-size: 13px; margin: 10px 0 2px; }
.inbound-list { margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.inline-form label { min-width: 180px; }
.inline-form .grow { flex: 1; min-width: 300px; }

/* ===== Бейджи, флеши ===== */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge-ok { background: rgba(47,191,113,.15); border-color: rgba(47,191,113,.4); color: #7ee2ae; }
.badge-err { background: rgba(239,95,107,.15); border-color: rgba(239,95,107,.4); color: #ff9ba4; }
.badge-warn { background: rgba(240,180,41,.15); border-color: rgba(240,180,41,.4); color: #ffd57a; }
.badge-off { background: rgba(147,160,184,.12); border-color: rgba(147,160,184,.3); color: var(--muted); }

.flash { border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; font-size: 14.5px; border: 1px solid; }
.flash-ok { background: rgba(47,191,113,.12); border-color: rgba(47,191,113,.4); color: #9df0c4; }
.flash-err { background: rgba(239,95,107,.12); border-color: rgba(239,95,107,.45); color: #ffb3ba; }
.flash-warn { background: rgba(240,180,41,.12); border-color: rgba(240,180,41,.4); color: #ffd57a; }

/* ===== Списки ===== */
.kv { list-style: none; padding: 0; margin: 0 0 14px; }
.kv li { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.kv li span { color: var(--muted); }
.kv li b { text-align: right; font-weight: 600; }
.bullets { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.bullets li { margin-bottom: 6px; }
.events { list-style: none; padding: 0; margin: 0 0 12px; max-height: 320px; overflow: auto; }
.event { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.event-time { color: var(--muted); flex: 0 0 auto; }
.event-src { color: var(--accent); flex: 0 0 auto; min-width: 74px; }
.event-error span:last-child { color: #ffb3ba; }
.event-warn span:last-child { color: #ffd57a; }

/* ===== Прочее ===== */
.btn-row form, .btn-row button { margin: 0; }
.link-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.link-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 6px; }
.link-row code { word-break: break-all; font-size: 13.5px; }
.message-box { width: 100%; margin-top: 10px; }
.qr-wrap { text-align: center; margin-top: 18px; }
.qr-wrap img { background: #fff; padding: 8px; border-radius: 10px; }
.qr-caption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.log { background: #0b101b; border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  font-size: 12.5px; max-height: 340px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* ===== Вход ===== */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; text-align: center; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-card .stack { text-align: left; margin-top: 18px; }

/* ===== Тост ===== */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 99; max-width: 90vw; font-size: 14.5px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(239,95,107,.5); color: #ffb3ba; }
.toast.ok { border-color: rgba(47,191,113,.5); color: #9df0c4; }

/* ===== Портал клиента ===== */
.portal-body {
  background: linear-gradient(160deg, #101728 0%, #0d1220 60%, #131a2c 100%);
  min-height: 100vh; padding: 26px 16px 50px;
}
.portal { max-width: 560px; margin: 0 auto; }
.portal-head { text-align: center; margin-bottom: 22px; }
.portal-logo { font-size: 42px; }
.portal-head h1 { font-size: 27px; margin: 6px 0 4px; }
.portal-sub { color: var(--muted); margin: 0; }
.portal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 24px 20px; margin-bottom: 18px; box-shadow: 0 18px 40px rgba(0,0,0,.28);
}
.portal-card h2 { font-size: 19px; margin: 22px 0 8px; }
.portal-card h2:first-of-type { margin-top: 14px; }
.hint { color: var(--muted); font-size: 14.5px; margin: 6px 0 12px; }
.platform-pill {
  display: inline-block; background: rgba(79,140,255,.14); border: 1px solid rgba(79,140,255,.35);
  color: #cfe0ff; border-radius: 999px; padding: 6px 14px; font-size: 13.5px; margin-bottom: 6px;
}
.btn-primary.btn-xl { box-shadow: 0 10px 24px rgba(47,111,224,.35); }
.portal-card .btn { margin-bottom: 10px; }
.sub-url { margin-top: 16px; background: var(--panel-2); border: 1px dashed var(--line);
  border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); }
.sub-url code { display: block; color: var(--text); word-break: break-all; margin-top: 6px; font-size: 13px; }
.platform-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.platform-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.platform-title { font-weight: 600; margin-bottom: 10px; font-size: 14.5px; }
.platform-item .btn { width: 100%; margin-bottom: 8px; }
.portal-foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }
@media (max-width: 480px) {
  .platform-grid { grid-template-columns: 1fr; }
  .portal-card { padding: 20px 16px; }
}

/* ===== Мобильная админка ===== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 18px 14px 50px; }
  .table { display: block; overflow-x: auto; }
}
