/* Inwentaryzacja – style aplikacji (bez frameworka, mobile-first) */
:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --border: #e2e5ea;
    --text: #1d2330;
    --muted: #667085;
    --primary: #1f6feb;
    --primary-hover: #1a5fd0;
    --primary-soft: #e7f0ff;
    --success: #12805c;
    --success-soft: #e3f6ee;
    --warning: #9a6700;
    --warning-soft: #fff4d6;
    --danger: #c9302c;
    --danger-soft: #fdecea;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1218;
        --surface: #171b23;
        --surface-2: #1d222c;
        --border: #2a303c;
        --text: #e6e9ef;
        --muted: #98a2b3;
        --primary: #4c8dff;
        --primary-hover: #6aa0ff;
        --primary-soft: #1a2740;
        --success: #3ccf91;
        --success-soft: #12291f;
        --warning: #f0b429;
        --warning-soft: #2e2512;
        --danger: #ff6b66;
        --danger-soft: #331816;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .75rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* Layout */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
    max-width: 1100px; margin: 0 auto; padding: .6rem 1rem;
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: #fff;
    display: grid; place-items: center; font-size: 14px;
}
.topnav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topnav a { padding: .35rem .65rem; border-radius: 6px; color: var(--muted); }
.topnav a.active, .topnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.container-narrow { max-width: 460px; margin: 0 auto; padding: 2.5rem 1rem; }

