/* ============================================
   EMERYTURAPROSTO - design system v1
   Paleta: spokojny błękit + srebro + głęboki granat (zaufanie, finanse)
   Typografia: Lora (display) + Karla (body)
   ============================================ */

:root {
  /* Light theme - krem, granat, błękit */
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --text: #1c2733;
  --text-soft: #33404d;
  --muted: #5a6b7d;
  --accent: #1d4e89;
  --accent-2: #3a7ca5;
  --accent-soft: #e3ecf5;
  --gold: #b98a2f;
  --gold-soft: #f5edda;
  --border: #e2ddd2;
  --border-strong: #cfc8ba;
  --success: #2f6b3a;
  --danger: #a33d2e;
  --warning: #9a6a12;
  --shadow: 0 1px 3px rgba(28,39,51,.06), 0 4px 16px rgba(28,39,51,.05);
  --shadow-hover: 0 2px 6px rgba(28,39,51,.08), 0 10px 28px rgba(28,39,51,.09);
  --header-h: 60px;
  --sidebar-w: 300px;
  --font-heading: 'Lora', Georgia, 'Times New Roman', serif;
  --font-body: 'Karla', 'Segoe UI', system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all .2s ease-out;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1620;
    --surface: #17202b;
    --surface-2: #1e2836;
    --text: #e6e1d6;
    --text-soft: #c9c2b4;
    --muted: #9aa8b8;
    --accent: #6ba3d6;
    --accent-2: #8dbbe3;
    --accent-soft: #1c2c3f;
    --gold: #d4a94e;
    --gold-soft: #2c2415;
    --border: #2a3544;
    --border-strong: #3a4859;
    --success: #7fbf8a;
    --danger: #e08a7a;
    --warning: #d4b06a;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --shadow-hover: 0 2px 6px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
  }
}

/* --- RESET --- */
*, *::before, *::after { 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);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .3s ease, color .3s ease;
}

/* Subtle body gradient - spokojne tło */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 800px 500px at 85% -10%, rgba(58,124,165,.10), transparent 60%),
    radial-gradient(ellipse 700px 500px at -10% 105%, rgba(185,138,47,.07), transparent 60%);
  pointer-events: none;
}

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

img { max-width: 100%; height: auto; }

/* --- HEADER --- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.app-header::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-soft), transparent);
  opacity: .6;
  pointer-events: none;
}

.logo-mark { font-size: 1.35rem; line-height: 1; }

.logo-text {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.logo-text a { color: var(--text); }
.logo-text a:hover { color: var(--accent); }

.header-search {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  width: min(320px, 40vw);
  transition: var(--transition);
}
.header-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-icon { font-size: .9rem; opacity: .6; }
.header-search input {
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: .95rem;
  color: var(--text);
  width: 100%;
}
.header-search input::placeholder { color: var(--muted); }

.mobile-menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.15rem;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
}

/* --- SIDEBAR --- */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px 40px;
  z-index: 90;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.sidebar-nav { list-style: none; }

.sidebar-nav li { margin: 1px 0; }

.sidebar-nav a {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: .9rem;
  line-height: 1.35;
  transition: var(--transition);
}
.sidebar-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sidebar-nav a.active:hover { color: #fff; }

.nav-section {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 10px 4px;
  white-space: nowrap;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,22,32,.5);
  z-index: 89;
}

/* --- MAIN --- */
.main-content {
  margin-left: var(--sidebar-w);
  padding: calc(var(--header-h) + 28px) 32px 80px;
  max-width: 980px;
  min-height: 100vh;
}
.main-content > * { animation: fadeUp .25s ease-out both; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- HOME / HERO --- */
.home-hero {
  background: linear-gradient(135deg, #1d4e89 0%, #3a7ca5 70%, #5a9bc0 100%);
  border-radius: var(--radius);
  padding: 44px 40px;
  color: #fff;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
}
.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 400px 300px at 90% 10%, rgba(255,255,255,.14), transparent 60%),
    radial-gradient(ellipse 300px 240px at 10% 90%, rgba(255,255,255,.08), transparent 60%);
  pointer-events: none;
}
.home-hero h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
  margin-bottom: 12px;
}
.home-hero p {
  font-size: 1.05rem;
  max-width: 620px;
  opacity: .95;
  line-height: 1.6;
}
.home-hero .hero-stats {
  display: flex;
  gap: 32px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.home-hero .hero-stat strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
}
.home-hero .hero-stat span {
  font-size: .82rem;
  opacity: .85;
}

/* --- HOME CARDS --- */
.home-section { margin-bottom: 36px; }

.home-section h2 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  position: relative;
  text-wrap: balance;
}
.home-section h2::after {
  content: '';
  position: absolute;
  left: 0; bottom: -2px;
  width: 64px;
  height: 2px;
  background: var(--gold);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 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);
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.home-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  opacity: 0;
  transition: var(--transition);
}
.home-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--border-strong);
  color: var(--text);
}
.home-card:hover::before { opacity: 1; }

