/* TBT Admin — minimal dashboard UI */
:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171a22;
  --surface-2: #1e222d;
  --border: #2a3040;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #4f8cff;
  --accent-hover: #3a7af0;
  --ok: #34c759;
  --warn: #ffb020;
  --bad: #ff5a5f;
  --radius: 10px;
  --sidebar: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

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

.skip-link {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 1000;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

@font-face {
  font-family: Vazirmatn;
  src: url('/admin/assets/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url('/admin/assets/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

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

.sidebar {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
  padding: 0 8px;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  margin-top: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  transition: .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--surface-2);
  color: var(--text);
}
.nav-link.active { border: 1px solid var(--border); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.main {
  padding: 28px 32px;
  max-width: 1600px;
  display: flex;
  flex-direction: column;
  /* grid item: allow shrinking below content min-width so wide children
     (scrollable tabs/tables) scroll internally instead of stretching the page */
  min-width: 0;
}

/* The admin's primary task is reading and deciding. Keep the inbox above
   crawler diagnostics and configuration regardless of template source order. */
#dashboard-stats { order: 1; }
#crawl-history-card { order: 2; }
#dashboard-tabs { order: 3; }
#tweets-card { order: 4; }
#crawl-log-card { order: 5; }
#settings-card { order: 6; }
#manual-add-card { order: 7; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.page-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: rgba(52,199,89,.15); border-color: var(--ok); color: var(--ok); }
.btn-danger { background: rgba(255,90,95,.12); border-color: var(--bad); color: var(--bad); }
.btn-warning { background: rgba(255,176,32,.12); border-color: var(--warn); color: var(--warn); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 36px; min-height: 36px; justify-content: center; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { margin: 0; font-size: 15px; font-weight: 700; }
.card-subtitle { color: var(--muted); font-size: 11px; margin-top: 3px; }
.card-body { padding: 18px; }

.crawl-last-run {
  color: var(--muted);
  font-size: 12px;
}
.crawl-summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(100px, 1fr));
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}
.crawl-success-meta {
  padding: 9px 14px;
  color: var(--muted);
  font-size: 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.crawl-summary-item {
  padding: 12px 14px;
  background: var(--surface-2);
}
.crawl-summary-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}
.crawl-summary-item strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
}
.crawl-run-notice {
  padding: 12px 18px;
  color: var(--warn);
  background: rgba(255,176,32,.08);
  border-bottom: 1px solid var(--border);
}
.crawl-run-failed {
  color: var(--bad);
  background: rgba(255,90,95,.08);
}
.crawl-history-empty { padding: 22px 18px; }
.table-wrap.crawl-history-wrap { overflow-x: auto; }
.crawl-history-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 12px;
}
.crawl-history-table th,
.crawl-history-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.crawl-history-table th {
  color: var(--muted);
  font-weight: 500;
  background: var(--surface-2);
}
.crawl-history-table tbody tr:last-child td { border-bottom: 0; }
.crawl-history-table td:last-child {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.crawl-status {
  display: inline-block;
  margin-inline-start: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 10px;
}
.crawl-status-completed { color: var(--ok); }
.crawl-status-failed { color: var(--bad); }
.crawl-status-skipped { color: var(--warn); }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.flash-success { border-color: rgba(52,199,89,.4); color: var(--ok); }
.flash-error { border-color: rgba(255,90,95,.4); color: var(--bad); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.col-12 { grid-column: span 12; }
.col-9 { grid-column: span 9; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
.col-2 { grid-column: span 2; }
.col-1 { grid-column: span 1; }

label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid transparent;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.25);
}
textarea { resize: vertical; min-height: 100px; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 13px;
}
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
tr:hover td { background: rgba(255,255,255,.02); }
tr.row-deleted td { opacity: .65; }
.tweet-table tbody tr {
  content-visibility: auto;
  contain-intrinsic-size: auto 180px;
}

:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
}
.badge-pending { background: rgba(255,176,32,.12); color: var(--warn); border-color: rgba(255,176,32,.3); }
.badge-published { background: rgba(52,199,89,.12); color: var(--ok); border-color: rgba(52,199,89,.3); }
.badge-expired { background: rgba(139,149,168,.12); color: var(--muted); }
.badge-deleted { background: rgba(255,90,95,.12); color: var(--bad); border-color: rgba(255,90,95,.3); }
.badge-active { background: rgba(79,140,255,.15); color: var(--accent); border-color: rgba(79,140,255,.35); }
.badge-rejected { background: rgba(255,90,95,.10); color: var(--bad); border-color: rgba(255,90,95,.25); }
/* Tag next to a rejection badge: is this rejection permanent (admin/trash) or
   re-checked on later crawls (pre-filter/AI)? */