/* Komponenty */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.card-header h2, .card-header h3 { margin: 0; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header h1 { margin-bottom: .25rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 40px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success); border-color: var(--success); color: #fff; filter: brightness(1.12); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .3rem .6rem; min-height: 32px; font-size: .875rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.05rem; min-height: 52px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; min-height: 0; cursor: pointer; font: inherit; }
.inline { display: inline; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-draft { background: var(--surface-2); }
.badge-active { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-closed { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--primary-soft); color: var(--text); border-color: var(--border); }

/* Formularze */
.field { margin-bottom: 1rem; }
label { display: block; font-weight: 500; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=search], input[type=file], select, textarea {
    width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); font: inherit; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.checkbox { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
.checkbox input { margin-top: .3rem; width: 18px; height: 18px; }
.error { color: var(--danger); font-size: .875rem; margin-top: .25rem; }
.hint { color: var(--muted); font-size: .875rem; margin-top: .25rem; }
.form-row { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-row { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Tabele */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.row-diff td { background: var(--warning-soft); }
tr.row-deleted td { opacity: .5; text-decoration: line-through; }
.diff-plus { color: var(--success); font-weight: 600; }
.diff-minus { color: var(--danger); font-weight: 600; }

/* Statystyki */
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); margin-bottom: 1rem; }
@media (min-width: 800px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--success); }

/* Zakładki / filtry */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .85rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); font-size: .875rem; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip:hover { text-decoration: none; }

/* Lista inwentaryzacji */
.inv-list { display: grid; gap: .75rem; }
.inv-item { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.inv-item h3 { margin: 0 0 .2rem; }
.inv-meta { color: var(--muted); font-size: .875rem; display: flex; gap: .75rem; flex-wrap: wrap; }
.inv-progress { min-width: 180px; flex: 1; max-width: 260px; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.copy-box { display: flex; gap: .5rem; }
.copy-box input { font-family: ui-monospace, monospace; font-size: .85rem; }

/* Paginacja */
.pagination { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; }
.pagination a, .pagination span { padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: var(--muted); }

.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo .brand-mark { width: 48px; height: 48px; font-size: 22px; border-radius: 12px; margin: 0 auto .5rem; }
.demo-box { font-size: .875rem; }
.demo-box code { user-select: all; }

.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 2fr 1fr; } }
.mapping-grid { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .mapping-grid { grid-template-columns: repeat(3, 1fr); } }

/* ====== Ekran skanowania (telefon) ====== */
body.scan-body { background: var(--bg); }
.scan-top {
    position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border);
    padding: .5rem .75rem; display: flex; align-items: center; gap: .5rem;
}
.scan-top .title { font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-wrap { max-width: 640px; margin: 0 auto; padding: .75rem; }
.camera {
    position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
    aspect-ratio: 4 / 3; max-height: 42vh; width: 100%; margin-bottom: .75rem;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .reticle {
    position: absolute; left: 10%; right: 10%; top: 38%; height: 24%;
    border: 2px solid rgba(255, 255, 255, .85); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .25);
    pointer-events: none;
}
.camera .camera-msg {
    position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; padding: 1rem;
}
.camera.flash { animation: flash .35s; }
@keyframes flash { from { box-shadow: inset 0 0 0 6px var(--success); } to { box-shadow: inset 0 0 0 0 transparent; } }
.manual { display: flex; gap: .5rem; margin-bottom: .75rem; }
.manual input { font-size: 1.05rem; }
.product-card { border-width: 2px; }
.product-card.unknown { border-color: var(--warning); }
.product-card.found { border-color: var(--success); }
.product-name { font-size: 1.15rem; font-weight: 700; margin-bottom: .25rem; }
.product-codes { color: var(--muted); font-size: .875rem; margin-bottom: .75rem; word-break: break-all; }
.qty-row { display: flex; gap: .5rem; align-items: stretch; }
.qty-row input { font-size: 1.6rem; font-weight: 700; text-align: center; min-height: 56px; }
.qty-row .btn { min-width: 56px; font-size: 1.3rem; }
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .75rem; }
.counts div { background: var(--surface-2); border-radius: 8px; padding: .4rem .5rem; text-align: center; }
.counts strong { display: block; font-size: 1.15rem; }
.counts span { font-size: .75rem; color: var(--muted); }
.search-results { list-style: none; margin: 0 0 .75rem; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); max-height: 45vh; overflow: auto; }
.search-results li { padding: .6rem .75rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-results li:last-child { border-bottom: 0; }
.search-results li:hover { background: var(--surface-2); }
.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li { display: flex; gap: .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.entry-list .e-main { flex: 1; min-width: 0; }
.entry-list .e-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-list .e-qty { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.sync-bar {
    position: sticky; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border);
    padding: .6rem .75rem calc(.6rem + env(safe-area-inset-bottom)); display: flex; gap: .75rem; align-items: center;
}
.sync-info { flex: 1; font-size: .85rem; line-height: 1.3; }
.sync-info strong { font-size: 1rem; }
.pending-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--warning); margin-right: .35rem; }
.ok-dot { background: var(--success); }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: .75rem; }
.seg button { flex: 1; border: 0; background: var(--surface); color: var(--muted); padding: .55rem; font: inherit; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }
.toast {
    position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 50;
    background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; font-size: .9rem;
    max-width: 90vw; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.hidden { display: none !important; }

/* Na szerokim ekranie (laptop ze skanerem USB) paski trzymają szerokość treści */
.scan-top, .sync-bar { padding-left: max(.75rem, calc((100% - 640px) / 2)); padding-right: max(.75rem, calc((100% - 640px) / 2)); }
.quick-toggle { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .75rem; margin-bottom: .75rem; }
.scanner-info { border-color: var(--primary); }

/* ====== Arkusz do druku ====== */
.sheet { background: #fff; color: #000; max-width: 1000px; margin: 0 auto; padding: 1.5rem; font-size: 12px; }
.sheet h1 { font-size: 18px; text-align: center; margin-bottom: .25rem; }
.sheet table { font-size: 11px; }
.sheet th, .sheet td { border: 1px solid #999; padding: 3px 5px; color: #000; }
.sheet th { background: #eee; text-transform: none; letter-spacing: 0; font-size: 11px; }
.sheet .meta { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem 2rem; margin: 1rem 0; }
.sheet .signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; margin-top: 3rem; }
.sheet .signatures div { border-top: 1px solid #000; padding-top: .3rem; text-align: center; font-size: 11px; }
.no-print { margin: 1rem auto; max-width: 1000px; display: flex; gap: .5rem; padding: 0 1rem; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .sheet { padding: 0; max-width: none; }
    @page { size: A4; margin: 12mm; }
    tr { page-break-inside: avoid; }
}
