@layer reset, tokens, base, layout, components, utilities, themes;

/* ==========================================================================
   Modern CSS Reset
   Cooperatives App — Theme System
   ========================================================================== */

@layer reset {

  /*
   * 1. Use border-box everywhere
   * 2. Remove default margin/padding
   * 3. Prevent font-size inflation on mobile
   */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    overflow-x: clip;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    hanging-punctuation: first last;
  }

  /*
   * Body defaults:
   * - min-height ensures full viewport coverage
   * - line-height for readability
   * - font-smoothing for macOS
   */
  body {
    min-height: 100dvh;
    line-height: 1.6;
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Remove list styles on ul/ol with class (keep defaults for semantic lists) */
  ul[class],
  ol[class] {
    list-style: none;
  }

  /* Headings: balance wrapping, tighter line-height */
  h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    text-wrap: balance;
    overflow-wrap: break-word;
  }

  /* Body text: prettier wrapping */
  p, li, figcaption {
    text-wrap: pretty;
    overflow-wrap: break-word;
  }

  /* Links inherit color by default */
  a {
    color: inherit;
    text-decoration-skip-ink: auto;
  }

  /* Media defaults */
  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
  }

  /* Form elements inherit font */
  input, button, textarea, select {
    font: inherit;
    color: inherit;
  }

  /* Textarea: only vertical resize */
  textarea {
    resize: vertical;
  }

  /* Button reset */
  button {
    cursor: pointer;
    border: none;
    background: none;
  }

  /* Fieldset reset */
  fieldset {
    border: none;
    padding: 0;
    margin: 0;
  }

  legend {
    padding: 0;
  }

  /* Table reset */
  table {
    border-collapse: collapse;
    border-spacing: 0;
  }

  /* Target anchors: scroll margin for sticky header */
  :target {
    scroll-margin-block-start: 5rem;
  }

  /* Reduced motion: respect user preferences */
  @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;
    }
  }

}

/* ==========================================================================
   Design Tokens
   Cooperatives App — Theme System
   
   Wartości referencyjne (seed). Tematy mogą nadpisywać aliasy.
   Używamy oklch() dla perceptualnie spójnych kolorów.
   ========================================================================== */

@layer tokens {

  /* -------------------------------------------------------------------------
     Registered Custom Properties (@property)
     — umożliwia animowanie kolorów i wartości liczbowych
     ------------------------------------------------------------------------- */

  @property --color-primary {
    syntax: '<color>';
    inherits: true;
    initial-value: oklch(0.45 0.14 158);
  }

  @property --color-accent {
    syntax: '<color>';
    inherits: true;
    initial-value: oklch(0.72 0.14 75);
  }

  /* -------------------------------------------------------------------------
     Root Tokens — neutralne wartości nie zależne od tematu
     ------------------------------------------------------------------------- */

  :root {
    /* ---- Color Seeds ---- */
    --seed-primary:    oklch(0.45 0.14 158);  /* Kooperatywny zielony */
    --seed-primary-l:  oklch(0.58 0.12 158);  /* Jaśniejszy */
    --seed-primary-d:  oklch(0.32 0.12 158);  /* Ciemniejszy */

    --seed-accent:     oklch(0.72 0.14 75);   /* Ciepły amber */
    --seed-accent-l:   oklch(0.82 0.10 75);
    --seed-accent-d:   oklch(0.58 0.14 75);

    --seed-error:      oklch(0.58 0.22 25);   /* Czerwony */
    --seed-warning:    oklch(0.75 0.15 60);   /* Pomarańczowy */
    --seed-success:    oklch(0.62 0.17 145);  /* Zielony sukcesu */
    --seed-info:       oklch(0.60 0.12 240);  /* Niebieski info */

    /* ---- Spacing Scałe ---- */
    --space-3xs: 0.125rem;  /* 2px */
    --space-2xs: 0.25rem;   /* 4px */
    --space-xs:  0.5rem;    /* 8px */
    --space-sm:  0.75rem;   /* 12px */
    --space-md:  1rem;      /* 16px */
    --space-lg:  1.5rem;    /* 24px */
    --space-xl:  2rem;      /* 32px */
    --space-2xl: 3rem;      /* 48px */
    --space-3xl: 4rem;      /* 64px */
    --space-4xl: 6rem;      /* 96px */

    /* ---- Typography ---- */
    --font-sans:    'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
    --font-display: 'Outfit', var(--font-sans);
    --font-mono:    'Cascadia Code', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;

    /* ---- Icon masks (kolor sterowany przez background-color) ---- */
    --icon-search: url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27black%27 stroke-width=%272%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3E%3Ccircle cx=%2711%27 cy=%2711%27 r=%277%27/%3E%3Cpath d=%27m20 20-3.5-3.5%27/%3E%3C/svg%3E");

    --text-xs:   clamp(0.7rem,  0.65rem + 0.25vw, 0.78rem);
    --text-sm:   clamp(0.8rem,  0.75rem + 0.25vw, 0.88rem);
    --text-base: clamp(0.88rem, 0.84rem + 0.2vw,  1rem);
    --text-md:   clamp(0.95rem, 0.9rem  + 0.25vw, 1.08rem);
    --text-lg:   clamp(1.05rem, 0.95rem + 0.5vw,  1.2rem);
    --text-xl:   clamp(1.25rem, 1.1rem  + 0.75vw, 1.5rem);
    --text-2xl:  clamp(1.6rem,  1.3rem  + 1.5vw,  2.25rem);
    --text-3xl:  clamp(2rem,    1.5rem  + 2.5vw,   3rem);
    --text-4xl:  clamp(2.5rem,  1.8rem  + 3vw,    3.8rem);
    --text-5xl:  clamp(3rem,    2rem    + 4vw,    5rem);
    --text-hero: clamp(2.5rem,  1.8rem  + 3.5vw,   4.5rem);

    --leading-tight:  1.2;
    --leading-normal: 1.6;
    --leading-relaxed: 1.7;
    --leading-loose:  1.8;
    --line-relaxed: var(--leading-relaxed);

    --weight-regular:  400;
    --weight-normal:   400;
    --weight-medium:   500;
    --weight-semibold: 600;
    --weight-bold:     700;

    --tracking-tight:  -0.02em;
    --tracking-normal:  0;
    --tracking-wide:    0.04em;
    --tracking-wider:   0.08em;

    /* ---- Border Radius ---- */
    --radius-xs:   0.25rem;
    --radius-sm:   0.375rem;
    --radius-md:   0.5rem;
    --radius-lg:   0.75rem;
    --radius-xl:   1rem;
    --radius-2xl:  1.5rem;
    --radius-full: 9999px;
    --radius-pill: var(--radius-full);

    /* ---- Shadows ---- */
    --shadow-xs:  0 1px 2px oklch(0 0 0 / 0.06);
    --shadow-sm:  0 1px 3px oklch(0 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.04);
    --shadow-md:  0 4px 6px oklch(0 0 0 / 0.07), 0 2px 4px oklch(0 0 0 / 0.04);
    --shadow-lg:  0 10px 15px oklch(0 0 0 / 0.08), 0 4px 6px oklch(0 0 0 / 0.04);
    --shadow-xl:  0 20px 25px oklch(0 0 0 / 0.10), 0 8px 10px oklch(0 0 0 / 0.04);
    --shadow-glow: 0 0 20px oklch(0.45 0.14 158 / 0.15);

    /* ---- Transitions ---- */
    --ease-default:  cubic-bezier(0.4, 0, 0.2, 1);
    --ease-in:       cubic-bezier(0.4, 0, 1, 1);
    --ease-out:      cubic-bezier(0, 0, 0.2, 1);
    --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);

    --duration-fast:    100ms;
    --duration-normal:  200ms;
    --duration-slow:    350ms;
    --duration-slower:  500ms;

    /* ---- Z-index Scałe ---- */
    --z-base:     1;
    --z-dropdown: 100;
    --z-sticky:   200;
    --z-overlay:  300;
    --z-modal:    400;
    --z-toast:    500;
    --z-tooltip:  600;

    /* ---- Layout ---- */
    --header-height: 3.75rem;  /* 60px */
    --control-height-md: 2.75rem;
    --content-max:   56rem;    /* 896px — main content */
    --aside-width:   20rem;    /* 320px */
    --rail-width:    15rem;    /* 240px */
    --page-gutter:   var(--space-md);
  }

}

/* ==========================================================================
   Light Theme
   Cooperatives App — Theme System
   
   Domyślny temat jasny. Definiuje aliasy kolorystyczne.
   ========================================================================== */

