:root {
  --navy: #0f2a4a; --navy-2: #16375f; --teal: #14b8a6; --teal-d: #0d9488; --teal-l: #ccfbf1;
  --bg: #f4f6f9; --card: #fff; --line: #e3e8ef; --text: #0f172a; --muted: #64748b;
  --red: #dc2626; --red-l: #fee2e2; --amber: #b45309; --amber-l: #fef3c7; --green: #15803d; --green-l: #dcfce7;
  --blue: #2563eb; --wa: #22c55e; --tg: #229ed9; --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 14px; }
button:hover { border-color: #cbd5e1; }
button.primary { background: var(--teal-d); border-color: var(--teal-d); color: #fff; font-weight: 600; }
button.primary:hover { background: #0f766e; }
button.danger { color: var(--red); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .55; cursor: default; }
input, textarea, select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--teal-l); border-color: var(--teal); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
a { color: var(--blue); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* вход */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #1f4f86 0, transparent 60%), var(--navy); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand img { width: 34px; height: 34px; }
.brand span b { color: var(--teal); font-weight: 700; }
.auth-card .brand { margin-bottom: 18px; }
.auth-card button.primary { width: 100%; margin-top: 18px; padding: 10px; }
.auth-switch { margin-top: 14px; text-align: center; font-size: 13px; }
.err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* каркас */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.side { background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column; padding: 16px 12px; }
.side .brand { color: #fff; padding: 4px 8px 18px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #cbd5e1; text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.active { background: var(--teal-d); color: #fff; }
.nav .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .me { margin-top: auto; font-size: 12px; padding: 10px; border-top: 1px solid var(--navy-2); }
.side .me b { color: #fff; display: block; font-size: 13px; }
.side .me button { margin-top: 8px; background: transparent; color: #cbd5e1; border-color: var(--navy-2); padding: 4px 10px; font-size: 12px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.page { padding: 24px; overflow: auto; flex: 1; }
.alerts .alert { display: flex; gap: 12px; align-items: center; padding: 10px 18px; background: var(--red-l); color: #7f1d1d; border-bottom: 1px solid #fecaca; }
.alerts .alert.trial { background: var(--amber-l); color: #78350f; border-color: #fde68a; }
.alerts .alert b { white-space: nowrap; }
.alerts .alert button { margin-left: auto; background: #fff; }

/* карточки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: start; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--green-l); color: var(--green); }
.pill.bad { background: var(--red-l); color: var(--red); }
.pill.warn { background: var(--amber-l); color: var(--amber); }
.pill.off { background: #f1f5f9; color: var(--muted); }
.ch-head { display: flex; gap: 12px; align-items: center; }
.ch-logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex: none; }
.ch-logo.whatsapp { background: var(--wa); } .ch-logo.telegram { background: var(--tg); }
.ch-logo svg { width: 24px; height: 24px; }
.ch-title { font-weight: 600; font-size: 15px; }
.ch-problem { margin-top: 12px; background: var(--red-l); border-radius: 8px; padding: 10px 12px; color: #7f1d1d; font-size: 13px; }
.ch-problem ol { margin: 6px 0 0; padding-left: 18px; }
.ch-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.ch-actions button { font-size: 13px; padding: 5px 11px; }

/* окно чатов */
.chats { display: grid; grid-template-columns: 330px 1fr; height: 100%; min-height: 0; }
.chat-list { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.chat-list .top { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; padding: 5px; font-size: 13px; }
.tabs button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chat-items { overflow: auto; flex: 1; }
.chat-item { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #f1f5f9; cursor: pointer; align-items: center; }
.chat-item:hover { background: #f8fafc; }
.chat-item.on { background: #e6f7f5; }
.chat-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .meta { text-align: right; font-size: 11px; color: var(--muted); display: grid; gap: 4px; justify-items: end; }
.chat-item .wait { color: var(--red); font-weight: 700; }
.chat-item .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.section-label { padding: 8px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
.section-label.red { color: var(--red); }
.avatar { width: 44px; height: 44px; border-radius: 50%; position: relative; flex: none; }
.avatar img, .avatar .ini { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: grid; place-items: center; color: #fff; font-weight: 700; }
.avatar .ch { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; }
.avatar .ch svg { width: 10px; height: 10px; color: #fff; }
.avatar .ch.whatsapp { background: var(--wa); } .avatar .ch.telegram { background: var(--tg); }
.conv { display: flex; flex-direction: column; min-height: 0; background: #eef2f6; }
.conv-head { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.conv-head .name { font-weight: 600; }
.msgs { flex: 1; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 68%; padding: 7px 11px 5px; border-radius: 12px; background: #fff; align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.04); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: #d9f7f2; }
.msg.out.phone { background: #e8eefb; }
.msg.failed { background: var(--red-l); }
.msg .foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .foot svg { width: 16px; height: 16px; }
.tick-read { color: #2563eb; }
.msg .err-text { color: var(--red); font-size: 12px; margin-top: 4px; }
.msg img.media { max-width: 280px; max-height: 320px; border-radius: 8px; display: block; margin-bottom: 4px; }
.msg video, .msg audio { max-width: 300px; display: block; margin-bottom: 4px; }
.msg .file { display: flex; gap: 8px; align-items: center; padding: 6px 8px; background: rgba(0,0,0,.04); border-radius: 8px; margin-bottom: 4px; text-decoration: none; color: inherit; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.7); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }
.composer { display: flex; gap: 8px; padding: 10px 14px; background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { resize: none; max-height: 160px; min-height: 38px; }
.composer .att { display: flex; gap: 6px; align-items: center; font-size: 12px; background: #f1f5f9; border-radius: 6px; padding: 3px 8px; margin: 0 14px 0; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }

/* модальные окна */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice button { display: grid; justify-items: center; gap: 8px; padding: 18px 10px; }
.risk { background: var(--amber-l); border: 1px solid #fde68a; border-radius: 8px; padding: 12px 14px; font-size: 13px; color: #78350f; }
.risk ul { margin: 6px 0 0; padding-left: 18px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 13px; color: var(--text); }
.check input { width: auto; margin-top: 2px; }
.qr-box { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: center; }
.qr-box img { width: 220px; height: 220px; border-radius: 10px; border: 1px solid var(--line); }
.qr-wait { width: 220px; height: 220px; border-radius: 10px; border: 1px dashed var(--line); display: grid; place-items: center; color: var(--muted); text-align: center; padding: 12px; }
.qr-box ol { padding-left: 18px; margin: 0; line-height: 1.7; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; background: #fafbfc; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: #f1f5f9; padding: 2px 6px; border-radius: 5px; word-break: break-all; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow: auto; font-size: 12px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 10px; max-width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 13px; }
.toast.bad { background: var(--red); } .toast.good { background: var(--green); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { flex-direction: row; align-items: center; padding: 8px; overflow-x: auto; }
  .side .brand span, .side .me { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav a { white-space: nowrap; }
  .chats { grid-template-columns: 1fr; }
  .chats.open .chat-list { display: none; }
  .chats:not(.open) .conv { display: none; }
  .qr-box { grid-template-columns: 1fr; justify-items: center; }
}
