/* ============================================
   DESIGN SYSTEM - Elektryka v1
   Kompendium elektryki domowej dla zwykłych ludzi
   Paleta "BURSZTYN I GRAFIT": bursztyn prądu (#b45309/#f59e0b)
   + głęboki grafit (#12161b) + błękit techniczny (#0e7490/#38bdf8)
   na ciepłym papierze (#f7f5f0)
   Typografia: Bricolage Grotesque (display) + Instrument Sans (body)
   ============================================ */

/* --- CSS VARIABLES --- */
:root {
  /* Light theme - ciepły papier */
  --bg: #f7f5f0;
  --bg-card: #fffefb;
  --bg-surface: #fbf9f4;
  --bg-sidebar: #faf8f2;
  --text: #1c2126;
  --text-secondary: #3a434c;
  --text-muted: #5c666e;
  --accent: #b45309;
  --accent-hover: #9a3412;
  --accent-light: #faf0dd;
  --accent-subtle: #e8d5ab;
  --ink: #12161b;
  --ink-deep: #0b0e12;
  --ink-soft: #1e252d;
  --amber-bright: #f59e0b;
  --blue: #0e7490;
  --blue-bright: #38bdf8;
  --blue-soft: #e0f2f9;
  --red-soft: #fdecec;
  --green-bright: #15803d;
  --border: #e5e0d6;
  --border-light: #ede9e0;
  --code-bg: #f1ece0;
  --header-bg: rgba(250, 248, 242, .92);
  --shadow-sm: 0 1px 2px rgba(18, 22, 27, .07);
  --shadow-md: 0 4px 20px rgba(18, 22, 27, .1);
  --shadow-lg: 0 14px 44px rgba(18, 22, 27, .16);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --nav-width: 305px;
  --header-height: 64px;
  --content-max: 780px;
  --font-body: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading: 'Bricolage Grotesque', Georgia, 'Times New Roman', serif;
  --red: #b91c1c;
  --transition: .2s ease-out;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --bg-card: #1a2027;
    --bg-surface: #161b21;
    --bg-sidebar: #141920;
    --text: #e8e6e1;
    --text-secondary: #c2c4c1;
    --text-muted: #9aa4ad;
    --accent: #f59e0b;
    --accent-hover: #fbbf24;
    --accent-light: #2a2314;
    --accent-subtle: #4a3a1c;
    --ink: #0b0e12;
    --ink-deep: #07090c;
    --ink-soft: #1e252d;
    --amber-bright: #f5a524;
    --blue: #38bdf8;
    --blue-bright: #5cc8f8;
    --blue-soft: #12252e;
    --red-soft: #2a1212;
    --green-bright: #4ade80;
    --border: #2a323b;
    --border-light: #232a32;
    --code-bg: #1a2027;
    --header-bg: rgba(18, 22, 27, .92);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, .4);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, .55);
  }
}

/* --- BASE --- */
* { 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 700px 420px at -10% -5%, rgba(245, 158, 11, .13), transparent 60%),
    radial-gradient(ellipse 700px 460px at 110% 105%, rgba(56, 189, 248, .12), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-heading); line-height: 1.25; color: var(--text); text-wrap: balance; }
code { font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace; font-size: .85em; background: var(--code-bg); padding: .15em .45em; border-radius: 5px; }
:focus-visible { outline: 3px solid var(--amber-bright); outline-offset: 2px; border-radius: 4px; }
.skip-link {
  position: absolute; left: -9999px; top: 0; background: var(--ink); color: #fff;
  padding: .6rem 1rem; border-radius: 0 0 8px 0; z-index: 200; font-size: .9rem;
}
.skip-link:focus { left: 0; color: #fff; }

/* --- HEADER --- */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-height);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  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(--amber-bright), var(--blue-bright), transparent);
  opacity: .5; pointer-events: none;
}
.mobile-menu-btn {
  display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1.25rem; width: 42px; height: 42px; cursor: pointer; color: var(--text);
  transition: all var(--transition);
}
.mobile-menu-btn:hover { border-color: var(--accent); color: var(--accent); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo-seal { display: inline-flex; flex-shrink: 0; }
.brand-name { font-family: var(--font-heading); font-size: 1.22rem; font-weight: 700; letter-spacing: -.01em; }
.brand-name em { font-style: italic; color: var(--accent); }
.header-search { position: relative; margin-left: auto; width: min(340px, 40vw); }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); display: flex; }
.header-search input {
  width: 100%; padding: 9px 12px 9px 34px; font-size: .9rem; font-family: var(--font-body);
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-full);
  transition: all var(--transition);
}
.header-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