@layer themes {

  body[data-theme="light"],
  body:not([data-theme]) {

    color-scheme: light;

    /* ---- Backgrounds ---- */
    --color-bg:             oklch(0.975 0.005 240);
    --color-bg-subtle:      oklch(0.955 0.008 240);
    --color-surface:        oklch(1 0 0);
    --color-surface-raised: oklch(0.985 0.003 240);
    --color-surface-sunken: oklch(0.94 0.008 240);
    --color-surface-subtle: var(--color-surface-raised);
    --color-surface-muted:  var(--color-surface-sunken);
    --color-overlay:        oklch(0 0 0 / 0.45);

    /* ---- Text ---- */
    --color-text:           oklch(0.18 0.01 240);
    --color-text-primary:   var(--color-text);
    --color-text-secondary: oklch(0.42 0.015 240);
    --color-text-muted:     oklch(0.58 0.01 240);
    --color-text-on-primary: oklch(0.98 0.005 160);
    --color-text-on-accent:  oklch(0.18 0.01 75);

    /* ---- Primary ---- */
    --color-primary:        var(--seed-primary);
    --color-primary-hover:  var(--seed-primary-d);
    --color-primary-strong: var(--color-primary-hover);
    --color-primary-border: oklch(0.72 0.05 158);
    --color-primary-subtle: oklch(0.92 0.04 158);
    --color-primary-text:   var(--seed-primary-d);

    /* ---- Accent ---- */
    --color-accent:         var(--seed-accent);
    --color-accent-hover:   var(--seed-accent-d);
    --color-accent-subtle:  oklch(0.94 0.05 75);

    /* ---- Borders ---- */
    --color-border:         oklch(0.82 0.008 240);
    --color-border-strong:  oklch(0.68 0.01 240);
    --color-border-subtle:  oklch(0.90 0.005 240);

    /* ---- States ---- */
    --color-error:          var(--seed-error);
    --color-error-subtle:   oklch(0.94 0.06 25);
    --color-danger:         var(--color-error);
    --color-danger-subtle:  var(--color-error-subtle);
    --color-warning:        var(--seed-warning);
    --color-warning-subtle: oklch(0.94 0.05 60);
    --color-success:        var(--seed-success);
    --color-success-subtle: oklch(0.94 0.06 145);
    --color-info:           var(--seed-info);
    --color-info-subtle:    oklch(0.94 0.04 240);

    /* ---- Interactive ---- */
    --color-focus-ring:     oklch(0.55 0.18 240 / 0.4);
    --color-hover-overlay:  oklch(0 0 0 / 0.04);
    --color-active-overlay: oklch(0 0 0 / 0.08);
    --color-disabled:       oklch(0.72 0.005 240);
    --color-disabled-bg:    oklch(0.94 0.005 240);

    /* ---- Header ---- */
    --header-bg:            oklch(0.20 0.02 240);
    --header-text:          oklch(0.92 0.005 240);
    --header-text-muted:    oklch(0.68 0.01 240);
    --header-border:        oklch(0.30 0.02 240);

    /* ---- Input ---- */
    --input-bg:             var(--color-surface);
    --input-border:         var(--color-border);
    --input-border-focus:   var(--color-primary);
    --input-placeholder:    var(--color-text-muted);
    --select-chevron:       url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23667085%27 stroke-width=%272%27 viewBox=%270 0 24 24%27%3E%3Cpath d=%27m6 9 6 6 6-6%27/%3E%3C/svg%3E");

    /* ---- Button ---- */
    --btn-primary-bg:       var(--color-primary);
    --btn-primary-text:     var(--color-text-on-primary);
    --btn-primary-hover:    var(--color-primary-hover);
    --btn-secondary-bg:     var(--color-surface);
    --btn-secondary-text:   var(--color-text);
    --btn-secondary-border: var(--color-border-strong);
    --btn-secondary-hover:  var(--color-surface-sunken);

    /* ---- Card ---- */
    --card-bg:              var(--color-surface);
    --card-border:          var(--color-border-subtle);
    --card-shadow:          var(--shadow-sm);

    /* ---- Shadows (theme-aware) ---- */
    --shadow-theme-sm:  0 1px 3px oklch(0 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.04);
    --shadow-theme-md:  0 4px 8px oklch(0 0 0 / 0.07), 0 2px 4px oklch(0 0 0 / 0.04);
    --shadow-theme-lg:  0 12px 24px oklch(0 0 0 / 0.08), 0 4px 8px oklch(0 0 0 / 0.04);
  }

}

/* ==========================================================================
   Dark Theme
   Cooperatives App — Theme System
   
   Ciemny temat. Te same aliasy, inne wartości.
   ========================================================================== */

@layer themes {

  body[data-theme="dark"] {

    color-scheme: dark;

    /* ---- Backgrounds ---- */
    --color-bg:             oklch(0.14 0.01 240);
    --color-bg-subtle:      oklch(0.17 0.012 240);
    --color-surface:        oklch(0.20 0.015 240);
    --color-surface-raised: oklch(0.24 0.015 240);
    --color-surface-sunken: oklch(0.12 0.008 240);
    --color-surface-subtle: var(--color-surface-raised);
    --color-surface-muted:  oklch(0.18 0.012 240);
    --color-overlay:        oklch(0 0 0 / 0.65);

    /* ---- Text ---- */
    --color-text:           oklch(0.92 0.005 240);
    --color-text-primary:   var(--color-text);
    --color-text-secondary: oklch(0.72 0.01 240);
    --color-text-muted:     oklch(0.55 0.01 240);
    --color-text-on-primary: oklch(0.98 0.005 160);
    --color-text-on-accent:  oklch(0.15 0.01 75);

    /* ---- Primary ---- */
    --color-primary:        var(--seed-primary-l);
    --color-primary-hover:  oklch(0.65 0.13 158);
    --color-primary-strong: var(--color-primary-hover);
    --color-primary-border: oklch(0.38 0.06 158);
    --color-primary-subtle: oklch(0.25 0.05 158);
    --color-primary-text:   var(--seed-primary-l);

    /* ---- Accent ---- */
    --color-accent:         var(--seed-accent);
    --color-accent-hover:   var(--seed-accent-l);
    --color-accent-subtle:  oklch(0.28 0.05 75);

    /* ---- Borders ---- */
    --color-border:         oklch(0.32 0.012 240);
    --color-border-strong:  oklch(0.45 0.012 240);
    --color-border-subtle:  oklch(0.26 0.01 240);

    /* ---- States ---- */
    --color-error:          oklch(0.68 0.20 25);
    --color-error-subtle:   oklch(0.22 0.08 25);
    --color-danger:         var(--color-error);
    --color-danger-subtle:  var(--color-error-subtle);
    --color-warning:        oklch(0.78 0.14 60);
    --color-warning-subtle: oklch(0.25 0.06 60);
    --color-success:        oklch(0.68 0.15 145);
    --color-success-subtle: oklch(0.22 0.06 145);
    --color-info:           oklch(0.68 0.12 240);
    --color-info-subtle:    oklch(0.22 0.05 240);

    /* ---- Interactive ---- */
    --color-focus-ring:     oklch(0.60 0.16 240 / 0.5);
    --color-hover-overlay:  oklch(1 0 0 / 0.05);
    --color-active-overlay: oklch(1 0 0 / 0.10);
    --color-disabled:       oklch(0.40 0.005 240);
    --color-disabled-bg:    oklch(0.22 0.005 240);

    /* ---- Header ---- */
    --header-bg:            oklch(0.12 0.01 240);
    --header-text:          oklch(0.92 0.005 240);
    --header-text-muted:    oklch(0.58 0.01 240);
    --header-border:        oklch(0.25 0.015 240);

    /* ---- Input ---- */
    --input-bg:             oklch(0.18 0.012 240);
    --input-border:         var(--color-border);
    --input-border-focus:   var(--color-primary);
    --input-placeholder:    var(--color-text-muted);
    --select-chevron:       url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%239aa4b2%27 stroke-width=%272%27 viewBox=%270 0 24 24%27%3E%3Cpath d=%27m6 9 6 6 6-6%27/%3E%3C/svg%3E");

    /* ---- Button ---- */
    --btn-primary-bg:       var(--color-primary);
    --btn-primary-text:     oklch(0.12 0.01 158);
    --btn-primary-hover:    var(--color-primary-hover);
    --btn-secondary-bg:     var(--color-surface-raised);
    --btn-secondary-text:   var(--color-text);
    --btn-secondary-border: var(--color-border-strong);
    --btn-secondary-hover:  oklch(0.30 0.015 240);

    /* ---- Card ---- */
    --card-bg:              var(--color-surface);
    --card-border:          var(--color-border-subtle);
    --card-shadow:          0 1px 3px oklch(0 0 0 / 0.25);

    /* ---- Shadows (theme-aware) ---- */
    --shadow-theme-sm:  0 1px 3px oklch(0 0 0 / 0.3), 0 1px 2px oklch(0 0 0 / 0.15);
    --shadow-theme-md:  0 4px 8px oklch(0 0 0 / 0.35), 0 2px 4px oklch(0 0 0 / 0.15);
    --shadow-theme-lg:  0 12px 24px oklch(0 0 0 / 0.4), 0 4px 8px oklch(0 0 0 / 0.2);
  }

}

/* inter-latin-400-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/fonts/inter-latin-400-normal.woff2) format('woff2'), url(/fonts/inter-latin-400-normal.woff) format('woff');
}
/* inter-latin-500-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/inter-latin-500-normal.woff2) format('woff2'), url(/fonts/inter-latin-500-normal.woff) format('woff');
}
/* inter-latin-600-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/inter-latin-600-normal.woff2) format('woff2'), url(/fonts/inter-latin-600-normal.woff) format('woff');
}
/* inter-latin-700-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/inter-latin-700-normal.woff2) format('woff2'), url(/fonts/inter-latin-700-normal.woff) format('woff');
}
/* inter-latin-ext-400-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/fonts/inter-latin-ext-400-normal.woff2) format('woff2'), url(/fonts/inter-latin-ext-400-normal.woff) format('woff');
}
/* inter-latin-ext-500-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/inter-latin-ext-500-normal.woff2) format('woff2'), url(/fonts/inter-latin-ext-500-normal.woff) format('woff');
}
/* inter-latin-ext-600-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/inter-latin-ext-600-normal.woff2) format('woff2'), url(/fonts/inter-latin-ext-600-normal.woff) format('woff');
}
/* inter-latin-ext-700-normal */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/inter-latin-ext-700-normal.woff2) format('woff2'), url(/fonts/inter-latin-ext-700-normal.woff) format('woff');
}
/* outfit-latin-400-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/fonts/outfit-latin-400-normal.woff2) format('woff2'), url(/fonts/outfit-latin-400-normal.woff) format('woff');
}
/* outfit-latin-500-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/outfit-latin-500-normal.woff2) format('woff2'), url(/fonts/outfit-latin-500-normal.woff) format('woff');
}
/* outfit-latin-600-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/outfit-latin-600-normal.woff2) format('woff2'), url(/fonts/outfit-latin-600-normal.woff) format('woff');
}
/* outfit-latin-700-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/outfit-latin-700-normal.woff2) format('woff2'), url(/fonts/outfit-latin-700-normal.woff) format('woff');
}
/* outfit-latin-ext-400-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url(/fonts/outfit-latin-ext-400-normal.woff2) format('woff2'), url(/fonts/outfit-latin-ext-400-normal.woff) format('woff');
}
/* outfit-latin-ext-500-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 500;
  src: url(/fonts/outfit-latin-ext-500-normal.woff2) format('woff2'), url(/fonts/outfit-latin-ext-500-normal.woff) format('woff');
}
/* outfit-latin-ext-600-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 600;
  src: url(/fonts/outfit-latin-ext-600-normal.woff2) format('woff2'), url(/fonts/outfit-latin-ext-600-normal.woff) format('woff');
}
/* outfit-latin-ext-700-normal */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url(/fonts/outfit-latin-ext-700-normal.woff2) format('woff2'), url(/fonts/outfit-latin-ext-700-normal.woff) format('woff');
}
/* ==========================================================================
   Base Styles
   Cooperatives App — Theme System
   
   Style bazowe elementów HTML. Używają aliasów z tematów.
   ========================================================================== */

