/* ──────────────────────────────────────────────────────────────────────────
 * base.css — EBS Ads Dashboard shared design system
 *
 * This file is loaded on every authenticated page. It defines the colour
 * tokens, component primitives (platform nav, buttons, tables, modals,
 * toasts, badges, form fields) and a small set of utilities.
 *
 * Templates may still embed their own <style> blocks for page-specific
 * tweaks. Inline styles win against this file thanks to CSS source order,
 * so adding the <link> is a no-visual-regression change.
 *
 * When migrating a template to "shared-only" CSS, delete the lines from
 * its inline <style> that this file already provides, and lean on these.
 * ────────────────────────────────────────────────────────────────────── */

/* ── Reset ───────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design system: Apple HIG-inspired tokens ───────────────────────────
 * Tokens are defined at body level (not :root) so they override any
 * per-template inline `:root { --foo }` blocks. body.light-theme flips
 * surface colors; brand/status colors stay constant.
 * ───────────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 232px;

  /* Typography (SF Pro on Apple devices, system fallback elsewhere) */
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-text:    -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'SF Mono', ui-monospace, 'JetBrains Mono', Menlo, monospace;

  /* Type scale */
  --text-xs:   11px;
  --text-sm:   12px;
  --text-md:   13px;
  --text-lg:   15px;
  --text-xl:   17px;
  --text-2xl:  22px;
  --text-3xl:  28px;
  --text-4xl:  34px;

  /* Spacing (4-pt grid) */
  --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;

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Brand & status (theme-agnostic, iOS system colors) */
  --brand:        #007AFF;
  --brand-dark:   #0062CC;
  --brand-glow:   rgba(0,122,255,.18);
  --indigo:       #5856D6;
  --indigo-dark:  #4A48C0;
  --indigo-glow:  rgba(88,86,214,.18);
  --green:        #34C759;
  --amber:        #FF9F0A;
  --red:          #FF3B30;
  --blue:         #0A84FF;
  --pink:         #FF2D55;
  --purple:       #AF52DE;
  --teal:         #5AC8FA;
  --fire:         #FF6B35;
  --accent:       var(--brand);  /* alias for legacy templates */
}

/* Dark theme (default) — Apple dark mode aesthetic */
body {
  --dark:   #000000;
  --mid:    #1C1C1E;
  --card:   #1C1C1E;
  --card-2: #2C2C2E;
  --card-soft: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.18);

  --white:  #FFFFFF;
  --text:   #EBEBF5;
  --muted:  rgba(235,235,245,.62);
  --dim:    rgba(235,235,245,.30);
  --ink-soft: rgba(235,235,245,.85);

  --ltgreen:  rgba(48,209,88,.18);
  --ltamber:  rgba(255,159,10,.18);
  --ltred:    rgba(255,69,58,.18);
  --ltblue:   rgba(10,132,255,.18);
  --ltpurple: rgba(191,90,242,.18);
  --ltteal:   rgba(100,210,255,.18);
  --ltpink:   rgba(255,55,95,.18);

  --surface-blur:  saturate(180%) blur(20px);
  --sidebar-bg:    rgba(0,0,0,.72);

  /* Apple-style soft shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,.30), 0 1px 1px rgba(0,0,0,.20);
  --shadow-2: 0 4px 12px rgba(0,0,0,.30), 0 2px 4px rgba(0,0,0,.20);
  --shadow-3: 0 20px 40px rgba(0,0,0,.45), 0 6px 12px rgba(0,0,0,.25);
}

/* Light theme */
body.light-theme {
  --dark:   #F2F2F7;
  --mid:    #FFFFFF;
  --card:   #FFFFFF;
  --card-2: #F2F2F7;
  --card-soft: rgba(0,0,0,.03);
  --border: rgba(60,60,67,.12);
  --border-strong: rgba(60,60,67,.24);

  --white:  #1C1C1E;
  --text:   #3A3A3C;
  --muted:  rgba(60,60,67,.60);
  --dim:    rgba(60,60,67,.30);
  --ink-soft: rgba(60,60,67,.85);

  --ltgreen:  rgba(48,209,88,.14);
  --ltamber:  rgba(255,159,10,.16);
  --ltred:    rgba(255,59,48,.12);
  --ltblue:   rgba(0,122,255,.10);
  --ltpurple: rgba(175,82,222,.10);
  --ltteal:   rgba(90,200,250,.14);
  --ltpink:   rgba(255,45,85,.12);

  --sidebar-bg:    rgba(246,246,248,.82);

  --shadow-1: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.06);
  --shadow-2: 0 4px 12px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
  --shadow-3: 0 20px 40px rgba(0,0,0,.10), 0 6px 12px rgba(0,0,0,.06);
}

