/* CSS Variables - Design System
 * Source: .mockups/kalkulator-v2/css/tokens.css (decision D18), including the contrast
 * proposals block (AA verified in .mockups/kalkulator-v2/tests/contrast.mjs).
 * Dark theme: :root[data-theme="dark"], set by js/theme.js before first paint. */
:root {
    /* Colors - Primary (Indigo - Stitch brand) */
    --color-primary-50: #eef2ff;
    --color-primary-100: #e0e7ff;
    --color-primary-200: #c7d2fe;
    --color-primary-300: #a5b4fc;
    --color-primary-400: #818cf8;
    --color-primary-500: #6366f1;
    --color-primary-600: #4f46e5;
    --color-primary-700: #4338ca;
    --color-primary-800: #3730a3;
    --color-primary-900: #312e81;

    /* Colors - Accent (Orange - revenue/highlight) */
    --color-accent-50: #fff7ed;
    --color-accent-100: #ffedd5;
    --color-accent-500: #f97316;
    --color-accent-600: #ea580c;

    /* Colors - Gray */
    --color-gray-50: #f9fafb;
    --color-gray-100: #f3f4f6;
    --color-gray-200: #e5e7eb;
    --color-gray-300: #d1d5db;
    --color-gray-400: #9ca3af;
    --color-gray-500: #6b7280;
    --color-gray-600: #4b5563;
    --color-gray-700: #374151;
    --color-gray-800: #1f2937;
    --color-gray-900: #111827;

    /* Colors - Success */
    --color-success-50: #ecfdf5;
    --color-success-100: #d1fae5;
    --color-success-500: #10b981;
    --color-success-600: #059669;
    --color-success-700: #047857;

    /* Colors - Warning */
    --color-warning-50: #fffbeb;
    --color-warning-100: #fef3c7;
    --color-warning-500: #f59e0b;
    --color-warning-600: #d97706;

    /* Colors - Danger */
    --color-danger-50: #fef2f2;
    --color-danger-100: #fee2e2;
    --color-danger-500: #ef4444;
    --color-danger-600: #dc2626;
    --color-danger-700: #b91c1c;

    /* Colors - Orange (for costs) */
    --color-orange-50: #fff7ed;
    --color-orange-100: #ffedd5;
    --color-orange-200: #fed7aa;
    --color-orange-500: #f97316;
    --color-orange-600: #ea580c;

    /* Colors - Purple (for fixed costs) */
    --color-purple-50: #faf5ff;
    --color-purple-100: #f3e8ff;
    --color-purple-200: #e9d5ff;
    --color-purple-500: #a855f7;
    --color-purple-600: #9333ea;

    /* Colors - Emerald (for income card) */
    --color-emerald-50: #ecfdf5;
    --color-emerald-100: #d1fae5;
    --color-emerald-200: #a7f3d0;
    --color-emerald-500: #10b981;
    --color-emerald-600: #059669;

    /* Colors - Cyan (for sales summary) */
    --color-cyan-50: #ecfeff;
    --color-cyan-100: #cffafe;
    --color-cyan-200: #a5f3fc;
    --color-cyan-500: #06b6d4;
    --color-cyan-600: #0891b2;

    /* Colors - Amber (for purchases summary) */
    --color-amber-50: #fffbeb;
    --color-amber-100: #fef3c7;
    --color-amber-200: #fde68a;
    --color-amber-500: #f59e0b;
    --color-amber-600: #d97706;

    /* Colors - Rose (for VAT) */
    --color-rose-50: #fff1f2;
    --color-rose-100: #ffe4e6;
    --color-rose-200: #fecdd3;
    --color-rose-500: #f43f5e;
    --color-rose-600: #e11d48;

    /* Colors - Slate (for tax summary) */
    --color-slate-50: #f8fafc;
    --color-slate-100: #f1f5f9;
    --color-slate-200: #e2e8f0;
    --color-slate-500: #64748b;
    --color-slate-600: #475569;
    --color-slate-700: #334155;

    /* Colors - Lime (for profit) */
    --color-lime-50: #f7fee7;
    --color-lime-100: #ecfccb;
    --color-lime-200: #d9f99d;
    --color-lime-500: #84cc16;
    --color-lime-600: #65a30d;
    --color-lime-700: #4d7c0f;

    /* Colors - Indigo (for summary card) */
    --color-indigo-50: #eef2ff;
    --color-indigo-100: #e0e7ff;
    --color-indigo-200: #c7d2fe;
    --color-indigo-500: #6366f1;
    --color-indigo-600: #4f46e5;
    --color-indigo-700: #4338ca;

    /* Semantic Colors */
    --color-bg: #f1f5f9;
    --color-bg-card: #ffffff;
    --color-bg-subtle: #f8fafc;
    --color-text: #0f172a;
    --color-text-secondary: #475569;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;

    /* Typography - Apple-style with Inter */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    --font-family-heading: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;

    --font-size-xs: 0.75rem;    /* 12px */
    --font-size-sm: 0.8125rem;  /* 13px - Apple uses 13px often */
    --font-size-base: 0.9375rem; /* 15px - Apple's preferred body size */
    --font-size-lg: 1.0625rem;  /* 17px */
    --font-size-xl: 1.25rem;    /* 20px */
    --font-size-2xl: 1.5rem;    /* 24px */
    --font-size-3xl: 2rem;      /* 32px */

    --font-weight-light: 300;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.2;
    --line-height-normal: 1.47;  /* Apple's preferred line height */
    --line-height-relaxed: 1.6;

    /* Letter spacing - Apple style */
    --letter-spacing-tight: -0.022em;
    --letter-spacing-normal: -0.016em;
    --letter-spacing-wide: 0.02em;

    /* Spacing */
    --spacing-0: 0;
    --spacing-1: 0.25rem;
    --spacing-2: 0.5rem;
    --spacing-3: 0.75rem;
    --spacing-4: 1rem;
    --spacing-5: 1.25rem;
    --spacing-6: 1.5rem;
    --spacing-8: 2rem;
    --spacing-10: 2.5rem;
    --spacing-12: 3rem;
    --spacing-16: 4rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;
    --radius-2xl: 1rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -1px rgb(0 0 0 / 0.03);
    --shadow-card-hover: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -2px rgb(0 0 0 / 0.04);

    /* Card-specific radius (Stitch rounded-2xl) */
    --radius-card: 1rem;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Z-Index */
    --z-dropdown: 100;
    --z-modal-backdrop: 200;
    --z-modal: 300;
    --z-tooltip: 400;

    /* Layout */
    --header-height: 64px;
    --sidebar-width: 240px;
    --sidebar-width-mobile: 280px;
    --content-max-width: 1400px;
}

