/*
 * Visual system of the portal and of the critique page: tokens, typography, components.
 *
 * One source: the portal serves this file as /static/tokens.css; report.py pastes it as is into
 * the <style> of prezentacja.html and of the series' index.html, so it stays self-contained (no
 * url(), no @import, no fonts or images to fetch). portal.css holds only the layout of the portal
 * pages and builds on these classes.
 *
 * Tokens — the only colours used anywhere; light and dark follow prefers-color-scheme.
 *   --paper    page background            --surface  cards, header, fields
 *   --ink      text                       --sub      secondary text, field borders
 *   --line     decorative rules only (too faint for a control border)
 *   --green    primary button, links      --on       text on --green
 *   --soft     highlighted card, badge    --ochre    logo accent, quotes, focus ring
 *   --danger   error text and borders
 *   --s1 … --s6  spacing on an 8 px rhythm (8, 16, 24, 32, 48, 64 px)
 *   Each colour is written three times: light value, dark value in @media, and
 *   light-dark() for browsers that have it. tests/portal/test_visual_system.py checks that
 *   the three agree and that the text pairs reach WCAG AA contrast in both modes.
 *
 * Components
 *   .btn                 primary button (dark green); on <button> and <a>
 *   .btn-secondary       outlined button
 *   .btn-danger          destructive action ("Usuń na zawsze"): --surface text on --danger
 *   .btn-link            button that looks like a link
 *   .btn-small           compact button (tables) — still a 44 px target
 *   .card                light card with rounded corners
 *   .card-accent         highlighted card in soft green ("Zadanie", "Następny krok")
 *   .badge               small label ("Nowa korekta", "Beta · zaproszenie")
 *   .eyebrow             section label: small spaced capitals
 *   .lead / .muted / .hint   larger intro text / secondary text / help text
 *   .field               label above the input, then .hint, then .field-error
 *   .field-error         error next to its field: an icon and text, never colour alone
 *   .notice / .notice-error  message box (ochre / red rule on the left)
 *   .state + .state-done | .state-pending | .state-failed
 *                        status as text plus a shape (filled circle, ring, diamond)
 *   .state-list          a list of .state items
 *   .check               checkbox or radio with its label, 44 px tall
 *   details / summary    expandable section with an arrow, 44 px summary
 *   .scroll              wrapper that lets a wide table scroll sideways
 *   .site-footer         page footer
 * Every focusable element gets a visible :focus-visible ring; motion is off for
 * prefers-reduced-motion.
 */

:root {
  color-scheme: light dark;
  --paper: #f5f3ed;
  --surface: #fffefa;
  --ink: #243c32;
  --sub: #626d65;
  --line: #d9dfd5;
  --green: #244e3c;
  --on: #fffefa;
  --soft: #e8eedf;
  --ochre: #92602e;
  --danger: #a12a22;
  --s1: 8px;
  --s2: 16px;
  --s3: 24px;
  --s4: 32px;
  --s5: 48px;
  --s6: 64px;
  --radius: 8px;
  --target: 44px;
  --measure: 68ch;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #202321;
    --surface: #282d29;
    --ink: #e5eee5;
    --sub: #b5c1b8;
    --line: #465248;
    --green: #b1d2a8;
    --on: #173322;
    --soft: #354b39;
    --ochre: #e5bb81;
    --danger: #f2a199;
  }
}

