/* =============================================================================
   FCR Control Panel by FarmaPro - Design System
   Premium agri-tech (Apple Health x Stripe, 2026)
   Czysty CSS, mobile-first, dark-mode ready, PWA, print-ready.

   Spis treści:
     1.  Design tokens (:root) + dark overrides (html.dark)
     2.  Reset / base
     3.  Typografia stron i helpery tekstowe
     4.  Layout shell (sidebar / topbar / content / bottomnav / footer)
     5.  Nawigacja (nav-item, bottomnav-item)
     6.  Brand
     7.  Karty (card, ring-*)
     8.  KPI / StatTile
     9.  Bento grid + grid helpers
     10. Przyciski (btn + warianty + is-loading)
     11. Formularze
     12. Tabela + cards-mobile
     13. Badge / status
     14. Tabs
     15. Empty state
     16. Loading (spinner / skeleton / overlay)
     17. Modal
     18. Toast
     19. Info box / checklist / chip
     20. Charts
     21. Auth
     22. Helpers (hidden, desktop-only, safe-area, scrollbar-hide ...)
     23. Responsywność (sidebar >=900px / bottomnav mobile / tabele->karty)
     24. Print styles
   ============================================================================= */

/* =============================================================================
   1. DESIGN TOKENS
   ============================================================================= */
:root {
  /* --- Skala kolorów semantycznych: bezpieczny (safe / emerald) --- */
  --safe-50: #ecfdf5;
  --safe-100: #d1fae5;
  --safe-500: #10b981;
  --safe-600: #059669;
  --safe-700: #047857;

  /* --- Ostrzeżenie (warn / amber) --- */
  --warn-50: #fffbeb;
  --warn-100: #fef3c7;
  --warn-500: #f59e0b;
  --warn-600: #d97706;
  --warn-700: #b45309;

  /* --- Alarm (danger / rose) --- */
  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;

  /* --- Informacja (info / sky) --- */
  --info-50: #eff6ff;
  --info-100: #dbeafe;
  --info-500: #3b82f6;
  --info-600: #2563eb;
  --info-700: #1d4ed8;

  /* --- Neutralna skala (slate) --- */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* --- Tokeny roli (jasny motyw) --- */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: rgba(226, 232, 240, 0.8);
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f172a;          /* slate-900 w jasnym */
  --primary-contrast: #ffffff;

  /* --- Promienie --- */
  --radius-card: 16px;
  --radius-modal: 24px;
  --radius-input: 12px;
  --radius-pill: 9999px;

  /* --- Cienie --- */
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -12px rgba(15, 23, 42, 0.08);
  --shadow-card-hover: 0 2px 4px rgba(15, 23, 42, 0.06), 0 16px 48px -16px rgba(15, 23, 42, 0.12);
  --shadow-pop: 0 4px 12px rgba(15, 23, 42, 0.08), 0 24px 64px -20px rgba(15, 23, 42, 0.24);

  /* --- Dotyk / ruch --- */
  --tap: 44px;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* --- Typografia --- */
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* --- Wymiary layoutu --- */
  --sidebar-w: 264px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;
  --content-max: 1200px;

  /* --- Bezpieczne obszary (notch) --- */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* --- Tło gradientu ekranu logowania --- */
  --auth-gradient: radial-gradient(1200px 600px at 50% -10%, #ffffff 0%, var(--slate-50) 55%, var(--slate-100) 100%);

  color-scheme: light;
}

/* --- Nadpisania ciemnego motywu --- */
html.dark {
  --bg: #020617;
  --surface: rgba(15, 23, 42, 0.8);
  --surface-2: rgba(30, 41, 59, 0.7);
  --border: rgba(51, 65, 85, 0.6);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #ffffff;          /* biały w ciemnym */
  --primary-contrast: #0f172a;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  --shadow-card-hover: 0 2px 4px rgba(0, 0, 0, 0.5), 0 16px 48px -16px rgba(0, 0, 0, 0.7);
  --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.5), 0 24px 64px -20px rgba(0, 0, 0, 0.7);

  --auth-gradient: radial-gradient(1200px 600px at 50% -10%, #0b1220 0%, #020617 60%, #000000 100%);

  color-scheme: dark;
}

/* =============================================================================
   2. RESET / BASE
   ============================================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
  transition: background-color var(--transition), color var(--transition);
  overflow-x: hidden;
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

ul,
ol {
  list-style: none;
}

/* Inputy min 16px na mobile - blokada auto-zoomu iOS */
input,
select,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: inherit;
}

