html, body {
  height: 100%;
}

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

:root {
  --bg: #101217;
  --surface: #171a21;
  --surface2: #20242d;
  --surface3: #2a303b;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --accent: #f0a6ca;
  --accent2: #79d8c2;
  --accent-glow: rgba(240,166,202,0.14);
  --teal: #79d8c2;
  --teal-dim: rgba(121,216,194,0.12);
  --text: #f6f2ed;
  --text-2: #b9b2aa;
  --text-3: #7d858e;
  --gold: #f4c76b;
  --gold-dim: rgba(244,199,107,0.13);
  --red: #f87171;
  --red-dim: rgba(248,113,113,0.12);
  --green: #8bdc8b;
  --green-dim: rgba(139,220,139,0.12);
  --purple-dim: rgba(240,166,202,0.12);
  --serif: Georgia, 'Times New Roman', serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  min-height: 100vh;
  display: flex;
  overflow: hidden;
}

body::before {
  display: none;
}
body::after {
  display: none;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 0.5px solid var(--border);
}

.logo-character {
  width: 54px;
  height: 54px;
  display: block;
  object-fit: cover;
  border-radius: 16px;
  margin-bottom: 10px;
  border: 0.5px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
}

.logo-name {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--accent);
  letter-spacing: 0;
  line-height: 1;
}
.logo-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 12px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-section {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 10px 4px;
  margin-top: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 400;
  user-select: none;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--sans);
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 500;
}
.nav-icon { font-size: 15px; opacity: 0.85; }

.sidebar-profile {
  padding: 14px 16px;
  border-top: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.profile-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.image-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.profile-name { font-size: 13px; font-weight: 500; color: var(--text); }
.profile-handle { font-size: 11px; color: var(--text-3); }
.profile-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); margin-left: auto; flex-shrink: 0;
  box-shadow: 0 0 6px var(--green);
}

/* ============================================================
   MAIN AREA
   ============================================================ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 5;
  min-width: 0;
  min-height: 100vh;
}

/* Top bar */
.topbar {
  padding: 14px 24px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  flex-shrink: 0;
}
.topbar-title {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--text);
  flex: 1;
}
.topbar-title span { color: var(--accent); font-style: italic; }

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 20px;
  padding: 4px;
}

.status-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--teal-dim);
  border: 0.5px solid rgba(45,212,191,0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px; color: var(--teal); font-weight: 500;
  white-space: nowrap;
}
.status-pill.error {
  background: var(--red-dim);
  border-color: rgba(248,113,113,0.2);
  color: var(--red);
}
.status-pill.running {
  background: var(--gold-dim);
  border-color: rgba(251,191,36,0.2);
  color: var(--gold);
}

.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sync-btn {
  background: var(--surface2);
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12px; color: var(--text-2);
  cursor: pointer; font-family: var(--sans);
  transition: all 0.15s;
  white-space: nowrap;
  touch-action: manipulation;
}
.sync-btn:hover { background: var(--surface3); color: var(--text); }
.sync-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   CONTENT AREA
   ============================================================ */

.content {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(720px, 1fr) clamp(460px, 32vw, 620px);
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

body.chat-hidden .content {
  grid-template-columns: minmax(0, 1fr);
}

body.chat-hidden .chat-panel {
  display: none;
}

body.chat-expanded .content {
  grid-template-columns: minmax(520px, 0.78fr) minmax(620px, 1fr);
}

body.chat-expanded .briefing-hero,
body.chat-expanded .workflow-grid {
  grid-template-columns: 1fr;
}

body.chat-expanded .stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ============================================================
   DASHBOARD (left panel)
   ============================================================ */

.dashboard {
  overflow-y: auto;
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overscroll-behavior: contain;
  min-height: 0;
}
.dashboard::-webkit-scrollbar { width: 4px; }
.dashboard::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

/* Section header */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-family: var(--serif);
  font-size: 15px; color: var(--text);
}
.section-link {
  font-size: 12px; color: var(--accent); cursor: pointer;
  background: none; border: none; font-family: var(--sans);
  touch-action: manipulation;
}
.section-link:hover { text-decoration: underline; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  opacity: 0;
  transition: opacity 0.3s;
}
.stat-card.highlight::before { opacity: 1; }
.stat-label {
  font-size: 10px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.stat-val {
  font-family: var(--serif);
  font-size: 26px; color: var(--text); line-height: 1;
}
.stat-val.accent { color: var(--accent); }
.stat-delta {
  font-size: 11px; margin-top: 4px;
  display: flex; align-items: center; gap: 3px;
  flex-wrap: wrap;
}
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }
.stat-delta.neutral { color: var(--text-3); }
.stat-delta a {
  color: var(--accent);
  text-decoration: none;
}
.stat-delta a:hover { text-decoration: underline; }
.metric-source {
  color: var(--text-3);
}

