/* ==========================================================================
   Modern Finance — interfejs aplikacji
   Autorski system stylów (bez frameworka CSS). Fonty lokalne w fonts.css.
   ========================================================================== */

/* --- Tokeny ------------------------------------------------------------- */
:root {
    color-scheme: light;

    --font-display: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

    --bg: #f2f6fb;
    --bg-soft: #e8eef7;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eff4fa;
    --text: #0d1a2b;
    --text-strong: #071320;
    --muted: #62748d;
    --muted-2: #8a9ab1;
    --border: #e2e9f2;
    --border-strong: #cfdae7;

    --brand: #0f9e8f;
    --brand-strong: #0b7c70;
    --brand-2: #1d7fd6;
    --brand-soft: rgba(15, 158, 143, .10);
    --accent-gradient: linear-gradient(135deg, #14b8a6 0%, #1d8fd6 100%);
    --accent-gradient-soft: linear-gradient(135deg, rgba(20, 184, 166, .14), rgba(29, 143, 214, .14));

    --success: #0f9d58;
    --success-bg: rgba(15, 157, 88, .10);
    --warning: #b45309;
    --warning-bg: rgba(180, 83, 9, .10);
    --danger: #d6455d;
    --danger-bg: rgba(214, 69, 93, .10);
    --info: #1d7fd6;
    --info-bg: rgba(29, 127, 214, .10);

    --sidebar-bg: #08131f;
    --sidebar-bg-2: #0c1c2e;
    --sidebar-text: #dbe6f3;
    --sidebar-muted: #8698ad;

    --shadow-sm: 0 1px 2px rgba(13, 26, 43, .06);
    --shadow-md: 0 12px 30px rgba(13, 26, 43, .08);
    --shadow-lg: 0 28px 70px rgba(8, 19, 31, .18);

    --radius-sm: 9px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --sidebar-w: 268px;
    --topbar-h: 74px;

    --ring: 0 0 0 4px rgba(20, 184, 166, .18);
}

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

    --bg: #070d17;
    --bg-soft: #0a1421;
    --surface: #0e1828;
    --surface-2: #121f33;
    --surface-3: #16253b;
    --text: #e4ecf7;
    --text-strong: #f4f8fd;
    --muted: #93a5bc;
    --muted-2: #6e8098;
    --border: rgba(148, 163, 184, .16);
    --border-strong: rgba(148, 163, 184, .28);

    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-2: #38bdf8;
    --brand-soft: rgba(45, 212, 191, .12);
    --accent-gradient: linear-gradient(135deg, #2dd4bf 0%, #38bdf8 100%);
    --accent-gradient-soft: linear-gradient(135deg, rgba(45, 212, 191, .16), rgba(56, 189, 248, .12));

    --success: #34d399;
    --success-bg: rgba(52, 211, 153, .12);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, .12);
    --danger: #fb7185;
    --danger-bg: rgba(251, 113, 133, .12);
    --info: #38bdf8;
    --info-bg: rgba(56, 189, 248, .12);

    --sidebar-bg: #050b14;
    --sidebar-bg-2: #0a1421;
    --sidebar-text: #dbe6f3;
    --sidebar-muted: #7d8ea3;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 16px 40px rgba(0, 0, 0, .35);
    --shadow-lg: 0 32px 90px rgba(0, 0, 0, .55);
    --ring: 0 0 0 4px rgba(45, 212, 191, .22);
}

/* --- Reset -------------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 {
    font-family: var(--font-display);
    color: var(--text-strong);
    line-height: 1.2;
    letter-spacing: -.02em;
    margin: 0;
}

p { margin: 0; }

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

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

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 6px;
}

::selection { background: rgba(20, 184, 166, .28); }

.skip-link {
    position: absolute;
    left: -9999px;
    top: 10px;
    z-index: 2000;
    background: var(--surface);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}
.skip-link:focus { left: 16px; }

.noscript {
    max-width: 640px;
    margin: 60px auto;
    padding: 24px;
    border-radius: var(--radius);
    background: var(--danger-bg);
    color: var(--danger);
}

/* --- Ładowanie startowe -------------------------------------------------- */
.app-loading {
    min-height: 100vh;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 18px;
    color: var(--muted);
    text-align: center;
}

.app-loading__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    color: var(--text-strong);
}