.reject-tag { display: inline-block; margin-inline-start: 6px; padding: 1px 7px; border-radius: 999px; font-size: 10px; line-height: 1.6; border: 1px solid transparent; white-space: nowrap; }
.reject-permanent { background: rgba(255,90,95,.14); color: var(--bad); border-color: rgba(255,90,95,.3); }
.reject-transient { background: rgba(255,176,32,.12); color: var(--warn); border-color: rgba(255,176,32,.3); }
.status-note { margin-top: 6px; color: var(--muted); font-size: 11px; }
.status-note.publish-error { color: var(--bad); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.drag-handle { display: inline-flex; cursor: grab; color: var(--muted); margin-inline-end: 4px; vertical-align: middle; }
.drag-handle:active { cursor: grabbing; }
tr[draggable="true"] { cursor: grab; }
tr.dragging { opacity: .4; }
tr.drag-over { box-shadow: inset 0 2px 0 var(--accent); }
.queue-move-actions { display: flex; gap: 4px; margin-top: 8px; }
.queue-move-actions form { margin: 0; }
.queue-move-actions .btn-icon { width: 36px; height: 36px; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.setting {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.setting span { color: var(--muted); font-size: 12px; }
/* Full-width row for long values like the search query. */
.setting-wide { grid-column: 1 / -1; }
.setting-wide strong { word-break: break-all; text-align: left; }
.settings-note { margin-top: 12px; color: var(--muted); font-size: 12px; }

/* AI review on/off switch (dashboard settings card) */
.ai-toggle-form { display: inline-flex; }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: .15s;
}
.toggle:hover { border-color: var(--muted); }
.toggle-label { font-weight: 700; }
.toggle-track {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--border);
  transition: .15s;
  flex-shrink: 0;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--muted);
  transition: .15s;
}
.toggle-state { color: var(--bad); font-weight: 700; }
.toggle-on .toggle-track { background: rgba(52,199,89,.35); }
.toggle-on .toggle-thumb { right: 18px; background: var(--ok); }
.toggle-on .toggle-state { color: var(--ok); }