.platform-overview {
  display: block;
}

.platform-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.platform-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.platform-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.platform-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 0.5px solid var(--border2);
  background: var(--surface2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 800;
}

.platform-pill.tiktok {
  color: var(--teal);
  background: var(--teal-dim);
  border-color: rgba(121,216,194,0.22);
}

.platform-pill.instagram {
  color: var(--accent);
  background: var(--accent-glow);
  border-color: rgba(240,166,202,0.24);
}

.platform-pill.youtube {
  color: #fca5a5;
  background: rgba(248,113,113,0.11);
  border-color: rgba(248,113,113,0.22);
}

.platform-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.platform-metrics div {
  min-width: 0;
  padding: 8px;
  border-radius: 8px;
  background: var(--surface2);
}

.platform-metrics strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 15px;
}

.platform-metrics span {
  display: block;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.platform-card p {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
}

/* Insight cards */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.insight-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.insight-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; font-weight: 500; letter-spacing: 0.05em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 4px;
  margin-bottom: 8px;
}
.insight-tag.purple { background: var(--purple-dim); color: var(--accent); }
.insight-tag.teal   { background: var(--teal-dim); color: var(--teal); }
.insight-tag.gold   { background: var(--gold-dim); color: var(--gold); }
.insight-tag.green  { background: var(--green-dim); color: var(--green); }
.insight-tag.red    { background: var(--red-dim); color: var(--red); }

.insight-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  margin-bottom: 5px;
}
.insight-body {
  font-size: 12px; color: var(--text-2); line-height: 1.5;
}

/* Recommendation card */
.rec-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.rec-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 10px;
}
.rec-title {
  font-size: 14px; font-weight: 500; color: var(--text);
}
.rec-badge {
  background: var(--purple-dim);
  border: 0.5px solid rgba(192,132,252,0.2);
  color: var(--accent);
  font-size: 11px; padding: 3px 8px;
  border-radius: 20px; white-space: nowrap;
}
.rec-meta {
  display: flex; gap: 16px; margin-bottom: 10px;
}
.rec-meta-item {
  font-size: 12px; color: var(--text-3);
}
.rec-meta-item span { color: var(--text-2); font-weight: 500; }
.rec-hashtags {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px;
}
.hashtag {
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px; color: var(--teal);
}
.rec-tip {
  font-size: 12px; color: var(--text-2);
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 12px;
  border-left: 2px solid var(--accent);
}

/* Video table */
.video-table-wrap {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
}
.video-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.video-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 0.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.video-table th:hover { color: var(--text-2); }
.video-table th.sorted { color: var(--accent); }
.video-table td {
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}
.video-table tr:last-child td { border-bottom: none; }
.video-table tr:hover td { background: var(--surface2); }
.video-title-cell {
  width: min(380px, 42vw);
  color: var(--text);
}
.video-title-main {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-title-main a {
  color: var(--text);
  text-decoration: none;
}
.video-title-main a:hover { color: var(--accent); }
.video-title-sub {
  margin-top: 3px;
  overflow: hidden;
  color: var(--text-3);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--surface2);
  font-size: 11px; font-weight: 600; color: var(--text-3);
}
.rank-badge.gold { background: var(--gold-dim); color: var(--gold); }
.rank-badge.silver { background: rgba(168,158,192,0.15); color: var(--text-2); }
.rank-badge.bronze { background: rgba(192,132,100,0.15); color: #c08460; }

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
}
.empty-state .empty-icon { font-size: 32px; margin-bottom: 10px; }
.empty-state p { font-size: 13px; }

/* ============================================================
   CHAT PANEL (right)
   ============================================================ */

