/* ============================================================================
   REVAMP DESIGN SYSTEM
   Single source of truth for every surface in the platform.

   Structure:
     1. Tokens          - palette, type, space, radius, elevation, motion
     2. Compatibility   - legacy short aliases (--bg, --text2, --red, ...)
     3. Base            - reset, typography, focus, scrollbars
     4. Layout          - app shell, header, nav, sections, grids
     5. Components      - buttons, cards, stats, tables, badges, forms,
                          toasts, modals, tabs, skeletons, empty/error states
     6. Utilities       - spacing, text, visibility helpers
     7. Responsive      - breakpoints
     8. Themes          - dark mode, reduced motion, print

   Conventions:
     - Never hardcode a colour in a page; use a token.
     - Every interactive element needs a visible :focus-visible ring.
     - Wide content scrolls inside its own container, never the page body.
   ========================================================================= */

/* ==========================================================================
   1. TOKENS
   ========================================================================== */

:root {
  color-scheme: light;

  /* ── Brand ramp: Revamp red ───────────────────────────────────────────── */
  --brand-50:  #fef3f2;
  --brand-100: #fee4e2;
  --brand-200: #fecdca;
  --brand-300: #fda29b;
  --brand-400: #f97066;
  --brand-500: #f04438;
  --brand-600: #d92d20;
  --brand-700: #b42318;
  --brand-800: #912018;
  --brand-900: #7a271a;

  /* ── Ink ramp: warm neutral, not pure grey ───────────────────────────── */
  --ink-25:  #fdfcfb;
  --ink-50:  #faf7f4;
  --ink-100: #f3ece3;
  --ink-200: #e7ded3;
  --ink-300: #cfc4b6;
  --ink-400: #a39687;
  --ink-500: #7a6f63;
  --ink-600: #5d564f;
  --ink-700: #423d38;
  --ink-800: #2a2622;
  --ink-900: #1d1916;

  /* ── Accent + status ─────────────────────────────────────────────────── */
  --indigo-500: #6172f3;
  --indigo-600: #444ce7;
  --teal-600:   #0f766e;

  --green-50:  #ecfdf3;
  --green-500: #12b76a;
  --green-600: #0f9f6e;
  --amber-50:  #fffaeb;
  --amber-500: #f79009;
  --amber-600: #c27c11;
  --red-50:    #fef3f2;
  --red-600:   #d92d20;
  --blue-50:   #eff8ff;
  --blue-600:  #1570ef;

  /* ── Semantic surfaces ───────────────────────────────────────────────── */
  --bg-primary:   #f6f2ec;
  --bg-secondary: rgba(255, 255, 255, 0.92);
  --bg-tertiary:  #f3ece3;
  --bg-raised:    #ffffff;
  --bg-sunken:    #ece4da;
  --bg-inverse:   var(--ink-900);

  --border-light:  rgba(16, 24, 40, 0.07);
  --border-medium: rgba(16, 24, 40, 0.14);
  --border-strong: rgba(16, 24, 40, 0.24);

  --text-primary:   var(--ink-900);
  --text-secondary: var(--ink-600);
  --text-tertiary:  var(--ink-400);
  --text-inverse:   #ffffff;
  --text-on-brand:  #ffffff;

  --accent-primary:   var(--brand-600);
  --accent-secondary: var(--indigo-600);
  --accent-tertiary:  #f97316;

  --success:    var(--green-600);
  --success-bg: var(--green-50);
  --warning:    var(--amber-600);
  --warning-bg: var(--amber-50);
  --error:      var(--red-600);
  --error-bg:   var(--red-50);
  --info:       var(--blue-600);
  --info-bg:    var(--blue-50);

  /* ── Type ────────────────────────────────────────────────────────────── */
  --font-sans: "Raleway", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Roboto Condensed", "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;

  --text-xs:   0.6875rem;  /* 11 */
  --text-sm:   0.8125rem;  /* 13 */
  --text-base: 0.9375rem;  /* 15 */
  --text-md:   1.0625rem;  /* 17 */
  --text-lg:   1.25rem;    /* 20 */
  --text-xl:   1.5rem;     /* 24 */
  --text-2xl:  1.875rem;   /* 30 */
  --text-3xl:  2.25rem;    /* 36 */
  --text-4xl:  3rem;       /* 48 */

  --leading-tight:  1.2;
  --leading-snug:   1.4;
  --leading-normal: 1.6;

  --tracking-tight: -0.02em;
  --tracking-wide:  0.08em;

  /* ── Space (4px base) ────────────────────────────────────────────────── */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* ── Radius ──────────────────────────────────────────────────────────── */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-full: 999px;

  /* ── Elevation ───────────────────────────────────────────────────────── */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 4px 12px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 12px 32px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.12);
  --shadow-xl: 0 32px 80px rgba(16, 24, 40, 0.16);

  /* ── Motion ──────────────────────────────────────────────────────────── */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 120ms;
  --duration-base: 220ms;
  --duration-slow: 380ms;
  --transition: all var(--duration-base) var(--ease);

  /* ── Focus ───────────────────────────────────────────────────────────── */
  --focus-ring: 0 0 0 3px rgba(217, 45, 32, 0.32);

  /* ── Layout ──────────────────────────────────────────────────────────── */
  --container: 1240px;
  --container-wide: 1400px;
  --header-height: 72px;
}