/* Widoczny fokus klawiaturowy */
:focus-visible {
  outline: 2px solid var(--info-500);
  outline-offset: 2px;
  border-radius: 6px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Selekcja tekstu */
::selection {
  background: var(--info-100);
  color: var(--info-700);
}

html.dark ::selection {
  background: var(--info-700);
  color: #ffffff;
}

/* Stylizacja paska przewijania */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--slate-300) transparent;
}

html.dark * {
  scrollbar-color: var(--slate-700) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--slate-300);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--slate-400);
  background-clip: content-box;
}

html.dark ::-webkit-scrollbar-thumb {
  background: var(--slate-700);
  background-clip: content-box;
}

html.dark ::-webkit-scrollbar-thumb:hover {
  background: var(--slate-600);
  background-clip: content-box;
}

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

/* =============================================================================
   3. TYPOGRAFIA STRON + HELPERY TEKSTOWE
   ============================================================================= */
.page-title {
  font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
}

.page-subtitle {
  margin-top: 6px;
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 400;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

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

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.text-center {
  text-align: center;
}

.divider {
  height: 1px;
  width: 100%;
  background: var(--border);
  border: 0;
  margin: 4px 0;
}

/* =============================================================================
   4. LAYOUT SHELL
   ============================================================================= */
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto;
  background: var(--bg);
}

/* Sidebar (desktop) */
.app-sidebar {
  display: none;          /* domyślnie ukryty (mobile-first) */
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px calc(20px + var(--safe-bottom));
  padding-left: calc(16px + var(--safe-left));
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  gap: 8px;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
  margin-top: 8px;
}

/* „Powered by FarmaPro.pl" przyklejone do SAMEGO DOŁU sidebara, z separatorem. */
.app-sidebar .brand-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Główna kolumna */
.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

/* Topbar */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: clamp(16px, 4vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}

/* Treść strony */
.app-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: clamp(16px, 4vw, 32px);
  padding-bottom: calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 3vw, 28px);
  animation: fade-in-up var(--transition) both;
}

@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dolna nawigacja (mobile) */
.app-bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 2px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
}

/* Stopka */
.app-footer {
  padding: 20px clamp(16px, 4vw, 32px) calc(20px + var(--safe-bottom));
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* =============================================================================
   5. NAWIGACJA
   ============================================================================= */
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius-input);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  transition: background-color var(--transition), color var(--transition), transform var(--transition);
  user-select: none;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item:active {
  transform: scale(0.99);
}

.nav-item.active {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-card);
}

.nav-item .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
}

.nav-item .nav-label {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Pozycje dolnej nawigacji */
.bottomnav-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tap);
  padding: 6px 4px;
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--transition), transform var(--transition);
}

.bottomnav-item .nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.bottomnav-item:active {
  transform: scale(0.94);
}

.bottomnav-item.active {
  color: var(--primary);
}

html.dark .bottomnav-item.active {
  color: var(--info-500);
}

/* =============================================================================
   6. BRAND
   ============================================================================= */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 11px;
  background: var(--primary);
  color: var(--primary-contrast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-name {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text);
  white-space: nowrap;
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.brand-footer {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  opacity: 0.75;
  letter-spacing: 0.02em;
}

/* =============================================================================
   7. KARTY + STATUS RINGI
   ============================================================================= */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: clamp(16px, 3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--border) 60%, var(--slate-300));
}