.chat-panel {
  border-left: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  width: auto;
  min-height: 0;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.chat-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
  overflow: hidden;
}
.chat-header-name {
  font-weight: 500; font-size: 14px; color: var(--text);
}
.chat-header-sub {
  font-size: 11px; color: var(--text-3);
}
.chat-expand-btn,
.chat-toggle-btn,
.chat-clear-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  touch-action: manipulation;
}
.chat-expand-btn,
.chat-toggle-btn {
  width: 26px;
  height: 26px;
  font-size: 18px;
  line-height: 1;
}
.chat-expand-btn {
  margin-left: auto;
  font-size: 15px;
}
.chat-toggle-btn {
  margin-left: 0;
}
.chat-clear-btn {
  margin-left: 0;
}
.chat-expand-btn:hover,
.chat-toggle-btn:hover { color: var(--accent); background: var(--accent-glow); }
.chat-clear-btn:hover { color: var(--red); background: var(--red-dim); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

.msg {
  display: flex;
  gap: 10px;
  max-width: min(92%, 760px);
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0; align-self: flex-end;
  overflow: hidden;
}

.msg-bubble {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.msg-bubble p {
  margin: 0 0 10px;
}
.msg-bubble p:last-child {
  margin-bottom: 0;
}
.msg-bubble h3,
.msg-bubble h4,
.msg-bubble h5 {
  margin: 16px 0 8px;
  color: var(--text);
  font-family: var(--serif);
  letter-spacing: 0;
  line-height: 1.25;
}
.msg-bubble h3:first-child,
.msg-bubble h4:first-child,
.msg-bubble h5:first-child {
  margin-top: 0;
}
.msg-bubble h3 { font-size: 20px; }
.msg-bubble h4 { font-size: 17px; }
.msg-bubble h5 { font-size: 15px; }
.msg-bubble strong {
  color: var(--text);
  font-weight: 800;
}
.msg-bubble em {
  color: var(--text-2);
}
.msg-bubble a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 0.5px solid rgba(240,166,202,0.45);
}
.msg-bubble a:hover {
  color: var(--teal);
  border-bottom-color: rgba(121,216,194,0.55);
}
.msg-bubble ul {
  margin: 8px 0 12px;
  padding-left: 20px;
}
.msg-bubble li {
  margin: 4px 0;
}
.msg-bubble blockquote {
  margin: 12px 0;
  padding: 9px 12px;
  border-left: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(240,166,202,0.08);
  color: var(--text-2);
}
.msg-bubble hr {
  height: 1px;
  margin: 16px 0;
  border: 0;
  background: var(--border2);
}
.msg-bubble code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255,255,255,0.07);
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92em;
}
.msg-bubble pre {
  margin: 10px 0 14px;
  padding: 12px;
  overflow-x: auto;
  border-radius: 8px;
  background: #101217;
  border: 0.5px solid var(--border);
}
.msg-bubble pre code {
  padding: 0;
  background: transparent;
  white-space: pre;
}
.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0 14px;
  border: 0.5px solid var(--border);
  border-radius: 8px;
}
.msg-bubble table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}
.msg-bubble th,
.msg-bubble td {
  padding: 8px 10px;
  border-bottom: 0.5px solid var(--border);
  border-right: 0.5px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.msg-bubble th:last-child,
.msg-bubble td:last-child {
  border-right: 0;
}
.msg-bubble tr:last-child td {
  border-bottom: 0;
}
.msg-bubble th {
  color: var(--teal);
  background: rgba(255,255,255,0.04);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg.assistant .msg-bubble {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.msg.user .msg-bubble {
  background: var(--accent-glow);
  border: 0.5px solid rgba(192,132,252,0.25);
  color: var(--text);
  border-bottom-right-radius: 3px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 3px;
  padding: 0 2px;
}
.msg.user .msg-time { text-align: right; }

/* Typing indicator */
.typing-indicator {
  display: flex; gap: 4px; padding: 4px 2px;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: typing 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Suggestion chips */
.chat-suggestions {
  padding: 0 14px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}
.chat-suggestions::-webkit-scrollbar {
  display: none;
}
.chip {
  background: var(--surface2);
  border: 0.5px solid var(--border2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.15s;
  touch-action: manipulation;
}
.chip:hover {
  background: var(--accent-glow);
  border-color: rgba(192,132,252,0.3);
  color: var(--accent);
}

/* Chat input */
.chat-input-area {
  padding: 12px 14px;
  border-top: 0.5px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
}
.chat-textarea {
  flex: 1;
  background: var(--surface2);
  border: 0.5px solid var(--border2);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--sans);
  resize: none;
  outline: none;
  max-height: 140px;
  min-height: 42px;
  line-height: 1.5;
  transition: border-color 0.15s;
  overflow-y: auto;
}
.chat-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chat-textarea::placeholder { color: var(--text-3); }

.send-btn {
  width: 40px; height: 40px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: opacity 0.15s;
  flex-shrink: 0;
  touch-action: manipulation;
}
.send-btn:hover { opacity: 0.9; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 8px 14px 8px 8px;
  border: 0.5px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  background: rgba(23,26,33,0.94);
  color: var(--text);
  box-shadow: 0 18px 44px rgba(0,0,0,0.35);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 800;
}
.chat-fab img {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
}
.chat-fab:hover {
  border-color: rgba(240,166,202,0.35);
  color: var(--accent);
}

/* ============================================================
   SIDEBAR OVERLAY (mobile)
   ============================================================ */

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9;
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 1340px) {
  body {
    overflow: auto;
  }

  .main {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .content,
  body.chat-expanded .content {
    display: flex;
    flex-direction: column;
    flex: none;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .dashboard {
    flex: none;
    overflow: visible;
  }

  .chat-panel {
    flex: none;
    width: auto;
    min-height: 680px;
    max-height: none;
    border-left: none;
    border-top: 0.5px solid var(--border);
  }

  .chat-messages {
    min-height: 460px;
  }
}

@media (max-width: 768px) {
  body { overflow: auto; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; }

  .hamburger { display: block; }

  .main { min-width: 0; width: 100%; }

  .content,
  body.chat-expanded .content {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .chat-panel {
    border-left: none;
    border-top: 0.5px solid var(--border);
    min-height: 560px;
  }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .insights-grid { grid-template-columns: 1fr; }

  .dashboard { padding: 14px 14px; }
  .topbar { padding: 12px 14px; }
  .topbar-title { flex-basis: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .status-pill { display: none; }
}

.hidden {
  display: none !important;
}

.stale-banner {
  background: rgba(248,113,113,0.1);
  border: 0.5px solid rgba(248,113,113,0.2);
  color: var(--red);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
}

.rec-description {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 12px;
}

.table-actions {
  font-size: 12px;
  color: var(--text-3);
}

.rec-badge span {
  color: var(--text);
  margin-left: 4px;
}

/* ============================================================
   CREATOR STUDIO REFRESH
   ============================================================ */

.startup-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(160deg, rgba(16,18,23,0.92), rgba(16,18,23,0.78)),
    linear-gradient(135deg, #211a21, #101217 48%, #14221f);
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.startup-overlay.dismissed {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.startup-panel {
  width: min(680px, 100%);
  padding: 38px;
  border: 0.5px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  background: rgba(23,26,33,0.88);
  box-shadow: 0 24px 70px rgba(0,0,0,0.34);
}

.startup-character {
  width: 106px;
  height: 106px;
  overflow: hidden;
  border-radius: 28px;
  margin-bottom: 16px;
  background: rgba(255,255,255,0.06);
  border: 0.5px solid rgba(255,255,255,0.14);
  box-shadow: 0 16px 38px rgba(240,166,202,0.13);
}
.startup-character img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.startup-kicker,
.eyebrow,
.section-kicker,
.idea-topline,
.focus-label {
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.startup-panel h1 {
  margin-top: 10px;
  font-family: var(--serif);
  font-size: clamp(34px, 6vw, 62px);
  line-height: 0.98;
  letter-spacing: 0;
  max-width: 620px;
}

.startup-panel p {
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.7;
  margin: 18px 0 26px;
  max-width: 560px;
}

.startup-login {
  max-width: 520px;
}
.startup-login label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.startup-login-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}
.startup-login input {
  min-width: 0;
  height: 43px;
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  padding: 0 12px;
  font-family: var(--sans);
  outline: none;
}
.startup-login input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.startup-login.authenticated-start label,
.startup-login.authenticated-start input {
  display: none;
}
.startup-login.authenticated-start .startup-login-row {
  display: flex;
}
.login-error {
  min-height: 18px;
  margin-top: 8px;
  color: var(--red);
  font-size: 12px;
}

.primary-action,
.ghost-action,
.danger-action,
.mini-btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--sans);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  touch-action: manipulation;
}

.primary-action {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #171a21;
  font-weight: 800;
  padding: 12px 18px;
  font-size: 13px;
}

.primary-action.small {
  padding: 9px 16px;
}

.ghost-action,
.danger-action,
.mini-btn {
  background: var(--surface2);
  border: 0.5px solid var(--border2);
  color: var(--text-2);
  padding: 10px 14px;
  font-size: 13px;
}

.danger-action {
  color: var(--red);
  background: var(--red-dim);
  border-color: rgba(248,113,113,0.22);
}

.mini-btn {
  padding: 5px 10px;
  font-size: 11px;
}

.primary-action:hover,
.ghost-action:hover,
.danger-action:hover,
.mini-btn:hover {
  transform: translateY(-1px);
}

.nav-badge {
  margin-left: auto;
  min-width: 22px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.08);
  color: var(--text-2);
  font-size: 11px;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5,7,10,0.72);
}

.hidden-modal {
  display: none;
}

.modal-card {
  width: 620px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
  background: var(--surface);
  border: 0.5px solid var(--border2);
  border-radius: 12px;
}

.modal-title {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--text);
}

.modal-copy {
  margin: 8px 0 16px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.65;
}

.modal-copy a {
  color: var(--accent);
}

.modal-hint {
  margin: 8px 0 14px;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.5;
}

.select-input,
.text-input {
  width: 100%;
  min-height: 42px;
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  padding: 0 11px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
}

.select-input:focus,
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.settings-card {
  width: min(900px, 95vw);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field span {
  color: var(--text-3);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-field small {
  min-height: 16px;
  color: var(--text-3);
  font-size: 11px;
}

.settings-danger-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border: 0.5px solid rgba(248,113,113,0.2);
  border-radius: 8px;
  background: rgba(248,113,113,0.07);
}

.danger-title {
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-danger-zone p {
  margin-top: 5px;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
}

.danger-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.script-box {
  position: relative;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: 8px;
}

.script-label,
.field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.script-box pre {
  max-height: 210px;
  overflow: auto;
  margin: 0;
  padding-right: 82px;
  color: var(--teal);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.script-copy {
  position: absolute;
  top: 12px;
  right: 12px;
}

.json-input {
  width: 100%;
  height: 128px;
  resize: vertical;
  outline: none;
  padding: 11px;
  border: 0.5px solid var(--border2);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.inline-status {
  min-height: 20px;
  margin-top: 8px;
  font-size: 12px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.briefing-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 16px;
  align-items: stretch;
}

.briefing-copy,
.focus-panel,
.workflow-panel,
.idea-card,
.hashtag-pack {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
}

.briefing-copy {
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(240,166,202,0.09), rgba(121,216,194,0.07)),
    var(--surface);
}

.briefing-copy h1 {
  margin: 10px 0 12px;
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1;
  letter-spacing: 0;
}

.briefing-copy p {
  max-width: 720px;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.7;
}

.briefing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.focus-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.focus-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.25;
}

.focus-description,
.focus-proof,
.workflow-panel p,
.idea-card p,
.hashtag-pack p {
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.6;
}

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

.focus-meta span,
.focus-hashtags span,
.pack-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--text-2);
  font-size: 11px;
  border: 0.5px solid var(--border);
}

.focus-hashtags,
.pack-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.workflow-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.6fr);
  gap: 12px;
}

.workflow-panel {
  padding: 16px;
}

.section-head.compact {
  margin-bottom: 14px;
}

.planner-grid {
  display: grid;
  gap: 8px;
}

.plan-item {
  display: grid;
  grid-template-columns: 62px 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
}

.plan-day {
  color: var(--gold);
  font-weight: 800;
  font-size: 12px;
}

.plan-step {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(240,166,202,0.13);
  color: var(--accent);
  font-weight: 800;
  font-size: 12px;
}

.plan-label {
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.plan-headline {
  margin: 2px 0 3px;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}

.quality-score {
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 48px;
  line-height: 1;
  color: var(--accent);
}

.quality-bar {
  height: 8px;
  overflow: hidden;
  margin: 14px 0 12px;
  border-radius: 999px;
  background: var(--surface2);
}

.quality-bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--teal));
  transition: width 0.35s ease;
}

