/* ==========================================================================
   Dach - Design system
   Paleta: terakota dachówki + antracyt blachodachówki + drewno + krem
   Typografia: Bricolage Grotesque (display) + Hanken Grotesk (body) + IBM Plex Mono
   ========================================================================== */

:root {
  /* Light theme - krem, drewno, terakota */
  --bg: #f7f3ec;
  --bg-soft: #efe8dc;
  --card: #fffdf8;
  --card-border: #e3d9c8;
  --text: #2a2420;
  --text-soft: #5c534a;
  --muted: #7a6f63;
  --ink: #1d1a17;
  --accent: #b3451f;          /* terakota dachówki */
  --accent-strong: #94370f;
  --accent-soft: #e8c9b8;
  --wood: #c98a2b;            /* drewno więźby */
  --anthracite: #3a3d42;      /* blachodachówka */
  --anthracite-soft: #6b7078;
  --header-bg: #f7f3ec;
  --sidebar-bg: #f2ece1;
  --shadow: 0 1px 2px rgba(29,26,23,.06), 0 8px 24px rgba(29,26,23,.06);
  --shadow-hover: 0 4px 12px rgba(29,26,23,.1), 0 16px 40px rgba(29,26,23,.1);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 60px;
  --sidebar-w: 290px;
  --transition: .2s ease-out;
  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Hanken Grotesk', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --bg-soft: #1d1915;
    --card: #201c17;
    --card-border: #332c25;
    --text: #eae3d8;
    --text-soft: #c4b9ab;
    --muted: #a29584;
    --ink: #f2ece2;
    --accent: #e0713f;
    --accent-strong: #f08250;
    --accent-soft: #4a2e1e;
    --wood: #e0a54f;
    --anthracite: #a8aeb8;
    --anthracite-soft: #8d939c;
    --header-bg: #16130f;
    --sidebar-bg: #1b1713;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    --shadow-hover: 0 4px 12px rgba(0,0,0,.5), 0 16px 40px rgba(0,0,0,.45);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; overflow-x: clip; }
body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60vw 40vh at 90% -5%, rgba(201,138,43,.14), transparent 60%),
    radial-gradient(ellipse 50vw 35vh at -10% 105%, rgba(179,69,31,.1), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 0 0 8px 0;
  font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--header-bg);
  border-bottom: 1px solid var(--card-border);
  backdrop-filter: blur(10px);
}
.app-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(179,69,31,.35), rgba(201,138,43,.35), transparent);
  opacity: .5; pointer-events: none;
}
.header-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 20px;
  height: var(--header-h);
  display: flex; align-items: center; gap: 24px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 800; font-size: 1.35rem;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 1.4rem; line-height: 1; }
.brand-text em {
  font-style: normal; color: var(--accent);
  background: linear-gradient(135deg, var(--accent), var(--wood));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.header-search { flex: 1; max-width: 480px; margin-left: auto; position: relative; }
.header-search input {
  width: 100%; padding: .55rem 1rem .55rem 2.4rem;
  border: 1px solid var(--card-border); border-radius: 999px;
  background: var(--card); color: var(--text); font-size: .95rem; font-family: var(--font-body);
}
.header-search input::placeholder { color: var(--muted); }
.header-search::before {
  content: '⌕'; position: absolute; left: .9rem; top: 50%; transform: translateY(-50%);
  font-size: 1.15rem; color: var(--muted); pointer-events: none;
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 120;
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-hover); overflow: hidden;
}
.search-results a {
  display: flex; flex-direction: column; padding: .6rem .9rem;
  border-bottom: 1px solid var(--card-border); color: var(--text);
}
.search-results a:last-child { border-bottom: none; }
.search-results a:hover { background: var(--bg-soft); text-decoration: none; }
.sr-title { font-weight: 600; font-size: .95rem; }
.sr-section { font-size: .78rem; color: var(--muted); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .04em; }
.sr-none { padding: .8rem .9rem; color: var(--muted); font-size: .9rem; }

.menu-toggle {
  display: none; flex-direction: column; justify-content: center; gap: 5px;
  width: 44px; height: 44px; padding: 10px; background: none; border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); cursor: pointer;
}
.menu-toggle span { display: block; height: 2px; width: 100%; background: var(--text); transition: all .25s ease; }
.menu-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle.open span:nth-child(2) { opacity: 0; }
.menu-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- Layout ---------- */
.layout {
  display: flex; flex: 1;
  max-width: 1440px; width: 100%; margin: 0 auto;
}
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 22px 18px 32px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--card-border);
  scrollbar-width: thin;
}
.sidebar-nav { list-style: none; }
.sidebar-section-label {
  font-family: var(--font-mono); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
  padding: 18px 10px 6px; border-bottom: 1px solid var(--card-border); margin-bottom: 4px;
}
.sidebar-nav li:first-child .sidebar-section-label { padding-top: 4px; }
.sidebar-link {
  display: block; padding: .42rem .6rem; border-radius: 6px;
  font-size: .9rem; line-height: 1.35; color: var(--text-soft);
  border-left: 2px solid transparent;
}
.sidebar-link:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.sidebar-link.active {
  background: var(--accent-soft); color: var(--ink);
  border-left-color: var(--accent); font-weight: 600;
}
.sidebar-foot { margin-top: 24px; padding: 14px 10px; border-top: 1px solid var(--card-border); }
.sidebar-foot p { font-size: .8rem; color: var(--muted); line-height: 1.5; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
}

