/* =========================================================================
   TeaHousePosts — design system
   Linear / Vercel inspired. Dark by default, neutral with indigo accent.
   ========================================================================= */

:root {
  --bg: #0a0a0b;
  --bg-elevated: #111114;
  --bg-card: #141417;
  --bg-card-hover: #18181c;
  --bg-input: #0e0e10;
  --border: #23232a;
  --border-strong: #2f2f37;
  --border-hover: #3a3a44;
  --text: #ededed;
  --text-dim: #8c8c93;
  --text-faint: #8a8a93;       /* raised from #6b6b75 to clear WCAG AA (5:1 on --bg) */
  --accent: #6366f1;
  --accent-hover: #7679f3;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --accent-border: rgba(99, 102, 241, 0.35);
  --success: #46c08a;
  --success-dim: rgba(70, 192, 138, 0.12);
  --success-border: rgba(70, 192, 138, 0.32);
  --success-text: #07140d;      /* text colour for filled success buttons / today tag */
  --success-hover: #5fd49d;     /* hover for filled success buttons */
  --warning: #eab045;
  --warning-dim: rgba(234, 176, 69, 0.12);
  --warning-border: rgba(234, 176, 69, 0.32);
  --danger: #ef5350;
  --danger-dim: rgba(239, 83, 80, 0.12);
  --danger-border: rgba(239, 83, 80, 0.32);

  /* Telegram-preview palette (matches the channel look; not theme-aware on purpose). */
  --tg-bg: #17212b;
  --tg-text: #d8e3eb;
  --tg-link: #6ab3f3;
  --tg-code-text: #e8e8e8;

  --sidebar-w: 232px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --shadow-card: 0 1px 0 rgba(255,255,255,0.04) inset, 0 0 0 1px var(--border);
  --shadow-input: 0 0 0 1px var(--border) inset;
  --shadow-input-focus: 0 0 0 1px var(--accent) inset, 0 0 0 3px var(--accent-dim);

  /* Tells the browser to render NATIVE form controls (date pickers, dropdowns,
     calendar popups, scrollbars) in dark mode. Without this, <input type=date>
     etc. fall back to the OS light theme and look like a white box inside our
     dark UI. Overridden to `light` under [data-theme="light"] below. */
  color-scheme: dark;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Spacing scale — 4px base, 8px grid. Use these instead of magic numbers. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Typography scale. */
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-lg: 14px;
  --text-xl: 16px;
  --text-2xl: 18px;
  --text-3xl: 20px;
  --text-4xl: 22px;
  --lh-tight: 1.35;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;

  /* Breakpoints (informational, mirrored in media queries below).
     sm: 640px, md: 768px, lg: 1024px, xl: 1280px */
}

/* =========================================================================
   Light theme overrides — applied when <html data-theme="light"> is set.
   Components that use CSS vars automatically adapt; the few hardcoded
   colours (modal backdrop, Telegram draft preview) stay as-is intentionally.
   ========================================================================= */
:root[data-theme="light"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f4f4f5;
  --bg-input: #ffffff;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --border-hover: #a1a1aa;
  --text: #18181b;
  --text-dim: #52525b;
  --text-faint: #71717a;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-dim: rgba(79, 70, 229, 0.10);
  --accent-border: rgba(79, 70, 229, 0.35);
  --success: #16a34a;
  --success-dim: rgba(22, 163, 74, 0.10);
  --success-border: rgba(22, 163, 74, 0.30);
  --success-text: #ffffff;
  --success-hover: #15803d;
  --warning: #b45309;
  --warning-dim: rgba(180, 83, 9, 0.10);
  --warning-border: rgba(180, 83, 9, 0.30);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.10);
  --danger-border: rgba(220, 38, 38, 0.30);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 1px var(--border);
  color-scheme: light;
}

/* Logo is a pure-white SVG; flip to near-black in light mode. */
:root[data-theme="light"] .sidebar-brand img,
:root[data-theme="light"] .mobile-topbar-brand img {
  filter: invert(1) brightness(0.85);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
code {
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text);
}

hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

/* =================== Layout =================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  padding: 16px 12px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.sidebar-brand {
  display: flex; align-items: center; justify-content: flex-start;
  padding: 4px 10px;
  margin-bottom: 18px;
}
.sidebar-brand img { height: 36px; width: auto; border-radius: 6px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.sidebar-nav a:hover {
  background: var(--bg-card);
  color: var(--text);
}
.sidebar-nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  color: var(--text);
}
.sidebar-nav a.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar-nav a svg { flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  font-size: 11.5px; color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
.sidebar-footer-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
/* Every control in the footer row shares one height so the labelled Restart
   button, the theme toggle and the logout icon line up as a clean set. */
.footer-ctl { height: 30px; border-radius: var(--radius-sm); }
.sidebar-restart { flex: 1; display: flex; min-width: 0; }  /* Restart fills the row — the easy, primary target */
.sidebar-restart .footer-restart { width: 100%; justify-content: center; }
.sidebar-footer-row .theme-toggle.footer-ctl { width: 30px; height: 30px; border-color: var(--border-strong); }
.sidebar-footer-row .btn-icon.footer-ctl { width: 30px; height: 30px; }

.sidebar-version {
  display: flex;
  flex-direction: column;
  line-height: 1.45;
  font-size: 11px;
  color: var(--text-faint);
}
.sidebar-credit { color: var(--text-faint); }
.sidebar-version a {
  color: var(--text-dim);
  text-decoration: none;
}
.sidebar-version a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Theme toggle: icon-only square button next to the Restart row.
   Shows sun in dark mode (click → switch to light) and moon in light. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  width: 24px;
  height: 24px;
  padding: 0;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.theme-toggle:hover { background: var(--bg-card-hover); color: var(--text); border-color: var(--border-hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .theme-icon-light { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .theme-icon-dark { display: none; }
/* Screen-reader-only labels — keep .sr-only hiding them visually, but make
   sure only one (matching the current theme) is announced. */
.theme-toggle .theme-label-light { display: none; }
:root[data-theme="light"] .theme-toggle .theme-label-light { display: inline; }
:root[data-theme="light"] .theme-toggle .theme-label-dark { display: none; }

.main {
  padding: 32px 40px;
  max-width: 1240px;
}

/* Mobile topbar (burger). Hidden on desktop. */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.mobile-topbar-brand img { height: 28px; }
.mobile-topbar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.mobile-topbar-toggle:hover { background: var(--bg-card); }
.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; display: block; }
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    box-shadow: 0 0 28px rgba(0, 0, 0, 0.4);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .sidebar-brand { display: none; }  /* duplicated in topbar */
  .main { padding: 16px; max-width: 100%; }
  .page-header h1 { font-size: 19px; }
}

/* =================== Headings =================== */

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header > div:first-child { flex: 1 1 320px; min-width: 0; }
.page-header h1 { margin: 0 0 6px 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.page-header .subtitle { color: var(--text-dim); font-size: 13.5px; margin: 0; max-width: 720px; }
.page-header .actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.005em; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.help-text { color: var(--text-dim); font-size: 12.5px; margin-top: 4px; }

/* =================== Cards =================== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.card-header h2 { margin: 0; }
.card-section + .card-section { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }

/* =================== Buttons =================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px;
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--border-hover); color: var(--text); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn svg { flex-shrink: 0; }

.btn-primary {
  background: var(--accent); color: white; border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover); color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-success {
  background: var(--success); color: var(--success-text); border-color: var(--success);
}
.btn-success:hover {
  background: var(--success-hover); border-color: var(--success-hover); color: var(--success-text);
  box-shadow: 0 2px 8px rgba(70, 192, 138, 0.4);
}

.btn-danger {
  background: transparent; color: var(--danger); border-color: var(--danger-border);
}
.btn-danger:hover { background: var(--danger-dim); color: var(--danger); border-color: var(--danger); }

/* Outline / neutral secondary button — use when an action is non-destructive
   but not primary (e.g. cancel, secondary save). */
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

/* Icon-only button. Always pair with aria-label or title. */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon.btn-sm { width: 28px; height: 28px; }

.btn-ghost {
  background: transparent; border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-card-hover); }

.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-lg { padding: 9px 16px; font-size: 14px; }

form.inline { display: inline-flex; }

/* =================== Inputs =================== */

label.field {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 14px;
}
label.field > span:first-child {
  font-size: 13px; font-weight: 500; color: var(--text);
}
.field-help { font-size: 12px; color: var(--text-dim); }

/* Date/time/url/email types were missing from this selector — without them the
   <input type=date> and <input type=url> fell back to the OS-native light style,
   showing as white boxes inside our dark cards. They are styled the same as text
   inputs; the calendar / clock picker icons get colour-corrected below. */
input[type="text"], input[type="password"], input[type="number"], input[type="search"],
input[type="email"], input[type="url"], input[type="tel"],
input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"], input[type="week"],
input:not([type]), textarea, select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-sans); font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  background: var(--bg-card);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