.card-interactive:active {
  transform: translateY(0);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.card-subtitle {
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

/* Status ring - lewy akcent obwódki karty */
.ring-neutral,
.ring-ok,
.ring-warn,
.ring-alert,
.ring-info {
  border-left-width: 4px;
  border-left-style: solid;
}

.ring-neutral {
  border-left-color: var(--slate-400);
}

.ring-ok {
  border-left-color: var(--safe-500);
}

.ring-warn {
  border-left-color: var(--warn-500);
}

.ring-alert {
  border-left-color: var(--danger-500);
}

.ring-info {
  border-left-color: var(--info-500);
}

/* =============================================================================
   8. KPI / STATTILE
   ============================================================================= */
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: clamp(16px, 3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  transition: box-shadow var(--transition), transform var(--transition);
}

.kpi-label {
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 6px;
  word-break: break-word;
}

.kpi-unit {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

.kpi-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Modyfikatory koloru wartości KPI */
.kpi--ok .kpi-value {
  color: var(--safe-600);
}

.kpi--warn .kpi-value {
  color: var(--warn-600);
}

.kpi--alert .kpi-value {
  color: var(--danger-600);
}

.kpi--info .kpi-value {
  color: var(--info-600);
}

.kpi--neutral .kpi-value {
  color: var(--text);
}

html.dark .kpi--ok .kpi-value {
  color: var(--safe-500);
}

html.dark .kpi--warn .kpi-value {
  color: var(--warn-500);
}

html.dark .kpi--alert .kpi-value {
  color: var(--danger-500);
}

html.dark .kpi--info .kpi-value {
  color: var(--info-500);
}

/* =============================================================================
   9. BENTO GRID + GRID HELPERS
   ============================================================================= */
.bento {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: clamp(12px, 2vw, 18px);
}

.grid-2,
.grid-3,
.grid-4 {
  display: grid;
  gap: clamp(12px, 2vw, 18px);
  grid-template-columns: 1fr;
}

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

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

/* =============================================================================
   10. PRZYCISKI
   ============================================================================= */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-input);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--transition), color var(--transition),
    border-color var(--transition), box-shadow var(--transition), transform 80ms ease, opacity var(--transition);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn .nav-icon,
.btn svg {
  flex-shrink: 0;
}

/* --- Warianty --- */
.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-card);
}

.btn-primary:hover {
  box-shadow: var(--shadow-card-hover);
  filter: brightness(1.06);
}

html.dark .btn-primary:hover {
  filter: brightness(0.94);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-card);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--slate-300);
}

html.dark .btn-secondary:hover {
  border-color: var(--slate-600);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-subtle {
  background: var(--surface-2);
  color: var(--text);
}

.btn-subtle:hover {
  background: color-mix(in srgb, var(--surface-2) 70%, var(--slate-300));
}

.btn-success {
  background: var(--safe-600);
  color: #ffffff;
  box-shadow: var(--shadow-card);
}

.btn-success:hover {
  background: var(--safe-700);
}

.btn-danger {
  background: var(--danger-600);
  color: #ffffff;
  box-shadow: var(--shadow-card);
}

.btn-danger:hover {
  background: var(--danger-700);
}

/* --- Rozmiary --- */
.btn-lg {
  min-height: 52px;
  padding: 0 24px;
  font-size: 1rem;
  border-radius: 14px;
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.82rem;
  border-radius: 10px;
  gap: 6px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  min-height: var(--tap);
  width: var(--tap);
  padding: 0;
  flex-shrink: 0;
}

.btn-icon.btn-sm {
  min-height: 36px;
  width: 36px;
}

.btn-icon.btn-lg {
  min-height: 52px;
  width: 52px;
}

/* --- Stan ładowania --- */
.btn.is-loading {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}

.btn.is-loading > * {
  visibility: hidden;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--primary-contrast);
  visibility: visible;
  animation: spin 0.7s linear infinite;
}

.btn-secondary.is-loading::after,
.btn-ghost.is-loading::after,
.btn-subtle.is-loading::after {
  color: var(--text);
}

/* =============================================================================
   11. FORMULARZE
   ============================================================================= */
.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 14px;
  font-size: 16px;          /* blokada zoomu iOS */
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

