:root {
  --bg: #FAF7F4; --surface: #FFFFFF; --card2: #F4EFEA; --deep: #F3EDE6; --ph: #F0E8E0;
  --ink: #1B1430; --muted: #6C6480; --line: #1B14301C; --hairline: #1B143038;
  --accent: #C42E60; --accent-text: #8E2C63; --accent-soft: #F6EBE6; --on-accent: #FFFFFF;
  --ok: #116152; --ok-soft: #DDEFE8; --signal: #8A5A0B; --signal-soft: #F9EBD6;
  --plum: #3A1148; --danger: #B3261E;
  --out-bubble: #F6EBE6; --in-bubble: #FFFFFF;
  --shadow: 0 8px 30px #1B143014;
  --radius: 14px;
  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Unbounded", "Manrope", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120D22; --surface: #1D1536; --card2: #241B41; --deep: #0C0817; --ph: #2C2145;
    --ink: #F7F3EE; --muted: #9A90B4; --line: #FFFFFF1F; --hairline: #FFFFFF44;
    --accent: #D93A6E; --accent-text: #FF8FB0; --accent-soft: #37183C; --on-accent: #F7F3EE;
    --ok: #4FD4B4; --ok-soft: #12332E; --signal: #F0A93A; --signal-soft: #3B2A15; --danger: #FF8A80;
    --out-bubble: #37183C; --in-bubble: #241B41;
    --shadow: 0 8px 30px #00000055;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #120D22; --surface: #1D1536; --card2: #241B41; --deep: #0C0817; --ph: #2C2145;
  --ink: #F7F3EE; --muted: #9A90B4; --line: #FFFFFF1F; --hairline: #FFFFFF44;
  --accent: #D93A6E; --accent-text: #FF8FB0; --accent-soft: #37183C; --on-accent: #F7F3EE;
  --ok: #4FD4B4; --ok-soft: #12332E; --signal: #F0A93A; --signal-soft: #3B2A15; --danger: #FF8A80;
  --out-bubble: #37183C; --in-bubble: #241B41;
  --shadow: 0 8px 30px #00000055;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent-text); }
[hidden] { display: none !important; }

.btn { border: 1px solid var(--hairline); background: var(--surface); border-radius: 10px; padding: 8px 14px;
  cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--card2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 18px; height: 18px; display: block; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: none; background: transparent; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--card2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

input[type=text], input[type=password], input[type=search], input[type=tel], textarea, select {
  width: 100%; border: 1px solid var(--hairline); background: var(--surface); border-radius: 10px; padding: 9px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin: 0 0 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- вход ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  padding: 28px; box-shadow: var(--shadow); }
.brand { font-family: var(--display); font-weight: 800; letter-spacing: -.01em; font-size: 22px; }
.brand small { display: block; font-family: var(--font); font-weight: 600; font-size: 13px; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.auth-card h2 { font-family: var(--display); font-size: 18px; margin: 22px 0 14px; font-weight: 600; }
.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 8px; margin: 10px auto; width: fit-content; }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--card2); padding: 8px 10px; border-radius: 8px; word-break: break-all; font-size: 13px; }

