/* ========================================================================
   Threads Manager — "Broadsheet"
   A refined print-magazine aesthetic: warm paper, espresso ink,
   terracotta accent, Fraunces display with italic flourishes, fine
   rules, tabular serif numerals, and warm layered depth.
   ======================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;0,9..144,900;1,9..144,400;1,9..144,500;1,9..144,600&family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
  /* Paper & surfaces */
  --bg: #f6f2ec;
  --bg-warm: #efe9e0;
  --surface: #fffdf9;
  --surface-2: #f1ebe1;
  --surface-3: #e6ddd0;
  --border: #e3dacd;
  --border-strong: #cabda9;

  /* Ink */
  --text: #221c16;
  --text-2: #6f6358;
  --text-3: #a59889;

  /* Terracotta accent */
  --accent: #bd5630;
  --accent-hover: #a14625;
  --accent-bg: rgba(189, 86, 48, 0.09);
  --accent-strong: #9c4322;
  --accent-tint: #e8b79f;

  /* Semantic */
  --green: #3f7d62;
  --green-bg: rgba(63, 125, 98, 0.11);
  --red: #b8413f;
  --red-bg: rgba(184, 65, 63, 0.1);
  --yellow: #a87908;
  --yellow-bg: rgba(168, 121, 8, 0.12);
  --blue: #3f6f9c;
  --blue-bg: rgba(63, 111, 156, 0.1);

  /* Radii */
  --radius: 9px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Warm-tinted layered shadows */
  --shadow-sm: 0 1px 2px rgba(58, 42, 28, 0.05), 0 1px 1px rgba(58, 42, 28, 0.04);
  --shadow: 0 4px 14px -4px rgba(58, 42, 28, 0.12), 0 2px 4px -2px rgba(58, 42, 28, 0.07);
  --shadow-lg: 0 24px 48px -12px rgba(58, 42, 28, 0.22), 0 8px 20px -8px rgba(58, 42, 28, 0.14);
  --shadow-accent: 0 6px 18px -6px rgba(189, 86, 48, 0.45);

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  background-color: var(--bg);
  /* Subtle warm vignette + fine paper grain for depth without noise. */
  background-image:
    radial-gradient(1200px 600px at 100% -10%, rgba(189, 86, 48, 0.05), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(168, 121, 8, 0.045), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.025'/%3E%3C/svg%3E");
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; transition: color 0.18s var(--ease); }
a:hover { color: var(--accent-hover); }
button { font-family: inherit; }
::selection { background: var(--accent-tint); color: var(--accent-strong); }

/* Tabular figures everywhere numbers matter */
.value, .stat .value, table td, .counter, .top-card .metrics strong {
  font-variant-numeric: tabular-nums;
}

/* Keyboard accessibility: a single, consistent focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
a:focus-visible, button:focus-visible, .tab:focus-visible { outline-offset: 3px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ========================================================================
   Layout
   ======================================================================== */
.app {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: 100vh;
}

.sidebar {
  background:
    linear-gradient(180deg, var(--surface) 0%, var(--bg-warm) 100%);
  border-right: 1px solid var(--border);
  padding: 30px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 2px 6px 28px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.brand .logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(150deg, #d4733f 0%, var(--accent) 55%, var(--accent-strong) 100%);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  flex-shrink: 0;
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.015em;
  color: var(--text);
  line-height: 1.1;
}
.brand .name .accent {
  color: var(--accent);
  font-style: italic;
  font-weight: 500;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  padding-top: 4px;
}
.nav a {
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 13px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
  cursor: pointer;
  position: relative;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav a:active { transform: translateX(1px); }
.nav a.active {
  background: var(--accent-bg);
  color: var(--accent-strong);
  font-weight: 600;
}
.nav a.active::before {
  content: "";
  position: absolute;
  left: -18px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 22px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.nav a .ico {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.85;
}
.nav a .ico svg { width: 18px; height: 18px; display: block; }
.nav a.active .ico { opacity: 1; }

.user-card {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}
.user-card .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--accent-tint), var(--surface-3));
  display: grid;
  place-items: center;
  color: var(--accent-strong);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
}
.user-card .avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-card .info { flex: 1; min-width: 0; }
.user-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .handle { color: var(--text-3); font-size: 12px; }
.user-card .logout {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 7px 9px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: all 0.2s var(--ease);
}
.user-card .logout:hover { color: var(--red); background: var(--red-bg); }

