/* WRSM 2026 — Classical design system (light + derived dark theme).
   Tokens first; component classes reference only the tokens. */

/* Combined latin + latin-ext + Polish-diacritics subset in one file each
   (pyftsubset, exact union of the codepoints the two split files used to
   cover — verified no glyph lost). One file per family means one request
   and no unicode-range fallback gap, instead of two ~20-40 KB files. */
@font-face {
  font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../fonts/cormorant-garamond-600-pl.woff2') format('woff2');
}
@font-face {
  font-family: 'Lora'; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url('../fonts/lora-pl.woff2') format('woff2');
}

:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

:root {
  /* base roles — light value, dark value */
  --bg:      light-dark(#f3f2f2, #1d1c1a);
  --surface: light-dark(#eae9e9, #262523);
  --text:    light-dark(#201f1d, #ece9e4);
  --accent:  light-dark(#b68235, #d9a856);
  /* --accent as body text fails AA in light bursztyn (3.0:1) — a darker
     value used only for text roles (links, chat-sender, active tab).
     The 5 alt palettes already clear 4.5:1 with --accent itself, so each
     overrides this back to var(--accent) below. */
  --accent-text: light-dark(#8a5f22, #d9a856);
  --divider: light-dark(color-mix(in srgb, #201f1d 16%, transparent),
                        color-mix(in srgb, #ece9e4 18%, transparent));
  /* --divider (16%/18%) is too faint for form control borders (1.37:1 L /
     1.67:1 D — WCAG 1.4.11 wants 3:1 for UI components). A separate,
     stronger token for controls; --divider stays for decorative
     separators (hr, card borders) which can remain subtle. */
  --control-border: light-dark(color-mix(in srgb, #201f1d 50%, transparent),
                               color-mix(in srgb, #ece9e4 45%, transparent));

  /* neutral ramp (dark = inverted lightness) */
  --n-100: light-dark(#f8f4f4, #2d2b2b);
  --n-200: light-dark(#eae7e7, #444141);
  --n-300: light-dark(#d7d3d3, #605d5d);
  --n-800: light-dark(#444141, #eae7e7);
  --n-900: light-dark(#2d2b2b, #f8f4f4);

  /* accent ramp endpoints used by tags */
  --a-100: light-dark(#fff3e4, #3a270d);
  --a-800: light-dark(#5a3b0a, #facb8d);

  --ok:   light-dark(#256040, #59b586);
  --warn: light-dark(#9a6b0f, #e0a020);
  --err:  light-dark(#a04430, #e8a898);

  /* semantic tag ramps */
  --p-100: light-dark(#e8f0fe, #1a2744);
  --p-800: light-dark(#1a4d8f, #8ab4f8);
  --s-100: light-dark(#e6f4ea, #1a3324);
  --s-800: light-dark(#1e6e3e, #81c995);
  --w-100: light-dark(#fef7e0, #3a2e0a);
  --w-800: light-dark(#7c5c00, #fdd663);
  --i-100: light-dark(#e0f7fa, #0d3038);
  --i-800: light-dark(#006064, #80deea);

  --font-heading: "Cormorant Garamond", Georgia, 'Times New Roman', serif;
  --font-heading-weight: 600;
  --font-body: "Lora", Georgia, serif;

  --space-1: 4.6px; --space-2: 9.2px; --space-3: 13.8px;
  --space-4: 18.4px; --space-6: 27.6px; --space-8: 36.8px;
  --radius-sm: 2px; --radius-md: 4px; --radius-lg: 7px;

  --shadow-sm: light-dark(0 1px 2px color-mix(in srgb, #2d2b2b 14%, transparent), 0 0 0 1px #38352f);
  --shadow-md: light-dark(0 3px 10px color-mix(in srgb, #2d2b2b 16%, transparent), 0 0 0 1px #403c35);
  --shadow-lg: light-dark(0 12px 32px color-mix(in srgb, #2d2b2b 22%, transparent), 0 0 0 1px #4a463e);

  --tabbar-h: 58px;
  --topbar-h: 52px;

  /* animation tokens — compositor-only (transform/opacity), short and
     calm to match the classical style; prefers-reduced-motion kill-switch
     is at the end of this file. */
  --dur-fast: 150ms;
  --dur-med: 200ms;
  --dur-slow: 300ms;
  --ease-out: cubic-bezier(.25,.6,.3,1);

  /* Container widths per Bulma breakpoints: mobile <769, tablet ≥769 (fluid),
     desktop ≥1024 → 960px, widescreen ≥1216 → 1152px, fullhd ≥1408 → 1344px. */
  --container: 480px;
}
@media (min-width: 481px)  { :root { --container: min(600px, 100vw - 32px); } }
@media (min-width: 769px)  { :root { --container: calc(100vw - 64px); } }
@media (min-width: 1024px) { :root { --container: 960px; } }
@media (min-width: 1216px) { :root { --container: 1152px; } }
@media (min-width: 1408px) { :root { --container: 1344px; } }

/* ── color palettes (data-palette on <html>, orthogonal to data-theme) ──
   bursztyn is the default (no attribute needed) and matches the values
   already declared above; each variant below overrides only the roles
   that differ, everything else (--n-*, --p/--s/--w/--i, --ok/--warn,
   shadows) stays shared. */
:root[data-palette="szmaragd"] {
  --bg:      light-dark(#f0f4f1, #191e1a);
  --surface: light-dark(#e6ece8, #222824);
  --accent:  light-dark(#1d7049, #63bd92);
  --accent-text: var(--accent);
  --a-100:   light-dark(#e2f3e9, #10311f);
  --a-800:   light-dark(#14532d, #a3d9b8);
}
:root[data-palette="burgund"] {
  --bg:      light-dark(#f5f1f0, #201b1b);
  --surface: light-dark(#ece6e5, #2a2423);
  --accent:  light-dark(#8e2f43, #dd8f9e);
  --accent-text: var(--accent);
  --a-100:   light-dark(#fbe9ed, #3b1620);
  --a-800:   light-dark(#641e30, #f2b8c3);
}
:root[data-palette="szafir"] {
  --bg:      light-dark(#f0f2f5, #191c20);
  --surface: light-dark(#e6e9ee, #22252b);
  --accent:  light-dark(#2f5da8, #8fb4ef);
  --accent-text: var(--accent);
  --a-100:   light-dark(#e6eefb, #142443);
  --a-800:   light-dark(#1c3d74, #b6cff5);
}
:root[data-palette="wrzos"] {
  --bg:      light-dark(#f3f1f5, #1d1b20);
  --surface: light-dark(#eae7ee, #26232b);
  --accent:  light-dark(#6b4a9c, #b79ce6);
  --accent-text: var(--accent);
  --a-100:   light-dark(#efe7f8, #2a1d3f);
  --a-800:   light-dark(#462d70, #d4c0f0);
}
:root[data-palette="oliwka"] {
  --bg:      light-dark(#f3f3ee, #1c1c17);
  --surface: light-dark(#eaeae3, #252520);
  --accent:  light-dark(#5d671c, #b7c25f);
  --accent-text: var(--accent);
  --a-100:   light-dark(#f0f2d8, #2c2e10);
  --a-800:   light-dark(#3f4611, #d6dd94);
}

/* ── base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* component display rules must not defeat the hidden attribute */
/* Typographic scale: rem-based, html font-size grows with the viewport so
   every component scales together on larger screens. */
html { height: 100%; font-size: 15px; }
@media (min-width: 1024px) { html { font-size: 16px; } }
@media (min-width: 1216px) { html { font-size: 17px; } }
@media (min-width: 1408px) { html { font-size: 18px; } }
/* User font-size override (data-fontsize attribute set by JS) */
:root[data-fontsize="80"]  { font-size: 12px !important; }
:root[data-fontsize="90"]  { font-size: 14px !important; }
:root[data-fontsize="110"] { font-size: 18px !important; }
:root[data-fontsize="120"] { font-size: 20px !important; }
:root[data-fontsize="130"] { font-size: 21px !important; }
:root[data-fontsize="140"] { font-size: 23px !important; }
:root[data-fontsize="150"] { font-size: 24px !important; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 1rem; line-height: 1.55;
}
h1,h2,h3,h4,h5,h6 {
  font-family: var(--font-heading); font-weight: var(--font-heading-weight);
  line-height: 1.12; letter-spacing: -0.015em; margin: 0 0 var(--space-2);
}
h1{font-size:2.8rem} h2{font-size:2.13rem} h3{font-size:1.67rem} h4{font-size:1.33rem} h5{font-size:1.07rem}
h6, .k { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 65%, transparent);
  font-family: var(--font-body); font-weight: 600; margin: 0; }
p { margin: 0 0 var(--space-2); }
a { color: var(--accent-text); text-underline-offset: 3px; }
img { display: block; max-width: 100%; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.text-muted { color: color-mix(in srgb, var(--text) 65%, transparent); }
.visually-hidden { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.skip-link {
  position: absolute; top: -100px; left: var(--space-2); z-index: 50;
  background: var(--surface); color: var(--text); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  transition: top var(--dur-fast);
}
.skip-link:focus-visible { top: var(--space-2); }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--space-2); }
.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.hr { height: 1px; border: 0; margin: var(--space-3) 0; background: var(--divider); }

/* ── spacing/layout utilities — override .row/.stack's default gap, or
   add margin, without a one-off inline style ──────────────────────── */
.row-wrap { flex-wrap: wrap; }
.gap-0 { gap: 0; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.m-0 { margin: 0; }
.text-center { text-align: center; }

/* ── app shell ────────────────────────────────────────────────────── */
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }
#page {
  max-width: var(--container); margin-inline: auto; width: 100%;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-4));
  animation: page-in var(--dur-med) var(--ease-out);
}
.page-pad {
  padding: var(--space-3);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
}
.page-head { margin-bottom: var(--space-2); }
.page-title { margin: 0; font-size: 1.67rem; }

@keyframes nav-progress { 0% { opacity: 1; transform: scaleX(0); } 100% { opacity: 1; transform: scaleX(.85); } }
#nav-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 30;
  background: var(--accent); transform-origin: left; transform: scaleX(0);
  opacity: 0; transition: opacity var(--dur-fast);
}
#nav-progress.htmx-request {
  animation: nav-progress 1.2s cubic-bezier(.1,.7,.4,1) 120ms forwards;
}

/* form.htmx-request: htmx adds this class to the requesting element itself
   (independent of hx-indicator) for the duration of the request — dim the
   submit so a slow response doesn't invite a second click / duplicate post. */
form.htmx-request button[type="submit"] { opacity: .6; pointer-events: none; }

/* ── toast (transient success/error feedback) ────────────────────────── */
.toast-region {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-3));
  transform: translateX(-50%); z-index: 40;
  display: flex; flex-direction: column; gap: var(--space-2); align-items: center;
  pointer-events: none; width: min(420px, calc(100% - 2 * var(--space-3)));
}
@media (min-width: 769px) {
  .toast-region { bottom: var(--space-4); }
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-md);
  border: 1px solid var(--divider); font-size: .87rem;
  animation: toast-in var(--dur-med) var(--ease-out);
  transition: opacity var(--dur-med), transform var(--dur-med);
}
.toast.is-leaving { opacity: 0; transform: translateY(4px); }
.toast-error { border-color: var(--err); color: var(--err); }
.toast-success { border-color: var(--ok); color: var(--ok); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-2);
  padding: calc(var(--space-2) + env(safe-area-inset-top)) var(--space-3) var(--space-2);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--divider);
  max-width: var(--container); margin-inline: auto;
  min-height: var(--topbar-h);
}
.topbar-brand {
  font-family: var(--font-heading); font-weight: 600; font-size: 1.33rem;
  color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 6px;
}
.topbar-logo { border-radius: 6px; }
.app-version {
  font-size: .67rem; letter-spacing: .04em; align-self: flex-end; padding-bottom: 3px;
  color: color-mix(in srgb, var(--text) 65%, transparent);
}
.dev-badge {
  font-size: .67rem; font-weight: 700; letter-spacing: .04em;
  color: #fff; background: #dc2626; border-radius: 4px;
  padding: 1px 6px; align-self: center;
}
.update-badge { cursor: pointer; font-weight: 600; }
.update-badge:hover { box-shadow: 0 0 0 1px var(--accent); }

@keyframes dot-blink { 50% { opacity: .35; } }
@keyframes dot-pop { 0% { transform: scale(.5); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
.conn-dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--warn); transition: background .3s;
}
[data-conn="online"] .conn-dot { background: var(--ok); animation: dot-pop var(--dur-med) var(--ease-out); }
[data-conn="offline"] .conn-dot { animation: dot-blink 2s ease-in-out infinite; }

.tabbar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 20;
  display: flex; max-width: var(--container); margin-inline: auto;
  background: var(--surface); border-top: 1px solid var(--divider);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 0 6px; font-size: .73rem; text-decoration: none;
  color: color-mix(in srgb, var(--text) 68%, transparent);
  position: relative; transition: color var(--dur-fast);
}
.tabbar a[aria-current="page"] { color: var(--accent-text); font-weight: 600; }
.tab-icon { font-size: 1.13rem; line-height: 1; transition: transform 100ms; }
.tabbar a:active .tab-icon { transform: scale(.88); }
@keyframes badge-pop { 0% { transform: scale(.5); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.tab-badge {
  position: absolute; top: 3px; right: calc(50% - 22px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--accent-text); color: light-dark(#fff, #1d1c1a);
  font-size: .7rem; line-height: 16px; text-align: center; font-weight: 600;
}
.tab-badge:not(.is-empty) { animation: badge-pop var(--dur-med) var(--ease-out); }
.tab-badge.is-empty { display: none; }
.badge-inline {
  display: inline-block; min-width: 16px; height: 16px; padding: 0 4px;
  margin-left: 6px; border-radius: 999px; background: var(--accent-text);
  color: light-dark(#fff, #1d1c1a); font-size: .7rem; line-height: 16px;
  text-align: center; font-weight: 600; vertical-align: middle;
}

.offline-banner {
  max-width: var(--container); margin-inline: auto;
  background: var(--a-100);
  border-bottom: 1px solid var(--accent);
  color: var(--a-800);
  padding: 6px var(--space-3); font-size: .83rem;
}
[data-conn="offline"] .needs-net { opacity: .45; pointer-events: none; }
.is-stale #page { opacity: .75; }

.sync-queue {
  max-width: var(--container); margin-inline: auto;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px dashed var(--divider);
}
.sync-queue ul { margin: var(--space-1) 0 0; padding: 0; list-style: none; font-size: .87rem; }
.sync-queue li::before { content: '⏳ '; }

/* ── buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; text-decoration: none;
  font-family: var(--font-heading); font-weight: 600;
  font-size: .93rem; line-height: 1.2; color: var(--text);
  background: transparent; border: 1px solid transparent;
  padding: calc(var(--space-2) * .95) var(--space-3);
  border-radius: var(--radius-md);
  transition: background-color var(--dur-fast), border-color var(--dur-fast), transform 100ms;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn-primary:active { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.btn-secondary { border-color: var(--divider); }
.btn-secondary:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.btn-ghost { color: var(--accent-text); padding-inline: var(--space-1); }
.btn-ghost:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.btn-danger { color: var(--err); border-color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); }
.btn-danger:active { background: color-mix(in srgb, var(--err) 22%, transparent); }
.btn-outline { border-color: var(--accent); color: var(--accent-text); }
.btn-outline:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.btn-sm { font-size: .8rem; padding: 4px 10px; }
.btn-icon { width: 34px; height: 34px; padding: 0; font-size: 18px; }
.btn-block { width: 100%; }

/* ── forms ────────────────────────────────────────────────────────── */
.field > label {
  display: block; font-size: .8rem; margin-bottom: 5px;
  color: color-mix(in srgb, var(--text) 70%, transparent);
}
.field-row { display: flex; gap: var(--space-2); }
.field-row .field { flex: 1; min-width: 0; }
@media (max-width: 480px) { .field-row { flex-direction: column; } }
.input {
  width: 100%; min-height: 38px; padding: 6px 10px; font: inherit;
  font-size: .93rem; color: var(--text); caret-color: var(--accent);
  background: transparent;
  border: 1px solid var(--control-border); border-radius: var(--radius-md);
}
.input:hover { border-color: color-mix(in srgb, var(--text) 60%, transparent); }
.input:focus-visible { border-color: var(--accent); outline-offset: 0; }
.input::placeholder { color: color-mix(in srgb, var(--text) 65%, transparent); opacity: 1; }
textarea.input { min-height: 60px; resize: vertical; }
.select-narrow { width: auto; max-width: 40%; }
.form-error {
  background: light-dark(#f6e4e0, #3c2320); border: 1px solid light-dark(#c0604e, #d98673);
  color: light-dark(#8a3a2b, #e8a898);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); font-size: .9rem;
}
.radio { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .93rem; }
.radio input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.radio .dot {
  width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 1.5px solid var(--control-border);
}
.radio:hover .dot { border-color: var(--accent); }
.radio input:checked + .dot {
  border-color: var(--accent); background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--bg);
}
.radio input:focus-visible + .dot { outline: 2px solid var(--accent); outline-offset: 2px; }

/* .check: same structure as .radio but square with a checkmark — for
   actual multi-select checkboxes, so their shape doesn't imply
   "choose one" the way a round .radio dot does. */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .93rem; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.check .box {
  width: 16px; height: 16px; flex: none; border-radius: 3px;
  border: 1.5px solid var(--divider); position: relative;
}
.check:hover .box { border-color: var(--accent); }
.check input:checked + .box {
  border-color: var(--accent); background: var(--accent);
}
.check input:checked + .box::after {
  content: ''; position: absolute; left: 4px; top: 1px;
  width: 4px; height: 8px; border: solid var(--bg);
  border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg {
  display: inline-flex; overflow: hidden; border: 1px solid var(--control-border);
  border-radius: var(--radius-md); padding: 0; margin: 0;
}
.seg-opt, .seg > a {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 12px; font-size: .87rem; cursor: pointer;
  color: var(--text); text-decoration: none; flex: 1;
}
.seg-opt + .seg-opt, .seg > a + a { border-left: 1px solid var(--divider); }
.seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.seg-opt:has(input:checked), .seg > a[aria-current="true"] {
  color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent);
}
.seg-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.group-tabs {
  display: flex; width: 100%; overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.group-tabs::-webkit-scrollbar { display: none; }
.group-tabs > a { flex: 0 0 auto; white-space: nowrap; }

/* Palette picker: swatches must show each palette's OWN colors regardless
   of which one is currently active, so they're hardcoded here rather than
   drawn from tokens. */
.palette-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: var(--space-2); border: 0; padding: 0; margin: 0;
}
.palette-opt {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: var(--space-2); border-radius: var(--radius-md);
  border: 1px solid var(--divider); cursor: pointer; font-size: .8rem;
  text-align: center; transition: transform var(--dur-fast), border-color var(--dur-fast);
}
.palette-opt:hover { transform: translateY(-2px); }
.palette-opt input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.palette-opt:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.palette-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.palette-swatch {
  width: 32px; height: 32px; border-radius: 50%; display: block;
  background: linear-gradient(135deg, var(--sw-accent), var(--sw-accent-2));
}
.palette-opt[data-palette="bursztyn"] .palette-swatch { --sw-accent: #b68235; --sw-accent-2: #5a3b0a; }
.palette-opt[data-palette="szmaragd"] .palette-swatch { --sw-accent: #1d7049; --sw-accent-2: #14532d; }
.palette-opt[data-palette="burgund"]  .palette-swatch { --sw-accent: #8e2f43; --sw-accent-2: #641e30; }
.palette-opt[data-palette="szafir"]   .palette-swatch { --sw-accent: #2f5da8; --sw-accent-2: #1c3d74; }
.palette-opt[data-palette="wrzos"]    .palette-swatch { --sw-accent: #6b4a9c; --sw-accent-2: #462d70; }
.palette-opt[data-palette="oliwka"]   .palette-swatch { --sw-accent: #5d671c; --sw-accent-2: #3f4611; }

/* Kafelkowy widok strony Akcje — kolory kafelków cyklicznie z palety 6
   akcentów aplikacji (klucz-wartość bez znaczenia semantycznego). */
.actions-tiles {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--space-3);
}
.action-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2); padding: var(--space-3) var(--space-2); border-radius: var(--radius-lg);
  text-decoration: none; color: var(--text); text-align: center; position: relative;
  aspect-ratio: 1; transition: transform var(--dur-fast);
  background: color-mix(in srgb, var(--tile-accent) 20%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--tile-accent) 35%, var(--divider));
}
.action-tile:hover, .action-tile:focus-visible { transform: translateY(-2px); }
.action-tile-icon { font-size: 2.25rem; line-height: 1; }
.action-tile-label { font-size: .8rem; font-weight: 600; }
.action-tile .badge-inline { position: absolute; top: 6px; right: 6px; }
[data-conn="offline"] .action-tile.needs-net { opacity: .45; pointer-events: none; }
.action-tile:nth-child(6n+1) { --tile-accent: #b68235; }
.action-tile:nth-child(6n+2) { --tile-accent: #1d7049; }
.action-tile:nth-child(6n+3) { --tile-accent: #2f5da8; }
.action-tile:nth-child(6n+4) { --tile-accent: #8e2f43; }
.action-tile:nth-child(6n+5) { --tile-accent: #6b4a9c; }
.action-tile:nth-child(6n+0) { --tile-accent: #5d671c; }

.switch {
  width: 40px; height: 22px; border-radius: 999px; border: 1.5px solid var(--control-border);
  background: transparent; cursor: pointer; padding: 1px; display: inline-flex;
}
.switch .knob {
  width: 16px; height: 16px; border-radius: 50%;
  background: color-mix(in srgb, var(--text) 55%, transparent);
  transition: transform var(--dur-fast), background-color var(--dur-fast);
}
.switch[aria-checked="true"] { border-color: var(--accent); }
.switch[aria-checked="true"] .knob { background: var(--accent); transform: translateX(18px); }

.file-input { font-size: .8rem; max-width: 45%; color: var(--text); }

/* ── cards & tags ─────────────────────────────────────────────────── */
.card {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3); border-radius: var(--radius-md);
  background: transparent; border: 1px solid var(--divider);
}
.card.row { flex-direction: row; align-items: center; }
.card-title { font-family: var(--font-heading); font-weight: 600; font-size: 1.13rem; line-height: 1.2; }
.card-body { margin: 0; font-size: .93rem; opacity: .85; }
.card-meta {
  display: flex; align-items: center; gap: 6px; font-size: .77rem;
  color: color-mix(in srgb, var(--text) 65%, transparent);
}
.card-photo {
  border-radius: var(--radius-sm); width: 100%; aspect-ratio: 4 / 3;
  object-fit: cover; background: var(--surface);
}

/* ── empty state — one shared pattern for "nothing here yet", with an
   optional call-to-action when the viewer could create something ──── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-2); padding: var(--space-4) var(--space-2);
}
.empty-state-icon { font-size: 2rem; opacity: .6; }
.empty-state p { margin: 0; }
.card-desc { margin-top: var(--space-2); padding: var(--space-2); background: var(--n-100); border-radius: var(--radius-sm); font-size: .9rem; white-space: pre-wrap; }
.desc-toggle { font-size: .8rem; padding: 2px 8px; }
.changelog-list { margin: 0; padding-left: 1.2em; font-size: .9rem; opacity: .85; }
.changelog-list li { margin-bottom: var(--space-1); }
.changelog-version { border-bottom: 1px solid var(--n-200); }
.changelog-version:last-child { border-bottom: 0; }
.changelog-version-head {
  display: flex; align-items: baseline; gap: var(--space-2);
  padding: var(--space-2) 0; cursor: pointer; list-style: none;
  font-size: .95rem; user-select: none;
}
.changelog-version-head::-webkit-details-marker { display: none; }
.changelog-version-head .changelog-arrow { font-size: .7rem; transition: transform .15s; flex-shrink: 0; }
.changelog-version[open] > .changelog-version-head .changelog-arrow { transform: rotate(90deg); }
.changelog-version > .changelog-list { padding-top: var(--space-1); padding-bottom: var(--space-2); }
.elev-sm { box-shadow: var(--shadow-sm); }

.tag {
  display: inline-flex; align-items: center; font-size: .73rem; letter-spacing: .02em;
  padding: 3px 10px; border-radius: 3px; border: 0; cursor: default;
  font-family: var(--font-body); white-space: nowrap;
}
button.tag { cursor: pointer; }
.rsvp-chips { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.tag-accent { background: var(--a-100); color: var(--a-800); }
.tag-neutral { background: var(--n-100); color: var(--n-800); }
.tag-primary { background: var(--p-100); color: var(--p-800); }
.tag-success { background: var(--s-100); color: var(--s-800); }
.tag-warning { background: var(--w-100); color: var(--w-800); }
.tag-info { background: var(--i-100); color: var(--i-800); }
.tag-outline { border: 1px solid var(--accent); color: var(--accent-text); background: transparent; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--n-200); color: var(--n-800);
  font-size: .8rem; font-weight: 600; text-decoration: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: .73rem; }
.avatar-xs { width: 22px; height: 22px; font-size: .63rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.33rem; }

/* ── dashboard ────────────────────────────────────────────────────── */
.next-up, .event-card {
  flex-direction: row; align-items: center; text-decoration: none; color: inherit;
}
.date-block {
  text-align: center; line-height: 1.05; flex: none; min-width: 40px;
  font-family: var(--font-heading);
}
.date-day { font-size: 1.47rem; font-weight: 600; }
.date-month { font-size: .73rem; text-transform: uppercase; letter-spacing: .06em;
  color: color-mix(in srgb, var(--text) 65%, transparent); }
.announcement { transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out); }
.announcement.htmx-added { opacity: 0; transform: translateY(-4px); }
.announcement .author { font-weight: 600; font-size: .9rem; }
.feed-more { height: 1px; }

/* ── groups / members ─────────────────────────────────────────────── */
.group-row, .member-row { text-decoration: none; color: inherit; }
.member-link { text-decoration: none; color: inherit; }
.create-group summary { cursor: pointer; color: var(--accent-text); font-size: .93rem; }
.create-group[open] summary { margin-bottom: var(--space-2); }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; padding: 2px 8px; font-size: 1.07rem; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: 100%; z-index: 10; min-width: 170px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--divider);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); overflow: hidden;
}
.menu-items button, .menu-items a {
  display: block; width: 100%;
  text-align: left; padding: 9px 12px; font: inherit; font-size: .9rem;
  background: none; border: 0; color: var(--text); cursor: pointer;
  text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur-fast);
}
.menu-items button:hover, .menu-items a:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.menu-sep { height: 1px; border: 0; margin: 2px 0; background: var(--divider); }

@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu[open] .menu-items { animation: menu-in var(--dur-med) var(--ease-out); transform-origin: top right; }

.theme-toggle { width: 30px; height: 30px; font-size: 1rem; color: color-mix(in srgb, var(--text) 70%, transparent); transition: color var(--dur-fast); }
.theme-toggle:hover { color: var(--accent); }
@keyframes theme-flip { from { transform: rotate(-90deg) scale(.7); opacity: 0; } }
#theme-icon.theme-flip { display: inline-block; animation: theme-flip var(--dur-med) var(--ease-out); }

/* ── mode toggle ──────────────────────────────────────────────────── */
.mode-toggle { width: 30px; height: 30px; font-size: 1rem; color: color-mix(in srgb, var(--text) 70%, transparent); transition: color var(--dur-fast); }
.mode-toggle:hover { color: var(--accent); }
:root[data-mode="touch"] .mode-toggle,
:root[data-mode="mouse"] .mode-toggle { color: var(--accent); }

/* header user menu */
.topbar-menu summary { display: flex; align-items: center; gap: 3px; padding: 0; }
.menu-caret { font-size: .6rem; color: color-mix(in srgb, var(--text) 65%, transparent); transition: transform var(--dur-fast); }
.topbar-menu[open] .menu-caret { transform: rotate(180deg); }
.topbar-menu .menu-items { min-width: 200px; }

/* ── tasks & dues ─────────────────────────────────────────────────── */
.task-row {
  display: flex; align-items: center; gap: var(--space-2); cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--divider); border-radius: var(--radius-md);
}
.task-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
.task-row .task-title { flex: 1; transition: opacity var(--dur-med); }
.task-row.is-done .task-title, .task-row:has(input:checked) .task-title {
  text-decoration: line-through; opacity: .55;
}
.is-queued { border-style: dashed; }
.is-queued::after { content: '⏳'; font-size: 12px; }

/* ── chat ─────────────────────────────────────────────────────────── */
.chat-panel { display: flex; flex-direction: column; gap: var(--space-2); }
.chat-log {
  display: flex; flex-direction: column; gap: var(--space-2);
  min-height: 180px;
  max-height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 140px);
  overflow-y: auto;
  padding: var(--space-2); border: 1px solid var(--divider); border-radius: var(--radius-md);
}
.chat-msg {
  display: flex; gap: 8px; align-items: flex-end;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}
.chat-msg.htmx-added { opacity: 0; transform: translateY(6px); }
.chat-msg.is-mine { flex-direction: row-reverse; }
.chat-bubble {
  max-width: 78%; padding: 7px 11px; border-radius: var(--radius-lg);
  background: var(--n-100); font-size: .93rem;
}
.is-mine .chat-bubble { background: var(--a-100); color: var(--a-800); }
.chat-sender { font-size: .73rem; font-weight: 600; color: var(--accent-text); }
.chat-time { font-size: .67rem; opacity: .7; text-align: right; }
.chat-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.chat-form {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: var(--bg); padding-top: var(--space-1); border-top: 1px solid var(--divider);
}

/* ── profile / login ──────────────────────────────────────────────── */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); padding-top: var(--space-3); }
.chips-row { justify-content: center; }
.family-link { text-decoration: none; }
.auth-body { display: flex; min-height: 100dvh; }
.auth-body #page { margin: auto; padding: var(--space-4); }
.login-page { display: flex; flex-direction: column; gap: var(--space-4); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); }
.login-logo {
  width: 96px; height: 96px; border-radius: 14px; overflow: hidden;
}
.login-logo img { width: 100%; height: 100%; object-fit: cover; }
.login-title { margin: 0; }
.login-form { min-width: min(320px, 84vw); }
.login-divider { gap: 8px; }
.login-divider .line { flex: 1; height: 1px; background: var(--divider); }
.login-footer { text-align: center; }
.webauthn-login { border-color: var(--accent); color: var(--accent-text); }

/* ── dialog ───────────────────────────────────────────────────────── */
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes dialog-fade-in { from { opacity: 0; } }
.dialog {
  width: min(440px, calc(100% - 2 * var(--space-4)));
  padding: var(--space-4); border-radius: var(--radius-lg); border: 1px solid var(--divider);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog[open] { animation: dialog-in var(--dur-slow) var(--ease-out); }
.dialog::backdrop { background: color-mix(in srgb, #000 50%, transparent); }
.dialog[open]::backdrop { animation: dialog-fade-in var(--dur-slow) ease-out; }
.dialog-inner { display: flex; flex-direction: column; gap: var(--space-2); }
.dialog-title { margin: 0; }
.dialog-body { font-size: .93rem; opacity: .85; }
.dialog-actions { display: flex; flex-direction: column; gap: var(--space-2); }
.temp-password { font-size: 1.33rem; text-align: center; }
.temp-password code { background: var(--n-100); padding: 4px 12px; border-radius: var(--radius-sm); }

/* ── tables & event log ───────────────────────────────────────────── */
.table-scroll { overflow-x: auto; border: 1px solid var(--divider); border-radius: var(--radius-md); }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th {
  text-align: left; font-size: .73rem; letter-spacing: .08em; text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 65%, transparent);
  padding: var(--space-2); border-bottom: 1px solid var(--divider);
  font-family: var(--font-body); white-space: nowrap;
}
.table td { padding: var(--space-2); border-bottom: 1px solid var(--divider); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.nowrap { white-space: nowrap; }

.tag-ok  { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.tag-err { background: light-dark(#f6e4e0, #3c2320); color: light-dark(#a04430, #e8a898); }

.events-table .th-details { width: 99%; }
.json-cell {
  max-width: 0; width: 99%;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem;
}
.json-cell .json-short {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.json-cell .json-full { display: none; margin: 0; font: inherit; white-space: pre-wrap; word-break: break-word; }
.json-cell.is-expandable { cursor: pointer; }
.json-cell.is-expandable:hover .json-short { color: var(--accent); }
.json-cell.is-expanded .json-short { display: none; }
.json-cell.is-expanded .json-full { display: block; }

.pagination { padding: var(--space-1) 0; }
.pagination-info { text-align: center; font-size: .87rem; color: color-mix(in srgb, var(--text) 65%, transparent); }
.page-wide { width: 100%; }

/* ── misc ─────────────────────────────────────────────────────────── */
.audit-row { gap: 4px; padding: var(--space-2) var(--space-3); }
.audit-filters { flex-wrap: wrap; }
.audit-filters .input { width: auto; flex: 1; min-width: 120px; }
.calendar-title { margin: 0; text-align: center; font-size: 1.2rem; }
.calendar-grid { border: 1px solid var(--divider); border-radius: var(--radius-md); overflow: hidden; }
.calendar-header { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--n-100); }
.calendar-header span { text-align: center; font-size: .73rem; font-weight: 600; padding: var(--space-1) 0; opacity: .7; }
.calendar-week { display: grid; grid-template-columns: repeat(7, 1fr); border-top: 1px solid var(--divider); }
.calendar-cell { min-height: 48px; padding: 2px var(--space-1); border-left: 1px solid var(--divider); font-size: .8rem; }
.calendar-cell:nth-child(1) { border-left: 0; }
.calendar-empty { opacity: .3; }
.calendar-day { font-weight: 600; opacity: .7; }
.calendar-today .calendar-day { color: var(--accent-text); opacity: 1; }
.calendar-cell.has-events { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.calendar-event { display: block; font-size: .67rem; color: var(--accent-text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calendar-event:hover { text-decoration: underline; }
.urodziny-row { gap: var(--space-2); }
.urodziny-name { font-weight: 600; }
.text-sm { font-size: .8rem; }
.rodziny-row { gap: var(--space-2); }
.rodziny-name { font-weight: 600; }
.dues-row { gap: var(--space-2); }
.invite-link { word-break: break-all; }
.post-form textarea { font-size: .93rem; }

/* ── responsive: tablet & desktop (Bulma breakpoints) ─────────────── */
.pulpit-grid { display: flex; flex-direction: column; gap: var(--space-2); }

@media (min-width: 769px) {
  /* Nav moves from a bottom tab bar to a horizontal bar under the topbar. */
  .tabbar {
    position: sticky; top: var(--topbar-h); inset-inline: auto; bottom: auto; z-index: 19;
    justify-content: center; gap: var(--space-2);
    border-top: 0; border-bottom: 1px solid var(--divider);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(6px);
    padding-bottom: 0; width: 100%;
  }
  .tabbar a {
    flex: 0 0 auto; flex-direction: row; gap: 8px;
    padding: 10px 18px; font-size: .93rem;
  }
  .tabbar a::after {
    content: ''; position: absolute; left: 16px; right: 16px; bottom: 0; height: 2px;
    background: var(--accent); transform: scaleX(0); transition: transform var(--dur-med) var(--ease-out);
  }
  .tabbar a[aria-current="page"]::after { transform: scaleX(1); }
  .tab-icon { font-size: 1rem; }
  .tab-badge { position: static; margin-left: 2px; }

  #page { padding-bottom: var(--space-8); }
  .page-pad { padding: var(--space-4) var(--space-3); }
  .chat-form { position: static; }
  .chat-log { max-height: 62vh; min-height: 260px; }
  .auth-body #page { max-width: 420px; }
  .login-form { min-width: 340px; }
}

@media (min-width: 1024px) {
  /* Pulpit: next-up sidebar + wide announcements column. */
  .pulpit-grid {
    display: grid; grid-template-columns: 340px minmax(0, 1fr);
    gap: var(--space-6); align-items: start;
  }
  .pulpit-side { position: sticky; top: calc(var(--topbar-h) + 56px); }
  .pulpit-main #feed { max-width: none; }

  /* Two-column card lists. */
  #group-list, #admin-user-list, #audit-list {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2); align-content: start;
  }
  #group-list > p, #admin-user-list > p, #audit-list > p { grid-column: 1 / -1; }
  #audit-list .feed-more { grid-column: 1 / -1; }

  .group-tabs { max-width: 760px; }
  .chat-panel { max-width: 900px; }
  .dialog { width: min(520px, calc(100% - 2 * var(--space-4))); }
}

/* Online presence indicators */
.user-status-dot {
  position: absolute; bottom: 0; right: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); border: 2px solid var(--bg);
}
.user-status-dot[data-status="online"] { background: var(--ok); }
.user-status-dot-inline {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); vertical-align: middle;
  margin: 0 2px;
}
.user-status-dot-inline[data-status="online"] { background: var(--ok); }
.online-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg); }
.online-dot-inline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); vertical-align: middle; margin: 0 2px; }
.osoby-summary { padding: var(--space-1) 0; }

/* Song chords */
.song { line-height: 1.8; }
/* #song-preview w edytorze łączy .card (display:flex) z .song na tym samym
   elemencie — flex blockifies wszystkie dzieci (spec CSS Display), co
   zamieniało inline <span data-chord> w bloki i psuło nakładkę akordu nad
   sylabą. Wymuszamy z powrotem block; .card.row ma analogiczny wzorzec. */
.card.song { display: block; }
.song span[data-chord]:before {
  position: relative;
  top: -1em;
  display: inline-block;
  content: attr(data-chord);
  width: 0;
  font-style: italic;
  font-weight: bold;
  color: var(--accent);
}
.song span[data-chordbase]:before {
  content: attr(data-chordbase);
  font-style: italic;
  font-weight: bold;
}
.song .badge {
  background-color: var(--accent-text);
  color: var(--bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.8em;
}

/* ── touch mode: larger tap targets, increased spacing ─────────────── */
:root[data-resolved-mode="touch"] .btn { min-height: 44px; min-width: 44px; padding: var(--space-2) var(--space-3); }
:root[data-resolved-mode="touch"] .seg-opt { padding: 10px 14px; min-height: 44px; }
:root[data-resolved-mode="touch"] .tabbar a { padding: 12px 0 10px; min-height: 52px; }
:root[data-resolved-mode="touch"] .menu-items a,
:root[data-resolved-mode="touch"] .menu-items button { padding: 12px 14px; min-height: 44px; }
:root[data-resolved-mode="touch"] .task-row { padding: var(--space-3); }
:root[data-resolved-mode="touch"] .member-row,
:root[data-resolved-mode="touch"] .group-row { padding: var(--space-3); }
:root[data-resolved-mode="touch"] .chat-form { padding: var(--space-2) var(--space-3); }
:root[data-resolved-mode="touch"] .switch { width: 48px; height: 26px; }
:root[data-resolved-mode="touch"] .switch .knob { width: 20px; height: 20px; }
:root[data-resolved-mode="touch"] .switch[aria-checked="true"] .knob { transform: translateX(22px); }
:root[data-resolved-mode="touch"] .radio .dot { width: 20px; height: 20px; }
:root[data-resolved-mode="touch"] .input { min-height: 44px; padding: 10px 12px; }
:root[data-resolved-mode="touch"] button.tag,
:root[data-resolved-mode="touch"] a.tag { min-height: 38px; padding: 8px 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
