:root {
  --brand: #25D366;
  --brand-dark: #128C7E;
  --bg: #FFFFFF;
  --bg-soft: #F8FAFC;
  --bg-dark: #0B141A;
  --text: #1A1A1A;
  --muted: #6B7280;
  --border: #E5E7EB;
  --accent: #0EA5E9;
  --danger: #DC2626;
  --ok: #16A34A;
  --warn: #D97706;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,.07);
  /* Чаты */
  --chat-bg: #EFEAE2;
  --bubble-in: #FFFFFF;
  --bubble-out: #D9FDD3;
  --chat-meta: rgba(0,0,0,.45);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* атрибут hidden должен побеждать display: flex и т.п. */
html, body { margin: 0; padding: 0; background: var(--bg-soft); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
h1,h2,h3,h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--brand-dark); text-decoration: none; } a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); }

/* ─── Boot ─────────────────────────────────────────────────────────────── */
.boot { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--muted); }
.boot__spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Chats (мессенджер) ─────────────────────────────────────────────────── */
.main--wide { max-width: 1200px; }

.messenger {
  display: grid; grid-template-columns: 360px 1fr;
  height: calc(100vh - 96px); min-height: 480px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); overflow: hidden;
}
@media (max-width: 860px) { .messenger { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 38%) 1fr; } }

