:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --ink: #1a1a2e;
  --ink2: #64748b;
  --line: #e2e8f0;
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-light: #eef2ff;
  --brand-ink: #fff;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px -1px rgba(0,0,0,.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: "Assistant", "Heebo", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

body.review-mode {
  font-family: "Inter", "Assistant", "Heebo", system-ui, sans-serif;
}

body.has-lang-switch .dashboard,
body.has-lang-switch .wrap {
  padding-top: 72px;
}

body.has-lang-switch .page-center {
  padding-top: 84px;
}

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

.review-note {
  background: linear-gradient(135deg, #eef2ff 0%, #ffffff 100%);
  border: 1px solid #c7d2fe;
  border-radius: 14px;
  color: #312e81;
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.08);
}

.review-note strong {
  display: block;
  font-size: .95rem;
  margin-bottom: 4px;
}

.review-note p {
  font-size: .88rem;
  margin: 0;
}

.lang-switch {
  position: fixed;
  top: 14px;
  inset-inline-end: 14px;
  z-index: 30;
  display: inline-flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
}

.lang-switch button {
  border: none;
  background: transparent;
  color: var(--ink2);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}

.lang-switch button.active {
  background: var(--brand);
  color: #fff;
}

.onboarding-logout {
  position: fixed;
  top: 14px;
  inset-inline-start: 14px;
  z-index: 30;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink2);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.onboarding-logout:hover { color: var(--danger, #dc2626); border-color: var(--danger, #dc2626); }

/* ── Page Center (auth) ── */
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 440px;
}

.auth-card .logo { text-align: center; margin-bottom: 28px; }
.auth-card .logo h1 { font-size: 2.4rem; font-weight: 800; color: var(--brand); letter-spacing: -.01em; line-height: 1; margin: 0; }
.auth-card .logo .brand-sub { color: var(--ink2); font-size: .85rem; font-weight: 500; margin-top: 6px; letter-spacing: .02em; opacity: .85; }
.auth-card .logo .tagline { color: var(--ink2); font-size: .92rem; margin-top: 10px; }
.auth-card .logo p { color: var(--ink2); font-size: .92rem; margin-top: 4px; }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--ink2); font-size: .85rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.link-switch { text-align: center; margin-top: 16px; font-size: .9rem; color: var(--ink2); }
.link-switch a { cursor: pointer; font-weight: 600; }

/* ── Dashboard layout ── */
.dashboard {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.dash-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.dash-header h1 { font-size: 1.4rem; font-weight: 700; }
.dash-header .sub { color: var(--ink2); font-size: .88rem; margin-top: 2px; }

/* ── Tabs ── */
.tab-bar {
  display: flex; gap: 4px; background: var(--panel);
  border-radius: var(--radius); padding: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  margin-bottom: 20px; overflow-x: auto;
}
.tab-bar button {
  padding: 10px 20px; border: none; background: transparent;
  color: var(--ink2); font: inherit; font-weight: 600;
  border-radius: 8px; cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.tab-bar button.active { background: var(--brand); color: var(--brand-ink); }
.tab-bar button:hover:not(.active) { background: var(--brand-light); color: var(--brand); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat-card {
  background: var(--panel); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
  border: 1px solid var(--line); padding: 20px; text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--brand); line-height: 1.2; }
.stat-card .stat-label { font-size: .82rem; color: var(--ink2); margin-top: 4px; }
.stat-card.highlight { background: var(--brand-light); border-color: var(--brand); }
.stat-card.highlight .stat-value { color: var(--brand); }

/* ── Forms ── */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: .9rem; }
label .label-text { display: block; margin-bottom: 6px; }

input, select, textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 14px; background: #fff; color: var(--ink);
  font: inherit; font-size: .95rem;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); text-decoration: none;
  cursor: pointer; padding: 10px 18px; font-weight: 600; font-size: .9rem;
  font-family: inherit;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink2); }
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 24px; font-size: 1rem; border-radius: var(--radius); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions-spaced { margin-top: 10px; }

