/* ============================================================
   Spadki - design system
   Paleta: granat magistracki + burgund + stare złoto (prawo = powaga)
   Typografia: Cormorant Garamond (display) + Outfit (body)
   ============================================================ */

:root {
  /* Light theme - krem pergaminowy */
  --bg: #faf7f1;
  --bg-alt: #f2ede2;
  --card: #fffdf8;
  --card-border: #e5ddcc;
  --text: #23232b;
  --muted: #5f5d63;
  --heading: #1d2a4a;

  /* Brand */
  --navy: #1d2a4a;
  --navy-deep: #141d35;
  --navy-soft: #2a3a63;
  --burgundy: #7c2d3e;
  --burgundy-soft: #9c4254;
  --gold: #b08a3e;
  --gold-light: #d4b878;

  /* Semantic */
  --accent: var(--burgundy);
  --accent-soft: #f3e3e6;
  --accent-light: rgba(124, 45, 62, 0.09);
  --gold-subtle: rgba(176, 138, 62, 0.16);

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Outfit', system-ui, sans-serif;

  --header-height: 60px;
  --sidebar-w: 300px;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: all .2s ease-out;

  --shadow-card: 0 1px 2px rgba(29, 42, 74, 0.05), 0 4px 16px rgba(29, 42, 74, 0.06);
  --shadow-card-hover: 0 2px 4px rgba(29, 42, 74, 0.07), 0 10px 28px rgba(29, 42, 74, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --bg-alt: #171a22;
    --card: #1c1f28;
    --card-border: #2a2e3a;
    --text: #e8e6e0;
    --muted: #a6a39b;
    --heading: #e2e6f0;
    --navy: #232f52;
    --navy-deep: #10131c;
    --navy-soft: #33426e;
    --burgundy: #a8455a;
    --burgundy-soft: #c05c71;
    --gold: #c9a55e;
    --gold-light: #e0c58d;
    --accent: var(--burgundy);
    --accent-soft: #33202a;
    --accent-light: rgba(168, 69, 90, 0.14);
    --gold-subtle: rgba(201, 165, 94, 0.12);
    --shadow-card: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --shadow-card-hover: 0 2px 4px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.45);
  }
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 700px 500px at 92% -5%, var(--accent-light), transparent 60%),
    radial-gradient(ellipse 600px 450px at -8% 108%, var(--gold-subtle), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--burgundy); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--heading);
  line-height: 1.2;
  text-wrap: balance;
}

/* ---------- HEADER ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
  z-index: 100;
}
.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: .35;
  pointer-events: none;
}
.logo-mark { font-size: 1.3rem; line-height: 1; }
.logo-text { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.logo-text a { color: var(--heading); text-decoration: none; }
.logo-accent { color: var(--burgundy); }
.header-search {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 6px 14px;
  width: min(320px, 42vw);
  transition: var(--transition);
}
.header-search:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-subtle); }
.search-icon { font-size: .85rem; opacity: .6; }
.header-search input {
  border: none; outline: none; background: transparent;
  font-family: var(--font-body); font-size: .92rem;
  color: var(--text); width: 100%;
}
.search-results {
  position: fixed;
  top: calc(var(--header-height) + 8px);
  right: 20px;
  width: min(420px, calc(100vw - 40px));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card-hover);
  z-index: 99;
  max-height: 60vh;
  overflow-y: auto;
  display: none;
}
.search-results.open { display: block; }
.search-results a {
  display: block; padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text); text-decoration: none;
}
.search-results a:last-child { border-bottom: none; }
.search-results a:hover { background: var(--accent-light); }
.search-results .sr-title { font-weight: 600; font-size: .9rem; }
.search-results .sr-excerpt { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.search-results .sr-none { padding: 14px; color: var(--muted); font-size: .9rem; }

/* ---------- MOBILE MENU ---------- */
.mobile-menu-btn {
  display: none;
  background: none; border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  font-size: 1.05rem; cursor: pointer; color: var(--text);
  transition: var(--transition);
}
.mobile-menu-btn:hover { border-color: var(--gold); background: var(--gold-subtle); }
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20, 22, 28, 0.55);
  z-index: 98;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--bg-alt);
  border-right: 1px solid var(--card-border);
  padding: 16px 10px 40px;
  z-index: 97;
  scrollbar-width: thin;
}
.sidebar-nav { list-style: none; }
.sidebar-nav li { margin: 1px 0; }
.sidebar-nav .nav-section {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 16px 12px 5px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: .9rem;
  color: var(--text);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  text-decoration: none;
  line-height: 1.35;
}
.sidebar-nav a:hover { background: var(--accent-light); color: var(--burgundy); }
.sidebar-nav a.active {
  background: var(--navy);
  color: #f4f1ea;
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .sidebar-nav a.active { background: var(--navy-soft); color: #fff; }
}
.sidebar-nav a .nav-icon { flex-shrink: 0; font-size: .85rem; }

/* ---------- MAIN ---------- */
.main-content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--header-height) + 36px) 32px 60px;
  max-width: 860px;
}
@media (min-width: 1300px) {
  .main-content { max-width: 940px; }
}