/* --- SEARCH RESULTS --- */
#search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); overflow: hidden; z-index: 120; display: none;
}
.search-result {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px;
  border-bottom: 1px solid var(--border-light); color: var(--text);
  transition: background var(--transition);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--accent-light); text-decoration: none; }
.sr-icon { font-size: 1.1rem; flex-shrink: 0; }
.sr-title { font-size: .9rem; font-weight: 600; display: block; }
.sr-excerpt { font-size: .78rem; color: var(--text-muted); display: block; margin-top: 2px; }
mark { background: var(--accent-light); color: var(--accent); padding: 0 2px; border-radius: 3px; }

/* --- SIDEBAR --- */
.sidebar {
  position: fixed; top: var(--header-height); left: 0; bottom: 0; width: var(--nav-width);
  overflow-y: auto; background: var(--bg-sidebar); border-right: 1px solid var(--border);
  padding: 18px 14px 30px; z-index: 90; scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar-nav { list-style: none; }
.sidebar-nav li { margin: 1px 0; }
.nav-section {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-muted); padding: 16px 10px 5px; font-family: var(--font-body);
}
.sidebar-link {
  display: flex; align-items: center; gap: 9px; padding: 6px 10px;
  font-size: .9rem; line-height: 1.4; color: var(--text-secondary);
  border-radius: var(--radius-sm); border-left: 3px solid transparent;
  transition: all var(--transition);
}
.sidebar-link:hover { background: var(--accent-light); color: var(--accent); text-decoration: none; }
.sidebar-link.active {
  background: var(--accent-light); color: var(--accent); font-weight: 600;
  border-left-color: var(--accent);
}
.sl-icon { font-size: .95rem; flex-shrink: 0; opacity: .9; }
.sidebar-foot { margin-top: 26px; padding: 14px 10px 0; border-top: 1px solid var(--border-light); }
.foot-seal { font-size: 1.4rem; display: block; margin-bottom: 6px; }
.sidebar-foot p { font-size: .78rem; color: var(--text-muted); line-height: 1.5; }
.sidebar-overlay {
  position: fixed; inset: 0; background: rgba(7, 9, 12, .5); z-index: 85;
  opacity: 0; pointer-events: none; transition: opacity var(--transition);
}

