/* ============================================================
   Hydraulika - design system
   Paleta "miedź i woda": granat wody + miedź + krem
   Typografia: Gelasio (display) + Schibsted Grotesk (body) + IBM Plex Mono (etykiety)
   ============================================================ */

:root {
  /* Light theme */
  --bg: #f6f2ea;
  --bg-alt: #efe9dd;
  --surface: #fdfaf4;
  --surface-2: #f8f3e9;
  --text: #1b2329;
  --text-muted: #5d7283;
  --accent: #b0713a;
  --accent-strong: #8f5427;
  --accent-light: #e8d3bc;
  --accent-subtle: rgba(176, 113, 58, 0.14);
  --copper: #c9813f;
  --navy: #1c3d5a;
  --navy-strong: #16324f;
  --aqua: #7fa8c0;
  --border: #e2dac8;
  --border-strong: #cfc3a9;
  --header-bg: rgba(246, 242, 234, 0.96);
  --sidebar-bg: #f0eadd;
  --info-bg: #fbf4ea;
  --info-border: #e5c9a8;
  --success-bg: #edf3f2;
  --success-border: #b8d0cc;
  --warn-bg: #fbf1ec;
  --warn-border: #e2b8a8;
  --code-bg: #16222e;
  --code-text: #e9f0f4;
  --shadow-card: 0 1px 2px rgba(27, 35, 41, 0.05), 0 4px 16px rgba(27, 35, 41, 0.06);
  --shadow-card-hover: 0 2px 4px rgba(27, 35, 41, 0.07), 0 10px 28px rgba(27, 35, 41, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --header-height: 60px;
  --sidebar-width: 320px;
  --transition: 0.2s ease-out;
  --font-display: "Gelasio", Georgia, serif;
  --font-body: "Schibsted Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101a24;
    --bg-alt: #14202c;
    --surface: #182634;
    --surface-2: #1c2b3a;
    --text: #e8eef2;
    --text-muted: #9db4c3;
    --accent: #d08a4d;
    --accent-strong: #e09a5f;
    --accent-light: #5a3c20;
    --accent-subtle: rgba(208, 138, 77, 0.16);
    --copper: #c9813f;
    --navy: #1c3d5a;
    --aqua: #7fa8c0;
    --border: #2a3b4c;
    --border-strong: #3a4f63;
    --header-bg: rgba(16, 26, 36, 0.96);
    --sidebar-bg: #14202c;
    --info-bg: #2a2216;
    --info-border: #5a4526;
    --success-bg: #16252a;
    --success-border: #2e4a52;
    --warn-bg: #291d16;
    --warn-border: #5a3626;
    --code-bg: #0a1118;
    --code-text: #d9e4ea;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.4);
  }
}

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

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 800px 500px at -10% -10%, var(--accent-subtle), transparent 60%),
    radial-gradient(ellipse 700px 500px at 110% 110%, rgba(127, 168, 192, 0.12), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

::selection { background: var(--accent); color: #fff; }

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

h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; line-height: 1.2; }
h1 { font-size: 2.6rem; font-weight: 600; }
h2 { font-size: 1.7rem; font-weight: 600; margin-top: 2.2em; margin-bottom: 0.5em; }
h3 { font-size: 1.25rem; font-weight: 600; margin-top: 1.6em; margin-bottom: 0.4em; }
p { margin-bottom: 1em; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- HEADER ---------- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.app-header::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-subtle), transparent);
  opacity: 0.5; pointer-events: none;
}
.mobile-menu-btn {
  display: none;
  background: none; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 1.1rem; width: 40px; height: 40px; cursor: pointer; color: var(--text);
}
.brand { flex-shrink: 0; }
.brand a { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand-mark { font-size: 1.4rem; }
.brand-name {
  font-family: var(--font-display);
  font-size: 1.5rem; font-weight: 700; letter-spacing: 0.01em;
}
.brand-accent { color: var(--accent-strong); }
.header-search {
  flex: 1; max-width: 420px; margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.header-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }
.search-icon { font-size: 0.9rem; opacity: 0.7; }
.header-search input {
  border: none; background: none; outline: none; flex: 1;
  font-family: var(--font-body); font-size: 0.95rem; color: var(--text);
}
.search-results {
  position: absolute; top: calc(var(--header-height) - 4px); left: 0; right: 0;
  max-width: 560px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-card-hover);
  overflow: hidden; z-index: 150;
}
.search-results a {
  display: block; padding: 12px 18px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 0.95rem;
}
.search-results a:hover { background: var(--accent-subtle); }
.search-results .sr-section { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 10px 18px 4px; }
.search-results .sr-empty { padding: 16px 18px; color: var(--text-muted); font-size: 0.9rem; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0; bottom: 0;
  width: var(--sidebar-width);
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px 12px 40px;
  z-index: 90;
  scrollbar-width: thin;
}
.sidebar-nav { list-style: none; }
.nav-home {
  display: block; padding: 10px 12px; margin-bottom: 8px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.95rem; color: var(--text);
}
.nav-home:hover { background: var(--accent-subtle); text-decoration: none; }
.nav-section {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); font-weight: 600;
  padding: 18px 12px 6px;
}
.sidebar-nav a:not(.nav-home) {
  display: block; padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; color: var(--text);
  border-left: 2px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}