/* Левая колонка — список */
.mlist { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg); }
.mlist__head { padding: 14px 14px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.mlist__titlerow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mlist__title { font-size: 1.05rem; font-weight: 700; }
.mlist__select { max-width: 180px; padding: 6px 9px; font: inherit; font-size: .82rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
.mtabs { display: flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.mtab { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .84rem; padding: 7px 10px; border-radius: 7px; cursor: pointer; white-space: nowrap; transition: background .12s, color .12s; }
.mtab:hover { color: var(--text); }
.mtab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.mlist__scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.mlist__foot { border-top: 1px solid var(--border); padding: 8px 12px; }

.chat-item { position: relative; display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; cursor: pointer; transition: background .1s; }
.chat-item:hover { background: var(--bg-soft); }
.chat-item.active { background: #EAF7F0; }
.chat-item.active::before { content: ''; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.chat-item__body { min-width: 0; flex: 1; }
.chat-item__top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item__name { font-weight: 600; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item__time { color: var(--muted); font-size: .72rem; white-space: nowrap; flex-shrink: 0; }
.chat-item__last { color: var(--muted); font-size: .83rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.chat-item__last .me { color: var(--brand-dark); }
.chat-item__act { position: absolute; right: 10px; bottom: 8px; opacity: 0; transition: opacity .12s; border: 0; background: rgba(0,0,0,.06); color: var(--text); border-radius: 7px; font-size: .72rem; padding: 3px 9px; cursor: pointer; }
.chat-item:hover .chat-item__act, .chat-item:focus-within .chat-item__act { opacity: 1; }
.chat-item__act:hover { background: rgba(0,0,0,.12); }

.avatar { width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: .86rem; letter-spacing: .02em; }
.avatar--sm { width: 40px; height: 40px; font-size: .8rem; }

/* Правая колонка — тред */
.mthread { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.mthread__head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg); min-height: 60px; }
.mthread__id { min-width: 0; }
.mthread__title { font-weight: 600; font-size: .96rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mthread__sub { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mthread__spacer { flex: 1; }
.mthread__scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 7% 18px; display: flex; flex-direction: column; gap: 0;
  background-image: radial-gradient(rgba(0,0,0,.022) 1px, transparent 1px); background-size: 20px 20px; }
.mthread__empty { margin: auto; color: var(--muted); text-align: center; max-width: 280px; }
.mthread__empty .emoji { font-size: 2.6rem; display: block; margin-bottom: 6px; }
.mthread__older { align-self: center; padding: 2px 0 10px; }

.bubble { max-width: 72%; padding: 6px 9px 5px; border-radius: 9px; font-size: .9rem; line-height: 1.38; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px .5px rgba(0,0,0,.13); margin-top: 8px; }
.bubble--in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble--me { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble.grouped { margin-top: 2px; }
.bubble--in.grouped { border-top-left-radius: 9px; }
.bubble--me.grouped { border-top-right-radius: 9px; }
.bubble__meta { float: right; margin: 7px 0 0 12px; font-size: .64rem; color: var(--chat-meta); }
.daysep { align-self: center; background: rgba(255,255,255,.9); color: #54656F; font-size: .72rem; font-weight: 500; padding: 4px 12px; border-radius: 9px; margin: 12px 0 6px; box-shadow: 0 1px .5px rgba(0,0,0,.1); }

.pager { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.pager__nav { display: flex; gap: 6px; }

/* ─── Shell ────────────────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-dark); color: #E2E8F0; padding: 22px 16px; display: flex; flex-direction: column; }
.sidebar__brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: #fff; margin-bottom: 26px; }
.sidebar__brand .dot { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { color: #CBD5E1; padding: 9px 12px; border-radius: 8px; font-size: .95rem; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidebar nav a.active { background: var(--brand-dark); color: #fff; }
.sidebar__footer { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: .82rem; color: #94A3B8; }
.sidebar__footer button { margin-top: 10px; }

.main { padding: 28px 32px; max-width: 980px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head .muted { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.back-link { display: inline-block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }

/* ─── Cards ────────────────────────────────────────────────────────────── */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 22px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.card__title { margin: 0 0 4px; font-size: 1.02rem; }
.card__sub { margin: 0 0 14px; color: var(--muted); font-size: .87rem; }
.muted { color: var(--muted); }
.muted-cell { color: var(--muted); }

/* ─── Forms ────────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.field input, .field select, input.input { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
.field input:focus, input.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,211,102,.15); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ─── Buttons ──────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; transition: background .12s, border-color .12s, opacity .12s; }
.btn:disabled, .btn.is-busy { opacity: .6; cursor: default; }
.btn--primary { background: var(--brand); color: #06281A; }
.btn--primary:hover { background: var(--brand-dark); color: #fff; }
.btn--ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--bg-soft); }
.btn--danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { padding: 5px 10px; font-size: .82rem; }

/* ─── Badges ───────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge--ok { background: #DCFCE7; color: #166534; }
.badge--off { background: #F1F5F9; color: #64748B; }
.badge--warn { background: #FEF3C7; color: #92400E; }
.badge--danger { background: #FEE2E2; color: #991B1B; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ─── Table ────────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr.row-link { cursor: pointer; }
.table tr.row-link:hover td { background: var(--bg-soft); }
.mono { font-family: var(--font-mono); font-size: .85rem; }

/* ─── QR ───────────────────────────────────────────────────────────────── */
.qr-box { display: flex; align-items: center; justify-content: center; min-height: 280px; margin: 16px 0; padding: 16px; background: var(--bg-soft); border: 1px dashed var(--border); border-radius: 10px; }
.qr-box img { max-width: 260px; max-height: 260px; }

/* ─── Code block ───────────────────────────────────────────────────────── */
pre.code { background: var(--bg-dark); color: #E2E8F0; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: .82rem; line-height: 1.5; }
.copy-field { display: flex; gap: 8px; align-items: stretch; }
.copy-field input { flex: 1; font-family: var(--font-mono); font-size: .85rem; }

/* ─── Login ────────────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login__card { width: 100%; max-width: 380px; }
.login__brand { display: flex; align-items: center; gap: 10px; justify-content: center; font-weight: 700; font-size: 1.15rem; margin-bottom: 18px; }
.login__brand .dot { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; font-size: 1.1rem; }

/* ─── Toast ────────────────────────────────────────────────────────────── */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; }
.toast { padding: 11px 16px; border-radius: 10px; color: #fff; box-shadow: var(--shadow-md); font-size: .9rem; cursor: pointer; max-width: 360px; }
.toast--success { background: var(--ok); }
.toast--error { background: var(--danger); }
.toast--info { background: #334155; }

/* ─── Dialog ───────────────────────────────────────────────────────────── */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 900; padding: 20px; }
.dialog { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; box-shadow: var(--shadow-md); overflow: hidden; }
.dialog__header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog__title { margin: 0; font-size: 1.05rem; }
.dialog__close { background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }
.dialog__body { padding: 18px 20px; }
.dialog__footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg-soft); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 12px 16px; }
  .sidebar nav { flex-direction: row; }
  .sidebar__brand { margin: 0 16px 0 0; }
  .sidebar__footer { display: none; }
  .main { padding: 20px 16px; }
}
