/* ==========================================================================
   Boletim Brave v2 · Canonical Design Tokens & Foundation Primitives
   Source of truth: /DESIGN.md + /PRODUCT.md (Brave DS v16 + Linear / Apple Notes)
   Shared across Surface A (/) and Surface B (/portal/)
   ========================================================================== */

/* CLS-Zero Metric-Calibrated Fallback for Libre Franklin (from brave3/tokens.css) */
@font-face {
  font-family: "Libre Franklin Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Roboto");
  size-adjust: 104.2%;
  ascent-override: 93%;
  descent-override: 24%;
  line-gap-override: 0%;
}

:root {
  /* 1. Families
     - Libre Franklin governs 100% of headlines, UI, body, KPIs, and prices.
     - IBM Plex Mono is strictly restricted to shortcuts (⌘K), audio timestamps,
       technical codes (RSS, tickers), and legal footer notes. */
  --font-sans: "Libre Franklin", "Libre Franklin Fallback", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* 2. Immutable Brave Brand Palette (Layer 1) */
  --navy-950: #05070d;
  --navy-900: #0b1426;
  --navy-800: #0f1c2f;
  --navy-750: #13203a;
  --navy-700: #16233c;
  --navy-650: #1a2740;
  --navy-blue: #1d3786;
  --light-100: #edf2f4;
  --light-50: #f6f8fa;
  --white: #ffffff;
  --yellow-500: #eaca2d;
  --yellow-600: #d8b81f;

  /* 3. Fluid Typography Scale (Responsive-First Contract) */
  --text-hero: clamp(2rem, 1.35rem + 2.6vw, 3.375rem);          /* 32px -> 54px */
  --text-h2: clamp(1.5rem, 1.18rem + 1.4vw, 2.25rem);           /* 24px -> 36px */
  --text-h3: clamp(1.125rem, 1.04rem + 0.35vw, 1.3125rem);      /* 18px -> 21px */
  --text-page-title: clamp(1.25rem, 1.15rem + 0.35vw, 1.375rem);/* 20px -> 22px */
  --text-reading-h1: clamp(1.375rem, 1.18rem + 0.85vw, 1.75rem);/* 22px -> 28px */
  --text-body-lg: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);       /* 16px -> 18px */
  --text-body: 0.9375rem;                                       /* 15px */
  --text-sm: 0.8125rem;                                         /* 13px */
  --text-xs: 0.75rem;                                           /* 12px */

  /* 4. Fluid Spacing Rhythm (mobile floor <= 50% of desktop ceiling) */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;  /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-10: 2.5rem;  /* 40px */
  --space-12: 3rem;    /* 48px */

  --section-py-xl: clamp(3rem, 7vw, 6.5rem);      /* 48px -> 104px */
  --section-py-lg: clamp(2.5rem, 5.5vw, 5rem);    /* 40px -> 80px */
  --section-py-md: clamp(1.75rem, 4vw, 3.25rem);  /* 28px -> 52px */
  --section-py-sm: clamp(1.25rem, 2.8vw, 2.25rem);/* 20px -> 36px */

  --gap-xl: clamp(1.5rem, 3.5vw, 3rem);           /* 24px -> 48px */
  --gap-lg: clamp(1.125rem, 2.5vw, 2rem);         /* 18px -> 32px */
  --gap-md: clamp(0.75rem, 1.5vw, 1.25rem);       /* 12px -> 20px */
  --gap-sm: clamp(0.5rem, 1vw, 0.75rem);          /* 8px -> 12px */
  --container-pad: clamp(1rem, 4vw, 2rem);        /* 16px -> 32px */

  /* 5. Structural Geometry */
  --container-lp: 1120px;
  --container-app: 1040px;
  --container-reading: 760px;
  --container-narrow: 680px;
  --sidebar-w: 236px;
  --sidebar-w-collapsed: 72px;
  --header-lp-h: 64px;
  --mobile-nav-h: 56px;
  --mini-player-bar-h: 56px;
  --mini-player-pill-h: 44px;
  --touch-target: 44px;

  /* 6. Canonical Radii */
  --r-control: 8px;
  --r-card: 12px;
  --r-feature: 16px;
  --r-pill: 999px;

  /* Backwards-compatible aliases */
  --bt-raio-controle: var(--r-control);
  --bt-raio-botao-grande: var(--r-control);
  --bt-raio-cartao: var(--r-card);
  --bt-raio-destaque: var(--r-feature);
  --bt-raio-etiqueta: var(--r-pill);

  /* 7. Elevation & Motion (strictly reserved for floating surfaces) */
  --shadow-none: none;
  --shadow-card-light: 0 1px 2px rgba(15, 28, 47, 0.04);
  --shadow-float: 0 10px 30px rgba(5, 7, 13, 0.22), 0 2px 8px rgba(5, 7, 13, 0.12);

  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
}