@supports (color: light-dark(#000, #fff)) {
  :root {
    --paper: light-dark(#f5f3ed, #202321);
    --surface: light-dark(#fffefa, #282d29);
    --ink: light-dark(#243c32, #e5eee5);
    --sub: light-dark(#626d65, #b5c1b8);
    --line: light-dark(#d9dfd5, #465248);
    --green: light-dark(#244e3c, #b1d2a8);
    --on: light-dark(#fffefa, #173322);
    --soft: light-dark(#e8eedf, #354b39);
    --ochre: light-dark(#92602e, #e5bb81);
    --danger: light-dark(#a12a22, #f2a199);
  }
}

/* --- base and typography ------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 1.0625rem/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper);
  overflow-wrap: break-word;
}
h1, h2, h3 { font-family: var(--serif); font-weight: normal; color: var(--ink); }
h1 { font-size: 1.875rem; line-height: 1.15; letter-spacing: -0.02em; margin: var(--s1) 0 var(--s2); }
h2 { font-size: 1.5rem; line-height: 1.2; margin: var(--s4) 0 var(--s2); }
h3 { font-size: 1.1875rem; line-height: 1.3; margin: var(--s3) 0 var(--s1); }
@media (min-width: 40rem) { h1 { font-size: 2.25rem; } }
p, ul, ol { margin: 0 0 var(--s2); }
p, li, dd, .hint, .lead { max-width: var(--measure); }
a { color: var(--green); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s3) 0; }
strong, b { font-weight: 700; }

.lead { font-size: 1.1875rem; }
.muted, .hint { color: var(--sub); }
.hint { font-size: 0.9375rem; margin: var(--s1) 0 0; }
.eyebrow {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sub);
  margin: 0 0 var(--s1);
}

:focus-visible { outline: 3px solid var(--ochre); outline-offset: 3px; }

/* --- buttons ------------------------------------------------------------------------- */

.btn, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  min-height: var(--target);
  min-width: var(--target);
  padding: 10px var(--s3);
  font: inherit;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  border: 2px solid var(--green);
  border-radius: 6px;
  cursor: pointer;
}
.btn { color: var(--on); background: var(--green); }
.btn-secondary { color: var(--green); background: var(--surface); }
.btn-danger { color: var(--surface); background: var(--danger); border-color: var(--danger); }
.btn:hover, .btn-secondary:hover, .btn-danger:hover { text-decoration: underline; }
.btn-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 0;
  font: inherit;
  color: var(--green);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.btn-small { padding: 6px var(--s2); font-size: 0.9375rem; }
.btn:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: 0.45; cursor: default; }

/* --- cards, badges, notices ---------------------------------------------------------- */

.card {
  padding: var(--s3);
  margin: 0 0 var(--s2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-accent { background: var(--soft); border-color: var(--soft); }
.card > :last-child, .notice > :last-child { margin-bottom: 0; }
.badge {
  display: inline-block;
  padding: 3px var(--s1);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--soft);
  border-radius: 4px;
}
.notice {
  padding: var(--s2);
  margin: 0 0 var(--s2);
  background: var(--soft);
  border-left: 4px solid var(--ochre);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.notice-error { background: var(--surface); border-left-color: var(--danger); }

/* --- form fields --------------------------------------------------------------------- */

.field { margin: 0 0 var(--s3); }
label, .label { display: block; margin: 0 0 6px; font-weight: 600; }
input[type="text"], input[type="number"], input[type="url"], input[type="email"],
input:not([type]), textarea, select {
  display: block;
  width: 100%;
  min-height: var(--target);
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--sub);
  border-radius: 6px;
}
textarea { min-height: 6rem; resize: vertical; }
input[type="file"] { display: block; width: 100%; min-height: var(--target); padding: 6px 0; font: inherit; }
input[type="checkbox"], input[type="radio"] {
  width: 1.25rem; height: 1.25rem; margin: 2px 0 0; flex: none; accent-color: var(--green);
}
[aria-invalid="true"], .field.has-error input, .field.has-error textarea, .field.has-error select {
  border: 2px solid var(--danger);
}
.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-height: var(--target);
  padding: 10px 0;
  margin: 0;
  font-weight: normal;
  cursor: pointer;
}
.field-error {
  display: flex;
  gap: 6px;
  margin: 6px 0 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--danger);
}
.field-error::before {
  content: "!";
  content: "!" / "";
  flex: none;
  width: 1.25em;
  height: 1.25em;
  margin-top: 0.1em;
  font-size: 0.875em;
  line-height: 1.25em;
  text-align: center;
  color: var(--surface);
  background: var(--danger);
  border-radius: 50%;
}

/* --- statuses: text + shape, never colour alone --------------------------------------- */

.state-list { padding: 0; list-style: none; }
.state-list > li { margin: 0 0 var(--s1); }
.state { display: inline-flex; gap: var(--s1); align-items: baseline; }
.state::before {
  content: "";
  flex: none;
  width: 0.7em;
  height: 0.7em;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.state-done { color: var(--green); }
.state-done::before { background: currentColor; }
.state-pending { color: var(--sub); }
.state-failed { color: var(--danger); }
.state-failed::before { border-radius: 1px; background: currentColor; transform: rotate(45deg) scale(0.85); }

/* --- expandable sections ------------------------------------------------------------- */

details { border-top: 1px solid var(--line); }
summary {
  display: flex;
  align-items: center;
  gap: var(--s1);
  min-height: var(--target);
  padding: var(--s1) 0;
  font-weight: 600;
  color: var(--green);
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "";
  flex: none;
  width: 0.5em;
  height: 0.5em;
  margin: 0 0.2em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
details[open] > summary::before { transform: rotate(45deg); }
details > :not(summary) { margin-top: var(--s1); }

/* --- tables, footer ------------------------------------------------------------------ */

.scroll { overflow-x: auto; margin: 0 0 var(--s2); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 0.9375rem; }
th, td { padding: var(--s1); text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--sub); }

.site-footer {
  padding: var(--s2) var(--s3);
  font-size: 0.875rem;
  color: var(--sub);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.site-footer p { margin: 0; }

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