/* ============================================================
   Serce - Design System v1
   Koncepcja: "krew i zdrowie" - granat zaufania + koral serca
   + teal medyczny + ciepły krem. Premium magazine, WCAG AA.
   ============================================================ */

:root {
  /* Paleta light */
  --paper: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #10161d;
  --panel: #182029;
  --text: #232b33;
  --text-secondary: #5b656e;
  --border: #e3ded4;
  --border-strong: #cfc8ba;

  --accent: #b93a2f;          /* koral - serce, CTA, linki */
  --accent-dark: #9c2f26;
  --accent-soft: #f6e3df;     /* tło podświetleń */
  --teal: #1f7a74;            /* teal medyczny - drugorzędny akcent */
  --teal-soft: #dceeec;
  --teal-bright: #4fc3b8;     /* na ciemnym tle */
  --accent-bright: #f27a6b;   /* na ciemnym tle */
  --gold: #a8811f;

  --gradient-hero: linear-gradient(135deg, #10161d 0%, #1c2a35 55%, #25313d 100%);
  --shadow-card: 0 1px 2px rgba(16,22,29,.05), 0 4px 14px rgba(16,22,29,.06);
  --shadow-card-hover: 0 2px 4px rgba(16,22,29,.07), 0 10px 26px rgba(16,22,29,.12);

  --font-display: 'Spectral', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --header-h: 62px;
  --sidebar-w: 300px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all .2s ease-out;

  --body-size: 17px;
  --line-h: 1.7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f141b;
    --surface: #151c25;
    --surface-2: #1a222c;
    --ink: #10161d;
    --panel: #182029;
    --text: #e8e3da;
    --text-secondary: #a6aeb6;
    --border: #26313c;
    --border-strong: #34414e;
    --accent: #f27a6b;
    --accent-dark: #e26657;
    --accent-soft: #2c1a17;
    --teal: #4fc3b8;
    --teal-soft: #142826;
    --gold: #d4a72c;
    --gradient-hero: linear-gradient(135deg, #0d1218 0%, #16222e 55%, #1d2a38 100%);
    --shadow-card: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.35);
    --shadow-card-hover: 0 2px 4px rgba(0,0,0,.4), 0 10px 26px rgba(0,0,0,.5);
  }
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: var(--line-h);
  color: var(--text);
  background: var(--paper);
  background-image:
    radial-gradient(900px 500px at -10% -10%, rgba(242,122,107,.07), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(79,195,184,.06), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ---------- Header ---------- */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.app-header::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .3; pointer-events: none;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  color: var(--text); white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { flex: 0 0 auto; }
.brand-mark path:first-child { fill: var(--accent-bright); }
.brand-ecg {
  fill: none; stroke: var(--paper); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 90; stroke-dashoffset: 90;
  animation: ecg-draw 2.6s ease-out forwards infinite;
}
@keyframes ecg-draw {
  0% { stroke-dashoffset: 90; }
  55% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; }
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-accent { color: var(--accent); }

.header-search { position: relative; margin-left: auto; width: min(340px, 38vw); }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); pointer-events: none; }
#search-input {
  width: 100%; padding: 9px 14px 9px 36px;
  font-family: var(--font-body); font-size: .9rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px;
  transition: var(--transition);
}
#search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#search-results {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; width: min(420px, 90vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-card-hover); overflow: hidden; z-index: 120;
}
#search-results a { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border); align-items: flex-start; }
#search-results a:last-child { border-bottom: none; }
#search-results a:hover { background: var(--accent-soft); text-decoration: none; }
#search-results .sr-title { font-weight: 600; font-size: .9rem; color: var(--text); }
#search-results .sr-excerpt { display: block; font-size: .8rem; color: var(--text-secondary); line-height: 1.35; margin-top: 2px; }

