/* ===================================================
   CÁLCULO DIFERENCIAL — Design System Base
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Color Tokens --- */
:root {
  /* Backgrounds */
  --bg-base:        #ffffff;
  --bg-surface:     #f8fafc;
  --bg-card:        #ffffff;
  --bg-elevated:    #f1f5f9;
  --bg-hover:       #e2e8f0;

  /* Brand gradient: deep indigo → violet */
  --brand-from:     #6c63ff;
  --brand-to:       #a78bfa;
  --brand-mid:      #8b7cf8;
  --brand-glow:     rgba(108, 99, 255, 0.15);

  /* Accent colors */
  --accent-teal:    #06b6d4;
  --accent-amber:   #d97706;
  --accent-rose:    #e11d48;
  --accent-green:   #16a34a;
  --accent-orange:  #ea580c;

  /* Text */
  --text-primary:   #09090b;
  --text-secondary: #27272a;
  --text-muted:     #52525b;
  --text-inverse:   #ffffff;

  /* Borders */
  --border-subtle:  rgba(15, 23, 42, 0.08);
  --border-normal:  rgba(15, 23, 42, 0.15);
  --border-strong:  rgba(108, 99, 255, 0.3);

  /* Semantic */
  --success:        #16a34a;
  --error:          #e11d48;
  --warning:        #d97706;
  --info:           #06b6d4;

  /* Typography */
  --font-sans:      'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:      'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs:  0.25rem;
  --space-sm:  0.5rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --space-xl:  2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Border radius */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.6);
  --shadow-brand: 0 4px 24px rgba(108,99,255,0.3);
  --shadow-glow:  0 0 40px rgba(108,99,255,0.15);

  /* Transitions */
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in:    cubic-bezier(0.4, 0, 1, 1);
  --ease-inout: cubic-bezier(0.45, 0, 0.55, 1);
  --duration-fast:   150ms;
  --duration-normal: 250ms;
  --duration-slow:   400ms;

  /* Layout */
  --content-max-width: 1280px;
  --sidebar-width:     260px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar */
::-webkit-scrollbar        { width: 6px; height: 6px; }
::-webkit-scrollbar-track  { background: var(--bg-base); }
::-webkit-scrollbar-thumb  { background: var(--bg-elevated); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--brand-from); }

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
h3 { font-size: clamp(1.1rem, 2.5vw, 1.4rem); }
h4 { font-size: 1.1rem; }

p { color: var(--text-secondary); margin-bottom: var(--space-md); }
p:last-child { margin-bottom: 0; }

strong { color: var(--text-primary); font-weight: 600; }
em     { color: var(--brand-to); font-style: italic; }

a {
  color: var(--brand-mid);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}
a:hover { color: var(--brand-to); text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-elevated);
  color: var(--accent-teal);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}

pre {
  font-family: var(--font-mono);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* --- Gradient Text Utility --- */
.gradient-text {
  background: linear-gradient(135deg, var(--brand-from), var(--brand-to));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  transition: border-color var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-brand);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-out);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--brand-from), var(--brand-to));
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover {
  filter: brightness(1.12);
  box-shadow: 0 6px 28px rgba(108,99,255,0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-normal);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--brand-from);
  color: var(--brand-to);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
}
.badge-brand   { background: var(--brand-glow); color: var(--brand-to); border: 1px solid rgba(108,99,255,0.3); }
.badge-teal    { background: rgba(34,211,238,0.1); color: var(--accent-teal); border: 1px solid rgba(34,211,238,0.25); }
.badge-amber   { background: rgba(251,191,36,0.1); color: var(--accent-amber); border: 1px solid rgba(251,191,36,0.25); }
.badge-green   { background: rgba(74,222,128,0.1); color: var(--accent-green); border: 1px solid rgba(74,222,128,0.25); }
.badge-rose    { background: rgba(244,63,94,0.1); color: var(--accent-rose); border: 1px solid rgba(244,63,94,0.25); }

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-xl) 0;
}

/* --- Progress bar --- */
.progress-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-from), var(--brand-to));
  border-radius: var(--radius-full);
  transition: width 0.6s var(--ease-out);
}

/* --- KaTeX overrides for dark mode --- */
.katex { color: var(--text-primary); }
.katex-display { 
  margin: var(--space-lg) 0; 
  overflow-x: auto;
  overflow-y: hidden;
}
.katex-display > .katex { padding: var(--space-md); }

/* --- Animations --- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(108,99,255,0); }
  50%       { box-shadow: 0 0 30px rgba(108,99,255,0.3); }
}
@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50%       { transform: translateY(-6px); }
}

.anim-fade-up    { animation: fadeInUp 0.5s var(--ease-out) both; }
.anim-fade-in    { animation: fadeIn   0.4s var(--ease-out) both; }
.anim-float      { animation: float    3s ease-in-out infinite; }

/* Stagger delays */
.delay-1  { animation-delay: 0.1s; }
.delay-2  { animation-delay: 0.2s; }
.delay-3  { animation-delay: 0.3s; }
.delay-4  { animation-delay: 0.4s; }
.delay-5  { animation-delay: 0.5s; }

/* --- Utility classes --- */
.text-center  { text-align: center; }
.text-left    { text-align: left; }
.text-right   { text-align: right; }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: 0.875rem; }
.text-xs      { font-size: 0.75rem; }
.text-lg      { font-size: 1.125rem; }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-sm       { gap: var(--space-sm); }
.gap-md       { gap: var(--space-md); }
.gap-lg       { gap: var(--space-lg); }

.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;
}
.badge-brand { 
  background: rgba(108,99,255,.08); 
  color: var(--brand-to); 
  border: 1px solid rgba(108,99,255,.2); 
}

/* ════════════════════════════════════════════
   STANDARDIZED PAGE HEADER
════════════════════════════════════════════ */
.page-header {
  margin: 0 auto 2.5rem;
  max-width: var(--content-max-width, 1280px);
}
.page-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}
.page-title {
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -0.03em;
  margin-bottom: 0.75rem;
  line-height: 1.1;
  color: var(--text-primary);
}
.page-desc {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 650px;
  line-height: 1.6;
  margin: 0;
}

/* ════════════════════════════════════════════
   GLOBAL SIDEBAR NAVIGATION (Injected via JS)
════════════════════════════════════════════ */
body.nav-enabled {
  padding-left: 260px; /* Make room for the sidebar */
}
@media (max-width: 768px) {
  body.nav-enabled { padding-left: 0; }
}

.sidebar-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-primary);
  text-decoration: none;
  display: flex;
  align-items: center;
}

.sidebar-menu {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
}

.sidebar-link {
  padding: 0.75rem 1.5rem;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.03);
  color: var(--brand-to);
}

.sidebar-accordion {
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.accordion-btn {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0.85rem 1.5rem;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.2s;
}
.accordion-btn:hover { background: rgba(255,255,255,0.03); }

.accordion-btn .arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
  color: var(--text-muted);
}
.accordion-btn.active .arrow { transform: rotate(180deg); }

.accordion-content {
  display: none;
  background: rgba(0,0,0,0.2);
  padding: 0.5rem 0;
}
.accordion-content.show {
  display: block;
}

.accordion-content a {
  display: block;
  padding: 0.5rem 1.5rem 0.5rem 2.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}
.accordion-content a:hover, .accordion-content a.current {
  color: var(--brand-to);
}