.loading { display: flex; justify-content: center; padding: 80px 0; }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--card-border);
  border-top-color: var(--burgundy);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Page transition */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.page-enter { animation: fadeUp .25s ease-out; }

/* ---------- HOME / HERO ---------- */
.home-hero {
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 55%, #24345e 100%);
  border-radius: var(--radius);
  padding: 44px 40px 38px;
  margin-bottom: 34px;
  position: relative;
  overflow: hidden;
  color: #efe9dc;
}
.home-hero::before {
  content: '';
  position: absolute;
  top: -120px; right: -80px;
  width: 340px; height: 340px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 165, 94, 0.22), transparent 65%);
  pointer-events: none;
}
.home-hero::after {
  content: '§';
  position: absolute;
  right: 26px; bottom: -46px;
  font-family: var(--font-display);
  font-size: 13rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.045);
  pointer-events: none;
  user-select: none;
}
.home-hero h1 {
  font-size: clamp(2rem, 4.4vw, 2.9rem);
  font-weight: 700;
  color: #f7f3ea;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}
.home-hero h1 .hero-accent { color: var(--gold-light); }
.home-hero p {
  font-size: 1.05rem;
  color: rgba(239, 233, 220, 0.86);
  max-width: 560px;
  position: relative;
  z-index: 1;
}
.hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
  position: relative;
  z-index: 1;
}
.hero-fact {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(212, 184, 120, 0.3);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: .85rem;
  font-weight: 500;
  color: #f0e9da;
}
.hero-fact b { color: var(--gold-light); font-weight: 700; }

.home-grid h2.section-label {
  font-family: var(--font-body);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 34px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--card-border);
}
.home-grid h2.section-label:first-child { margin-top: 0; padding-top: 0; border-top: none; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.home-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  text-decoration: none;
}
.home-card::after {
  content: '';
  position: absolute;
  left: 18px; right: 18px; bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), var(--burgundy));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .25s ease-out;
}
.home-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  text-decoration: none;
  border-color: var(--gold);
}
.home-card:hover::after { transform: scaleX(1); }
.home-card .card-icon { font-size: 1.15rem; }
.home-card h3 {
  font-size: .95rem;
  font-weight: 600;
  color: var(--heading);
  margin: 7px 0 5px;
  line-height: 1.35;
}
.home-card p {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- ARTICLE PAGE ---------- */
.content-article { max-width: 780px; }
.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.category-badge {
  display: inline-block;
  background: var(--gold-subtle);
  color: var(--gold);
  border: 1px solid rgba(176, 138, 62, 0.35);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
}
.read-time { font-size: .8rem; color: var(--muted); }
.content-article h1 {
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  font-weight: 700;
  margin-bottom: 14px;
}
.article-rule {
  border: none;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent 70%);
  margin: 4px 0 26px;
  opacity: .6;
}
.content-article h2 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 34px 0 12px;
  padding-top: 6px;
}
.content-article h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 24px 0 8px;
  color: var(--navy);
}
@media (prefers-color-scheme: dark) { .content-article h3 { color: var(--heading); } }
.content-article p { margin: 0 0 15px; }
.content-article ul, .content-article ol { margin: 0 0 16px 24px; }
.content-article li { margin-bottom: 6px; }
.content-article strong { color: var(--heading); }

/* TOC */
.toc {
  background: var(--bg-alt);
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin: 8px 0 26px;
}
.toc summary {
  font-weight: 600;
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--navy);
  cursor: pointer;
  list-style: none;
}
.toc summary::-webkit-details-marker { display: none; }
.toc summary::before { content: '▸ '; color: var(--gold); }
.toc[open] summary::before { content: '▾ '; }
.toc ul { list-style: none; margin: 10px 0 0; }
.toc li { margin: 4px 0; }
.toc a { color: var(--text); font-size: .9rem; }
.toc a:hover { color: var(--burgundy); }

