/* Личка — «письменный стол»: бумага, чернила, сургуч.
   Literata — буквы письма, Onest — интерфейс. */
:root {
  --paper: #f4efe6;        /* стол */
  --sheet: #fffcf6;        /* лист */
  --sheet-2: #faf5ec;
  --ink: #211d18;
  --ink-2: #5e574d;
  --ink-3: #9a9185;
  --line: #e7dfd1;
  --line-2: #d9cfbf;
  --wax: #c8472b;          /* сургуч: отправка */
  --wax-deep: #a53a21;
  --wax-soft: #f8e6df;
  --moss: #2f5d50;         /* чернила-мох: генерация, выбор */
  --moss-deep: #234a3f;
  --moss-soft: #e2ebe6;
  --gold: #b27d22;         /* черновик */
  --gold-soft: #f6ecd6;
  --tg-wall: #d6e2cf;
  --tg-out: #effdde;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow-1: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 1px 2px rgba(60, 45, 20, .06);
  --shadow-2: 0 1px 2px rgba(60, 45, 20, .05), 0 8px 24px -6px rgba(60, 45, 20, .12);
  --shadow-3: 0 24px 60px -12px rgba(40, 30, 15, .35);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ui: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Literata", Georgia, "Times New Roman", serif;
  --top-h: 64px;
}

* { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 14.5px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  background-color: var(--paper);
  /* едва заметная фактура стола */
  background-image: radial-gradient(rgba(120, 100, 70, .07) 1px, transparent 1px);
  background-size: 22px 22px;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--moss); }