/* Outfit — font wyświetlań (nagłówki, hero). Ma latin-ext dla polskich znaków. */

@layer base {

  /* ---- Body ---- */
  body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-normal);
    letter-spacing: var(--tracking-normal);
    transition:
      background-color var(--duration-slow) var(--ease-default),
      color var(--duration-slow) var(--ease-default);
  }

  /* ---- Headings ---- */
  h1, h2, h3, h4, h5, h6 {
    color: var(--color-text);
    font-family: var(--font-display);
    font-weight: var(--weight-semibold);
  }

  h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tight); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  h4 { font-size: var(--text-lg); }
  h5 { font-size: var(--text-base); font-weight: var(--weight-bold); }
  h6 { font-size: var(--text-sm); font-weight: var(--weight-bold); text-transform: uppercase; letter-spacing: var(--tracking-wider); }

  /* ---- Links ---- */
  a {
    color: var(--color-primary-text);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-default);
  }

  a:hover {
    color: var(--color-accent);
  }

  a:focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
  }

  /* ---- Paragraphs ---- */
  p {
    color: var(--color-text-secondary);
    line-height: var(--leading-normal);
  }

  /* ---- Strong / Em ---- */
  strong, b {
    font-weight: var(--weight-semibold);
    color: var(--color-text);
  }

  small {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
  }

  /* ---- Lists ---- */
  ul, ol {
    padding-inline-start: var(--space-lg);
  }

  li {
    margin-block-end: var(--space-2xs);
  }

  /* ---- Horizontal Rule ---- */
  hr {
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    margin-block: var(--space-lg);
  }

  /* ---- Buttons ---- */
  button,
  .btn {
    align-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    gap: var(--space-xs);
    justify-content: center;
    line-height: 1.2;
    min-height: 2.75rem;
    padding: var(--space-xs) var(--space-lg);
    text-align: center;
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default),
      color var(--duration-fast) var(--ease-default),
      box-shadow var(--duration-fast) var(--ease-default),
      transform var(--duration-fast) var(--ease-default);
    user-select: none;
    white-space: nowrap;

    /* Default: secondary style */
    background-color: var(--btn-secondary-bg);
    border-color: var(--btn-secondary-border);
    color: var(--btn-secondary-text);
  }

  button:hover,
  .btn:hover {
    background-color: var(--btn-secondary-hover);
    box-shadow: var(--shadow-xs);
  }

  button:active,
  .btn:active {
    transform: scale(0.98);
  }

  button:focus-visible,
  .btn:focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 2px;
  }

  button:disabled,
  .btn:disabled {
    background-color: var(--color-disabled-bg);
    border-color: transparent;
    color: var(--color-disabled);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  /* Primary button variant */
  .btn-primary,
  button.btn-primary {
    background-color: var(--btn-primary-bg);
    border-color: var(--btn-primary-bg);
    color: var(--btn-primary-text);
  }

  .btn-primary:hover,
  button.btn-primary:hover {
    background-color: var(--btn-primary-hover);
    border-color: var(--btn-primary-hover);
    box-shadow: var(--shadow-md), var(--shadow-glow);
  }

  /* Ghost button variant */
  .btn-ghost,
  button.btn-ghost {
    background-color: transparent;
    border-color: transparent;
    color: var(--color-text-secondary);
  }

  .btn-ghost:hover,
  button.btn-ghost:hover {
    background-color: var(--color-hover-overlay);
    box-shadow: none;
  }

  /* Danger button */
  .btn-danger,
  button.btn-danger {
    background-color: var(--color-error);
    border-color: var(--color-error);
    color: oklch(0.98 0 0);
  }

  .btn-danger:hover,
  button.btn-danger:hover {
    background-color: oklch(0.48 0.22 25);
    border-color: oklch(0.48 0.22 25);
  }

  /* Icon-only button */
  .btn-icon {
    min-height: 2.25rem;
    min-width: 2.25rem;
    padding: var(--space-xs);
  }

  /* Small button */
  .btn-sm {
    font-size: var(--text-xs);
    min-height: 2rem;
    padding: var(--space-2xs) var(--space-sm);
  }

  /* Full-width button */
  .btn-block {
    width: 100%;
  }

  /* ---- Form Inputs ---- */
  input,
  textarea,
  select {
    appearance: none;
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    min-height: 2.75rem;
    padding: var(--space-xs) var(--space-sm);
    transition:
      border-color var(--duration-fast) var(--ease-default),
      box-shadow var(--duration-fast) var(--ease-default),
      background-color var(--duration-fast) var(--ease-default);
    width: 100%;
  }

  input:focus,
  textarea:focus,
  select:focus {
    border-color: var(--input-border-focus);
    box-shadow: 0 0 0 3px var(--color-focus-ring);
    outline: none;
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--input-placeholder);
  }

  input:disabled,
  textarea:disabled,
  select:disabled {
    background-color: var(--color-disabled-bg);
    color: var(--color-disabled);
    cursor: not-allowed;
  }

  /* Input with error — uses :has() on parent */
  .field:has(input:invalid:not(:placeholder-shown)) .field-error,
  .field.has-error .field-error {
    display: block;
  }

  .field.has-error input,
  .field.has-error textarea,
  .field.has-error select {
    border-color: var(--color-error);
  }

  textarea {
    min-height: 6rem;
    resize: vertical;
  }

  select {
    background-image: var(--select-chevron);
    background-position: right var(--space-sm) center;
    background-repeat: no-repeat;
    background-size: 1rem;
    padding-right: var(--space-xl);
  }

  label {
    color: var(--color-text-secondary);
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    margin-block-end: var(--space-2xs);
  }

  /* ---- Fieldset ---- */
  fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
  }

  legend {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-wide);
    padding-inline: var(--space-xs);
    text-transform: uppercase;
  }

  /* ---- Code ---- */
  code, pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
  }

  code {
    background-color: var(--color-surface-sunken);
    border-radius: var(--radius-xs);
    padding: var(--space-3xs) var(--space-2xs);
  }

  pre {
    background-color: var(--color-surface-sunken);
    border-radius: var(--radius-md);
    overflow-x: auto;
    padding: var(--space-md);
  }

  /* ---- Selection ---- */
  ::selection {
    background-color: color-mix(in oklch, var(--color-primary) 25%, transparent);
    color: var(--color-text);
  }

  /* ---- Scrollbar (Chromium) ---- */
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-track {
    background: var(--color-bg-subtle);
  }

  ::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: var(--radius-full);
  }

  ::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
  }

  /* Firefox scrollbar */
  * {
    scrollbar-color: var(--color-border-strong) var(--color-bg-subtle);
    scrollbar-width: thin;
  }

}

/* ==========================================================================
   Layout System
   Cooperatives App — Theme System
   
   Mobile-first adaptive layout. Na szerokim monitorze dodajemy boczne panele,
   NIE rozciągamy głównej treści.
   
   Nowoczesne rozwiązania:
   - container queries na komponentach
   - subgrid tam gdzie potrzeba
   - clamp() dla fluid spacing
   ========================================================================== */