/* ---------- раскладка ---------- */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; height: 100dvh; overflow: hidden; }
.app > * { min-height: 0; }
.app.with-info { grid-template-columns: 340px 1fr 300px; }
.side { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.side-head { padding: 14px 14px 10px; display: flex; align-items: center; gap: 8px; }
.side-head .brand { font-size: 17px; flex: 1; }
.side-tools { padding: 0 14px 10px; display: grid; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--hairline); background: transparent; border-radius: 999px; padding: 4px 11px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip .n { opacity: .7; margin-left: 4px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.filters select { padding: 6px 8px; font-size: 13px; }

.list { overflow-y: auto; flex: 1; border-top: 1px solid var(--line); }
.item { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); align-items: center; }
.item:hover { background: var(--bg); }
.item.active { background: var(--accent-soft); }
.item .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .p { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .p .me { color: var(--ink); opacity: .7; }
.item .meta { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--muted); }
.item .sub { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); min-width: 0; }
.item .sub span.acc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { background: var(--accent); color: var(--on-accent); border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.waiting { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.ava { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; position: relative; font-size: 15px; background-size: cover; background-position: center; }
.ava.sm { width: 36px; height: 36px; font-size: 13px; }
.net { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 6px; font-size: 8px; font-weight: 800; display: grid; place-items: center; color: #fff; border: 2px solid var(--surface); letter-spacing: -.02em; }
.net.net3 { font-size: 6.5px; letter-spacing: -.04em; }
.netpick .net.net3, .card .net.net3 { font-size: 9px; }
.net-tg_user, .net-tg_bot { background: #2AABEE; }
.net-vk_group, .net-vk_user { background: #0077FF; }
.net-max_bot, .net-max_green { background: linear-gradient(135deg, #3D7BFF, #9B4DFF); }
.net-wa_green { background: #25D366; }
.net-demo { background: var(--muted); }
.label-chip { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--card2); color: var(--muted); }
.label-partner { background: var(--ok-soft); color: var(--ok); }
.label-buyer { background: var(--accent-soft); color: var(--accent-text); }
.label-setevik { background: var(--signal-soft); color: var(--signal); }
.label-seller { background: #E3E9FF; color: #2E46A8; }
.label-blogger { background: #EEE3FF; color: #6B2EB8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .label-seller { background: #1E2750; color: #A9B8FF; } :root:not([data-theme="light"]) .label-blogger { background: #2D1D4A; color: #CDA9FF; } }

/* ---------- переписка ---------- */
.conv { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.conv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); min-height: 60px; }
.conv-head .t { font-weight: 800; }
.conv-head .s { font-size: 12.5px; color: var(--muted); }
.conv-head .grow { flex: 1; min-width: 0; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--card2); border-radius: 999px; padding: 2px 10px; margin: 8px 0; }
.msg { max-width: min(560px, 78%); padding: 8px 12px 6px; border-radius: 16px; background: var(--in-bubble); border: 1px solid var(--line); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: var(--out-bubble); border-color: transparent; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--accent-text); margin-bottom: 2px; }
.msg .foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.msg.error { border: 1px solid var(--danger); }
.msg .errtxt { color: var(--danger); font-size: 12px; }
.msg img.ph { max-width: 100%; max-height: 360px; border-radius: 10px; display: block; margin: 2px 0 4px; cursor: zoom-in; }
.msg video { max-width: 100%; max-height: 360px; border-radius: 10px; }
.msg audio { width: 260px; max-width: 100%; }
.att { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--card2); border-radius: 10px; margin: 2px 0 4px; font-size: 13.5px; }
.more { align-self: center; }

.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 12px; display: grid; gap: 8px; }
.composer .row { display: flex; gap: 6px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 200px; min-height: 42px; border-radius: 12px; }
.composer .file { font-size: 13px; display: flex; gap: 8px; align-items: center; background: var(--card2); border-radius: 8px; padding: 4px 8px; width: fit-content; }
.readonly { padding: 12px 16px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.from-acc { font-size: 12px; color: var(--muted); }
.from-acc b { color: var(--ink); }

.tpl-pop { position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--hairline); border-radius: 14px; box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; padding: 6px; z-index: 5; }
.tpl-pop .ti { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.tpl-pop .ti:hover { background: var(--card2); }
.tpl-pop .ti b { display: block; font-size: 13.5px; }
.tpl-pop .ti span { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- карточка собеседника ---------- */
.info { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 18px 16px; display: grid; gap: 18px; align-content: start; }
.info h3 { font-family: var(--display); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.info .who-big { display: grid; justify-items: center; gap: 6px; text-align: center; }
.info .who-big .ava { width: 72px; height: 72px; font-size: 24px; }
.info .who-big b { font-size: 16px; }
.share-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.share-row .grow { flex: 1; }

/* ---------- окна ---------- */
.modal-bg { position: fixed; inset: 0; background: #0B0913A0; display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: 20px; width: 100%; max-width: 760px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; }
.modal.narrow { max-width: 460px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-family: var(--display); font-size: 17px; font-weight: 600; margin: 0; flex: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: none; background: none; padding: 10px 12px; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; background: var(--bg); }
.card .top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card .top .grow { flex: 1; min-width: 160px; }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.status.online { background: var(--ok-soft); color: var(--ok); }
.status.error { background: #FCE4E2; color: var(--danger); }
.status.login, .status.new { background: var(--signal-soft); color: var(--signal); }
.status.off { background: var(--card2); color: var(--muted); }
.card .errline { font-size: 13px; color: var(--danger); margin-top: 6px; }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; }
.steps li { margin-bottom: 6px; }
.netpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-bottom: 14px; }
.netpick button { text-align: left; border: 1px solid var(--hairline); border-radius: 12px; padding: 10px 12px; background: var(--surface); cursor: pointer; display: flex; gap: 10px; align-items: center; }
.netpick button.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.netpick button:disabled { opacity: .45; cursor: default; }
.netpick .net { position: static; border: none; width: 26px; height: 26px; font-size: 10px; border-radius: 8px; }
.netpick small { display: block; color: var(--muted); font-size: 12px; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users td, table.users th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.users th { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.seg { display: inline-flex; border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: transparent; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--ink); color: var(--bg); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.lightbox { position: fixed; inset: 0; background: #000D; display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }
.placeholder .brand { font-size: 26px; color: var(--ink); opacity: .15; }
.banner { background: var(--signal-soft); color: var(--signal); padding: 8px 14px; font-size: 13.5px; font-weight: 600; border-bottom: 1px solid var(--line); }

@media (max-width: 1100px) { .app.with-info { grid-template-columns: 320px 1fr; } .app.with-info .info { position: fixed; right: 0; top: 0; bottom: 0; width: min(320px, 90vw); z-index: 10; box-shadow: var(--shadow); } }
@media (max-width: 760px) {
  .app, .app.with-info { grid-template-columns: 1fr; }
  .app.open .side { display: none; }
  .app:not(.open) .conv { display: none; }
  .back { display: inline-grid; }
  .msg { max-width: 88%; }
  .grid2 { grid-template-columns: 1fr; }
  .modal { max-height: 100%; border-radius: 16px; }
}