/* ==========================================================================
   Semantic Mode Tokens: Claro (Default in /portal/ and Light LP Folds)
   ========================================================================== */
:root,
[data-theme="claro"],
[data-theme="light"] {
  color-scheme: light;
  --bt-fundo: #edf2f4;
  --bt-superficie: #ffffff;
  --bt-superficie-2: #f6f8fa;
  --bt-superficie-3: #e4ecf1;

  --bt-ink: #0f1c2f;
  --bt-ink-2: rgba(15, 28, 47, 0.72);
  --bt-ink-3: rgba(15, 28, 47, 0.62);

  --bt-linha: rgba(15, 28, 47, 0.09);
  --bt-linha-forte: rgba(15, 28, 47, 0.18);

  /* Solid Action Rule: solid Executive Navy on light surfaces */
  --bt-cta: #0f1c2f;
  --bt-cta-hover: #1a2740;
  --bt-cta-ink: #ffffff;

  --bt-dourado: #eaca2d;
  --bt-azul: #1d3786;
  --bt-ponto-titulo: #1d3786;
  --bt-foco: rgba(29, 55, 134, 0.32);

  --bt-campo-fundo: #ffffff;
  --bt-campo-borda: rgba(15, 28, 47, 0.20);

  /* Sidebar Rail (always institutional Navy, zero >1px side-stripes) */
  --bt-menu: #0f1c2f;
  --bt-menu-borda: rgba(255, 255, 255, 0.08);
  --bt-menu-texto: rgba(255, 255, 255, 0.74);
  --bt-menu-hover: rgba(255, 255, 255, 0.06);
  --bt-menu-ativo: #1a2740;
  --bt-menu-ativo-ink: #ffffff;
  --bt-menu-ativo-acento: #eaca2d;

  /* Semantic Status (WCAG AA on light) */
  --bt-ok: #0b7451;
  --bt-ok-fundo: rgba(11, 116, 81, 0.10);
  --bt-aviso: #9a5b00;
  --bt-aviso-fundo: rgba(180, 83, 9, 0.10);
  --bt-risco: #b42318;
  --bt-risco-fundo: rgba(180, 35, 24, 0.10);
}

/* ==========================================================================
   Semantic Mode Tokens: Dark (Dark LP Folds and /portal/ Night Mode)
   ========================================================================== */
[data-theme="dark"] {
  color-scheme: dark;
  --bt-fundo: #0b1426;
  --bt-superficie: #0f1c2f;
  --bt-superficie-2: #13203a;
  --bt-superficie-3: #16233c;

  --bt-ink: #ffffff;
  --bt-ink-2: rgba(255, 255, 255, 0.78);
  --bt-ink-3: rgba(255, 255, 255, 0.64);

  --bt-linha: rgba(255, 255, 255, 0.08);
  --bt-linha-forte: rgba(255, 255, 255, 0.16);

  /* Solid Action Rule: solid Brave Gold on dark surfaces */
  --bt-cta: #eaca2d;
  --bt-cta-hover: #d8b81f;
  --bt-cta-ink: #0b1426;

  --bt-dourado: #eaca2d;
  --bt-azul: #93c5fd;
  --bt-ponto-titulo: #eaca2d;
  --bt-foco: rgba(234, 202, 45, 0.38);

  --bt-campo-fundo: #0b1426;
  --bt-campo-borda: rgba(255, 255, 255, 0.18);

  --bt-menu: #080f1d;
  --bt-menu-borda: rgba(255, 255, 255, 0.08);
  --bt-menu-texto: rgba(255, 255, 255, 0.72);
  --bt-menu-hover: rgba(255, 255, 255, 0.06);
  --bt-menu-ativo: #16233c;
  --bt-menu-ativo-ink: #ffffff;
  --bt-menu-ativo-acento: #eaca2d;

  --bt-ok: #34d399;
  --bt-ok-fundo: rgba(16, 185, 129, 0.14);
  --bt-aviso: #fbbf24;
  --bt-aviso-fundo: rgba(245, 158, 11, 0.15);
  --bt-risco: #f87171;
  --bt-risco-fundo: rgba(239, 68, 68, 0.15);
}