/* ── Body defaults ──────────────────────────────────────────────────── */
body {
  background: var(--dark);
  color:      var(--text);
  font-family: var(--font-text);
  font-size:  var(--text-md);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  padding-left: var(--sidebar-w) !important;  /* needed; per-template body rules would clobber this */
}
body.page-login,
body.page-403 { padding-left: 0 !important; }

h1, h2, h3, h4, h5 { font-family: var(--font-display); letter-spacing: -.01em; }

/* Page headers were originally sticky at top:38px (the old horizontal nav bar height).
   With the sidebar layout there's no top bar so they should stick to the very top. */
.header { top: 0 !important; }

/* ── Platform navigation (LEFT SIDEBAR, Apple HIG style) ──────────────── */
.platform-nav {
  background: var(--sidebar-bg);
  backdrop-filter: var(--surface-blur);
  -webkit-backdrop-filter: var(--surface-blur);
  border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  z-index: 50;
}
.platform-nav::-webkit-scrollbar { width: 4px; }
.platform-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2) var(--space-4);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--brand), var(--indigo));
  color: #FFF;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: .5px;
  flex-shrink: 0;
  box-shadow: var(--shadow-1);
}
.sidebar-brand-name { font-size: var(--text-md); font-weight: 700; color: var(--white); line-height: 1.2; letter-spacing: -.01em; }
.sidebar-brand-sub  { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

.platform-nav-section { display: flex; flex-direction: column; gap: 1px; margin-bottom: var(--space-3); }
.platform-nav-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 700;
  padding: var(--space-2) var(--space-3) var(--space-1);
  white-space: nowrap;
}

.platform-pill {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .15s, color .15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  color: var(--text);
}
.platform-pill:hover { background: var(--card-soft); color: var(--white); }
.platform-pill svg { flex-shrink: 0; opacity: .8; }
.platform-pill:hover svg { opacity: 1; }
.platform-pill .pill-emoji { font-size: var(--text-lg); width: 16px; text-align: center; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; }
.sidebar-logout, .sidebar-theme-toggle {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 8px 12px; border-radius: var(--radius-md);
  color: var(--muted); font-size: var(--text-md); font-weight: 500;
  text-decoration: none;
  transition: .15s;
  background: none; border: none; cursor: pointer; font-family: inherit; width: 100%; text-align: left;
}
.sidebar-theme-toggle:hover { background: var(--card-soft); color: var(--white); }
.sidebar-logout:hover { background: var(--ltred); color: var(--red); }
.sidebar-theme-toggle .theme-light-only { display: none; }
.sidebar-theme-toggle .theme-dark-only  { display: inline-flex; }
body.light-theme .sidebar-theme-toggle .theme-light-only { display: inline-flex; }
body.light-theme .sidebar-theme-toggle .theme-dark-only  { display: none; }