.mobile-menu-btn {
  display: none; width: 40px; height: 40px; flex: 0 0 auto;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 1.15rem; cursor: pointer;
}
.mobile-menu-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0; z-index: 90;
  width: var(--sidebar-w); overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--border);
  padding: 16px 10px 40px;
  scrollbar-width: thin;
}
.sidebar-nav { list-style: none; margin: 0; padding: 0; }
.sidebar-nav li { margin: 1px 0; }
.sidebar-nav a {
  display: block; padding: 6px 12px;
  font-size: .9rem; line-height: 1.35; color: var(--text);
  border-radius: var(--radius-sm); border-left: 2px solid transparent;
  transition: var(--transition);
}
.sidebar-nav a:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; transform: translateX(2px); }
.sidebar-nav a.active {
  background: var(--accent-soft); color: var(--accent-dark);
  border-left-color: var(--accent); font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .sidebar-nav a:hover, .sidebar-nav a.active { color: var(--accent-bright); }
}
.nav-section {
  padding: 16px 12px 5px; margin-top: 6px;
  font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-secondary);
}
.nav-section:first-of-type { margin-top: 0; padding-top: 4px; }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 85;
  background: rgba(10,14,18,.5);
}

/* ---------- Main ---------- */
.main-content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--header-h) + 34px) 40px 80px;
  max-width: 980px;
}
.loading { display: flex; justify-content: center; padding: 80px 0; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Home hero ---------- */
.home-hero {
  position: relative; overflow: hidden;
  border-radius: var(--radius);
  background: var(--gradient-hero);
  padding: 44px 44px 38px;
  color: #f2eee6;
  margin-bottom: 38px;
}
.home-hero::before {
  content: ''; position: absolute; top: -60px; right: -60px; width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(242,122,107,.28), transparent 65%);
  pointer-events: none;
}
.home-hero h1 {
  margin: 0 0 10px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.9rem, 3.4vw, 2.6rem); letter-spacing: -.015em; text-wrap: balance;
}
.home-hero .hero-lead { margin: 0 0 20px; font-size: 1.06rem; line-height: 1.6; color: #c9d2da; max-width: 620px; }
.hero-ecg { margin-top: 6px; }
.hero-ecg svg { display: block; width: 100%; height: 64px; }
.hero-ecg path { fill: none; stroke: var(--teal-bright); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 620; stroke-dashoffset: 620; animation: ecg-hero 3.4s ease-out forwards; }
.hero-ecg path.beat { stroke: var(--accent-bright); animation-delay: .1s; }
@keyframes ecg-hero { 0% { stroke-dashoffset: 620; } 55% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: 0; } }
.stats-row { display: flex; gap: 26px; margin-top: 26px; flex-wrap: wrap; }
.stat-card { display: flex; flex-direction: column; }
.stat-card .num { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; color: var(--accent-bright); line-height: 1.1; }
.stat-card .label { font-size: .75rem; color: #9fb0bd; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Section labels + grid ---------- */
.home-section-label {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: 1.35rem; font-weight: 700;
  margin: 40px 0 16px; color: var(--text); text-wrap: balance;
}
.accent-bar { width: 26px; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--teal)); flex: 0 0 auto; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.home-card {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
  color: var(--text);
}
.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.35rem; line-height: 1; }
.home-card h3 { margin: 0; font-size: .95rem; font-weight: 600; line-height: 1.35; text-wrap: balance; }
.home-card h3::after { content: ' →'; opacity: 0; transition: var(--transition); color: var(--accent); }
.home-card:hover h3::after { opacity: 1; }
.home-card p { margin: 0; font-size: .85rem; color: var(--text-secondary); line-height: 1.5; }

/* ---------- Article ---------- */
.content-article { animation: fadeUp .28s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.content-article > h1, .content-article > h2, .content-article > p, .content-article > ul, .content-article > ol,
.content-article > .info-box, .content-article > .warning-box, .content-article > .table-responsive,
.content-article > .article-toc, .content-article > .related-box, .content-article > blockquote {
  max-width: 720px;
}
.content-article h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.7rem, 3vw, 2.35rem); line-height: 1.2;
  margin: 0 0 12px; letter-spacing: -.015em; text-wrap: balance;
}
.breadcrumbs {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: .8rem; color: var(--text-secondary); margin-bottom: 14px;
}
.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs a:hover { color: var(--accent); }
.article-lead {
  font-size: 1.06rem; line-height: 1.6; color: var(--text-secondary);
  padding-bottom: 16px; border-bottom: 1px solid var(--border); margin: 0 0 22px;
}
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; margin: 18px 0 4px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: .92rem;
  transition: var(--transition); text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); transform: translateY(-1px); text-decoration: none; }
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #24120f; }
  .btn-primary:hover { background: var(--accent-bright); }
}
.btn-ghost { border: 1px solid rgba(255,255,255,.35); color: #eef1f4; }
.btn-ghost:hover { border-color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.content-article h2 {
  font-family: var(--font-display); font-weight: 700;
  font-size: 1.45rem; margin: 34px 0 12px; line-height: 1.3; text-wrap: balance;
  scroll-margin-top: calc(var(--header-h) + 16px);
}
.content-article h3 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.15rem; margin: 26px 0 10px; line-height: 1.35; text-wrap: balance;
  scroll-margin-top: calc(var(--header-h) + 16px);
}
.content-article p { margin: 0 0 16px; }
.content-article ul, .content-article ol { margin: 0 0 18px; padding-left: 24px; }
.content-article li { margin-bottom: 7px; }
.content-article strong { font-weight: 600; }
.content-article blockquote {
  margin: 20px 0; padding: 4px 18px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary); font-style: italic;
}