/* --- MAIN --- */
.main-content {
  margin-left: var(--nav-width); padding: calc(var(--header-height) + 34px) 28px 60px;
  min-height: 100vh;
}
.content-article { max-width: var(--content-max); margin: 0 auto; animation: fadeUp .28s ease-out both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.content-article h1 { font-size: 2.15rem; font-weight: 700; margin-bottom: 12px; letter-spacing: -.01em; }
.content-article h2 { font-size: 1.5rem; font-weight: 700; margin: 34px 0 12px; padding-top: 6px; }
.content-article h2::before { content: ''; display: block; width: 46px; height: 3px; background: linear-gradient(90deg, var(--amber-bright), var(--blue-bright)); border-radius: 2px; margin-bottom: 10px; }
.content-article h3 { font-size: 1.18rem; font-weight: 700; margin: 24px 0 8px; }
.content-article p { margin: 0 0 14px; }
.content-article ul, .content-article ol { margin: 0 0 16px; padding-left: 24px; }
.content-article li { margin-bottom: 6px; }
.article-meta { font-size: 1rem; color: var(--text-muted); margin-bottom: 18px; }

/* --- TOC --- */
.article-toc {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin: 18px 0 26px;
}
.article-toc h3 { font-size: .78rem; margin: 0 0 10px; color: var(--text-secondary); font-family: var(--font-body); text-transform: uppercase; letter-spacing: .06em; }
.article-toc a { display: block; padding: 3px 0; font-size: .92rem; color: var(--accent); }
.article-toc a:hover { text-decoration: underline; }
.article-toc .toc-h2 { font-weight: 600; }
.article-toc .toc-h3 { padding-left: 16px; font-size: .86rem; color: var(--text-secondary); }

/* --- BOXES --- */
.info-box {
  background: var(--accent-light); border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm); padding: 14px 18px; margin: 18px 0; font-size: .97rem;
  color: var(--text);
}
.info-box strong { color: var(--accent); }
.tip-box {
  background: var(--blue-soft); border-left: 4px solid var(--blue);
  border-radius: var(--radius-sm); padding: 14px 18px; margin: 18px 0; font-size: .97rem;
  color: var(--text);
}
.tip-box strong { color: var(--blue); }
.warning-box {
  background: var(--red-soft); border-left: 4px solid var(--red);
  border-radius: var(--radius-sm); padding: 14px 18px; margin: 18px 0; font-size: .97rem;
  color: var(--text);
}
.warning-box strong { color: var(--red); }
.key-takeaways {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 22px; margin: 20px 0;
}
.key-takeaways h3 { font-size: .82rem; margin: 0 0 10px; font-family: var(--font-body); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.key-takeaways ul { margin: 0; padding-left: 20px; }
.key-takeaways li { margin-bottom: 5px; font-size: .96rem; }
.focus-box {
  background: var(--bg-card); border: 1px dashed var(--accent-subtle); border-radius: var(--radius-sm);
  padding: 14px 18px; margin: 18px 0; font-size: .97rem;
}

/* --- TABLES --- */
.table-responsive { overflow-x: auto; margin: 20px 0; border-radius: var(--radius); border: 1px solid var(--border); }
.error-table { width: 100%; border-collapse: collapse; font-size: .93rem; min-width: 560px; }
.error-table th {
  background: var(--ink); color: #f0ece0; text-align: left; padding: 11px 14px;
  font-weight: 600; font-size: .88rem; letter-spacing: .02em;
}
.error-table td { padding: 10px 14px; border-top: 1px solid var(--border-light); vertical-align: top; }
.error-table tr:nth-child(even) td { background: var(--bg-surface); }
.error-table tr:hover td { background: var(--accent-light); }

/* --- FAQ (details/summary) --- */
.faq-item { border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 10px 0; overflow: hidden; background: var(--bg-card); }
.faq-item details > summary {
  font-family: var(--font-body); font-size: 1rem; font-weight: 700; margin: 0;
  padding: 13px 18px; cursor: pointer; color: var(--text);
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  list-style: none; transition: background var(--transition);
}
.faq-item details > summary::-webkit-details-marker { display: none; }
.faq-item details > summary::after { content: '+'; font-size: 1.3rem; color: var(--accent); flex-shrink: 0; transition: transform var(--transition); }
.faq-item details[open] > summary::after { transform: rotate(45deg); }
.faq-item details[open] > summary { background: var(--accent-light); }
.faq-item details > summary:hover { background: var(--accent-light); }
.faq-answer { padding: 4px 18px 14px; margin: 0; font-size: .95rem; }
.faq-answer p { margin-bottom: 8px; }
.faq-answer p:last-child { margin-bottom: 0; }

/* --- GLOSSARY (dl/dt/dd) --- */
.content-article dl { margin: 18px 0; }
.content-article dt {
  font-weight: 700; color: var(--accent); margin-top: 14px; font-size: 1rem;
  padding-left: 14px; border-left: 3px solid var(--accent-subtle);
}
.content-article dd { margin: 3px 0 0 17px; font-size: .95rem; color: var(--text-secondary); }

/* --- PREV / NEXT --- */
.prev-next { display: flex; justify-content: space-between; gap: 16px; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); }
.prev-next a {
  flex: 1; padding: 12px 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: .92rem; color: var(--text);
  transition: all var(--transition);
}
.prev-next a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.pn-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 3px; }

/* --- LEGAL NOTE --- */
.legal-note {
  margin-top: 34px; padding: 14px 18px; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .82rem; color: var(--text-muted);
}