.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  margin-right: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
.tab.active .tab-count { background: var(--accent); border-color: var(--accent); color: #fff; }

.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 0;
  flex-wrap: wrap;
}
.sort-label { color: var(--muted); font-size: 12px; }
.sort-link {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.sort-link:hover { border-color: var(--muted); color: var(--text); }
.sort-link.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.bulk-actions {
  align-items: center;
}
.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.select-all-label input,
.select-all {
  width: auto;
}
.selected-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.table-footer-controls {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.table-footer-controls > .bulk-actions {
  padding: 0 18px 4px;
}
.table-bottom-sort {
  padding-bottom: 12px;
}
.table-bottom-tabs {
  padding: 0 18px 14px;
  margin: 0;
  flex-wrap: wrap;
}

/* NOTE: pre-wrap must stay scoped to .tweet-body (the tweet's own text).
   Putting it on the whole cell makes every EJS template newline render as a
   blank line, blowing the layout apart with huge vertical gaps. */
.tweet-text {
  max-width: 360px;
  line-height: 1.7;
}
.tweet-body { white-space: pre-wrap; }
/* Repost ("X بازنشر کرد") context line — mirrors Twitter's socialContext row. */
.repost-line {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

/* Quoted tweet — styled like Twitter's embedded quote card:
   rounded 16px border, inline [avatar name @handle] header, text,
   then edge-to-edge media clipped by the card radius. */
.quote-card {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: transparent;
}
.quote-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 0;
  min-width: 0;
}
.quote-avatar {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  object-fit: cover;
  flex-shrink: 0;
}
.quote-avatar-empty {
  display: inline-grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
}
.quote-name {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quote-handle {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.quote-text {
  padding: 4px 12px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-size: 13px;
}
.quote-head:last-child { padding-bottom: 12px; }
.quote-media-wrap { position: relative; }
.quote-head + .quote-media-wrap { margin-top: 8px; }
.quote-media {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
}
.thread-preview {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  display: grid;
  gap: 8px;
  color: var(--muted);
}
.thread-preview > div,
.collapsible-body > div { white-space: pre-wrap; }
.replies-preview { border-style: dashed; }
.replies-preview.replies-off { opacity: .6; }
.replies-preview.replies-on { border-color: var(--accent); }
.replies-head { color: var(--muted); font-size: 11px; }

/* Collapsible long previews (threads / replies): clip to a small height and
   reveal the rest with a "بیشتر" toggle so a long row doesn't dominate the page. */
.collapsible-body {
  display: grid;
  gap: 8px;
  max-height: 120px;
  overflow: hidden;
  position: relative;
}
.collapsible.expanded .collapsible-body { max-height: none; }
/* Fade the clipped edge while collapsed, but only when there's actually more. */
.collapsible:not(.expanded) .collapsible-body.has-more::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--surface-2));
  pointer-events: none;
}
.collapsible-toggle {
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.collapsible-toggle:hover { text-decoration: underline; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.checkbox-row input { width: auto; }
.mono {
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}
.tab.active, .tab:hover {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(79,140,255,.1);
}

.row-actions { display: flex; flex-wrap: wrap; gap: 4px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 400px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}
.login-card p {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 13px;
}

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

.toast-root {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 1000;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 48px));
}

.toast {
  transform: translateY(10px);
  opacity: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .28);
  transition: .2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success { border-color: rgba(52,199,89,.45); }
.toast-error { border-color: rgba(255,90,95,.55); color: #ffd7d9; }

[data-lightbox] { cursor: zoom-in; }

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  padding: 32px;
  background: rgba(6, 8, 14, .92);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox-overlay.show { display: flex; }
.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
}
.lightbox-close:hover { border-color: var(--muted); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(6, 8, 14, .75);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-card {
  width: min(880px, 100%);
  height: min(900px, calc(100vh - 40px));
  height: min(900px, calc(100dvh - 40px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.modal-card > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body {
  flex: 1 1 0;
  padding: 18px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) var(--surface-2);
}
.modal-body::-webkit-scrollbar { width: 10px; }
.modal-body::-webkit-scrollbar-track { background: var(--surface-2); }
.modal-body::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 999px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
body.modal-open { overflow: hidden; }
.form-section-title {
  color: var(--accent);
  font-weight: 700;
  padding-top: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.edit-checks { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.edit-checks .checkbox-row { margin: 0; }

.tweet-table { min-width: 1100px; }

.author-cell { min-width: 180px; }
.author-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.author-handle { color: var(--muted); font-size: 12px; }
.tweet-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.tweet-avatar-empty {
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
}
.tweet-media {
  width: 100%;
  max-width: 120px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.tweet-media-video {
  display: block;
  height: auto;
  object-fit: contain;
  background: var(--surface-2);
}
.media-thumb-wrap { display: block; margin-top: 4px; position: relative; }
.telegram-media-grid {
  display: grid;
  grid-template-columns: repeat(2, 56px);
  gap: 5px;
  margin-top: 6px;
}
.telegram-media-grid .media-thumb-wrap { margin: 0; }
.telegram-media-grid .tweet-media { width: 56px; height: 56px; }
.video-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.video-badge-standalone {
  position: static;
  margin-top: 6px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
}

.metric-list { display: grid; gap: 4px; min-width: 90px; }
.metric { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.metric span { color: var(--muted); }
.metric strong { font-family: ui-monospace, monospace; }
.reaction-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; max-width: 180px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 11px; }
.reaction-chip b { font-family: ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.metric-date { display: grid; gap: 2px; margin-top: 4px; }
.metric-date strong { direction: ltr; font-size: 10px; white-space: nowrap; }
.telegram-source-filter { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }
.telegram-source-filter label { margin: 0; white-space: nowrap; }
.telegram-source-filter select { width: auto; min-width: 180px; padding-block: 6px; }
.telegram-channel-list { margin-top: 14px; }
.form-submit-cell { display: flex; align-items: flex-end; }
.form-submit-cell .btn { width: 100%; min-height: 42px; }
.infinite-load {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 18px 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.infinite-load .btn { min-height: 44px; }
.infinite-load[aria-busy="true"] .infinite-load-status::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-inline-end: 7px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -2px;
  animation: infinite-load-spin .7s linear infinite;
}
@keyframes infinite-load-spin { to { transform: rotate(360deg); } }
#telegram-page.ajax-loading { opacity: .65; pointer-events: none; }
#telegram-page { transition: opacity .15s ease-out; }

@media (prefers-reduced-motion: reduce) {
  #telegram-page { transition: none; }
  .infinite-load[aria-busy="true"] .infinite-load-status::before { animation: none; }
}

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

.crawl-log {
  max-height: 360px;
  overflow: auto;
  padding: 12px 16px;
  font-size: 13px;
  background: var(--surface-2);
}
.crawl-meta { color: var(--muted); font-size: 12px; }
.log-line { padding: 8px 0; border-bottom: 1px solid var(--border); }
.log-line:last-child { border-bottom: none; }
.log-ts { color: var(--muted); font-size: 11px; }
.log-step { color: var(--accent); font-weight: 700; font-size: 11px; }
.log-msg { color: var(--text); }
.log-approve .log-step { color: var(--ok); }
.log-reject .log-step, .log-error .log-step { color: var(--bad); }
.log-tweet-preview {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 8px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.log-avatar { width: 36px; height: 36px; border-radius: 999px; object-fit: cover; }
.log-media { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; margin-right: auto; }
.log-tweet-meta { flex: 1; font-size: 12px; }
.log-tweet-text { color: var(--muted); margin-top: 4px; line-height: 1.6; }
.log-summary { margin-top: 6px; font-size: 11px; color: var(--muted); }

/* ── Tablet and below ─────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { margin-bottom: 0; margin-left: auto; font-size: 15px; }
  .brand small { display: none; }
  .nav-link { padding: 8px 10px; font-size: 13px; }
  .sidebar-footer {
    margin: 0;
    padding: 0;
    border: none;
  }
  .main { padding: 16px; max-width: 100%; }
  .col-9, .col-6, .col-4, .col-3, .col-2, .col-1 { grid-column: span 12; }
  .card-head { flex-wrap: wrap; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .actions { justify-content: flex-start; }
}

/* ── Phones ───────────────────────────────────────────────────────────────
   Below this width the tweet table is unreadable as a table, so each row
   becomes a stacked card: status, author, full-width media, the full text
   (with its Twitter-style quote card), stats, then actions. The edit modal
   becomes a full-width bottom sheet. */
@media (max-width: 760px) {
  html, body { font-size: 14px; }
  .main { padding: 12px; }

  /* stats: two columns instead of a cramped auto-fit */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 20px; }

  /* tabs & sort: one scrollable row, no wrapping */
  .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex-shrink: 0; }
  .sort-bar { padding: 12px 12px 0; }

  .card-head { padding: 12px; }
  .card-body { padding: 12px; }
  .card-head .actions { width: 100%; }
  .card-head .actions .btn { flex: 1 1 auto; justify-content: center; }
  .settings-grid { grid-template-columns: 1fr; }
  .crawl-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .table-wrap.crawl-history-wrap { overflow-x: auto; }

  /* tweet rows → stacked cards */
  .table-wrap { overflow: visible; }
  .tweet-table { min-width: 0; width: 100%; }
  .tweet-table thead { display: none; }
  .tweet-table, .tweet-table tbody, .tweet-table tr, .tweet-table td {
    display: block;
    width: 100%;
  }
  .tweet-table tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
  }
  .tweet-table tr:hover td { background: transparent; }
  .tweet-table td {
    border-bottom: none;
    padding: 6px 0;
    font-size: 14px;
  }
  .tweet-table td:first-child {
    display: flex;
    justify-content: flex-end;
    padding: 0 0 10px;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 6px;
  }
  .row-select { width: 20px; height: 20px; }
  .tweet-table td:last-child {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 6px;
  }

  .author-cell { min-width: 0; }
  .tweet-media { width: 100%; max-width: 100%; height: auto; max-height: 340px; }
  .tweet-media-video { width: auto; margin-inline: auto; }
  .media-thumb-wrap { margin-top: 10px; }
  .tweet-text { max-width: 100%; font-size: 14px; }
  .quote-media { max-height: 260px; }
  .metric-list { grid-template-columns: repeat(2, 1fr); min-width: 0; }

  /* actions: comfortable touch targets */
  .row-actions { gap: 8px; }
  .row-actions .btn-icon,
  .queue-move-actions .btn-icon { width: 44px; height: 44px; }
  .bulk-actions .btn { min-height: 44px; }
  .telegram-source-filter { width: 100%; margin-inline-start: 0; }
  .telegram-source-filter select { min-width: 0; flex: 1; }

  /* edit modal → full-width bottom sheet */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-card {
    width: 100%;
    max-width: 100%;
    height: 94vh;
    height: 94dvh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  .modal-body { padding: 14px; -webkit-overflow-scrolling: touch; }
  .modal-head, .modal-foot { padding: 12px 14px; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
  input, select, textarea { font-size: 16px; } /* prevents iOS auto-zoom on focus */

  /* lightbox */
  .lightbox-overlay { padding: 12px; }

  .crawl-log { max-height: 260px; padding: 10px 12px; }
  .log-media { width: 48px; height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
