/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sb-bg:        #262321;
  --sb-border:    #38342f;
  --sb-text:      #b3aca2;
  --sb-active:    #d97757;
  --sb-active-bg: rgba(217,119,87,.16);
  --sb-hover-bg:  rgba(255,255,255,.05);

  --main-bg:   #f7f5f1;
  --card-bg:   #ffffff;
  --text:      #262321;
  --muted:     #78736b;
  --border:    #e8e4dc;
  --accent:    #d97757;
  --accent-dark: #bd5f42;
  --green:     #647a5a;
  --orange:    #c07b3a;
  --red:       #b3492f;
  --radius:    10px;
  --font:      -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;

  /* Surfaces — overridden in the dark theme below. */
  --surface-alt:   #f9fafb;   /* table header */
  --row-hover:     #fbf3ee;
  --row-expanded:  #f6e2d8;
  --detail-bg:     #faf6f1;
  --border-soft:   #f1f3f5;   /* row separators */
  --tag-bg:        #f6e9e2;
  --tag-text:      #a8562f;
  --btn-sec-hover: #faf1ec;
  color-scheme: light;
}

/* Dark theme — the sidebar was always dark; this brings the main content,
   cards, tables and surfaces along with it. Set via data-theme on <html>
   (see the inline head script + toggleTheme()), so it never flashes. */
:root[data-theme="dark"] {
  --main-bg:   #1b1917;
  --card-bg:   #262321;
  --text:      #ece7df;
  --muted:     #a39c92;
  --border:    #3a352f;

  --surface-alt:   #2b2823;
  --row-hover:     #302b25;
  --row-expanded:  #3a2f28;
  --detail-bg:     #211e1b;
  --border-soft:   #332e29;
  --tag-bg:        #3a2e28;
  --tag-text:      #e6a184;
  --btn-sec-hover: #302b25;
  color-scheme: dark;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--main-bg);
  color: var(--text);
}

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(217,119,87,.08), transparent 60%),
    var(--main-bg);
}
.login-card {
  width: 100%;
  max-width: 396px;
  padding: 40px 40px 30px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 1px 2px rgba(38,35,33,.04), 0 12px 32px -12px rgba(38,35,33,.18);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  background: linear-gradient(145deg, var(--accent), var(--accent-dark));
  display: grid; place-items: center;
  color: #fff; font-family: var(--font-serif); font-size: 17px; line-height: 1;
  box-shadow: 0 2px 8px -2px rgba(217,119,87,.6);
}
.login-wordmark {
  font-family: var(--font-serif); font-size: 20px; color: var(--text); letter-spacing: -.2px;
}
.login-head { display: flex; flex-direction: column; gap: 8px; }
.login-head h1 {
  margin: 0; font-family: var(--font-serif); font-weight: 400;
  font-size: 25px; line-height: 1.2; letter-spacing: -.3px; color: var(--text);
  text-wrap: balance;
}
.login-head p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--muted); max-width: 34ch; }
.login-widget { display: flex; justify-content: center; min-height: 1px; }