.app-loading__spinner {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    animation: spin .8s linear infinite;
}

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

/* --- Układ aplikacji ---------------------------------------------------- */
.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}

/* --- Sidebar ------------------------------------------------------------ */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 24px 18px 20px;
    color: var(--sidebar-text);
    background:
        radial-gradient(600px 300px at 10% -10%, rgba(45, 212, 191, .16), transparent 60%),
        radial-gradient(500px 320px at 110% 10%, rgba(56, 189, 248, .12), transparent 55%),
        linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
    border-right: 1px solid rgba(148, 163, 184, .08);
    z-index: 40;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 0;
    color: var(--sidebar-text);
}

.brand:hover { text-decoration: none; }

.brand-mark {
    width: 44px;
    height: 44px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: var(--accent-gradient);
    color: #04121a;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -.03em;
    box-shadow: 0 14px 30px rgba(20, 184, 166, .28);
}

.brand-copy { display: grid; line-height: 1.2; }
.brand-copy strong {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.02em;
}
.brand-copy span {
    font-size: 11.5px;
    color: var(--sidebar-muted);
    letter-spacing: .04em;
    text-transform: uppercase;
}

.company-chip {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(148, 163, 184, .14);
    background: rgba(255, 255, 255, .035);
}

.company-chip__avatar {
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    color: #06121c;
    background: linear-gradient(135deg, #facc15, #fb923c);
}

.company-chip__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.company-chip__meta { font-size: 11.5px; color: var(--sidebar-muted); }

.nav { display: grid; gap: 4px; }
.nav__label {
    padding: 6px 12px;
    font-size: 10.5px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}

.nav__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    color: #b9c8da;
    font-size: 13.8px;
    font-weight: 500;
    transition: background .16s ease, color .16s ease, transform .16s ease;
    position: relative;
}

.nav__link:hover {
    background: rgba(255, 255, 255, .06);
    color: #f1f7ff;
    text-decoration: none;
}

.nav__link.is-active {
    background: linear-gradient(100deg, rgba(45, 212, 191, .18), rgba(56, 189, 248, .10));
    color: #ffffff;
    box-shadow: inset 0 0 0 1px rgba(94, 234, 212, .22);
}

.nav__link.is-active::before {
    content: "";
    position: absolute;
    left: -18px;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent-gradient);
}

.nav__link svg { flex: none; opacity: .9; }

.nav__badge {
    margin-left: auto;
    min-width: 22px;
    height: 20px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(45, 212, 191, .18);
    color: #7ff3e4;
    font-size: 11px;
    font-weight: 700;
}

.sidebar__footer { margin-top: auto; display: grid; gap: 12px; }

.user-card {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(148, 163, 184, .12);
}

.avatar {
    width: 38px;
    height: 38px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 12.5px;
    font-weight: 700;
    color: #06121c;
    background: linear-gradient(135deg, #5eead4, #7dd3fc);
}

.user-card__name { font-size: 13px; font-weight: 600; color: var(--sidebar-text); }
.user-card__role { font-size: 11.5px; color: var(--sidebar-muted); text-transform: capitalize; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--sidebar-muted);
    cursor: pointer;
    transition: .16s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.sidebar-note {
    font-size: 11px;
    color: var(--sidebar-muted);
    padding: 0 6px;
    line-height: 1.5;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px clamp(18px, 3vw, 36px);
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar__title { min-width: 0; }
.topbar__title h1 { font-size: clamp(19px, 2.2vw, 24px); }
.topbar__title p { color: var(--muted); font-size: 12.8px; margin-top: 2px; }

.topbar__search {
    margin-left: auto;
    position: relative;
    width: min(340px, 34vw);
}

.topbar__search input {
    width: 100%;
    height: 42px;
    padding: 0 14px 0 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    box-shadow: var(--shadow-sm);
}
.topbar__search svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted-2);
    pointer-events: none;
}

.topbar__actions { display: flex; align-items: center; gap: 9px; }

.menu-toggle { display: none; }