@layer layout {

  /* ---- App Shell ---- */
  .app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  /* ---- Main Page Wrapper ---- */
  .page {
    display: grid;
    gap: var(--page-gutter);
    grid-template-areas: "main";
    grid-template-columns: 1fr;
    margin-inline: auto;
    max-width: 100%;
    padding: var(--page-gutter);
    padding-top: calc(var(--header-height) + var(--space-lg));
    width: 100%;
  }

  .page-main {
    grid-area: main;
    min-width: 0;  /* Prevent grid blowout */
  }

  .page-aside {
    grid-area: aside;
    display: none;  /* Hidden on mobile */
    min-width: 0;
  }

  .page-rail {
    grid-area: rail;
    display: none;  /* Hidden on mobile + tablet */
    min-width: 0;
  }

  /* ---- Desktop: pojedyncza, wyśrodkowana kolumna ----
     Sloty rail/main/aside nie są nigdzie używane w JSX, więc .page NIE
     narzuca już gridu wielokolumnowego (rozrzucał treść stron typu
     /privacy). Strony, które chcą paneli boczne, mogą je dodać same. */
  @media (min-width: 1024px) {
    .page {
      gap: var(--space-xl);
      grid-template-areas: "main";
      grid-template-columns: minmax(0, 1fr);
      max-width: calc(var(--content-max) + var(--aside-width) + var(--space-xl));
      padding-inline: var(--space-xl);
    }

    .page-aside {
      display: block;
      position: sticky;
      top: calc(var(--header-height) + var(--space-lg));
      max-height: calc(100dvh - var(--header-height) - var(--space-xl));
      overflow-y: auto;
    }
  }

  /* ---- Wide: szersza, wciąż pojedyncza kolumna ---- */
  @media (min-width: 1440px) {
    .page {
      gap: var(--space-2xl);
      grid-template-areas: "main";
      grid-template-columns: minmax(0, 1fr);
      max-width: calc(var(--rail-width) + var(--content-max) + var(--aside-width) + var(--space-2xl) * 2);
      padding-inline: var(--space-2xl);
    }

    .page-rail {
      display: block;
      position: sticky;
      top: calc(var(--header-height) + var(--space-lg));
      max-height: calc(100dvh - var(--header-height) - var(--space-xl));
      overflow-y: auto;
    }
  }

  /* ---- Ultrawide: generous spacing ---- */
  @media (min-width: 1920px) {
    :root {
      --aside-width: 22rem;
      --rail-width: 17rem;
    }

    .page {
      max-width: 1800px;
    }
  }

  /* ---- Page variant: centered (no aside/rail) ---- */
  .page--centered {
    grid-template-areas: "main";
    grid-template-columns: 1fr;
    max-width: var(--content-max);
  }

  @media (min-width: 1024px) {
    .page--centered {
      grid-template-areas: "main";
      grid-template-columns: 1fr;
      max-width: var(--content-max);
      padding-inline: var(--space-2xl);
    }
  }

  /* ---- Page variant: narrow (auth forms) ---- */
  .page--narrow {
    grid-template-areas: "main";
    grid-template-columns: 1fr;
    max-width: 28rem;
    margin-inline: auto;
  }

  /* ---- Content Sections ---- */
  .section {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
  }

  .section + .section {
    margin-top: var(--space-2xl);
  }

  /* ---- Card Container ---- */
  .card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--card-shadow);
    container-type: inline-size;
    overflow: hidden;
    padding: var(--space-lg);
    transition:
      box-shadow var(--duration-normal) var(--ease-default),
      border-color var(--duration-normal) var(--ease-default);
  }

  .card:hover {
    border-color: var(--color-border);
    box-shadow: var(--shadow-theme-md);
  }

  .card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    justify-content: space-between;
    margin-bottom: var(--space-md);
  }

  .card-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .card-footer {
    border-top: 1px solid var(--color-border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    justify-content: flex-end;
    margin-top: var(--space-md);
    padding-top: var(--space-md);
  }

  /* ---- Responsive Grid (for lists of items) ---- */
  .grid {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: 1fr;
  }

  @media (min-width: 640px) {
    .grid--2 { grid-template-columns: repeat(2, 1fr); }
  }

  @media (min-width: 1024px) {
    .grid--3 { grid-template-columns: repeat(3, 1fr); }
  }

  .grid--auto {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  }

  /* ---- Stack (vertical layout with gap) ---- */
  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .stack--sm  { gap: var(--space-sm); }
  .stack--lg  { gap: var(--space-lg); }
  .stack--xl  { gap: var(--space-xl); }

  /* ---- Cluster (horizontal layout with wrapping) ---- */
  .cluster {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: center;
  }

  .cluster--between {
    justify-content: space-between;
  }

  .cluster--end {
    justify-content: flex-end;
  }

  /* ---- Sidebar Layout ---- */
  .with-sidebar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-lg);
  }

  .with-sidebar > :first-child {
    flex-basis: 280px;
    flex-grow: 1;
  }

  .with-sidebar > :last-child {
    flex-basis: 0;
    flex-grow: 999;
    min-inline-size: 60%;
  }

  /* ---- Divider ---- */
  .divider {
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    margin-block: var(--space-lg);
  }

  /* ---- Aside Widgets ---- */
  .aside-widget {
    background-color: var(--color-surface-raised);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
  }

  .aside-widget + .aside-widget {
    margin-top: var(--space-md);
  }

  .aside-widget-title {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-wider);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
  }

  /* ---- Rail Navigation ---- */
  .rail-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-2xs);
  }

  .rail-nav-item {
    align-items: center;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    display: flex;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      color var(--duration-fast) var(--ease-default);
  }

  .rail-nav-item:hover {
    background-color: var(--color-hover-overlay);
    color: var(--color-text);
  }

  .rail-nav-item.active {
    background-color: var(--color-primary-subtle);
    color: var(--color-primary-text);
    font-weight: var(--weight-semibold);
  }

  .rail-section-title {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-wider);
    margin-bottom: var(--space-2xs);
    margin-top: var(--space-lg);
    padding-inline: var(--space-sm);
    text-transform: uppercase;
  }

  .rail-section-title:first-child {
    margin-top: 0;
  }

}

/* ==========================================================================
   Shared Components
   Cooperatives App — Theme System
   
   Style wspólne dla komponentów UI używanych na wielu podstronach.
   Każdy komponent używa CSS custom properties z tematów.
   ========================================================================== */

@layer components {

  /* =======================================================================
     MESSAGES / TOASTS
     ======================================================================= */

  .messages-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    left: 50%;
    max-width: min(28rem, calc(100vw - var(--space-xl)));
    position: fixed;
    top: calc(var(--header-height) + var(--space-md));
    transform: translateX(-50%);
    width: 100%;
    z-index: var(--z-toast);
  }

  .message {
    align-items: center;
    animation: message-slide-in var(--duration-slow) var(--ease-spring);
    backdrop-filter: blur(8px);
    border: 1px solid;
    border-radius: var(--radius-lg);
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    box-shadow: var(--shadow-theme-md);
  }

  .message--success {
    background-color: var(--color-success-subtle);
    border-color: color-mix(in oklch, var(--color-success) 40%, transparent);
    color: var(--color-success);
  }

  .message--error {
    background-color: var(--color-error-subtle);
    border-color: color-mix(in oklch, var(--color-error) 40%, transparent);
    color: var(--color-error);
  }

  .message--info {
    background-color: var(--color-info-subtle);
    border-color: color-mix(in oklch, var(--color-info) 40%, transparent);
    color: var(--color-info);
  }

  .message--warning {
    background-color: var(--color-warning-subtle);
    border-color: color-mix(in oklch, var(--color-warning) 40%, transparent);
    color: var(--color-warning);
  }

  @keyframes message-slide-in {
    from {
      opacity: 0;
      transform: translateX(-50%) translateY(-1rem);
    }
    to {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }
  }

  /* =======================================================================
     DIALOG / MODAL
     ======================================================================= */

  .dialog-overlay {
    align-items: center;
    background: var(--color-overlay);
    display: flex;
    inset: 0;
    justify-content: center;
    position: fixed;
    z-index: var(--z-modal);
    animation: overlay-fade-in var(--duration-normal) var(--ease-default);
  }

  .dialog {
    animation: dialog-scale-in var(--duration-slow) var(--ease-spring);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-theme-lg);
    max-height: 85dvh;
    max-width: min(28rem, calc(100vw - var(--space-xl)));
    overflow-y: auto;
    padding: var(--space-xl);
    width: 100%;
  }

  .dialog-title {
    font-size: var(--text-xl);
    margin-bottom: var(--space-md);
  }

  .dialog-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    margin-top: var(--space-xl);
  }

  @keyframes overlay-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  @keyframes dialog-scale-in {
    from {
      opacity: 0;
      transform: scale(0.95) translateY(0.5rem);
    }
    to {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }

  /* =======================================================================
     SECTION TOGGLE (CooperativePageSection pattern)
     ======================================================================= */

  .section-toggle {
    width: 100%;
  }

  .section-toggle-trigger {
    align-items: center;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    gap: var(--space-sm);
    justify-content: space-between;
    min-height: auto;
    padding: var(--space-sm) var(--space-md);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default);
    width: 100%;
  }

  .section-toggle-trigger:hover {
    background: var(--color-surface-sunken);
    border-color: var(--color-border);
  }

  .section-toggle-trigger::after {
    content: '▸';
    display: inline-block;
    font-size: 0.75em;
    transition: transform var(--duration-normal) var(--ease-spring);
  }

  .section-toggle-trigger[aria-expanded="true"]::after,
  .section-toggle.open .section-toggle-trigger::after {
    transform: rotate(90deg);
  }

  .section-toggle-content {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows var(--duration-slow) var(--ease-default);
  }

  .section-toggle.open .section-toggle-content,
  .section-toggle-content[data-open="true"] {
    grid-template-rows: 1fr;
  }

  .section-toggle-content > div {
    overflow: hidden;
  }

  .section-toggle-content > div > * {
    padding-top: var(--space-md);
  }

  /* =======================================================================
     FORM LAYOUT
     ======================================================================= */

  .form-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    max-width: 28rem;
  }

  .form-layout--wide {
    max-width: none;
  }

  .form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }

  .form-row {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  }

  .form-actions {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
    padding-top: var(--space-sm);
  }

  .form-actions--end {
    justify-content: flex-end;
  }

  .field-error {
    color: var(--color-error);
    display: none;
    font-size: var(--text-xs);
  }

  .field-hint {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
  }

  /* =======================================================================
     BADGE / TAG
     ======================================================================= */

  .badge {
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    display: inline-flex;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    gap: var(--space-2xs);
    line-height: 1;
    padding: var(--space-2xs) var(--space-xs);
    white-space: nowrap;
  }

  .badge--primary {
    background-color: var(--color-primary-subtle);
    border-color: color-mix(in oklch, var(--color-primary) 30%, transparent);
    color: var(--color-primary-text);
  }

  .badge--accent {
    background-color: var(--color-accent-subtle);
    border-color: color-mix(in oklch, var(--color-accent) 30%, transparent);
    color: var(--seed-accent-d);
  }

  .badge--count {
    background-color: var(--color-text);
    border-color: var(--color-text);
    color: var(--color-bg);
    min-width: 1.5rem;
    padding: var(--space-2xs) var(--space-2xs);
    text-align: center;
  }

  /* =======================================================================
     SEARCH
     ======================================================================= */

  .search-box {
    position: relative;
    width: 100%;
    max-width: 24rem;
  }

  .search-box input {
    padding-left: var(--space-xl);
  }

  .search-box::before {
    background-color: var(--color-text-muted);
    block-size: 1.1rem;
    content: '';
    inline-size: 1.1rem;
    left: var(--space-sm);
    -webkit-mask: var(--icon-search) center / contain no-repeat;
    mask: var(--icon-search) center / contain no-repeat;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  /* =======================================================================
     EMPTY STATE
     ======================================================================= */

  .empty-state {
    align-items: center;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-2xl);
    text-align: center;
  }

  .empty-state-icon {
    font-size: var(--text-3xl);
    opacity: 0.5;
  }

  .state-feedback {
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-theme-sm);
    color: var(--color-text-secondary);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-xl);
    text-align: center;
    width: 100%;
  }

  .app-error-boundary {
    align-items: center;
    display: flex;
    min-height: calc(100dvh - var(--header-height));
    padding: var(--space-xl);
  }

  .app-error-boundary .state-feedback {
    margin-inline: auto;
    max-width: 36rem;
  }

  .state-feedback h3,
  .state-feedback p {
    margin: 0;
  }

  .state-feedback h3 {
    color: var(--color-text);
    font-size: var(--text-lg);
  }

  .state-feedback p {
    max-width: 34rem;
  }

  .state-feedback-icon {
    align-items: center;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-full);
    color: var(--color-text-muted);
    display: inline-flex;
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    height: 3rem;
    justify-content: center;
    width: 3rem;
  }

  .state-feedback--error {
    background: var(--color-error-subtle);
    border-color: color-mix(in oklch, var(--color-error) 30%, transparent);
    color: var(--color-error);
  }

  .state-feedback--error h3,
  .state-feedback--error .state-feedback-icon {
    color: var(--color-error);
  }

  .state-feedback--loading {
    align-items: stretch;
    text-align: left;
  }

  .state-feedback-skeletons {
    display: grid;
    gap: var(--space-sm);
    margin-top: var(--space-xs);
    width: 100%;
  }

  .state-feedback-action {
    margin-top: var(--space-xs);
  }

  /* =======================================================================
     STATUS INDICATOR
     ======================================================================= */

  .status-dot {
    border-radius: var(--radius-full);
    display: inline-block;
    height: 0.5rem;
    width: 0.5rem;
  }

  .status-dot--active  { background-color: var(--color-success); }
  .status-dot--pending { background-color: var(--color-warning); }
  .status-dot--error   { background-color: var(--color-error); }
  .status-dot--muted   { background-color: var(--color-text-muted); }

  /* =======================================================================
     COOPERATIVE LIST ITEM (specific but used broadly)
     ======================================================================= */

  .list-item {
    align-items: center;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default);
  }

  .list-item:hover {
    background-color: var(--color-surface-raised);
    border-color: var(--color-border);
  }

  .list-item-letter {
    align-items: center;
    background-color: var(--color-primary-subtle);
    border-radius: var(--radius-sm);
    color: var(--color-primary-text);
    display: flex;
    flex-shrink: 0;
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    height: 2rem;
    justify-content: center;
    width: 2rem;
  }

  .list-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* =======================================================================
     SKELETON / LOADING
     ======================================================================= */

  .skeleton {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    background: linear-gradient(
      90deg,
      var(--color-surface-sunken) 25%,
      var(--color-surface-raised) 37%,
      var(--color-surface-sunken) 63%
    );
    background-size: 400% 100%;
    border-radius: var(--radius-sm);
    min-height: 1rem;
  }

  .skeleton--text { width: 80%; }
  .skeleton--title { width: 50%; min-height: 1.5rem; }
  .skeleton--avatar { width: 3rem; height: 3rem; border-radius: var(--radius-full); }

  @keyframes skeleton-pulse {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
  }

  /* =======================================================================
     RESPONSIVE HELPERS FOR COMPONENTS
     ======================================================================= */

  /* Hide on mobile, show on desktop */
  .desktop-only {
    display: none;
  }

  @media (min-width: 1024px) {
    .desktop-only {
      display: block;
    }
  }

  /* Hide on desktop, show on mobile */
  .mobile-only {
    display: block;
  }

  @media (min-width: 1024px) {
    .mobile-only {
      display: none;
    }
  }

}

