:root {
  --bg: #0b1020;
  --bg-2: #0f172a;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e6e9f5;
  --muted: #9aa5c7;
  --primary: #8b5cf6;
  --primary-2: #ec4899;
  --accent: #22d3ee;
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.15);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245, 158, 11, 0.15);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.15);
  --purple-bg: rgba(139, 92, 246, 0.15);
  --blue-bg: rgba(59, 130, 246, 0.15);
  --radius: 16px;
  --shadow: 0 10px 40px -15px rgba(0, 0, 0, 0.55);
  --gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 50%, #f59e0b 100%);
  --sidebar-w: 280px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb;
    --bg-2: #ffffff;
    --surface: rgba(15, 23, 42, 0.03);
    --surface-2: rgba(15, 23, 42, 0.06);
    --border: rgba(15, 23, 42, 0.09);
    --border-strong: rgba(15, 23, 42, 0.15);
    --text: #0f172a;
    --muted: #5c6479;
    --shadow: 0 10px 30px -15px rgba(15, 23, 42, 0.18);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at -10% -20%, rgba(139, 92, 246, 0.25), transparent 60%),
    radial-gradient(900px 600px at 110% 0%, rgba(236, 72, 153, 0.2), transparent 60%),
    radial-gradient(800px 500px at 50% 120%, rgba(34, 211, 238, 0.18), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  font-size: 14px;
}

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

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--gradient);
  box-shadow: var(--shadow);
  font-size: 22px;
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.nav { display: flex; flex-direction: column; gap: 4px; padding: 4px 0 24px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 12px;
  color: var(--muted); text-decoration: none;
  font-weight: 500; transition: all 0.15s ease;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(139,92,246,0.22), rgba(236,72,153,0.12));
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
.nav-icon { width: 20px; text-align: center; }

.connector-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.connector-title { font-weight: 700; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.connector-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.connector-row > span:nth-child(2) { flex: 1; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); opacity: 0.7;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
}
.dot.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); animation: pulse 2s infinite; }
.dot.red { background: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }
.dot.yellow { background: var(--yellow); box-shadow: 0 0 0 3px var(--yellow-bg); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-bg); }
  50% { box-shadow: 0 0 0 5px var(--green-bg); }
}

/* Content */
.content { padding: 32px 40px 60px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; padding-bottom: 28px; border-bottom: 1px solid var(--border); margin-bottom: 28px;
  flex-wrap: wrap;
}
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 600; }
.title { margin: 4px 0 0; font-size: 28px; letter-spacing: -0.02em; font-weight: 800; }
.topbar-actions { display: flex; gap: 12px; align-items: flex-end; }
.range { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 600;
  cursor: pointer; transition: all 0.15s ease; font-family: inherit; font-size: 14px;
}
.btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.btn.primary {
  background: var(--gradient);
  border-color: transparent;
  color: white;
  box-shadow: var(--shadow);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn.ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface); }