.content {
    padding: clamp(18px, 3vw, 34px);
    padding-top: clamp(16px, 2.4vw, 26px);
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}
.page-head h2 { font-size: clamp(20px, 2.4vw, 26px); }
.page-head p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.page-head__actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- Przyciski ---------------------------------------------------------- */
.btn {
    --btn-bg: var(--surface);
    --btn-color: var(--text);
    --btn-border: var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 15px;
    border-radius: 11px;
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--btn-color);
    font-size: 13.3px;
    font-weight: 600;
    letter-spacing: -.005em;
    cursor: pointer;
    white-space: nowrap;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
    text-decoration: none;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn svg { flex: none; }

.btn--primary {
    --btn-bg: var(--accent-gradient);
    --btn-color: #04121a;
    --btn-border: transparent;
    box-shadow: 0 12px 26px rgba(20, 184, 166, .26);
}
.btn--primary:hover { box-shadow: 0 16px 32px rgba(20, 184, 166, .32); }

.btn--ghost { --btn-bg: transparent; --btn-border: var(--border); }
.btn--ghost:hover { --btn-bg: var(--surface-2); }

.btn--soft {
    --btn-bg: var(--brand-soft);
    --btn-color: var(--brand-strong);
    --btn-border: transparent;
}
[data-theme="dark"] .btn--soft { --btn-color: var(--brand); }

.btn--danger { --btn-bg: var(--danger-bg); --btn-color: var(--danger); --btn-border: transparent; }

.btn--sm { height: 33px; padding: 0 11px; font-size: 12.3px; border-radius: 9px; }
.btn--lg { height: 46px; padding: 0 20px; font-size: 14px; border-radius: 13px; }
.btn--block { width: 100%; }
.btn--icon { width: 40px; padding: 0; }
.btn--icon.btn--sm { width: 33px; }

/* --- Karty -------------------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    min-width: 0;
}

.card--flush { padding: 0; overflow: hidden; }

.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}
.card__head h3 { font-size: 15.5px; }
.card__head p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--sidebar { grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); }
.grid--even { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

/* --- KPI ---------------------------------------------------------------- */
.kpi {
    position: relative;
    overflow: hidden;
    padding: 18px 18px 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.kpi::after {
    content: "";
    position: absolute;
    inset: auto -30px -60px auto;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: var(--accent-gradient-soft);
    opacity: .7;
    pointer-events: none;
}

.kpi__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.kpi__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .02em;
}

.kpi__icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand-strong);
}
[data-theme="dark"] .kpi__icon { color: var(--brand); }

.kpi__value {
    font-family: var(--font-display);
    font-size: clamp(22px, 2.3vw, 27px);
    font-weight: 700;
    letter-spacing: -.035em;
    color: var(--text-strong);
    line-height: 1.1;
}
.kpi__value small { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.kpi__meta {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.2px;
    color: var(--muted);
}

.kpi--accent {
    background:
        radial-gradient(420px 200px at 110% -20%, rgba(255, 255, 255, .18), transparent 60%),
        var(--accent-gradient);
    border-color: transparent;
    color: #04121a;
}
.kpi--accent .kpi__label,
.kpi--accent .kpi__meta { color: rgba(4, 18, 26, .72); }
.kpi--accent .kpi__value { color: #04121a; }
.kpi--accent .kpi__icon { background: rgba(255, 255, 255, .25); color: #04121a; }
.kpi--accent::after { display: none; }

/* --- Znaczniki / statusy ------------------------------------------------ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 23px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 11.2px;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}

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

.badge--draft { background: var(--surface-3); color: var(--muted); }
.badge--issued { background: var(--info-bg); color: var(--info); }
.badge--sent { background: rgba(124, 92, 255, .12); color: #7c5cff; }
[data-theme="dark"] .badge--sent { color: #a78bfa; }
.badge--paid { background: var(--success-bg); color: var(--success); }
.badge--overdue { background: var(--danger-bg); color: var(--danger); }
.badge--cancelled { background: var(--surface-3); color: var(--muted-2); text-decoration: line-through; }
.badge--neutral { background: var(--surface-3); color: var(--muted); }
.badge--plain::before { display: none; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11.8px;
    font-weight: 600;
}
.chip--ok { border-color: transparent; background: var(--success-bg); color: var(--success); }
.chip--warn { border-color: transparent; background: var(--warning-bg); color: var(--warning); }
.chip--bad { border-color: transparent; background: var(--danger-bg); color: var(--danger); }

/* --- Tabele ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.2px; }

.table th {
    text-align: left;
    padding: 11px 14px;
    font-size: 10.8px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted-2);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}

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

.table tbody tr { transition: background .14s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .strong { font-weight: 600; color: var(--text-strong); }
.table .sub { display: block; font-size: 11.8px; color: var(--muted); margin-top: 2px; }
.table__actions { display: flex; gap: 5px; justify-content: flex-end; }

.table--compact td { padding: 9px 12px; }
.table--compact th { padding: 8px 12px; }

.row-link { cursor: pointer; }

/* --- Formularze --------------------------------------------------------- */
.field { display: grid; gap: 6px; min-width: 0; }

.field > label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .01em;
}

.field .hint { font-size: 11.5px; color: var(--muted-2); }

.input,
.select,
.textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 11px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13.6px;
    transition: border-color .15s ease, box-shadow .15s ease;
}

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

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

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 34px;
}