/* Webkit calendar / clock picker icon — inverted so it's visible on the dark
   input background. The browser draws this as a black SVG by default; flipping
   it to near-white matches our text colour. Light theme leaves it untouched. */
:root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator,
:root:not([data-theme="light"]) input[type="datetime-local"]::-webkit-calendar-picker-indicator,
:root:not([data-theme="light"]) input[type="time"]::-webkit-calendar-picker-indicator,
:root:not([data-theme="light"]) input[type="month"]::-webkit-calendar-picker-indicator,
:root:not([data-theme="light"]) input[type="week"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7) brightness(1.1);
  cursor: pointer;
  opacity: 0.7;
}
:root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator:hover,
:root:not([data-theme="light"]) input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
:root:not([data-theme="light"]) input[type="time"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* Tabular numerals inside date/time fields so digits don't jiggle while
   typing — feels more "form input" than "text". Also blocks the WebKit
   built-in spin buttons we don't use. */
input[type="date"], input[type="datetime-local"], input[type="time"],
input[type="month"], input[type="week"] {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono), var(--font-sans);
  font-size: 13px;
}

textarea { resize: vertical; min-height: 80px; font-family: var(--font-sans); line-height: 1.5; }
textarea.mono, textarea.code { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; }

input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  vertical-align: middle;
}
input[type="file"] {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px; font-size: 13px;
}
input[type="file"]::file-selector-button {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 5px;
  padding: 5px 10px; font-size: 12.5px; margin-right: 10px;
  cursor: pointer;
}

.field-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-elevated);
}
.checkbox-row input { margin-top: 2px; }
.checkbox-row .lbl { font-weight: 500; }
.checkbox-row .sub { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

/* =================== Tables =================== */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left; font-weight: 500;
  color: var(--text-dim); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:hover { background: var(--bg-card-hover); }
tbody tr:last-child td { border-bottom: 0; }
table.compact td { padding: 7px 12px; }

/* Hide non-essential table columns on narrow screens. */
@media (max-width: 720px) {
  .col-hide-sm { display: none; }
}

/* Wide data tables (Sources / Articles) inside cards: let them scroll
   horizontally on narrow screens instead of getting clipped by the card. */
@media (max-width: 800px) {
  .card > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card > table thead, .card > table tbody { width: max-content; min-width: 100%; }
}

/* =================== Login page =================== */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  padding: 24px;
  background:
    radial-gradient(800px 400px at 50% -10%, var(--accent-dim), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.login-logo {
  display: inline-flex;
  margin-bottom: 18px;
}
.login-logo img {
  height: 40px;
  width: auto;
}
:root[data-theme="light"] .login-logo img {
  filter: invert(1) brightness(0.85);
}
.login-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.login-subtitle {
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--text-dim);
}
.login-form {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.login-form .field {
  margin-bottom: 12px;
}
.login-submit {
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  font-size: 14px;
}
.login-error {
  background: var(--danger-dim);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

/* =================== Sortable table headers =================== */

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
}
th.sortable:hover { color: var(--text); }
th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* Unified inline-flex wrap so the label, optional help-tip and the sort arrow
   all stay on a single baseline — independent of the header's content. */
.th-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
}
/* Sort indicator: a CSS chevron pair. Two 6×6 squares with diagonal borders
   form an up + down arrow. The active state hides one of them. */
.sort-indicator {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  width: 8px;
  margin-left: 2px;
  color: var(--text-faint);
  transition: color 0.12s;
}
.sort-indicator::before,
.sort-indicator::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  opacity: 0.55;
}
.sort-indicator::before { border-bottom: 4px solid currentColor; }
.sort-indicator::after  { border-top: 4px solid currentColor; }
th.sortable:hover .sort-indicator { color: var(--text-dim); }
th.sortable.sort-asc .sort-indicator,
th.sortable.sort-desc .sort-indicator { color: var(--accent); }
th.sortable.sort-asc .sort-indicator::before  { opacity: 1; }
th.sortable.sort-asc .sort-indicator::after   { opacity: 0.2; }
th.sortable.sort-desc .sort-indicator::before { opacity: 0.2; }
th.sortable.sort-desc .sort-indicator::after  { opacity: 1; }

/* =================== Sources: priority select tiers =================== */

.priority-select {
  width: auto;
  min-width: 130px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  border-width: 1px;
  cursor: pointer;
}
.priority-select.priority-high {
  color: var(--success);
  background: var(--success-dim);
  border-color: var(--success-border);
}
.priority-select.priority-normal {
  color: var(--text);
  background: var(--bg-elevated);
  border-color: var(--border);
}
.priority-select.priority-low {
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-color: var(--border);
  font-weight: 400;
}
.priority-select:disabled { opacity: 0.6; cursor: wait; }

.priority-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.priority-status {
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: opacity 0.2s ease;
}
.priority-status-pending { color: var(--text-dim); }
.priority-status-success { color: var(--success); }
.priority-status-error { color: var(--danger); }

/* Brief green pulse on the select right after a successful save. */
@keyframes priority-saved-pulse {
  0%   { box-shadow: 0 0 0 0 var(--success-border); }
  60%  { box-shadow: 0 0 0 4px var(--success-dim); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.priority-select.is-just-saved { animation: priority-saved-pulse 0.9s ease-out; }

/* =================== Settings: weekly schedule rows =================== */

.schedule-form { display: flex; flex-direction: column; }
.schedule-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.schedule-row:last-of-type { border-bottom: 0; }
.schedule-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.schedule-label { font-weight: 500; font-size: 13.5px; }
.schedule-detail { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.schedule-raw { color: var(--warning); font-size: 11.5px; margin-top: 4px; }
.schedule-controls { display: flex; gap: 8px; align-items: center; }
.schedule-controls select { width: 92px; }
.schedule-controls input[type="time"] { width: 110px; }
@media (max-width: 600px) {
  .schedule-row { grid-template-columns: 36px 1fr; }
  .schedule-controls { grid-column: 1 / -1; margin-left: 52px; }
}

/* =================== Coming up / automation timeline =================== */

.timeline { display: flex; flex-direction: column; }
.timeline-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-row:last-child { border-bottom: 0; }
.timeline-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.timeline-row.is-soon .timeline-icon {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent-border);
}
.timeline-meta .label { font-weight: 500; font-size: 13.5px; color: var(--text); }
.timeline-meta .detail { color: var(--text-dim); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.timeline-when { text-align: right; white-space: nowrap; }
.timeline-when .when-abs { font-weight: 500; font-size: 13px; color: var(--text); }
.timeline-when .when-rel { color: var(--text-dim); font-size: 11.5px; margin-top: 2px; }
.timeline-row.is-soon .timeline-when .when-rel { color: var(--accent); font-weight: 500; }
@media (max-width: 600px) {
  .timeline-row { grid-template-columns: 32px 1fr; gap: 10px; }
  .timeline-when { grid-column: 2; text-align: left; margin-top: 4px; }
  .timeline-when .when-abs, .timeline-when .when-rel { display: inline; margin-right: 8px; }
}

/* =================== Badges =================== */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  font-size: 11.5px; font-weight: 500;
  border-radius: 999px;
  border: 1px solid;
  line-height: 1.5;
}
.badge::before {
  content: ""; width: 6px; height: 6px;
  border-radius: 50%; background: currentColor;
}
.badge-pending   { color: var(--warning); border-color: var(--warning-border); background: var(--warning-dim); }
.badge-approved  { color: var(--success); border-color: var(--success-border); background: var(--success-dim); }
.badge-posted    { color: var(--accent);  border-color: var(--accent-border);  background: var(--accent-dim); }
.badge-rejected  { color: var(--danger);  border-color: var(--danger-border);  background: var(--danger-dim); }
.badge-failed    { color: var(--danger);  border-color: var(--danger-border);  background: var(--danger-dim); }
.badge-publishing{ color: var(--accent);  border-color: var(--accent-border);  background: var(--accent-dim); }
.badge-default   { color: var(--text-dim); border-color: var(--border); background: var(--bg-elevated); }
.badge-connected { color: var(--success); border-color: var(--success-border); background: var(--success-dim); }

/* AI editorial score 0-100. Three colour bands match the system prompt's tier ladder. */
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; padding: 2px 8px;
  border-radius: 4px; font-weight: 600; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  border: 1px solid; cursor: help;
}
.score-red   { color: var(--danger);  border-color: var(--danger-border);  background: var(--danger-dim); }
.score-amber { color: var(--warning); border-color: var(--warning-border); background: var(--warning-dim); }
.score-green { color: var(--success); border-color: var(--success-border); background: var(--success-dim); }

/* The "How AI picks news" info card on the Articles page. Collapsible via
   <details>/<summary> so power users can hide it after onboarding. */
.score-explainer {
  border-left: 3px solid var(--accent);
}
.score-explainer-summary {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; list-style: none;
  font-size: 14.5px;
}
.score-explainer-summary::-webkit-details-marker { display: none; }
.score-explainer-summary svg { color: var(--accent); flex-shrink: 0; }
.score-explainer[open] .score-explainer-summary { margin-bottom: 12px; }
.score-explainer-summary .ml-auto { margin-left: auto; }
.score-explainer-body p:last-child { margin-bottom: 0; }
.score-explainer-body code { font-size: 12px; }

/* One-line AI reason shown under each article title on /articles/. Subtle but
   readable — italic + accent icon — so the operator can scan a page of reasons. */
.score-reason {
  font-style: italic;
  display: flex; align-items: center; gap: 6px;
  color: var(--text-dim);
}
.score-reason svg { color: var(--accent); flex-shrink: 0; }

/* Compact select for inline filter dropdowns (e.g. Sort on Articles). */
.select-sm {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--text);
  font-size: 13px; height: 28px;
}
.select-sm:focus { outline: none; border-color: var(--accent); }

