/* ============================================================
   BEF Ads Report — Design System
   Modern SaaS · Light mode · Token-driven · Fully consistent
   ============================================================ */

/* ---------- 1. Design Tokens ---------- */
:root {
  /* Brand */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* Neutrals (slate) */
  --c-bg:        #f6f7f9;
  --c-surface:   #ffffff;
  --c-surface-2: #fafbfc;
  --c-border:    #e7e9ee;
  --c-border-strong: #d6dae1;
  --c-ink:       #14161b;
  --c-text:      #2b303b;
  --c-muted:     #6b7480;
  --c-faint:     #99a1ad;

  /* Semantic */
  --c-success:   #16a34a;  --c-success-bg: #e8f7ee;  --c-success-bd: #b8e6c8;
  --c-warning:   #c2710c;  --c-warning-bg: #fdf3e3;  --c-warning-bd: #f3d8a6;
  --c-danger:    #dc2626;  --c-danger-bg:  #fdecec;  --c-danger-bd:  #f5c2c2;
  --c-info:      #4f46e5;  --c-info-bg:    #eef2ff;  --c-info-bd:    #d2d9fb;

  /* Chart palette */
  --chart-1: #4f46e5;
  --chart-2: #0ea5e9;
  --chart-3: #10b981;
  --chart-4: #f59e0b;
  --chart-5: #ec4899;
  --chart-6: #8b5cf6;

  /* Radius */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Shadows */
  --sh-xs: 0 1px 2px rgba(16,24,40,.04);
  --sh-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --sh-md: 0 2px 4px rgba(16,24,40,.05), 0 4px 12px rgba(16,24,40,.07);
  --sh-lg: 0 8px 24px rgba(16,24,40,.10), 0 2px 6px rgba(16,24,40,.06);

  /* Spacing scale */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;

  --sidebar-w: 264px;
  --topbar-h: 64px;
}

/* ---------- 2. Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv02','cv03','cv04','cv11';
}
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1,h2,h3,h4 { color: var(--c-ink); font-weight: 650; letter-spacing: -.014em; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
::selection { background: var(--brand-100); }

/* ---------- 3. Utilities ---------- */
.u-muted { color: var(--c-muted); }
.u-faint { color: var(--c-faint); }
.u-mono  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.u-tnum  { font-variant-numeric: tabular-nums; }
.u-eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--c-faint); }
.u-right { text-align: right; }
.u-nowrap { white-space: nowrap; }
.u-flex  { display: flex; align-items: center; }
.u-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.u-gap-2 { gap: var(--s-2); } .u-gap-3 { gap: var(--s-3); } .u-gap-4 { gap: var(--s-4); }
.u-mt-4 { margin-top: var(--s-4); } .u-mt-6 { margin-top: var(--s-6); } .u-mt-8 { margin-top: var(--s-8); }
.u-mb-2 { margin-bottom: var(--s-2);} .u-mb-4 { margin-bottom: var(--s-4); } .u-mb-6 { margin-bottom: var(--s-6); }
.u-wrap { flex-wrap: wrap; }
.u-grow { flex: 1; }
.u-hide { display: none !important; }

/* ---------- 4. App Shell (sidebar + topbar) ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-5); height: var(--topbar-h);
  border-bottom: 1px solid var(--c-border);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: var(--sh-sm); flex-shrink: 0;
}
.brand-name { font-weight: 650; color: var(--c-ink); letter-spacing: -.01em; }
.brand-name small { display: block; font-size: 11px; font-weight: 500; color: var(--c-faint); letter-spacing: 0; }

.nav { padding: var(--s-4) var(--s-3); display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav__label { padding: var(--s-3) var(--s-3) var(--s-2); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--c-faint); }
.nav__item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 9px var(--s-3); border-radius: var(--r-sm);
  color: var(--c-muted); font-weight: 500; transition: background .12s, color .12s;
}
.nav__item svg { width: 18px; height: 18px; stroke-width: 1.9; flex-shrink: 0; }
.nav__item:hover { background: var(--c-surface-2); color: var(--c-ink); }
.nav__item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav__item.is-active svg { color: var(--brand-600); }

.sidebar__foot { padding: var(--s-3); border-top: 1px solid var(--c-border); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  background: rgba(255,255,255,.82); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-8); position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 16px; font-weight: 600; color: var(--c-ink); }
.content { padding: var(--s-8); max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- 5. Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { color: var(--c-muted); margin-top: 2px; }

/* ---------- 6. Card ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
}
.card__head { padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.card__head h3 { font-size: 15px; }
.card__head .u-muted { font-size: 13px; }
.card__body { padding: var(--s-6); }
.card__body--flush { padding: 0; }

/* ---------- 7. KPI stat cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s-4); }
.kpi {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); padding: var(--s-5); box-shadow: var(--sh-xs);
  display: flex; flex-direction: column; gap: var(--s-3);
}
.kpi__top { display: flex; align-items: center; justify-content: space-between; }
.kpi__label { font-size: 12.5px; font-weight: 550; color: var(--c-muted); }
.kpi__icon { width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); }
.kpi__icon svg { width: 18px; height: 18px; stroke-width: 2; }
.kpi__value { font-size: 26px; font-weight: 680; color: var(--c-ink); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi__sub { font-size: 12.5px; color: var(--c-faint); }

/* trend chip */
.trend { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-pill); }
.trend--up { color: var(--c-success); background: var(--c-success-bg); }
.trend--down { color: var(--c-danger); background: var(--c-danger-bg); }
.trend--flat { color: var(--c-muted); background: var(--c-surface-2); }