.main {
  padding: 44px 52px 96px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 66px 1fr; }
  .sidebar { padding: 22px 9px; }
  .brand { justify-content: center; padding: 2px 0 22px; }
  .brand .name, .nav a span, .user-card .info { display: none; }
  .nav a { justify-content: center; padding: 12px; }
  .nav a.active::before { left: -9px; }
  .user-card { justify-content: center; }
}

@media (max-width: 640px) {
  .main { padding: 24px 16px 60px; }
}

/* ========================================================================
   Pages
   ======================================================================== */
.page {
  display: none;
  animation: page-in 0.3s ease;
}
.page.active { display: block; }

@keyframes page-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 34px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.page-head::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 56px;
  height: 2px;
  background: var(--accent);
}
.page-head h1 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--text);
}
.page-head .desc {
  color: var(--text-2);
  font-size: 14.5px;
  margin-top: 7px;
  max-width: 60ch;
}

.token-banner {
  background: linear-gradient(135deg, var(--yellow-bg), rgba(196, 101, 58, 0.05));
  border: 1px solid rgba(184, 134, 11, 0.25);
  color: var(--text);
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.token-banner a { font-weight: 600; }

/* ========================================================================
   Cards / surfaces
   ======================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.25s var(--ease);
}
.card h2, .card h3 {
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-3);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card h2::after, .card h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}
.card h2 { font-size: 12px; color: var(--text-2); }

/* ========================================================================
   Stats
   ======================================================================== */
.dash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.dash-window {
  font-size: 12.5px;
  color: var(--text-3);
  font-style: italic;
  font-family: var(--font-display);
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

/* ----- Dashboard zones: period-driven vs current snapshot ----- */
/* The period zone is what the 7/30/90 selector controls. When the filter
   changes only this zone reloads, so we dim it briefly instead of flashing
   the whole page. The accent rail ties it visually to the toolbar above. */
.dash-zone { position: relative; transition: opacity 0.2s var(--ease); }
.dash-zone--period.is-loading { opacity: 0.4; pointer-events: none; }

/* A labelled divider that makes explicit where period-dependent content ends
   and the always-current snapshot (audience, best hour) begins. */
.zone-sep {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 30px 0 18px;
}
.zone-sep::before,
.zone-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.zone-sep span {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease), border-color 0.28s var(--ease);
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.28s var(--ease);
}
.stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.stat:hover::before { opacity: 1; }
.stat .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.stat .label span { font-size: 14px; opacity: 0.7; }
.stat .value {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--text);
}
.stat .change {
  font-size: 12px;
  font-weight: 500;
  margin-top: 7px;
}
.stat .change.pos { color: var(--green); }
.stat .change.neg { color: var(--red); }
.stat .change.neu { color: var(--text-3); }

/* ========================================================================
   Buttons
   ======================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(160deg, #c96138 0%, var(--accent) 60%, var(--accent-strong) 100%);
  color: #fff;
  border-color: var(--accent-strong);
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-hover) 70%, var(--accent-strong) 100%);
  border-color: var(--accent-strong);
  box-shadow: 0 10px 24px -8px rgba(189, 86, 48, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(196, 75, 75, 0.2);
}
.btn-danger:hover:not(:disabled) {
  background: var(--red);
  color: white;
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }
.btn-block { width: 100%; }

/* ========================================================================
   Forms
   ======================================================================== */
.form-row { display: grid; gap: 16px; margin-bottom: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .form-row.cols-2 { grid-template-columns: 1fr; } }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.form-group .hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 6px;
  font-style: italic;
}

input, textarea, select {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
textarea { resize: vertical; min-height: 100px; line-height: 1.6; }

.input-with-counter { position: relative; }
.input-with-counter textarea { padding-bottom: 28px; }
.input-with-counter .counter {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--text-3);
}
.input-with-counter .counter.warn { color: var(--yellow); }
.input-with-counter .counter.over { color: var(--red); font-weight: 600; }