/* ====== Articles filter bar (compact, single card) ====== */
.filter-bar { padding: 14px 18px; }
.filter-bar .filter-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.filter-bar .filter-row:last-child { border-bottom: none; }
.filter-label {
  flex-shrink: 0; min-width: 64px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em;
  padding-top: 6px;
}
.filter-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  flex: 1; min-width: 0;
}
.filter-search { align-items: center; flex-wrap: wrap; }
.filter-search-input {
  flex: 1; min-width: 220px;
  padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--text); font-size: 13px;
}
.filter-search-input:focus { outline: none; border-color: var(--accent); }
.filter-summary { font-size: 12.5px; }

/* ====== Sortable header link (overrides <th> built-in link styling) ====== */
th.sortable .th-sort-link {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: inherit;
  /* Pull the click target out to fill the whole header cell, so the entire
     header area is clickable, not just the text. */
  margin: -10px -10px;
  padding: 10px 10px;
}
th.sortable .th-sort-link:hover { color: var(--text); }
th.sortable .th-sort-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 4px;
}

/* ====== Articles table micro-polish ====== */
.articles-table .col-id { width: 56px; }
.articles-table .col-title { min-width: 320px; }
.articles-table th { white-space: nowrap; }

/* ====== Inline spinner for loading buttons ====== */
.btn .spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; vertical-align: -2px;
  animation: btn-spin 0.7s linear infinite;
  margin-right: 4px;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
.btn.is-loading { opacity: 0.85; cursor: progress; }

/* ====== Articles pagination tightening ====== */
.articles-pagination { padding-top: 8px; border-top: 1px solid var(--border); margin-top: 16px; }

/* Collapsed snapshot of the editorial criteria that produced this draft.
   Click to expand. Kept low-key — surfaced for context, not as primary content. */
.criteria-snapshot summary {
  cursor: pointer; padding: 6px 10px;
  border: 1px dashed var(--border); border-radius: 6px;
  display: inline-flex; align-items: center; gap: 6px;
}
.criteria-snapshot summary:hover { border-color: var(--border-hover); color: var(--text); }
.criteria-snapshot summary svg { color: var(--accent); }
.criteria-snapshot-body {
  margin: 8px 0 0; padding: 12px 14px;
  background: var(--bg-elevated); border-radius: 6px;
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap;
  color: var(--text-dim); border: 1px solid var(--border);
  max-height: 280px; overflow-y: auto;
}

/* Clickable filter chip — used on /articles/ to filter by source */
.badge-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 12.5px;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.badge-link:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  color: var(--text);
}
.badge-link strong {
  background: var(--bg-card);
  color: var(--text);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11.5px;
}
.badge-link.is-active {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--text);
}
.badge-link.is-active strong { background: var(--accent); color: white; }

/* =================== Switch (toggle) =================== */

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  vertical-align: middle;
  cursor: pointer;
  flex-shrink: 0;
}
.switch input {
  position: absolute;
  opacity: 0; width: 0; height: 0;
}
.switch .slider {
  position: absolute; inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background 0.18s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.18s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.switch input:checked + .slider {
  background: var(--success);
}
.switch input:checked + .slider::before {
  transform: translateX(14px);
}
.switch input:disabled + .slider {
  opacity: 0.5; cursor: not-allowed;
}
.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* =================== Toast container (floating) =================== */

#toast-container {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  max-width: 380px;
}
#toast-container .toast {
  margin: 0;
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.4s, transform 0.4s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
#toast-container .toast.hiding { opacity: 0; transform: translateY(8px); }

/* =================== Toasts (inline) =================== */

.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid;
}
.toast-info { background: var(--accent-dim); border-color: var(--accent-border); color: var(--text); }
.toast-success { background: var(--success-dim); border-color: var(--success-border); color: var(--text); }
.toast-warning { background: var(--warning-dim); border-color: var(--warning-border); color: var(--text); }
.toast-error { background: var(--danger-dim); border-color: var(--danger-border); color: var(--text); }
.toast svg { flex-shrink: 0; margin-top: 1px; }

/* =================== Checklist (Dashboard) =================== */

.check-list { display: flex; flex-direction: column; }
.check-item {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center;
  gap: 14px; padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.check-item:last-child { border-bottom: 0; }
.check-icon {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.check-icon.ok { color: var(--success); background: var(--success-dim); }
.check-icon.warn { color: var(--warning); background: var(--warning-dim); }
.check-meta .label { font-weight: 500; }
.check-meta .detail { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.check-meta .help { color: var(--text-faint); font-size: 12px; margin-top: 4px; }

/* =================== Grid layouts =================== */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }

/* =================== Settings sections =================== */

.section { margin-bottom: 32px; }
.section-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.section-header h2 { margin: 0; font-size: 16px; }
.section-header .icon { color: var(--text-dim); }
.section-subtitle { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }

/* =================== Tabs =================== */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
  /* Setting overflow-x makes overflow-y default to 'auto' (CSS quirk) — explicitly suppress it. */
  overflow-y: hidden;
}
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
  cursor: pointer;
}
.tabs a:hover { color: var(--text); background: var(--bg-card-hover); }
.tabs a.active:hover { background: transparent; }
.tabs a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  color: var(--text);
}
.tabs a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tabs a svg { opacity: 0.85; }
.tabs a.active svg { opacity: 1; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Pipeline view-switch is now rendered with the same `.tabs` styling as
   Settings/Compose for visual consistency. The `.view-switch-tabs` modifier
   is a marker for JS/test selectors only — no extra style needed unless we
   want to slightly tweak it later. The previous bordered segmented-control
   variant was retired so the toggle reads unambiguously as section tabs. */

/* =================== Preview (draft) =================== */

/* Title-line preview: bold caption directly under the cover, matching how
   Telegram renders the photo's caption above the body text. */
.draft-title {
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  padding: 14px 18px 0;
  margin-top: 16px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  word-wrap: break-word;
}
.draft-title:empty { display: none; }

.draft-preview {
  background: var(--tg-bg);
  color: var(--tg-text);
  border-radius: var(--radius);
  padding: 18px;
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px; line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  border: 1px solid var(--border);
  margin-top: 16px;
}
/* When the title is present, merge it visually with the body (no border between). */
.draft-title + .draft-preview {
  margin-top: 0;
  border-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  padding-top: 10px;
}
.draft-preview a {
  color: var(--tg-link);
  text-decoration: none;
}
.draft-preview a:hover { text-decoration: underline; }
.draft-preview code {
  background: rgba(255, 255, 255, 0.08);
  color: var(--tg-code-text);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.draft-preview pre {
  background: rgba(0, 0, 0, 0.25);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}
.draft-preview pre code { background: transparent; padding: 0; }
.draft-preview .tg-spoiler {
  background: rgba(255, 255, 255, 0.18);
  color: transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: color 0.2s;
}
.draft-preview .tg-spoiler:hover { color: var(--tg-text); }
.draft-preview .tg-quote {
  margin: 6px 0;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 3px solid var(--tg-link);
  border-radius: 4px;
  white-space: pre-wrap;
}

/* Live-preview card: sticky to top of viewport, but capped so a long body
   stays scrollable inside the card instead of overflowing past the screen. */
.live-preview-card {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =================== Compose page — split layout ===================
   Left pane scrolls naturally with the page. Right pane is sticky so the
   live preview + action buttons stay visible while the operator edits. */
.compose-layout { align-items: flex-start; }
.compose-edit { display: flex; flex-direction: column; gap: 16px; }
.compose-side {
  display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
/* Wider gutter when there's room — the preview deserves it. */
@media (min-width: 1100px) {
  .compose-layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .compose-side { position: static; max-height: none; }
}

/* Telegram-look mock — mimics the channel post the bot will publish.
   Background + bubble shape borrowed from the existing .tg-* palette
   (defined near the top of this file). */
.compose-preview-card { padding: 14px 16px 16px; }
.tg-mock {
  background: var(--tg-bg);
  border-radius: 12px;
  overflow: hidden;
  color: var(--tg-text);
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 4px 18px rgba(0,0,0,0.35);
}
.tg-mock-cover {
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #0b1219;
  display: flex; align-items: center; justify-content: center;
  /* Becomes the positioning context + drag-canvas for the overlays
     (.cover-bg + .logo-overlay + .text-overlay sit inside, absolutely
     positioned). The .cover-canvas class is shared for compatibility with
     the existing JS that reads getBoundingClientRect of this container. */
  position: relative;
  overflow: hidden;
  user-select: none;
}
.tg-mock-cover .cover-bg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  /* contain (not cover) so the operator sees the FULL uploaded image with
     letterbox bars instead of a zoomed-in crop. Telegram preserves the
     original aspect ratio when delivering the photo, so the preview should
     match: a 4:3 phone snap shouldn't lose its top/bottom in the mock. The
     dark canvas background (#0b1219) fills the bars cleanly. */
  object-fit: contain;
  display: block;
}
.tg-mock-cover-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  /* The cover area is a hardcoded dark #0b1219 (Telegram-look) regardless of
     theme — keep the placeholder light enough to read against it. Solid
     readable contrast (~76% white) rather than the previous 40% which was
     barely visible in light mode where the rest of the page is bright. */
  color: rgba(255, 255, 255, 0.76);
  font-size: 13px;
  text-align: center; padding: 0 12px;
}
.tg-mock-meta { padding: 12px 14px 14px; }
.tg-mock-channel {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: rgba(216, 227, 235, 0.6);
  margin-bottom: 8px;
}
.tg-mock-channel-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, #4a8bd2, #2a5e9c);
  display: inline-block;
}
.tg-mock-channel-name { color: var(--tg-text); font-weight: 600; }
.tg-mock-title {
  font-size: 14.5px; font-weight: 600; color: var(--tg-text);
  margin: 0 0 6px;
  word-break: break-word;
}
.tg-mock-title.is-empty,
.tg-mock-body.is-empty {
  color: rgba(216, 227, 235, 0.4);
  font-style: italic;
  font-weight: normal;
}
.tg-mock-title.is-empty::before { content: attr(data-empty); }
.tg-mock-body.is-empty::before { content: attr(data-empty); }
.tg-mock-body {
  font-size: 13.5px;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ====== Inline align-buttons (used by title-overlay alignment row) ======
   Compact icon-only buttons. Active state highlighted with accent. */
.btn-align {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 24px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.btn-align:hover { color: var(--text); background: var(--bg-card-hover); }
.btn-align[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-dim);
}
.text-align-row { gap: 6px; }

/* Compact textarea for the title-overlay text input — about half the
   default height. The overlay is usually 1-2 short lines, and the live
   preview on the cover is what really matters for layout. */
.text-overlay-input-compact {
  min-height: 0;
  padding: 4px 8px;
  line-height: 1.25;
  font-size: 12px;
  resize: vertical;
}

/* Image-engine + model dropdowns row — compact, single line on desktop. */
.image-engine-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.image-engine-label {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px;
}
.image-engine-label select {
  padding: 3px 6px;
  font-size: 12px;
  height: auto;
  width: auto;
}
.image-engine-note {
  line-height: 1.45;
  font-size: 12px;
  color: var(--text);
}

/* "?" popover — keeps the engine note out of the layout until the operator
   clicks the icon. Uses the native <details> element so it's keyboard-
   accessible and works without JS. The popover floats over surrounding
   content so opening it never pushes the body editor down. */
.image-engine-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 2px;
}
.image-engine-help summary.image-engine-help-summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  color: var(--muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: color .12s, border-color .12s, background .12s;
}
.image-engine-help summary.image-engine-help-summary::-webkit-details-marker { display: none; }
.image-engine-help summary.image-engine-help-summary:hover,
.image-engine-help[open] summary.image-engine-help-summary {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}
.image-engine-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  max-width: 90vw;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.16);
}