/* ==========================================================================
   2. COMPATIBILITY ALIASES
   Short names used by existing page markup. Keeping them here means a page
   can drop its private :root block and inherit the system unchanged.
   ========================================================================== */

:root {
  --bg:       var(--bg-primary);
  --surface:  var(--bg-secondary);
  --surface2: var(--bg-tertiary);
  --surface3: var(--bg-sunken);
  --border:   var(--border-light);
  --border2:  var(--border-medium);
  --text:     var(--text-primary);
  --text2:    var(--text-secondary);
  --text3:    var(--text-tertiary);
  --muted:    var(--text-tertiary);
  --accent:   var(--accent-primary);
  --accent2:  var(--accent-secondary);
  --green:    var(--success);
  --amber:    var(--warning);
  --red:      var(--error);
  --teal:     var(--info);
  --font:     var(--font-sans);
  --mono:     var(--font-mono);
  --radius:   var(--radius-lg);
  --shadow:   var(--shadow-md);
}

/* ==========================================================================
   3. BASE
   ========================================================================== */

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background:
    radial-gradient(ellipse 80% 50% at 15% -5%, rgba(217, 45, 32, 0.07), transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 0%, rgba(68, 76, 231, 0.05), transparent 60%),
    linear-gradient(180deg, #fbf8f4 0%, var(--bg-primary) 45%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  font-weight: 700;
  color: var(--text-primary);
  text-wrap: balance;
}

h1 { font-size: var(--text-3xl); font-weight: 800; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p { text-wrap: pretty; }

a { color: var(--accent-primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--brand-700); }

img, svg, video { max-width: 100%; height: auto; display: block; }

/* Visible focus for keyboard users on every interactive element. */
:where(a, button, input, select, textarea, [tabindex], [role="button"]):focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:where(a, button, [role="button"]):focus:not(:focus-visible) { outline: none; }

::selection { background: var(--brand-100); color: var(--brand-900); }

/* Screen-reader-only content that still receives focus. */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--space-4); top: -60px;
  z-index: 2000; padding: var(--space-3) var(--space-5);
  background: var(--bg-raised); color: var(--text-primary);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-weight: 700; transition: top var(--duration-fast) var(--ease);
}
.skip-link:focus { top: var(--space-4); }

/* ==========================================================================
   4. LAYOUT
   ========================================================================== */

.app {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-10) var(--space-6) var(--space-20);
}
.app-wide { max-width: var(--container-wide); }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding-bottom: var(--space-6);
  margin-bottom: var(--space-8);
  border-bottom: 1px solid var(--border-light);
}