/* ==========================================================================
   Expandable Section System
   Cooperatives App — Theme System
   
   System sekcji/paneli rozszerzalnych od 1 do 4 kolumn.
   Używany w: fieldset wewnątrz UserPage, CooperativePage, HomePage.
   
   Dwie filozofie:
   1. AUTO — sekcja automatycznie zajmuje tyle kolumn ile ma miejsca
   2. USER — użytkownik klikając może rozszerzać/zwężać sekcje
   
   Klasy:
   .section-panel           — kontener sekcji (fieldset, div, etc.)
   .section-panel--cols-1   — wymuś 1 kolumnę
   .section-panel--cols-2   — wymuś 2 kolumny
   .section-panel--cols-3   — wymuś 3 kolumny
   .section-panel--cols-4   — wymuś 4 kolumny (full width)
   
   .section-expand-controls — przyciski sterujące (generowane przez JS helper)
   ========================================================================== */

@layer components {

  /* ---- Page content width override for desktop ---- */
  /* Na desktop usuwamy restrykcyjne max-width i dajemy sekcjom oddychać */

  @media (min-width: 1024px) {
    .mainpage,
    .user-page,
    .cooperative-page,
    .cooperative-list,
    .provider {
      max-width: none;
      width: 100%;
    }

    /* Treść główna nie jest ograniczona do 56rem — rozciąga się */
    .mainpage-user,
    .cooperative-page-common,
    .cooperative-page-founder,
    .form-container {
      max-width: none;
      width: 100%;
    }
  }

  /* ---- Section Panel Base ---- */
  .section-panel {
    --cols: 1;
    --workspace-span: 1;
    container-type: inline-size;
    max-width: 100%;
    min-width: 0;
    position: relative;
    transition: max-width var(--duration-slow) var(--ease-default);
    width: 100%;
  }

  /* ---- Column sizing via CSS variable ---- */

  /* Smartfon: zawsze 1 kolumna, ale pełna szerokość */
  .section-panel {
    max-width: 100%;
  }

  /* Desktop (1024px+): 1-4 kolumny */
  @media (min-width: 1024px) {
    .section-panel--cols-1 { --cols: 1; max-width: 38rem; }     /* ~608px */
    .section-panel--cols-2 { --cols: 2; max-width: 56rem; }     /* ~896px */
    .section-panel--cols-3 { --cols: 3; max-width: 80rem; }     /* ~1280px */
    .section-panel--cols-4 { --cols: 4; max-width: min(100%, 112rem); }

    /* Default: sekcja = 2 kolumny na desktop */
    .section-panel:not([class*="cols-"]) {
      max-width: 56rem;
    }
  }

  /* Wide (1440px+): bardziej hojne rozmiary */
  @media (min-width: 1440px) {
    .section-panel--cols-1 { max-width: 42rem; }
    .section-panel--cols-2 { max-width: 64rem; }
    .section-panel--cols-3 { max-width: 96rem; }
    .section-panel--cols-4 { max-width: min(100%, 112rem); }

    .section-panel:not([class*="cols-"]) {
      max-width: 64rem;
    }
  }

  /* ---- Fieldset inside section-panel ---- */
  .section-panel > fieldset,
  .section-panel > .card {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  /* ---- Expand Controls ---- */
  .section-expand-controls {
    display: none; /* Mobile: ukryte */
    align-items: center;
    gap: var(--space-2xs);
    justify-content: flex-end;
    margin-bottom: var(--space-2xs);
    padding-right: var(--space-xs);
  }

  @media (min-width: 1024px) {
    .section-expand-controls {
      backdrop-filter: blur(14px);
      background: color-mix(in oklch, var(--color-surface-raised) 82%, transparent);
      border: 1px solid color-mix(in oklch, var(--color-border) 70%, transparent);
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-sm);
      display: flex;
      gap: var(--space-2xs);
      margin: 0;
      opacity: 0;
      padding: var(--space-2xs);
      pointer-events: none;
      position: absolute;
      right: calc(var(--space-md) + var(--space-2xs));
      top: calc(var(--space-md) + var(--space-2xs));
      transform: translateY(-2px);
      transition:
        opacity var(--duration-fast) var(--ease-default),
        transform var(--duration-fast) var(--ease-default);
    }
  }

  @media (min-width: 1024px) {
    .section-panel:hover > .section-expand-controls,
    .section-panel:focus-within > .section-expand-controls,
    .section-panel:hover > .section-order-controls-shell,
    .section-panel:focus-within > .section-order-controls-shell {
      opacity: 1;
      pointer-events: auto;
      transform: translateY(0);
    }
  }

  .section-expand-btn {
    align-items: center;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    display: inline-flex;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    gap: var(--space-2xs);
    height: 1.9rem;
    justify-content: center;
    min-height: auto;
    min-width: 1.9rem;
    padding: 0 var(--space-xs);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default),
      color var(--duration-fast) var(--ease-default);
  }

  .section-expand-btn:hover {
    background: var(--color-surface-sunken);
    border-color: var(--color-border);
    color: var(--color-text);
  }

  .section-expand-btn.active {
    background: var(--color-primary-subtle);
    border-color: color-mix(in oklch, var(--color-primary) 30%, transparent);
    color: var(--color-primary-text);
  }

  .section-expand-btn:disabled {
    cursor: not-allowed;
    opacity: 0.35;
  }

  .section-column-controls {
    display: inline-flex;
    gap: var(--space-2xs);
  }

  .section-order-controls {
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    display: inline-flex;
    gap: var(--space-2xs);
    margin-right: var(--space-2xs);
    padding: var(--space-2xs);
  }

  .section-order-controls-shell {
    display: none;
  }

  .section-order-btn {
    font-weight: var(--weight-bold);
    min-width: 1.8rem;
    padding-inline: var(--space-2xs);
  }

  @media (min-width: 1024px) {
    .section-order-controls-shell {
      display: flex;
      left: var(--space-md);
      opacity: 0;
      pointer-events: none;
      position: absolute;
      top: var(--space-md);
      transform: translateY(calc(var(--space-md) + 0.75rem)) scale(0.96);
      transition:
        opacity var(--duration-fast) var(--ease-default),
        transform var(--duration-fast) var(--ease-default);
      z-index: 3;
    }

    .section-order-controls-shell .section-order-controls {
      backdrop-filter: blur(14px);
      background: color-mix(in oklch, var(--color-surface-raised) 84%, transparent);
      border: 1px solid color-mix(in oklch, var(--color-border) 70%, transparent);
      box-shadow: var(--shadow-sm);
      margin-right: 0;
    }

    .section-order-controls-shell .section-expand-btn {
      height: 1.65rem;
      min-width: 1.65rem;
      padding-inline: var(--space-2xs);
    }

    .section-panel:hover > .section-order-controls-shell,
    .section-panel:focus-within > .section-order-controls-shell {
      transform: translateY(calc(-100% - var(--space-2xs))) scale(1);
    }
  }

  /* ---- Improved global fieldset sizes on desktop ---- */
  /* Każdy fieldset na desktop dostaje sensowną minimalną szerokość */
  @media (min-width: 1024px) {
    fieldset {
      min-width: min(100%, 400px);
    }

    /* Founder, BasicUser, Provider — ich fieldset powinien rosnąć */
    .founder > fieldset,
    .basic-user > fieldset,
    .provider .provider-shell {
      max-width: none;
      width: 100%;
    }
  }

  /* ---- CooperativeList fieldset: item with name needs min-width ---- */
  .cooperative-item {
    min-width: 0;
  }

  .cooperative-item .cooperative-list-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
  }

  .cooperative-item button {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: var(--text-xs);
  }

  /* ---- Auto-grid for inner content based on panel columns ---- */
  @container (min-width: 640px) {
    .section-panel .form-row,
    .section-panel .provider-actions {
      grid-template-columns: repeat(2, 1fr);
    }
  }

  @container (min-width: 960px) {
    .section-panel .form-row {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  @container (min-width: 1200px) {
    .section-panel .form-row {
      grid-template-columns: repeat(4, 1fr);
    }
  }

  /* ---- Workspace grid ---- */
  .workspace-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    width: 100%;
  }

  .workspace-page-titlebar {
    align-items: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
    justify-content: space-between;
    width: 100%;
  }

  .workspace-page-titlebar h2 {
    font-size: clamp(var(--text-xl), 2vw, var(--text-3xl));
    letter-spacing: 0;
    line-height: 1.15;
    margin: 0;
  }

  .workspace-page-titlebar p {
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    line-height: 1.6;
    margin: 0;
    max-width: 52rem;
  }

  .workspace-reset-button {
    align-self: flex-start;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    margin: 0;
    min-height: 2.35rem;
    padding: var(--space-xs) var(--space-md);
    width: auto;
  }

  .workspace-reset-button:hover {
    border-color: var(--color-primary);
    color: var(--color-text);
  }

  @media (min-width: 760px) {
    .workspace-page-titlebar {
      align-items: flex-end;
      flex-direction: row;
    }
  }

  .workspace-page-standalone .workspace-page-titlebar {
    margin-top: calc(var(--header-height) + var(--space-lg));
  }

  .workspace-grid {
    --workspace-columns: 1;
    align-items: stretch;
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: repeat(var(--workspace-columns), minmax(0, 1fr));
    width: 100%;
  }

  .workspace-grid > .section-panel {
    align-self: stretch;
    grid-column: span 1;
    max-width: none;
    min-width: 0;
    overflow: visible;
    width: 100%;
  }

  .workspace-grid > .section-panel.workspace-section--collapsed {
    align-self: start;
  }

  .workspace-grid > .section-panel > * {
    max-width: 100%;
    min-width: 0;
  }

  .workspace-section h1,
  .workspace-section h2,
  .workspace-section h3,
  .workspace-section legend {
    hyphens: auto;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: normal;
  }

  .workspace-section p {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  .workspace-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
  }

  .workspace-section-toggle {
    align-items: center;
    background: var(--color-surface-raised);
    border-color: var(--color-border);
    color: var(--color-text);
    font-weight: var(--weight-semibold);
    justify-content: center;
    line-height: 1.25;
    margin: 0;
    max-width: none;
    min-height: 2.85rem;
    overflow-wrap: anywhere;
    text-wrap: balance;
    width: 100%;
  }

  .workspace-section:not(:has(> .workspace-section-content)) .workspace-section-toggle {
    flex: 1 1 auto;
  }

  .workspace-section.workspace-section--collapsed {
    padding: var(--space-sm);
  }

  .workspace-section.workspace-section--collapsed .workspace-section-toggle,
  .workspace-section.workspace-section--collapsed:not(:has(> .workspace-section-content)) .workspace-section-toggle {
    flex: 0 0 auto;
  }

  .workspace-section:hover .workspace-section-toggle,
  .workspace-section:focus-within .workspace-section-toggle {
    min-height: 2.85rem;
  }

  .workspace-section-toggle-label {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  @media (min-width: 1024px) {
    .workspace-section > .section-expand-controls {
      right: calc(var(--space-md) + var(--space-2xs));
      top: var(--space-md);
      transform: translateY(calc(var(--space-md) + 0.75rem)) scale(0.96);
      z-index: 2;
    }

    .workspace-section > .section-expand-controls .section-expand-btn {
      font-size: var(--text-xs);
      height: 1.65rem;
      min-width: 1.65rem;
      padding-inline: 0;
    }

    .workspace-section:hover > .section-expand-controls,
    .workspace-section:focus-within > .section-expand-controls {
      transform: translateY(calc(-100% - var(--space-2xs))) scale(1);
    }

    .workspace-section-toggle-label {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }
  }

  .workspace-section-content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    margin-top: var(--space-md);
    min-width: 0;
    overflow-x: auto;
    scrollbar-gutter: stable;
    width: 100%;
  }

  .workspace-section-content > * {
    min-width: 0;
  }

  @container (max-width: 26rem) {
    .workspace-section {
      padding-inline: var(--space-sm);
    }

    .workspace-section-content {
      overflow-x: visible;
      scrollbar-gutter: auto;
    }
  }

  @media (min-width: 760px) {
    .workspace-grid {
      --workspace-columns: 2;
    }

    .workspace-grid > .section-panel--cols-2,
    .workspace-grid > .section-panel--cols-3,
    .workspace-grid > .section-panel--cols-4 {
      grid-column: span 2;
    }
  }

  @media (min-width: 1120px) {
    .workspace-grid {
      --workspace-columns: 4;
    }

    .workspace-grid > .section-panel--cols-1 { grid-column: span 1; }
    .workspace-grid > .section-panel--cols-2 { grid-column: span 2; }
    .workspace-grid > .section-panel--cols-3 { grid-column: span 3; }
    .workspace-grid > .section-panel--cols-4 { grid-column: span 4; }
  }

  @media (min-width: 2200px) {
    .workspace-grid {
      --workspace-columns: 6;
    }
  }

  @media (min-width: 2800px) {
    .workspace-grid {
      --workspace-columns: 8;
    }
  }

  @media (min-width: 3800px) {
    .workspace-grid {
      --workspace-columns: 12;
    }
  }
}