/* Direct "Get key" link. Compact, slightly accented so the operator
   notices it on first paint — paid engines need a key, no point hiding
   the call to action. */
.image-engine-setup-link {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  text-decoration: none;
}
.image-engine-setup-link:hover {
  background: var(--accent);
  color: var(--bg);
}
.image-engine-setup-link[hidden] { display: none !important; }

/* 3-step how-to shown only when a paid engine has no key configured. */
.image-engine-howto {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--warning-border);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.image-engine-howto[hidden] { display: none !important; }
.image-engine-howto ol {
  margin: 6px 0 0; padding-left: 18px;
}
.image-engine-howto code {
  font-size: 11.5px;
  padding: 1px 4px;
  background: var(--bg-elevated);
  border-radius: 3px;
}

/* ====== Compose cover-tools card — compact controls under the preview ====== */
.compose-cover-tools { padding: 14px 16px 16px; }
.compose-cover-tools .field { margin-bottom: 10px; }
.cover-tools-divider {
  border: none; border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* Labelled "or" divider between the two ways to add a cover (generate vs
   upload). A faint line on each side of a centered text chip makes the
   either/or relationship obvious without a heavy heading. */
.cover-source-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0 10px;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.cover-source-divider::before,
.cover-source-divider::after {
  content: ""; flex: 1;
  border-top: 1px solid var(--border);
}
.cover-source-divider span { padding: 0 2px; }
.overlay-controls[hidden] { display: none !important; }
.overlay-block {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
.overlay-toggle-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}
.overlay-toggle-row input[type="checkbox"] { width: 16px; height: 16px; }
.overlay-block-controls {
  margin-top: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.overlay-block-controls[hidden] { display: none !important; }
.overlay-row {
  display: flex; align-items: center; gap: 8px;
}
.overlay-row input[type="range"] { flex: 1; min-width: 80px; }
.overlay-detail summary {
  cursor: pointer; padding: 4px 0;
  font-size: 11.5px;
}

/* Compose actions card — stack of four buttons + schedule field, grouped
   into "ship to channel" and "stay local" with caption labels. The caption
   labels are mini-headings so a tired operator at 11pm doesn't mash the
   green button thinking it's "Save draft". */
.compose-actions-card { padding: 14px 16px 16px; }
.compose-actions-card[hidden] { display: none !important; }
.compose-action-buttons {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 4px;
}
.compose-action-buttons .btn { width: 100%; justify-content: center; }
.compose-action-group-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  margin: 4px 0 0;
}
.compose-action-group-label.compose-action-group-safe {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.btn.btn-publish-now {
  /* Slightly more emphasis: this is the "ship it" button, give it weight. */
  font-weight: 600;
}

/* Placeholder card visible BEFORE the body has content — replaces the action
   card so the right pane isn't empty at first load. Hidden once .has-content. */
.compose-actions-placeholder {
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  box-shadow: none;
}
.compose-actions-placeholder[hidden] { display: none !important; }
.compose-actions-placeholder p {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim);
}
.compose-actions-placeholder svg { flex-shrink: 0; color: var(--accent); }

/* =================== Compose page — compact cover row ===================
   Two columns inside the Cover card: small preview on the left, generate /
   upload / logo-toggle controls share the right side. Eats much less
   vertical space than the old full-width canvas. The logo-controls strip
   (size + 9 presets + Bake) drops to full width below this row when shown. */
.cover-card-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 14px;
  align-items: start;
}
.cover-card-canvas-wrap { min-width: 0; }
.cover-card-controls {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.cover-card-controls .field-help { font-size: 11px; line-height: 1.35; }
.cover-canvas-compact { /* same .cover-canvas, just smaller via the grid */ }
.logo-overlay-toggle[hidden] { display: none !important; }

@media (max-width: 700px) {
  .cover-card-row { grid-template-columns: 1fr; }
}
.live-preview-card > .draft-preview {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.cover-thumb {
  /* Fills the live-preview card the same way the Compose page's
     .tg-mock-cover does — full pane width, natural aspect ratio (no
     height cap that would otherwise shrink the preview into a tiny strip
     and look inconsistent next to the Compose page). `align-self: stretch`
     would normally distort the image, but `height: auto` keeps the aspect
     intact since width drives the layout. The 1px border + radius match
     the Compose cover canvas, so a digest preview and a tea-post Compose
     preview look like the same widget. */
  width: 100%; height: auto;
  align-self: stretch;
  max-width: 100%;
  border-radius: var(--radius); display: block;
  border: 1px solid var(--border);
}

/* =================== Item rows (draft items, sortable) =================== */

.item-row {
  display: flex; flex-direction: column; gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  margin-bottom: 8px;
  cursor: default;
}
.item-row .title { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.item-row .meta { color: var(--text-dim); font-size: 12px; word-break: break-word; }
.item-row .meta a { color: var(--text-dim); text-decoration: underline; }
.item-row .meta a:hover { color: var(--text); }
.item-row select { max-width: 280px; }
.drag-handle {
  cursor: grab; color: var(--text-faint);
  display: inline-flex; align-items: center;
  padding: 6px;
  margin: -6px;
  border-radius: var(--radius-sm);
}
.drag-handle:hover { background: var(--bg-card-hover); color: var(--text-dim); }
.drag-handle:active { cursor: grabbing; }
.item-row.sortable-ghost { opacity: 0.4; }
.item-row.sortable-chosen { background: var(--bg-card-hover); border-color: var(--border-hover); }
@media (max-width: 600px) {
  .item-row select { max-width: 100%; }
}

/* Excluded items: dimmed + struck so the active set stays visually dominant. */
.item-row.item-excluded {
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
}
.item-row.item-excluded .title { color: var(--text-faint); font-weight: 400; }
.item-row.item-excluded .meta { opacity: 0.55; }
.item-row.item-excluded select { opacity: 0.55; }

/* =================== Logs viewer =================== */

.log-list {
  display: flex; flex-direction: column;
  max-height: 70vh; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.log-row {
  display: grid;
  grid-template-columns: 175px 84px minmax(160px, 240px) 1fr;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  align-items: start;
}
.log-row:last-child { border-bottom: 0; }
.log-row:hover { background: var(--bg-card-hover); }
.log-ts { color: var(--text-faint); }
.log-src {
  color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.log-msg {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}
.log-badge {
  font-family: var(--font-sans);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}
.log-badge::before { display: none; }  /* hide the dot for the log badges */
.log-badge.log-level-debug    { color: var(--text-faint); border-color: var(--border); background: var(--bg-elevated); }
.log-badge.log-level-info     { color: var(--accent);  border-color: var(--accent-border);  background: var(--accent-dim); }
.log-badge.log-level-warning  { color: var(--warning); border-color: var(--warning-border); background: var(--warning-dim); }
.log-badge.log-level-error,
.log-badge.log-level-critical { color: var(--danger);  border-color: var(--danger-border);  background: var(--danger-dim); }

.log-row.log-level-row-error,
.log-row.log-level-row-critical { background: rgba(239, 83, 80, 0.04); }
.log-row.log-level-row-warning  { background: rgba(234, 176, 69, 0.04); }

@media (max-width: 900px) {
  .log-row { grid-template-columns: 1fr; gap: 4px; }
  .log-src { white-space: normal; }
}

/* =================== Loading / spinners =================== */

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  left: 50%; top: 50%;
  margin: -7px 0 0 -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin-btn 0.7s linear infinite;
  color: var(--text);
}
.btn-primary.is-loading::after,
.btn-success.is-loading::after { border-color: white; border-top-color: transparent; }
@keyframes spin-btn { to { transform: rotate(360deg); } }

/* =================== Bot status indicator =================== */

.bot-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim);
}
.bot-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.bot-status .dot.ok    { background: var(--success); box-shadow: 0 0 0 2px rgba(70, 192, 138, 0.18); }
.bot-status .dot.warn  { background: var(--warning); box-shadow: 0 0 0 2px rgba(234, 176, 69, 0.18); }
.bot-status .dot.down  { background: var(--danger);  box-shadow: 0 0 0 2px rgba(239, 83, 80, 0.18); }

/* =================== Empty state =================== */

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-dim);
}
.empty-icon {
  display: inline-flex;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--bg-elevated);
  align-items: center; justify-content: center;
  color: var(--text-faint);
  margin-bottom: 12px;
}

