/* BOTVA admin — собственная дизайн-система (без CSS-фреймворка).
   Токены: светлая/тёмная тема через [data-theme] (localStorage + prefers-color-scheme).
   Компоненты: карточки, таблицы, кнопки, бэйджи, чипы, гейдж, модалка, поповер. */

:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f7f6f2;
  --surface-3: #edebe4;
  --text: #1c1c1a;
  --text-2: #5f5e5a;
  --text-3: #94938c;
  --border: #e5e3dc;
  --border-2: #d2d0c8;
  --accent: #5348c7;
  --accent-bg: #eeedfe;
  --accent-text: #3c3489;
  --ok: #1d9e75;      --ok-bg: #e1f5ee;   --ok-text: #085041;
  --err: #e24b4a;     --err-bg: #fcebeb;  --err-text: #791f1f;
  --warn: #ba7517;    --warn-bg: #faeeda; --warn-text: #633806;
  --radius: 8px;
  --radius-lg: 14px;
  /* Размеры каркаса — токенами: отступ карточки был записан тремя разными
     числами и завязан на отрицательные марджины таблиц, поэтому уменьшить
     плотность на мобиле означало переписать три компонента (ревью §4, шаг 0). */
  --sidebar-w: 216px;
  --pad-page-x: 1.8rem;  --pad-page-y: 1.4rem;
  --card-pad-x: 1.15rem; --card-pad-y: 1rem;
  /* Единая высота интерактивных контролов. Без неё высота зависела от
     содержимого — кнопка с иконкой была на 4 px ниже кнопки с текстом, а
     .btn-sm рядом с .btn отличалась на 9 px: в одном ряду это видно. */
  --ctl-h: 32px;
  --shadow: 0 1px 2px rgba(25, 25, 20, .04), 0 4px 14px rgba(25, 25, 20, .05);
  --shadow-pop: 0 6px 16px rgba(0, 0, 0, .1), 0 16px 40px rgba(0, 0, 0, .16);
}
[data-theme="dark"] {
  --bg: #161614;
  --surface: #1e1e1c;
  --surface-2: #252522;
  --surface-3: #2e2e2a;
  --text: #ececea;
  --text-2: #a9a8a1;
  --text-3: #7a7972;
  --border: #32322d;
  --border-2: #45443e;
  --accent: #8d84e8;
  --accent-bg: #2c2850;
  --accent-text: #cecbf6;
  --ok: #5dcaa5;      --ok-bg: #0c3d30;   --ok-text: #9fe1cb;
  --err: #f09595;     --err-bg: #46201f;  --err-text: #f7c1c1;
  --warn: #ef9f27;    --warn-bg: #413109; --warn-text: #fac775;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .3);
  --shadow-pop: 0 6px 16px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
/* 100% запрещал браузеру увеличивать мелкий текст в ландшафте */
html { -webkit-text-size-adjust: auto; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h2 { font-size: 1.3rem; }
h4 { font-size: .95rem; margin: 1.4rem 0 .5rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }
small { font-size: .8rem; }
.muted { color: var(--text-3); }
.err { color: var(--err); display: block; margin: .3rem 0; font-size: .85rem; }
.num { text-align: right; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Каркас ── */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1rem .8rem; display: flex; flex-direction: column; gap: .2rem;
  position: sticky; top: 0; height: 100dvh;
}
.brand { font-size: 1.15rem; font-weight: 700; color: var(--text); padding: .2rem .6rem 1rem; }
.brand:hover { text-decoration: none; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: .5rem .65rem;
  border-radius: var(--radius); color: var(--text-2); font-size: .875rem;
}
.nav-item i { font-size: 17px; }
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding: 0 .3rem; }
.foot-row { display: flex; gap: .4rem; }
.foot-row .btn { flex: 1; justify-content: center; }
.content { padding: var(--pad-page-y) var(--pad-page-x) 2.2rem; max-width: 1240px; min-width: 0; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem; }
.crumbs { font-size: .78rem; color: var(--text-3); margin-bottom: .5rem; }
.crumbs a { color: var(--text-3); }

/* Флеш-сообщение о результате действия (templating.flash). */
.flash { display: flex; align-items: center; justify-content: space-between; gap: .8rem;
  padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem;
  border: 1px solid var(--border-2); font-size: .875rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.flash-err { background: var(--err-bg); color: var(--err-text); border-color: transparent; }
.flash-warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.flash button { color: inherit; }

/* ── Кнопки ── */
button, .btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  min-height: var(--ctl-h); padding: 0 .85rem; border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  font: inherit; font-size: .85rem; line-height: 1.2; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--err); border-color: var(--border-2); background: var(--surface); }
.btn-danger:hover { background: var(--err-bg); border-color: var(--err); }
/* «маленькая» кнопка отличается шрифтом и отступами, но НЕ высотой */
.btn-sm { padding: 0 .6rem; font-size: .78rem; border-radius: 7px; }
.btn i { font-size: 15px; }
.btn-row { display: flex; gap: .5rem; margin-top: 1rem; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }

/* ── Формы ── */
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  font: inherit; font-size: .875rem;
}
/* однострочные поля — ровно той же высоты, что кнопки: в тулбарах и формах они
   стоят в одном ряду, и разница в 3-5 px бросалась в глаза */
input:not([type="checkbox"]):not([type="radio"]), select {
  height: var(--ctl-h); padding: 0 .65rem; line-height: 1.2;
}
textarea { padding: .45rem .65rem; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
::placeholder { color: var(--text-3); }
.form { max-width: 620px; }
.form label { display: block; margin-bottom: .85rem; font-size: .82rem; color: var(--text-2); }
.form label > input, .form label > select, .form label > textarea { margin-top: .28rem; }
.form .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; }
.form fieldset { border: 1px dashed var(--border-2); border-radius: var(--radius-lg);
  padding: .8rem 1rem .4rem; margin: 0 0 .9rem; }
.check { display: flex !important; align-items: center; gap: .5rem; color: var(--text) !important; }

/* ── Карточки ── */
article, .card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: var(--card-pad-y) var(--card-pad-x); margin-bottom: 1rem;
}
article > header, .card-title {
  font-size: .8rem; color: var(--text-2); font-weight: 500;
  margin: -0.2rem 0 .6rem; letter-spacing: .01em;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; }
.grid article { margin-bottom: 0; }
/* секции-сетки (метрики) не должны слипаться со следующим блоком */
section.grid { margin-bottom: 1rem; }

/* Метрики. */
.metric { background: var(--surface-2); border: none; box-shadow: none; }
.metric .m-label { font-size: .78rem; color: var(--text-2); margin-bottom: .3rem; }
.metric .m-value { font-size: 1.55rem; font-weight: 600; line-height: 1.2; }
.metric .m-sub { font-size: .75rem; color: var(--text-3); }

/* Пополнение баланса в карточке метрики (Anthropic): свёрнуто в «Добавить». */
.topup summary {
  cursor: pointer; width: fit-content; margin-top: .55rem;
  font-size: .78rem; color: var(--accent); list-style: none;
}
.topup summary::-webkit-details-marker { display: none; }
.topup summary:hover { text-decoration: underline; }
/* Журнал: группы по сессиям — строка-сессия раскрывает вызовы. */
.log-sess { cursor: pointer; background: var(--surface-2); }
.log-sess td { font-weight: 500; }
.log-sess .chev { display: inline-block; color: var(--text-3); transition: transform .12s; }
.log-sess.open .chev { transform: rotate(90deg); }
.log-call.hide { display: none; }
.log-call td:first-child { padding-left: 1.6rem; }

.topup-form { display: flex; gap: .35rem; margin-top: .4rem; }
/* специфичность не ниже глобального input:not(...):not(...) (width: 100%) */
.topup-form input[type="number"] { padding: 0 .5rem; font-size: .78rem; width: 5.5rem; flex: none; }
.topup-form button { padding: 0 .6rem; font-size: .82rem; flex: none; }