/* Dark mode - toggled via JS class on <html> */
:root[data-theme="dark"] {
    /* Semantic Colors */
    --color-bg: #0f172a;
    --color-bg-card: #1e293b;
    --color-bg-subtle: #273449;
    --color-text: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --color-border-light: #2b3a50;

    /* Gray palette (inverted) */
    --color-gray-50: #1e293b;
    --color-gray-100: #334155;
    --color-gray-200: #475569;
    --color-gray-300: #64748b;
    --color-gray-400: #94a3b8;
    --color-gray-500: #cbd5e1;
    --color-gray-600: #e2e8f0;
    --color-gray-700: #f1f5f9;
    --color-gray-800: #f8fafc;
    --color-gray-900: #ffffff;

    /* Shadows for dark mode */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.2);

    /* Colors - Primary (Indigo - brighter for dark bg) */
    --color-primary-50: #1e1b4b;
    --color-primary-100: #312e81;
    --color-primary-200: #4338ca;
    --color-primary-300: #6366f1;
    --color-primary-400: #818cf8;
    --color-primary-500: #818cf8;
    --color-primary-600: #a5b4fc;
    --color-primary-700: #c7d2fe;

    /* Colors - Accent (Orange - dark mode) */
    --color-accent-50: #431407;
    --color-accent-100: #7c2d12;
    --color-accent-500: #fb923c;
    --color-accent-600: #fdba74;

    /* Card shadows - subtle in dark mode */
    --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -1px rgb(0 0 0 / 0.2);
    --shadow-card-hover: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -2px rgb(0 0 0 / 0.3);

    /* Colors - Success */
    --color-success-50: #052e16;
    --color-success-100: #065f46;
    --color-success-500: #34d399;
    --color-success-600: #6ee7b7;

    /* Colors - Danger */
    --color-danger-50: #450a0a;
    --color-danger-100: #7f1d1d;
    --color-danger-500: #f87171;
    --color-danger-600: #fca5a5;

    /* Colors - Warning */
    --color-warning-50: #451a03;
    --color-warning-100: #78350f;
    --color-warning-500: #fbbf24;
    --color-warning-600: #fcd34d;

    /* Colors - Emerald */
    --color-emerald-50: #052e16;
    --color-emerald-100: #065f46;
    --color-emerald-200: #059669;
    --color-emerald-500: #34d399;
    --color-emerald-600: #6ee7b7;

    /* Colors - Cyan */
    --color-cyan-50: #083344;
    --color-cyan-100: #0e4d5e;
    --color-cyan-200: #0891b2;
    --color-cyan-500: #22d3ee;
    --color-cyan-600: #67e8f9;

    /* Colors - Amber */
    --color-amber-50: #451a03;
    --color-amber-100: #78350f;
    --color-amber-200: #d97706;
    --color-amber-500: #fbbf24;
    --color-amber-600: #fcd34d;

    /* Colors - Rose */
    --color-rose-50: #4c0519;
    --color-rose-100: #881337;
    --color-rose-200: #e11d48;
    --color-rose-500: #fb7185;
    --color-rose-600: #fda4af;

    /* Colors - Orange */
    --color-orange-50: #431407;
    --color-orange-100: #7c2d12;
    --color-orange-200: #ea580c;
    --color-orange-500: #fb923c;
    --color-orange-600: #fdba74;

    /* Colors - Purple */
    --color-purple-50: #2e1065;
    --color-purple-100: #4c1d95;
    --color-purple-200: #7c3aed;
    --color-purple-500: #c084fc;
    --color-purple-600: #d8b4fe;

    /* Colors - Slate */
    --color-slate-50: #1e293b;
    --color-slate-100: #334155;
    --color-slate-200: #475569;
    --color-slate-500: #94a3b8;
    --color-slate-600: #cbd5e1;
    --color-slate-700: #e2e8f0;

    /* Colors - Lime */
    --color-lime-50: #1a2e05;
    --color-lime-100: #365314;
    --color-lime-200: #4d7c0f;
    --color-lime-500: #a3e635;
    --color-lime-600: #bef264;
    --color-lime-700: #d9f99d;

    /* Colors - Indigo */
    --color-indigo-50: #1e1b4b;
    --color-indigo-100: #312e81;
    --color-indigo-200: #4338ca;
    --color-indigo-500: #818cf8;
    --color-indigo-600: #a5b4fc;
    --color-indigo-700: #c7d2fe;
}