.textarea { min-height: 84px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.form-grid--3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.field--full { grid-column: 1 / -1; }

.form-section { margin: 22px 0 14px; }
.form-section h4 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted-2);
    margin-bottom: 12px;
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 13.2px;
    color: var(--text);
    cursor: pointer;
}
.checkbox input {
    width: 17px;
    height: 17px;
    accent-color: var(--brand);
}

.form-error {
    margin-top: 12px;
    padding: 10px 13px;
    border-radius: 10px;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 12.5px;
}

.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 3px;
    border-radius: 11px;
    background: var(--surface-3);
    border: 1px solid var(--border);
}
.segmented button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.segmented button.is-active {
    background: var(--surface);
    color: var(--text-strong);
    box-shadow: var(--shadow-sm);
}

/* --- Edytor pozycji ----------------------------------------------------- */
.items-editor { display: grid; gap: 8px; }
.items-editor__head,
.items-editor__row {
    display: grid;
    grid-template-columns: minmax(180px, 2.4fr) 86px 76px 108px 92px 116px 36px;
    gap: 8px;
    align-items: center;
}
.items-editor__head {
    font-size: 10.6px;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted-2);
    font-weight: 700;
    padding: 0 2px;
}
.items-editor__row .input,
.items-editor__row .select { min-height: 36px; font-size: 13px; padding: 7px 9px; }
.items-editor__row .amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-strong);
    padding-right: 4px;
}
.items-editor__row .remove {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--danger-bg);
    color: var(--danger);
    cursor: pointer;
}

.items-editor__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.totals-box {
    margin-left: auto;
    min-width: 250px;
    display: grid;
    gap: 6px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.totals-box__row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    font-size: 13px;
    color: var(--muted);
}
.totals-box__row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.totals-box__row--total {
    padding-top: 8px;
    border-top: 1px dashed var(--border-strong);
    font-size: 15px;
    color: var(--text-strong);
}
.totals-box__row--total strong { font-family: var(--font-display); font-size: 18px; letter-spacing: -.02em; }