.idea-grid,
.hashtag-studio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.idea-card,
.hashtag-pack {
  padding: 15px;
}

.idea-card h3 {
  margin: 8px 0 4px;
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0;
}

.idea-card strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 13px;
}

.pack-name {
  margin-bottom: 10px;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}

.hashtag-pack p {
  margin-top: 10px;
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .main {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .content,
  body.chat-expanded .content {
    display: flex;
    flex-direction: column;
    flex: none;
    height: auto;
    min-height: auto;
    overflow: visible;
  }

  .dashboard {
    flex: none;
    overflow: visible;
  }

  .chat-panel { min-height: 620px; }
}

@media (max-width: 900px) {
  .briefing-hero,
  .workflow-grid {
    grid-template-columns: 1fr;
  }

  .idea-grid,
  .hashtag-studio,
  .platform-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .startup-panel {
    padding: 28px 22px;
  }

  .startup-login-row {
    grid-template-columns: 1fr;
  }

  .chat-fab {
    right: 14px;
    bottom: 14px;
  }

  .briefing-copy,
  .focus-panel,
  .workflow-panel {
    padding: 16px;
  }

  .plan-item {
    grid-template-columns: 1fr;
  }

  .idea-grid,
  .hashtag-studio,
  .platform-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-danger-zone {
    grid-template-columns: 1fr;
  }

  .danger-grid {
    justify-content: flex-start;
  }

  .modal-card {
    padding: 18px;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    display: block;
    overflow-y: auto;
    background: var(--bg);
  }

  .main {
    width: 100%;
    min-height: 100svh;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    gap: 7px;
    padding: 9px 12px;
    background: rgba(23,26,33,0.96);
    backdrop-filter: blur(14px);
  }

  .topbar-title {
    flex: 1 1 calc(100% - 44px);
    font-size: 16px;
  }

  .sync-btn {
    flex: 1 1 calc(50% - 6px);
    min-height: 38px;
    padding: 8px 10px;
  }

  #syncBtn {
    display: none;
  }

  .status-pill {
    flex: 1 1 100%;
    justify-content: center;
    min-height: 30px;
    padding: 4px 10px;
  }

  .dashboard {
    padding: 12px 12px 88px;
    gap: 14px;
  }

  .briefing-hero,
  .workflow-grid,
  .idea-grid,
  .hashtag-studio,
  .platform-grid,
  .insights-grid {
    grid-template-columns: 1fr;
  }

  .briefing-copy {
    padding: 18px;
  }

  .briefing-copy h1 {
    font-size: clamp(30px, 10vw, 42px);
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card,
  .platform-card,
  .insight-card,
  .rec-card,
  .workflow-panel,
  .idea-card,
  .hashtag-pack {
    border-radius: 10px;
  }

  .platform-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .video-table-wrap {
    margin-inline: -12px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .video-table {
    min-width: 760px;
  }

  .video-title-cell {
    width: 260px;
  }

  .chat-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    height: min(78svh, 720px);
    min-height: 420px;
    border-top: 0.5px solid var(--border2);
    border-left: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -24px 60px rgba(0,0,0,0.42);
  }

  body.chat-expanded .chat-panel {
    top: 0;
    height: 100svh;
    border-radius: 0;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .chat-messages {
    min-height: 0;
    padding: 14px 14px 18px;
  }

  .msg {
    max-width: 100%;
  }

  .msg-bubble {
    font-size: 14px;
    line-height: 1.58;
  }

  .chat-suggestions {
    padding-inline: 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .chip {
    white-space: nowrap;
    min-height: 34px;
  }

  .chat-input-area {
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  }

  .chat-fab {
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    min-height: 50px;
    box-shadow: 0 18px 50px rgba(0,0,0,0.48);
  }

  .sidebar {
    width: min(82vw, 310px);
    min-width: min(82vw, 310px);
  }

  .modal-shell {
    align-items: flex-end;
    padding: 10px;
  }

  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 88svh;
    border-radius: 16px 16px 8px 8px;
  }

  .settings-grid,
  .settings-danger-zone {
    grid-template-columns: 1fr;
  }

  .danger-grid,
  .modal-actions {
    justify-content: stretch;
  }

  .danger-grid > *,
  .modal-actions > * {
    flex: 1 1 100%;
  }
}

@media (max-width: 420px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .platform-metrics {
    grid-template-columns: 1fr;
  }

  .startup-overlay {
    padding: 12px;
  }

  .startup-panel {
    padding: 24px 18px;
    border-radius: 12px;
  }

  .startup-character {
    width: 86px;
    height: 86px;
    border-radius: 22px;
  }

  .startup-panel h1 {
    font-size: clamp(30px, 12vw, 42px);
  }
}