.btn.danger-ghost {
  background: transparent;
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.25);
}
.btn.danger-ghost:hover { background: var(--red-bg); border-color: var(--red); color: #fecaca; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; filter: none; }

.select, .input {
  padding: 9px 12px; border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-family: inherit; font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
  min-width: 160px;
}
.select:focus, .input:focus { border-color: var(--primary); }

.chip {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.chip.small { padding: 2px 8px; font-size: 11px; }
.chip.red { background: var(--red-bg); color: #fca5a5; border-color: transparent; }
.chip.green { background: var(--green-bg); color: #6ee7b7; border-color: transparent; }
.chip.yellow { background: var(--yellow-bg); color: #fcd34d; border-color: transparent; }
.chip.purple { background: var(--purple-bg); color: #c4b5fd; border-color: transparent; }
.chip.blue { background: var(--blue-bg); color: #93c5fd; border-color: transparent; }
.chip.positive { background: var(--green-bg); color: #6ee7b7; border-color: transparent; }
.chip.negative { background: var(--red-bg); color: #fca5a5; border-color: transparent; }
.chip.neutral { background: var(--blue-bg); color: #93c5fd; border-color: transparent; }
.chip.mixed { background: var(--yellow-bg); color: #fcd34d; border-color: transparent; }

.panel-section { margin-bottom: 48px; scroll-margin-top: 20px; }
.section-header { margin-bottom: 20px; }
.section-header h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.muted.small { font-size: 12px; }
.small { font-size: 12px; }

/* KPI */
.kpi-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  margin-bottom: 28px;
}
.kpi-card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--gradient);
  opacity: 0.9;
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 30px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-delta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.kpi-delta.up::before { content: "▲"; color: var(--green); font-size: 10px; }
.kpi-delta.down::before { content: "▼"; color: var(--red); font-size: 10px; }
.kpi-delta.neutral::before { content: "●"; color: var(--accent); font-size: 8px; }
.kpi-card.sentiment::before { background: linear-gradient(90deg, #10b981, #3b82f6); }
.kpi-card.complaints::before { background: linear-gradient(90deg, #ef4444, #f59e0b); }
.kpi-card.features::before { background: linear-gradient(90deg, #8b5cf6, #22d3ee); }
.kpi-card.bugs::before { background: linear-gradient(90deg, #f59e0b, #ef4444); }

/* Card / Chart */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card-header h3 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.chart-wrap { height: 260px; position: relative; }
.chart-wrap.tall { height: 340px; }
.chart-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.chart-grid .wide { grid-column: 1 / -1; }
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }

/* Lists + tables */
.list-table { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow: auto; }
.list-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  padding: 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  transition: background 0.15s ease;
}
.list-row:hover { background: rgba(139, 92, 246, 0.08); }
.list-count {
  width: 40px; display: grid; place-items: center;
  background: var(--gradient); color: white;
  border-radius: 10px; font-weight: 800;
  align-self: start;
  min-height: 40px;
}
.list-name { font-weight: 700; margin-bottom: 4px; }
.list-examples { display: flex; flex-direction: column; gap: 6px; }
.quote {
  padding: 8px 10px; border-radius: 10px;
  background: var(--surface); border: 1px dashed var(--border-strong);
  color: var(--text); font-size: 13px;
}
.quote:hover { border-style: solid; border-color: var(--primary); }
.empty {
  padding: 24px; text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 12px;
}

.mt24 { margin-top: 24px; }
.mb16 { margin-bottom: 16px; }

.table-wrap { overflow: auto; max-height: 520px; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table thead th {
  position: sticky; top: 0;
  background: var(--bg-2); z-index: 1;
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700;
}
.table tbody td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; }
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }

/* Brief */
.brief-actions { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.brief-card { padding: 28px; }
.brief-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.brief-head h3 { margin: 4px 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.brief-stats { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.brief-body.markdown h4 { margin: 24px 0 10px; font-size: 14px; color: var(--primary); letter-spacing: 0.04em; text-transform: uppercase; }
.brief-body.markdown h4:first-child { margin-top: 0; }
.brief-body.markdown p { margin: 0 0 12px; color: var(--text); }
.brief-body.markdown ul { margin: 0 0 16px 20px; padding: 0; }
.brief-body.markdown li { margin: 4px 0; }
.brief-body.markdown strong { background: var(--purple-bg); padding: 1px 5px; border-radius: 4px; }
.brief-body .empty-brief { color: var(--muted); text-align: center; padding: 40px; border: 1px dashed var(--border); border-radius: 12px; }

/* Pipeline */
.pipeline-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid label.span-2 { grid-column: span 2; }
.form-grid .input, .form-grid .select { min-width: 0; }
.action-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.footer {
  margin-top: 60px; padding-top: 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; font-size: 12px;
}

/* Toast */
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 99;
  padding: 12px 16px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600;
  max-width: 360px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
.toast.error { background: var(--red-bg); border-color: transparent; color: #fecaca; }
.toast.success { background: var(--green-bg); border-color: transparent; color: #bbf7d0; }

/* Spinner */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}
.spinner.inline { vertical-align: -3px; }
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .pipeline-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .content { padding: 24px 20px 40px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Instagram connection gate / notices ---------- */
.notice { border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.45; margin-bottom: 16px; }
.notice.warn { background: var(--yellow-bg); color: #fcd34d; }
.notice.error { background: var(--red-bg); color: #fca5a5; }
.notice.info { background: var(--blue-bg); color: #93c5fd; }
.notice.ok { background: var(--green-bg); color: #6ee7b7; }
.ig-gate { max-width: 720px; }
.ig-gate h2 { margin: 4px 0 8px; }
.ig-gate.problem { border-color: var(--red); }
.code-input { font-size: 20px; letter-spacing: 0.3em; text-align: center; }
.form-grid .span-2 { grid-column: span 2; }
.btn.small-btn { padding: 6px 10px; font-size: 12px; }
/* No Instagram connected yet: only the connect panel is shown */
body.ig-not-connected .panel-section:not(#instagram-gate),
body.ig-not-connected .topbar-actions { display: none; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.ig-alt { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.ig-alt h3 { margin: 0 0 6px; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.ig-howto { margin: 10px 0 14px; font-size: 13px; color: var(--muted); }
.ig-howto summary { cursor: pointer; color: var(--text); font-weight: 600; }
.ig-howto ol { margin: 10px 0 0; padding-left: 20px; line-height: 1.6; }
.ig-challenge img { width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; border: 1px solid var(--border); background: #fff; margin-bottom: 10px; }
.ig-challenge-options { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.ig-challenge-options .btn { padding: 6px 12px; font-size: 13px; }
#ig-challenge-texts div { margin: 2px 0; }
#ig-challenge-shot { cursor: crosshair; }
#ig-shot-hint { margin-bottom: 8px; color: var(--text); }