/* ---------- 8. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 38px; padding: 0 var(--s-4); border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  border: 1px solid transparent; transition: background .12s, border-color .12s, box-shadow .12s, color .12s;
  user-select: none;
}
.btn svg { width: 16px; height: 16px; stroke-width: 2; }
.btn--primary { background: var(--brand-600); color: #fff; box-shadow: var(--sh-xs); }
.btn--primary:hover { background: var(--brand-700); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong); box-shadow: var(--sh-xs); }
.btn--secondary:hover { background: var(--c-surface-2); border-color: var(--c-faint); }
.btn--ghost { background: transparent; color: var(--c-muted); }
.btn--ghost:hover { background: var(--c-surface-2); color: var(--c-ink); }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }
.btn--danger-soft { background: var(--c-danger-bg); color: var(--c-danger); border-color: var(--c-danger-bd); }
.btn--danger-soft:hover { background: #fbe0e0; }
.btn--sm { height: 32px; padding: 0 var(--s-3); font-size: 12.5px; }
.btn--lg { height: 44px; padding: 0 var(--s-6); font-size: 15px; }
.btn--block { width: 100%; }
.btn--icon { width: 34px; height: 34px; padding: 0; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 9. Forms ---------- */
.field { margin-bottom: var(--s-5); }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--c-text); margin-bottom: var(--s-2); }
.label .req { color: var(--c-danger); }
.hint { font-size: 12px; color: var(--c-faint); margin-top: 6px; }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 var(--s-3);
  background: var(--c-surface); border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm); font-size: 14px; color: var(--c-ink);
  transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; padding: var(--s-3); min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.input::placeholder, .textarea::placeholder { color: var(--c-faint); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7480' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; cursor: pointer; }
.input--error { border-color: var(--c-danger); }
.input--error:focus { box-shadow: 0 0 0 3px var(--c-danger-bg); }
.field-error { font-size: 12px; color: var(--c-danger); margin-top: 6px; }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); }
.form-grid .field--full { grid-column: 1 / -1; }

