/* ============================================================
   Polisa - design system
   Premium magazine style: warm cream + ink navy + amber accent
   Typografia: Spectral (display) + Work Sans (body)
   ============================================================ */

:root {
  /* Light theme */
  --bg: #f6f3ec;
  --bg-card: #fffdf8;
  --bg-sunken: #efe9dd;
  --ink: #1d2733;
  --ink-soft: #3d4754;
  --muted: #5d6672;
  --line: #e2dacb;
  --accent: #b45309;
  --accent-strong: #92400e;
  --accent-soft: #fdeed9;
  --accent-subtle: rgba(180, 83, 9, 0.16);
  --gold: #c99a2e;
  --ok: #1f7a4d;
  --ok-soft: #e2f2e9;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --header-h: 64px;
  --sidebar-w: 292px;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-card: 0 1px 2px rgba(29, 39, 51, 0.05), 0 6px 24px -12px rgba(29, 39, 51, 0.14);
  --shadow-card-hover: 0 2px 4px rgba(29, 39, 51, 0.06), 0 14px 34px -14px rgba(180, 83, 9, 0.28);
  --font-display: "Spectral", Georgia, serif;
  --font-body: "Work Sans", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --bg-card: #171e26;
    --bg-sunken: #0c1015;
    --ink: #ece7dd;
    --ink-soft: #c9c2b4;
    --muted: #a49c8e;
    --line: #2a333e;
    --accent: #f59e0b;
    --accent-strong: #fbbf24;
    --accent-soft: #2a2113;
    --accent-subtle: rgba(245, 158, 11, 0.18);
    --gold: #d9b34a;
    --ok: #4ade80;
    --ok-soft: #14281c;
    --bad: #f87171;
    --bad-soft: #2b1616;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px -12px rgba(0, 0, 0, 0.5);
    --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 16px 38px -14px rgba(245, 158, 11, 0.22);
    color-scheme: dark;
  }
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(52rem 30rem at -12% -8%, var(--accent-subtle), transparent 60%),
    radial-gradient(46rem 28rem at 112% 108%, var(--accent-subtle), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.22; text-wrap: balance; margin: 0 0 0.5em; }
h1 { font-size: 2.35rem; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 1.55rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.18rem; font-weight: 600; }
p { margin: 0 0 1.05em; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img { max-width: 100%; height: auto; }
strong { font-weight: 600; }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 200;
  background: var(--accent-strong); color: #fff; padding: 10px 16px;
  border-radius: var(--radius-sm); font-weight: 600;
}
.skip-link:focus { left: 8px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Header ---------- */
.app-header {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-subtle), transparent);
  opacity: 0.9;
}
.header-inner {
  max-width: 1320px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 18px; padding: 0 22px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.5rem; line-height: 1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.32rem; letter-spacing: -0.02em; }
.brand-name em { font-style: normal; color: var(--accent); }