.brand { display: flex; align-items: center; gap: var(--space-3); }

.brand-logo {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.05em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}
.brand-logo:hover { color: var(--text-primary); }
.brand-logo span { color: var(--accent-primary); }

.brand-tagline {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.product-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: rgba(16, 24, 40, 0.04);
  padding: var(--space-1);
  border-radius: var(--radius-full);
}

.nav-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  transition: var(--transition);
}
.nav-chip:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.6); }
.nav-chip.active {
  background: var(--bg-raised);
  color: var(--accent-primary);
  box-shadow: var(--shadow-xs);
}

.section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-3);
}
.section-label { /* alias used by admin pages */
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-3);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page-head p { color: var(--text-secondary); margin-top: var(--space-2); }

.grid { display: grid; gap: var(--space-4); }
.grid-cols-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }

/* ==========================================================================
   5. COMPONENTS
   ========================================================================== */

/* ── Card ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: box-shadow var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease);
}
/* Stacked cards get separation; grid/flex children rely on the container gap
   so every tile in a row starts at the same baseline. */
.card { margin-bottom: var(--space-5); }
.grid > .card,
.stack > .card,
.section-grid > .card,
.results-grid > .card { margin-bottom: 0; }
.card-interactive { cursor: pointer; }
.card-interactive:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-5); flex-wrap: wrap;
}
.card-flush { padding: 0; overflow: hidden; }

/* ── Button ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--brand-600), var(--accent-tertiary));
  color: var(--text-on-brand);
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn-primary:active:not(:disabled) { transform: translateY(0); filter: brightness(0.96); }

.btn-secondary {
  background: var(--bg-raised);
  color: var(--text-secondary);
  border-color: var(--border-medium);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-primary); color: var(--accent-primary); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: rgba(16, 24, 40, 0.05); color: var(--text-primary); }

.btn-danger { background: transparent; color: var(--error); border-color: rgba(217, 45, 32, 0.28); }
.btn-danger:hover:not(:disabled) { background: var(--error-bg); }

.btn-sm { padding: var(--space-2) var(--space-3); min-height: 34px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn-lg { padding: var(--space-4) var(--space-8); min-height: 52px; font-size: var(--text-md); }
.btn-block { width: 100%; }

/* Inline spinner for pending buttons. */
.btn[data-loading="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[data-loading="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--text-on-brand);
  animation: spin 0.7s linear infinite;
}
.btn-secondary[data-loading="true"]::after,
.btn-ghost[data-loading="true"]::after { color: var(--text-secondary); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Stat tile ────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}
.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-2);
}
.stat-value, .stat-val {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.stat-delta { font-size: var(--text-sm); font-weight: 700; margin-top: var(--space-1); }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--error); }

/* ── Table ────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: var(--text-base); }
th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 2px solid var(--border-medium);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  background: var(--bg-secondary);
}
td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-light); vertical-align: middle; }
tbody tr { transition: background var(--duration-fast) var(--ease); }
tbody tr:hover td { background: var(--bg-tertiary); }
tbody tr:last-child td { border-bottom: none; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ── Badge ────────────────────────────────────────────────────────────── */
.badge, .status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-neutral, .status-inactive, .status-withdrawn { background: rgba(16, 24, 40, 0.06); color: var(--text-secondary); }
.badge-success, .status-active, .status-accepted, .status-completed { background: var(--success-bg); color: var(--success); }
.badge-warning, .status-pending { background: var(--warning-bg); color: var(--warning); }
.badge-error, .status-banned, .status-rejected, .status-closed { background: var(--error-bg); color: var(--error); }
.badge-info, .status-draft { background: var(--info-bg); color: var(--info); }