/* toggle */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch__track { width: 40px; height: 22px; border-radius: var(--r-pill); background: var(--c-border-strong); transition: background .15s; flex-shrink: 0; }
.switch__track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--sh-sm); transition: transform .15s; }
.switch input:checked + .switch__track { background: var(--brand-600); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

/* ---------- 10. Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill); line-height: 1.4; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--c-success); background: var(--c-success-bg); }
.badge--warning { color: var(--c-warning); background: var(--c-warning-bg); }
.badge--danger  { color: var(--c-danger);  background: var(--c-danger-bg); }
.badge--info    { color: var(--c-info);    background: var(--c-info-bg); }
.badge--neutral { color: var(--c-muted);   background: var(--c-surface-2); border: 1px solid var(--c-border); }

/* ---------- 11. Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  color: var(--c-faint); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border);
  white-space: nowrap; background: var(--c-surface-2);
}
.table th.u-right, .table td.u-right { text-align: right; }
.table td { padding: var(--s-4); border-bottom: 1px solid var(--c-border); color: var(--c-text); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--c-surface-2); }
.table .cell-strong { font-weight: 600; color: var(--c-ink); }
.table .cell-num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tfoot td { padding: var(--s-4); font-weight: 650; color: var(--c-ink); background: var(--c-surface-2); border-top: 2px solid var(--c-border); font-variant-numeric: tabular-nums; }

/* ---------- 12. Alerts ---------- */
.alert { display: flex; gap: var(--s-3); padding: var(--s-4); border-radius: var(--r-md); font-size: 13.5px; border: 1px solid; margin-bottom: var(--s-5); }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert--success { background: var(--c-success-bg); border-color: var(--c-success-bd); color: #15803d; }
.alert--danger  { background: var(--c-danger-bg);  border-color: var(--c-danger-bd);  color: #b91c1c; }
.alert--warning { background: var(--c-warning-bg); border-color: var(--c-warning-bd); color: #b45309; }
.alert--info    { background: var(--c-info-bg);    border-color: var(--c-info-bd);    color: var(--brand-700); }
.alert strong { font-weight: 650; }

/* ---------- 13. Empty state ---------- */
.empty { text-align: center; padding: var(--s-12) var(--s-6); }
.empty__icon { width: 56px; height: 56px; margin: 0 auto var(--s-4); border-radius: var(--r-lg); background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; }
.empty__icon svg { width: 26px; height: 26px; }
.empty h3 { margin-bottom: var(--s-2); }
.empty p { color: var(--c-muted); max-width: 380px; margin: 0 auto var(--s-5); }

/* ---------- 14. Segmented / chips ---------- */
.seg { display: inline-flex; background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg a { padding: 6px 12px; border-radius: var(--r-xs); font-size: 13px; font-weight: 550; color: var(--c-muted); }
.seg a.is-active { background: var(--c-surface); color: var(--c-ink); box-shadow: var(--sh-xs); }

/* ---------- 15. Dropdown ---------- */
.dropdown { position: relative; }
.dropdown__menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md);
  box-shadow: var(--sh-lg); padding: var(--s-2); z-index: 30; display: none;
}
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item { display: flex; align-items: center; gap: var(--s-3); padding: 8px var(--s-3); border-radius: var(--r-xs); font-size: 13.5px; color: var(--c-text); cursor: pointer; width: 100%; background: none; border: none; text-align: left; }
.dropdown__item:hover { background: var(--c-surface-2); }
.dropdown__item--danger { color: var(--c-danger); }
.dropdown__sep { height: 1px; background: var(--c-border); margin: var(--s-2) 0; }

/* ---------- 16. Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s-6); background:
  radial-gradient(1200px 600px at 50% -10%, var(--brand-50), transparent), var(--c-bg); }
.auth__card { width: 100%; max-width: 400px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-xl); box-shadow: var(--sh-lg); padding: var(--s-10) var(--s-8); }
.auth__brand { display: flex; align-items: center; gap: var(--s-3); justify-content: center; margin-bottom: var(--s-6); }
.auth__title { text-align: center; margin-bottom: var(--s-2); }
.auth__sub { text-align: center; color: var(--c-muted); margin-bottom: var(--s-8); }

/* ---------- 17. Copy field ---------- */
.copy-row { display: flex; align-items: center; gap: var(--s-2); }
.copy-row .input { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- 17b. Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--c-border); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 11px 16px; font-size: 13.5px; font-weight: 600; color: var(--c-muted);
  border: none; background: none; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 7px;
  transition: color .12s, border-color .12s;
}
.tab:hover { color: var(--c-ink); }
.tab.is-active { color: var(--brand-700); border-bottom-color: var(--brand-600); }
.tab .count { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: var(--r-pill); background: var(--c-surface-2); color: var(--c-muted); }
.tab.is-active .count { background: var(--brand-50); color: var(--brand-700); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* keyword/term text cell */
.kw-text { font-weight: 600; color: var(--c-ink); }
.kw-meta { font-size: 11.5px; color: var(--c-faint); margin-top: 1px; }
.ad-lines { display: flex; flex-direction: column; gap: 2px; }
.ad-lines .h { font-weight: 600; color: var(--c-ink); font-size: 13px; }
.ad-lines .d { color: var(--c-muted); font-size: 12.5px; }

/* ---------- 18. Misc ---------- */
.divider { height: 1px; background: var(--c-border); border: none; margin: var(--s-6) 0; }
.list-reset { list-style: none; padding: 0; }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--c-faint); margin-bottom: var(--s-3); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--brand-200); border-top-color: var(--brand-600); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 19. Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--sh-lg); }
  .sidebar.is-open { transform: translateX(0); }
  .content { padding: var(--s-5); }
  .topbar { padding: 0 var(--s-5); }
  .form-grid { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex !important; }
  .scrim { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 40; }
}
.menu-toggle { display: none; }