.menu-btn {
  display: none; flex-direction: column; gap: 5px;
  background: none; border: 0; cursor: pointer; padding: 8px;
}
.menu-btn span { width: 22px; height: 2px; background: var(--ink); border-radius: 2px; transition: transform 0.2s var(--ease), opacity 0.2s; }
.menu-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.search-wrap { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search-input {
  width: 100%; padding: 9px 16px; font-family: var(--font-body); font-size: 0.92rem;
  color: var(--ink); background: var(--bg-card); border: 1px solid var(--line);
  border-radius: 999px; transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; z-index: 120;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card-hover); max-height: 380px; overflow-y: auto;
  display: none;
}
.search-results.open { display: block; }
.search-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: var(--accent-soft); text-decoration: none; }
.search-item .si-title { font-weight: 600; font-size: 0.92rem; }
.search-item .si-section { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.search-empty { padding: 14px; color: var(--muted); font-size: 0.9rem; }

.header-tagline { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  max-width: 1320px; margin: 0 auto;
  padding-top: calc(var(--header-h) + 28px);
  gap: 42px;
}

.sidebar {
  position: sticky; top: calc(var(--header-h) + 24px);
  align-self: start; max-height: calc(100vh - var(--header-h) - 48px);
  overflow-y: auto; padding: 4px 6px 24px 0;
  scrollbar-width: thin;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 18px; }
.side-group { display: flex; flex-direction: column; }
.side-group-title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted); margin: 0 0 6px; padding: 0 10px;
}
.side-group-title::after { content: ""; display: block; height: 1px; background: var(--line); margin-top: 6px; }
.sidebar-link {
  display: flex; align-items: center; gap: 9px;
  font-size: 0.9rem; line-height: 1.35; color: var(--ink-soft);
  padding: 6px 10px; border-radius: 8px;
  border-left: 2px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar-link .s-icon { font-size: 0.95rem; flex-shrink: 0; }
.sidebar-link:hover { background: var(--accent-soft); color: var(--ink); text-decoration: none; }
.sidebar-link.active {
  background: var(--accent-soft); color: var(--accent-strong);
  border-left-color: var(--accent); font-weight: 600;
}

.sidebar-overlay { display: none; }

/* ---------- Main content ---------- */
.main-content { min-width: 0; padding-bottom: 70px; }
.app-content { animation: fadeUp 0.28s var(--ease) both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Home: hero ---------- */
.home-hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-strong) 0%, var(--accent) 55%, var(--gold) 130%);
  color: #fff; border-radius: var(--radius);
  padding: 44px 44px 38px; margin-bottom: 34px;
  box-shadow: var(--shadow-card-hover);
}
.home-hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(30rem 18rem at 88% -20%, rgba(255, 255, 255, 0.28), transparent 60%),
    radial-gradient(24rem 16rem at -10% 120%, rgba(255, 255, 255, 0.16), transparent 55%);
}
.home-hero .hero-inner { position: relative; z-index: 1; max-width: 720px; }
.home-hero .hero-eyebrow {
  display: inline-block; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 5px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.3);
  margin-bottom: 16px;
}
.home-hero h1 { color: #fff; font-size: 2.6rem; margin-bottom: 12px; }
.home-hero .hero-sub { font-size: 1.08rem; opacity: 0.94; margin-bottom: 24px; max-width: 600px; }
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-body); font-size: 0.95rem; font-weight: 600;
  padding: 11px 22px; border-radius: 999px; border: 0; cursor: pointer;
  transition: transform 0.18s var(--ease), box-shadow 0.18s, background 0.18s;
}
.btn:hover { transform: translateY(-2px); text-decoration: none; }
.btn-primary { background: #fff; color: var(--accent-strong); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }
.btn-primary:hover { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24); }
.btn-ghost { background: rgba(255, 255, 255, 0.14); color: #fff; border: 1px solid rgba(255, 255, 255, 0.4); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.22); }

.hero-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin-top: 30px; padding-top: 24px; border-top: 1px solid rgba(255, 255, 255, 0.25);
}
.hero-stat .hs-num { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.hero-stat .hs-label { font-size: 0.82rem; opacity: 0.9; }

/* ---------- Home: sections & cards ---------- */
.home-section { margin-bottom: 40px; }
.home-section h2 {
  display: flex; align-items: baseline; gap: 10px;
  font-size: 1.45rem; margin-bottom: 6px;
}
.home-section h2 .sec-count {
  font-family: var(--font-body); font-size: 0.78rem; font-weight: 700;
  color: var(--accent-strong); letter-spacing: 0.05em;
}
.home-section .sec-desc { color: var(--muted); font-size: 0.95rem; margin-bottom: 16px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 14px; }

.home-card {
  position: relative; display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 17px; color: var(--ink);
  box-shadow: var(--shadow-card);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s;
}
.home-card::before {
  content: ""; position: absolute; top: 0; left: 18px; right: 18px; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 0 0 4px 4px; opacity: 0; transition: opacity 0.2s;
}
.home-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); text-decoration: none; }
.home-card:hover::before { opacity: 1; }
.home-card .hc-icon { font-size: 1.35rem; line-height: 1.2; }
.home-card h3 { font-size: 0.95rem; font-weight: 600; margin: 0; }
.home-card p { font-size: 0.85rem; color: var(--muted); margin: 0; line-height: 1.55; }
.home-card .hc-more {
  margin-top: 4px; font-size: 0.8rem; font-weight: 600; color: var(--accent-strong);
  display: inline-flex; align-items: center; gap: 4px;
}
.home-card .hc-more .arrow { transition: transform 0.2s var(--ease); }
.home-card:hover .hc-more .arrow { transform: translateX(4px); }

