/* Threads · Автопостинг — бело-синяя палитра (SaaS-tool style).
   Значения ниже — светлая тема по умолчанию и тёмный фолбэк на случай,
   если приложение открыто не в Telegram. Внутри Telegram эти переменные
   переопределяются в рантайме через Telegram.WebApp.themeParams (см. app.js),
   так что фирменный синий держится и в тёмной теме Telegram — меняется
   только фон/карточки под системную тему. */

:root {
  --bg: #F5F8FC;
  --card: #FFFFFF;
  --text: #0F172A;
  --hint: #64748B;
  --link: #2563EB;
  --btn: #2563EB;
  --btn-text: #FFFFFF;
  --border: #E2E8F0;
  --chip-bg: #EEF4FF;
  --chip-text: #1D4ED8;
  --danger: #DC2626;
  --danger-bg: #FEF0EF;
  --ok: #16A34A;
  --ok-bg: #EEFBF1;
  --warn: #D97706;
  --warn-bg: #FEF6E7;
  --ring: #93C5FD;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 1px rgba(15, 23, 42, .03);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  padding-bottom: calc(64px + var(--safe-bottom));
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-top)) 14px 10px;
}

.status { font-size: 13px; color: var(--hint); line-height: 1.5; }
.status b { color: var(--text); }
.status .paused { color: var(--warn); font-weight: 600; }
.status a { color: var(--link); text-decoration: none; font-weight: 600; }

#app { padding: 12px 14px 24px; max-width: 640px; margin: 0 auto; }

.tab[hidden] { display: none; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--hint);
  margin: 22px 2px 8px;
}
.section-title .muted { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--link); }

.add-box {
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

textarea, input[type=time], input[type=text], select {
  width: 100%;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--link);
  box-shadow: 0 0 0 3px var(--chip-bg);
}

textarea { min-height: 90px; resize: vertical; line-height: 1.4; }

.add-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
  font-size: 13px;
}

.char-count { color: var(--hint); font-variant-numeric: tabular-nums; }
.char-count.over { color: var(--danger); font-weight: 700; }

.bulk-toggle { display: flex; align-items: center; gap: 6px; color: var(--hint); }
.bulk-toggle input { margin: 0; accent-color: var(--link); }

.bulk-preview {
  font-size: 13px;
  color: var(--chip-text);
  background: var(--chip-bg);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 36px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  background: var(--chip-bg);
  color: var(--chip-text);
  cursor: pointer;
  transition: transform .1s ease, opacity .15s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: var(--btn);
  color: var(--btn-text);
  width: 100%;
  min-height: 46px;
  padding: 12px;
  font-size: 15px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, .22);
}
.btn.secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn.small { min-height: 32px; padding: 6px 12px; font-size: 13px; }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.accent { background: var(--btn); color: var(--btn-text); }
.btn:disabled { opacity: .5; transform: none; cursor: default; }

#gateScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(24px + var(--safe-top)) calc(24px + var(--safe-bottom));
}
/* Без этого правила JS-переключение gateScreen.hidden=true ничего не
   меняет визуально: наше собственное `display: flex` выше перебивает
   встроенное браузерное `[hidden]{display:none}`, потому что авторские
   стили побеждают стили user-agent независимо от специфичности. Именно
   это не давало войти через Telegram — initData приходил, enterApp()
   отрабатывал, hidden выставлялся, а экран входа всё равно оставался
   видимым поверх открывшегося приложения. */
#gateScreen[hidden] { display: none; }
.gate-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 26px;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.gate-card h1 { font-size: 19px; margin: 0 0 16px; }
.gate-card p { color: var(--hint); font-size: 14px; margin: 0 0 20px; line-height: 1.5; }
.gate-card .btn.primary { text-decoration: none; }

.gate-divider { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; color: var(--hint); font-size: 12.5px; }
.gate-divider::before, .gate-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.gate-tabs { display: flex; gap: 6px; margin-bottom: 18px; background: var(--bg); border-radius: 10px; padding: 3px; }
.gate-tab {
  flex: 1; border: none; background: transparent; border-radius: 8px; padding: 8px 0;
  font-size: 13px; font-weight: 600; color: var(--hint); cursor: pointer; transition: background-color .15s ease, color .15s ease;
}
.gate-tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-card); }
.gate-form { text-align: left; }
.gate-form label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.gate-form label:first-of-type { margin-top: 0; }
.gate-form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; background: var(--card); color: var(--text); font-family: inherit;
}
.gate-form .btn.primary { margin-top: 16px; }
.gate-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; min-height: 18px; text-align: left; }
.gate-hint { color: var(--hint); font-size: 12.5px; margin: 18px 0 0; line-height: 1.5; text-align: center; }
.gate-hint a { color: var(--link); }

#accountLinkBox:empty { display: none; }
.account-identity { font-size: 13px; color: var(--text); margin-bottom: 6px; }
.account-identity .verified { color: var(--ok); }
.account-identity .unverified { color: var(--warn); }
.link-code-display {
  font-size: 24px; font-weight: 700; letter-spacing: 3px; text-align: center;
  background: var(--chip-bg); color: var(--chip-text); border-radius: 10px; padding: 12px; margin: 10px 0;
}