/* ==========================================================================
   Contrast and layout tokens from mockup v2 (PROPOZYCJE)
   Uzasadnienie liczbowe: tests/contrast.mjs (WCAG 2.x, AA = 4.5:1 tekst, 3:1 grafika)
   ========================================================================== */
:root {
    /* 1. Tekst przyciszony: #64748b dawał 4,34:1 na --color-bg (#f1f5f9) → AA nie przechodzi. */
    --color-text-muted: #5b6b82;                 /* 4,95:1 na tle strony, 5,2:1 na kartach */

    /* 2. Brakujące stopnie -700 (jasny tekst na jasnym tle statusu: 600 daje 3,1–4,4:1) */
    --color-amber-700: #b45309;
    --color-orange-700: #c2410c;

    /* 3. Statusy semantyczne (płatność, KSeF, dopasowanie bankowe): para tło + tekst z AA */
    --status-success-bg: var(--color-success-50);  --status-success-fg: var(--color-success-700);
    --status-warning-bg: var(--color-warning-50);  --status-warning-fg: var(--color-amber-700);
    --status-danger-bg:  var(--color-danger-50);   --status-danger-fg:  var(--color-danger-700);
    --status-info-bg:    var(--color-primary-50);  --status-info-fg:    var(--color-primary-700);
    --status-neutral-bg: var(--color-slate-100);   --status-neutral-fg: var(--color-slate-600);
    --status-accent-bg:  var(--color-orange-50);   --status-accent-fg:  var(--color-orange-700);

    /* 4. Wykres: pomarańcz #f97316 ma 2,8:1 na białym (< 3:1 dla grafiki) → ciemniejszy odcień słupków */
    --chart-revenue: #ea580c;                    /* 3,56:1 */
    --chart-costs: var(--color-primary-500);     /* 4,47:1 */

    /* 5. Nowe tokeny układu i interakcji */
    --focus-ring: 0 0 0 3px rgb(99 102 241 / 0.45);
    --overlay: rgb(15 23 42 / 0.55);
    --font-size-2xs: 0.6875rem;                  /* 11px: nagłówki tabel, meta */
    --table-row-h: 3.25rem;
    --drawer-width: 40rem;
    --bottom-nav-h: 4rem;
    --sidebar-rail-width: 4.5rem;                /* tablet: wąski pasek z ikonami */

    /* 6. Przycisk główny: w trybie ciemnym --color-primary-600 jest jasny (#a5b4fc), biały tekst miałby 1,8:1 */
    --btn-primary-bg: #4f46e5;                   /* biały tekst: 6,29:1 */
    --btn-primary-bg-hover: #4338ca;
    --btn-primary-fg: #ffffff;
    --btn-danger-bg: #b91c1c;                    /* biały tekst: 6,47:1 */

    /* 7. Rodzaj wydatku „środek trwały” (obok TH = info i KF = accent): fiolet z kontrastem AA */
    --color-purple-700: #7e22ce;
    --status-asset-bg: var(--color-purple-50);   --status-asset-fg: var(--color-purple-700);

    /* 8. Kolory podkategorii KF (kropki, słupki, udziały): grafika >= 3:1 na karcie; znaczenie zawsze podaje też etykieta */
    --kf-1: #4f46e5; --kf-2: #ea580c; --kf-3: #059669; --kf-4: #e11d48; --kf-5: #0891b2; --kf-6: #b45309; --kf-7: #64748b;
}
:root[data-theme="dark"] {
    --status-success-fg: var(--color-success-600);
    --status-warning-fg: var(--color-warning-600);
    --status-danger-fg: var(--color-danger-600);
    --status-info-fg: var(--color-primary-600);
    --status-neutral-bg: var(--color-slate-100);
    --status-neutral-fg: var(--color-slate-600);
    --status-accent-fg: var(--color-orange-600);
    --chart-revenue: #fb923c;
    --focus-ring: 0 0 0 3px rgb(165 180 252 / 0.55);
    --color-purple-700: #e9d5ff;
    --kf-1: #818cf8; --kf-2: #fb923c; --kf-3: #34d399; --kf-4: #fb7185; --kf-5: #22d3ee; --kf-6: #fbbf24; --kf-7: #94a3b8;
}

