/* ==========================================================================
   EAC — reset, typografia bazowa, fokus, tryby wyświetlania
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + var(--space-4));
}

body {
  margin: 0;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: var(--fw-regular);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-title);
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-display-md);
  line-height: var(--lh-display-md);
  letter-spacing: var(--ls-display-md);
}
h2 {
  font-size: var(--fs-title);
  line-height: var(--lh-title);
}
h3 {
  font-size: var(--fs-subtitle);
  line-height: var(--lh-subtitle);
}
h4 {
  font-size: var(--fs-body-lg);
  line-height: var(--lh-body-lg);
}

p {
  margin: 0;
  text-wrap: pretty;
}

a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--text-secondary);
}

img,
svg,
video {
  max-width: 100%;
}

img {
  height: auto;
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

table {
  border-collapse: collapse;
  width: 100%;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-inline-size: 0;
}

legend {
  padding: 0;
}

hr {
  border: 0;
  border-top: var(--border-w) solid var(--border-soft);
  margin: var(--space-5) 0;
}

/* ---- Fokus ---------------------------------------------------------------
   Jeden pierścień w całej aplikacji. Na ciemnych powierzchniach przechodzi
   w jasny wariant — czarny outline na czerni był realnym błędem starego UI. */

:focus {
  outline: none;
}

:focus-visible {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-xs);
}

.on-dark :focus-visible,
.app-sidebar :focus-visible,
.panel--dark :focus-visible,
.code-panel :focus-visible {
  outline-color: var(--focus-color-on-dark);
}

/* Fokus nigdy nie chowa się pod sticky topbarem */
.app-main :focus-visible {
  scroll-margin-top: calc(var(--topbar-h) + var(--space-4));
}

/* ---- Skip link ---- */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-3) var(--space-4);
  background: var(--ink-900);
  color: var(--text-on-dark);
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

/* [hidden] musi wygrywać z display z komponentów (np. .bulk-bar { display: flex }) */
[hidden] {
  display: none !important;
}

/* ---- Klasy pomocnicze ---- */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  letter-spacing: var(--ls-caption);
  text-transform: uppercase;
  color: var(--text-muted);
}

.lead {
  font-size: var(--fs-body-lg);
  line-height: var(--lh-body-lg);
  color: var(--text-secondary);
}

.muted {
  color: var(--text-secondary);
}

.small {
  font-size: var(--fs-small);
  line-height: var(--lh-small);
}

.caption {
  font-size: var(--fs-caption);
  line-height: var(--lh-caption);
  color: var(--text-muted);
}

.mono {
  font-family: var(--font-mono);
}

.nowrap {
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.stack--tight {
  gap: var(--space-3);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.row--between {
  justify-content: space-between;
  align-items: flex-start;
}

.push-right {
  margin-left: auto;
}

/* ---- Basic / Professional -------------------------------------------------
   Tryby dotyczą wyłącznie gęstości informacji, nigdy uprawnień (spec 8). */

.mode-basic .professional-only {
  display: none !important;
}

.mode-professional .basic-only {
  display: none !important;
}

/* ---- Ruch ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Tryb wysokiego kontrastu systemu ----
   Statusy niosą kształt i tekst, więc pozostają rozróżnialne bez koloru. */
@media (forced-colors: active) {
  .badge,
  .card,
  .panel,
  .app-sidebar {
    border: 1px solid CanvasText;
  }

  :focus-visible {
    outline: 3px solid Highlight;
  }

  .chart__canvas {
    display: none;
  }

  .chart__data {
    display: block;
  }

  .chart__data > summary {
    display: none;
  }
}

/* ---- Druk ---- */
@media print {
  .app-sidebar,
  .app-topbar,
  .skip-link,
  .drawer,
  .page-actions,
  .bulk-bar {
    display: none !important;
  }

  .app-layout,
  .app-main {
    display: block;
    padding: 0;
    margin: 0;
  }

  .card,
  .panel {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #999;
  }

  .chart__data[open],
  .chart__data {
    display: block;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 10px;
    color: #555;
  }
}