/* Influencer tiers — labels must match analytics.get_influencer_tier(). */
.tier-pill {
  display: inline-flex; align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 700; text-transform: capitalize;
}
.tier-nano  { background: #f3ece3; color: var(--ink-600); }
.tier-micro { background: var(--info-bg); color: var(--info); }
.tier-mid   { background: #ede9fe; color: #6d28d9; }
.tier-macro { background: var(--warning-bg); color: var(--warning); }
.tier-mega  { background: var(--brand-100); color: var(--brand-700); }

/* ── Forms ────────────────────────────────────────────────────────────── */
.field { display: grid; gap: var(--space-2); margin-bottom: var(--space-4); }
.label { font-size: var(--text-sm); font-weight: 700; color: var(--text-secondary); }
.hint { font-size: var(--text-sm); color: var(--text-tertiary); }
.field-error { font-size: var(--text-sm); color: var(--error); font-weight: 600; }

/* Inline validation messages sit as a sibling after their input. They are
   hidden until the field is actually invalid AND the user has interacted with
   it, so a pristine form does not open covered in red text. */
.form-error {
  display: none;
  font-size: var(--text-sm);
  color: var(--error);
  font-weight: 600;
  margin-top: var(--space-2);
}
input:user-invalid ~ .form-error,
select:user-invalid ~ .form-error,
textarea:user-invalid ~ .form-error,
.form-group.has-error .form-error { display: block; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="url"], input[type="tel"], input[type="date"],
select, textarea, .input, .filter-select, .search-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  transition: var(--transition);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: var(--focus-ring);
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--error);
}
textarea { min-height: 110px; resize: vertical; line-height: var(--leading-normal); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a6f63' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  padding-right: var(--space-10);
}
.filters { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-5); }
.filters-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }
.search-input { flex: 1; min-width: 220px; }

/* ── Tabs ─────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-8);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1;
  min-width: 120px;
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: var(--transition);
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  white-space: nowrap;
}
.tab:hover { background: rgba(255, 255, 255, 0.55); color: var(--text-primary); }
.tab.active { background: var(--bg-raised); color: var(--text-primary); box-shadow: var(--shadow-xs); }
.tab-badge {
  background: var(--accent-primary); color: var(--text-on-brand);
  font-size: var(--text-xs); padding: 2px var(--space-2);
  border-radius: var(--radius-full); font-weight: 700;
}

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; top: var(--space-5); right: var(--space-5);
  z-index: 1000; display: flex; flex-direction: column; gap: var(--space-2);
  max-width: min(400px, calc(100vw - var(--space-10)));
}
.toast {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: var(--space-3);
  animation: toast-in var(--duration-slow) var(--ease);
  border-left: 4px solid var(--text-tertiary);
  font-size: var(--text-base);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }
.toast.info    { border-left-color: var(--accent-secondary); }
@keyframes toast-in { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Banner ───────────────────────────────────────────────────────────── */
.banner {
  display: none;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
  font-weight: 600;
  font-size: var(--text-base);
}
.banner.show { display: block; }
.banner.success { background: var(--success-bg); color: var(--success); }
.banner.error   { background: var(--error-bg); color: var(--error); }
.banner.warning { background: var(--warning-bg); color: var(--warning); }
.banner.info    { background: var(--info-bg); color: var(--info); }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(29, 25, 22, 0.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; padding: var(--space-5);
  opacity: 0; visibility: hidden;
  transition: opacity var(--duration-base) var(--ease), visibility var(--duration-base) var(--ease);
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-raised);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  max-width: 520px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: scale(0.96) translateY(8px);
  transition: transform var(--duration-base) var(--ease);
}
.modal-overlay.show .modal { transform: scale(1) translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin-bottom: var(--space-5); }
.modal-close {
  background: none; border: none; font-size: var(--text-xl); line-height: 1;
  cursor: pointer; color: var(--text-tertiary); padding: var(--space-2);
  border-radius: var(--radius-xs); min-width: 40px; min-height: 40px;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-tertiary); }