/* ── App Shell ───────────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 18px;
  font-family: var(--font-serif);
  font-size: 1.2rem;
  font-weight: 400;
  color: #f4f1ea;
  letter-spacing: -0.2px;
  border-bottom: 1px solid var(--sb-border);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.nav-section-label {
  padding: 0 20px 6px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--sb-text);
  opacity: .55;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sb-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
  cursor: pointer;
  border-left: 2px solid transparent;
}
.nav-item:hover {
  background: var(--sb-hover-bg);
  color: #e2e8f0;
}
.nav-item.active {
  background: var(--sb-active-bg);
  color: var(--sb-active);
  border-left-color: var(--sb-active);
}
.nav-icon { font-size: 13px; width: 16px; }

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-user {
  font-size: 12px;
  color: var(--sb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  background: none;
  border: 1px solid var(--sb-border);
  color: var(--sb-text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .12s, color .12s;
}
.sidebar-logout:hover { border-color: #8892a4; color: #e2e8f0; }

/* ── Main Content ────────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 32px 36px 48px;
}

/* ── Pages ───────────────────────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 24px; }

.page-title {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}
.page-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Filters Bar ─────────────────────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.filter-group label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.filter-input, .filter-select {
  background: var(--main-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  height: 34px;
  outline: none;
  transition: border-color .12s;
  font-family: var(--font);
}
.filter-input:focus, .filter-select:focus { border-color: var(--accent); }
.filter-select { cursor: pointer; appearance: auto; }

.filter-search {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  margin-left: auto;
}
.search-input { width: 190px; }

.btn-search {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
  height: 34px;
  cursor: pointer;
  transition: opacity .12s;
}
.btn-search:hover { opacity: .85; }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-container {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.posts-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.posts-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.col-check   { width: 34px; text-align: center; }
.col-channel { width: 175px; }
.col-dots    { width: 40px; }
.col-post    { }
.col-topics  { width: 190px; }
.col-date    { width: 72px; }

.posts-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  overflow: hidden;
}

.cell-check {
  text-align: center;
}
.cell-check input[type=checkbox],
.col-check input[type=checkbox] {
  accent-color: var(--accent);
  cursor: pointer;
}
.posts-table tbody tr:last-child td { border-bottom: none; }

.posts-table tbody tr.data-row {
  cursor: pointer;
  transition: background .1s;
}
.posts-table tbody tr.data-row:hover { background: var(--row-hover); }
.posts-table tbody tr.data-row.expanded { background: var(--row-expanded); }

.cell-channel {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status dots */
.cell-dots { display: flex; gap: 4px; align-items: center; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: #10b981; }
.dot-orange { background: #f97316; }
.dot-blue   { background: #d97757; }
.dot-gray   { background: #d1d5db; }

.cell-post {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cell-topics {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topic-tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
}

.cell-date {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* Expanded detail row */
.detail-row { display: none; }
.detail-row.visible { display: table-row; }
.detail-row > td {
  padding: 0;
  background: var(--detail-bg);
  border-bottom: 1px solid var(--border);
}
.detail-inner {
  padding: 16px 20px 16px 207px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-summary {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}
.detail-original {
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 6px;
}
.detail-link {
  color: var(--accent);
  font-size: 12px;
  text-decoration: none;
  font-weight: 500;
}
.detail-link:hover { text-decoration: underline; }

.table-message {
  text-align: center;
  padding: 32px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .12s;
  font-family: var(--font);
}
.btn-primary:hover { opacity: .85; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  font-family: var(--font);
}
.btn-secondary:hover { border-color: var(--accent); background: var(--btn-sec-hover); }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

/* ── Digest Page ─────────────────────────────────────────────────────────────── */
.digest-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 760px;
}
.digest-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  max-height: 620px;
  overflow-y: auto;
  color: var(--text);
}

/* ── Events Table ────────────────────────────────────────────────────────────── */
.events-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.events-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.evcol-check    { width: 34px; text-align: center; }
.evcol-date     { width: 90px; }
.evcol-name     { width: 220px; }
.evcol-topics   { width: 170px; }
.evcol-type     { width: 110px; }
.evcol-location { width: 160px; }
.evcol-speakers { width: 130px; }
.evcol-partners { width: 130px; }
.evcol-mentions { width: 60px; text-align: center; }

.cell-evcheck {
  text-align: center;
}
.cell-evcheck input[type=checkbox],
.evcol-check input[type=checkbox] {
  accent-color: var(--accent);
  cursor: pointer;
}

.events-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  overflow: hidden;
  font-size: 13px;
}
.events-table tbody tr:last-child td { border-bottom: none; }

.events-table tbody tr.data-row {
  cursor: pointer;
  transition: background .1s;
}
.events-table tbody tr.data-row:hover { background: var(--row-hover); }
.events-table tbody tr.data-row.expanded { background: var(--row-expanded); }

.cell-evdate {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}
.ev-time { color: var(--muted); font-size: 11px; }

.cell-evname {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-expand-icon {
  color: var(--muted);
  font-size: 10px;
  margin-right: 6px;
}
.ev-name-link {
  color: var(--text);
  text-decoration: none;
}
.ev-name-link:hover { color: var(--accent); text-decoration: underline; }

.cell-evtopics {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-topic-tag {
  display: inline-block;
  background: var(--surface-alt);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  margin-right: 3px;
}

.ev-type-badge {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.cell-evlocation, .cell-evspeakers, .cell-evpartners {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
  font-size: 12px;
}

.cell-evmentions {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.ev-detail-inner { padding: 14px 20px; }

/* Reset / ghost button */
.btn-ghost-sm {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .12s, color .12s;
  align-self: flex-end;
  font-family: var(--font);
}
.btn-ghost-sm:hover { border-color: var(--accent); color: var(--text); }
.ev-date { color: var(--accent); font-weight: 600; font-size: 12px; }
.ev-name { font-weight: 500; font-size: 13px; margin-top: 3px; }
.ev-name a { color: var(--green); text-decoration: none; }
.ev-name a:hover { text-decoration: underline; }

/* ── Channels Page ───────────────────────────────────────────────────────────── */
.channels-page {
  max-width: 580px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.channels-actions { display: flex; flex-direction: column; gap: 10px; }
.add-channel-row { display: flex; gap: 8px; }
.add-input { flex: 1; height: 38px; }
.channels-btns { display: flex; gap: 8px; flex-wrap: wrap; }

.channels-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
}
.channel-item-name { font-weight: 500; }
.channel-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 0 4px;
  line-height: 1;
  transition: color .12s;
}
.channel-remove:hover { color: #ef4444; }

/* ── Schedule Page (table layout) ───────────────────────────────────────────── */
.sched-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.sched-table .scol-name   { width: 240px; }
.sched-table .scol-type   { width: 90px; }
.sched-table .scol-cron   { width: 160px; }
.sched-table .scol-topics { width: 100px; }
.sched-table .scol-status { width: 100px; }
.sched-table .scol-last   { width: 160px; }
.sched-table .scol-act    { width: 60px; }

.sched-name { font-size: 13px; font-weight: 500; color: var(--text); }

.type-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.type-badge.topics  { background: #e6ddf5; color: #5b4b8a; }
.type-badge.events  { background: #f5e2c2; color: #96601e; }
.type-badge.collect { background: #dbe7d5; color: #3f5c37; }

.cron-text { font-size: 12px; color: var(--muted); font-family: monospace; }

.status-btn {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity .15s;
}
.status-btn:hover { opacity: .8; }
.status-btn.active { background: #dbe7d5; color: #3f5c37; }
.status-btn.paused { background: #f3f4f6; color: var(--muted); }

.last-run { font-size: 12px; color: var(--muted); }

.row-del-btn, .row-edit-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  transition: color .12s;
}
.row-del-btn:hover { color: #ef4444; }
.row-edit-btn:hover { color: var(--accent); }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

.type-btns { display: flex; gap: 6px; }
.type-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--main-bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
  font-family: var(--font);
}
.type-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Old schedule-grid (kept for legacy CSS safety) ──────────────────────────── */
.schedule-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  max-width: 900px;
}
@media (max-width: 780px) { .schedule-grid { grid-template-columns: 1fr; } }

.sched-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sched-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sched-slot-title { font-size: 15px; font-weight: 600; color: var(--text); }
.sched-slot-time { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: #d1d5db;
  border-radius: 999px;
  transition: background .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-track::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-track::after { transform: translateX(18px); }

.sched-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: -6px;
}
.sched-hint { font-size: 10px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.sched-radio-row { display: flex; gap: 16px; flex-wrap: wrap; }
.sched-radio {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.sched-radio input[type=radio] { accent-color: var(--accent); cursor: pointer; }

.sched-select { width: 100%; height: 36px; }

.sched-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cat-check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  background: var(--main-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  transition: border-color .12s, background .12s;
}
.cat-check:has(input:checked) { border-color: var(--accent); background: var(--tag-bg); color: var(--tag-text); }
.cat-check input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }

.sched-save-btn { align-self: flex-start; margin-top: 4px; }
.sched-status { font-size: 12px; height: 18px; color: var(--green); }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .sidebar { width: 60px; }
  .sidebar-logo, .nav-section-label, .sidebar-user, .sidebar-logout { display: none; }
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-item { justify-content: center; padding: 13px; }
  .main-content { padding: 20px 16px; }
  .detail-inner { padding: 14px 16px; }
}

/* ── Magic Link ──────────────────────────────────────────────────────────────── */
.login-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .08em;
}
.login-divider::before, .login-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.magic-link-section { display: flex; flex-direction: column; gap: 9px; }
.magic-label { font-size: 12px; font-weight: 600; color: var(--text); }
.magic-link-row {
  display: flex; align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 11px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.magic-link-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--tag-bg);
}
.magic-at { padding: 0 4px 0 14px; color: var(--muted); font-size: 14.5px; }
.magic-input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  color: var(--text); font-size: 14.5px; padding: 12px 12px 12px 2px;
}
.magic-input::placeholder { color: var(--muted); }
.btn-magic {
  background: var(--accent); color: #fff; border: none;
  border-radius: 11px; font-size: 14px; font-weight: 600;
  padding: 12px 16px; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.btn-magic:hover { background: var(--accent-dark); }
.btn-magic:disabled { opacity: 0.55; cursor: default; }
.magic-link-hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }
.magic-link-hint code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11.5px;
  background: var(--tag-bg); color: var(--tag-text); padding: 1px 6px; border-radius: 5px;
}
.magic-link-hint a { color: var(--tag-text); text-decoration: none; }
.magic-status { font-size: 12.5px; min-height: 1em; }
.magic-status.success { color: var(--green); }
.magic-status.error { color: var(--red); }
.login-foot {
  display: flex; flex-direction: column; gap: 4px;
  text-align: center; font-size: 11.5px; color: var(--muted); line-height: 1.5;
  padding-top: 4px; border-top: 1px solid var(--border-soft);
}
.login-credit a { color: var(--accent-dark); text-decoration: none; font-weight: 600; }
.login-credit a:hover { text-decoration: underline; }
.sidebar-credit {
  display: block; margin-top: 10px;
  font-size: 11px; color: var(--sb-text); opacity: .7;
  text-decoration: none;
}
.sidebar-credit:hover { opacity: 1; color: var(--sb-active); }

/* ── Resizable table columns ───────────────────────────────────────────────── */
.posts-table thead th,
.events-table thead th {
  position: relative;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
  touch-action: none;
}
.col-resize-handle:hover,
.col-resize-handle.active {
  background: var(--accent);
  opacity: .5;
}

/* ── Row density toggle ────────────────────────────────────────────────────── */
.density-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  height: 34px;
}
.density-btn {
  background: var(--card-bg);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 0 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: background .12s, color .12s;
}
.density-btn:last-child { border-right: none; }
.density-btn:hover { background: var(--main-bg); color: var(--text); }
.density-btn.active { background: var(--accent); color: #fff; }

.table-container[data-density="compact"] .posts-table td { padding-top: 6px; padding-bottom: 6px; }
.table-container[data-density="compact"] .cell-post { font-size: 12.5px; }

.table-container[data-density="expanded"] .posts-table td { padding-top: 14px; padding-bottom: 14px; }
.table-container[data-density="expanded"] .cell-post {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.55;
}
.table-container[data-density="expanded"] .cell-channel,
.table-container[data-density="expanded"] .cell-topics {
  white-space: normal;
}

/* ── Unread state ──────────────────────────────────────────────────────────── */
.unread-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Read posts fade back; unread ones carry a left accent marker. */
.posts-table tbody tr.data-row.is-read .cell-channel,
.posts-table tbody tr.data-row.is-read .cell-post { color: var(--muted); font-weight: 400; }
.posts-table tbody tr.data-row:not(.is-read) .cell-channel {
  box-shadow: inset 3px 0 0 var(--accent);
  padding-left: 11px;
}

.unread-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  height: 34px;
  cursor: pointer;
  white-space: nowrap;
}
.unread-check input { accent-color: var(--accent); cursor: pointer; }

/* ── Skeleton loading rows ─────────────────────────────────────────────────── */
.skeleton-bar {
  height: 11px;
  border-radius: 4px;
  background: linear-gradient(90deg, #ece8e1 25%, #f4f1ea 37%, #ece8e1 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.3s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ── Keyboard navigation ───────────────────────────────────────────────────── */
.posts-table tbody tr.data-row.kb-active {
  background: var(--row-expanded);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.kbd-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
}
.kbd-hint kbd {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10.5px;
}

/* ── Theme toggle (sidebar) ────────────────────────────────────────────────── */
.sidebar-theme {
  background: none;
  border: 1px solid var(--sb-border);
  color: var(--sb-text);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .12s, color .12s;
}
.sidebar-theme:hover { border-color: #8892a4; color: #e2e8f0; }

/* ── Language toggle (fixed, top-right — visible on login/pending/app alike) ── */
.lang-toggle-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 2500;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  transition: border-color .12s, color .12s;
}
.lang-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Toasts ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  background: #33302b;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border-left: 3px solid var(--muted);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .22s, transform .22s;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-left-color: var(--green); }
.toast.error   { border-left-color: var(--red); }
.toast.info    { border-left-color: var(--accent); }

/* ── Semantic Search Similarity Badge ─────────────────────────────────────── */
.sim-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
  white-space: nowrap;
}

/* ── Statistics page ──────────────────────────────────────────────────────── */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-card .stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-top: 6px;
}
.stat-card.accent .stat-value { color: var(--accent); }

.stats-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.stats-h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 0 0 16px;
}
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 820px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Daily bar chart — flex row of vertical bars. */
.stats-daychart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
}
.day-bar {
  flex: 1 1 0;
  min-width: 2px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  position: relative;
}
.day-bar .day-fill {
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: opacity .15s;
}
.day-bar:hover .day-fill { opacity: .75; }
.day-bar .day-tip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--card-bg);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  margin-bottom: 4px;
  z-index: 5;
}
.day-bar:hover .day-tip { opacity: 1; }

/* Horizontal bar list — category / channel breakdown. */
.stats-barlist { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .bar-name {
  flex: 0 0 34%;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-row .bar-track {
  flex: 1 1 auto;
  background: var(--surface-alt);
  border-radius: 5px;
  height: 14px;
  overflow: hidden;
}
.bar-row .bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 5px;
  min-width: 2px;
}
.bar-row .bar-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
  text-align: right;
}

/* ── Channel health rows ──────────────────────────────────────────────────── */
.channel-item.health { flex-direction: column; align-items: stretch; gap: 6px; }
.channel-health-top { display: flex; align-items: center; gap: 10px; }
.channel-health-top .channel-item-name { flex: 1 1 auto; }
.ch-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
}
.ch-dot.ok    { background: var(--green); }
.ch-dot.stale { background: var(--orange); }
.ch-dot.err   { background: var(--red); }
.ch-dot.empty { background: var(--muted); }
.channel-health-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  padding-left: 19px;
}
.channel-health-meta b { color: var(--text); font-weight: 600; }
.channel-health-err {
  font-size: 12px;
  color: var(--red);
  padding-left: 19px;
  word-break: break-word;
}