/* =================== Error page =================== */

.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  margin: 0;
}
.error-card {
  text-align: center;
  padding: 40px;
  max-width: 480px;
}
.error-code {
  font-size: 64px;
  font-weight: 600;
  color: var(--text-faint);
  margin: 0;
  letter-spacing: -0.04em;
  font-family: var(--font-mono);
}
.error-title {
  font-size: 20px;
  font-weight: 600;
  margin: 8px 0 16px;
}
.error-desc {
  color: var(--text-dim);
  margin: 0 0 24px;
}

/* =================== Misc =================== */

details > summary {
  cursor: pointer;
  font-weight: 500;
  padding: 8px 0;
  color: var(--text);
  list-style: none;
  display: flex; align-items: center; gap: 6px;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '›';
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-dim);
}
details[open] > summary::before { transform: rotate(90deg); }
details .details-body { padding-top: 8px; padding-left: 14px; color: var(--text-dim); font-size: 13px; }

.kbd {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 4px; color: var(--text);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.photo-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}
.photo-card img { width: 100%; height: 140px; object-fit: cover; display: block; }
.photo-card .meta { padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.photo-card .name { font-size: 11.5px; color: var(--text-dim); word-break: break-all; }

.cat-thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--accent-border);
  background: var(--accent-dim);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.banner-icon { color: var(--accent); flex-shrink: 0; }

/* =================== Utilities =================== */

/* Spacing utilities (use the spacing scale tokens defined in :root). */
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.ml-1 { margin-left: var(--space-1); }
.ml-2 { margin-left: var(--space-2); }
.ml-auto, .push-right { margin-left: auto; }
.mr-1 { margin-right: var(--space-1); }
.mr-2 { margin-right: var(--space-2); }
.mx-1 { margin-left: var(--space-1); margin-right: var(--space-1); }
.mx-2 { margin-left: var(--space-2); margin-right: var(--space-2); }
.pl-list { padding-left: 18px; }

/* Typography utilities. */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-sm-plus { font-size: 12.5px; }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-right { text-align: right; }
.font-normal { font-weight: 400; }
.lh-tight { line-height: var(--lh-tight); }
.lh-relaxed { line-height: var(--lh-relaxed); }

/* Layout utilities. */
.w-full { width: 100%; }
.row-baseline { align-items: baseline; }
.row-center { align-items: center; }
.row-stretch { align-items: stretch; }
.row-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.shrink-0 { flex-shrink: 0; }
.inline-block { display: inline-block; }
.vmid { vertical-align: middle; }
.cursor-pointer { cursor: pointer; }
.opacity-55 { opacity: 0.55; }

/* Sizing utilities for narrow inputs / specific fields. */
.input-narrow { max-width: 360px; }
.input-emoji { width: 56px; }
.input-num-sm { width: 64px; }
.input-name-min { min-width: 140px; }
.input-desc-min { min-width: 200px; }
.input-time-min { min-width: 220px; }
.input-file-inline { display: inline-block; width: auto; padding: 3px; }

/* Coloured text helpers. */
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-link-dim { color: var(--text-dim); }
.text-link-dim:hover { color: var(--text); }

/* Sources table column widths. */
.th-toggle { width: 56px; }

/* Calendar legend list styling. */
.legend-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12.5px;
  line-height: 1.6;
}

/* Draft detail: reorder status line. */
.reorder-status-line {
  height: 1rem;
  font-size: 12.5px;
}

/* Schedule-for-specific-time card on the draft detail page.
   Replaces the old inline-form layout with a clearly framed box so the time
   picker doesn't visually collide with the Approve/Publish actions above. */
.schedule-box {
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.schedule-box.is-scheduled {
  background: var(--accent-dim);
  border-color: var(--accent-border);
}
.schedule-box-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.schedule-box-icon {
  flex-shrink: 0;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  margin-top: 1px;
}
.schedule-box.is-scheduled .schedule-box-icon { color: var(--accent-hover); }
.schedule-box-titles { flex: 1; min-width: 0; }
.schedule-box-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.schedule-box-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.45;
}
.schedule-box-form {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}
.schedule-box-input {
  flex: 1;
  min-width: 220px;
  max-width: 280px;
  /* Override the global input rule so it matches the button height precisely. */
  height: 34px;
}

/* Build status: error helpers. */
.build-error-text {
  font-size: 13px;
  margin-top: 4px;
}
.build-error-actions {
  margin-top: 8px;
}

/* Live preview frame warnings (Telegram length limits). */
.preview-warn { box-shadow: 0 0 0 1px var(--warning); }
.preview-over { box-shadow: 0 0 0 2px var(--danger); }

/* Dashboard / queue card details + tables. */
.upcoming-details {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.upcoming-details > summary { cursor: pointer; }
.upcoming-table {
  margin-top: 8px;
  width: 100%;
}

/* publication queue card */
.queue-card { border-left: 3px solid var(--text-faint); }
.queue-card.queue-ready { border-left-color: var(--success); }
.queue-card.queue-pending_only { border-left-color: var(--warning); }
.queue-card.queue-no_draft { border-left-color: var(--danger); }
.queue-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 16px;
}
.queue-head h2 { display: flex; align-items: center; gap: 8px; }
.queue-head .subtitle { font-size: 13px; }
.queue-grid {
  display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 20px 32px;
}
@media (max-width: 720px) { .queue-grid { grid-template-columns: 1fr; } }
.queue-label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); margin-bottom: 6px;
}
.queue-value { font-size: 14px; }
.queue-note {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: 12.5px; margin-top: 6px; color: var(--text-dim);
}
.queue-note.ok { color: var(--success); }
.queue-note.warn { color: var(--warning); }
.queue-note a { color: inherit; text-decoration: underline; }

.row-queued { background: rgba(70, 192, 138, 0.06); }
.row-queued td:first-child { box-shadow: inset 3px 0 0 0 var(--success); }
.badge-queued {
  background: var(--success-dim); color: var(--success);
  border: 1px solid var(--success-border); font-size: 11px;
  padding: 1px 6px; margin-left: 4px;
}
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