/* ---------- Article page ---------- */
.article-header { margin-bottom: 26px; }
.breadcrumbs { font-size: 0.8rem; color: var(--muted); margin-bottom: 12px; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs a:hover { color: var(--accent-strong); }
.breadcrumbs .sep { margin: 0 6px; opacity: 0.6; }
.article-header h1 { font-size: 2.1rem; margin-bottom: 8px; }
.article-header .article-excerpt { font-size: 1.06rem; color: var(--ink-soft); max-width: 720px; }
.article-meta {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--muted); margin-top: 12px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.article-meta .tag {
  background: var(--accent-soft); color: var(--accent-strong);
  font-weight: 600; padding: 3px 11px; border-radius: 999px; font-size: 0.75rem;
}

.article-body { max-width: 780px; }
.article-body > h2 {
  margin-top: 1.6em; padding-top: 0.4em;
  border-bottom: 2px solid var(--line); padding-bottom: 0.35em;
}
.article-body h2 .toc-anchor { scroll-margin-top: calc(var(--header-h) + 18px); }
.article-body ul, .article-body ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.article-body li { margin-bottom: 0.45em; }
.article-body a { font-weight: 500; }

/* Article TOC */
.article-toc {
  background: var(--bg-sunken); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px 20px; margin: 0 0 26px; max-width: 780px;
}
.article-toc summary { cursor: pointer; font-weight: 700; font-family: var(--font-display); font-size: 1.02rem; }
.article-toc ol { margin: 10px 0 2px; padding-left: 1.3em; }
.article-toc li { margin-bottom: 4px; font-size: 0.92rem; }
.article-toc a { color: var(--ink-soft); }
.article-toc a:hover { color: var(--accent-strong); }

/* Info box */
.info-box {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; margin: 0 0 1.2em; font-size: 0.95rem;
}
.info-box strong { color: var(--accent-strong); }

/* Tables */
.table-responsive { overflow-x: auto; margin: 0 0 1.3em; border-radius: var(--radius-sm); }
.error-table {
  width: 100%; border-collapse: collapse; font-size: 0.9rem;
  background: var(--bg-card); border: 1px solid var(--line);
}
.error-table th {
  background: var(--bg-sunken); font-weight: 700; text-align: left;
  padding: 10px 14px; border-bottom: 2px solid var(--line); font-size: 0.85rem;
}
.error-table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.error-table tr:last-child td { border-bottom: 0; }
.error-table tbody tr:hover { background: var(--accent-soft); }
.error-table .best { background: var(--ok-soft); font-weight: 600; }

/* FAQ */
.faq-item {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-card); padding: 16px 18px; margin-bottom: 12px;
  max-width: 780px;
}
.faq-item h3 { font-size: 1.04rem; margin-bottom: 6px; }
.faq-item h3::before { content: "Q: "; color: var(--accent); }
.faq-item p { margin: 0; font-size: 0.95rem; }
.faq-item p::first-letter { }

/* Glossary */
.glossary { max-width: 780px; }
.glossary dl { margin: 0; }
.glossary dt {
  font-weight: 700; font-family: var(--font-display); font-size: 1.06rem;
  margin-top: 18px; padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
.glossary dt::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-right: 9px; }
.glossary dd { margin: 6px 0 0 17px; font-size: 0.95rem; color: var(--ink-soft); }

/* Comparison callout */
.compare-note {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--ok-soft); border-left: 4px solid var(--ok);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; margin: 0 0 1.2em; font-size: 0.95rem;
}

/* Prev / Next */
.article-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line);
  max-width: 780px;
}
.article-nav a {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 18px; color: var(--ink);
  transition: transform 0.18s var(--ease), border-color 0.18s, box-shadow 0.18s;
}
.article-nav a:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: var(--shadow-card); text-decoration: none; }
.article-nav .an-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.article-nav .an-title { font-weight: 600; font-size: 0.95rem; }
.article-nav .next { text-align: right; }

/* ---------- Footer ---------- */
.app-footer {
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
  margin-top: 20px;
}
.footer-inner { max-width: 1320px; margin: 0 auto; padding: 30px 22px 34px; }
.footer-inner p { margin: 0 0 8px; font-size: 0.9rem; }
.footer-note { color: var(--muted); font-size: 0.82rem !important; max-width: 760px; }
.footer-copy { color: var(--muted); font-size: 0.8rem !important; margin-bottom: 0 !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .header-tagline { display: none; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 0; padding-top: calc(var(--header-h) + 18px); }
  .menu-btn { display: flex; }
  .sidebar {
    position: fixed; top: var(--header-h); bottom: 0; left: 0; width: min(320px, 84vw);
    background: var(--bg-card); border-right: 1px solid var(--line);
    padding: 20px 18px; z-index: 90;
    transform: translateX(-105%); transition: transform 0.26s var(--ease);
    max-height: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(0, 0, 0, 0.18); }
  .sidebar-overlay {
    display: block; position: fixed; inset: var(--header-h) 0 0 0; z-index: 80;
    background: rgba(10, 14, 18, 0.45); opacity: 0; pointer-events: none;
    transition: opacity 0.26s;
  }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }
  .main-content { padding: 0 16px 60px; }
  .home-hero { padding: 32px 26px; }
  .home-hero h1 { font-size: 2rem; }
  .hero-stats { grid-template-columns: 1fr; gap: 10px; }
  .header-inner { padding: 0 14px; gap: 12px; }
  .search-wrap { max-width: none; }
}

@media (max-width: 600px) {
  body { font-size: 16.5px; }
  h1 { font-size: 1.85rem; }
  .article-header h1 { font-size: 1.7rem; }
  .brand-name { font-size: 1.15rem; }
  .brand-mark { font-size: 1.25rem; }
  .article-nav { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .error-table { font-size: 0.83rem; }
}

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