/* ── Duplicate-cluster badge + sources ────────────────────────────────────── */
.dup-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  vertical-align: middle;
  transition: background .15s;
}
.dup-badge:hover { background: var(--accent-dark); }

.cluster-src {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}
.cluster-src:last-child { border-bottom: none; }

/* ── Favorites ★ ──────────────────────────────────────────────────────────── */
.fav-star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 4px 0 0;
  color: var(--muted);
  vertical-align: middle;
  transition: color .15s, transform .1s;
}
.fav-star:hover { color: var(--accent); transform: scale(1.15); }
.fav-star.active { color: var(--accent); }
.fav-star:disabled { opacity: .5; cursor: default; transform: none; }

.favorites-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 4px 0 32px;
}
.fav-group-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.fav-subgroup-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 10px 0 6px;
}
.fav-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.fav-card .fav-star { font-size: 17px; padding-top: 1px; }
.fav-card-body { flex: 1; min-width: 0; }
.fav-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 4px;
}
.fav-card-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.fav-card-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 6px;
}
.cluster-src-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.cluster-src-name { font-weight: 600; color: var(--text); font-size: 14px; }
.cluster-src-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cluster-src-sum { color: var(--muted); font-size: 13px; margin: 5px 0 6px; line-height: 1.4; }
.cluster-src-link { color: var(--accent); font-size: 13px; text-decoration: none; }
.cluster-src-link:hover { text-decoration: underline; }