/* ── Loading / skeleton ───────────────────────────────────────────────── */
.loading { text-align: center; padding: var(--space-20) 0; color: var(--text-secondary); }

.spinner {
  width: 28px; height: 28px; margin: 0 auto var(--space-4);
  border: 3px solid var(--border-medium);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-sunken) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-xs);
}
.skeleton-text { height: 12px; margin-bottom: var(--space-2); }
.skeleton-title { height: 20px; width: 45%; margin-bottom: var(--space-3); }
.skeleton-card { height: 120px; border-radius: var(--radius-lg); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Empty / error state ──────────────────────────────────────────────── */
.empty, .empty-state, .error-state {
  padding: var(--space-12) var(--space-6);
  text-align: center;
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-medium);
  color: var(--text-secondary);
}
.empty-icon { font-size: var(--text-3xl); margin-bottom: var(--space-3); opacity: 0.65; }
.empty-title { font-size: var(--text-md); font-weight: 700; color: var(--text-primary); margin-bottom: var(--space-2); }
.empty-body { font-size: var(--text-base); color: var(--text-secondary); max-width: 46ch; margin: 0 auto var(--space-5); }
.error-state { border-color: rgba(217, 45, 32, 0.3); background: var(--error-bg); color: var(--error); }
.error-state .empty-title { color: var(--error); }

/* ── Avatar ───────────────────────────────────────────────────────────── */
.avatar {
  width: 40px; height: 40px; flex: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--brand-600), var(--accent-tertiary));
  color: var(--text-on-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-sm);
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 72px; height: 72px; border-radius: var(--radius-lg); font-size: var(--text-lg); }

/* ── Pagination ───────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-2); margin-top: var(--space-8); flex-wrap: wrap;
}
.pagination-info { color: var(--text-secondary); font-size: var(--text-sm); margin: 0 var(--space-3); }

/* ── Post feed (analyzer) ─────────────────────────────────────────────── */
.post-feed { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-4); }
.post-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-raised);
  transition: var(--transition);
}
.post-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.post-media { aspect-ratio: 1; background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; color: var(--text-tertiary); }
.post-media img { width: 100%; height: 100%; object-fit: cover; }
.post-content, .post-body { padding: var(--space-4); }
.post-caption { font-size: var(--text-sm); color: var(--text-secondary); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-stats { display: flex; gap: var(--space-4); margin-top: var(--space-3); font-size: var(--text-sm); color: var(--text-tertiary); }
.post-stat { display: flex; align-items: center; gap: var(--space-1); }
.post-meta { font-size: var(--text-xs); color: var(--text-tertiary); }
.post-type-icon { font-size: var(--text-base); }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-light); margin: var(--space-6) 0; border: none; }
.list { display: grid; gap: var(--space-3); }
.list-item {
  padding: var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
}
.item-title { font-weight: 700; margin-bottom: var(--space-1); }
.item-meta { color: var(--text-secondary); font-size: var(--text-sm); line-height: var(--leading-snug); }

/* ==========================================================================
   6. UTILITIES
   ========================================================================== */

.hidden { display: none !important; }
[hidden] { display: none !important; }
.muted { color: var(--text-secondary); }
.subtle { color: var(--text-tertiary); }
.strong { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }

/* ==========================================================================
   7. RESPONSIVE
   ========================================================================== */

@media (max-width: 1024px) {
  .app { padding: var(--space-8) var(--space-5) var(--space-16); }
  h1 { font-size: var(--text-2xl); }
}