/* Hamburger toggle (mobile only) */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 60;
  background: var(--card);
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  cursor: pointer;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 49;
}
body.sidebar-open .sidebar-backdrop { display: block; }
/* Per-section accent colors — only used for the active-state tint */
.platform-pill.meta.active      { background: var(--ltblue);   color: #0A84FF; }
.platform-pill.linkedin.active  { background: var(--ltblue);   color: #0A84FF; }
.platform-pill.google.active    { background: var(--ltblue);   color: #0A84FF; }
.platform-pill.unified.active   { background: var(--ltpurple); color: #AF52DE; }
.platform-pill.projects.active  { background: var(--ltpink);   color: #FF2D55; }
.platform-pill.creator.active   { background: var(--ltamber);  color: #FF9F0A; }
.platform-pill.knowledge.active { background: var(--ltteal);   color: #5AC8FA; }
.platform-pill.admin.active     { background: var(--ltpurple); color: #5856D6; }
.platform-pill.users.active     { background: var(--ltpink);   color: #FF2D55; }
.platform-pill.active           { font-weight: 600; }
.platform-pill.active svg       { opacity: 1; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: .2s;
  text-decoration: none;
  white-space: nowrap;
  background: none;
}
.btn:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}
.btn-primary   { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-dark); }
.btn-secondary { background: var(--dark);   color: var(--muted); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--white); border-color: var(--muted); }
.btn-danger    { background: var(--ltred);   color: var(--red);   border: 1px solid rgba(239,68,68,.35); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-warn      { background: var(--ltamber); color: var(--amber); border: 1px solid rgba(245,158,11,.35); }
.btn-warn:hover { background: rgba(245,158,11,.2); }
.btn-info      { background: rgba(99,102,241,.12); color: #818CF8; border: 1px solid rgba(99,102,241,.3); }
.btn-info:hover{ background: rgba(99,102,241,.22); color: #fff; }
.btn-sm        { padding: 3px 9px; font-size: 10px; }

/* ── Logout chip ─────────────────────────────────────────────────────── */
.btn-logout {
  background: var(--ltred);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.4);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: .2s;
}
.btn-logout:hover { background: rgba(239,68,68,.2); }

/* ── User badge ─────────────────────────────────────────────────────── */
.user-badge {
  font-size: 11px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.user-badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--indigo);
  display: inline-block;
}

/* ── Tables ─────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--dark);
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 12px;
}
tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: rgba(255,255,255,.015); }

/* ── Spinner / loading indicator ────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: middle;
}

/* ── Focus indicators for accessibility ─────────────────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

/* ── Mobile-first responsive nudges ─────────────────────────────────── */
@media (max-width: 900px) {
  body { padding-left: 0; }
  .platform-nav {
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 240px;
  }
  body.sidebar-open .platform-nav { transform: translateX(0); box-shadow: 4px 0 18px rgba(0,0,0,.4); }
  .sidebar-toggle { display: inline-flex; }
  /* Push page content to clear the floating hamburger */
  .header, .page-header { padding-left: 60px !important; }
}

/* ──────────────────────────────────────────────────────────────────────
 * Unified alert / notification UI kit
 *
 * Used by every dashboard (and future ones) through the
 * `static/js/notifications.js` helper. Every alert surface — load
 * errors, stale-data warnings, CPL threshold breach, refresh failures,
 * generic toasts — renders through these classes so the look stays
 * consistent across pages and themes.
 *
 * Pattern overview:
 *   .ebs-banner            persistent inline strip (full width)
 *   .ebs-toast             transient floating bubble (bottom-right)
 *   variants: --info  --success  --warn  --error
 *
 * All variants respect theme tokens (--red, --amber, --green, --brand)
 * so dark/light theme inversion is automatic.
 * ────────────────────────────────────────────────────────────────────── */

/* Shared alert tokens — derived from status colors with theme-safe alpha. */
:root {
  --alert-error-bg:   color-mix(in srgb, var(--red)   12%, transparent);
  --alert-error-bd:   color-mix(in srgb, var(--red)   38%, transparent);
  --alert-error-fg:   var(--red);
  --alert-warn-bg:    color-mix(in srgb, var(--amber) 14%, transparent);
  --alert-warn-bd:    color-mix(in srgb, var(--amber) 40%, transparent);
  --alert-warn-fg:    var(--amber);
  --alert-info-bg:    color-mix(in srgb, var(--brand) 14%, transparent);
  --alert-info-bd:    color-mix(in srgb, var(--brand) 40%, transparent);
  --alert-info-fg:    var(--brand);
  --alert-success-bg: color-mix(in srgb, var(--green) 14%, transparent);
  --alert-success-bd: color-mix(in srgb, var(--green) 40%, transparent);
  --alert-success-fg: var(--green);
}

/* ── Inline banner (persistent) ─────────────────────────────────────── */
.ebs-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 16px;
  margin: 0 0 var(--space-4);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.45;
  background: var(--card);
  color: var(--ink-soft);
  /* Don't let inline content (long error strings) break the layout */
  word-break: break-word;
}
.ebs-banner__msg { flex: 1; min-width: 0; }
.ebs-banner__actions { display: flex; gap: var(--space-2); flex-shrink: 0; align-items: center; }
.ebs-banner__btn,
.ebs-banner__link {
  font-size: 11px;
  font-weight: 600;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity .15s;
}
.ebs-banner__btn:hover,
.ebs-banner__link:hover { opacity: .75; }
.ebs-banner__close {
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: inherit;
  opacity: .6;
  background: transparent;
  border: 0;
  padding: 0 4px;
}
.ebs-banner__close:hover { opacity: 1; }

.ebs-banner--error   { background: var(--alert-error-bg);   border-left-color: var(--alert-error-fg);   color: var(--alert-error-fg); }
.ebs-banner--warn    { background: var(--alert-warn-bg);    border-left-color: var(--alert-warn-fg);    color: var(--alert-warn-fg); }
.ebs-banner--info    { background: var(--alert-info-bg);    border-left-color: var(--alert-info-fg);    color: var(--alert-info-fg); }
.ebs-banner--success { background: var(--alert-success-bg); border-left-color: var(--alert-success-fg); color: var(--alert-success-fg); }

/* ── Toast container (floating, bottom-right, stacks) ───────────────── */
.ebs-toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;        /* container is transparent to mouse */
  max-width: min(420px, calc(100vw - 40px));
}
.ebs-toast {
  pointer-events: auto;        /* but individual toasts can be clicked */
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--ink-soft);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: ebs-toast-in .18s ease-out;
  word-break: break-word;
}
.ebs-toast.ebs-toast--leaving { animation: ebs-toast-out .15s ease-in forwards; }
@keyframes ebs-toast-in  { from { transform: translateX(20px); opacity: 0; } to   { transform: none; opacity: 1; } }
@keyframes ebs-toast-out { from { transform: none; opacity: 1; }              to { transform: translateX(20px); opacity: 0; } }
.ebs-toast--error   { background: var(--alert-error-bg);   border-left-color: var(--alert-error-fg);   color: var(--alert-error-fg); }
.ebs-toast--warn    { background: var(--alert-warn-bg);    border-left-color: var(--alert-warn-fg);    color: var(--alert-warn-fg); }
.ebs-toast--info    { background: var(--alert-info-bg);    border-left-color: var(--alert-info-fg);    color: var(--alert-info-fg); }
.ebs-toast--success { background: var(--alert-success-bg); border-left-color: var(--alert-success-fg); color: var(--alert-success-fg); }
.ebs-toast__msg   { flex: 1; min-width: 0; }
.ebs-toast__close {
  cursor: pointer; background: transparent; border: 0;
  color: inherit; opacity: .55; font-size: 16px; line-height: 1; padding: 0 2px;
}
.ebs-toast__close:hover { opacity: 1; }

/* Mobile: full-width toasts at the bottom */
@media (max-width: 600px) {
  .ebs-toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}

/* Browsers without color-mix() — graceful flat-color fallback */
@supports not (color: color-mix(in srgb, red 10%, transparent)) {
  .ebs-banner--error,   .ebs-toast--error   { background: rgba(255, 59, 48, .12); }
  .ebs-banner--warn,    .ebs-toast--warn    { background: rgba(255, 159, 10, .12); }
  .ebs-banner--info,    .ebs-toast--info    { background: rgba(0, 122, 255, .12); }
  .ebs-banner--success, .ebs-toast--success { background: rgba(52, 199, 89, .12); }
}