/* ── Assistant (RAG chat) ──────────────────────────────────────────────────── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  min-height: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: auto;
  max-width: 460px;
  text-align: center;
}
.chat-msg { max-width: 82%; font-size: 14px; line-height: 1.5; }
.chat-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  border-radius: 14px 14px 3px 14px;
  white-space: pre-wrap;
}
.chat-msg-bot {
  align-self: flex-start;
  background: var(--surface-alt);
  color: var(--text);
  padding: 11px 15px;
  border-radius: 14px 14px 14px 3px;
}
.chat-answer { white-space: pre-wrap; }
.chat-thinking { color: var(--muted); font-style: italic; }
.chat-error { color: var(--red); }
.cite {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  padding: 0 1px;
}
.cite:hover { text-decoration: underline; }

.chat-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
}
.chat-sources-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.chat-src {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: 6px;
  transition: background .2s;
}
.chat-src-n { color: var(--accent); font-weight: 700; flex: 0 0 auto; font-size: 13px; }
.chat-src-body { min-width: 0; }
.chat-src-head { font-size: 13px; font-weight: 600; }
.chat-src-head a { color: var(--text); text-decoration: none; }
.chat-src-head a:hover { color: var(--accent); }
.chat-src-date { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.chat-src-snip { color: var(--muted); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.cite-flash { background: var(--tag-bg); }

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.chat-input { flex: 1 1 auto; }

/* ── Channel enable/disable ─────────────────────────────────────────────────── */
.ch-off-badge {
  font-size: 11px;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 4px;
  padding: 0 6px;
  flex: 0 0 auto;
}
.ch-toggle { flex: 0 0 auto; height: 26px; padding: 0 10px; }

/* ── Posts export ───────────────────────────────────────────────────────────── */
.export-wrap { position: relative; display: inline-block; }
.export-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  z-index: 20;
  overflow: hidden;
  min-width: 120px;
}
.export-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.export-menu button:hover { background: var(--surface-alt); }

/* ── Invite code (login + pending screens) ────────────────────────────────── */
.invite-details {
  font-size: 12.5px;
  color: var(--muted);
}
.invite-details summary {
  cursor: pointer;
  user-select: none;
  color: var(--accent-dark);
  font-weight: 600;
}
.invite-details summary:hover { text-decoration: underline; }
.invite-input {
  width: 100%;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.invite-hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}
.login-widget-fallback {
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  margin: 0;
  padding: 10px 0;
}

/* ── Owner admin page ─────────────────────────────────────────────────────── */
.admin-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.admin-section-head .stats-h2 { margin: 0; }
