:root {
  --bg: #0a0e17;
  --bg2: #111726;
  --card: #151c2c;
  --card2: #1b2436;
  --line: #243049;
  --txt: #e8edf7;
  --muted: #8a97b2;
  --accent: #5b8cff;
  --accent2: #7b5bff;
  --green: #2ed47a;
  --red: #ff5b6e;
  --yellow: #ffc24b;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Атрибут hidden должен прятать элемент даже при display:flex/grid ниже. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  background:
    radial-gradient(1100px 600px at 85% -12%, rgba(123,91,255,.18), transparent),
    radial-gradient(900px 500px at 10% 0%, rgba(91,140,255,.14), transparent),
    var(--bg);
  color: var(--txt);
  min-height: 100vh;
}

#app { max-width: 720px; margin: 0 auto; padding: 14px 14px 40px; }

/* topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-weight: 800; font-size: 22px;
  box-shadow: 0 6px 20px rgba(91, 140, 255, .4);
}
.brand-title { font-weight: 800; font-size: 19px; letter-spacing: .5px; }
.brand-sub { color: var(--muted); font-size: 12px; }

/* tabs */
.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 5px; border-radius: 14px; border: 1px solid var(--line); }
.tab {
  flex: 1; padding: 10px; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--card2); color: var(--txt); box-shadow: 0 2px 10px rgba(0,0,0,.3); }

.tabview { margin-top: 14px; }

/* toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.stat { color: var(--muted); font-size: 13px; }

.selectbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sel-count { color: var(--accent); font-size: 13px; font-weight: 600; }

.massbar { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; max-height: 0; overflow: hidden; transition: max-height .25s, opacity .2s; opacity: 0; }
.massbar.show { max-height: 200px; opacity: 1; }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 11px 15px; font-weight: 650; font-size: 14px; cursor: pointer; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 4px 16px rgba(91,140,255,.35); }
.btn-ghost { background: var(--card2); color: var(--txt); border: 1px solid var(--line); }
.btn.full { width: 100%; margin-top: 6px; }

.chip {
  background: var(--card2); border: 1px solid var(--line); color: var(--txt);
  padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip:active { transform: scale(.96); }
.chip-danger { color: var(--red); border-color: #3a2330; }

/* account list */
.list { display: flex; flex-direction: column; gap: 10px; }
.acc {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px; display: flex; flex-direction: column; gap: 10px;
  animation: accIn .32s ease both;
}
@keyframes accIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.acc-top { display: flex; align-items: center; gap: 11px; }
.acc-check { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.acc-main { flex: 1; min-width: 0; }
.acc-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-phone { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.acc-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.tag.ok { color: var(--green); border-color: #1d3a2b; }
.tag.dead { color: var(--red); border-color: #3a2330; }
.tag.warn { color: var(--yellow); border-color: #3a3320; }
.tag.fa { color: var(--accent); border-color: #233052; }

.acc-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.acc-actions .chip { padding: 7px 10px; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 14px; }

/* proxies */
.proxy-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.proxy-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.proxy-head h3 { margin: 0; font-size: 16px; }
.badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 20px; }
textarea {
  width: 100%; min-height: 92px; resize: vertical; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--txt); padding: 11px; font-size: 13px; font-family: ui-monospace, monospace;
}
.row { display: flex; gap: 8px; margin-top: 10px; }
.row .btn { flex: 1; }
.proxy-list { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.proxy-item { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); padding: 7px 10px; background: var(--bg2); border-radius: 9px; word-break: break-all; }

/* fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; color: var(--txt);
  padding: 12px; font-size: 15px; width: 100%;
}
.checkbox { display: flex; align-items: center; gap: 9px; color: var(--txt); font-size: 14px; cursor: pointer; }
.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }
.checkbox.big { margin: 6px 0 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(5,8,14,.75); backdrop-filter: blur(4px); display: grid; place-items: end center; z-index: 50; padding: 0; }
.modal-card {
  width: 100%; max-width: 720px; background: var(--card); border-top-left-radius: 22px; border-top-right-radius: 22px;
  border: 1px solid var(--line); padding: 18px 16px 26px; animation: slideUp .25s ease;
  max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.modal-head { position: sticky; top: -2px; background: var(--card); padding-top: 2px; z-index: 2; }
@keyframes slideUp { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 18px; }

/* overlay */
.overlay { position: fixed; inset: 0; background: rgba(5,8,14,.82); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 80; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  display: grid; place-items: center; gap: 16px; padding: 26px 30px;
  background: rgba(21,28,44,.9); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5); animation: popIn .25s cubic-bezier(.2,.9,.3,1.3);
}
@keyframes popIn { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.loader { display: flex; gap: 9px; align-items: center; height: 26px; }
.loader span {
  width: 13px; height: 13px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  animation: bounce 1.1s ease-in-out infinite; box-shadow: 0 0 14px rgba(91,140,255,.55);
}
.loader span:nth-child(2) { animation-delay: .16s; }
.loader span:nth-child(3) { animation-delay: .32s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0) scale(.7); opacity: .5; }
  40% { transform: translateY(-12px) scale(1); opacity: 1; }
}
.overlay-text { color: var(--txt); font-size: 14px; text-align: center; font-weight: 600; }
.ov-sub { color: var(--muted); font-size: 12px; font-weight: 400; }
/* старый одиночный спиннер (на случай переиспользования) */
.spinner { width: 46px; height: 46px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* segmented switch (upload / sms) */
.seg { display: flex; gap: 6px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 5px; margin-bottom: 16px; }
.seg-btn { flex: 1; padding: 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 650; font-size: 14px; cursor: pointer; }
.seg-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 3px 12px rgba(91,140,255,.35); }

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: 14px; padding: 22px 14px; text-align: center;
  cursor: pointer; background: var(--bg2); transition: border-color .15s, background .15s;
}
.dropzone:active { border-color: var(--accent); background: var(--card2); }
.dz-icon { font-size: 30px; }
.dz-title { font-weight: 700; font-size: 15px; margin-top: 6px; }
.dz-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.dz-name { margin-top: 10px; color: var(--accent); font-size: 13px; word-break: break-all; }

.or-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0 12px; }
.or-line::before, .or-line::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .field { margin-bottom: 6px; }

