:root {
  --bg: #F4F4F2;
  --surface: #FFFFFF;
  --soft: #F7F7F5;
  --line: #E7E7E4;
  --line-2: #EFEFEC;
  --ink: #17171A;
  --ink-2: #4A4A50;
  --muted: #64646B;
  --accent: #2563EB;
  --accent-soft: #EEF3FE;
  --accent-off: #9DB6EE;
  --select: #F1F4FB;
  --bubble-in: #EFEFEC;
  --danger: #A3231A;
  --danger-btn: #B42318;
  --danger-soft: #FBEAE8;
  --ok: #1F9D55;
  --radius: 16px;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- кнопки и общие элементы */
.btn { height: 42px; padding: 0 16px; border-radius: 11px; border: 0; font-size: 14px; font-weight: 500; background: #F1F1EF; color: var(--ink); }
.btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:disabled { background: var(--accent-off); }
.btn.dark { background: var(--ink); color: #fff; font-weight: 600; }
.btn.danger { background: var(--danger-btn); color: #fff; font-weight: 600; }
.btn.soft { background: #F1F1EF; }
.btn.small { height: 34px; padding: 0 14px; border-radius: 10px; font-size: 13px; background: var(--surface); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.icon-btn { width: 40px; height: 40px; flex: 0 0 auto; border: 0; border-radius: 10px; background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: #F1F1EF; }
.icon-btn.filled { width: 44px; height: 44px; border-radius: 12px; background: var(--bg); color: var(--ink-2); }
.pill { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.pill.soft { background: var(--bg); border: 0; height: 30px; padding: 0 10px; font-size: 12px; color: var(--ink-2); gap: 6px; }
.pill-btn { font-weight: 500; }
.pill-btn:hover { background: var(--soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #C4C4BE; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger-btn); }
.mini-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
#mePill { padding-left: 4px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #F1F1EF; color: var(--ink-2); white-space: nowrap; }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.avatar { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; }

/* ---------- вход */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 360px; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: flex; flex-direction: column; gap: 8px; }
.login-card .brand { margin-bottom: 14px; }
.login-card label { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-top: 6px; }
.login-card input { height: 44px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line); outline: none; font-size: 15px; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { margin-top: 10px; height: 46px; }
.form-error { min-height: 18px; margin: 4px 0 0; font-size: 13px; color: var(--danger); }

/* ---------- каркас */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { flex: 0 0 auto; min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text b { font-size: 15px; font-weight: 600; }
.brand-text small { font-size: 12px; color: var(--muted); }
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.main { flex: 1 1 auto; min-height: 0; display: flex; gap: 12px; padding: 0 12px 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

/* ---------- список диалогов */
.list { flex: 0 0 360px; }
.list-head { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 10px; background: var(--bg); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 14px; color: var(--ink); }
/* вкладки — всегда в один ряд, равной ширины, без прокрутки */
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 3px; border-radius: 12px; background: var(--bg); }
.tab { height: 32px; min-width: 0; padding: 0 6px; border-radius: 9px; border: 0; font-size: 13px; font-weight: 500; background: transparent; color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; overflow: hidden; }
.tab .tab-full, .tab .tab-short { overflow: hidden; text-overflow: ellipsis; }
.tab .tab-short { display: none; }
.tab-n { flex: 0 0 auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #E4E4E0; color: var(--ink); font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.list .tab .tab-full { display: none; }
.list .tab .tab-short { display: inline; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(23,23,26,0.12); }
.chat-list { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.chat-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; border-radius: 12px; text-align: left; background: transparent; color: var(--ink); }
.chat-item:hover { background: var(--soft); }
.chat-item.active { background: var(--select); }
.ci-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ci-row { display: flex; align-items: center; gap: 6px; }
.ci-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { margin-left: auto; flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.ci-last { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-icon { flex: 0 0 auto; color: var(--muted); display: inline-flex; }
.unread { flex: 0 0 auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.list-empty { margin: 24px 12px; font-size: 13px; color: var(--muted); text-align: center; }
.list-foot { flex: 0 0 auto; display: flex; align-items: center; border-top: 1px solid var(--line-2); }
.logout-mini { margin-right: 8px; color: var(--muted); }
.archive-link { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 12px 16px; border: 0; background: var(--surface); font-size: 12px; color: var(--muted); text-align: left; }
.archive-link:hover { color: var(--ink); }

/* ---------- переписка */
.chat { flex: 1 1 auto; min-width: 0; position: relative; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.chat-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { position: relative; flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--line-2); }
.chat-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.chat-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-name { font-size: 15px; font-weight: 600; }
.badges { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.back { display: none; }
.menu { position: absolute; top: 62px; right: 14px; z-index: 5; width: 264px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px rgba(23,23,26,0.12); display: flex; flex-direction: column; }
.menu-item { display: flex; align-items: center; gap: 12px; height: 42px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; text-align: left; color: var(--ink); }
.menu-item:hover { background: var(--soft); }
.menu-item.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--line-2); margin: 6px 8px; }
.arch-banner { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: var(--soft); border-bottom: 1px solid var(--line-2); font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.arch-banner span { flex: 1 1 240px; }

.messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; background: #FAFAF9; padding: 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 10px; border-radius: 999px; background: #F1F1EF; margin: 6px 0; }
.load-more { align-self: center; font-size: 12px; color: var(--muted); }
.msg { max-width: 68%; display: flex; flex-direction: column; gap: 4px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 6px; }
.msg.in .bubble { background: var(--bubble-in); border-radius: 16px 16px 16px 6px; }
.msg.out .bubble { background: var(--accent); color: #fff; border-radius: 16px 16px 6px 16px; }
.msg.deleted .bubble { background: var(--surface); color: var(--ink); border: 1px dashed #C4C4BE; }
.del-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--danger); white-space: normal; }
.was { font-size: 12px; opacity: 0.85; white-space: pre-wrap; border-top: 1px solid rgba(127,127,127,0.3); padding-top: 6px; }
.meta { font-size: 11px; color: var(--muted); padding: 0 4px; }
.msg.selectable { cursor: pointer; }
.msg.selectable .bubble { outline: 2px solid transparent; outline-offset: 2px; }
.msg.selected .bubble { outline-color: var(--accent); }
.media-btn { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 10px; border: 0; font-size: 13px; font-weight: 500; background: rgba(255,255,255,0.7); color: var(--ink); text-decoration: none; }
.msg.out .media-btn { background: rgba(255,255,255,0.18); color: #fff; }
.media-img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.media-player { max-width: 100%; }

.forward-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line-2); font-size: 14px; }
.forward-bar span { flex: 1; }

.composer { position: relative; flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line-2); }
.composer textarea { flex: 1 1 auto; min-width: 0; min-height: 44px; max-height: 180px; resize: none; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; line-height: 1.45; outline: none; }
.composer textarea:focus { border-color: #C9D6F5; }
.send-btn { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.send-btn:disabled { background: var(--accent-off); }

.slash { position: absolute; left: 14px; right: 14px; bottom: calc(100% + 6px); z-index: 4; max-width: 600px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px rgba(23,23,26,0.12); padding: 6px; display: flex; flex-direction: column; }
.slash-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px 8px; }
.slash-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; text-transform: uppercase; }
.slash-edit { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 8px; border: 0; background: var(--bg); font-size: 12px; font-weight: 500; }
.slash-list { max-height: 264px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.slash-item { display: flex; align-items: baseline; gap: 12px; padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; text-align: left; }
.slash-item.active, .slash-item:hover { background: var(--select); }
.slash-cmd { flex: 0 0 120px; font-size: 14px; font-weight: 600; color: var(--accent); overflow: hidden; text-overflow: ellipsis; }
.slash-text { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slash-empty { padding: 10px; font-size: 13px; color: var(--muted); }

/* ---------- окна */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(23,23,26,0.36); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal > * { flex-shrink: 0; }
.modal { width: 540px; max-width: 100%; max-height: 100%; overflow-y: auto; background: var(--surface); border-radius: 20px; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal.wide { width: 680px; }
.modal.narrow { width: 420px; gap: 10px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.modal-head .icon-btn { margin-left: auto; width: 36px; height: 36px; background: var(--bg); }
.modal p.text { margin: 0; font-size: 14px; line-height: 1.5; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.modal-actions .hint { margin-right: auto; font-size: 13px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.field input, .field textarea, .field select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; line-height: 1.45; outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 84px; }
.prefix { display: flex; align-items: center; height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.prefix b { color: var(--accent); }
.prefix input { flex: 1; min-width: 0; border: 0; padding: 0 0 0 2px; outline: none; }

.cmd-table { display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; }
.cmd-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.cmd-row:last-child { border-bottom: 0; }
.cmd-row.editing { background: var(--select); }
.cmd-row .slash-cmd { padding-top: 2px; }
.cmd-row .cmd-text { flex: 1 1 auto; min-width: 0; font-size: 13px; line-height: 1.45; color: var(--ink-2); white-space: pre-line; overflow-wrap: anywhere; }
.sq-btn { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 9px; border: 0; background: var(--bg); display: inline-flex; align-items: center; justify-content: center; }
.sq-btn.red { background: var(--danger-soft); color: var(--danger); }
.cmd-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 14px; background: var(--soft); }
.cmd-form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.cmd-form-row .field:first-child { flex: 0 1 180px; }
.cmd-form-row .field:last-child { flex: 1 1 300px; }

.gift-tier { display: flex; flex-direction: column; gap: 8px; }
.gift-tier-title { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.gift-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.gift { position: relative; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; }
.gift-add { width: 100%; min-height: 96px; padding: 8px 4px; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.gift .emoji { font-size: 30px; line-height: 1; }
.gift-name { font-size: 12px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gift-price { font-size: 11px; color: var(--muted); }
.gift[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); }
.gift-qty { display: flex; align-items: center; justify-content: space-between; padding: 4px; border-top: 1px solid #D5E0FA; }
.gift-qty b { font-size: 13px; }
.qty-btn { width: 30px; height: 30px; border-radius: 8px; border: 0; background: var(--surface); font-size: 16px; font-weight: 600; color: var(--accent); }

.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow-y: auto; }
.audit-list { display: flex; flex-direction: column; font-size: 13px; }
.audit-row { display: grid; grid-template-columns: 110px 120px minmax(0, 1fr); gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line-2); }
.audit-row .what { overflow-wrap: anywhere; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13px; line-height: 1.4; box-shadow: 0 10px 30px rgba(23,23,26,0.25); }
.toast.error { background: var(--danger-btn); }

/* ---------- телефон */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; }
  .topbar .brand-text small, #meRole, #tgStatus .pill-text { display: none; }
  .main { padding: 0; gap: 0; }
  .panel { border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
  .list { flex: 1 1 auto; }
  .chat { display: none; }
  body.show-chat .list { display: none; }
  body.show-chat .chat { display: flex; }
  body.show-chat .topbar { display: none; }
  .back { display: inline-flex; }
  .chat-head { padding: 10px 8px 10px 4px; gap: 8px; }
  .retention { display: none; }
  .messages { padding: 16px 12px; }
  .msg { max-width: 84%; }
  .composer { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer textarea { font-size: 16px; }
  .slash { left: 8px; right: 8px; }
  .slash-item { flex-direction: column; gap: 2px; }
  .slash-cmd { flex: none; }
  .slash-text { max-width: 100%; }
  .backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: 22px 22px 0 0; max-height: 92vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .audit-row { grid-template-columns: 1fr; gap: 2px; }
  .chat-item { padding: 10px 8px; }
  .avatar { width: 50px; height: 50px; font-size: 16px; }
}

/* ---------- цвета аватаров */
.pal0 { background: #DCE7FB; color: #1E4FB8; }
.pal1 { background: #E2F1E6; color: #1E6B3A; }
.pal2 { background: #F6E8DA; color: #8A4A12; }
.pal3 { background: #EEE6F7; color: #5B2E91; }
.pal4 { background: #E1EEF1; color: #1F5A66; }
.pal5 { background: #F7E3E3; color: #922B2B; }
.modal-title { margin: 0; font-size: 18px; font-weight: 600; }
.form-title { font-size: 14px; }

/* ---------- подарки в переписке */
.gift-msg .gift-card { min-width: 200px; max-width: 280px; padding: 14px 16px; border-radius: 16px; background: #FFF8E8; border: 1px solid #F0E0B8; color: var(--ink); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.gift-dir { font-size: 12px; font-weight: 600; color: #7A5A12; }
.gift-emoji { font-size: 44px; line-height: 1.1; }
.gift-icon { display: inline-flex; color: #7A5A12; }
.gift-title { font-size: 14px; font-weight: 600; }
.gift-text { font-size: 13px; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- сотрудники */
.badge.dark { background: var(--ink); color: #fff; }
.staff-list { display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; }
.staff-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.staff-row:last-child { border-bottom: 0; }
.staff-row.off { opacity: 0.6; }
.staff-row .avatar { width: 40px; height: 40px; font-size: 14px; }
.staff-info { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.staff-info b { font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.staff-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.staff-form-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 760px) { .staff-form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- внутри Telegram */
body.in-tg #logoutBtn { display: none; }
body.in-tg .app { height: var(--tg-viewport-stable-height, 100dvh); }
body.tg-full .app { padding-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)); }
body.tg-full .composer { padding-bottom: calc(10px + var(--tg-safe-area-inset-bottom, 0px)); }

/* ---------- стикеры */
.sticker { display: inline-flex; align-items: center; gap: 8px; }
.sticker-emoji { font-size: 34px; line-height: 1; }
.sticker-label { font-size: 13px; opacity: 0.8; }

/* ---------- команды из нескольких сообщений */
.cmd-short { max-width: 240px; }
.cmd-parts { display: flex; flex-direction: column; gap: 10px; }
.part-head { display: flex; align-items: center; justify-content: space-between; }
.link-btn { border: 0; background: transparent; padding: 0; font-size: 12px; color: var(--danger); }
.add-part { align-self: flex-start; }
.part-no { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.part-gap { display: block; height: 8px; }
.parts-badge { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 999px; }
.split-hint { position: absolute; right: 70px; top: -26px; font-size: 12px; color: var(--accent); background: var(--surface); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }

/* ---------- телефон: без лишнего */
@media (max-width: 760px) {
  .topbar .brand { display: none; }
  .topbar { min-height: 0; padding: 6px 10px; justify-content: flex-end; }
  .list .search { display: none; }
  .list-head { padding: 10px 10px 8px; }
  .gift-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- состояние диалога в списке */
/* отвечено — серым; прочитано, но без ответа — белым; не прочитано — счётчик и жирное имя */
.chat-item.answered { background: #F4F4F2; }
.chat-item.answered .ci-name { color: var(--ink-2); font-weight: 500; }
.chat-item.answered .ci-last { color: #8A8A90; }
.chat-item.answered:hover { background: #EFEFEC; }
.chat-item.has-unread .ci-name { font-weight: 700; }
.chat-item.has-unread .ci-last { color: var(--ink); }
.chat-item.active, .chat-item.active.answered { background: var(--select); }
.chat-list { gap: 4px; }

/* ---------- оценка коллекционного подарка */
.nft-card { max-width: 320px; padding: 10px 12px; border-radius: 12px; background: #FFF8E8; border: 1px solid #F0E0B8; font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }
.msg.out .nft-card { align-self: flex-end; }
.nft-head { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); }
.nft-head .muted { font-weight: 500; }
.nft-value { font-size: 13px; color: var(--ink); }
.nft-line { line-height: 1.5; }

/* ---------- «прочитано» */
.tick { display: inline-flex; align-items: center; gap: 3px; margin-left: 4px; color: #9A9AA0; vertical-align: -2px; }
.tick.read { color: var(--accent); }
.ci-last .tick { margin: 0 4px 0 0; }

/* ---------- закрытый архив */
.locked { margin: 32px 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.5; }
.locked b { color: var(--ink); font-size: 15px; }

/* ---------- группы в списке и флаг страны */
.list-group { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.list-group:first-child { padding-top: 2px; }
.ci-flag { flex: 0 0 auto; font-size: 13px; line-height: 1; }

/* ---------- NFT-подарки клиента */
.gifts-hint { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 18px; background: #FFF8E8; border-bottom: 1px solid #F0E0B8; font-size: 13px; color: #5C4510; flex-wrap: wrap; }
.gifts-hint span { flex: 1 1 200px; }
.gifts-hint .icon-btn { width: 32px; height: 32px; }
.nft-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.nft-item { display: flex; flex-direction: column; gap: 6px; }
.nft-item .nft-card { max-width: none; }
.nft-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 10px; }
@media (max-width: 760px) { .nft-list { grid-template-columns: 1fr; } }

/* ---------- автосообщения */
.rule-row { display: flex; gap: 10px; flex-wrap: wrap; }
.rule-row .field:first-child { flex: 1 1 260px; }
.rule-delay { flex: 0 0 200px; }
.delay-inputs { display: flex; gap: 6px; }
.delay-inputs input { width: 80px; }
.delay-inputs select, .field select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.rule-when { display: block; font-size: 12px; color: var(--accent); margin: 2px 0 4px; }
.cmd-text b { display: block; color: var(--ink); }
.rule-off .cmd-text { opacity: 0.55; }
.switch { position: relative; flex: 0 0 auto; width: 40px; height: 24px; margin-top: 2px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #D5D5D1; transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- окно «Подарки в профиле» */
.nfts-modal { width: 780px; }
.nfts-head { align-items: center; }
.nfts-head .avatar { width: 44px; height: 44px; font-size: 15px; }
.nfts-head h2 { font-size: 19px; font-weight: 700; }
.nfts-summary { padding: 16px 18px; border-radius: 16px; background: var(--ink); color: #fff; display: flex; flex-direction: column; gap: 4px; }
.nfts-summary-label, .nfts-summary-sub { font-size: 12px; color: #B9B9BE; }
.nfts-total { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.nfts-sort { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.nfts-sort .muted { margin-right: 4px; }
.chip { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.nfts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.nft-tile-card { border-radius: 16px; border: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; background: var(--surface); }
.nft-tile { position: relative; height: 128px; background: #EFEFEC; display: flex; align-items: center; justify-content: center; }
.nft-tile-emoji { font-size: 58px; line-height: 1; }
.nft-badge { position: absolute; top: 10px; left: 10px; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,0.88); color: var(--ink); }
.nft-badge.dark { left: auto; right: 10px; background: rgba(23,23,26,0.78); color: #fff; }
.nft-tile-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.nft-tile-title { font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nft-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.nft-chips span { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--bg); color: var(--ink-2); }
.nft-price-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.nft-price { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.nft-price-row a { font-size: 12px; font-weight: 500; text-decoration: none; }
.nft-sub { font-size: 11px; color: var(--muted); line-height: 1.4; }
.nfts-note { margin: 0; font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  .nfts-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .nft-tile { height: 104px; }
  .nft-tile-emoji { font-size: 48px; }
  .nft-tile-body { padding: 10px 12px 12px; gap: 5px; }
  .nft-price { font-size: 16px; }
  .nft-price-row { flex-direction: column; gap: 2px; }
  .nfts-total { font-size: 26px; }
  .nft-badge.dark { display: none; }
  .nfts-sort .muted { display: none; }
}

/* ---------- форматирование, ответы, пересланные */
.rich { white-space: pre-wrap; }
.rich code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; padding: 1px 4px; border-radius: 5px; background: rgba(127,127,127,0.16); }
.rich code.pre { display: block; padding: 8px 10px; margin: 2px 0; white-space: pre-wrap; overflow-x: auto; }
.rich a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg.in .rich a { color: var(--accent); }
.rich .bq { display: block; padding: 2px 0 2px 10px; margin: 2px 0; border-left: 3px solid currentColor; opacity: 0.92; }
.spoiler { background: currentColor; border-radius: 4px; cursor: pointer; transition: background 0.2s; }
.spoiler.revealed { background: rgba(127,127,127,0.18); cursor: auto; }
.fwd { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; opacity: 0.8; }
.reply-quote { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; padding: 6px 10px; border: 0; border-left: 3px solid var(--accent); border-radius: 6px 10px 10px 6px; background: rgba(37,99,235,0.08); text-align: left; font-size: 12px; color: inherit; }
.msg.out .reply-quote { border-left-color: #fff; background: rgba(255,255,255,0.16); }
.reply-quote b { font-size: 12px; }
.reply-quote span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }
.reply-btn { margin-left: 6px; width: 24px; height: 20px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; vertical-align: -5px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .reply-btn, .reply-btn:focus-visible { opacity: 1; }
.reply-btn:hover { background: #EFEFEC; color: var(--ink); }
@media (hover: none) { .reply-btn { opacity: 0.6; } }
.msg.flash .bubble, .msg.flash .gift-card { outline: 2px solid var(--accent); outline-offset: 2px; }
.reply-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; border-top: 1px solid var(--line-2); background: var(--soft); color: var(--accent); }
.reply-bar-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; font-size: 12px; }
.reply-bar-text b { color: var(--accent); }
.reply-bar-text span { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar .icon-btn { width: 32px; height: 32px; color: var(--muted); }

/* ---------- карточка подарка под ссылкой t.me/nft/... */
.nftc { width: 340px; max-width: 100%; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); overflow: hidden; box-shadow: 0 1px 2px rgba(23,23,26,0.04); }
.msg.out .nftc { align-self: flex-end; }
.nftc-top { display: flex; gap: 12px; padding: 12px; }
.nftc-tile { flex: 0 0 auto; width: 72px; height: 72px; border-radius: 14px; background: #EFEFEC; display: flex; align-items: center; justify-content: center; font-size: 40px; line-height: 1; }
.nftc-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.nftc-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 14px; }
.nftc-head b { font-weight: 700; }
.nftc-num { font-size: 12px; color: var(--muted); font-weight: 500; }
.nftc-rare { font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 999px; background: var(--ink); color: #fff; }
.nftc-label { font-size: 11px; color: var(--muted); margin-top: 4px; }
.nftc-price { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.nftc-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.nftc-stats span { display: flex; flex-direction: column; padding: 6px 8px; border-radius: 9px; background: var(--bg); font-size: 12px; font-weight: 600; }
.nftc-stats em { font-style: normal; font-size: 10px; font-weight: 500; color: var(--muted); }
.nftc-link { display: block; padding: 10px 12px; border-top: 1px solid var(--line-2); font-size: 13px; font-weight: 500; text-decoration: none; text-align: center; }
.nftc-link:hover { background: var(--soft); }

/* ---------- меню сообщения */
.msg-menu-modal { gap: 12px; }
.msg-menu-preview { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--bg); font-size: 14px; line-height: 1.4; }
.msg-menu-preview.out { background: var(--accent-soft); }
.msg-menu-preview .muted { font-size: 12px; }
.msg-menu { display: flex; flex-direction: column; }
.bubble { user-select: text; }
.nftc-stats span:last-child:nth-child(odd) { grid-column: span 2; }

/* ---------- статистика */
.modal.stats-modal { width: 980px; }
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat-tile { padding: 14px; border-radius: 14px; background: var(--bg); display: flex; flex-direction: column; gap: 4px; }
.stat-tile:first-child { background: var(--ink); color: #fff; }
.stat-tile:first-child .stat-label, .stat-tile:first-child .stat-sub { color: #B9B9BE; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat-days { display: flex; align-items: flex-end; gap: 6px; height: 130px; padding: 8px 4px 0; border-bottom: 1px solid var(--line-2); overflow-x: auto; }
.stat-day { flex: 1 0 22px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 3px; }
.stat-bar { width: 70%; max-width: 34px; min-height: 4px; border-radius: 5px 5px 2px 2px; background: var(--accent); }
.stat-day-n { font-size: 11px; font-weight: 600; }
.stat-day-d { font-size: 10px; color: var(--muted); padding-bottom: 4px; }
.stat-table { display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 14px; overflow: hidden; font-size: 13px; }
.stat-row { display: grid; grid-template-columns: minmax(160px, 1.5fr) repeat(7, minmax(70px, 1fr)) minmax(90px, 1.1fr); gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
.stat-row:last-child { border-bottom: 0; }
.stat-row.head { background: var(--soft); font-size: 11px; font-weight: 600; color: var(--muted); }
.stat-name { display: flex; flex-direction: column; min-width: 0; }
.stat-name em { font-style: normal; font-size: 11px; color: var(--muted); }
@media (max-width: 760px) {
  .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 20px; }
  .stat-row.head { display: none; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; }
  .stat-row .stat-name { grid-column: 1 / -1; margin-bottom: 4px; }
  .stat-row span[data-l]::before { content: attr(data-l) ": "; color: var(--muted); }
}

/* ---------- умные подсказки */
.suggest-bar { flex: 0 0 auto; display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px 8px 14px; border-top: 1px solid var(--line-2); background: #FFF8E6; }
.suggest-ico { font-size: 16px; line-height: 34px; }
.suggest-items { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.suggest-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left; padding: 7px 11px; border-radius: 12px; border: 1px solid #F1DFAE; background: #fff; cursor: pointer; font: inherit; color: var(--ink); }
.suggest-item:hover { border-color: #E4C56F; }
.suggest-item b { font-size: 11px; font-weight: 600; color: #9A7414; }
.suggest-item span { font-size: 14px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.sm-num { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.sm-num.off { opacity: .4; pointer-events: none; }
.sm-try { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 14px; background: var(--bg); }
.sm-result { font-size: 14px; color: var(--muted); padding: 10px 12px; border-radius: 12px; background: var(--surface); white-space: pre-wrap; }
.sm-result.ok { color: var(--ink); border-left: 3px solid #E4C56F; }
@media (max-width: 760px) { .sm-num { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field .hint { font-size: 12px; color: var(--muted); }