.main { flex: 1; min-width: 0; padding: 28px 34px 60px; }

/* ---------- Home hero ---------- */
.home-hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--ink) 0%, #2e2620 55%, #3a3230 100%);
  border-radius: var(--radius);
  padding: 48px 46px;
  margin-bottom: 40px;
  color: #f2ece2;
}
.home-hero::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse 80% 80% at 70% 30%, #000 30%, transparent 75%);
  pointer-events: none;
}
.hero-inner { display: flex; align-items: center; gap: 40px; position: relative; z-index: 1; }
.hero-copy { flex: 1; }
.hero-eyebrow {
  display: inline-block; font-family: var(--font-mono); font-size: .75rem;
  text-transform: uppercase; letter-spacing: .12em; color: var(--wood);
  background: rgba(201,138,43,.14); border: 1px solid rgba(201,138,43,.4);
  padding: .3rem .7rem; border-radius: 999px; margin-bottom: 16px;
}
.home-hero h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(2rem, 4.4vw, 3.1rem); line-height: 1.12;
  text-wrap: balance; margin-bottom: 14px;
}
.home-hero h1 .hl {
  color: var(--wood);
  background: linear-gradient(135deg, #f0b45a, #e0713f);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-sub { font-size: 1.08rem; color: #cfc4b4; max-width: 620px; margin-bottom: 22px; }
.hero-stats { display: flex; gap: 26px; flex-wrap: wrap; }
.hero-stat b {
  display: block; font-family: var(--font-display); font-weight: 800;
  font-size: 1.7rem; color: #fff; line-height: 1.1;
}
.hero-stat span { font-size: .8rem; color: #a89a86; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .05em; }
.hero-art { flex-shrink: 0; width: 300px; }

/* ---------- Home sections ---------- */
.home-section { margin-bottom: 40px; }
.home-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 2px solid var(--card-border); padding-bottom: 10px; margin-bottom: 18px;
}
.home-section-head h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 1.5rem;
  text-wrap: balance;
}
.home-section-head .count {
  font-family: var(--font-mono); font-size: .75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px;
}
.home-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); padding: 16px 18px;
  color: var(--text); position: relative; overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.home-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--wood));
  opacity: 0; transition: opacity var(--transition);
}
.home-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); text-decoration: none; }
.home-card:hover::before { opacity: 1; }
.card-icon { font-size: 1.4rem; line-height: 1; }
.home-card h3 { font-size: .95rem; font-weight: 700; line-height: 1.35; text-wrap: balance; }
.home-card p { font-size: .85rem; color: var(--text-soft); line-height: 1.5; }

/* ---------- Article ---------- */
.content-article {
  max-width: 780px;
  animation: fadeUp .25s ease-out;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.article-eyebrow {
  font-family: var(--font-mono); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .1em; color: var(--accent); margin-bottom: 8px; font-weight: 500;
}
.content-article h1 {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(1.7rem, 3.6vw, 2.4rem); line-height: 1.15;
  margin-bottom: 12px; text-wrap: balance;
}
.article-meta {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--card-border);
  font-size: .83rem; color: var(--muted);
}
.article-meta .tag {
  font-family: var(--font-mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  background: var(--accent-soft); color: var(--ink);
  padding: .2rem .6rem; border-radius: 999px;
}
.article-toc {
  background: var(--bg-soft); border: 1px solid var(--card-border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 16px 20px; margin-bottom: 26px;
}
.article-toc strong { font-family: var(--font-display); font-size: .95rem; display: block; margin-bottom: 8px; }
.article-toc ol { padding-left: 1.2rem; }
.article-toc li { margin-bottom: 4px; font-size: .92rem; }
.article-toc a { color: var(--text-soft); }
.article-toc a:hover { color: var(--accent-strong); }
.article-body { font-size: 1.02rem; }
.article-body h2 {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.4rem; margin: 34px 0 12px; padding-top: 6px;
  text-wrap: balance; scroll-margin-top: calc(var(--header-h) + 16px);
}
.article-body h3 {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.12rem; margin: 26px 0 10px;
  text-wrap: balance; scroll-margin-top: calc(var(--header-h) + 16px);
}
.article-body h4 { font-size: 1rem; font-weight: 700; margin: 20px 0 8px; }
.article-body p { margin-bottom: 14px; }
.article-body ul, .article-body ol { margin: 0 0 16px 1.3rem; }
.article-body li { margin-bottom: 6px; }
.article-body strong { font-weight: 700; }

/* info-box / warn-box */
.info-box, .warn-box {
  border-radius: var(--radius-sm); padding: 14px 18px; margin: 18px 0;
  font-size: .97rem; line-height: 1.6;
}
.info-box {
  background: rgba(201,138,43,.12); border: 1px solid rgba(201,138,43,.35);
  border-left: 4px solid var(--wood);
}
.warn-box {
  background: rgba(179,69,31,.1); border: 1px solid rgba(179,69,31,.35);
  border-left: 4px solid var(--accent);
}
.info-box strong, .warn-box strong { display: block; margin-bottom: 4px; }

/* tables */
.table-responsive { overflow-x: auto; margin: 18px 0; border-radius: var(--radius-sm); }
.info-table, .error-table {
  width: 100%; border-collapse: collapse; font-size: .93rem;
  background: var(--card);
}
.info-table th, .error-table th {
  background: var(--anthracite); color: #f2ece2;
  font-family: var(--font-display); font-weight: 700; font-size: .88rem;
  text-align: left; padding: 10px 14px; white-space: nowrap;
}
.info-table td, .error-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--card-border); vertical-align: top;
}
.info-table tr:nth-child(even) td, .error-table tr:nth-child(even) td { background: var(--bg-soft); }
.info-table tr:hover td, .error-table tr:hover td { background: var(--accent-soft); }
.table-responsive + p { margin-top: 4px; }