html.dark .input,
html.dark .select,
html.dark .textarea {
  background: rgba(15, 23, 42, 0.55);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--slate-300);
}

html.dark .input:hover,
html.dark .select:hover,
html.dark .textarea:hover {
  border-color: var(--slate-600);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--info-500);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--info-500) 16%, transparent);
}

.textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

/* Strzałka selecta */
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

/* Pola błędne */
.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid {
  border-color: var(--danger-500);
}

.input.is-invalid:focus,
.select.is-invalid:focus,
.textarea.is-invalid:focus {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger-500) 16%, transparent);
}

.helper {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-error {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--danger-600);
  line-height: 1.4;
}

html.dark .field-error {
  color: var(--danger-500);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.form-actions .btn-block {
  flex: 1 1 100%;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

/* Pola w siatce mogą zajmować pełną szerokość */
.form-group.span-2 {
  grid-column: 1 / -1;
}

/* =============================================================================
   12. TABELA + CARDS-MOBILE
   ============================================================================= */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th {
  text-align: left;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background-color var(--transition);
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table td.num,
.table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.table .table-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Kontener kart zastępujących tabelę na mobile */
.cards-mobile {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cards-mobile .card {
  gap: 10px;
}

/* Wiersz etykieta-wartość w KAŻDEJ karcie (etykieta z lewej, wartość z prawej). */
.card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}
.card-row-label { color: var(--text-muted); min-width: 0; }
.card-row-value { font-weight: 600; text-align: right; }

.cards-mobile .card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.cards-mobile .card-row-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cards-mobile .card-row-value {
  font-weight: 600;
  text-align: right;
}

/* =============================================================================
   13. BADGE / STATUS
   ============================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge-ok {
  background: var(--safe-50);
  color: var(--safe-700);
}

.badge-warn {
  background: var(--warn-50);
  color: var(--warn-700);
}

.badge-alert {
  background: var(--danger-50);
  color: var(--danger-700);
}

.badge-info {
  background: var(--info-50);
  color: var(--info-700);
}

.badge-neutral {
  background: var(--slate-100);
  color: var(--slate-600);
}

html.dark .badge-ok {
  background: color-mix(in srgb, var(--safe-500) 18%, transparent);
  color: var(--safe-500);
}

html.dark .badge-warn {
  background: color-mix(in srgb, var(--warn-500) 18%, transparent);
  color: var(--warn-500);
}

html.dark .badge-alert {
  background: color-mix(in srgb, var(--danger-500) 18%, transparent);
  color: var(--danger-500);
}

html.dark .badge-info {
  background: color-mix(in srgb, var(--info-500) 18%, transparent);
  color: var(--info-500);
}

html.dark .badge-neutral {
  background: color-mix(in srgb, var(--slate-500) 24%, transparent);
  color: var(--slate-300);
}

/* =============================================================================
   14. TABS
   ============================================================================= */
.tabs {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tabs-scroll {
  overflow-x: auto;
  flex-wrap: nowrap;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 12px 14px;
  min-height: var(--tap);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  scroll-snap-align: start;
  transition: color var(--transition);
}

.tab::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  transition: background-color var(--transition);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
}

.tab.active::after {
  background: var(--primary);
}

html.dark .tab.active::after {
  background: var(--info-500);
}

/* =============================================================================
   15. EMPTY STATE
   ============================================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: clamp(32px, 6vw, 56px) 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-card);
}

.empty-icon {
  width: 64px;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 1.8rem;
  margin-bottom: 2px;
}

.empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.empty-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 42ch;
  line-height: 1.55;
}

/* =============================================================================
   16. LOADING (spinner / skeleton / overlay)
   ============================================================================= */
.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}

html.dark .spinner {
  border-top-color: var(--info-500);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-input);
  min-height: 16px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--surface) 80%, transparent) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s infinite;
}

html.dark .skeleton::after {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.06) 50%,
    transparent 100%
  );
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border-radius: inherit;
}