@layer components {
  .public-content-page {
    align-content: start;
    display: grid;
    gap: var(--space-xl);
    grid-auto-flow: row;
    grid-template-areas: none;
    grid-template-columns: minmax(0, 1fr);
    margin-inline: auto;
    max-width: min(76rem, calc(100vw - (2 * var(--page-gutter))));
    padding-block: calc(var(--header-height) + var(--space-2xl))
      var(--space-2xl);
  }

  .public-content-page > * {
    min-width: 0;
  }

  .public-content-hero,
  .public-content-section,
  .public-content-links,
  .public-content-index {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

  .public-content-breadcrumbs {
    align-items: center;
    color: var(--color-text-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: var(--text-sm);
    gap: var(--space-2xs);
  }

  .public-content-breadcrumbs a {
    color: var(--color-primary);
    font-weight: var(--weight-semibold);
  }

  .public-content-hero {
    align-items: start;
    background:
      radial-gradient(
        120% 100% at 100% 0%,
        color-mix(in oklch, var(--color-accent) 9%, transparent),
        transparent 58%
      ),
      linear-gradient(
        180deg,
        color-mix(in oklch, var(--color-primary) 6%, var(--color-surface)),
        var(--color-surface)
      );
    display: grid;
    column-gap: clamp(var(--space-xl), 5vw, var(--space-3xl));
    gap: var(--space-lg);
    grid-template-areas:
      "eyebrow meta"
      "title meta"
      "lead visual";
    grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 0.85fr);
    padding: clamp(var(--space-xl), 5vw, var(--space-3xl));
  }

  .public-content-eyebrow {
    align-items: center;
    background-color: color-mix(in oklch, var(--color-primary) 12%, var(--color-surface));
    border: 1px solid color-mix(in oklch, var(--color-primary) 26%, transparent);
    border-radius: var(--radius-full);
    color: var(--color-primary-text);
    display: inline-flex;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    grid-area: eyebrow;
    justify-self: start;
    letter-spacing: 0.08em;
    margin: 0;
    padding: var(--space-2xs) var(--space-md);
    text-transform: uppercase;
  }

  .public-content-hero h1 {
    font-size: clamp(var(--text-3xl), 4vw, var(--text-4xl));
    grid-area: title;
    line-height: 1.05;
    margin: 0;
    max-width: 18ch;
  }

  .public-content-lead {
    color: var(--color-text-muted);
    font-size: var(--text-lg);
    grid-area: lead;
    line-height: var(--line-relaxed);
    margin: 0;
    max-width: 68ch;
  }

  .public-content-meta {
    display: grid;
    gap: var(--space-sm);
    grid-area: meta;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    margin: 0;
  }

  .public-content-meta div {
    background: var(--color-surface-subtle);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-md);
  }

  .public-content-meta dt {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.06em;
    margin-bottom: var(--space-2xs);
    text-transform: uppercase;
  }

  .public-content-meta dd {
    margin: 0;
  }

  .public-content-visual {
    background: var(--color-surface-subtle);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    display: grid;
    gap: var(--space-sm);
    grid-area: visual;
    margin: 0;
    overflow: hidden;
    padding: var(--space-md);
  }

  .public-content-visual img {
    aspect-ratio: 16 / 7;
    display: block;
    height: auto;
    object-fit: contain;
    width: 100%;
  }

  .public-content-visual figcaption {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    margin: 0;
    text-align: center;
  }

  .public-content-grid {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  }

  @media (max-width: 900px) {
    .public-content-hero {
      grid-template-areas: none;
      grid-template-columns: minmax(0, 1fr);
    }

    .public-content-eyebrow,
    .public-content-hero h1,
    .public-content-lead,
    .public-content-meta,
    .public-content-visual {
      grid-area: auto;
    }
  }

  .public-content-section {
    padding: var(--space-xl);
  }

  .public-content-section h2,
  .public-content-links h2 {
    font-size: var(--text-2xl);
    margin-block: 0 var(--space-sm);
  }

  .public-content-section h2::after,
  .public-content-links h2::after {
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    block-size: 3px;
    border-radius: var(--radius-full);
    content: "";
    display: block;
    inline-size: 2.5rem;
    margin-block-start: var(--space-xs);
  }

  .public-content-section p {
    color: var(--color-text-muted);
    line-height: var(--line-relaxed);
    margin: 0;
  }

  .public-content-list {
    color: var(--color-text-muted);
    margin-block: var(--space-md) 0;
    padding-left: var(--space-lg);
  }

  .public-content-list li::marker {
    color: var(--color-primary);
  }

  .public-content-links {
    display: grid;
    gap: var(--space-md);
    padding: var(--space-xl);
  }

  .public-content-link-list,
  .public-content-index {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .public-content-link-list a,
  .public-content-index a {
    align-items: center;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    color: var(--color-primary);
    display: inline-flex;
    font-weight: var(--weight-semibold);
    min-height: 2.25rem;
    padding: var(--space-2xs) var(--space-md);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default),
      color var(--duration-fast) var(--ease-default);
  }

  .public-content-link-list a:hover,
  .public-content-index a:hover {
    background-color: var(--color-primary-subtle);
    border-color: color-mix(in oklch, var(--color-primary) 45%, var(--color-border));
    color: var(--color-primary-text);
  }

  .public-content-index {
    align-items: center;
    color: var(--color-text-muted);
    padding: var(--space-md) var(--space-xl);
  }

  .public-content-index span {
    font-weight: var(--weight-semibold);
  }

  @media (max-width: 640px) {
    .public-content-page {
      max-width: calc(100vw - (2 * var(--space-sm)));
      padding-block: calc(var(--header-height) + var(--space-lg))
        var(--space-lg);
    }

    .public-content-hero,
    .public-content-section,
    .public-content-links {
      padding: var(--space-lg);
    }
  }
}