/* TOC */
.article-toc {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 26px;
}
.article-toc h3 { margin: 0 0 10px; font-family: var(--font-display); font-size: 1rem; }
.article-toc a { display: block; padding: 4px 0; font-size: .9rem; color: var(--text-secondary); }
.article-toc a:hover { color: var(--accent); }
.article-toc .toc-h3 { padding-left: 18px; font-size: .85rem; }

/* Boxes */
.info-box, .warning-box {
  border-radius: var(--radius-sm); padding: 15px 18px; margin: 20px 0;
  font-size: .95rem; line-height: 1.6;
}
.info-box {
  background: var(--teal-soft); border: 1px solid rgba(31,122,116,.35);
  color: var(--text);
}
.info-box::before { content: 'ℹ️ '; }
.warning-box {
  background: var(--accent-soft); border: 1px solid rgba(185,58,47,.4);
  color: var(--text);
}
.warning-box::before { content: '⚠️ '; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .info-box, .warning-box { color: var(--text); }
}

/* Tables */
.table-responsive { overflow-x: auto; margin: 20px 0; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.error-table, .content-article table {
  width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--surface);
}
.error-table th, .content-article th {
  background: var(--panel); color: #f2eee6; text-align: left;
  padding: 10px 14px; font-weight: 600; font-size: .85rem; letter-spacing: .02em;
}
.error-table td, .content-article td { padding: 10px 14px; border-top: 1px solid var(--border); vertical-align: top; }
.error-table tr:nth-child(even) td, .content-article tr:nth-child(even) td { background: var(--surface-2); }
.error-table td:first-child, .content-article td:first-child { font-family: var(--font-mono); font-size: .85rem; white-space: nowrap; color: var(--accent); }

/* FAQ */
.faq-item { border-bottom: 1px solid var(--border); padding: 4px 0 6px; }
.faq-item:last-child { border-bottom: none; }
.faq-item h3 { font-size: 1.02rem; margin: 14px 0 6px; }
.faq-item p { margin: 0 0 10px; font-size: .95rem; }

/* Glossary */
.glossary dt {
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem;
  margin-top: 18px; color: var(--accent-dark);
}
.glossary dd { margin: 4px 0 0; font-size: .95rem; }
@media (prefers-color-scheme: dark) { .glossary dt { color: var(--accent-bright); } }

/* Related box */
.related-box {
  margin-top: 36px; padding: 20px 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.related-box h2 { font-size: 1.15rem; margin: 0 0 12px; }
.related-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 6px; border-radius: var(--radius-sm);
  color: var(--text); font-size: .93rem; font-weight: 500;
  transition: var(--transition);
}
.related-item:hover { background: var(--accent-soft); color: var(--accent-dark); text-decoration: none; transform: translateX(3px); }
.related-item:last-child { margin-bottom: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .mobile-menu-btn { display: block; }
  .sidebar { transform: translateX(-102%); transition: transform .24s ease-out; box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; padding: calc(var(--header-h) + 22px) 18px 60px; }
  .header-search { width: 44vw; }
  .home-hero { padding: 30px 24px 28px; }
  .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .header-search { width: 38vw; }
  .brand-name { font-size: 1rem; }
  .stats-row { gap: 18px; }
  .home-hero h1 { font-size: 1.55rem; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
  .brand-ecg, .hero-ecg path { stroke-dashoffset: 0; animation: none; }
}