/* ── Toggle ── */
.toggle-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.toggle-label { font-weight: 600; font-size: .95rem; }
.toggle-desc { font-size: .82rem; color: var(--ink2); }

.toggle { position: relative; width: 52px; height: 28px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle .slider {
  position: absolute; inset: 0; background: #cbd5e1;
  border-radius: 14px; cursor: pointer; transition: background .15s;
}
.toggle .slider::before {
  content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; top: 3px; right: 3px; transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.toggle input:checked + .slider { background: var(--brand); }
.toggle input:checked + .slider::before { transform: translateX(-24px); }

#scanToggleCard.scan-off { border: 1px solid var(--danger); background: var(--danger-light); }
#scanToggleCard.scan-off .toggle-label { color: var(--danger); }

/* ── Audience card ── */
.muted-text { font-size: .85rem; color: var(--ink2); margin: 0 0 12px; }
.audience-status { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.audience-badge {
  display: inline-block; background: var(--success-light, #dcfce7);
  color: var(--success, #16a34a); padding: 4px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 600;
}
.adset-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.adset-list {
  display: grid; gap: 6px; max-height: 360px; overflow-y: auto;
  padding: 4px; border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px; background: var(--surface-2, #f8fafc); margin-bottom: 12px;
}
.adset-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  background: #fff; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; transition: border-color .15s;
}
.adset-row:hover { border-color: var(--brand); }
.adset-row.checked { border-color: var(--brand); background: var(--brand-light); }
.adset-row input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; accent-color: var(--brand); }
.adset-text { flex: 1; min-width: 0; }
.adset-title { font-weight: 600; font-size: .9rem; }
.adset-meta { font-size: .78rem; color: var(--ink2); margin-top: 2px; }

/* ── Settings: prompt mode tabs ── */
.prompt-mode-tabs {
  display: inline-flex; gap: 4px; background: var(--surface-2, #f1f5f9);
  border-radius: 999px; padding: 4px; margin: 18px 0 12px;
}
.mode-tab {
  border: 0; background: transparent; padding: 8px 18px; border-radius: 999px;
  cursor: pointer; font-size: .9rem; font-weight: 500; color: var(--ink2);
  transition: background .15s, color .15s;
}
.mode-tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.mode-panel { margin-top: 8px; }

.field-group { display: block; margin-bottom: 20px; }
.field-group .label-text { font-weight: 600; font-size: .95rem; display: block; }
.field-group .label-hint {
  font-size: .82rem; color: var(--ink2); display: block; margin-top: 2px; margin-bottom: 10px;
}

/* ── Category cards ── */
.category-list { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 720px) { .category-list { grid-template-columns: 1fr 1fr; } }
.category-card {
  display: flex; align-items: flex-start; gap: 12px;
  border: 2px solid var(--line); border-radius: 12px;
  padding: 14px 16px; cursor: pointer;
  transition: border-color .15s, background .15s;
  background: #fff; min-width: 0;
}
.category-card:hover { border-color: var(--brand); }
.category-card.checked { border-color: var(--brand); background: var(--brand-light); }
.category-card input[type="checkbox"] {
  width: 18px; height: 18px; margin: 2px 0 0;
  flex: 0 0 auto; accent-color: var(--brand);
}
.cat-text { flex: 1 1 auto; min-width: 0; }
.cat-title {
  font-weight: 600; font-size: .95rem; color: var(--ink);
  line-height: 1.4; word-break: break-word;
}
.cat-desc {
  font-size: .82rem; color: var(--ink2); margin-top: 4px;
  line-height: 1.5; word-break: break-word;
}

/* ── Sensitivity gauge ── */
.gauge {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  margin-top: 4px;
}
.gauge-step {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 6px; border-radius: 12px; cursor: pointer;
  background: #fff; border: 2px solid var(--border, #e5e7eb);
  color: var(--ink2); font: inherit;
  transition: transform .12s ease, border-color .12s ease, background .12s ease, color .12s ease;
}
.gauge-step:hover { border-color: var(--brand); color: var(--ink); transform: translateY(-1px); }
.gauge-step.active {
  border-color: var(--brand); background: var(--brand-light);
  color: var(--brand); font-weight: 600;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .12);
}
.gauge-icon { font-size: 1.6rem; line-height: 1; }
.gauge-name { font-size: .78rem; text-align: center; line-height: 1.2; }
@media (max-width: 540px) {
  .gauge { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .gauge-step { padding: 8px 2px; }
  .gauge-icon { font-size: 1.3rem; }
  .gauge-name { font-size: .68rem; }
}

/* ── Status Messages ── */
.status-msg {
  padding: 12px 16px; border-radius: 10px; font-size: .9rem;
  font-weight: 500; margin-bottom: 16px; display: none;
}
.status-msg.visible { display: block; }
.status-msg.info { background: var(--brand-light); color: var(--brand); }
.status-msg.success { background: var(--success-light); color: var(--success); }
.status-msg.error { background: var(--danger-light); color: var(--danger); }
.status-msg.warning { background: var(--warning-light); color: var(--warning); }

/* ── Badges ── */
.badge {
  display: inline-flex; padding: 3px 10px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; text-transform: uppercase;
}
.badge.pending { background: var(--warning-light); color: var(--warning); }
.badge.approved, .badge.active { background: var(--success-light); color: var(--success); }
.badge.rejected { background: var(--danger-light); color: var(--danger); }

/* ── Items ── */
.item-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; background: #fff; transition: box-shadow .15s;
}
.item-card:hover { box-shadow: var(--shadow); }
.item-card + .item-card { margin-top: 8px; }
.item-card .item-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 6px; flex-wrap: wrap;
}
.item-card .item-header h3 { font-size: .95rem; margin: 0; }
.item-card .meta { font-size: .82rem; color: var(--ink2); margin-bottom: 2px; }
.meta-subtle { font-weight: 400; color: var(--ink2); font-size: .85rem; }
.meta-tight { margin-top: 4px; }
.error-meta { margin-top: 6px; color: #b42318; }
.error-comment-context { color: var(--ink2); }
.token-expired-flag { color: #e53e3e; font-weight: 600; }

.error-panel {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafafa;
}
.error-panel-title { font-weight: 700; margin-bottom: 6px; }

.comment-text { font-size: .95rem; margin-bottom: 8px; line-height: 1.5; }
.comment-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: .82rem; color: var(--ink2); }
.comment-error { color: #c21f2f; }
.delete-comment-btn {
  color: #c21f2f !important;
  margin-inline-start: auto;
}

/* ── Pending Screen ── */
.pending-screen { text-align: center; padding: 48px 24px; }
.pending-screen .icon { font-size: 4rem; margin-bottom: 16px; }
.pending-screen h2 { font-size: 1.4rem; margin-bottom: 8px; }
.pending-screen p { color: var(--ink2); max-width: 380px; margin: 0 auto 24px; font-size: .95rem; }

/* ── Connect Asset Screen ── */
.connect-screen { text-align: center; padding: 40px 20px; }
.connect-screen .icon { font-size: 3rem; margin-bottom: 12px; }
.connect-screen h2 { font-size: 1.3rem; margin-bottom: 8px; }
.connect-screen p { color: var(--ink2); margin-bottom: 20px; }

/* ── Empty state ── */
.empty { text-align: center; padding: 40px 20px; color: var(--ink2); }
.empty .icon { font-size: 2.5rem; margin-bottom: 8px; }

/* ── Banner ── */
.banner {
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: .9rem; flex-wrap: wrap;
}
.banner.warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(217,119,6,.2); }
.banner.danger { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(220,38,38,.25); font-weight: 500; }

.skip-link { display: block; text-align: center; margin-top: 12px; font-size: .88rem; color: var(--ink2); text-decoration: underline; }
.skip-link:hover { color: var(--ink); }

/* ── Stepper ── */
.stepper {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 16px 8px 8px;
  margin-bottom: 16px;
}
.stepper .step {
  flex: 1 1 0; display: flex; flex-direction: column; align-items: center;
  position: relative; min-width: 0;
}
.stepper .step + .step::before {
  content: ''; position: absolute; top: 16px;
  inset-inline-end: 50%; inset-inline-start: -50%;
  height: 2px; background: var(--line); z-index: 0;
}
.stepper .step.done + .step::before { background: var(--brand); }
.stepper .step .dot {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--ink2); font-size: .9rem;
  position: relative; z-index: 1;
}
.stepper .step.current .dot { border-color: var(--brand); color: var(--brand); }
.stepper .step.done .dot { background: var(--brand); border-color: var(--brand); color: #fff; }
.stepper .step.done .dot::after { content: '✓'; }
.stepper .step.done .dot span { display: none; }
.stepper .step .label {
  margin-top: 8px; font-size: .85rem; color: var(--ink2);
  text-align: center; line-height: 1.3;
}
.stepper .step.current .label { color: var(--ink); font-weight: 600; }

/* ── Asset picker sub-steps ── */
.picker-title {
  font-size: 1.05rem; font-weight: 700; color: var(--ink);
  margin: 4px 0 6px;
}
.picker-sub {
  color: var(--ink2); font-size: .88rem; line-height: 1.5;
  margin: 0 0 14px;
}
.picker-actions {
  display: flex; gap: 10px; align-items: center; margin-top: 4px;
}
.picker-actions .btn.primary { flex: 1; }
.picker-actions .btn.ghost { flex: 0 0 auto; }

.wizard-panel { display: block; }
.onboarding-success-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--success, #10b981); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; margin: 0 auto 16px;
  box-shadow: 0 6px 20px rgba(16, 185, 129, .25);
}
.warn-triangle {
  display: inline-block;
  color: #dc2626;
  font-size: 0.85em;
  margin-inline-end: 6px;
  transform: translateY(-1px);
}

/* ── Asset Cards ── */
.asset-cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px; margin-top: 8px; max-height: 320px; overflow-y: auto;
  padding: 4px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg);
}
.asset-card {
  position: relative;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--panel); border: 2px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: border-color .15s, transform .05s, box-shadow .15s;
}
.asset-card:hover { border-color: #c7d2fe; background: #fafbff; }
.asset-card.selected {
  border-color: var(--brand); background: var(--brand-light);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .18);
}
.asset-card.selected::after {
  content: '✓';
  position: absolute; top: 6px; inset-inline-start: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.asset-card .avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--line);
  flex-shrink: 0; object-fit: cover;
}
.asset-card .avatar-placeholder {
  width: 44px; height: 44px; border-radius: 50%; background: var(--brand-light);
  color: var(--brand); display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.asset-card .info { min-width: 0; flex: 1; }
.asset-card .info .name {
  font-weight: 600; font-size: .95rem; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asset-card .info .meta {
  font-size: .8rem; color: var(--ink2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asset-search {
  width: 100%; padding: 8px 12px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.asset-cards-empty {
  grid-column: 1 / -1; text-align: center; color: var(--ink2);
  padding: 24px; font-size: .9rem;
}
.load-more-assets {
  display: block; width: 100%; margin: 8px 0 16px;
}

/* ── Connected header (replaces hero after FB connect) ── */
.connected-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--success-light, #dcfce7);
  border: 1px solid rgba(22,163,74,.25);
  border-radius: var(--radius);
}
.connected-header .connected-icon {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--success, #16a34a); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0;
}
.connected-header .connected-text {
  display: flex; align-items: baseline; gap: 12px; flex: 1;
  flex-wrap: wrap;
}
.connected-header .connected-text strong { color: var(--success, #16a34a); }
.connected-header .connected-switch {
  font-size: .82rem; color: var(--ink2); text-decoration: underline;
}
.connected-header .connected-switch:hover { color: var(--brand); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .auth-card { padding: 28px 20px; }
  .dashboard { padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-header { flex-direction: column; align-items: stretch; }
  body.has-lang-switch .dashboard,
  body.has-lang-switch .wrap {
    padding-top: 84px;
  }
  body.has-lang-switch .page-center {
    padding-top: 96px;
  }
}