/* ========================================================================
   Tables
   ======================================================================== */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  font-weight: 700;
  background: var(--bg-warm);
  position: sticky;
  top: 0;
  z-index: 1;
}
th.sortable { transition: color 0.18s var(--ease); }
th.sortable:hover { color: var(--accent); }
tbody tr { transition: background 0.15s var(--ease); }
tr:hover td { background: var(--accent-bg); }
.text-cell {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
td .row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ========================================================================
   Badges
   ======================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}
.badge.draft { background: var(--surface-2); color: var(--text-2); }
.badge.scheduled { background: var(--yellow-bg); color: var(--yellow); }
.badge.publishing { background: var(--blue-bg); color: var(--blue); }
.badge.published { background: var(--green-bg); color: var(--green); }
.badge.failed { background: var(--red-bg); color: var(--red); }

/* ========================================================================
   Tabs
   ======================================================================== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
  position: relative;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ========================================================================
   Modal
   ======================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 32, 0.4);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(8px);
}
.modal-backdrop.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h3 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal .modal-desc {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ========================================================================
   Drawer (slide-in side panel)
   ======================================================================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 32, 0);
  z-index: 110;
  display: flex;
  justify-content: flex-end;
  transition: background 0.22s var(--ease);
}
.drawer-backdrop.show {
  background: rgba(44, 36, 32, 0.4);
  backdrop-filter: blur(6px);
}
.drawer {
  background: var(--surface);
  border-left: 1px solid var(--border);
  width: min(var(--drawer-w, 480px), 100vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.22s var(--ease);
}
.drawer-backdrop.show .drawer { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.drawer-head h3 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-close {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-warm);
  color: var(--text-2);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.drawer-close:hover { color: var(--accent); border-color: var(--accent); }
.drawer-body {
  padding: 20px 24px 32px;
  overflow-y: auto;
  flex: 1;
}
.drawer-body .card { box-shadow: none; border: none; padding: 0; margin-top: 18px; }
@media (max-width: 600px) {
  .drawer { width: 100vw; }
}

/* ========================================================================
   Toast
   ======================================================================== */
.toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 14px 20px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  pointer-events: auto;
  animation: toast-in 0.3s ease;
  min-width: 260px;
  max-width: 380px;
}
.toast.success { border-left: 3px solid var(--green); color: var(--green); }
.toast.error { border-left: 3px solid var(--red); color: var(--red); }
.toast.info { border-left: 3px solid var(--accent); color: var(--accent); }

@keyframes toast-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========================================================================
   Empty / Loading
   ======================================================================== */
.empty {
  text-align: center;
  padding: 72px 24px;
  color: var(--text-2);
}
.empty .ico { font-size: 48px; margin-bottom: 16px; opacity: 0.6; }
.empty p { font-size: 15px; margin-bottom: 16px; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-2);
  font-size: 14px;
}
.loading .spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================================
   Post / thread UI
   ======================================================================== */
.thread-part { position: relative; margin-bottom: 10px; }
.thread-part .num {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 6px;
  display: block;
  font-style: italic;
}
.thread-part textarea { min-height: 80px; }

.ai-result {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.ai-result .part {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.6;
  border: 1px solid var(--border);
}

/* ========================================================================
   Login page
   ======================================================================== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(196, 101, 58, 0.06), transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(184, 134, 11, 0.04), transparent 50%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 52px 44px;
  max-width: 432px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent), #d4733f, var(--yellow));
}
.login-card .logo {
  width: 66px;
  height: 66px;
  border-radius: 18px;
  background: linear-gradient(150deg, #d4733f 0%, var(--accent) 55%, var(--accent-strong) 100%);
  display: grid;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 32px;
  margin: 0 auto 24px;
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.login-card h1 {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-size: 30px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.025em;
}
.login-card p {
  color: var(--text-2);
  font-size: 15px;
  margin-bottom: 30px;
  line-height: 1.6;
}
.login-card .btn { font-size: 15px; padding: 13px 24px; }

.login-card .features {
  margin-top: 32px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.login-card .features li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-2);
}
.login-card .features li::before {
  content: "✓";
  color: var(--green);
  font-weight: 700;
  font-size: 14px;
}

/* ---- Login form ---- */
#localLoginForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 0;
}
#localLoginForm .input {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}
#localLoginForm .input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.error-text {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  padding: 8px;
  background: var(--red-bg);
  border-radius: var(--radius);
}