/* =============================================================================
   17. MODAL
   ============================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 4vw, 32px);
  padding-bottom: calc(clamp(12px, 4vw, 32px) + var(--safe-bottom));
  background: rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: backdrop-in var(--transition) both;
}

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

.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: modal-in var(--transition) both;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  margin: -6px -6px -6px 0;
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 1.2rem;
  transition: background-color var(--transition), color var(--transition);
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-close:active {
  transform: scale(0.94);
}

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 22px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn-block {
  flex: 1 1 100%;
}

/* =============================================================================
   18. TOAST
   ============================================================================= */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

@media (min-width: 900px) {
  .toast-root {
    left: auto;
    right: 24px;
    bottom: calc(24px + var(--safe-bottom));
    transform: none;
    align-items: flex-end;
  }
}

.toast {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 14px;
  box-shadow: var(--shadow-pop);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  animation: toast-in var(--transition) both;
}

.toast.is-leaving {
  animation: toast-out var(--transition) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.toast--ok {
  border-left-color: var(--safe-500);
}

.toast--error {
  border-left-color: var(--danger-500);
}

.toast--info {
  border-left-color: var(--info-500);
}

/* =============================================================================
   19. INFO BOX / CHECKLIST / CHIP
   ============================================================================= */
.info-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-input);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text);
}

/* Samodzielna ikona informacyjna (toasty, karty, nagłówki sekcji, listy).
   Bazowy styl niezależny od kontekstu .info-box, by ikona była zawsze
   poprawnie wyrównana i nie kurczyła się w układzie flex. */
.info-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1.4;
}

.info-box .info-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1.4;
  margin-top: 1px;
}

.info-box--info {
  background: var(--info-50);
  border-color: color-mix(in srgb, var(--info-500) 28%, transparent);
  color: var(--info-700);
}

.info-box--warn {
  background: var(--warn-50);
  border-color: color-mix(in srgb, var(--warn-500) 32%, transparent);
  color: var(--warn-700);
}

html.dark .info-box--info {
  background: color-mix(in srgb, var(--info-500) 12%, transparent);
  color: var(--info-100);
  border-color: color-mix(in srgb, var(--info-500) 32%, transparent);
}

html.dark .info-box--warn {
  background: color-mix(in srgb, var(--warn-500) 12%, transparent);
  color: var(--warn-100);
  border-color: color-mix(in srgb, var(--warn-500) 32%, transparent);
}

.checklist {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

.checklist-item::before {
  content: "";
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 6px;
  border: 2px solid var(--info-500);
  background: var(--info-50);
}

html.dark .checklist-item::before {
  background: color-mix(in srgb, var(--info-500) 18%, transparent);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* =============================================================================
   20. CHARTS
   ============================================================================= */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: clamp(16px, 3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 280px;
}

@media (min-width: 640px) {
  .chart-canvas-wrap {
    height: 320px;
  }
}

.chart-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* =============================================================================
   21. AUTH
   ============================================================================= */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 6vw, 48px);
  padding-top: calc(clamp(20px, 6vw, 48px) + var(--safe-top));
  padding-bottom: calc(clamp(20px, 6vw, 48px) + var(--safe-bottom));
  background: var(--auth-gradient);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: clamp(26px, 5vw, 40px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-pop);
  animation: auth-card-in 480ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* Nagłówek karty: tytuł + opis (neutralny, bez znaku i nazwy wykonawcy) */
.auth-head {
  display: flex;
  flex-direction: column;
}

.auth-title {
  font-size: clamp(1.4rem, 1.2rem + 1.1vw, 1.55rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
}

.auth-desc {
  margin-top: 7px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.auth-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-input);
  background: var(--danger-50);
  border: 1px solid color-mix(in srgb, var(--danger-500) 30%, transparent);
  color: var(--danger-700);
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.45;
}

html.dark .auth-error {
  background: color-mix(in srgb, var(--danger-500) 14%, transparent);
  color: var(--danger-100);
}

/* Formularz logowania */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form .btn-primary {
  margin-top: 2px;
}

/* Link „Nie pamiętam hasła" - subtelny, nie konkuruje z przyciskiem Zaloguj */
.auth-reset {
  margin-top: -4px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.auth-reset:hover {
  color: var(--text);
}

/* Łagodniejszy efekt wciśnięcia na pełnoszerokich przyciskach logowania */
.auth-form .btn-block:active {
  transform: scale(0.99);
}
.auth-reset:active {
  transform: none;
  background: var(--surface-2);
}

/* Stopka karty: subtelny branding wykonawcy */
.auth-foot {
  display: flex;
  justify-content: center;
  margin-top: 2px;
}

/* Link „Powered by FarmaPro.pl" - używany też w powłoce aplikacji */
.powered-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--slate-600);
  text-decoration: none;
  transition: color var(--transition);
}
.powered-link:hover {
  color: var(--text);
}
html.dark .powered-link {
  color: var(--slate-400);
}
html.dark .powered-link:hover {
  color: var(--slate-200);
}