/* --- HOME HERO --- */
.home-hero {
  background: var(--ink);
  background-image:
    radial-gradient(ellipse 520px 300px at 85% -10%, rgba(56, 189, 248, .22), transparent 60%),
    radial-gradient(ellipse 440px 300px at 0% 110%, rgba(245, 158, 11, .24), transparent 55%);
  border-radius: var(--radius);
  padding: 44px 42px 34px; margin-bottom: 40px; color: #f0ece0;
  position: relative; overflow: hidden;
}
.home-hero::before {
  content: ''; position: absolute; inset: 0; opacity: .1; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.5) 1px, transparent 1px);
  background-size: 22px 22px;
}
.hero-badge {
  display: inline-block; font-size: .78rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--amber-bright);
  border: 1px solid rgba(245, 158, 11, .5); border-radius: var(--radius-full);
  padding: 5px 14px; margin-bottom: 18px;
}
.home-hero h1 { color: #f7f3ea; font-size: 2.5rem; font-weight: 700; margin-bottom: 14px; letter-spacing: -.01em; }
.hero-sub { font-size: 1.08rem; color: #d3d8d4; max-width: 600px; margin-bottom: 26px; line-height: 1.65; }
.hero-cta {
  display: inline-block; background: var(--amber-bright); color: var(--ink-deep);
  font-weight: 700; font-size: 1rem; padding: 12px 26px; border-radius: var(--radius-full);
  transition: all var(--transition);
}
.hero-cta:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(245, 158, 11, .35); color: var(--ink-deep); text-decoration: none; }
.hero-cta span { margin-left: 6px; }

/* --- CIRCUIT SIGNATURE (SVG: żarówka -> przewód -> rozdzielnica + sinus) --- */
.hero-sig { margin: 30px 0 8px; }
.hero-sig svg { width: 100%; max-width: 640px; height: auto; display: block; }
.bulb-glow { transform-origin: 150px 88px; animation: glowPulse 3.6s ease-in-out infinite; }
@keyframes glowPulse { 0%, 100% { opacity: .35; } 50% { opacity: .9; } }
.bulb-filament { stroke-dasharray: 120; stroke-dashoffset: 120; }
.hero-sig.in .bulb-filament { animation: drawLine 1.2s .4s ease-out forwards; }
.hero-sig.in .bulb-glass { animation: fadeIn .8s .2s ease-out both; }
.electron { animation: electronMove 2.6s linear infinite; }
.electron.e2 { animation-delay: .87s; }
.electron.e3 { animation-delay: 1.74s; }
@keyframes electronMove { from { offset-distance: 0%; opacity: 0; } 8% { opacity: 1; } 92% { opacity: 1; } to { offset-distance: 100%; opacity: 0; } }
.sig-switch { animation: switchBlink 2s ease-in-out infinite; }
@keyframes switchBlink { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.ac-wave { stroke-dasharray: 300; stroke-dashoffset: 300; }
.hero-sig.in .ac-wave { animation: drawLine 1.6s .6s ease-out forwards; }
.hero-sig.in .sig-panel { animation: fadeIn .9s .45s ease-out both; }
@keyframes drawLine { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sig-label { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: .78rem; color: #b5b2a4; letter-spacing: .04em; }
.sig-tag { color: var(--blue-bright); font-weight: 700; text-transform: uppercase; font-size: .72rem; letter-spacing: .1em; }

/* --- STATS --- */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 26px; }
.stat-card { background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .12); border-radius: var(--radius-sm); padding: 14px 16px; }
.stat-card .num { display: block; font-family: var(--font-heading); font-size: 1.7rem; font-weight: 700; color: var(--amber-bright); line-height: 1.1; }
.stat-card .label { font-size: .8rem; color: #c8c5b7; }

/* --- HOME SECTIONS + CARDS --- */
.home-section-label {
  font-size: 1.35rem; font-weight: 700; margin: 40px 0 16px; display: flex; align-items: center; gap: 12px;
}
.accent-bar { display: inline-block; width: 8px; height: 26px; border-radius: 4px; background: linear-gradient(180deg, var(--amber-bright), var(--blue-bright)); }
.home-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.home-card {
  display: block; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; color: var(--text);
  transition: all var(--transition);
}
.home-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent-subtle); text-decoration: none; color: var(--text); }
.card-icon { font-size: 1.4rem; display: block; margin-bottom: 8px; }
.home-card h3 { font-size: .9rem; font-weight: 700; margin-bottom: 5px; line-height: 1.35; }
.home-card p { font-size: .85rem; color: var(--text-muted); line-height: 1.5; margin: 0; }

/* --- FOOTER --- */
.app-footer { margin-left: var(--nav-width); border-top: 1px solid var(--border); background: var(--bg-surface); }
.footer-inner { max-width: var(--content-max); margin: 0 auto; padding: 22px 28px; display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--text-muted); }
.footer-note { font-size: .78rem; }

/* --- RESPONSIVE --- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); transition: transform .25s ease-out; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }
  .main-content { margin-left: 0; padding: calc(var(--header-height) + 24px) 18px 50px; }
  .app-footer { margin-left: 0; }
  .mobile-menu-btn { display: block; }
  .header-search { width: auto; flex: 1; }
  .brand-name { font-size: 1.05rem; }
  .home-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .home-hero { padding: 34px 24px 28px; }
  .home-hero h1 { font-size: 1.9rem; }
  .content-article h1 { font-size: 1.7rem; }
  .prev-next { flex-direction: column; }
}

@media (max-width: 600px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 10px 12px; }
  .stat-card .num { font-size: 1.4rem; }
  .hero-cta { width: 100%; text-align: center; }
  .content-article { font-size: 16.5px; }
}

/* --- REDUCED MOTION --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .bulb-filament { stroke-dashoffset: 0; }
  .ac-wave { stroke-dashoffset: 0; }
  .bulb-glow, .electron, .sig-switch { animation: none !important; }
}
