:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --ink: #17191e;
  --ink2: #565c66;
  --ink3: #8a909a;
  --line: #e2e4e8;
  --dark: #1b1e24;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --ok: #2b8a3e;
  --ok-bg: #e6f4ea;
  --warn: #b35c00;
  --warn-bg: #fff1dc;
  --info: #1864ab;
  --info-bg: #e3effb;
  --bad: #c92a2a;
  --bad-bg: #fde8e8;
  --muted-bg: #eceef1;
  --radius: 12px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 16px; line-height: 1.4; }
a { color: inherit; }
h1 { font-size: 22px; margin: 4px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--ink2); text-transform: uppercase; letter-spacing: 0.04em; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  background: var(--dark); color: #fff; padding: calc(10px + var(--safe-t)) 16px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.bell { margin-left: auto; position: relative; display: flex; padding: 6px; color: #fff; }
.badge {
  position: absolute; top: 0; right: -2px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px;
}
.sidenav { display: none; }

.main { max-width: 980px; margin: 0 auto; padding: 16px 14px calc(var(--tab-h) + var(--safe-b) + 24px); }
.loading { padding: 40px; text-align: center; color: var(--ink3); }

/* Bottom tabs (mobile) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--tab-h) + var(--safe-b));
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink3); font-size: 11px; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidenav { display: flex; gap: 4px; margin-left: 24px; }
  .sidenav a { text-decoration: none; padding: 7px 12px; border-radius: 8px; color: #c9ccd2; font-weight: 600; font-size: 15px; }
  .sidenav a.active, .sidenav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
  .main { padding-bottom: 40px; }
}

/* Cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.card.pad0 { padding: 0; overflow: hidden; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row-card {
  display: flex; gap: 12px; background: var(--card); border-radius: var(--radius); padding: 12px 14px; text-decoration: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05); align-items: flex-start;
}
.row-card:active { background: #fafafa; }
.row-card .grow { flex: 1; min-width: 0; }
.row-card .title { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.row-card .sub { color: var(--ink2); font-size: 14px; margin-top: 2px; }
.row-card .meta { color: var(--ink3); font-size: 13px; margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--muted-bg); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--ink3); }
.num { color: var(--ink3); font-weight: 600; }

.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.ok2 { background: #d3f9d8; color: #1e6b30; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.muted { background: var(--muted-bg); color: var(--ink2); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

.progress { height: 6px; background: var(--muted-bg); border-radius: 3px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; }
.progress > i { display: block; height: 100%; background: var(--warn); }
.progress.full > i { background: var(--ok); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; text-decoration: none; box-shadow: 0 1px 2px rgba(0,0,0,0.05); border-left: 4px solid var(--line); }
.stat b { display: block; font-size: 30px; line-height: 1.1; }
.stat span { color: var(--ink2); font-size: 14px; font-weight: 600; }
.stat.ok { border-left-color: var(--ok); }
.stat.warn { border-left-color: var(--warn); }
.stat.info { border-left-color: var(--info); }
.stat.accent { border-left-color: var(--accent); }

/* Toolbar, chips */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; color: var(--ink2); white-space: nowrap; cursor: pointer; }
.chip.active { background: var(--dark); color: #fff; border-color: var(--dark); }
.search { flex: 1; min-width: 160px; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink2); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid #cfd3da; border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 520px) { .grid2.stack { grid-template-columns: 1fr; } }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; font-size: 15px;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.dark { background: var(--dark); color: #fff; border-color: var(--dark); }
.btn.danger { color: var(--bad); border-color: #f1c0c0; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 15; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 400;
  text-decoration: none; box-shadow: 0 4px 14px rgba(232, 89, 12, 0.45);
}
@media (min-width: 900px) { .fab { bottom: 28px; right: max(28px, calc(50vw - 470px)); } }

/* Items (parts) */
.items { display: flex; flex-direction: column; }
.item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .oem { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 14px; font-weight: 700; }
.item .nm { font-size: 14px; color: var(--ink2); }
.item .from { font-size: 12px; color: var(--ok); margin-top: 2px; }
.qtybox { font-weight: 800; font-size: 15px; min-width: 46px; text-align: center; padding: 4px 6px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); }
.qtybox.done { background: var(--ok-bg); color: var(--ok); }
.item-actions { display: flex; gap: 4px; }
.iconbtn { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 36px; height: 36px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink2); }
.iconbtn.ok { color: var(--ok); border-color: #b9e0c3; }
.additem { display: grid; grid-template-columns: 1.2fr 1.6fr 70px auto; gap: 6px; margin-top: 10px; }
@media (max-width: 560px) { .additem { grid-template-columns: 1fr 70px; } .additem .nm-in { grid-column: 1 / -1; grid-row: 2; } .additem .btn { grid-column: 1 / -1; } }
.edit-rows .erow { display: grid; grid-template-columns: 1.2fr 1.6fr 70px 36px; gap: 6px; margin-bottom: 6px; }
@media (max-width: 560px) { .edit-rows .erow { grid-template-columns: 1fr 64px 36px; } .edit-rows .erow .nm-in { grid-column: 1 / 3; grid-row: 2; } .edit-rows .erow { padding-bottom: 8px; border-bottom: 1px dashed var(--line); } }

/* Banners */
.banner { border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.banner.ok { background: var(--ok-bg); color: #1d5e2c; }
.banner.warn { background: var(--warn-bg); color: #7a3f00; }
.banner.info { background: var(--info-bg); color: #0f4479; }
.banner.dark { background: var(--dark); color: #fff; }
.banner b { display: block; font-size: 16px; margin-bottom: 4px; }
.banner .actions { margin-top: 10px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--ink3); }
.kv dd { margin: 0; word-break: break-word; }

details.card > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '▾'; color: var(--ink3); }
details.card[open] > summary::after { content: '▴'; }

/* Notes & photos */
.note { padding: 10px 0; border-bottom: 1px solid var(--line); }
.note:last-child { border-bottom: 0; }
.note .who { font-size: 13px; color: var(--ink3); display: flex; justify-content: space-between; }
.note .txt { white-space: pre-wrap; margin-top: 3px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.photos a { position: relative; display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--muted-bg); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 80vh; border-radius: 6px; }
.lightbox .lb-bar { display: flex; gap: 10px; margin-top: 14px; color: #ccc; font-size: 13px; align-items: center; }

/* Delivery preview */
.dl { padding: 10px 0; border-bottom: 1px solid var(--line); }
.dl:last-child { border-bottom: 0; }
.dl .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.alloc { font-size: 14px; margin-top: 4px; padding-left: 14px; position: relative; }
.alloc::before { content: '→'; position: absolute; left: 0; }
.alloc.ok { color: var(--ok); }
.alloc.surplus { color: var(--ink2); }
.alloc.similar { color: var(--warn); }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }

.muted { color: var(--ink3); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; word-break: break-all; }
.center { text-align: center; }
.empty { text-align: center; color: var(--ink3); padding: 30px 10px; }
.sp { height: 10px; }
.flex { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* Login */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--dark); }
.auth .card { width: 100%; max-width: 380px; padding: 24px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 10px; }
.auth .logo img { width: 72px; height: 72px; border-radius: 18px; }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 14px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; padding: 0 14px; }
.toast { background: var(--dark); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); max-width: 480px; pointer-events: auto; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* Podpowiedzi klientów */
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); overflow: hidden; margin-top: -2px; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: #fff; padding: 10px 12px; font: inherit; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest button:hover, .suggest button:focus { background: var(--muted-bg); outline: none; }
.suggest small { color: var(--ink3); display: block; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--dark); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0; }
.statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.statrow b { display: block; font-size: 22px; }
.statrow span { font-size: 12px; color: var(--ink3); font-weight: 600; }

.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }

.photos a .ph-badge { position: absolute; left: 4px; bottom: 4px; background: rgba(43,138,62,0.92); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.lightbox input { background: #fff; }