.powered-logo {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

/* --- Animacje wejścia (imitacja Framer Motion: fade + slide-up + scale) --- */
@keyframes auth-card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes auth-rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger: nagłówek, pola formularza i stopka pojawiają się kolejno */
.auth-head {
  animation: auth-rise 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 70ms;
}
.auth-form > * {
  animation: auth-rise 400ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.auth-form > *:nth-child(1) { animation-delay: 120ms; }
.auth-form > *:nth-child(2) { animation-delay: 165ms; }
.auth-form > *:nth-child(3) { animation-delay: 210ms; }
.auth-form > *:nth-child(4) { animation-delay: 255ms; }
.auth-foot {
  animation: auth-rise 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 300ms;
}

/* Szacunek dla użytkowników preferujących ograniczony ruch */
@media (prefers-reduced-motion: reduce) {
  .auth-card,
  .auth-head,
  .auth-form > *,
  .auth-foot {
    animation: none !important;
  }
}

/* =============================================================================
   22. HELPERS
   ============================================================================= */
.hidden {
  display: none !important;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.scrollbar-hide {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollbar-hide::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.pt-safe {
  padding-top: var(--safe-top);
}

.pb-safe {
  padding-bottom: var(--safe-bottom);
}

/* Widoczność desktop / mobile - domyślnie mobile-first */
.desktop-only {
  display: none !important;
}

.mobile-only {
  display: revert;
}

/* =============================================================================
   23. RESPONSYWNOŚĆ
   ============================================================================= */

/* >= 900px: sidebar widoczny, dolna nawigacja ukryta, tabele zamiast kart */
@media (min-width: 900px) {
  .app-shell {
    grid-template-columns: var(--sidebar-w) 1fr;
  }

  .app-sidebar {
    display: flex;
  }

  .app-bottomnav {
    display: none;
  }

  .app-content {
    padding-bottom: calc(clamp(16px, 4vw, 32px));
  }

  .desktop-only {
    display: revert !important;
  }

  .mobile-only {
    display: none !important;
  }

  /* na desktopie pokazujemy prawdziwe tabele, ukrywamy karty mobilne */
  .table-wrap.responsive {
    display: block;
  }

  .cards-mobile.responsive {
    display: none;
  }

  .toast-root {
    bottom: calc(24px + var(--safe-bottom));
  }
}

/* < 900px: tabele „responsive" chowamy, pokazujemy karty mobilne */
@media (max-width: 899.98px) {
  .table-wrap.responsive {
    display: none;
  }

  .cards-mobile.responsive {
    display: flex;
  }

  /* Topbar na mobile pozostawia miejsce na menu/brand */
  .app-topbar {
    padding-inline: 16px;
  }
}

/* Bardzo wąskie ekrany - KPI nieco mniejsze */
@media (max-width: 380px) {
  .kpi-value {
    font-size: 1.9rem;
  }

  .inline-fields {
    grid-template-columns: 1fr;
  }
}

/* =============================================================================
   24. PRINT - czysty raport FCR
   ============================================================================= */
@media print {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #ffffff;
    --text: #000000;
    --text-muted: #444444;
    --border: #cccccc;
    --shadow-card: none;
    --shadow-card-hover: none;
    --shadow-pop: none;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  /* Ukryj elementy nawigacyjne i akcje */
  .app-sidebar,
  .app-bottomnav,
  .app-topbar,
  .app-footer,
  .btn,
  .tabs,
  .modal-backdrop,
  .toast-root,
  .nav-item,
  .bottomnav-item,
  .modal-close,
  .desktop-only,
  .mobile-only,
  .loading-overlay {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .app-content {
    max-width: none;
    padding: 0;
    gap: 16px;
    animation: none;
  }

  .card,
  .kpi,
  .chart-card,
  .table-wrap,
  .info-box {
    border: 1px solid #cccccc !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Pokaż tabele zamiast kart mobilnych w druku */
  .table-wrap.responsive {
    display: block !important;
  }

  .cards-mobile.responsive {
    display: none !important;
  }

  .table th {
    position: static;
    background: #ffffff !important;
    color: #000000 !important;
    border-bottom: 1px solid #999999 !important;
  }

  .table td {
    border-bottom: 1px solid #dddddd !important;
  }

  .table tbody tr:hover {
    background: transparent !important;
  }

  .page-title,
  .section-title,
  .card-title,
  .kpi-value {
    color: #000000 !important;
  }

  /* Stopka raportu drukowanego */
  .brand-footer,
  .print-footer {
    display: block !important;
    color: #444444 !important;
  }

  a[href]::after {
    content: "";
  }
}

/* =============================================================================
   25. DATE PICKER (własny - popover desktop / bottom-sheet mobile)
   ============================================================================= */
.date-field { position: relative; width: 100%; }

.date-field-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}
.date-field-btn .df-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date-field-btn .df-cal { flex-shrink: 0; color: var(--text-muted); }
.date-field-btn.is-placeholder .df-text { color: var(--text-muted); opacity: 0.85; }
.date-field-btn:hover { border-color: var(--slate-300); }
html.dark .date-field-btn:hover { border-color: var(--slate-600); }
.date-field-btn:focus-visible {
  outline: none;
  border-color: var(--info-500);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--info-500) 16%, transparent);
}
.date-field-btn.is-invalid { border-color: var(--danger-500); }

.dp-root { position: fixed; inset: 0; z-index: 9999; }
.dp-backdrop { position: absolute; inset: 0; }
.dp-root--sheet .dp-backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: dp-fade 160ms ease both;
}

.dp-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-pop);
  padding: 14px;
  width: 320px;
  max-width: calc(100vw - 16px);
}
.dp-root--popover .dp-panel {
  position: fixed;
  animation: dp-pop 160ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.dp-root--sheet .dp-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  width: 100%; max-width: 100%;
  border-radius: 24px 24px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  animation: dp-sheet 220ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes dp-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes dp-pop { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes dp-sheet { from { transform: translateY(100%); } to { transform: translateY(0); } }

.dp-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dp-title { font-weight: 700; font-size: 0.95rem; color: var(--text); text-align: center; flex: 1; }
.dp-nav {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 1.2rem; line-height: 1; cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), transform 80ms ease;
}
.dp-nav:hover { background: var(--surface-2); }
.dp-nav:active { transform: scale(0.95); }

.dp-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-bottom: 4px; }
.dp-weekdays span { text-align: center; font-size: 0.7rem; font-weight: 600; color: var(--text-muted); padding: 4px 0; }

