/* tg-clients — интерфейс. Без сборки: переменные для тем, системный шрифт, адаптив до ширины телефона.
   Модули static/css склеиваются по порядку имён в один app.css (web/assets.go): каскад — как в
   одном файле, новое правило — в модуль своей темы, переопределение — в модуле после него. */

:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --surface-3: #e7e6e2;
  --border: #e2e1dc;
  --border-strong: #cfcdc6;
  --text: #17171a;
  --muted: #6b6a66;
  --accent: #1f66bd;
  --accent-hover: #18559f;
  --accent-soft: #e6f0fb;
  --accent-ink: #ffffff;
  --on-status: #ffffff; /* текст на заливке --ok/--warn */
  --ok: #1b7f4b;
  --ok-soft: #e3f4ea;
  --warn: #9a6100;
  --warn-soft: #fbf0d9;
  --err: #c0362c;
  --err-soft: #fbe6e3;
  --shadow: 0 1px 2px rgba(20, 20, 18, .05), 0 2px 8px rgba(20, 20, 18, .04);
  --toast-shadow: 0 8px 24px rgba(0, 0, 0, .14), 0 2px 6px rgba(0, 0, 0, .08);
  --radius: 12px;
  --radius-sm: 8px;
  --pill: 999px; /* пилюля: скругление «до конца» у чипов, бейджей, переключателей */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1b1b1a;
    --surface-2: #232322;
    --surface-3: #2d2d2b;
    --border: #2f2f2d;
    --border-strong: #42423f;
    --text: #f0efec;
    --muted: #a3a29b;
    --accent: #3987e5;
    --accent-hover: #5b9de9;
    --accent-soft: #1a2c44;
    --accent-ink: #0d1a2b;
    --on-status: #ffffff; /* текст на заливке --ok/--warn */
    --ok: #4cc283;
    --ok-soft: #173325;
    --warn: #e2a63b;
    --warn-soft: #3a2c12;
    --err: #ef7469;
    --err-soft: #3d1c19;
                --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --toast-shadow: 0 8px 28px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { overflow-wrap: anywhere; line-height: 1.25; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
h3.sub { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.2em 0 .6em; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.err-text { color: var(--err); }
.warn-text { color: var(--warn); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }


/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; color: var(--accent); }
.spacer { flex: 1; }
.admin-name { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.admin-name:hover, .admin-name.active { color: var(--text); text-decoration: none; }
form.inline { display: inline; margin: 0; }

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.shell.no-nav { grid-template-columns: minmax(0, 1fr); }
.sidenav {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px);
  display: flex; flex-direction: column; gap: 2px; padding: 16px 10px;
  border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto;
}
.navlink {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 500;
}
.navlink:hover { background: var(--surface-2); text-decoration: none; }
.navlink.active { background: var(--accent-soft); color: var(--accent); }
.icon { width: 18px; height: 18px; flex: none; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.main { padding: 24px 28px 64px; max-width: 1280px; width: 100%; }

/* ---------- Шапки страниц ---------- */
.page-head { margin-bottom: 20px; }
.page-head p { max-width: 70ch; }
.page-head.row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.crumbs { margin-bottom: 8px; font-size: .9rem; }
.crumbs-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0;
}
.card.narrow { max-width: 560px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.link-more { font-size: .88rem; white-space: nowrap; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 20px; align-items: start; margin-bottom: 20px; }
.cols > .card { margin-bottom: 0; }

/* ---------- Кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger, .menu-item.danger { color: var(--err); }
.btn.danger:not(.ghost) { border-color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: .88rem; }
.btn.big { min-height: 48px; padding: 10px 22px; font-size: 1.05rem; }
.btn .icon { width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row form { margin: 0; }
.push-right { margin-left: auto; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }

label { display: block; font-weight: 550; font-size: .92rem; }
label > input, label > select, label > textarea { display: block; margin-top: 5px; }
.check > input { display: inline-block; margin: 0; flex: none; }
.inline-field > input, .inline-field > select { display: inline-block; }
.label { font-weight: 550; font-size: .92rem; margin-bottom: 6px; }
label .muted, label .hint { font-weight: 400; }
.hint { display: block; margin-top: 4px; color: var(--muted); font-size: .8rem; font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 36px; width: 100%; min-width: 0;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); margin: 0; }
input[type=file] { padding: 6px; background: var(--surface-2); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled { opacity: .75; }
legend { font-weight: 550; font-size: .92rem; padding: 0; margin-bottom: 6px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 14px; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.check.top { align-items: flex-start; }
.radios { display: flex; flex-direction: column; gap: 6px; }
.radios .check { display: block; }
.radios .check > input { margin-right: 8px; vertical-align: -1px; }
.pad-top { padding-top: 26px; }
.danger-zone { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }
.code-input { font-size: 1.4rem; letter-spacing: .3em; font-family: var(--mono); max-width: 220px; }

/* ---------- Сообщения ---------- */
/* Тосты — итог действия поверх страницы, ничего не сдвигают: справа сверху под шапкой, на
   телефоне — во всю ширину. z-index 25: над полосой разделов (20), под шапкой (30). Пустая стопка нулевой высоты и пропускает клики. */
#flash-area {
  position: fixed; inset: 68px 16px auto auto; z-index: 25; width: min(400px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
body.bare #flash-area { top: 16px; }
.toast {
  position: relative; overflow: hidden; pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 40px 12px 14px;
  border: 1px solid; border-radius: var(--radius-sm); color: var(--text); box-shadow: var(--toast-shadow);
  animation: toast-in .18s ease-out;
}
.toast > .icon { flex: none; width: 20px; height: 20px; margin-top: 1px; }
.toast-text { flex: 1; min-width: 0; max-height: 40vh; overflow-y: auto; overflow-wrap: anywhere; line-height: 1.45; }
.toast-close {
  position: absolute; top: 8px; right: 8px; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  background: none; border: 0; border-radius: var(--radius-sm); font-size: 1.25rem; line-height: 1; cursor: pointer; color: var(--muted);
  outline-offset: -2px;
}
.toast-close:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.toast-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.toast-ok > .icon { color: var(--ok); }
.toast-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.toast-error > .icon { color: var(--err); }
.toast-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.toast-info > .icon { color: var(--accent); }
.toast-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.toast-warn > .icon { color: var(--warn); }
.toast.out { opacity: 0; transform: translateX(16px); transition: opacity .18s, transform .18s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast.out { transition: none; }
}
@media print { #flash-area { display: none; } }
.alert > span { min-width: 0; overflow-wrap: anywhere; }
.alert {
  display: flex; align-items: flex-start; gap: 10px; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid;
  transition: opacity .4s;
}
.alert-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.alert-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.alert-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-close { background: none; border: 0; font-size: 1.2rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 2px; }

/* ---------- Значки ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--pill);
  font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge.on, .as-active { background: var(--ok-soft); color: var(--ok); }
.badge.pending { background: var(--accent-soft); color: var(--accent); }
.as-needs_login { background: var(--warn-soft); color: var(--warn); }
.as-disabled, .badge.off { background: var(--surface-2); color: var(--muted); }

.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* Страницы приложения: список аккаунтов, карточка, чтение канала. */
.login-box { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.acc-list { list-style: none; margin: 0; padding: 0; }
.acc-row {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.acc-row:last-child { border-bottom: 0; }
.acc-name { font-weight: 600; overflow-wrap: anywhere; }
.acc-sub { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.acc-status { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; min-width: 0; }
.acc-error { color: var(--err); font-size: .82rem; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 12px 0; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0 0 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.result-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; margin-bottom: 10px; }
.msg { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.msg-thumb { width: 64px; min-height: 48px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14em; overflow: auto; }
.msg-meta { color: var(--muted); font-size: .8rem; display: flex; flex-wrap: wrap; gap: 2px 12px; margin-bottom: 4px; }
.preview { display: block; max-width: 100%; max-height: 420px; border-radius: 8px; margin-top: 8px; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 6px 14px; }
.limit-field { max-width: 160px; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

/* Прокси: фильтр пачки, инструменты отметки, список с галками. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: .85rem;
  color: var(--muted); text-decoration: none; min-width: 0; overflow-wrap: anywhere;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pack-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pack-tools input[type=number] { width: 84px; margin-left: 6px; }
.pack-list { max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.pack-list li { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.pack-list li:last-child { border-bottom: 0; }
.pack-acc { display: flex; flex-direction: column; min-width: 0; }
.proxy-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- Адаптив: от 320 px без прокрутки вбок ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidenav {
    position: sticky; top: 56px; z-index: 20; height: auto; flex-direction: row; overflow-x: auto;
    padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--border); scrollbar-width: none;
  }
  .sidenav::-webkit-scrollbar { display: none; }
  .navlink { flex: none; padding: 6px 10px; font-size: .9rem; }
  .main { padding: 16px 16px 48px; }
  .topbar { gap: 8px; padding: 0 12px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.35rem; }
  #flash-area { inset: 64px 8px auto 8px; width: auto; }
}
@media (max-width: 640px) {
  .acc-row { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .acc-row .btn-row { justify-content: flex-start; }
  .card { padding: 14px; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .facts dd { margin-bottom: 8px; }
  .msg { grid-template-columns: 48px minmax(0, 1fr); gap: 10px; }
  .msg-thumb { width: 48px; }
}
/* Поля 16px: иначе iOS увеличивает страницу при фокусе. Кнопки — под палец. */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; }
  .chip { display: inline-flex; align-items: center; min-height: 40px; }
}