.post-list, .slot-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.post-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
}
.post-card.next { border-color: var(--link); box-shadow: 0 0 0 3px var(--chip-bg); }

.post-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--hint); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.post-meta .next-label { color: var(--link); font-weight: 700; }
.post-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.post-text.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}
.text-toggle {
  display: block;
  background: none;
  border: none;
  color: var(--link);
  font-weight: 600;
  font-size: 12px;
  padding: 6px 0 0;
  margin: 0;
  cursor: pointer;
}
.post-edit { width: 100%; min-height: 80px; }

.post-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.reason { color: var(--danger); font-size: 12px; margin-top: 4px; }

.stats { display: flex; gap: 16px; font-size: 12px; color: var(--hint); margin-top: 8px; font-variant-numeric: tabular-nums; }
.stats span { display: flex; gap: 4px; align-items: center; }

.slot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
}
.slot-item button {
  background: var(--danger-bg);
  color: var(--danger);
  border: none;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.empty { color: var(--hint); text-align: center; padding: 28px 16px; font-size: 14px; }

a.permalink { color: var(--link); text-decoration: none; font-size: 13px; font-weight: 600; }
a.permalink:hover { text-decoration: underline; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 4px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--hint);
  position: relative;
}
.tab-btn.active { color: var(--link); font-weight: 700; }
.tab-btn.active::before {
  content: "";
  position: absolute;
  top: 0; left: 30%; right: 30%;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--link);
}

.toast {
  position: fixed;
  left: 14px; right: 14px;
  bottom: calc(72px + var(--safe-bottom));
  background: #1E293B;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
}
.toast.error { background: var(--danger); }

.file-hint { font-size: 12px; color: var(--hint); margin: 8px 2px 0; }
#fileBtn { margin-top: 8px; width: 100%; }

/* Тёмная тема — и по системным настройкам, и когда Telegram сообщает
   свою тему через colorScheme (app.js ставит data-theme на <html>,
   это надёжнее prefers-color-scheme, если тема Telegram отличается
   от системной). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1220;
    --card: #121B2E;
    --text: #F1F5F9;
    --hint: #94A3B8;
    --link: #60A5FA;
    --btn: #3B82F6;
    --border: #1E2B45;
    --chip-bg: #17233B;
    --chip-text: #93C5FD;
    --danger-bg: rgba(220, 38, 38, .16);
    --ok-bg: rgba(22, 163, 74, .16);
    --warn-bg: rgba(217, 119, 6, .16);
    --ring: #3B82F6;
    --shadow-card: none;
  }
  :root:not([data-theme="light"]) .toast { background: #1E2B45; }
}
:root[data-theme="dark"] {
  --bg: #0B1220;
  --card: #121B2E;
  --text: #F1F5F9;
  --hint: #94A3B8;
  --link: #60A5FA;
  --btn: #3B82F6;
  --border: #1E2B45;
  --chip-bg: #17233B;
  --chip-text: #93C5FD;
  --danger-bg: rgba(220, 38, 38, .16);
  --ok-bg: rgba(22, 163, 74, .16);
  --warn-bg: rgba(217, 119, 6, .16);
  --ring: #3B82F6;
  --shadow-card: none;
}
:root[data-theme="dark"] .toast { background: #1E2B45; }

.status-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.status-dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }

.account-select {
  width: auto;
  max-width: 100%;
  margin-bottom: 6px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--chip-text);
  background: var(--chip-bg);
  border: none;
  border-radius: 999px;
}

/* ---------- Постинг 2: медиа-вложение к посту, кнопки-пара, площадки ---------- */

.add-row-buttons { display: flex; gap: 8px; margin-top: 8px; }
.add-row-buttons .btn { flex: 1; }

.media-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--chip-bg);
  color: var(--chip-text);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 13px;
}

.platform-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.platform-card.disabled { opacity: .55; }
.platform-card .platform-name { font-weight: 600; }
.platform-card .platform-note { font-size: 12px; color: var(--hint); display: block; margin-top: 2px; }

.channel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.channel-card .channel-name { font-weight: 600; }

.topbar { position: sticky; }
.admin-link { position: absolute; right: 14px; top: calc(10px + var(--safe-top)); font-size: 13px; font-weight: 600; color: var(--link); text-decoration: none;
  background: var(--chip-bg); border-radius: 999px; padding: 7px 12px; min-height: 32px; display: inline-flex; align-items: center; }

/* ИИ-посты для Telegram */
.field-label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--hint, #6b7280); }
.add-box input[type=text] { width: 100%; box-sizing: border-box; }
.draft-preview { white-space: pre-wrap; word-break: break-word; line-height: 1.45; margin: 8px 0; }
.draft-preview a { color: var(--link); text-decoration: underline; }
.draft-warn { color: var(--danger); font-size: 13px; margin: 4px 0; }
.draft-photos { margin: 6px 0; font-size: 13px; color: var(--hint, #6b7280); }
.post-actions.wrap { flex-wrap: wrap; }
