/* ---------------------------------------------------------------
   Степан · админка бота Авито по керамограниту
   Палитра: тёплый камень + графит + терракота
---------------------------------------------------------------- */
:root {
  --topbar-bg: rgba(244, 241, 236, .86);
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1c2126;
  --ink-2: #3d454d;
  --muted: #7a8189;
  --line: #e5e0d8;
  --line-2: #efebe4;
  --accent: #b8563a;
  --accent-soft: #fbeee9;
  --green: #2f7a5f;
  --green-soft: #e9f5ef;
  --amber: #b07818;
  --amber-soft: #fdf4e2;
  --blue: #2b5f8f;
  --blue-soft: #eaf2fa;
  --sidebar: #191d22;
  --sidebar-2: #232830;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(24, 20, 16, .05), 0 8px 24px -12px rgba(24, 20, 16, .18);
  --shadow-lg: 0 24px 60px -20px rgba(24, 20, 16, .35);
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15.5px; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------------------------- вход ---------------------------- */
.pin-label { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 10px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 6px; }
.pin-dots i {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid #ccc4b8; background: transparent;
  transition: background .15s, border-color .15s, transform .12s;
}
.pin-dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.08); }
.pin-dots.err i { border-color: #b3261e; background: #b3261e; animation: pinShake .28s; }
@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.pin-pad button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 13px 0;
  font-size: 18px; font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, transform .06s;
}
.pin-pad button:hover { background: #f0ebe3; }
.pin-pad button:active { transform: scale(.97); }
.pin-pad .pin-ghost { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.pin-hidden { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 0%, #3a444f 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 100%, #4b2c22 0%, transparent 65%),
    #15181c;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.login-title { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 13px; }
.logo-mark {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #c2683f, #8e3f28);
  color: #fff; font-weight: 700; font-size: 19px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
  flex: none;
}
.login-error { color: #b3261e; font-size: 13px; min-height: 18px; margin-top: 8px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------------------------- каркас ---------------------------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--sidebar);
  color: #cfd4da;
  display: flex; flex-direction: column;
  padding: 18px 14px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #fff; font-size: 15px; letter-spacing: -.01em; }
.brand-text span { font-size: 11.5px; color: #8b939c; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.6px;
  color: #b6bdc5;
  transition: background .15s, color .15s;
}
.nav a svg { width: 17px; height: 17px; fill: currentColor; opacity: .8; flex: none; }
.nav a:hover { background: #262c34; color: #fff; }
.nav a.active { background: #2f3742; color: #fff; }
.nav a.active svg { opacity: 1; color: #e2a184; }
.nav-sep {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: #6c757e; padding: 14px 10px 5px;
}
.nav-badge:not(:empty) {
  margin-left: auto;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600;
  border-radius: 20px; padding: 1px 7px;
}
.sidebar-foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.balance-mini {
  background: #232a32; border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: #9aa3ac;
}
.balance-mini strong { color: #fff; font-size: 14px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 20px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.page-sub { color: var(--muted); font-size: 12.8px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--green-soft); color: var(--green);
  border-radius: 20px; padding: 5px 12px; font-size: 12.5px; font-weight: 600;
}
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pill.off { background: #fbeceb; color: #b3261e; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ink); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}

.view { padding: 22px 28px 40px; }

/* ---------------------------- общее ---------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line-2);
}
.card-head h2 { font-size: 14.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grid { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.4px; font-weight: 550;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #d8d2c8; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #a44c33; border-color: #a44c33; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #2b3238; }
.btn-ghost { background: transparent; border-color: #333c46; color: #b8c0c8; }
.btn-ghost:hover { background: #262d35; color: #fff; }
.btn-small { padding: 5px 10px; font-size: 12.4px; }
.btn-full { width: 100%; padding: 11px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 15px; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--line-2); color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field > span { font-size: 12.4px; font-weight: 600; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-family: inherit; font-size: 13.6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: #c9a08f; box-shadow: 0 0 0 3px rgba(184, 86, 58, .12);
}
.field .hint { font-size: 11.6px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.6px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  background: var(--line-2); color: var(--ink-2);
}
.tag-green { background: var(--green-soft); color: var(--green); }
.tag-amber { background: var(--amber-soft); color: var(--amber); }
.tag-red { background: #fbeceb; color: #b3261e; }
.tag-blue { background: var(--blue-soft); color: var(--blue); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

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

/* ---------------------------- KPI ---------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 16px 14px;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--accent); opacity: .9;
}
.kpi.green::after { background: var(--green); }
.kpi.blue::after { background: var(--blue); }
.kpi.amber::after { background: var(--amber); }
.kpi-label { font-size: 12.2px; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 27px; font-weight: 700; letter-spacing: -.03em; margin-top: 4px; }
.kpi-foot { font-size: 11.8px; color: var(--muted); margin-top: 2px; }

.chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding: 10px 4px 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart-bar { width: 12px; border-radius: 4px 4px 2px 2px; background: var(--ink); min-height: 3px; transition: height .3s; }
.chart-bar.lead { background: var(--accent); }
.chart-x { font-size: 10.5px; color: var(--muted); }

.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* ---------------------------- таблицы ---------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 13.2px; }
th {
  text-align: left; font-size: 11.6px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* ---------------------------- диалоги ---------------------------- */
.dialogs-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 16px;
  align-items: stretch;
  height: calc(100vh - 150px);
  min-height: 0;
}
.dialog-list { overflow-y: auto; height: 100%; }
/* переписка живёт в своей прокрутке: страница и список при этом не едут */
#chat-slot { display: flex; flex-direction: column; min-height: 0; height: 100%; overflow: hidden; padding: 0; }
#chat-slot > .chat-panel { flex: 1; min-height: 0; }
#chat-slot .chat-foot:last-child { max-height: 42%; overflow-y: auto; }
.dialog-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  transition: background .12s;
}
.dialog-item:hover { background: var(--surface-2); }
.dialog-item.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 12px; }
.dialog-item .di-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dialog-item .di-name { font-weight: 620; font-size: 13.6px; }
.dialog-item .di-time { font-size: 11px; color: var(--muted); }
.dialog-item .di-text {
  font-size: 12.4px; color: var(--muted); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.dialog-item .di-badges { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }

.chat-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line-2); flex: 0 0 auto; }
.chat-head .who { font-weight: 650; font-size: 14.5px; }
/* Экспорт переписки в шапке диалога: на телефоне кнопки переносятся под заголовок */
.export-btns { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.export-btns .small { white-space: nowrap; }
/* Видимая полоса ошибок на странице */
.js-error {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 9999;
  max-height: 40vh; overflow: auto; padding: 10px 14px; border-radius: 10px;
  background: #7f1d1d; color: #fff; font: 13px/1.45 ui-monospace, Consolas, monospace;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); white-space: pre-wrap;
}
.chat-scroll { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 18px; background: var(--surface-2); min-height: 0; }
.msg { display: flex; margin-bottom: 12px; }
.msg .bubble {
  max-width: 74%; padding: 10px 13px; border-radius: 13px;
  font-size: 13.4px; line-height: 1.48; white-space: pre-wrap; word-break: break-word;
}
.msg.client { justify-content: flex-start; }
.msg.client .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot { justify-content: flex-end; }
.msg.bot .bubble { background: #20262d; color: #eef1f4; border-bottom-right-radius: 4px; }
.msg.manager { justify-content: flex-end; }
.msg.manager .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.system { justify-content: center; }
.msg.system .bubble {
  background: transparent; color: var(--muted); font-size: 11.8px;
  border: 1px dashed var(--line); border-radius: 8px; max-width: 90%;
}
.msg-meta { font-size: 10.8px; color: var(--muted); margin-top: 5px; }
.msg.bot .msg-meta, .msg.manager .msg-meta { text-align: right; }
.chat-foot { border-top: 1px solid var(--line-2); padding: 12px 14px; background: var(--surface); flex: 0 0 auto; }
.chat-input { display: flex; gap: 9px; align-items: flex-end; }
.chat-input textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 120px;
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px;
  font-family: inherit; font-size: 13.6px; outline: none;
}
.chat-input textarea:focus { border-color: #c9a08f; box-shadow: 0 0 0 3px rgba(184, 86, 58, .12); }

.lead-panel { padding: 16px 18px; }
.lead-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line-2); font-size: 13px; }
.lead-row:last-child { border-bottom: none; }
.lead-row span { color: var(--muted); }
.lead-row strong { font-weight: 600; text-align: right; }

/* ---------------------------- база знаний ---------------------------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs button {
  border: none; background: transparent; cursor: pointer;
  padding: 9px 14px; font-size: 13.4px; font-weight: 570; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.sup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.sup-card { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.sup-card .sup-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.sup-card .sup-name { font-weight: 650; font-size: 14.5px; }
.sup-card .sup-about { font-size: 12.8px; color: var(--ink-2); line-height: 1.45; }
.sup-card .sup-site { font-size: 12px; color: var(--blue); word-break: break-all; }
.sup-card .sup-brands { display: flex; gap: 5px; flex-wrap: wrap; }
.sup-card .sup-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }

/* Фото плитки: превью в карточках, миниатюры в форме и в переписке */
.photo-strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.photo-strip img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-empty { width: 84px; height: 84px; border-radius: 8px; border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--ink-2); opacity: .65; }
.photo-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.photo-thumb { position: relative; width: 92px; height: 92px; }
.photo-thumb img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-del { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(20,22,25,.82); color: #fff; font-size: 12px; cursor: pointer; }
.msg-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.msg-photos img { width: 132px; height: 132px; object-fit: cover; border-radius: 8px; border: 1px solid rgba(0,0,0,.08); display: block; }

.rule-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-bottom: 1px solid var(--line-2);
}
.rule-item .num {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent); font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center; flex: none; margin-top: 1px;
}
.rule-item p { margin: 0; font-size: 13.2px; }

.faq-item { padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.faq-q { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.faq-a { font-size: 13px; color: var(--ink-2); }

/* ---------------------------- баланс ---------------------------- */
.balance-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 22px 24px;
  background: linear-gradient(120deg, #1d2228, #2c343d 60%, #3a2b24);
  color: #fff; border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.balance-hero .amount { font-size: 34px; font-weight: 700; letter-spacing: -.03em; }
.balance-hero .lbl { font-size: 12.2px; color: #a9b2bb; }
.tx-in { color: var(--green); font-weight: 650; }
.tx-out { color: var(--accent); font-weight: 650; }

/* ---------------------------- настройки ---------------------------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) {
  .settings-grid { grid-template-columns: 1fr; }
  .dialogs-layout { grid-template-columns: 1fr; height: auto; }
  .dialog-list { max-height: 320px; }
}

/* ---------------------------- всплывающее ---------------------------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 10px; font-size: 13.2px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b3261e; }

.modal { position: fixed; inset: 0; background: rgba(20, 24, 28, .45); display: grid; place-items: center; padding: 20px; z-index: 90; }
.modal-card {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------------------------- тест-чат ---------------------------- */
.test-layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .test-layout { grid-template-columns: 1fr; } }
.phone {
  border: 1px solid var(--line); border-radius: 20px; background: var(--surface);
  overflow: hidden; box-shadow: var(--shadow);
}
.phone-head {
  display: flex; align-items: center; gap: 11px; padding: 13px 16px;
  background: #20262d; color: #fff;
}
.phone-head .logo-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
.phone-head .n { font-weight: 650; font-size: 14px; }
.phone-head .s { font-size: 11.5px; color: #9aa3ac; }
.phone-body { height: 430px; overflow-y: auto; padding: 16px; background: #f0ede8; }
.quick-row { display: flex; gap: 7px; padding: 0 14px 10px; flex-wrap: wrap; }
.quick-chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 20px;
  padding: 5px 11px; font-size: 12.2px; cursor: pointer; color: var(--ink-2);
}
.quick-chip:hover { background: var(--accent-soft); border-color: #dcc0b4; color: var(--accent); }

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr !important; }
}

/* ---------------------------- мобильное: режим приложения ---------------------------- */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  body { -webkit-tap-highlight-color: transparent; }

  .app { grid-template-columns: 1fr; min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  /* боковое меню превращается в нижнюю панель приложения */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; width: 100%;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(25, 29, 34, .97);
    backdrop-filter: blur(12px);
    border-top: 1px solid #2c333b;
    z-index: 60;
  }
  .brand, .sidebar-foot, .nav-sep { display: none; }
  .nav {
    flex-direction: row; overflow-x: auto; gap: 2px;
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 0 0 auto; flex-direction: column; gap: 3px;
    padding: 7px 10px; border-radius: 12px;
    font-size: 12px; line-height: 1.2; white-space: nowrap;
  }
  .nav a svg { width: 20px; height: 20px; }
  .nav a.active { background: #2f3742; }
  /* в панели только главное, остальное под «Ещё» */
  .nav a.nav-extra { display: none !important; }
  .nav-more {
    display: flex; flex: 0 0 auto; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 10px; border: 0; border-radius: 12px; background: transparent;
    color: #9aa3ac; font: inherit; font-size: 12px; line-height: 1.2; white-space: nowrap; cursor: pointer;
  }
  .nav-more.active { background: #2f3742; color: #fff; }
  .nav-more svg { width: 20px; height: 20px; fill: currentColor; }
  .nav-more-list { display: flex; flex-direction: column; gap: 6px; }
  .nav-more-list a {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px;
    background: var(--surface-2); color: var(--ink); text-decoration: none; font-size: 14.5px;
  }
  .nav a { position: relative; }
  .nav-badge:not(:empty) { position: absolute; top: 3px; right: 5px; transform: none; margin: 0; padding: 0 5px; font-size: 10px; }

  .main { min-width: 0; }
  .topbar {
    position: sticky; top: 0; z-index: 30;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    gap: 10px;
  }
  .topbar h1 { font-size: 18px; }
  .page-sub { display: none; }
  .status-pill { display: none; }
  .avatar { width: 30px; height: 30px; font-size: 12px; }

  .view { padding: 12px 12px 20px; }

  /* всё в одну колонку, ничего не вылезает */
  .grid, .kpi-grid, .sup-grid, .settings-grid, .test-layout, .field-row { grid-template-columns: 1fr !important; }
  .kpi-value { font-size: 23px; }
  .card, .kpi { border-radius: 14px; }
  .card-pad, .card-head { padding: 14px; }

  /* таблицы не растягивают экран — прокручиваются внутри своей обёртки */
  .card { overflow: hidden; }
  .table-scroll { max-width: 100%; }
  /* история операций ужимается по экрану, сумма всегда видна */
  .table-scroll table { min-width: 0; width: 100%; font-size: 12.5px; }
  .table-scroll th { padding: 8px 6px; white-space: nowrap; font-size: 11.5px; }
  .table-scroll td { padding: 8px 6px; white-space: normal; word-break: break-word; }
  .table-scroll td:first-child { white-space: nowrap; }
  .table-scroll th:first-child, .table-scroll td:first-child { padding-left: 14px; }
  .table-scroll th:last-child, .table-scroll td:last-child { text-align: right; padding-right: 14px; white-space: nowrap; }


  /* диалоги: список экраном, чат отдельным экраном */
  .dialogs-layout { grid-template-columns: 1fr; height: auto; gap: 0; }
  .dialogs-layout .dialog-list { height: auto; max-height: none; }
  #chat-slot { display: none; }
  body.chat-open .dialogs-layout { height: calc(100dvh - 130px - env(safe-area-inset-bottom)); }
  body.chat-open .dialogs-layout .dialog-list { display: none; }
  body.chat-open #chat-slot { display: flex; height: 100%; }
  .chat-panel { height: 100%; }
  #chat-slot .chat-foot:last-child { max-height: 38%; overflow-y: auto; }
  .chat-head { padding: 10px 12px; gap: 8px; }
  .chat-scroll { padding: 12px; }
  .msg .bubble { max-width: 86%; font-size: 14px; }
  .chat-foot { padding: 10px 12px; }
  .chat-input textarea { font-size: 15px; min-height: 44px; }
  .chat-back { display: inline-flex !important; }
  .lead-panel { padding: 6px 0 0; }

  /* кнопки удобны под палец */
  .btn { padding: 10px 14px; font-size: 14px; }
  .btn-small { padding: 7px 11px; font-size: 13px; }

  /* модалка как экран приложения */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    max-width: 100%; width: 100%; max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* тест-чат на весь экран, без «телефона в телефоне» */
  .phone { border-radius: 16px; }
  .phone-body { height: min(58dvh, 460px); }
  .quick-row { padding: 0 10px 8px; }
  .quick-chip { font-size: 12.5px; padding: 7px 12px; }

  .balance-hero { flex-direction: column; align-items: stretch; gap: 12px; padding: 16px; }
  .balance-hero .amount { font-size: 28px; }
  .balance-hero .row { flex-wrap: wrap; }
  .balance-hero input { flex: 1; min-width: 120px; }

  .toast { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateY(20px); text-align: center; }
  .toast.show { transform: translateY(0); }

  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { white-space: nowrap; flex: 0 0 auto; }

  .login-card { padding: 22px; border-radius: 18px; }
  .pin-pad button { padding: 15px 0; font-size: 20px; }
}

.chat-back { display: none; }
/* «Ещё» в нижней панели — только на телефоне */
@media (min-width: 861px) {
  .nav-more { display: none; }
}
.nav a.nav-main, .nav a.nav-extra { display: flex; }

/* совсем узкие экраны */
@media (max-width: 380px) {
  .nav a { padding: 7px 6px; font-size: 11.5px; }
  .kpi-value { font-size: 21px; }
}

/* Превью объявлений Авито */
.avito-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  display: block;
}
.avito-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 9.5px;
  line-height: 1.15;
  color: var(--muted, #8b8b8b);
  background: #f7f5f2;
}
/* ---------------------------- темы ---------------------------- */
html[data-theme="dark"] {
  --topbar-bg: rgba(24, 28, 33, .92);
  --bg: #14181c;
  --surface: #1c2228;
  --surface-2: #222a31;
  --ink: #eef1f4;
  --ink-2: #c9d1d9;
  --muted: #94a1ad;
  --line: #2c343d;
  --line-2: #262e36;
  --accent: #d9714f;
  --accent-soft: #3a2721;
  --green: #56b593;
  --green-soft: #1c2a24;
  --amber: #dca948;
  --amber-soft: #2f2718;
  --blue: #74a9d8;
  --blue-soft: #1c2733;
  --sidebar: #101317;
  --sidebar-2: #181d23;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 26px -14px rgba(0, 0, 0, .65);
  --shadow-lg: 0 26px 60px -20px rgba(0, 0, 0, .75);
}

html[data-theme="dark"] .msg.client .bubble { background: var(--surface-2); }
html[data-theme="dark"] .msg.bot .bubble { background: #262f38; color: var(--ink); }
html[data-theme="dark"] .avito-thumb,
html[data-theme="dark"] .avito-thumb-empty { background: var(--surface-2); }
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-card,
html[data-theme="dark"] .chat-panel { border-color: var(--line); }
html[data-theme="dark"] .btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
html[data-theme="dark"] .avatar { background: #2f3742; color: #fff; }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--muted); }
html[data-theme="dark"] .balance-hero { background: linear-gradient(120deg, #1b2129, #262f39 60%, #3a2b24); }
html[data-theme="dark"] table th { color: var(--muted); }
html[data-theme="dark"] .tag { border-color: var(--line); }
html[data-theme="dark"] .tabs button.active { color: var(--ink); }

/* ---------------------------- адаптив ---------------------------- */
.billing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
/* карточки в сетке не должны растягиваться содержимым (таблицы, длинные строки) */
.grid, .billing-grid, .test-layout { min-width: 0; }
.grid > *, .billing-grid > * { min-width: 0; }
.card { min-width: 0; }
.card table { max-width: 100%; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (min-width: 861px) {
  .table-scroll table { min-width: 520px; }
}

.theme-btn { font-size: 17px; line-height: 1; color: var(--ink-2); }
.theme-btn:hover { color: var(--ink); }
@media (max-width: 980px) { .billing-grid { grid-template-columns: 1fr; } }

@media (max-width: 760px) {
  .balance-hero { flex-direction: column; align-items: flex-start; gap: 14px; padding: 18px; }
  .balance-hero .amount { font-size: 28px; }
  .balance-hero .row { width: 100%; flex-wrap: wrap; }
  .balance-hero input { flex: 1 1 130px; width: auto !important; }
  .settings-grid { grid-template-columns: 1fr; }
  .card-pad .field-row { flex-direction: column; }
  .row [data-copy] { flex: 0 0 auto; }
  .lead-panel .lead-row { font-size: 12.6px; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs button { white-space: nowrap; }
}
