/* ============================================================
   Inwentaryzacja v2 — styl ciemny, komputer + tablet
   ============================================================ */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --bg: #0e131a;
  --bg-2: #121821;
  --card: #1a222c;
  --card-2: #151c25;
  --ink: #e6edf3;
  --muted: #9aa7b4;
  --line: #2a3542;
  --line-soft: #222c37;
  --gold: #c9a227;
  --gold-2: #e0b93a;
  --gold-ink: #14181d;
  --ok: #3fb950;
  --ok-bg: rgba(63, 185, 80, .14);
  --miss: #f85149;
  --miss-bg: rgba(248, 81, 73, .14);
  --extra: #d29922;
  --extra-bg: rgba(210, 153, 34, .16);
  --pend: #8b949e;
  --pend-bg: rgba(139, 148, 158, .15);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .25);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, .3);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(201, 162, 39, .08), transparent 60%),
    radial-gradient(900px 450px at 0% 0%, rgba(63, 185, 80, .05), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(22px, 3vw, 30px); line-height: 1.15; margin-bottom: 6px; letter-spacing: -.02em; }
h2 { font-size: 18px; margin-bottom: 8px; }
h3 { font-size: 15px; margin-bottom: 8px; }
a { color: var(--gold-2); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 16, 22, .94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--gold-2), #a9861b);
  color: #151a20;
  box-shadow: 0 3px 12px rgba(201, 162, 39, .28);
  flex: 0 0 auto;
}
.brand-mark svg { width: 23px; height: 23px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 17px; letter-spacing: -.01em; }
.brand-text small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.sync {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(63, 185, 80, .12); }
.sync.offline .dot { background: var(--miss); box-shadow: 0 0 0 3px rgba(248, 81, 73, .12); }
.sync.saving .dot { background: var(--extra); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- layout ---------- */
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 18px calc(60px + env(safe-area-inset-bottom));
}
.view { animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.crumbs { margin: 0 0 12px; font-size: 14px; }
.crumbs a { text-decoration: none; color: var(--muted); }
.crumbs a:hover { color: var(--gold-2); }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin-bottom: 0; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.title-row h1 { margin-bottom: 0; }
.session-title { min-width: 0; }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, .015), transparent 55%), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.btn-primary:hover { background: var(--gold-2); border-color: var(--gold-2); }
.btn-ghost { background: rgba(255, 255, 255, .03); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: #465568; background: rgba(255, 255, 255, .05); }
.btn-danger-ghost { background: transparent; color: var(--miss); border-color: rgba(248, 81, 73, .35); }
.btn-danger-ghost:hover { background: var(--miss-bg); }
.btn-sm { min-height: 34px; padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  color: var(--ink);
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { border-color: #465568; background: rgba(255, 255, 255, .05); }
.icon-btn.small { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; }
.icon-btn.danger { color: var(--miss); }
.icon-btn svg { width: 17px; height: 17px; }

:focus-visible {
  outline: 2px solid var(--gold-2);
  outline-offset: 2px;
}

/* ---------- menu ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 7px);
  min-width: 240px;
  background: #1c2530;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 60;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.menu button:hover { background: rgba(255, 255, 255, .06); }
.menu form { margin: 0; }
.menu .menu-danger { color: var(--miss); }
.menu .sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ---------- stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: clamp(20px, 2.4vw, 27px); font-weight: 700; line-height: 1.15; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-hint { color: var(--muted); font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.ok .stat-value { color: var(--ok); }
.stat.extra .stat-value { color: var(--extra); }
.stat.missing .stat-value { color: var(--miss); }
.stat.gold .stat-value { color: var(--gold-2); }
.stat .mini-bar { height: 5px; border-radius: 999px; background: var(--line); margin-top: 8px; overflow: hidden; }
.stat .mini-bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2f9e44, #51cf66); }

/* ---------- session list ---------- */
.session-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-bottom: 20px; }
.session-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color .15s, transform .15s;
}
.session-card:hover { border-color: #3c4a5b; }
.session-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.session-card h3 { margin: 0; font-size: 17px; line-height: 1.25; word-break: break-word; }
.session-card .date { color: var(--muted); font-size: 12px; margin-top: 3px; }
.session-card .note { color: var(--muted); font-size: 13px; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.session-progress { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2f9e44, #51cf66); transition: width .3s; }
.session-progress b { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-stat { font-size: 12px; border-radius: 999px; padding: 4px 9px; background: var(--bg-2); border: 1px solid var(--line-soft); color: var(--muted); white-space: nowrap; }
.mini-stat b { color: var(--ink); font-weight: 600; }
.mini-stat.extra b { color: var(--extra); }
.mini-stat.missing b { color: var(--miss); }
.mini-stat.ok b { color: var(--ok); }
.session-card-actions { display: flex; gap: 8px; margin-top: auto; }
.session-card-actions .btn { flex: 1; }
.session-card-actions .icon-btn { flex: 0 0 auto; }

/* ---------- empty / how ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 10px 0 6px; }
.empty p { max-width: 520px; margin: 0 auto 16px; }
.empty-icon { font-size: 38px; opacity: .8; }
.how { padding: 18px 20px; margin-top: 8px; }
.steps { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.step-no { flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%; background: var(--extra-bg); color: var(--gold-2); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.steps p { margin: 2px 0 0; font-size: 13px; }

/* ---------- banner ---------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid rgba(210, 153, 34, .35);
  background: var(--extra-bg);
  color: #e8c266;
  font-size: 14px;
  margin-bottom: 14px;
}
.banner-info { border-color: rgba(88, 166, 255, .35); background: rgba(88, 166, 255, .1); color: #9ecbff; }

/* ---------- quick count ---------- */
.count-card {
  padding: 16px;
  margin-bottom: 14px;
  border-color: rgba(201, 162, 39, .32);
  background:
    linear-gradient(180deg, rgba(201, 162, 39, .06), transparent 60%),
    var(--card);
}
.count-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.count-head h2 { margin: 0 0 2px; font-size: 17px; }
.count-head p { margin: 0; font-size: 13px; }
.count-head .hint { border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; white-space: nowrap; }
.count-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}
.count-grid .field-index { grid-column: span 4; }
.count-grid .field-name { grid-column: span 4; }
.count-grid .field-unit { grid-column: span 4; }
.count-grid .field-initial { grid-column: span 3; }
.count-grid .field-counted { grid-column: span 3; }
.count-grid .field-location { grid-column: span 4; }
.count-grid .btn-save { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.field input, .field textarea, .field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:hover, .field textarea:hover { border-color: #3b4a5c; }
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, .14);
  background: #0e131a;
}
.field-index input { font-weight: 700; letter-spacing: .03em; }
.btn-save { min-height: 44px; padding-inline: 24px; }
.lookup-info {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
}
.lookup-info strong { color: var(--gold-2); }
.lookup-info .li-item { color: var(--muted); }
.lookup-info .li-item b { color: var(--ink); font-variant-numeric: tabular-nums; }
.lookup-info .li-diff { font-weight: 700; }
.lookup-info.new { border-color: rgba(88, 166, 255, .35); }
.lookup-info.new strong { color: #9ecbff; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px;
  margin-bottom: 12px;
}
.search-wrap { position: relative; flex: 1 1 240px; min-width: 180px; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search-wrap input {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.search-wrap input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201, 162, 39, .12); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip b { font-weight: 700; margin-left: 3px; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: #465568; color: var(--ink); }
.chip.active { background: var(--extra-bg); border-color: rgba(201, 162, 39, .5); color: var(--gold-2); }
.chip.active b { color: var(--gold-2); }
.sort-wrap { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.sort-wrap select {
  min-height: 38px;
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

/* ---------- table ---------- */
.table-wrap { overflow: auto; max-height: 68vh; padding: 0; }
#itemsTable { width: 100%; min-width: 980px; border-collapse: separate; border-spacing: 0; font-size: 14px; }
#itemsTable thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #151c25;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
#itemsTable thead th.num, #itemsTable td.num { text-align: right; }
#itemsTable th.th-lp { width: 48px; text-align: center; }
#itemsTable th.th-unit { width: 74px; }
#itemsTable th.th-act { width: 76px; }
#itemsTable td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
#itemsTable tbody tr:hover td { background: rgba(255, 255, 255, .018); }
#itemsTable td.c-lp { color: var(--muted); text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; }
#itemsTable td.c-index { font-weight: 700; white-space: nowrap; }
#itemsTable td.c-name { color: var(--ink); max-width: 280px; }
#itemsTable td.c-name .sub { display: block; color: var(--muted); font-size: 12px; }
#itemsTable td.c-act { white-space: nowrap; text-align: right; }
#itemsTable td.c-act .icon-btn { margin-left: 4px; }
#itemsTable tr.row-extra td.c-diff { color: var(--extra); }
#itemsTable tr.row-missing td.c-diff { color: var(--miss); }
#itemsTable tr.row-ok td.c-diff { color: var(--ok); }
#itemsTable td.c-diff { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
#itemsTable td.c-diff .zero { color: var(--muted); font-weight: 400; }
#itemsTable td.c-status { white-space: nowrap; }

.cell-input {
  width: 100%;
  min-width: 76px;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.cell-input:hover { border-color: var(--line); background: var(--bg-2); }
.cell-input:focus { outline: none; border-color: var(--gold); background: #0e131a; box-shadow: 0 0 0 2px rgba(201, 162, 39, .12); }
.cell-input.num { text-align: right; font-variant-numeric: tabular-nums; max-width: 110px; margin-left: auto; }
.cell-input.loc { max-width: 190px; }
.cell-input.unit { max-width: 82px; }
.cell-input::placeholder { color: #59636f; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { color: var(--ok); background: var(--ok-bg); }
.badge-extra { color: var(--extra); background: var(--extra-bg); }
.badge-missing { color: var(--miss); background: var(--miss-bg); }
.badge-pending { color: var(--pend); background: var(--pend-bg); }
.badge-closed { color: var(--muted); background: var(--pend-bg); }

.table-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: #151c25;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}
.pager { display: flex; align-items: center; gap: 8px; }
.pager button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.pager button:disabled { opacity: .35; cursor: not-allowed; }
.pager span { min-width: 90px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- lista pozycji (telefon / tablet) ---------- */
.items-list { display: none; }

.item-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.item-row:active { background: var(--card-2); }
.item-row[aria-disabled="true"] { cursor: default; }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.item-index { font-size: 16px; font-weight: 700; letter-spacing: .01em; word-break: break-word; }
.item-unit {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.item-name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.item-meta b { color: var(--ink); font-weight: 600; }
.item-note { color: #7f8b98; font-style: italic; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-right { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.item-diff { font-size: 16px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.item-diff.extra { color: var(--extra); }
.item-diff.missing { color: var(--miss); }
.item-diff.ok { color: var(--ok); }
.item-diff.pending { color: var(--muted); font-weight: 400; }
.item-chevron { flex: 0 0 auto; color: #5d6a78; font-size: 22px; line-height: 1; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 11, .72); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: min(90vh, 900px);
  overflow: auto;
  background: #1a222c;
  border: 1px solid #354150;
  border-radius: 16px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .55);
  padding: 20px;
  animation: modalIn .16s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { margin: 0; }
.modal-card form { display: flex; flex-direction: column; gap: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.modal-actions.split { align-items: center; }
.modal-actions.split .spacer { flex: 1; }

/* ---------- import ---------- */
.dropzone {
  border: 2px dashed #3a4655;
  border-radius: 14px;
  padding: 30px 18px;
  text-align: center;
  background: var(--bg-2);
  transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--gold); background: rgba(201, 162, 39, .06); }
.dropzone p { margin: 4px 0; }
.drop-icon { font-size: 34px; margin-bottom: 6px; }
.import-file { font-size: 13px; color: var(--muted); background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; margin-bottom: 13px; word-break: break-all; }
.import-file b { color: var(--ink); }
.mapping-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.mapping-grid .field > span { font-size: 11px; }
.mapping-grid select { min-height: 40px; font-size: 14px; }
.preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.preview-wrap { overflow: auto; max-height: 240px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 14px; background: var(--bg-2); }
.preview-wrap table { border-collapse: separate; border-spacing: 0; font-size: 12px; width: 100%; white-space: nowrap; }
.preview-wrap th { position: sticky; top: 0; background: #151c25; color: var(--muted); text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); font-size: 11px; }
.preview-wrap td { padding: 6px 9px; border-bottom: 1px solid var(--line-soft); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.mode-group { border: 1px solid var(--line); border-radius: 11px; padding: 10px 13px 12px; margin: 0 0 15px; }
.mode-group legend { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 0 5px; }
.mode-group label { display: flex; align-items: flex-start; gap: 9px; padding: 7px 0; cursor: pointer; font-size: 14px; }
.mode-group input { margin-top: 3px; accent-color: var(--gold); }
.mode-group span { display: flex; flex-direction: column; }
.mode-group small { color: var(--muted); font-size: 12px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast {
  background: #1f2933;
  border: 1px solid #3a4655;
  border-left: 3px solid var(--gold);
  color: var(--ink);
  padding: 11px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: toastIn .18s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--miss); }
.toast.info { border-left-color: #58a6ff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 24px 16px; }
.login-wrap { width: 100%; max-width: 420px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand .brand-mark { width: 48px; height: 48px; border-radius: 13px; }
.login-brand .brand-mark svg { width: 27px; height: 27px; }
.login-brand strong { display: block; font-size: 19px; }
.login-brand small { color: var(--muted); font-size: 13px; }
.login-card { padding: 24px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card > p { font-size: 13px; margin-bottom: 18px; }
.login-card form { display: flex; flex-direction: column; gap: 13px; }
.login-card .btn { margin-top: 4px; }
.login-error { color: var(--miss); background: var(--miss-bg); border: 1px solid rgba(248, 81, 73, .3); border-radius: 9px; padding: 9px 11px; font-size: 13px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ---------- print ---------- */
#printArea { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { background: #fff !important; color: #111 !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; color: #111; font-size: 10px; }
  #printArea h1 { font-size: 17px; margin: 0 0 4px; }
  #printArea .print-meta { font-size: 10px; color: #444; margin-bottom: 8px; }
  #printArea .print-summary { display: flex; gap: 16px; flex-wrap: wrap; font-size: 10px; margin-bottom: 8px; }
  #printArea table { width: 100%; border-collapse: collapse; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 3px 5px; text-align: left; }
  #printArea th { background: #eee; font-size: 9px; text-transform: uppercase; }
  #printArea td.num { text-align: right; font-variant-numeric: tabular-nums; }
  #printArea tr { page-break-inside: avoid; }
  #printArea .p-extra { color: #8a5a00; font-weight: 700; }
  #printArea .p-missing { color: #a51d16; font-weight: 700; }
  #printArea .p-ok { color: #1e7b34; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .count-grid { grid-template-columns: 1fr 1fr; }
  .count-grid .field-index,
  .count-grid .field-name { grid-column: 1 / -1; }
  .count-grid .field-unit { grid-column: 1; }
  .count-grid .field-initial { grid-column: 2; }
  .count-grid .field-counted { grid-column: 1; }
  .count-grid .field-location { grid-column: 2; }
  .count-grid .btn-save { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .wrap { padding: 16px 12px calc(50px + env(safe-area-inset-bottom)); }
  .page-head { gap: 10px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1 1 auto; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .table-wrap { max-height: none; overflow: visible; background: transparent; border: 0; box-shadow: none; }
  #itemsTable { display: none; }
  .items-list { display: flex; flex-direction: column; gap: 8px; }
  .table-foot { border: 1px solid var(--line); border-radius: 10px; margin-top: 10px; position: static; background: var(--card); }
  .session-list { grid-template-columns: 1fr; }
  .toasts { right: 12px; left: 12px; bottom: 12px; max-width: none; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 9px 12px; }
  .brand-text small { display: none; }
  .sync #syncText { display: none; }
  .sync { padding: 6px 8px; }
  .page-head h1 { font-size: 23px; }
  .count-card, .toolbar, .how { padding: 13px; }
  .count-grid { grid-template-columns: 1fr; }
  .count-grid .field,
  .count-grid .btn-save { grid-column: 1 / -1; }
  .count-head .hint { white-space: normal; }
  .toolbar { align-items: stretch; }
  .search-wrap { flex-basis: 100%; }
  .chips { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .sort-wrap { flex: 1; }
  .sort-wrap select { width: 100%; }
  .toolbar > .btn { flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 10px; align-items: flex-end; }
  .modal-card { max-height: 92vh; border-radius: 16px 16px 12px 12px; padding: 16px; }
  .modal-actions { justify-content: stretch; }
  .modal-actions .btn { flex: 1; }
  .modal-actions.split .btn-danger-ghost { flex: 1 1 100%; order: 2; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 21px; }
  .session-card-actions { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