/* proxy status dots */
.proxy-item { display: flex; align-items: center; gap: 8px; }
.ptext { flex: 1; min-width: 0; word-break: break-all; }
.pdot { font-size: 12px; flex: none; }
.pdot.ok { color: var(--green); }
.pdot.dead { color: var(--red); }

/* messenger */
.topbar-actions { display: flex; gap: 8px; }
.icon-btn { padding: 9px 12px; font-size: 17px; line-height: 1; }
.chip-accent { color: var(--accent); border-color: #233052; }

.screen {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column; animation: slideLeft .22s ease;
}
@keyframes slideLeft { from { transform: translateX(30px); opacity: .3; } to { transform: none; opacity: 1; } }

.chat-top {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg2); flex: none;
}
.chat-top .icon-btn { font-size: 24px; padding: 4px 10px; }
.chat-top-main { flex: 1; min-width: 0; }
.chat-top-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top-sub { color: var(--muted); font-size: 12px; }
.chat-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-weight: 700;
  overflow: hidden;
}
.chat-avatar img, .dlg-av img { width: 100%; height: 100%; object-fit: cover; display: block; }

.dialogs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dlg { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid rgba(36,48,73,.5); cursor: pointer; }
.dlg:active { background: var(--card2); }
.dlg-av {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #2a3550, #384668); color: #cfe0ff; font-weight: 700; font-size: 19px;
  overflow: hidden;
}
.dlg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; justify-content: center; }
.dlg-row1, .dlg-row2 { display: flex; align-items: center; gap: 8px; }
.dlg-title { flex: 1; min-width: 0; font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg-time { color: var(--muted); font-size: 11px; flex: none; }
.dlg-last { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dlg-badge { flex: none; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center; }

.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg-load { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }
.msg { display: flex; max-width: 82%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.msg-bubble {
  padding: 8px 12px 6px; border-radius: 14px; font-size: 14px; line-height: 1.35;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; max-width: 100%;
}
.msg.in .msg-bubble { background: var(--card2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.out .msg-bubble { background: linear-gradient(135deg, #2b5bd0, #4a3bd0); color: #fff; border-bottom-right-radius: 5px; }
.msg-time { display: block; text-align: right; font-size: 10px; opacity: .6; margin-top: 3px; }
.msg-who { font-size: 11px; color: var(--accent); font-weight: 600; margin: 0 0 2px 4px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-att { font-size: 12px; opacity: .85; margin-top: 3px; }

/* эмодзи-пикер */
.emoji-btn { flex: none; font-size: 20px; padding: 6px 8px; }
.emoji-panel {
  flex: none; display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 10px; max-height: 180px;
  overflow-y: auto; background: var(--bg2); border-top: 1px solid var(--line);
}
.emoji-i { font-size: 22px; line-height: 1; padding: 6px; background: none; border: none; cursor: pointer; border-radius: 8px; }
.emoji-i:active { background: rgba(255,255,255,.1); }

/* панель форматирования выделенного текста */
.fmt-bar { flex: none; display: flex; gap: 6px; padding: 6px 10px; background: var(--bg2); border-top: 1px solid var(--line); }
.fmt-bar button {
  min-width: 36px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); color: var(--text); cursor: pointer; font-size: 14px;
}
.fmt-bar button:active { background: rgba(91,140,255,.2); }
.fmt-bar .fmt-b { font-weight: 800; }
.fmt-bar .fmt-i { font-style: italic; }
.fmt-bar .fmt-u { text-decoration: underline; }
.fmt-bar .fmt-s { text-decoration: line-through; }
.fmt-bar .fmt-m { font-family: monospace; }

/* масс-диалоги: метка аккаунта-владельца */
.dlg-acc { display: inline-block; font-size: 11px; color: var(--accent); background: rgba(91,140,255,.14);
  border-radius: 6px; padding: 0 5px; margin-right: 6px; vertical-align: middle; }
.chip-accent { border-color: var(--accent) !important; color: var(--accent) !important; }

/* загрузка списка диалогов */
.dlg-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px 16px; color: var(--muted, #8a93a6); font-size: 14px; text-align: center; }
.dlg-loading .spinner { display: inline-block; flex: none; width: 20px; height: 20px; border-width: 2px; }

/* фильтр диалогов */
.dlg-filter { flex: none; display: flex; gap: 8px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--line); overflow-x: auto; }
.dlg-filter .flt {
  flex: none; padding: 6px 12px; border-radius: 20px; font-size: 13px; cursor: pointer;
  background: rgba(255,255,255,.06); color: var(--text); border: 1px solid var(--line); opacity: .5;
}
.dlg-filter .flt.on { opacity: 1; border-color: var(--accent); background: rgba(91,140,255,.16); color: var(--accent); }

/* вложения */
.att-photo { position: relative; margin-bottom: 4px; display: inline-block; }
.att-photo img { display: block; max-width: 220px; max-height: 280px; border-radius: 12px; cursor: zoom-in; object-fit: cover; }
.att-photo.att-broken { padding: 10px 12px; background: rgba(255,255,255,.06); border-radius: 10px; }
.att-dl {
  position: absolute; right: 6px; bottom: 6px; width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  background: rgba(0,0,0,.55); color: #fff; text-decoration: none; backdrop-filter: blur(2px);
}
.att-dl:active { background: rgba(0,0,0,.75); }
.att-sticker { max-width: 128px; max-height: 128px; margin-bottom: 4px; }
.att-audio { display: block; max-width: 240px; margin: 4px 0; height: 36px; }
.att-file {
  display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; margin: 4px 0;
  background: rgba(255,255,255,.06); border-radius: 10px; cursor: pointer; max-width: 240px;
}
.att-file span { font-size: 13px; font-weight: 600; word-break: break-word; }
.att-file small { font-size: 11px; opacity: .6; }
.att-file:active { background: rgba(255,255,255,.12); }
.att-share {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; margin: 4px 0;
  background: rgba(255,255,255,.06); border-left: 3px solid var(--accent); border-radius: 8px;
  text-decoration: none; color: inherit; max-width: 240px;
}
.att-share b { font-size: 13px; color: var(--accent); }
.att-share span { font-size: 12px; opacity: .8; }

/* лайтбокс */
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 94vw; max-height: 88vh; border-radius: 8px; }
.lb-close, .lb-dl {
  position: absolute; top: 14px; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
  background: rgba(255,255,255,.14); color: #fff; border: none; cursor: pointer; text-decoration: none;
}
.lb-close { right: 14px; }
.lb-dl { right: 66px; }

/* контекстное меню */
.ctx-menu {
  position: fixed; z-index: 210; min-width: 170px; padding: 6px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 2px;
}
.ctx-menu button {
  text-align: left; padding: 10px 12px; background: none; border: none; color: var(--text);
  font-size: 14px; border-radius: 8px; cursor: pointer;
}
.ctx-menu button:active { background: rgba(255,255,255,.1); }

/* панель ответа */
.reply-bar {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--bg2); border-top: 1px solid var(--line); border-left: 3px solid var(--accent);
}
.reply-info { flex: 1; min-width: 0; }
.reply-name { font-size: 12px; font-weight: 600; color: var(--accent); }
.reply-text { font-size: 12px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { padding: 6px 10px; }

/* пересылка */
.fwd-search { width: 100%; margin-bottom: 10px; }
.fwd-list { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.fwd-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.fwd-item:active { background: rgba(255,255,255,.08); }
.fwd-item span { font-size: 14px; font-weight: 500; }
.fwd-av { width: 36px; height: 36px; flex: none; }

.composer { flex: none; display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--bg2); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 120px; background: var(--card2); border: 1px solid var(--line);
  border-radius: 18px; color: var(--txt); padding: 10px 14px; font-size: 14px; font-family: inherit; line-height: 1.3;
}
.send-btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 18px; flex: none; }

/* toasts */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 90; pointer-events: none; padding: 0 12px; }
.toast { background: var(--card2); border: 1px solid var(--line); color: var(--txt); padding: 11px 16px; border-radius: 12px; font-size: 13px; max-width: 100%; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: toastIn .2s ease; }
.toast.ok { border-color: #1d3a2b; }
.toast.err { border-color: #3a2330; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