/* ==========================================================================
   Utilities
   Cooperatives App — Theme System
   
   Klasy pomocnicze. Najwyższy priorytet w kaskadzie (ostatnia warstwa).
   ========================================================================== */

@layer utilities {

  /* ---- Text Alignment ---- */
  .text-left    { text-align: left; }
  .text-center  { text-align: center; }
  .text-right   { text-align: right; }

  /* ---- Text Size ---- */
  .text-xs   { font-size: var(--text-xs); }
  .text-sm   { font-size: var(--text-sm); }
  .text-base { font-size: var(--text-base); }
  .text-lg   { font-size: var(--text-lg); }
  .text-xl   { font-size: var(--text-xl); }
  .text-2xl  { font-size: var(--text-2xl); }

  /* ---- Text Color ---- */
  .text-primary   { color: var(--color-primary-text); }
  .text-secondary { color: var(--color-text-secondary); }
  .text-muted     { color: var(--color-text-muted); }
  .text-accent    { color: var(--color-accent); }
  .text-error     { color: var(--color-error); }
  .text-success   { color: var(--color-success); }

  /* ---- Font Weight ---- */
  .font-normal   { font-weight: var(--weight-normal); }
  .font-medium   { font-weight: var(--weight-medium); }
  .font-semibold { font-weight: var(--weight-semibold); }
  .font-bold     { font-weight: var(--weight-bold); }

  /* ---- Font Family ---- */
  .font-sans    { font-family: var(--font-sans); }
  .font-display { font-family: var(--font-display); }
  .font-mono    { font-family: var(--font-mono); }

  /* ---- Spacing (margin) ---- */
  .mt-0   { margin-top: 0; }
  .mt-sm  { margin-top: var(--space-sm); }
  .mt-md  { margin-top: var(--space-md); }
  .mt-lg  { margin-top: var(--space-lg); }
  .mt-xl  { margin-top: var(--space-xl); }
  .mt-2xl { margin-top: var(--space-2xl); }

  .mb-0   { margin-bottom: 0; }
  .mb-sm  { margin-bottom: var(--space-sm); }
  .mb-md  { margin-bottom: var(--space-md); }
  .mb-lg  { margin-bottom: var(--space-lg); }
  .mb-xl  { margin-bottom: var(--space-xl); }

  .mx-auto { margin-inline: auto; }

  /* ---- Spacing (padding) ---- */
  .p-0   { padding: 0; }
  .p-sm  { padding: var(--space-sm); }
  .p-md  { padding: var(--space-md); }
  .p-lg  { padding: var(--space-lg); }
  .p-xl  { padding: var(--space-xl); }

  .px-md { padding-inline: var(--space-md); }
  .px-lg { padding-inline: var(--space-lg); }
  .py-md { padding-block: var(--space-md); }
  .py-lg { padding-block: var(--space-lg); }

  /* ---- Display ---- */
  .hidden  { display: none; }
  .block   { display: block; }
  .flex    { display: flex; }
  .grid    { display: grid; }
  .inline  { display: inline; }

  /* ---- Flex Utilities ---- */
  .flex-col     { flex-direction: column; }
  .flex-row     { flex-direction: row; }
  .flex-wrap    { flex-wrap: wrap; }
  .flex-1       { flex: 1; }
  .flex-shrink-0 { flex-shrink: 0; }
  .items-center { align-items: center; }
  .items-start  { align-items: flex-start; }
  .justify-center  { justify-content: center; }
  .justify-between { justify-content: space-between; }
  .justify-end     { justify-content: flex-end; }

  /* ---- Gap ---- */
  .gap-xs  { gap: var(--space-xs); }
  .gap-sm  { gap: var(--space-sm); }
  .gap-md  { gap: var(--space-md); }
  .gap-lg  { gap: var(--space-lg); }
  .gap-xl  { gap: var(--space-xl); }

  /* ---- Width ---- */
  .w-full { width: 100%; }
  .w-auto { width: auto; }

  .max-w-sm  { max-width: 24rem; }
  .max-w-md  { max-width: 28rem; }
  .max-w-lg  { max-width: 32rem; }
  .max-w-xl  { max-width: 40rem; }
  .max-w-content { max-width: var(--content-max); }

  /* ---- Overflow ---- */
  .overflow-hidden { overflow: hidden; }
  .overflow-auto   { overflow: auto; }
  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ---- Border ---- */
  .rounded-sm   { border-radius: var(--radius-sm); }
  .rounded-md   { border-radius: var(--radius-md); }
  .rounded-lg   { border-radius: var(--radius-lg); }
  .rounded-xl   { border-radius: var(--radius-xl); }
  .rounded-full { border-radius: var(--radius-full); }

  /* ---- Shadows ---- */
  .shadow-sm { box-shadow: var(--shadow-theme-sm); }
  .shadow-md { box-shadow: var(--shadow-theme-md); }
  .shadow-lg { box-shadow: var(--shadow-theme-lg); }

  /* ---- Position ---- */
  .relative { position: relative; }
  .absolute { position: absolute; }
  .sticky   { position: sticky; }

  /* ---- Cursor ---- */
  .cursor-pointer { cursor: pointer; }
  .cursor-default { cursor: default; }

  /* ---- Visually Hidden (accessible) ---- */
  .sr-only {
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    white-space: nowrap;
    width: 1px;
  }

  /* ---- Animation ---- */
  .animate-fade-in {
    animation: fade-in var(--duration-slow) var(--ease-default);
  }

  .animate-slide-up {
    animation: slide-up var(--duration-slow) var(--ease-spring);
  }

  @keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

  @keyframes slide-up {
    from {
      opacity: 0;
      transform: translateY(var(--space-md));
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* ---- Hover Lift (interaktywne karty / kafle) ---- */
  .u-lift {
    transition:
      transform var(--duration-normal) var(--ease-default),
      box-shadow var(--duration-normal) var(--ease-default),
      border-color var(--duration-normal) var(--ease-default);
  }

  @media (hover: hover) {
    .u-lift:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-theme-md);
    }
  }

  /* ---- Inline SVG icon ---- */
  .icon {
    display: inline-block;
    flex-shrink: 0;
    height: 1em;
    width: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.125em;
  }

  /* ---- Responsive visibility ---- */
  @media (max-width: 767px) {
    .hide-mobile { display: none !important; }
  }

  @media (min-width: 768px) and (max-width: 1023px) {
    .hide-tablet { display: none !important; }
  }

  @media (min-width: 1024px) {
    .hide-desktop { display: none !important; }
  }

}

/* ==========================================================================
   Global Entry Point
   Cooperatives App — Theme System
   
   Ten plik importuje cały system stylów w poprawnej kolejności warstw.
   Jest jedynym importem potrzebnym w index.js / App.js.
   
   WAŻNE: Kolejność @import odpowiada priorytetom kaskady (@layer).
   reset < tokens < base < layout < components < utilities < themes
   ========================================================================== */

/* ---- Deklaracja kolejności warstw ---- */
@layer reset, tokens, base, layout, components, utilities, themes;

/* ---- Imports ---- */

/* ==========================================================================
   Header Component
   ========================================================================== */

.app-header {
  align-items: center;
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  gap: var(--space-md);
  height: var(--header-height);
  justify-content: space-between;
  left: 0;
  max-width: 100vw;
  min-width: 0;
  overflow: hidden;
  padding-inline: var(--page-gutter);
  position: fixed;
  right: 0;
  top: 0;
  width: auto;
  z-index: var(--z-sticky);
}

.app-header-logo {
  flex: 0 0 auto;
  min-width: 0;
}

.app-header-logo a {
  color: var(--header-text);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: 0;
  transition: color var(--duration-fast) var(--ease-default);
}

.app-header-logo a:hover {
  color: var(--color-accent);
}

.app-nav {
  min-width: 0;
}

.app-nav-list {
  align-items: center;
  display: flex;
  gap: var(--space-xs);
  list-style: none;
  min-width: 0;
  padding: 0;
}