/* Info box */
.info-box {
  background: var(--accent-light);
  border: 1px solid rgba(124, 45, 62, 0.25);
  border-left: 4px solid var(--burgundy);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 18px 0;
  font-size: .95rem;
}
.info-box strong { color: var(--burgundy); }
.info-box.tip {
  background: var(--gold-subtle);
  border-color: rgba(176, 138, 62, 0.3);
  border-left-color: var(--gold);
}
.info-box.tip strong { color: var(--gold); }

/* Warning box */
.warn-box {
  background: #fdf3ec;
  border: 1px solid #e8c9b8;
  border-left: 4px solid #c2571b;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 18px 0;
  font-size: .95rem;
}
.warn-box strong { color: #b04a12; }
@media (prefers-color-scheme: dark) {
  .warn-box { background: #2b2018; border-color: #4a3526; }
  .warn-box strong { color: #e08a55; }
}

/* Tables */
.table-responsive { overflow-x: auto; margin: 18px 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  background: var(--card);
}
.error-table { /* legacy alias */ }
th {
  background: var(--navy);
  color: #f4f1ea;
  text-align: left;
  font-weight: 600;
  padding: 10px 14px;
  font-size: .88rem;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: top;
}
tr:nth-child(even) td { background: var(--bg-alt); }
tr:hover td { background: var(--accent-light); }

/* FAQ */
.faq-item {
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 15px 18px;
  margin: 12px 0;
}
.faq-item h3 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  margin: 0 0 8px;
}
@media (prefers-color-scheme: dark) { .faq-item h3 { color: var(--heading); } }
.faq-item p { margin: 0; font-size: .95rem; }

/* Glossary */
.glossary-list dl { margin: 0; }
.glossary-list dt {
  font-weight: 600;
  color: var(--burgundy);
  margin: 16px 0 4px;
  font-size: 1rem;
}
.glossary-list dd { margin: 0 0 6px; font-size: .95rem; color: var(--text); }

/* Steps */
.steps { counter-reset: step; list-style: none; margin: 0 0 16px; }
.steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 14px 44px;
  margin-bottom: 4px;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--gold-light);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  display: flex; align-items: center; justify-content: center;
}

/* Prev / next */
.article-nav {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--card-border);
  font-size: .9rem;
}
.article-nav a {
  color: var(--muted);
  max-width: 45%;
}
.article-nav a:hover { color: var(--burgundy); }
.article-nav .nav-next { text-align: right; }

/* ---------- FOOTER ---------- */
.site-footer {
  margin-left: var(--sidebar-w);
  background: var(--navy-deep);
  color: rgba(239, 233, 220, 0.8);
  padding: 40px 32px 30px;
  border-top: 3px solid var(--gold);
}
.site-footer a { color: var(--gold-light); }
.footer-inner { max-width: 940px; margin: 0 auto; }
.footer-brand { margin-bottom: 22px; }
.footer-logo {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: #f4f1ea;
}
.footer-brand p { font-size: .88rem; margin-top: 6px; max-width: 520px; }
.footer-cols {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.footer-col h4 {
  font-family: var(--font-body);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold-light);
  margin-bottom: 10px;
}
.footer-col a { display: block; font-size: .88rem; margin-bottom: 6px; }
.footer-note { font-size: .78rem; opacity: .6; border-top: 1px solid rgba(255,255,255,.12); padding-top: 16px; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease-out;
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    width: min(320px, 84vw);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .mobile-menu-btn { display: block; }
  .main-content { margin-left: 0; padding: calc(var(--header-height) + 24px) 18px 50px; }
  .site-footer { margin-left: 0; padding: 34px 20px 26px; }
  .home-hero { padding: 32px 24px 28px; }
}

@media (max-width: 600px) {
  .header-search { width: auto; flex: 1; }
  .search-results { right: 12px; width: calc(100vw - 24px); }
  .card-grid { grid-template-columns: 1fr; }
  .content-article h1 { font-size: 1.75rem; }
  .hero-facts { gap: 8px; }
  .hero-fact { font-size: .8rem; padding: 5px 11px; }
  .article-nav { flex-direction: column; }
  .article-nav .nav-next { text-align: left; }
}

/* ---------- ACCESSIBILITY ---------- */
.skip-link {
  position: absolute;
  top: -48px; left: 12px;
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 200;
  font-size: .9rem;
  transition: top .15s ease-out;
}
.skip-link:focus { top: 10px; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