.home-card .card-icon { font-size: 1.4rem; line-height: 1; margin-bottom: 8px; }
.home-card h3 {
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 6px;
  color: var(--text);
}
.home-card p {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.5;
}

/* --- ARTICLE --- */
.content-article { max-width: 760px; }

.content-article h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 10px;
  text-wrap: balance;
}

.article-meta {
  font-size: .88rem;
  color: var(--muted);
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.content-article h2 {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 700;
  margin: 34px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: calc(var(--header-h) + 20px);
  text-wrap: balance;
}

.content-article h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 26px 0 10px;
  scroll-margin-top: calc(var(--header-h) + 20px);
}

.content-article p { margin: 12px 0; color: var(--text-soft); }
.content-article ul, .content-article ol { margin: 12px 0 12px 24px; color: var(--text-soft); }
.content-article li { margin: 6px 0; }
.content-article strong { color: var(--text); font-weight: 600; }

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

/* --- BOXES --- */
.info-box, .warning-box, .tip-box {
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 18px 0;
  font-size: .95rem;
  line-height: 1.6;
}
.info-box {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  color: var(--text-soft);
}
.warning-box {
  background: var(--gold-soft);
  border-left: 4px solid var(--gold);
  color: var(--text-soft);
}
.tip-box {
  background: var(--surface-2);
  border-left: 4px solid var(--success);
  color: var(--text-soft);
}
.info-box strong, .warning-box strong, .tip-box strong { color: var(--text); }

/* --- TABLES --- */
.table-responsive { overflow-x: auto; margin: 18px 0; }

table.compare-table, table.error-table, table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.compare-table th, .error-table th, .data-table th {
  background: var(--accent);
  color: #fff;
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: .9rem;
}
.compare-table td, .error-table td, .data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
  vertical-align: top;
}
.compare-table tr:nth-child(even) td, .error-table tr:nth-child(even) td, .data-table tr:nth-child(even) td {
  background: var(--surface-2);
}
.compare-table tr:last-child td, .error-table tr:last-child td, .data-table tr:last-child td {
  border-bottom: none;
}

/* --- FAQ --- */
.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin: 12px 0;
  overflow: hidden;
}
.faq-item summary {
  cursor: pointer;
  padding: 14px 18px;
  font-weight: 600;
  font-size: .98rem;
  color: var(--text);
  list-style: none;
  position: relative;
  padding-right: 40px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+';
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--accent);
  transition: var(--transition);
}
.faq-item[open] summary::after { transform: translateY(-50%) rotate(45deg); }
.faq-item summary:hover { background: var(--surface-2); }
.faq-item .faq-a {
  padding: 0 18px 14px;
  color: var(--text-soft);
  font-size: .95rem;
}

/* --- GLOSSARY --- */
.glossary { margin: 18px 0; }
.glossary dt {
  font-weight: 600;
  color: var(--text);
  margin-top: 16px;
  font-size: 1rem;
}
.glossary dd {
  color: var(--text-soft);
  margin: 4px 0 0;
  font-size: .95rem;
}

/* --- SEARCH RESULTS --- */
.search-results {
  position: fixed;
  top: var(--header-h);
  right: 20px;
  width: min(420px, calc(100vw - 40px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  z-index: 120;
  padding: 8px;
  display: none;
}
.search-results.visible { display: block; animation: fadeUp .18s ease-out both; }
.search-results a {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
}
.search-results a:hover { background: var(--surface-2); }
.search-results .sr-title { font-weight: 600; font-size: .93rem; }
.search-results .sr-excerpt { font-size: .82rem; color: var(--muted); }

/* --- 404 --- */
.not-found { text-align: center; padding: 80px 20px; }
.not-found h1 { font-family: var(--font-heading); font-size: 2.4rem; margin-bottom: 12px; }
.not-found p { color: var(--muted); margin-bottom: 20px; }

/* --- FOOTER NOTE --- */
.main-footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.6;
}

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

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

/* --- RESPONSIVE --- */
@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease-out; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar-overlay.visible { display: block; }
  .mobile-menu-btn { display: block; }
  .main-content { margin-left: 0; padding: calc(var(--header-h) + 20px) 18px 60px; }
  .header-search { width: auto; flex: 1; max-width: 260px; }
  .home-hero { padding: 32px 24px; }
  .home-hero h1 { font-size: 1.6rem; }
}

@media (max-width: 600px) {
  body { font-size: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .content-article h1 { font-size: 1.6rem; }
  .home-hero .hero-stats { gap: 20px; }
  .logo-text { font-size: .98rem; }
}

/* --- 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; }
}