/* Native form controls and scrollbars follow the theme */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* Shell tokens */
:root {
    --shell-pad: var(--spacing-6);
    --notification-max-h: 50vh;
}

/* One UI standard (DESIGN.md, #105): component sizes, radii and inner paddings.
   Layout spacing in the tab stylesheets uses only --spacing-1 … --spacing-6 (+ 8/10/12 for page bottom and empty states). */
:root {
    --control-h: 40px;
    --control-h-sm: 32px;
    --control-h-touch: 40px;          /* the mockup keeps 40 px controls on the phone (D28) */
    --chip-h: 34px;
    --segment-btn-h: 36px;
    --badge-h: 20px;
    --pill-h: auto;                   /* mockup: 3 px padding + 12 px x 1.4 line = 22.8 px */
    --count-h: 1.4rem;                /* chip / filter-button counter (mockup .quick__count) */
    --btn-icon: 1.1rem;               /* icon inside a button (mockup components.css) */
    --tile-pad: var(--spacing-2) var(--spacing-4);
    --tile-pad-phone: var(--spacing-2) var(--spacing-3);
    --tile-label-font-phone: 9px;     /* wg makiety, decyzja D28 */
    --radius-tile: 14px;
    --page-header-h: 86px;
    --context-bar-h: 53px;            /* 40 px button + 12 px padding + 1 px border */
    --content-pad-top: var(--spacing-5);
    --control-font: var(--font-size-sm);
    --field-font: var(--font-size-base); /* mockup fields inherit the 15 px body font */
    --th-pad: 10px 12px;
    --td-pad: 12px;
    --td-pad-dense: 8px 12px;
    --badge-pad-x: 7px;
    --pill-pad: 3px 10px;
    --field-gap: 6px;
    --radius-control: 10px;
    --radius-sheet: 20px;
    --font-size-kpi: 1.875rem;
    --drawer-width: 40rem;
    /* Edge shadow of horizontal scroll containers; follows the theme through --color-text */
    --scroll-shadow: color-mix(in srgb, var(--color-text) 25%, transparent);
}
/* Wide screens: the sidebar narrows to 14rem, as in the mockup (views-b.css) */
@media (min-width: 1100px) { :root { --sidebar-width: 14rem; } }
@media (max-width: 767px) {
    :root {
        --page-header-h: auto;          /* phone: 16 px + content + 8 px, as in the mockup */
        --content-pad-top: var(--spacing-4);
        /* Phone: controls keep the desktop 40 px / 13 px and fields 15 px, as in the mockup (D28) */
    }
}