@media (max-width: 768px) {
  body { font-size: var(--text-base); }
  .app { padding: var(--space-6) var(--space-4) var(--space-12); }

  header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
    padding-bottom: var(--space-5);
    margin-bottom: var(--space-6);
  }
  .header-actions { justify-content: flex-start; }
  .product-nav { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .product-nav::-webkit-scrollbar { display: none; }

  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

  .card { padding: var(--space-5); border-radius: var(--radius-lg); }
  .modal { padding: var(--space-6); border-radius: var(--radius-lg); }

  .tabs { gap: var(--space-1); padding: var(--space-1); }
  .tab { flex: 0 0 auto; min-width: auto; padding: var(--space-3) var(--space-4); }

  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select { width: 100%; min-width: 0; }
  .search-input { min-width: 0; }

  .toast-container {
    top: auto; bottom: var(--space-4);
    left: var(--space-4); right: var(--space-4);
    max-width: none;
  }

  .stat-value, .stat-val { font-size: var(--text-xl); }
  .post-feed { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (max-width: 480px) {
  h1 { font-size: var(--text-xl); }
  .brand-logo { font-size: var(--text-xl); }
  .btn { width: 100%; }
  .btn-sm, .row .btn { width: auto; }
  .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr 1fr; }
}

/* Follower gender split from Instagram's follower_demographics insight. */
.gender-split { display: grid; gap: 6px; text-align: left; }
.gender-bar { display: flex; height: 6px; border-radius: 999px; overflow: hidden; background: var(--bg-tertiary); }
.gender-bar > .is-female { background: var(--brand-500); }
.gender-bar > .is-male { background: var(--teal-600); }
.gender-legend { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.gender-split.is-empty { font-size: 12px; color: var(--text-tertiary); }

/* ==========================================================================
   8. THEMES
   ========================================================================== */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg-primary:   #16130f;
    --bg-secondary: rgba(38, 33, 28, 0.86);
    --bg-tertiary:  #221d19;
    --bg-raised:    #211c18;
    --bg-sunken:    #100e0b;

    --border-light:  rgba(255, 255, 255, 0.08);
    --border-medium: rgba(255, 255, 255, 0.16);
    --border-strong: rgba(255, 255, 255, 0.28);

    --text-primary:   #f5efe8;
    --text-secondary: #bdb2a6;
    --text-tertiary:  #8a7f74;

    --accent-primary: var(--brand-400);
    --success: #45c88a;
    --warning: #e6a23c;
    --error:   var(--brand-400);
    --info:    #63a5f5;

    --success-bg: rgba(18, 183, 106, 0.14);
    --warning-bg: rgba(247, 144, 9, 0.14);
    --error-bg:   rgba(240, 68, 56, 0.14);
    --info-bg:    rgba(21, 112, 239, 0.16);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.34);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.44);
    --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.54);
    --shadow-xl: 0 32px 80px rgba(0, 0, 0, 0.62);

    --focus-ring: 0 0 0 3px rgba(249, 112, 102, 0.4);
  }

  :root:not([data-theme="light"]) body {
    background:
      radial-gradient(ellipse 80% 50% at 15% -5%, rgba(240, 68, 56, 0.12), transparent 60%),
      radial-gradient(ellipse 70% 50% at 90% 0%, rgba(97, 114, 243, 0.09), transparent 60%),
      linear-gradient(180deg, #1c1814 0%, var(--bg-primary) 45%);
  }

  :root:not([data-theme="light"]) .card { border-color: rgba(255, 255, 255, 0.07); }
  :root:not([data-theme="light"]) .nav-chip.active { background: var(--bg-raised); }
  :root:not([data-theme="light"]) .product-nav { background: rgba(255, 255, 255, 0.05); }
  :root:not([data-theme="light"]) .tier-nano  { background: rgba(255, 255, 255, 0.07); color: var(--text-secondary); }
  :root:not([data-theme="light"]) .tier-mid   { background: rgba(139, 92, 246, 0.18); color: #c4b5fd; }
  :root:not([data-theme="light"]) .tier-mega  { background: rgba(240, 68, 56, 0.18); color: var(--brand-300); }
  :root:not([data-theme="light"]) select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238a7f74' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  }
  :root:not([data-theme="light"]) ::selection { background: var(--brand-800); color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body { background: #fff; }
  header, .tabs, .product-nav, .btn, .toast-container, .filters { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
}