/* ==========================================================================
   Systemic Resets & Responsive-First Guards
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  min-width: 0;
}

html {
  max-width: 100vw;
  overflow-x: clip;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  max-width: 100vw;
  overflow-x: clip;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.58;
  background-color: var(--bt-fundo);
  color: var(--bt-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* Prevent iOS Safari auto-zoom on form focus below 768px */
@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

:focus-visible {
  outline: 2px solid var(--bt-foco);
  outline-offset: 2px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
}

.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;
}

/* ==========================================================================
   Canonical Layer-2 Atoms (Linear / Apple Notes Structural Silence)
   ========================================================================== */

/* 1. Continuous 1px Surface (zero header hats, zero >1px side stripes) */
.bt-surface {
  background-color: var(--bt-superficie);
  color: var(--bt-ink);
  border: 1px solid var(--bt-linha);
  border-radius: var(--r-card);
  padding: clamp(1rem, 2.2vw, 1.5rem);
  box-shadow: none;
}

@media (max-width: 760px) {
  .bt-surface {
    border-radius: var(--r-feature);
  }
}

.bt-divider {
  height: 1px;
  border: 0;
  margin: var(--space-5) 0;
  background-color: var(--bt-linha);
}

/* 2. Clean Page Header (.bt-cab) */
.bt-cab {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-6) 0;
  padding: 0;
  background: transparent;
  border: 0;
}

.bt-cab__titulo {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-page-title);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--bt-ink);
}

/* 3. Solid Action Buttons (zero gradients, zero glow, zero translateY) */
.bt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 1.25rem;
  border-radius: var(--r-control);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: none;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.bt-btn-primary {
  background-color: var(--bt-cta);
  color: var(--bt-cta-ink);
}

.bt-btn-primary:hover {
  background-color: var(--bt-cta-hover);
}

.bt-btn-secondary {
  background-color: transparent;
  border-color: var(--bt-linha-forte);
  color: var(--bt-ink);
}

.bt-btn-secondary:hover {
  background-color: var(--bt-superficie-2);
}

.bt-btn-ghost {
  background-color: transparent;
  border-color: transparent;
  color: var(--bt-ink-2);
}

.bt-btn-ghost:hover {
  background-color: var(--bt-superficie-2);
  color: var(--bt-ink);
}

/* 4. Sidebar Navigation Item (.bt-menu-item & .bt-menu-ativo)
      Anti-side-stripe law: ZERO border-left or border-right > 1px!
      Active state uses subtle fill + #eaca2d icon tint + 6px circular dot. */
.bt-menu-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6875rem;
  width: 100%;
  min-height: 40px;
  padding: 0 0.75rem;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--bt-menu-texto);
  font-family: var(--font-sans);
  font-size: 0.90625rem;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.bt-menu-item:hover {
  background-color: var(--bt-menu-hover);
  color: #ffffff;
}

.bt-menu-item[aria-current="page"],
.bt-menu-item.is-active,
.bt-menu-ativo {
  background-color: var(--bt-menu-ativo);
  color: var(--bt-menu-ativo-ink);
  font-weight: 600;
}

.bt-menu-item[aria-current="page"] svg,
.bt-menu-item.is-active svg,
.bt-menu-ativo svg {
  color: var(--bt-menu-ativo-acento);
}

.bt-menu-item[aria-current="page"]::after,
.bt-menu-item.is-active::after,
.bt-menu-ativo::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background-color: var(--bt-menu-ativo-acento);
  flex-shrink: 0;
}

/* 5. Form Inputs */
.bt-input,
.bt-select {
  width: 100%;
  min-height: var(--touch-target);
  padding: 0.625rem 0.875rem;
  border-radius: var(--r-control);
  border: 1px solid var(--bt-campo-borda);
  background-color: var(--bt-campo-fundo);
  color: var(--bt-ink);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.bt-input::placeholder {
  color: var(--bt-ink-3);
}

.bt-input:focus,
.bt-select:focus {
  outline: none;
  border-color: var(--bt-azul);
  box-shadow: 0 0 0 3px var(--bt-foco);
}

/* 6. Semantic Status Pills (strictly for operational status & speed cycling) */
.bt-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--r-pill);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.2;
}

.bt-pill-ok {
  background-color: var(--bt-ok-fundo);
  color: var(--bt-ok);
}

.bt-pill-warn {
  background-color: var(--bt-aviso-fundo);
  color: var(--bt-aviso);
}

.bt-pill-err {
  background-color: var(--bt-risco-fundo);
  color: var(--bt-risco);
}

/* Respect reduced motion across all transitions and animations */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