.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-day {
  height: 36px; min-width: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  border-radius: 10px; font-size: 0.86rem; font-weight: 500;
  color: var(--text); font-variant-numeric: tabular-nums;
  transition: background-color var(--transition), color var(--transition), transform 80ms ease, box-shadow var(--transition);
}
.dp-day:hover { background: var(--surface-2); }
.dp-day:active { transform: scale(0.97); }
.dp-day.is-out { color: var(--text-muted); opacity: 0.45; }
.dp-day.is-today { box-shadow: inset 0 0 0 1.5px var(--info-500); color: var(--info-600); }
html.dark .dp-day.is-today { color: var(--info-500); }
.dp-day.is-selected { background: var(--primary); color: var(--primary-contrast); box-shadow: var(--shadow-card); }
.dp-day.is-selected:hover { background: var(--primary); filter: brightness(1.06); }
html.dark .dp-day.is-selected:hover { filter: brightness(0.94); }

.dp-footer { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.dp-footer .btn { flex: 1; }

/* =============================================================================
   26. SEGMENTED CONTROL (filtr Aktywne / Zakończone / Wszystkie)
   ============================================================================= */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.seg {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 7px 14px;
  min-height: 36px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background-color var(--transition), color var(--transition), transform 80ms ease;
}
.seg:hover { color: var(--text); }
.seg:active { transform: scale(0.97); }
.seg.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-card);
}
html.dark .seg.is-active { background: var(--slate-700); }