.sidebar-nav a:not(.nav-home):hover { background: var(--accent-subtle); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--accent-subtle);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 85;
}

/* ---------- MAIN ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  padding: calc(var(--header-height) + 28px) 32px 60px;
  max-width: 980px;
  min-height: 100vh;
}
.main-content:focus { outline: none; }

/* ---------- HOME ---------- */
.home-hero {
  padding: 52px 8px 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 36px;
  position: relative;
}
.home-hero::before {
  content: '';
  position: absolute; top: 20px; right: 8px;
  width: 96px; height: 96px;
  background-image:
    linear-gradient(var(--accent-subtle), var(--accent-subtle)),
    linear-gradient(rgba(127, 168, 192, 0.25), rgba(127, 168, 192, 0.25));
  background-size: 50% 50%, 50% 50%;
  background-position: 0 0, 100% 100%;
  background-repeat: no-repeat;
  opacity: 0.9;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(#000, transparent);
          mask-image: linear-gradient(#000, transparent);
}
.home-hero h1 {
  font-size: 3.1rem;
  margin-bottom: 14px;
}
.home-hero h1 .hero-accent { color: var(--accent-strong); font-style: italic; }
.home-hero p.hero-lead {
  font-size: 1.15rem; color: var(--text-muted);
  max-width: 640px; margin-bottom: 0;
}
.home-hero .hero-stats {
  display: flex; gap: 28px; flex-wrap: wrap; margin-top: 28px;
}
.home-hero .hero-stats .stat b {
  display: block; font-family: var(--font-display); font-size: 1.7rem; color: var(--accent-strong);
}
.home-hero .hero-stats .stat span { font-size: 0.85rem; color: var(--text-muted); }

.home-section { margin-bottom: 40px; }
.home-section h2 {
  font-size: 1.45rem; margin: 0 0 4px;
  display: flex; align-items: center; gap: 10px;
}
.home-section h2::after {
  content: ''; flex: 1; height: 1px; background: var(--border-strong);
}
.home-section .section-note { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 16px; }

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.home-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.home-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
  text-decoration: none;
}
.home-card .card-icon { font-size: 1.55rem; display: block; margin-bottom: 8px; }
.home-card h3 { font-family: var(--font-body); font-size: 0.9rem; font-weight: 600; margin: 0 0 6px; line-height: 1.4; }
.home-card p { font-size: 0.85rem; color: var(--text-muted); margin: 0; line-height: 1.55; }

/* ---------- ARTICLE ---------- */
.content-article { animation: fadeUp 0.28s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.article-header { padding: 18px 8px 26px; border-bottom: 1px solid var(--border); margin-bottom: 26px; }
.article-kicker {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--accent-strong); font-weight: 600; margin-bottom: 10px;
}
.article-header h1 { font-size: 2.5rem; margin-bottom: 12px; }
.article-header .article-excerpt { font-size: 1.08rem; color: var(--text-muted); max-width: 680px; }

.article-toc {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 0 0 28px;
  font-size: 0.92rem;
}
.article-toc summary {
  cursor: pointer; font-weight: 600; font-family: var(--font-display); font-size: 1.1rem;
  list-style: none;
}
.article-toc summary::before { content: '📑 '; }
.article-toc ul { list-style: none; margin-top: 10px; }
.article-toc li { padding: 3px 0; }
.article-toc a { color: var(--text); }
.article-toc a:hover { color: var(--accent-strong); }

.content-article h2 { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.content-article h2[id], .content-article h3[id] { scroll-margin-top: calc(var(--header-height) + 16px); }
.content-article ul, .content-article ol { margin: 0 0 1.2em 1.4em; }
.content-article li { margin-bottom: 0.4em; }
.content-article strong { font-weight: 600; }
.content-article img { max-width: 100%; border-radius: var(--radius); height: auto; }
.content-article blockquote {
  border-left: 3px solid var(--accent);
  padding: 10px 18px; margin: 1.2em 0;
  background: var(--accent-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic; color: var(--text);
}

/* Tables */
.table-responsive { overflow-x: auto; margin: 1.2em 0; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.content-article table, .error-table {
  width: 100%; border-collapse: collapse; font-size: 0.92rem;
}
.content-article table th, .error-table th {
  background: var(--surface-2); text-align: left; font-weight: 600;
  padding: 10px 14px; border-bottom: 2px solid var(--border-strong);
}
.content-article table td, .error-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.content-article table tr:last-child td, .error-table tr:last-child td { border-bottom: none; }
.content-article table tr:hover td, .error-table tr:hover td { background: var(--accent-subtle); }

/* Info boxes */
.info-box, .faq-item, .error-code {
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 1.2em 0;
}
.info-box strong:first-child, .info-box b:first-child { color: var(--accent-strong); }

.faq-item h3 { font-family: var(--font-body); font-size: 1rem; margin: 0 0 8px; font-weight: 600; }
.faq-item h3::before { content: '❓ '; }

.error-code { background: var(--code-bg); color: var(--code-text); font-family: var(--font-mono); font-size: 0.9rem; }

/* Glossary */
.content-article dl { margin: 1.2em 0; }
.content-article dt {
  font-weight: 600; margin-top: 1em; color: var(--accent-strong);
}
.content-article dd { margin: 0.2em 0 0.6em 1em; color: var(--text); }

/* Comparison tables in articles */
table.error-table td:first-child { font-weight: 600; }

/* ---------- FOOTER ---------- */
.app-footer {
  margin-left: var(--sidebar-width);
  border-top: 1px solid var(--border);
  padding: 28px 32px 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 980px;
}
.footer-links { margin-top: 8px; }
.footer-links a { color: var(--text-muted); text-decoration: underline; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease-out; box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-card-hover); }
  .sidebar-overlay.show { display: block; }
  .mobile-menu-btn { display: block; }
  .main-content { margin-left: 0; padding: calc(var(--header-height) + 20px) 20px 40px; }
  .app-footer { margin-left: 0; padding: 24px 20px 32px; }
  .home-hero h1 { font-size: 2.2rem; }
  .article-header h1 { font-size: 2rem; }
  .home-hero .hero-stats { gap: 18px; }
}

@media (max-width: 600px) {
  body { font-size: 17px; }
  h2 { font-size: 1.45rem; }
  .brand-name { font-size: 1.25rem; }
  .header-search { padding: 7px 12px; }
  .search-icon { display: none; }
  .home-grid { grid-template-columns: 1fr; }
  .home-hero { padding: 36px 4px 28px; }
  .home-hero h1 { font-size: 1.9rem; }
  .main-content { padding-left: 16px; padding-right: 16px; }
  .table-responsive { margin-left: -4px; margin-right: -4px; }
}

/* ---------- FOCUS ---------- */
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

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