/* --- Filtry ------------------------------------------------------------- */
.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}
.filters .input, .filters .select { height: 38px; min-height: 38px; font-size: 13px; }
.filters .search { flex: 1 1 240px; }
.filters__group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* --- Pasek postępu ------------------------------------------------------ */
.progress {
    position: relative;
    height: 8px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
}
.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent-gradient);
    transition: width .4s ease;
}
.progress.is-warn > span { background: linear-gradient(135deg, #fbbf24, #f97316); }
.progress.is-bad > span { background: linear-gradient(135deg, #fb7185, #ef4444); }

/* --- Wykresy ------------------------------------------------------------ */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart__tooltip {
    position: fixed;
    z-index: 300;
    padding: 7px 10px;
    border-radius: 9px;
    background: var(--text-strong);
    color: var(--surface);
    font-size: 11.5px;
    font-weight: 600;
    pointer-events: none;
    transform: translate(-50%, -130%);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    opacity: 0;
    transition: opacity .12s ease;
}
.chart__tooltip.is-visible { opacity: 1; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.legend__dot { width: 9px; height: 9px; border-radius: 3px; }

.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 148px; height: 148px; flex: none; }
.donut-legend { display: grid; gap: 9px; min-width: 140px; flex: 1; }
.donut-legend__row { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--muted); }
.donut-legend__row strong { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.donut-legend__dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* --- Listy -------------------------------------------------------------- */
.list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.list__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 8px;
    border-radius: 10px;
    border-bottom: 1px dashed var(--border);
}
.list__item:last-child { border-bottom: 0; }
.list__item:hover { background: var(--surface-2); }
.list__main { min-width: 0; flex: 1; }
.list__title {
    font-size: 13.4px;
    font-weight: 600;
    color: var(--text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.list__meta { font-size: 11.8px; color: var(--muted); margin-top: 2px; }
.list__value { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13.4px; text-align: right; }
.list__value small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }

.avatar-stack { display: flex; }
.avatar-stack .avatar { width: 30px; height: 30px; font-size: 10.5px; border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* --- Puste stany / szkielety ------------------------------------------- */
.empty {
    display: grid;
    justify-items: center;
    text-align: center;
    gap: 8px;
    padding: 46px 20px;
    color: var(--muted);
}
.empty__icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: var(--brand-soft);
    color: var(--brand-strong);
    margin-bottom: 4px;
}
[data-theme="dark"] .empty__icon { color: var(--brand); }
.empty h3 { font-size: 16px; }
.empty p { font-size: 13px; max-width: 420px; }

.skeleton {
    border-radius: 8px;
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skeleton-line { height: 12px; margin: 8px 0; }
.skeleton-card { height: 96px; border-radius: var(--radius-lg); }

.spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    animation: spin .7s linear infinite;
    display: inline-block;
}

/* --- Modale ------------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(5, 14, 24, .55);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    padding: 20px;
    animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal {
    width: min(720px, 100%);
    max-height: min(88vh, 940px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: pop .18s ease;
    overflow: hidden;
}
@keyframes pop { from { transform: translateY(12px) scale(.985); opacity: 0; } }

.modal--lg { width: min(980px, 100%); }
.modal--sm { width: min(440px, 100%); }

.modal__head {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--border);
}
.modal__head h3 { font-size: 18px; }
.modal__head p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.modal__head .icon-btn { margin-left: auto; color: var(--muted); flex: none; border-radius: 10px; }
.modal__head .icon-btn:hover { background: var(--surface-3); color: var(--text); }

.modal__body { padding: 20px 22px; overflow-y: auto; }
.modal__foot {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    flex-wrap: wrap;
}
.modal__foot .spacer { margin-right: auto; }

/* --- Toasty ------------------------------------------------------------- */
.toasts {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 200;
    display: grid;
    gap: 10px;
    width: min(380px, calc(100vw - 40px));
}
.toast {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 13px 15px;
    border-radius: 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    animation: slide-in .2s ease;
}
@keyframes slide-in { from { transform: translateY(10px); opacity: 0; } }
.toast.is-error { border-color: rgba(214, 69, 93, .35); }
.toast__icon { flex: none; margin-top: 1px; }
.toast.is-success .toast__icon { color: var(--success); }
.toast.is-error .toast__icon { color: var(--danger); }
.toast.is-info .toast__icon { color: var(--info); }
.toast__text { flex: 1; }
.toast__title { font-weight: 600; color: var(--text-strong); }
.toast__msg { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.toast__close { border: 0; background: transparent; color: var(--muted-2); cursor: pointer; padding: 2px; }

/* --- Logowanie ---------------------------------------------------------- */
.login {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
}

.login__visual {
    position: relative;
    overflow: hidden;
    padding: clamp(32px, 5vw, 64px);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 40px;
    color: #eaf5ff;
    background:
        radial-gradient(900px 500px at 20% 0%, rgba(45, 212, 191, .25), transparent 55%),
        radial-gradient(700px 500px at 100% 100%, rgba(56, 189, 248, .22), transparent 55%),
        linear-gradient(150deg, #07131f, #0a1e30 55%, #071a2a);
}

.login__visual::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(148, 163, 184, .07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, .07) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(70% 60% at 30% 40%, #000 20%, transparent 100%);
    pointer-events: none;
}

.login__visual .brand { position: relative; z-index: 2; color: #f0f8ff; }
.login__visual .brand-copy span { color: #93b0c8; }

.login__pitch { position: relative; z-index: 2; max-width: 520px; }
.login__pitch h2 {
    color: #f5fbff;
    font-size: clamp(28px, 3.4vw, 42px);
    line-height: 1.08;
    letter-spacing: -.04em;
}
.login__pitch p { color: #a8c1d6; margin-top: 16px; font-size: 15px; max-width: 440px; }

.login__stats {
    position: relative;
    z-index: 2;
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
}
.login__stat strong {
    display: block;
    font-family: var(--font-display);
    font-size: 24px;
    letter-spacing: -.03em;
    color: #ffffff;
}
.login__stat span { font-size: 11.5px; color: #8fa9bf; letter-spacing: .04em; text-transform: uppercase; }

.login__badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid rgba(94, 234, 212, .28);
    background: rgba(45, 212, 191, .10);
    color: #7ff3e4;
    font-size: 11.8px;
    font-weight: 600;
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
    width: fit-content;
}

.login__form-wrap {
    display: grid;
    place-items: center;
    padding: clamp(24px, 4vw, 56px);
    background: var(--surface);
}

.login__form { width: min(400px, 100%); }
.login__form h1 { font-size: 27px; letter-spacing: -.035em; }
.login__form > p { color: var(--muted); font-size: 13.8px; margin-top: 7px; margin-bottom: 26px; }
.login__form .field { margin-bottom: 14px; }
.login__form .btn { margin-top: 8px; }

.login__hint {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    font-size: 11.8px;
    color: var(--muted);
    line-height: 1.55;
}
.login__hint code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

.login__foot {
    margin-top: 26px;
    font-size: 11.6px;
    color: var(--muted-2);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

/* --- Detale faktury ----------------------------------------------------- */
.invoice-head {
    display: flex;
    justify-content: space-between;
    gap: 22px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}
.invoice-head__number { font-family: var(--font-display); font-size: 22px; letter-spacing: -.03em; }
.invoice-head__meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.invoice-head__amount { text-align: right; }
.invoice-head__amount strong {
    display: block;
    font-family: var(--font-display);
    font-size: clamp(24px, 3vw, 31px);
    letter-spacing: -.04em;
}
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 18px 0; }
.party { padding: 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.party__label { font-size: 10.6px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted-2); font-weight: 700; margin-bottom: 6px; }
.party__name { font-weight: 600; color: var(--text-strong); font-size: 13.8px; }
.party__meta { font-size: 12.2px; color: var(--muted); line-height: 1.5; margin-top: 3px; }

.timeline { display: grid; gap: 0; margin-top: 6px; }
.timeline__item { display: flex; gap: 12px; padding: 9px 0; }
.timeline__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border-strong);
    margin-top: 5px;
    flex: none;
    position: relative;
}
.timeline__item.is-done .timeline__dot { background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.timeline__body { font-size: 12.4px; color: var(--muted); }
.timeline__body strong { color: var(--text); font-weight: 600; }

.kv { display: grid; gap: 8px; }
.kv__row { display: flex; justify-content: space-between; gap: 14px; font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.kv__row:last-child { border-bottom: 0; }
.kv__row span:first-child { color: var(--muted); }
.kv__row span:last-child { font-weight: 600; text-align: right; }
.kv__row .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.8px; }

/* --- Sekcje informacyjne ------------------------------------------------ */
.notice {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12.8px;
    color: var(--muted);
    line-height: 1.55;
}
.notice svg { flex: none; margin-top: 1px; color: var(--info); }
.notice strong { color: var(--text); }
.notice--warn { background: var(--warning-bg); border-color: transparent; color: var(--warning); }
.notice--warn svg { color: var(--warning); }
.notice--error { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.notice--error svg { color: var(--danger); }
.notice--success { background: var(--success-bg); border-color: transparent; color: var(--success); }
.notice--success svg { color: var(--success); }

/* --- Zakładki ----------------------------------------------------------- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13.2px;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: 10px 10px 0 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    white-space: nowrap;
    transition: color .16s ease, background .16s ease;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.is-active { color: var(--text-strong); border-bottom-color: var(--accent); }
.tab svg { flex: none; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell .sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.code-block {
    margin: 0;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.8px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
}

.spinner--lg { width: 30px; height: 30px; border-width: 3px; margin: 0 auto; display: block; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

.muted { color: var(--muted); }
.tiny { font-size: 11.6px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex-center { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* --- Paginacja ---------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 4px 2px;
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--muted);
}
.pagination__buttons { display: flex; gap: 6px; }

/* --- Druk --------------------------------------------------------------- */
.print-area { display: none; }

@media print {
    @page { size: A4; margin: 16mm; }
    body { background: #fff !important; color: #000 !important; }
    .shell, .toasts, .modal-backdrop, .skip-link, #modal-root { display: none !important; }
    .print-area { display: block !important; font-family: "Inter", Arial, sans-serif; color: #000; }
    .print-area h1 { font-size: 22pt; margin: 0 0 4mm; }
    .print-area .print-head { display: flex; justify-content: space-between; gap: 10mm; margin-bottom: 8mm; }
    .print-area .print-box { border: 1px solid #ccc; padding: 4mm; border-radius: 2mm; flex: 1; }
    .print-area table { width: 100%; border-collapse: collapse; font-size: 9pt; margin-top: 6mm; }
    .print-area th, .print-area td { border-bottom: 1px solid #ddd; padding: 2.4mm 2mm; text-align: left; }
    .print-area td.num, .print-area th.num { text-align: right; }
    .print-area .print-totals { margin-top: 6mm; display: flex; justify-content: flex-end; }
    .print-area .print-totals table { width: 70mm; margin: 0; }
    .print-area .print-foot { margin-top: 12mm; font-size: 8pt; color: #555; border-top: 1px solid #ddd; padding-top: 3mm; }
}

/* --- Responsywność ------------------------------------------------------ */
@media (max-width: 1180px) {
    .grid--sidebar { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
    .login { grid-template-columns: 1fr; }
    .login__visual { display: none; }
    .login__form-wrap { min-height: 100vh; }
    .items-editor__head { display: none; }
    .items-editor__row {
        grid-template-columns: 1fr 1fr;
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface-2);
    }
    .items-editor__row .input--name { grid-column: 1 / -1; }
    .items-editor__row .remove { justify-self: end; }
}

@media (max-width: 880px) {
    :root { --sidebar-w: 0px; }

    .shell { grid-template-columns: 1fr; }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 286px;
        transform: translateX(-102%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
    }
    .shell.is-nav-open .sidebar { transform: translateX(0); }
    .shell.is-nav-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(5, 14, 24, .5);
        z-index: 35;
    }

    .menu-toggle {
        display: inline-grid;
        place-items: center;
        width: 40px;
        height: 40px;
        border-radius: 11px;
        border: 1px solid var(--border);
        background: var(--surface);
        color: var(--text);
        cursor: pointer;
        flex: none;
    }

    .topbar__search { display: none; }
    .topbar { gap: 12px; }
    .topbar__actions { margin-left: auto; }
    .content { padding-bottom: 90px; }
}

@media (max-width: 640px) {
    .page-head { align-items: flex-start; }
    .page-head__actions { width: 100%; }
    .page-head__actions .btn { flex: 1; }
    .kpi { padding: 15px; }
    .card { padding: 16px; border-radius: 16px; }
    .modal { border-radius: 18px; max-height: 94vh; }
    .modal__body { padding: 16px; }
    .modal__head, .modal__foot { padding: 15px 16px; }
    .invoice-parties { grid-template-columns: 1fr; }
    .invoice-head__amount { text-align: left; }
    .items-editor__row { grid-template-columns: 1fr 1fr; }
    .grid--4 { grid-template-columns: 1fr; }
    .filters .search { flex-basis: 100%; }
    .filters__group { width: 100%; }
    .filters__group .select, .filters__group .input { flex: 1; }
    .totals-box { width: 100%; margin-left: 0; }
    .login__form-wrap { padding: 24px 18px; }
    .toasts { right: 12px; left: 12px; bottom: 12px; width: auto; }
}

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

/* --- Elementy powłoki aplikacji ----------------------------------------- */
.nav__group { display: grid; gap: 4px; }

.topbar .icon-btn {
    border-color: var(--border);
    background: var(--surface);
    color: var(--muted);
}
.topbar .icon-btn:hover { background: var(--surface-2); color: var(--text); }

.view-loading {
    display: grid;
    place-items: center;
    min-height: 260px;
    color: var(--muted);
}

.password-field { position: relative; }
.password-field .input { padding-right: 44px; }
.password-field__toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted-2);
    cursor: pointer;
}
.password-field__toggle:hover { color: var(--text); background: var(--surface-2); }