.app-nav-list li {
  align-items: center;
  display: flex;
  margin: 0;
  min-width: 0;
}

.app-nav-link,
.app-user-link,
.app-nav-action {
  align-items: center;
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  color: var(--header-text-muted);
  display: inline-flex;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  min-height: 2rem;
  padding: var(--space-2xs) var(--space-sm);
  transition:
    background-color var(--duration-fast) var(--ease-default),
    border-color var(--duration-fast) var(--ease-default),
    color var(--duration-fast) var(--ease-default);
  white-space: nowrap;
}

.app-conversation-link {
  gap: var(--space-2xs);
  padding-right: var(--space-2xs);
}

.app-nav-badge {
  align-items: center;
  background-color: var(--color-accent);
  border: 1px solid color-mix(in oklch, var(--color-accent), white 22%);
  border-radius: var(--radius-full);
  color: var(--color-text-on-accent);
  display: inline-flex;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-bold);
  justify-content: center;
  line-height: 1;
  min-height: 1.35rem;
  min-width: 1.35rem;
  padding: 0 var(--space-2xs);
}

.app-nav-link:hover,
.app-user-link:hover,
.app-nav-action:hover,
.app-nav-link.active,
.app-user-link.active {
  background-color: oklch(1 0 0 / 0.08);
  color: var(--header-text);
}

.app-nav-action {
  cursor: pointer;
  font-family: var(--font-sans);
}

.app-nav-action:active {
  transform: none;
}

.app-user-summary {
  color: var(--header-text-muted);
  font-size: var(--text-sm);
  gap: var(--space-2xs);
  white-space: nowrap;
}

.app-user-summary strong {
  color: var(--header-text);
}

.app-user-link {
  color: var(--header-text);
  font-weight: var(--weight-semibold);
  padding-inline: var(--space-xs);
}

.theme-toggle {
  align-items: center;
  background: oklch(1 0 0 / 0.1);
  border: 1px solid oklch(1 0 0 / 0.15);
  border-radius: var(--radius-full);
  color: var(--header-text);
  display: inline-flex;
  font-size: var(--text-xs);
  gap: var(--space-2xs);
  justify-content: center;
  min-height: 2rem;
  min-width: 2.25rem;
  padding: var(--space-2xs) var(--space-sm);
  transition:
    background-color var(--duration-fast) var(--ease-default),
    border-color var(--duration-fast) var(--ease-default),
    transform var(--duration-fast) var(--ease-spring);
}

.theme-toggle:hover {
  background: oklch(1 0 0 / 0.18);
  border-color: oklch(1 0 0 / 0.28);
  transform: translateY(-1px);
}

.theme-toggle-icon {
  font-size: var(--text-base);
  line-height: 1;
}

.theme-toggle-text {
  color: var(--header-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1;
}

@media (min-width: 1024px) {
  .app-header {
    padding-inline: var(--space-xl);
  }
}

@media (max-width: 640px) {
  .app-header {
    gap: var(--space-xs);
    padding-inline: var(--space-sm);
  }

  .app-header-logo a {
    font-size: clamp(var(--text-base), 4.5vw, var(--text-lg));
  }

  .app-nav-list {
    gap: var(--space-2xs);
  }

  .app-nav-link,
  .app-user-link,
  .app-nav-action {
    font-size: var(--text-xs);
    padding-inline: var(--space-xs);
  }

  .app-user-summary span {
    display: none;
  }

  .app-nav-list .app-nav-privacy {
    display: none;
  }

  .app-nav-list .app-nav-public {
    display: none;
  }

  .theme-toggle {
    padding-inline: var(--space-xs);
  }

  .theme-toggle-text {
    display: none;
  }
}

/* SuccessMessage */

.message-container .success-message {
  background-color: var(--color-success-subtle);
  border-color: color-mix(in oklch, var(--color-success) 32%, var(--color-border));
  color: var(--color-success);
  font-weight: var(--weight-semibold);
  margin: 0;
}

/* ErrorMessage */

.message-container .error-message {
  background-color: var(--color-error-subtle);
  border-color: color-mix(in oklch, var(--color-error) 32%, var(--color-border));
  color: var(--color-error);
  font-weight: var(--weight-semibold);
}

/* InfoMessage */

.message-container .info-message {
  background-color: var(--color-info-subtle);
  border-color: color-mix(in oklch, var(--color-info) 32%, var(--color-border));
  color: var(--color-info);
  font-weight: var(--weight-semibold);
}

/* Message */

.message-container .message {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-theme-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-normal);
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  pointer-events: auto;
  text-align: left;
  animation: message-slide-in var(--duration-slow) var(--ease-spring);
}

@keyframes message-slide-in {
  from {
    opacity: 0;
    transform: translateY(calc(var(--space-md) * -1));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Messages container */

.message-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-xs);
  position: fixed;
  top: calc(var(--header-height) + var(--space-sm));
  right: var(--page-gutter);
  z-index: var(--z-toast);
  max-width: min(26rem, calc(100vw - (2 * var(--page-gutter))));
  pointer-events: none;
  width: 100%;
}

.message-container .messages {
  display: grid;
  gap: var(--space-xs);
  width: 100%;
}

@media (max-width: 640px) {
  .message-container {
    align-items: stretch;
    left: var(--space-sm);
    max-width: none;
    right: var(--space-sm);
    width: auto;
  }
}

/* DeleteAccountDialog */

.delete-container {
  height: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
/* DialogWrapper */

.delete-container {
  transform: translateY(calc(var(--space-lg) * -1));
}

.delete-buttons button {
  margin-top: var(--space-sm);
}
@layer components {
  .consent-banner {
    background: color-mix(in srgb, var(--color-surface) 94%, transparent);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    bottom: var(--space-md);
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
    left: 50%;
    max-width: min(68rem, calc(100vw - (2 * var(--space-md))));
    position: fixed;
    transform: translateX(-50%);
    width: 100%;
    z-index: 60;
  }

  .consent-banner-content {
    align-items: end;
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: minmax(0, 1fr) auto;
    padding: var(--space-lg);
  }

  .consent-banner h2,
  .consent-modal h2 {
    font-size: var(--text-xl);
    margin: 0;
  }

  .consent-banner p,
  .consent-note {
    color: var(--color-text-muted);
    margin: var(--space-xs) 0;
  }

  .consent-eyebrow {
    color: var(--color-primary);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    letter-spacing: 0.08em;
    margin: 0 0 var(--space-2xs);
    text-transform: uppercase;
  }

  .consent-actions,
  .consent-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: end;
  }

  .consent-actions button,
  .consent-modal-actions button {
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    color: var(--color-text);
    cursor: pointer;
    font-weight: var(--weight-semibold);
    min-height: 2.75rem;
    min-width: 10.5rem;
    padding: var(--space-xs) var(--space-md);
  }

  .consent-actions button:hover,
  .consent-modal-actions button:hover,
  .consent-icon-button:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
  }

  .consent-modal-backdrop {
    align-items: center;
    background: rgb(0 0 0 / 0.54);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: var(--space-md);
    position: fixed;
    z-index: 70;
  }

  .consent-modal {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
    display: grid;
    gap: var(--space-md);
    max-height: calc(100dvh - (2 * var(--space-md)));
    max-width: min(48rem, calc(100vw - (2 * var(--space-md))));
    overflow: auto;
    padding: var(--space-lg);
    width: 100%;
  }

  .consent-modal-header {
    align-items: start;
    display: flex;
    gap: var(--space-md);
    justify-content: space-between;
  }

  .consent-icon-button {
    align-items: center;
    aspect-ratio: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    width: 2.5rem;
  }

  .consent-category-list {
    display: grid;
    gap: var(--space-sm);
  }

  .consent-category {
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: var(--space-md);
    grid-template-columns: minmax(0, 1fr) auto;
    padding: var(--space-md);
  }

  .consent-category.is-required {
    background: var(--color-surface-subtle);
  }

  .consent-category strong,
  .consent-category small {
    display: block;
  }

  .consent-category small {
    color: var(--color-text-muted);
    line-height: var(--line-relaxed);
    margin-top: var(--space-2xs);
  }

  .consent-switch {
    align-items: center;
    display: inline-flex;
    position: relative;
  }

  .consent-switch input {
    height: 100%;
    inset: 0;
    margin: 0;
    opacity: 0;
    position: absolute;
    width: 100%;
    z-index: 1;
  }

  .consent-switch-track {
    align-items: center;
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-full);
    display: inline-flex;
    height: 1.75rem;
    padding: 0.18rem;
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default);
    width: 3.1rem;
  }

  .consent-switch-thumb {
    aspect-ratio: 1;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-xs);
    display: block;
    height: 100%;
    transform: translateX(0);
    transition:
      background-color var(--duration-fast) var(--ease-default),
      border-color var(--duration-fast) var(--ease-default),
      transform var(--duration-fast) var(--ease-default);
  }

  .consent-switch input:checked + .consent-switch-track {
    background: var(--color-primary);
    border-color: var(--color-primary);
  }

  .consent-switch input:checked + .consent-switch-track .consent-switch-thumb {
    border-color: color-mix(in oklch, var(--color-primary) 28%, var(--color-surface));
    transform: translateX(1.32rem);
  }

  .consent-switch input:focus-visible + .consent-switch-track {
    box-shadow: 0 0 0 3px var(--color-focus-ring);
  }

  .consent-switch input:disabled + .consent-switch-track {
    cursor: not-allowed;
    opacity: 0.72;
  }

  @media (max-width: 760px) {
    .consent-banner {
      bottom: var(--space-sm);
      max-width: calc(100vw - (2 * var(--space-sm)));
    }

    .consent-banner-content {
      grid-template-columns: 1fr;
    }

    .consent-actions,
    .consent-modal-actions {
      justify-content: stretch;
    }

    .consent-actions button,
    .consent-modal-actions button {
      flex: 1 1 100%;
      min-width: 0;
    }

    .consent-modal {
      max-height: calc(100dvh - (2 * var(--space-sm)));
      padding: var(--space-lg);
    }
  }
}