/* =================== Modal (custom confirm dialog) =================== */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  opacity: 0;
  transition: opacity 0.14s ease;
  padding: 16px;
}
.modal-backdrop.is-open {
  opacity: 1;
}
.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 14px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255,255,255,0.04) inset;
  max-width: 440px;
  width: 100%;
  padding: 24px;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.14s ease;
}
.modal-backdrop.is-open .modal-dialog { transform: translateY(0) scale(1); }
.modal-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.modal-icon.warn   { color: var(--warning); background: var(--warning-dim); }
.modal-icon.danger { color: var(--danger);  background: var(--danger-dim); }
.modal-icon.info   { color: var(--accent);  background: var(--accent-dim); }
.modal-title {
  font-size: 16px; font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.005em;
}
.modal-message {
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 18px;
}
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
}
.modal-actions .btn { min-width: 88px; justify-content: center; }
.modal-actions .btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.modal-require-text {
  display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px;
  font-size: 12.5px; color: var(--text-dim);
}
.modal-require-text code {
  background: var(--bg-card-hover); padding: 1px 6px; border-radius: 4px;
  font-size: 12px; color: var(--text);
}
.modal-require-text input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-input, var(--bg-card)); color: var(--text);
  font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.modal-require-text input:focus { outline: none; border-color: var(--accent); }

/* hover tooltip — wraps a help icon */
.help-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  border-radius: 50%;
  color: var(--text-faint);
  cursor: help;
  vertical-align: middle;
  transition: color 0.12s, background 0.12s;
}
.help-tip:hover,
.help-tip:focus-visible {
  color: var(--accent);
  background: var(--accent-dim);
  outline: none;
}
.help-tip[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: max-content;
  max-width: 320px;
  padding: 10px 12px;
  /* Hard-coded near-black / near-white per theme so the popup pops off the page
     regardless of which surface it's sitting over (card, elevated, input). */
  background: #1a1a1f;
  color: #ededed;
  border: 1px solid #3a3a44;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  text-align: left;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  z-index: 1000;
}
/* Speech-bubble arrow connecting tooltip to the trigger icon. */
.help-tip[data-tip]::before {
  content: '';
  position: absolute;
  top: calc(100% + 4px);
  right: 6px;
  width: 10px;
  height: 10px;
  background: #1a1a1f;
  border-left: 1px solid #3a3a44;
  border-top: 1px solid #3a3a44;
  transform: rotate(45deg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
  z-index: 1001;
}
.help-tip[data-tip]:hover::after,
.help-tip[data-tip]:focus::after,
.help-tip[data-tip]:focus-visible::after,
.help-tip[data-tip]:hover::before,
.help-tip[data-tip]:focus::before,
.help-tip[data-tip]:focus-visible::before {
  opacity: 1;
  transform: translateY(0) rotate(0);
}
.help-tip[data-tip]:hover::before,
.help-tip[data-tip]:focus::before,
.help-tip[data-tip]:focus-visible::before {
  transform: rotate(45deg);
}

/* In light mode flip the popup colours so dark text on light background.
   Hard-coded too — readable on any theme regardless of where it lands. */
:root[data-theme="light"] .help-tip[data-tip]::after {
  background: #1f1f24;
  color: #f5f5f7;
  border-color: #2f2f37;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25), 0 2px 6px rgba(0,0,0,0.15);
}
:root[data-theme="light"] .help-tip[data-tip]::before {
  background: #1f1f24;
  border-color: #2f2f37;
}

/* Inside the sidebar the default top-anchored tooltip gets clipped by the
   screen edge. Flip it to extend right into the main content area instead. */
.sidebar .help-tip[data-tip]::after {
  top: 50%;
  right: auto;
  left: calc(100% + 12px);
  transform: translateY(-50%) translateX(-4px);
}
.sidebar .help-tip[data-tip]::before {
  top: 50%;
  right: auto;
  left: calc(100% + 6px);
  transform: translateY(-50%) rotate(-45deg);
}
.sidebar .help-tip[data-tip]:hover::after,
.sidebar .help-tip[data-tip]:focus::after,
.sidebar .help-tip[data-tip]:focus-visible::after {
  transform: translateY(-50%) translateX(0);
}
.sidebar .help-tip[data-tip]:hover::before,
.sidebar .help-tip[data-tip]:focus::before,
.sidebar .help-tip[data-tip]:focus-visible::before {
  transform: translateY(-50%) rotate(-45deg);
}

/* When a help-tip sits at the LEFT edge of a row (e.g. first column), flipping
   the tooltip to extend left would clip it. Use `.help-tip-left` modifier on
   the trigger to anchor the popup to its left edge instead. */
.help-tip.help-tip-left[data-tip]::after { right: auto; left: 0; }
.help-tip.help-tip-left[data-tip]::before { right: auto; left: 6px; }

/* Narrow screens: cap tooltip width so it doesn't run off the viewport. */
@media (max-width: 640px) {
  .help-tip[data-tip]::after {
    max-width: min(280px, calc(100vw - 32px));
    font-size: 12px;
  }
}

/* =================== Screen-reader only (a11y) =================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =================== Skip-to-content link (a11y) =================== */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 9999;
  background: var(--accent);
  color: white;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}
.skip-link:focus {
  left: 8px;
  color: white;
  outline: 2px solid white;
  outline-offset: 2px;
}

/* =================== Draft-detail: action zones =================== */

.actions-zones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "primary primary"
    "refine  discard";
  gap: 12px;
}
.actions-zone {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  min-width: 0;
}
.actions-zone-primary { grid-area: primary; border-color: var(--accent-border); background: var(--accent-dim); }
.actions-zones > .actions-zone:not(.actions-zone-primary):not(.actions-zone-danger) { grid-area: refine; }
.actions-zone-danger { grid-area: discard; border-color: var(--danger-border); background: var(--danger-dim); }
.actions-zone .zone-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 500;
}
.actions-zone .zone-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.action-hint {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}
@media (max-width: 720px) {
  .actions-zones {
    grid-template-columns: 1fr;
    grid-template-areas: "primary" "refine" "discard";
  }
}

/* =================== Character counter (textarea) =================== */

.char-counter {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: right;
  letter-spacing: 0.02em;
}
.char-counter.warn { color: var(--warning); }
.char-counter.over { color: var(--danger); font-weight: 500; }

/* =================== Dirty-form indicator =================== */

.dirty-dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px var(--warning-dim);
  margin-left: 6px;
  vertical-align: middle;
}
.dirty-dot.is-dirty { display: inline-block; }

/* =================== Password input wrapper with toggle =================== */

.input-with-toggle {
  position: relative;
  display: block;
}
.input-with-toggle > input { padding-right: 36px; }
.pwd-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.pwd-toggle:hover { color: var(--text); background: var(--bg-card-hover); }
.pwd-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* =================== Drafts list: status filter chips =================== */

.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-chip {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid;
  background: transparent;
  transition: filter 0.12s, box-shadow 0.12s, transform 0.12s;
}
.filter-chip:hover { filter: brightness(1.25); transform: translateY(-1px); }
.filter-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.filter-chip.is-active {
  box-shadow: 0 0 0 2px currentColor, 0 0 0 4px var(--accent-dim);
  filter: brightness(1.15);
}
.filter-chip-clear {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
}
.filter-chip-clear:hover { color: var(--text); }

/* =================== Mobile preview FAB =================== */

.mobile-preview-fab {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 500;
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
@media (max-width: 900px) {
  .mobile-preview-fab { display: inline-flex; }
}

/* =================== Floating toasts (used by JS showToast) =================== */

#toast-container .toast {
  border-width: 1px;
  border-style: solid;
}

/* =================== File-input small (replaces inline style) =================== */

input[type="file"].file-input-sm {
  display: inline-block;
  width: auto;
  padding: 4px 6px;
  font-size: 12px;
  border-style: solid;
}

/* =================== Settings: provider key card (AI keys grid) =================== */

/* Settings → API keys: visual separation of the two key sections.
   Coloured top edge = quick anchor: blue-ish accent for Text AI,
   green for Image generation. */
#text-ai  { border-top: 3px solid var(--accent); }
#image-gen { border-top: 3px solid var(--success); }

/* "How to get the key" collapsibles inside provider cards — collapsed by
   default so the cards read as: name → one line → input → actions. */
.key-steps summary { font-size: 12px; color: var(--text-dim); }
.key-steps summary:hover { color: var(--text); }
.key-steps ol { margin: 6px 0 0; padding-left: 20px; }
.key-steps li { margin-bottom: 2px; }

/* Default-engine picker gets its own boxed sub-block so it doesn't blend
   into the engine key cards below. */
.image-default-picker {
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 12px 14px;
}
.image-default-picker > .muted { letter-spacing: 0.04em; }

.provider-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.12s;
}
.provider-card:focus-within { border-color: var(--border-hover); }
.provider-card .provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.provider-card .provider-head strong { font-size: 13.5px; font-weight: 600; }
.provider-card .provider-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.provider-card .provider-foot a { color: var(--text-dim); }
.provider-card .provider-foot a:hover { color: var(--accent-hover); }
/* Disconnected providers get a subtler look so the connected ones stand out. */
.provider-card:not(:has(.badge-connected)) .provider-head strong { color: var(--text-dim); }