/* Na desktopie .desktop-only ma display:revert !important - przywracamy inline-flex segmentu. */
@media (min-width: 900px) {
  .segmented.desktop-only { display: inline-flex !important; }
}

/* .mobile-only ma display:revert (UA default = block) i nadpisuje display komponentu.
   Przywracamy flex tam, gdzie jest wymagany na telefonie - dolna nawigacja MUSI być
   w rzędzie (przyciski obok siebie, klikalne), a nie jeden pod drugim. */
.app-bottomnav.mobile-only { display: flex; }
.cards-mobile.mobile-only { display: flex; }

/* Selektor „Zakres danych" na Pulpicie */
.scope-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.scope-bar .label { margin: 0; }
.scope-select { max-width: 280px; }

/* Mini znaczek wykonawcy - TYLKO w stopce aplikacji, bardzo maly i dyskretny.
   Na logowaniu i w sidebarze go nie ma. */
.mini-brand {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--slate-400);
  text-decoration: none;
  transition: color var(--transition);
}
.mini-brand:hover { color: var(--slate-600); }
html.dark .mini-brand:hover { color: var(--slate-300); }
.mini-brand-logo {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

/* =============================================================================
   27. DOPRACOWANIE MOBILE PULPITU
   ============================================================================= */

/* Box "FCR szacunkowy" - skrocony z rozwijanym "Wiecej". */
.fcr-note-more {
  background: none;
  border: none;
  padding: 0;
  margin-left: 4px;
  color: var(--info-700);
  font-weight: 700;
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}
html.dark .fcr-note-more { color: var(--info-500); }
.fcr-note-full { display: block; margin-top: 4px; }

/* Mały hint pod wartością w sekcji "Koszty i wynik" (np. powód braku danych). */
.cost-hint {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Akcje na karcie aktywnej partii - Otworz primary, dwa "Dodaj" jako subtle. */
.dash-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.dash-card-actions > .btn {
  flex: 1 1 auto;
  min-height: 40px;
}
@media (max-width: 480px) {
  .dash-card-actions > .btn-primary { flex: 1 1 100%; }
  .dash-card-actions > [data-add-weighing],
  .dash-card-actions > [data-add-feed] { flex: 1 1 0; min-width: 0; }
}

/* Na desktopie nie ma dolnej nawigacji - mniejszy dolny padding. */
@media (min-width: 900px) {
  .app-content { padding-bottom: clamp(24px, 3vw, 36px); }
}

/* Kompakt mobile: KPI 2 kolumny, mniejsze paddingi/odstepy, wartosci duze ale nie przesadzone. */
@media (max-width: 640px) {
  .app-content { gap: 14px; }
  .bento { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px 13px; border-radius: 14px; }
  .kpi-value { font-size: 1.65rem; }
  .kpi-label { font-size: 0.6rem; letter-spacing: 0.06em; }
  .kpi-hint { font-size: 0.68rem; }
  .grid-2 { gap: 12px; }
  .cards-mobile { gap: 12px; }
}

@media (max-width: 640px) {
  .dp-day { height: 40px; min-width: 40px; font-size: 0.95rem; }
  .dp-weekdays span { font-size: 0.75rem; }
}
@media (prefers-reduced-motion: reduce) {
  .dp-root--popover .dp-panel,
  .dp-root--sheet .dp-panel,
  .dp-root--sheet .dp-backdrop { animation: none !important; }
}