/* FAQ */
.faq-item {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); margin-bottom: 12px; overflow: hidden;
}
.faq-item summary {
  cursor: pointer; padding: 14px 18px; font-weight: 600; font-size: .98rem;
  list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+'; font-family: var(--font-mono); font-size: 1.2rem; color: var(--accent);
  transition: transform var(--transition); flex-shrink: 0;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item summary:hover { background: var(--bg-soft); }
.faq-item .faq-a { padding: 0 18px 16px; font-size: .97rem; line-height: 1.65; }

/* glossary */
.glossary { display: grid; gap: 0; margin: 16px 0; }
.glossary dt {
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  padding: 12px 16px 4px; color: var(--accent-strong);
}
.glossary dd { padding: 0 16px 12px; font-size: .96rem; line-height: 1.6; border-bottom: 1px dashed var(--card-border); }
.glossary dt:first-child { padding-top: 0; }

/* steps / checklist */
.steps { counter-reset: step; list-style: none; margin: 16px 0 16px 0 !important; }
.steps li {
  counter-increment: step; position: relative; padding-left: 44px; margin-bottom: 14px;
}
.steps li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute; left: 0; top: 0;
  font-family: var(--font-mono); font-size: .8rem; font-weight: 500;
  color: var(--ink); background: var(--accent-soft);
  border: 1px solid var(--card-border);
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.checklist { list-style: none !important; }
.checklist li { padding-left: 30px; position: relative; }
.checklist li::before {
  content: '✓'; position: absolute; left: 4px; top: 0; color: var(--wood); font-weight: 700;
}

/* article nav */
.article-nav {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--card-border);
}
.article-nav a {
  flex: 1; max-width: 46%;
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: .9rem; font-weight: 600; color: var(--text);
  transition: transform var(--transition), box-shadow var(--transition);
}
.article-nav a:hover { transform: translateY(-2px); box-shadow: var(--shadow); text-decoration: none; }
.article-nav .nav-label {
  display: block; font-family: var(--font-mono); font-size: .7rem;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px;
}

/* warn in article footer */
.content-article > .warn-box { margin-top: 32px; }

/* ---------- Footer ---------- */
.app-footer {
  border-top: 1px solid var(--card-border); background: var(--sidebar-bg);
  margin-top: 40px;
}
.footer-inner { max-width: 1440px; margin: 0 auto; padding: 28px 34px; }
.footer-inner p { font-size: .88rem; color: var(--text-soft); margin-bottom: 6px; max-width: 780px; }
.footer-meta { font-size: .78rem !important; color: var(--muted); font-family: var(--font-mono); }

/* ---------- Reveal ---------- */
.reveal { opacity: 0; transform: translateY(8px); transition: opacity .45s ease-out, transform .45s ease-out; }
.reveal.visible { opacity: 1; transform: translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 110;
    height: 100vh; width: min(320px, 85vw);
    transform: translateX(-105%); transition: transform .28s ease-out;
    box-shadow: var(--shadow-hover); border-right: none;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .menu-toggle { display: flex; }
  .header-search { max-width: none; }
  .main { padding: 20px 18px 48px; }
  .home-hero { padding: 34px 26px; }
  .hero-inner { flex-direction: column; }
  .hero-art { width: 220px; }
  .footer-inner { padding: 24px 18px; }
}

@media (max-width: 600px) {
  body { font-size: 16.5px; }
  .home-grid { grid-template-columns: 1fr; }
  .hero-stats { gap: 16px; }
  .hero-stat b { font-size: 1.4rem; }
  .article-nav { flex-direction: column; }
  .article-nav a { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; }
}