/* ========================================================================
   Comments
   ======================================================================== */
.comment {
  margin-bottom: 12px;
  padding: 14px 16px;
  background: var(--bg-warm);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.comment .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.comment .author { font-weight: 600; font-size: 13px; }
.comment .ts { font-size: 11px; color: var(--text-3); }
.comment .text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.comment .likes { font-size: 11px; color: var(--text-3); margin-top: 6px; }

.analysis {
  background: var(--bg-warm);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 14px;
  border: 1px solid var(--border);
}
.analysis h4 {
  font-family: var(--font-display);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 12px;
}
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-2);
  margin: 3px 4px 3px 0;
}
.tag.pos { background: var(--green-bg); color: var(--green); }
.tag.neg { background: var(--red-bg); color: var(--red); }
.tag.neu { background: var(--surface-2); color: var(--text-2); }
.tag.mix { background: var(--yellow-bg); color: var(--yellow); }

/* ========================================================================
   Charts
   ======================================================================== */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.chart-card h3 {
  font-family: var(--font-display);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.chart-wrap { position: relative; height: 280px; }

.heatmap {
  display: grid;
  grid-template-columns: 32px repeat(24, 1fr);
  gap: 3px;
  font-size: 10px;
  color: var(--text-3);
  align-items: center;
}
/* Hour labels are shown every 2 hours, so each spans 2 cell-columns. This
   makes the header row fill all 25 columns (corner + 24) so the grid
   auto-flow wraps correctly and day rows line up under the cells. */
.heatmap .hour { grid-column: span 2; text-align: left; font-size: 10px; padding: 2px 0; }
.heatmap .day { text-align: right; padding-right: 8px; }
.heatmap .cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface-2);
  transition: transform 0.15s, box-shadow 0.15s;
}
.heatmap .cell:hover {
  transform: scale(1.3);
  box-shadow: 0 0 0 2px var(--accent);
}

/* ========================================================================
   Audience / demographics
   ======================================================================== */
.audience-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.audience-card[hidden] { display: none; }
.audience-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.audience-head h3 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.audience-head span {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
}
.aud-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.aud-panel {
  background: linear-gradient(160deg, var(--surface) 0%, var(--bg-warm) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.aud-panel h4 {
  font-family: var(--font-display);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin: 0 0 14px;
}
.donut-wrap { position: relative; height: 150px; margin-bottom: 12px; }
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
}
.donut-legend span { display: flex; align-items: center; gap: 7px; }
.donut-legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row {
  display: grid;
  grid-template-columns: 84px 1fr 38px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.bar-label {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-tint), var(--accent));
  transition: width 0.6s var(--ease);
}
.bar-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  font-size: 12px;
}
.aud-note {
  margin-top: 16px;
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
}

/* ========================================================================
   Top post cards
   ======================================================================== */
.top-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.top-card {
  background: linear-gradient(160deg, var(--surface) 0%, var(--bg-warm) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease), border-color 0.28s var(--ease);
}
.top-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}
.top-card .text {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.55;
  margin-bottom: 16px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.top-card .metrics {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-2);
  flex-wrap: wrap;
}
.top-card .metrics strong {
  color: var(--text);
  display: block;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

/* ========================================================================
   Image upload
   ======================================================================== */
.image-uploader {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.2s;
}
.image-uploader:hover, .image-uploader.dragover {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.image-uploader .ico { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }
.image-uploader .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; font-style: italic; }

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
}
.image-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius);
}
.image-preview .url {
  flex: 1;
  font-size: 12px;
  color: var(--text-3);
  word-break: break-all;
}

/* ========================================================================
   Search bar
   ======================================================================== */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search-bar input, .search-bar select { width: auto; flex: 0 0 auto; }
.search-bar input[type="search"] { flex: 1 1 200px; min-width: 200px; }