/* Статус-пилюли сервисов. */
.status-strip { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.status-pill { display: inline-flex; align-items: center; gap: .5rem; padding: .4rem .8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  font-size: .82rem; box-shadow: var(--shadow); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot.up { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.down { background: var(--err); box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 22%, transparent); }

/* ── Таблицы ── */
table { width: 100%; border-collapse: collapse; font-size: .855rem; }
table.fixed { table-layout: fixed; }
table.fixed td { overflow-wrap: break-word; }
th { text-align: left; font-weight: 500; font-size: .72rem; color: var(--text-3);
  padding: .45rem .7rem; letter-spacing: .02em; }
td { padding: .52rem .7rem; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
article table, .card table {
  margin: 0 calc(-1 * var(--card-pad-x)) calc(-1 * var(--card-pad-y));
  width: calc(100% + 2 * var(--card-pad-x)); }
article table th:first-child, article table td:first-child { padding-left: var(--card-pad-x); }
article table th:last-child, article table td:last-child { padding-right: var(--card-pad-x); }
table.kv { margin: 0; width: 100%; }
table.kv td { border: 0; padding: .18rem 0; }
table.kv td:last-child { text-align: right; }
table.kv tr:hover { background: none; }
.cell-main { font-weight: 500; }
.cell-sub { font-size: .75rem; color: var(--text-3); }
.table-wrap { overflow-x: auto; }
.actions { display: flex; gap: .35rem; white-space: nowrap; justify-content: flex-end; }

/* Список-группы. */
.group-head { margin: 1.3rem 0 .45rem; font-size: .92rem; font-weight: 600; }
.group-head .count { color: var(--text-3); font-weight: 400; font-size: .8rem; }
.group-head:first-of-type { margin-top: .4rem; }
.list-table { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.list-table table td:first-child, .list-table table th:first-child { padding-left: var(--card-pad-x); }
.list-table table td:last-child, .list-table table th:last-child { padding-right: var(--card-pad-x); }
.list-table tbody tr:first-child td { border-top: 1px solid var(--border); }

/* ── Тулбар / сегменты / табы ── */
.toolbar { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin: .2rem 0 .9rem;
  font-size: .84rem; color: var(--text-2); }
.toolbar form { margin: 0; }
.toolbar label { display: flex; align-items: center; gap: .4rem; margin: 0; }
.seg { display: flex; gap: .25rem; }
.seg .btn.active { background: var(--accent-bg); color: var(--accent-text); border-color: transparent; }
.search { max-width: 230px; }
.tabs { display: flex; gap: .3rem; margin: 0 0 1rem; }
.period { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.period input[type="number"] { width: 5.2rem; }
.period select, .period input[type="date"] { width: auto; }

/* Настройки: компактные инлайн-формы в таблицах. */
.settings-table input, .settings-table select { padding: 0 .5rem; font-size: .8rem; }
.settings-table select { width: auto; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* ── Бэйджи и чипы ── */
.badge { font-size: .72rem; padding: .1rem .55rem; border-radius: 20px; white-space: nowrap;
  display: inline-block; font-weight: 500; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.off { background: var(--err-bg); color: var(--err-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.neutral { background: var(--surface-3); color: var(--text-2); }

.lic-cell { display: inline-block; position: relative; }
.lic-chip { margin: 0; min-height: var(--ctl-h); padding: 0 .7rem; font-size: .76rem;
  border-radius: 20px;
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text); }
.lic-chip:hover { border-color: var(--accent); background: var(--surface); }
.lic-chip.empty { border-style: dashed; color: var(--text-3); }
.lic-picker { border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  padding: .3rem; min-width: 230px; box-shadow: var(--shadow-pop); position: relative; z-index: 30; }
.lic-picker .pick-note { padding: .28rem .55rem; font-size: .7rem; color: var(--text-3); }
.lic-picker .pick-row { margin: 0; display: block; }
.lic-picker .pick { display: block; width: 100%; text-align: left; margin: 1px 0;
  padding: .34rem .55rem; font-size: .8rem; background: none; border: none;
  border-radius: 7px; color: var(--text); }
.lic-picker .pick:hover { background: var(--surface-2); }
.lic-picker .pick.cur { background: var(--accent-bg); color: var(--accent-text); }
.lic-picker .pick.unset, .lic-picker .pick.cancel { color: var(--text-3); font-size: .74rem; }

.btn-status { min-height: var(--ctl-h); padding: 0 .7rem; border-radius: 20px;
  font-size: .72rem; font-weight: 500; border: 1px solid transparent; }
.btn-status.on { background: var(--ok-bg); color: var(--ok-text); }
.btn-status.off { background: var(--err-bg); color: var(--err-text); }

/* ── Гейдж мест ── */
.gauge-num { font-size: 1.55rem; font-weight: 600; margin: .1rem 0 .5rem; }
.gauge { height: 6px; border-radius: 6px; background: var(--surface-3); overflow: hidden; }
.gauge-fill { height: 100%; background: var(--accent); border-radius: 6px; }

/* ── Карточка лицензии ── */
.lic-title { display: flex; align-items: center; gap: .6rem; }
.lic-meta { margin: .1rem 0 1rem; font-size: .84rem; }
.bots-card { padding: 0; }
.bots-card-head { display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; flex-wrap: wrap;
  padding: .8rem var(--card-pad-x); border-bottom: 1px solid var(--border); font-size: .9rem; }
.bots-card table { margin: 0; width: 100%; }
.bots-card td:first-child, .bots-card th:first-child { padding-left: var(--card-pad-x); }
.bots-card td:last-child, .bots-card th:last-child { padding-right: var(--card-pad-x); }
.empty-note { padding: .8rem var(--card-pad-x); color: var(--text-3); font-size: .84rem; }

/* Инвайт-ссылки. */
.invite-row { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; flex-wrap: wrap; }
.invite-link { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .78rem;
  background: var(--surface-2); padding: .2rem .55rem; border-radius: 7px;
  border: 1px solid var(--border); color: var(--text-2); word-break: break-all; }

/* ── Модалка ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(12, 12, 10, .5);
  display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--surface); border-radius: var(--radius-lg);
  max-width: 480px; width: 92%; max-height: 80vh; overflow: auto; box-shadow: var(--shadow-pop); }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: .85rem var(--card-pad-x); border-bottom: 1px solid var(--border); }
.modal-x { background: none; border: none; color: var(--text-3); padding: 0 .4rem; }
.modal-card table { margin: 0; }
.modal-card td { padding: .5rem var(--card-pad-x); }

/* ── Фидбек ── */
.fb-item { margin-bottom: .8rem; }
.fb-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  font-size: .78rem; color: var(--text-3); margin-bottom: .4rem; }
.fb-text { white-space: pre-wrap; font-size: .88rem; }

/* ── Вход ── */
.login-body { display: grid; place-items: center; min-height: 100dvh;
  padding: 1rem; background: var(--bg); }
.login-card { max-width: 340px; width: 100%; }
.login-card h1 { font-size: 1.5rem; margin-bottom: .1rem; }
.login-card .sub { color: var(--text-3); margin: 0 0 1.2rem; }
.login-card input { margin-bottom: .7rem; }
.login-card button { width: 100%; }

/* Результат проверки продукта (собранный промпт / ответ тест-бота). */
.check-out { margin-top: .8rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); overflow: hidden; }
.check-head { display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .45rem .7rem; border-bottom: 1px solid var(--border);
  font-size: .8rem; color: var(--text-2); }
.check-text { margin: 0; padding: .7rem; max-height: 420px; overflow: auto;
  white-space: pre-wrap; word-break: break-word; font-size: .8rem;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* График расхода по дням — свой SVG (Chart.js убран вместе с CDN).
   Линия рисуется в растянутой системе координат, поэтому оси и курсор —
   HTML поверх: текст внутри такого SVG исказился бы по горизонтали. */
.chart { display: grid; grid-template-columns: 46px 1fr; grid-template-rows: 1fr 18px;
  gap: 0 .4rem; margin-top: .3rem; }
.chart-y { position: relative; height: 130px; }
.chart-y span { position: absolute; right: 0; transform: translateY(-50%);
  font-size: .68rem; color: var(--text-3); white-space: nowrap; }
.chart-plot { position: relative; height: 130px; cursor: crosshair; }
.chart-grid { position: absolute; inset: 0; pointer-events: none; }
.chart-grid i { position: absolute; left: 0; right: 0; height: 1px;
  background: var(--border); opacity: .7; }
.chart-x { grid-column: 2; position: relative; height: 18px; }
.chart-x span { position: absolute; transform: translateX(-50%); top: 2px;
  font-size: .68rem; color: var(--text-3); white-space: nowrap; }
.chart-x span:first-child { transform: none; }
.chart-x span:last-child { transform: translateX(-100%); }
.chart-cursor { position: absolute; top: 0; bottom: 0; width: 0; pointer-events: none; }
.chart-cursor i { position: absolute; top: 0; bottom: 0; left: 0; width: 1px;
  background: var(--accent); opacity: .5; }
.chart-cursor b { position: absolute; left: 0; width: 9px; height: 9px; margin: -4.5px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.chart-tip { position: absolute; top: -2px; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .25rem .5rem; font-size: .74rem; white-space: nowrap; }
.chart-tip b { display: block; font-size: .85rem; }
.chart-tip span { color: var(--text-3); }

.spark-wrap { margin-top: .2rem; }
.spark { width: 100%; height: 100%; display: block; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 1.6;
  stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-area { fill: color-mix(in srgb, var(--accent) 14%, transparent); stroke: none; }
.spark-axis { display: flex; justify-content: space-between; gap: .5rem; margin-top: .3rem; }

canvas { max-width: 100%; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); align-items: start; }
.stats-grid article { overflow-x: auto; }

/* Share-бар в таблицах разрезов (доля от общего расхода). */
.share { display: inline-block; vertical-align: middle; width: 90px; height: 6px;
  border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-right: .45rem; }
.share i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.share-cell { white-space: nowrap; color: var(--text-3); font-size: .78rem; }

/* Чипы «пользователь ↔ его боты» (страница Пользователи). */
.user-bots { display: flex; flex-wrap: wrap; gap: .25rem; }
.user-bot { display: inline-flex; align-items: center; gap: 3px;
  min-height: var(--ctl-h); padding: 0 .3rem 0 .7rem;
  border: 1px solid var(--border-2); border-radius: 20px; font-size: .76rem; }
.user-bot.off { border-style: dashed; }
.user-bot.off > span { color: var(--text-3); text-decoration: line-through; }
/* флекс-элементом чипа является <form>, а не кнопка внутри — тянем обоих,
   иначе крестик остаётся 13 px при чипе в 32 px */
.user-bot .inline-form { display: flex; align-self: stretch; }
.chip-x { border: none; background: none; min-height: 0; height: 100%;
  padding: 0 6px; color: var(--text-3); font-size: .8rem; line-height: 1; }
.chip-x:hover { color: var(--err); background: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   АДАПТИВ
   Ломалось не на телефоне, а гораздо раньше: сайдбар 216 px несжимаем, а
   .content с паддингами 28.8 px оставлял на 375 px около 100 px под данные.
   Порядок правил важен — блоки идут от каркаса к деталям.
   ═══════════════════════════════════════════════════════════════════════════ */

.topbar, .nav-scrim { display: none; }

/* Hover-эффекты только там, где мышь есть: после тапа они залипают, и крестик
   отзыва доступа выглядит нажатым. */
@media (hover: none) {
  button:hover, .btn:hover, .nav-item:hover, tbody tr:hover,
  .lic-chip:hover, .chip-x:hover, a:hover { background: inherit; color: inherit;
    text-decoration: none; border-color: inherit; }
  .btn-primary:hover { background: var(--accent); color: #fff; }
  .chip-x:hover { color: var(--text-3); }
}

/* ── ≤1100px: честный скролл вместо обрезки ──
   .list-table держит overflow:hidden ради скруглений — это обрезка, а не
   скролл; широкие таблицы просто теряли колонки. */
@media (max-width: 1100px) {
  .table-wrap, .bots-card, article.settings-table, .list-table {
    overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table, .bots-card table, .settings-table table { min-width: 620px; }
}

/* ── ≤900px: каркас в одну колонку, меню — off-canvas ──
   Нижний таб-бар не годится: разделов одиннадцать, в него влезает 4-5, а
   резать разделы нельзя. */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { display: flex; align-items: center; gap: .5rem; position: sticky; top: 0;
    z-index: 90; padding: .5rem .6rem; background: var(--surface);
    border-bottom: 1px solid var(--border); }
  .topbar .brand { padding: 0; font-size: 1rem; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 268px; height: 100dvh;
    z-index: 200; transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow-pop); overflow-y: auto; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 150;
    background: rgba(12, 12, 10, .5); }
  .content { padding: var(--pad-page-y) var(--pad-page-x) 2rem; max-width: none; }
  .nav-item { min-height: 44px; }

  /* 16px — порог, ниже которого iOS Safari зумит вьюпорт при фокусе и обратно
     не откатывает. Блок обязан идти ПОСЛЕ .settings-table (специфичность та же). */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px; }
  .settings-table input, .settings-table select { font-size: 16px; padding: .45rem .6rem; }
  .topup-form input[type="number"] { font-size: 16px; width: 7rem; }
  th { font-size: .78rem; }
  .cell-sub, .badge, small { font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ── ≤760px: плотность, списки карточками, sticky-действия ── */
@media (max-width: 760px) {
  :root { --pad-page-x: .9rem; --pad-page-y: .9rem; --card-pad-x: .9rem; }

  /* Списковые таблицы → карточки. Разметка не меняется: подпись колонки
     подставляется из data-label, поэтому HTMX-свапы продолжают работать. */
  .list-table { background: none; border: 0; box-shadow: none; overflow: visible; }
  .list-table colgroup, .list-table thead { display: none; }
  .list-table table, .list-table tbody, .list-table tr, .list-table td {
    display: block; width: auto; min-width: 0; }
  .list-table tr { background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow);
    padding: .75rem var(--card-pad-x); margin-bottom: .6rem; }
  .list-table td { border-top: 0; padding: .22rem 0; }
  .list-table td.num { text-align: left; }
  .list-table td[data-label]:not([data-label=""])::before {
    content: attr(data-label) ": "; color: var(--text-3); font-size: .72rem; }
  .list-table .actions { justify-content: flex-start; margin-top: .55rem;
    padding-top: .5rem; border-top: 1px solid var(--border); }

  /* Формы: одна колонка и кнопки, приклеенные к низу — самая длинная форма на
     375 px это ~2.5 экрана, и «Создать» жила в самом низу. */
  .form { max-width: none; }
  .form .grid { grid-template-columns: 1fr; }
  .form > .btn-row { position: sticky; bottom: 0; z-index: 40;
    margin: 1.2rem calc(-1 * var(--card-pad-x)) calc(-1 * var(--card-pad-y));
    padding: .7rem var(--card-pad-x) calc(.7rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); }
  .form > .btn-row > .btn, .form > .btn-row > button { flex: 1 1 0; }

  /* Отзыв доступа — необратимое действие вплотную к соседним чипам. */
  .user-bots { flex-direction: column; }
  .user-bot { display: flex; width: 100%; justify-content: space-between; }

  /* Модалка и пикер лицензии — снизу, как нативные шторки. */
  .modal-backdrop { align-items: flex-end; }
  .modal-card { width: 100%; max-width: none; max-height: 88dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom); }
  .modal-card table, .modal-card tbody, .modal-card tr, .modal-card td { display: block; }
  .lic-picker { position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 70dvh; overflow-y: auto; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: calc(.3rem + env(safe-area-inset-bottom)); z-index: 210; }

  .page-head { gap: .6rem; }
  .search-form { width: 100%; }
  .search { max-width: none; flex: 1; }
  .chart-y, .chart-plot { height: 150px; }
  .chart { grid-template-columns: 40px 1fr; }

  /* Панель периода статистики: пять контролов в строку не помещаются. */
  .period { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; width: 100%; }
  .period select, .period input, .period button { width: 100%; }
  .period > button { grid-column: 1 / -1; }
  .tabs, .seg { flex-wrap: wrap; }
  .toolbar { gap: .5rem; }
  /* журнал и настройки в карточки не превращаем — им скролл (см. ≤1100px) */
  .status-strip { gap: .4rem; }
  .invite-link { font-size: .7rem; }
}

/* ── Тач: размеры целей нажатия ── */
@media (pointer: coarse) {
  :root { --ctl-h: 40px; }
  .btn-sm, .lic-chip { padding: 0 .8rem; }
  .chip-x { min-width: 34px; min-height: 34px; padding: 0 8px; font-size: 1rem; }
  .modal-x { min-width: 40px; min-height: 40px; }
  input[type="checkbox"] { width: 20px; height: 20px; }
}

/* Пикер лицензии на десктопе: был position:relative и распирал колонку, потому
   что оставался в потоке при min-width 230px, а колонка по colgroup — 17%. */
.lic-cell { position: relative; display: inline-block; }
@media (min-width: 761px) {
  .lic-picker { position: absolute; top: calc(100% + 4px); left: 0; z-index: 60; }
}
.search-form { display: flex; gap: .35rem; align-items: center; }
.hints { margin: .6rem 0 0; font-size: .8rem; }
.hints dt { font-weight: 500; margin-top: .4rem; }
.hints dd { margin: 0 0 .2rem; }
.token-swap summary { cursor: pointer; font-size: .82rem; color: var(--accent);
  width: fit-content; margin-top: .9rem; }
.otp summary { cursor: pointer; font-size: .8rem; color: var(--text-3);
  margin-bottom: .5rem; width: fit-content; }
/* htmx-индикатор: без него на медленном канале жмут второй раз */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