/* =================== Settings: engine status header =================== */

.engine-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.engine-status .badge { font-size: 12px; padding: 3px 10px; }

/* =================== Settings: card-header for h3 + badge inline =================== */

.card > h3 + .help-text { margin-top: -2px; margin-bottom: 12px; }
.card-h3-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-h3-row h3 { margin: 0; }

/* =================== Settings: action-row (save + secondary side by side) =================== */

.settings-action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.settings-action-row .muted { font-size: 12px; }

/* =================== Source health dots =================== */
.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.health-green { background: var(--success); box-shadow: 0 0 0 3px var(--success-dim); }
.health-amber { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-dim); }
.health-red   { background: var(--danger);  box-shadow: 0 0 0 3px var(--danger-dim); }
.health-gray  { background: var(--text-faint); }

/* Engagement metrics (history page) */
.engagement-cell { font-variant-numeric: tabular-nums; }
.engagement-cell .total { font-weight: 600; }
.engagement-cell .breakdown {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* =================== Calendar =================== */
.calendar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0 14px;
  gap: 16px;
  flex-wrap: wrap;
}
.month-name { margin: 0; font-size: 18px; font-weight: 600; }
.calendar-legend { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.cal-legend-item { font-size: 12px; color: var(--text-dim); }

.calendar-card { padding: 0; overflow: hidden; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.cal-weekhead {
  padding: 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cal-day {
  min-height: 110px;
  padding: 6px 7px 8px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
}
.cal-out { background: var(--bg-elevated); opacity: 0.55; }
.cal-today { background: rgba(99, 132, 255, 0.06); }
.cal-today .cal-daynum { color: var(--accent); font-weight: 700; }
.cal-daynum {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cal-today-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--accent);
  color: #fff;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 700;
}
/* Calendar events — thumbnail card per scheduled/posted draft */
.cal-event {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left-width: 3px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.cal-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  border-color: var(--border-hover);
}
.cal-event-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1;
  background: var(--bg);
  display: block;
}
.cal-event-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cal-event-thumb-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
}
.cal-event-badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.35);
}
.cal-event-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding: 3px 6px;
  font-size: 10.5px;
  line-height: 1.3;
  background: linear-gradient(to bottom, rgba(0,0,0,0.15), transparent);
}
.cal-event-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.cal-event-id { color: var(--text-dim); font-size: 10px; }

/* Status accents — left border + badge color */
.kind-posted    { border-left-color: var(--success); }
.kind-posted    .cal-event-badge { background: var(--success); }
.kind-scheduled { border-left-color: var(--warning); }
.kind-scheduled .cal-event-badge { background: var(--warning); }
.kind-weekly    { border-left-color: var(--accent); }
.kind-weekly    .cal-event-badge { background: var(--accent); }

/* Legend dots */
.cal-dot {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 50%; vertical-align: middle; margin-right: 4px;
}
.dot-posted    { background: var(--success); }
.dot-scheduled { background: var(--warning); }
.dot-weekly    { background: var(--accent); }

.pending-list { list-style: none; padding: 0; margin: 0; }
.pending-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.pending-list li:last-child { border-bottom: 0; }
.pending-list a { color: var(--text); text-decoration: none; }
.pending-list a:hover { color: var(--accent); }

/* Calendar layout: main grid + 280px sidebar (Needs review / legend) */
.layout-calendar {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

@media (max-width: 900px) {
  .layout-calendar { grid-template-columns: 1fr; }
  .cal-day { min-height: 90px; }
  .cal-event-meta { font-size: 10px; }
}

/* =================== Sidebar group labels =================== */
.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  font-weight: 600;
  padding: 12px 14px 4px;
  margin-top: 4px;
}
.nav-group-label:first-child { margin-top: 0; padding-top: 4px; }

/* =================== Dashboard: This week / Health rows =================== */
.this-week-row {
  padding: 10px 0;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
  align-items: start;
  border-bottom: 1px solid var(--border);
}
.this-week-row:last-child { border-bottom: 0; }
.this-week-row[open] { display: block; }
.this-week-row[open] summary { padding: 0; }
.this-week-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  font-weight: 600;
  padding-top: 4px;
}
.this-week-value { font-size: 14px; line-height: 1.5; }
.this-week-detail { margin-top: 4px; font-size: 13px; }

.pending-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.pending-row a:first-child {
  flex: 1;
  min-width: 200px;
  color: var(--text);
  text-decoration: none;
}
.pending-row a:first-child:hover { color: var(--accent); }

.health-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.health-row:last-child { border-bottom: 0; }
.health-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.health-value { font-size: 13.5px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.health-value .health-dot { margin: 0 2px 0 4px; }

/* =================== Quick-schedule popover on /drafts/ =================== */
.quick-actions {
  white-space: nowrap;
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  align-items: center;
}
.quick-actions form.inline { display: inline; }

.quick-schedule-popover {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.4);
  z-index: 100;
  min-width: 270px;
}
.qs-form { display: flex; flex-direction: column; gap: 10px; }
.qs-label { font-size: 12px; color: var(--text-dim); }
.qs-form input[type="datetime-local"] {
  /* Compact override for the inline quick-schedule popover. Background/colour
     come from the global input rule so dark theme stays consistent. */
  padding: 6px 8px;
}
.qs-actions { display: flex; gap: 6px; }

/* =================== Build-status page =================== */
.build-card { padding: 20px 22px; }

.build-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.build-stage-label { font-size: 16px; font-weight: 600; }
.build-detail { font-size: 13px; margin-top: 2px; }
.build-elapsed {
  margin-left: auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.build-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: build-spin 0.9s linear infinite;
  flex-shrink: 0;
}
.build-spinner.spinner-ok {
  border-color: var(--success);
  border-top-color: var(--success);
  animation: none;
}
.build-spinner.spinner-fail {
  border-color: var(--danger);
  border-top-color: var(--danger);
  animation: none;
}
@keyframes build-spin { to { transform: rotate(360deg); } }

.build-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 20px;
}
.build-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #8b9bff);
  transition: width 0.4s ease-out;
}

.build-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.build-steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-dim);
  padding: 6px 0;
}
.build-step-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.build-step-meta { margin-left: auto; font-size: 12px; }

.build-steps li.step-done { color: var(--success); }
.build-steps li.step-done .build-step-dot {
  background: var(--success);
  border-color: var(--success);
}
.build-steps li.step-active { color: var(--text); font-weight: 500; }
.build-steps li.step-active .build-step-dot {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18);
  animation: build-pulse 1.4s ease-in-out infinite;
}
.build-steps li.step-failed { color: var(--danger); }
.build-steps li.step-failed .build-step-dot {
  border-color: var(--danger);
  background: var(--danger);
}
@keyframes build-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.18); }
  50%      { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0.05); }
}

.build-result { margin-top: 20px; }