svg { width: 18px; height: 18px; flex: none; }
::selection { background: #f1d3c7; }

/* ── кнопки ─────────────────────────────── */
.btn {
  --bg: var(--sheet); --fg: var(--ink); --bd: var(--line-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--bd); background: var(--bg); color: var(--fg);
  font-weight: 600; font-size: 14px; letter-spacing: -.005em; white-space: nowrap;
  text-decoration: none; box-shadow: var(--shadow-1);
  transition: transform .15s var(--ease), background .2s, border-color .2s, box-shadow .2s, color .2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.btn:active { transform: translateY(0) scale(.97); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.btn.quiet { --bg: transparent; --bd: transparent; box-shadow: none; color: var(--ink-2); }
.btn.quiet:hover { --bg: rgba(90, 70, 40, .07); color: var(--ink); box-shadow: none; }
.btn.ink { --bg: var(--ink); --fg: #fbf7ef; --bd: var(--ink); }
.btn.ink:hover { --bg: #3a342c; }
.btn.moss { --bg: var(--moss); --fg: #f3f8f5; --bd: var(--moss); }
.btn.moss:hover { --bg: var(--moss-deep); }
.btn.moss svg { transition: transform .5s var(--ease); }
.btn.moss:hover svg { transform: rotate(72deg) scale(1.1); }
.btn.wax {
  --bg: var(--wax); --fg: #fff7f3; --bd: var(--wax-deep);
  height: 46px; padding: 0 26px; font-size: 15px; border-radius: 12px;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .14), transparent);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 6px 16px -6px rgba(168, 58, 33, .7);
}
.btn.wax:hover { --bg: var(--wax-deep); }
.btn.wax svg { transition: transform .35s var(--ease); }
.btn.wax:hover svg { transform: translate(3px, -3px); }
.btn.big { height: 48px; padding: 0 24px; font-size: 15px; }
.btn.busy { pointer-events: none; }
.btn.busy svg { animation: spin 1s linear infinite; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink-2);
  transition: background .2s, color .2s, transform .15s var(--ease);
}
.icon-btn:hover { background: rgba(90, 70, 40, .08); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 8px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.xs { width: 24px; height: 24px; border-radius: 6px; }
.icon-btn.xs svg { width: 14px; height: 14px; }
.icon-btn.danger:hover { color: var(--wax); background: var(--wax-soft); }
.icon-btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.only-mobile { display: none !important; }

/* ── поля ─────────────────────────────── */
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; height: 42px; padding: 0 13px;
  border: 1px solid var(--line-2); border-radius: 10px; background: #fff;
  outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
textarea { height: auto; padding: 11px 13px; resize: vertical; line-height: 1.55; }
select {
  appearance: none; padding-right: 34px; cursor: pointer; font-weight: 500;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6' fill='none' stroke='%235e574d' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 11px center / 16px;
}
input:hover, select:hover, textarea:hover { border-color: #c9bda9; }
input:focus, select:focus, textarea:focus { border-color: var(--moss); box-shadow: 0 0 0 4px rgba(47, 93, 80, .12); }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input[type=checkbox] { accent-color: var(--moss); width: 16px; height: 16px; margin: 0; }

/* ── верхняя панель ─────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--top-h); display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: rgba(244, 239, 230, .82);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark img { display: block; border-radius: 9px; box-shadow: 0 4px 12px -4px rgba(36, 30, 20, .4); }
.brand-name { font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.account-chip {
  display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 14px 0 6px;
  margin-right: 8px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--sheet);
  font-weight: 600; box-shadow: var(--shadow-1); transition: box-shadow .2s, transform .15s var(--ease);
}
.account-chip:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); }
.account-chip .avatar { width: 28px; height: 28px; font-size: 11px; }
.account-chip .meter { display: flex; flex-direction: column; gap: 3px; min-width: 64px; }
.account-chip .meter small { font-size: 11px; font-weight: 500; color: var(--ink-3); line-height: 1; }
.account-chip .meter i { display: block; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; }
.account-chip .meter i b { display: block; height: 100%; background: var(--moss); border-radius: inherit; transition: width .6s var(--ease); }
.account-chip .meter i b.hot { background: var(--wax); }
.account-chip.off { color: var(--wax); border-color: #efc6b8; background: var(--wax-soft); padding-left: 14px; }
.account-chip .state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--wax); box-shadow: 0 0 0 4px rgba(200, 71, 43, .15); animation: pulse 2s infinite; }

.notice {
  max-width: 1440px; margin: 16px auto 0; padding: 12px 16px;
  width: calc(100% - 48px);
  background: var(--gold-soft); color: #7a5412; border: 1px solid #ecd9ad;
  border-radius: var(--r); font-size: 13.5px; line-height: 1.5;
}

/* ── пустое состояние ─────────────────── */
.welcome {
  max-width: 560px; margin: 8vh auto 40px; padding: 0 24px; text-align: center;
  animation: rise .6s var(--ease) both;
}
.welcome-art svg { width: 220px; height: 150px; }
.welcome-letter { animation: letter 3.2s var(--ease) infinite; }
.welcome h1 { font-family: var(--serif); font-weight: 500; font-size: 36px; letter-spacing: -.02em; margin: 18px 0 10px; }
.welcome p { color: var(--ink-2); font-size: 15.5px; margin: 0 auto 26px; max-width: 440px; }
.welcome-steps { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-bottom: 30px; }
.welcome-steps div {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--sheet); font-size: 13px; color: var(--ink-2);
}
.welcome-steps b {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--paper); font-size: 11.5px; color: var(--ink);
}

/* ── стол: список + лист ────────────────── */
.desk {
  max-width: 1440px; margin: 0 auto; padding: 20px 24px 32px;
  display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start;
}

.roster {
  position: sticky; top: calc(var(--top-h) + 20px);
  height: calc(100vh - var(--top-h) - 40px); min-height: 420px;
  display: flex; flex-direction: column;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); overflow: hidden;
}
.roster-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.base-pick { display: flex; align-items: center; gap: 4px; }
.base-pick select { flex: 1; min-width: 0; height: 40px; font-family: var(--serif); font-size: 15.5px; font-weight: 600; border-color: transparent; background-color: transparent; padding-left: 6px; }
.base-pick select:hover { background-color: var(--sheet-2); border-color: var(--line); }
.base-tools { display: flex; }

.progress { display: grid; gap: 6px; padding: 0 4px; }
.progress-bar { display: flex; height: 6px; border-radius: 6px; overflow: hidden; background: var(--line); }
.progress-bar i { display: block; height: 100%; transition: width .6s var(--ease); }
.progress-bar .p-sent { background: var(--moss); }
.progress-bar .p-draft { background: var(--gold); }
.progress-bar .p-error { background: var(--wax); }
.progress-bar .p-skip { background: var(--line-2); }
.progress-text { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); }
.progress-text b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
#search { height: 38px; padding-left: 36px; background: var(--sheet-2); border-color: var(--line); }

.filters { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 0 -2px; padding: 0 2px; }
.filters::-webkit-scrollbar { display: none; }
.filters button {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border-radius: 999px; border: 1px solid transparent; background: transparent;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2); transition: background .2s, color .2s;
}
.filters button:hover { background: rgba(90, 70, 40, .07); }
.filters button.on { background: var(--ink); color: #fbf7ef; }
.filters b { font-weight: 600; font-size: 11.5px; opacity: .6; font-variant-numeric: tabular-nums; }
.filters .fdot { width: 6px; height: 6px; border-radius: 50%; }

.client-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; scroll-padding: 8px; }
.client-list li {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: 11px; cursor: pointer;
  transition: background .15s;
}
.client-list li::before {
  content: ""; position: absolute; left: -6px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--wax); transform: scaleY(0); transition: transform .25s var(--ease);
}
.client-list li:hover { background: var(--sheet-2); }
.client-list li.active { background: #f3ece0; }
.client-list li.active::before { transform: scaleY(1); }
.client-list .who { min-width: 0; flex: 1; }
.client-list .who div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-list .nm { font-weight: 600; font-size: 14px; }
.client-list .ch { color: var(--ink-3); font-size: 12.5px; }
.client-list .ch.none { font-style: italic; }
.client-list .n { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.client-list li.done .nm { color: var(--ink-2); }
.list-note { color: var(--ink-3); font-size: 13px; padding: 24px 12px; text-align: center; cursor: default !important; }

/* статус: точка в углу аватара */
.avatar {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 13px; font-weight: 700; letter-spacing: .02em; color: #fff;
  background: var(--av, #8a7f6f);
}
.avatar.lg { width: 52px; height: 52px; font-size: 18px; font-family: var(--serif); font-weight: 600; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar[data-st]::after {
  content: ""; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--sheet); background: var(--ink-3);
}
.avatar[data-st="new"]::after { display: none; }
.avatar[data-st="draft"]::after { background: var(--gold); }
.avatar[data-st="sent"]::after { background: var(--moss); }
.avatar[data-st="error"]::after { background: var(--wax); }
.avatar[data-st="skip"] { filter: grayscale(1) opacity(.5); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--paper); color: var(--ink-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill.draft { background: var(--gold-soft); color: #8a5f14; }
.pill.sent { background: var(--moss-soft); color: var(--moss); }
.pill.error { background: var(--wax-soft); color: var(--wax-deep); }

/* ── лист ─────────────────────────────── */
.sheet {
  position: relative; min-height: calc(100vh - var(--top-h) - 40px);
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); display: flex; flex-direction: column;
}
.sheet-empty { margin: auto; color: var(--ink-3); font-family: var(--serif); font-style: italic; font-size: 17px; }
.sheet-body { display: flex; flex-direction: column; flex: 1; }
.sheet-body.swap .client-head, .sheet-body.swap .work { animation: rise .35s var(--ease) both; }
.sheet-body.swap .work { animation-delay: .04s; }

.client-head { display: flex; align-items: center; gap: 14px; padding: 22px 26px 18px; }
.client-id { min-width: 0; flex: 1; }
.client-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.client-title h2 {
  margin: 0; font-family: var(--serif); font-size: 25px; font-weight: 600; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.client-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin-top: 3px; color: var(--ink-3); font-size: 13px; }
#position { white-space: nowrap; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-3); }
.link-ext { display: inline-flex; align-items: center; gap: 4px; color: var(--moss); font-weight: 500; text-decoration: none; }
.link-ext svg { width: 13px; height: 13px; opacity: .6; transition: transform .2s var(--ease); }
.link-ext:hover svg { transform: translate(2px, -2px); opacity: 1; }
.link-ext[aria-disabled="true"] { color: var(--ink-3); pointer-events: none; }
.link-ext[aria-disabled="true"] svg { display: none; }
.nav { display: flex; gap: 2px; background: var(--sheet-2); border: 1px solid var(--line); border-radius: 12px; padding: 2px; }
.nav .icon-btn { width: 34px; height: 34px; }

.client-extra {
  margin: -4px 26px 14px; padding: 10px 14px; border-radius: 10px; background: var(--sheet-2);
  border: 1px dashed var(--line-2); color: var(--ink-2); font-size: 13px; white-space: pre-wrap;
}

.work { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 26px; padding: 4px 26px 24px; flex: 1; }
.compose { display: grid; gap: 22px; align-content: start; min-width: 0; }

.step-label {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3);
}
.step-num {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--line-2); font-size: 11px; letter-spacing: 0; color: var(--ink-2);
  transition: background .3s, border-color .3s, color .3s;
}
.step.done .step-num { background: var(--moss); border-color: var(--moss); color: #fff; }
.step.done .step-num { font-size: 0; }
.step.done .step-num::after { content: "✓"; font-size: 12px; }
.input-row { display: flex; gap: 6px; }
.input-row .icon-btn { width: 42px; height: 42px; border: 1px solid var(--line-2); background: #fff; }

.attach { cursor: pointer; }
.attach:hover { color: var(--moss); border-color: var(--moss); }
.export-chip {
  display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 7px 8px 7px 12px;
  border-radius: 10px; background: var(--moss-soft); color: var(--moss-deep); font-size: 13px;
  animation: rise .3s var(--ease) both;
}
.export-chip svg { width: 15px; height: 15px; }
.export-chip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.export-chip span b { font-weight: 600; }
.export-chip .icon-btn { color: var(--moss-deep); }
.drop-hint { margin-top: 6px; font-size: 12px; color: var(--ink-3); }
#stepChannel { border-radius: 14px; transition: background .2s, box-shadow .2s; }
#stepChannel.over { background: var(--moss-soft); box-shadow: 0 0 0 8px var(--moss-soft); }
.token-info { margin-right: auto; margin-left: 12px; }
.gen-bar { display: flex; gap: 8px; }
.gen-bar input { flex: 1; }
.gen-bar .btn { height: 42px; }
.refresh {
  display: inline-flex; align-items: center; gap: 6px; margin: 8px 0 12px 2px;
  font-size: 12.5px; color: var(--ink-3); cursor: pointer; user-select: none;
}
.refresh svg { width: 13px; height: 13px; }
.refresh:hover { color: var(--ink-2); }

/* бумага для письма */
.paper {
  position: relative; border-radius: 14px; border: 1px solid var(--line-2); background: #fff;
  box-shadow: 0 1px 2px rgba(60, 45, 20, .04), 0 12px 28px -18px rgba(60, 45, 20, .35);
  transition: border-color .2s, box-shadow .2s;
}
.paper:focus-within { border-color: var(--moss); box-shadow: 0 0 0 4px rgba(47, 93, 80, .1), 0 12px 28px -18px rgba(60, 45, 20, .35); }
.paper textarea {
  display: block; border: 0; box-shadow: none !important; background: transparent;
  min-height: 260px; padding: 20px 22px 8px; border-radius: 14px 14px 0 0;
  font-family: var(--serif); font-size: 16.5px; line-height: 1.75; color: var(--ink);
  transition: opacity .3s;
}
.paper-foot {
  display: flex; justify-content: space-between; gap: 12px; padding: 8px 22px 12px;
  font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.paper-foot .warn { color: var(--wax); font-weight: 600; }
.kbd-hint { opacity: .8; }

.paper-loading {
  position: absolute; inset: 0; display: none; flex-direction: column; justify-content: center; gap: 18px;
  padding: 26px; border-radius: 14px; background: rgba(255, 255, 255, .7);
}
.paper.loading textarea { opacity: .12; }
.paper.loading .paper-loading { display: flex; animation: fade .25s both; }
.skeleton { display: grid; gap: 12px; }
.skeleton i {
  display: block; height: 11px; border-radius: 6px;
  background: linear-gradient(90deg, #f1eadf 0%, #e6dccb 40%, #f1eadf 80%);
  background-size: 250% 100%; animation: shimmer 1.4s linear infinite;
}
.skeleton i:nth-child(1) { width: 92%; }
.skeleton i:nth-child(2) { width: 100%; animation-delay: .1s; }
.skeleton i:nth-child(3) { width: 84%; animation-delay: .2s; }
.skeleton i:nth-child(4) { width: 96%; animation-delay: .3s; }
.skeleton i:nth-child(5) { width: 58%; animation-delay: .4s; }
.gen-status { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 500; color: var(--moss); }
.gen-status::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--moss-soft); border-top-color: var(--moss); animation: spin .8s linear infinite;
}

.flash { padding: 11px 14px; border-radius: 11px; font-size: 13.5px; animation: rise .3s var(--ease) both; }
.flash.ok { background: var(--moss-soft); color: var(--moss-deep); }
.flash.bad { background: var(--wax-soft); color: var(--wax-deep); }

/* ── превью: так увидит клиент ─────────── */
.preview { display: grid; gap: 14px; align-content: start; position: sticky; top: calc(var(--top-h) + 40px); }
.preview-label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.phone {
  border-radius: 20px; overflow: hidden; border: 1px solid var(--line-2);
  background: var(--tg-wall); box-shadow: 0 18px 40px -22px rgba(40, 60, 30, .5);
}
.phone-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: rgba(255, 255, 255, .92); border-bottom: 1px solid rgba(0, 0, 0, .05);
}
.pv-name { font-weight: 600; font-size: 13.5px; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-status { font-size: 11.5px; color: #8a9a86; }
.phone-chat {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 300px; max-height: 480px; overflow: hidden; padding: 16px 12px;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, .35) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, .3) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 40% 85%, rgba(255, 255, 255, .25) 0 2px, transparent 3px);
  background-size: 60px 60px, 80px 80px, 70px 70px;
}
.bubble {
  align-self: flex-end; max-width: 92%; position: relative;
  padding: 7px 10px 6px 11px; border-radius: 14px 14px 4px 14px;
  background: var(--tg-out); box-shadow: 0 1px 1px rgba(0, 0, 0, .12);
  font-size: 13.5px; line-height: 1.42; color: #111; overflow-wrap: anywhere;
  transform-origin: 100% 100%; animation: pop .35s var(--ease) both;
}
.bubble-text { white-space: pre-wrap; }
.bubble-meta {
  float: right; display: inline-flex; align-items: center; gap: 3px;
  margin: 6px 0 -3px 10px; font-size: 11px; color: #5fa15a;
}
.bubble-meta svg { width: 15px; height: 15px; }
.bubble.fly { animation: fly .7s cubic-bezier(.5, 0, .75, 0) forwards; }
.pv-empty { text-align: center; color: #6f8269; font-size: 12.5px; font-style: italic; padding: 40px 0; }

.channel-card {
  border: 1px solid var(--line); border-radius: 14px; background: var(--sheet-2); padding: 14px;
  font-size: 13px; animation: rise .3s var(--ease) both;
}
.cc-head { display: flex; align-items: center; gap: 10px; }
.cc-title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.cc-meta { color: var(--ink-3); font-size: 12px; }
.cc-note { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--gold-soft); color: #7a5412; font-size: 12.5px; }
.cc-about { margin: 10px 0 0; color: var(--ink-2); white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.channel-card details { margin-top: 10px; }
.channel-card summary { cursor: pointer; color: var(--moss); font-weight: 500; font-size: 12.5px; list-style: none; }
.channel-card summary::-webkit-details-marker { display: none; }
.channel-card summary::after { content: " ↓"; }
.channel-card details[open] summary::after { content: " ↑"; }
.cc-posts { max-height: 300px; overflow-y: auto; margin-top: 8px; display: grid; gap: 8px; }
.cc-post { padding: 8px 10px; background: #fff; border-radius: 8px; border: 1px solid var(--line); color: var(--ink-2); font-size: 12.5px; white-space: pre-wrap; }
.cc-post b { display: block; color: var(--ink-3); font-weight: 500; font-size: 11px; margin-bottom: 2px; }

/* ── отправка ─────────────────────────── */
.dispatch {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 14px 26px;
  background: rgba(255, 252, 246, .9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.dispatch-from { margin-right: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-3); min-width: 0; }
.dispatch-from b { color: var(--ink); font-weight: 600; }
.dispatch-from .avatar { width: 28px; height: 28px; font-size: 11px; }

/* ── диалоги ─────────────────────────── */
.dlg {
  border: none; border-radius: 22px; padding: 0; width: min(500px, calc(100vw - 24px));
  max-height: calc(100vh - 32px); background: var(--sheet); color: var(--ink); box-shadow: var(--shadow-3);
}
.dlg.wide { width: min(800px, calc(100vw - 24px)); }
.dlg[open] { animation: dlg-in .3s var(--ease) both; }
.dlg::backdrop { background: rgba(33, 29, 24, .35); backdrop-filter: blur(3px); }
.dlg-body { padding: 22px 26px 24px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 14px 0; }
.dlg h2 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.dlg h3 { margin: 22px 0 10px; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.dlg-lead { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dlg-error { color: var(--wax-deep); font-size: 13px; min-height: 18px; margin-top: 10px; }
.rules-text { font-family: var(--serif); font-size: 15px; line-height: 1.7; padding: 16px 18px; min-height: 340px; }

.import-src { display: grid; grid-template-columns: 1fr auto 1.35fr; gap: 14px; align-items: stretch; }
.drop {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px;
  min-height: 150px; padding: 18px; border-radius: 14px; cursor: pointer; text-align: center;
  border: 1.5px dashed var(--line-2); background: var(--sheet-2); color: var(--ink-3); font-size: 13px;
  transition: border-color .2s, background .2s, transform .2s var(--ease);
}
.drop svg { width: 26px; height: 26px; color: var(--moss); margin-bottom: 4px; transition: transform .3s var(--ease); }
.drop strong { color: var(--ink); font-weight: 600; font-size: 14px; }
.drop:hover svg, .drop.over svg { transform: translateY(-3px); }
.drop:hover { border-color: var(--moss); }
.drop.over { border-color: var(--moss); background: var(--moss-soft); transform: scale(1.01); }
.drop input { display: none; }
.or { display: grid; place-items: center; color: var(--ink-3); font-size: 12px; }
#pasteInput { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; min-height: 150px; }
.map-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0 10px; }
.map-row label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; margin-bottom: 12px; }
.preview-table { overflow: auto; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; max-height: 240px; background: #fff; }
.preview-table table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.preview-table th, .preview-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.preview-table th { background: var(--sheet-2); font-weight: 600; color: var(--ink-3); position: sticky; top: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.preview-table td.bad { color: var(--wax); }
.preview-table .sum { padding: 9px 10px; color: var(--ink-2); font-size: 12.5px; background: var(--sheet-2); }
.field { display: block; }
.field > span { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }

.accounts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.accounts li {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px;
  border: 1px solid var(--line); background: #fff; transition: border-color .2s;
}
.accounts li.active { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(47, 93, 80, .08); }
.accounts li .info { flex: 1; min-width: 0; }
.accounts li .info strong { display: block; }
.accounts li .info small { display: block; color: var(--ink-3); font-size: 12.5px; }
.accounts li .info small.err { color: var(--wax-deep); }
.accounts .acc-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.accounts .acc-actions .btn { height: 32px; padding: 0 10px; font-size: 12.5px; }
.accounts .badge-on { font-size: 11.5px; font-weight: 600; color: var(--moss); background: var(--moss-soft); padding: 3px 8px; border-radius: 999px; }
.accounts .none { justify-content: center; color: var(--ink-3); border-style: dashed; background: transparent; }
.dlg-foot { margin: 16px 2px 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-3); }

/* ── вход ─────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center;
  padding: 34px 30px 28px; border-radius: 24px; background: var(--sheet); border: 1px solid var(--line);
  box-shadow: var(--shadow-3); animation: rise .5s var(--ease) both;
}
.login-card img { align-self: center; border-radius: 12px; box-shadow: 0 8px 20px -8px rgba(36, 30, 20, .5); }
.login-card h1 { margin: 8px 0 0; font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
.login-card p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; }
.login-card .btn { height: 46px; }
.login-error { color: var(--wax-deep); font-size: 13px; min-height: 18px; }

/* ── тост ─────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  max-width: min(480px, calc(100vw - 32px)); padding: 12px 18px 12px 14px;
  background: var(--ink); color: #fbf7ef; border-radius: 14px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-3); animation: toast-in .35s var(--ease) both;
}
.toast::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: #8fd1a8; }
.toast.bad::before { background: #ff9a80; }

/* ── движение ─────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.92) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fly { 30% { transform: translate(-6px, 4px) scale(.98); } 100% { opacity: 0; transform: translate(40px, -260px) rotate(-8deg) scale(.6); } }
@keyframes dlg-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(200, 71, 43, 0); } }
@keyframes letter { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.toast { transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ── адаптив ─────────────────────────── */
@media (max-width: 1180px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .preview-label { grid-column: 1 / -1; }
  .phone-chat { min-height: 200px; }
}

@media (max-width: 900px) {
  :root { --top-h: 58px; }
  .only-mobile { display: inline-grid !important; }
  .topbar { padding: 0 12px 0 16px; gap: 8px; }
  .brand-name { display: none; }
  .top-actions { gap: 0; }
  .top-actions .icon-btn, .top-actions .btn { width: 38px; }
  .top-actions .btn span { display: none; }
  .top-actions .btn { width: 40px; padding: 0; }
  .account-chip { margin-right: 2px; padding-right: 10px; }
  .account-chip .meter { min-width: 0; max-width: 104px; }
  .account-chip .meter small { white-space: nowrap; }
  .account-chip .acc-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #listToggle { order: -1; margin-left: -6px; }
  .notice { width: calc(100% - 32px); }

  .desk { grid-template-columns: 1fr; padding: 12px 12px 0; }
  /* список уезжает в выдвижную панель */
  .roster {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; height: auto; min-height: 0;
    width: min(360px, 88vw); border-radius: 0 20px 20px 0; border-left: 0;
    transform: translateX(-105%); transition: transform .35s var(--ease);
    padding-top: env(safe-area-inset-top);
  }
  body.list-open .roster { transform: none; box-shadow: var(--shadow-3); }
  .scrim {
    position: fixed; inset: 0; z-index: 39; background: rgba(33, 29, 24, .35);
    opacity: 0; pointer-events: none; transition: opacity .3s;
  }
  body.list-open .scrim { opacity: 1; pointer-events: auto; }
  body.list-open { overflow: hidden; }

  .sheet { min-height: calc(100vh - var(--top-h) - 12px); border-radius: 18px 18px 0 0; border-bottom: 0; }
  .client-head { padding: 18px 16px 14px; gap: 12px; }
  .avatar.lg { width: 44px; height: 44px; font-size: 16px; }
  .client-title h2 { font-size: 21px; }
  .client-extra { margin: -2px 16px 12px; }
  .work { padding: 4px 16px 20px; gap: 22px; }
  .preview { grid-template-columns: 1fr; }
  .phone { display: none; }
  .preview-label { display: none; }
  .kbd-hint { display: none; }

  input:not([type=checkbox]):not([type=file]), select, textarea { font-size: 16px; height: 46px; }
  textarea { height: auto; }
  .gen-bar { flex-direction: column; }
  .gen-bar input { flex: none; }
  .nav { flex-direction: column; }
  .nav .icon-btn { width: 36px; height: 32px; }
  .gen-bar .btn { height: 46px; }
  .input-row .icon-btn { width: 46px; height: 46px; }
  .paper textarea { font-size: 17px; min-height: 240px; padding: 16px 16px 6px; }
  .paper-foot { padding: 6px 16px 10px; }

  .dispatch {
    position: sticky; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-radius: 0; margin: 0 -1px;
  }
  .dispatch-from { display: none; }
  .dispatch .btn.quiet { flex: none; height: 48px; }
  .dispatch .btn.wax { flex: 1; height: 50px; }

  .dlg { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  .dlg.wide { width: 100vw; }
  .dlg[open] { animation: sheet-up .35s var(--ease) both; }
  .dlg-body { padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); }
  .import-src { grid-template-columns: 1fr; }
  .drop { min-height: 110px; }
  .map-row { grid-template-columns: 1fr; }
  .accounts li { flex-wrap: wrap; }
  .accounts .acc-actions { width: 100%; justify-content: flex-start; }

  .welcome { margin-top: 6vh; }
  .welcome h1 { font-size: 30px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