.figma-coverage { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* =================== Photos page: branded covers by article count =================== */
.covers-group { margin-top: 18px; }
.covers-group:first-of-type { margin-top: 6px; }
.covers-group-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: 6px; margin-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.covers-group-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.covers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 6px;
}
.brand-cover {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg-elevated);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.brand-cover:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.brand-cover img { display: block; width: 100%; aspect-ratio: 2 / 1; object-fit: cover; }
.brand-cover-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 3px 4px 3px 6px; border-top: 1px solid var(--border);
}
.brand-cover-name {
  font-size: 10px; color: var(--text-dim); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cover-upload { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.cover-upload .field { margin: 0; flex: 1 1 260px; }
.cover-upload .cover-upload-n { flex: 0 0 120px; align-self: flex-start; }
.upload-form { margin: 10px 0 14px; }

/* =================== Published (history) cards =================== */
.published-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.pub-card {
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.pub-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  border-color: var(--border-hover);
}
.pub-card-cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 1;
  background: var(--bg);
  text-decoration: none;
}
.pub-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pub-card-cover-empty {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint);
}
.pub-card-reactions {
  position: absolute;
  top: 8px; right: 8px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  font-size: 11.5px; font-weight: 600;
  color: white;
  background: rgba(0,0,0,0.55);
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.pub-card-body {
  padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.pub-card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; font-size: 13px;
}
.pub-card-head .muted { font-size: 11.5px; }
.pub-card-emoji-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
.pub-card-links {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}
.pub-link {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  font-size: 11.5px;
  color: var(--text-dim);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}
.pub-link:hover { color: var(--text); border-color: var(--border-hover); }
.pub-card-crossposts { display: flex; flex-wrap: wrap; gap: 6px; }
.pub-card-crossposts .badge { font-size: 10.5px; text-decoration: none; }

/* =================== Calendar event hover popover =================== */
.cal-event { position: relative; }
.cal-event-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 280px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease-out, transform 0.14s ease-out;
  z-index: 30;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  text-align: left;
  white-space: normal;
}
.cal-event:hover .cal-event-tip,
.cal-event:focus-visible .cal-event-tip,
.cal-event.cal-event-show-tip .cal-event-tip {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(-2px);
}
.cal-tip-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
}
.cal-tip-head .badge { font-size: 10px; padding: 2px 6px; }
.cal-tip-title { font-weight: 600; margin-bottom: 4px; word-break: break-word; }
.cal-tip-meta { color: var(--text-dim); font-size: 11.5px; margin-bottom: 6px; }
.cal-tip-meta strong { color: var(--text); }
.cal-tip-meta svg { vertical-align: middle; }
.cal-tip-body {
  color: var(--text-dim);
  font-size: 11.5px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Reaction chips on Published cards (overrides intentionally — these win the cascade) */
.pub-react-top { font-size: 14px; line-height: 1; }
.pub-react-total { font-variant-numeric: tabular-nums; }

.react-chip {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.react-chip-emoji { font-size: 13px; line-height: 1; }
.react-chip-count { color: var(--text-dim); font-size: 11px; }

/* Reactions inside the calendar tooltip */
.cal-tip-reactions {
  display: flex; flex-wrap: wrap; gap: 5px;
  align-items: baseline;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.cal-tip-reactions span {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}

.cal-tip-reactions-hint {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--success);
  font-weight: 600;
  margin-left: 2px;
}

/* =================== Source auto-detector =================== */
.auto-detect { margin-bottom: 4px; }
#detect-result {
  margin-top: 14px;
}
.detect-loading {
  padding: 14px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
}
.detect-fail {
  padding: 14px;
  background: var(--danger-dim);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}
.detect-ok {
  padding: 14px;
  background: var(--success-dim);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-sm);
}
.detect-ok-head { font-size: 14px; margin-bottom: 8px; }
.detect-sample-label { font-size: 12px; margin-top: 8px; }
.detect-sample {
  margin: 4px 0 8px 18px;
  padding: 0;
  font-size: 12.5px;
  color: var(--text-dim);
}
.detect-add-form {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.detect-add-form .field { margin: 8px 0 0; }
.detect-add-form .field-label-sm { font-size: 12px; }
.detect-add-form .field-grow { flex: 1; }
.detect-add-form .field-w-130 { width: 130px; }
.detect-add-form .btn-self-end { align-self: flex-end; }

/* =================== Accessibility / responsive niceties =================== */

/* Honour reduced-motion preference: cancel animations and shorten transitions.
   Keeps essential visibility transitions (modal/popover open) but no spinning. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Settings: force single column on tablets and below — the 2-column API key
   grid is too cramped at narrow widths. */
@media (max-width: 768px) {
  .provider-grid,
  .tab-panel .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Sources table: scroll horizontally on small screens rather than crushing
   every column. The table-wrapping `.card` already has its own padding. */
@media (max-width: 640px) {
  #sources-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  .layout-calendar { grid-template-columns: 1fr; }
}

/* Reactions inline next to a post count (e.g. Recent posts table on Dashboard).
   Renders the top-popular emoji + total as a compact unit so the table stays
   one-line per row. */
.reaction-cell {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}
.reaction-emoji {
  font-size: 14px;
  line-height: 1;
}

/* Channel-reactions panel on the draft detail page (posted draft only). */
.posted-reactions {
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.posted-reactions-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.posted-reactions-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.posted-reactions-total {
  font-size: 13px;
  color: var(--text-dim);
}
.posted-reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* =================== Analytics page =================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.stat-tile-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 500;
}
.stat-tile-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-tile-sub {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-dim);
}

.best-post-card { margin-bottom: 18px; }
.best-post-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}
.best-post-meta { flex: 1; min-width: 0; }
.best-post-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.best-post-title:hover { color: var(--accent-hover); }
.best-post-count {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.best-post-num {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.best-post-suffix {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 320px;
  margin-top: 4px;
}
.chart-wrap-square { height: 280px; }

.analytics-table th { font-size: 12px; }
.analytics-table td { vertical-align: middle; }

.analytics-caveats { margin-top: 8px; }
.analytics-caveats ul { padding-left: 18px; line-height: 1.7; }
.analytics-caveats li { margin-bottom: 4px; }

/* =================== Long-action overlay (regenerate, etc.) =================== */
.long-action-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: long-action-fade-in 0.18s ease-out;
}
@keyframes long-action-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.long-action-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  min-width: 320px;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.long-action-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: long-action-spin 0.9s linear infinite;
}
@keyframes long-action-spin {
  to { transform: rotate(360deg); }
}
.long-action-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.long-action-detail {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.45;
}
.long-action-elapsed {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.long-action-elapsed [data-elapsed] {
  color: var(--text-dim);
  font-weight: 500;
}

/* =================== Custom posts (tea_fact) =================== */

/* Pipeline Kind column badge. Digest gets the neutral chip, tea uses success-tinted. */
.badge-kind-digest {
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-color: var(--border);
}
.badge-kind-tea {
  color: var(--success);
  background: var(--success-dim);
  border-color: var(--success-border);
}
.badge-kind-tea::before, .badge-kind-digest::before { display: none; }

/* Calendar event tints — green left border + slight tinted bg for tea_fact. */
.cal-event.content-kind-tea_fact {
  border-left: 3px solid var(--success);
  background: linear-gradient(90deg, var(--success-dim), transparent 45%);
}

/* Compose page cover preview.
   3:2 matches the 1216x832 Pollinations output (Flux-friendly aspect). Uses
   object-fit: contain so user uploads of any aspect ratio (4:3 phone snaps,
   square shots, 16:9 stills) display in full with letterbox bars — matches
   what Telegram actually delivers to the channel (it preserves the photo's
   real aspect, never crops). */
.cover-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
  user-select: none;
}
.cover-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* Author CSS otherwise beats the UA `[hidden]{display:none}` rule (same
   specificity, author wins) — without this the empty <img> renders and the
   browser shows a broken-image icon over the empty-state placeholder.
   `.logo-controls[hidden]` is in the same boat: its `display: flex` rule (set
   below) overrides the UA `display: none`, leaving the file picker / size
   slider / preset arrows visible even when the checkbox is unchecked. */
.cover-bg[hidden],
.logo-overlay[hidden],
.logo-controls[hidden],
.text-controls[hidden],
.text-overlay[hidden] { display: none !important; }

/* DrukWideBold — used by the title-overlay live preview. Backend rendering
   reads the same file from data/DrukWideBold.ttf; we keep a copy under
   /static/fonts/ so the browser can preview the exact glyphs the bake will
   produce. font-display:block avoids a flash of fallback font that would
   miscalculate sizes. */
@font-face {
  font-family: "DrukWideBold";
  src: url("/static/fonts/DrukWideBold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

/* Draggable title-overlay shown on top of the cover canvas during compose.
   Inline styles set left/top (% of canvas) and font-size (vw-relative).
   The drop-shadow mirrors the bake step so what you drag is what you ship. */
.text-overlay {
  position: absolute;
  left: 5%;
  top: 80%;
  /* font-size is set inline by JS as N% of the canvas height. */
  font-family: "DrukWideBold", "Inter", -apple-system, sans-serif;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  line-height: 1.05;
  letter-spacing: 0.5px;
  white-space: pre-line;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  pointer-events: auto;
  text-shadow:
    2px 2px 6px rgba(0, 0, 0, 0.7),
    0 0 1px rgba(0, 0, 0, 0.4);
  max-width: 92%;
  /* Wrap long text the same way the backend does — fits inside the canvas. */
  overflow-wrap: break-word;
}
.text-overlay:active { cursor: grabbing; }
.cover-canvas.dragging-text .text-overlay { cursor: grabbing; }
.text-overlay[data-empty="1"] {
  opacity: 0.35;
  font-style: italic;
}
.cover-preview-empty {
  position: absolute;
  inset: 0;
  text-align: center;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.cover-preview-empty p { margin: 0; font-size: 12.5px; }

/* Logo overlay — draggable stamp positioned over the cover. */
.logo-overlay {
  position: absolute;
  left: 5%;
  top: 5%;
  width: 22%;
  height: auto;
  cursor: grab;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
  touch-action: none;
  -webkit-user-drag: none;
}
.logo-overlay:active { cursor: grabbing; }
.cover-canvas.dragging .logo-overlay { cursor: grabbing; }

/* Logo controls (size slider + position presets). */
.logo-overlay-section { padding-top: 12px; }
.logo-controls {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.logo-size-label {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-size-label input[type=range] {
  flex: 1;
  min-width: 100px;
}
.logo-size-label #logo-size-val {
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.logo-position-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  max-width: 140px;
}
.logo-position-presets button {
  padding: 6px 0;
  font-size: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.logo-position-presets button:hover {
  background: var(--bg-hover, var(--bg-elevated));
  border-color: var(--accent);
}
.logo-position-presets button.active {
  background: var(--accent-dim, var(--bg-elevated));
  border-color: var(--accent);
  color: var(--accent);
}
