:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cfd7e3;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8492a6;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #059669;
  --ok-soft: #e6f6f0;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-hover: #1e293b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #0f1729;
    --border: #1f2a40;
    --border-strong: #2c3a55;
    --text: #e6ebf5;
    --text-2: #a5b1c6;
    --text-3: #6b7a94;
    --accent: #5b8dff;
    --accent-soft: #182a52;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --ok: #34d399;
    --ok-soft: #0f2f26;
    --warn: #fbbf24;
    --warn-soft: #3a2a0c;
    --sidebar: #070c18;
    --sidebar-hover: #111a2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- formularze ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=url],
select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); outline: none; min-height: 36px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 450; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
input[type=color] { width: 40px; height: 34px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; min-height: 36px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap; text-decoration: none !important; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; min-height: 30px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* ---------- logowanie ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand img { width: 30px; height: 30px; }

/* ---------- układ ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100%; }
.shell > div { min-width: 0; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 16px 12px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
}
.sidebar .brand { color: #fff; padding: 2px 8px 6px; }
.nav-group h4 { margin: 0 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; color: var(--sidebar-text);
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--sidebar-hover); }
.nav a.active { background: var(--sidebar-hover); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--sidebar-muted); font-variant-numeric: tabular-nums; }
.nav a.active .count { color: #fff; }
.nav svg { width: 17px; height: 17px; opacity: .85; flex: none; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--sidebar-hover); padding: 12px 8px 0; font-size: 13px; }
.sidebar .me .name { color: #fff; font-weight: 600; }
.sidebar .me button { background: none; border: 0; color: var(--sidebar-muted); cursor: pointer; padding: 0; margin-top: 4px; }
.sidebar .me button:hover { color: #fff; }

.main { min-width: 0; padding: 20px 24px 60px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.kpis > .card, .grid-2 > .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 8px; }

/* ---------- filtry ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.filters > * { min-width: 0; flex: 1 1 150px; max-width: 240px; }
.filters .search { flex: 3 1 200px; max-width: none; }
.filters .dates { display: flex; gap: 6px; flex: 2 1 270px; max-width: 340px; }
.filters .dates input { min-width: 0; }
.filters-toggle { display: none !important; }
.status-tabs { display: none; }

.bulkbar {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--accent-soft);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.bulkbar select { width: auto; min-width: 190px; }
.bulkbar strong { margin-right: 4px; }

/* ---------- tabela zamówień ---------- */
.table-wrap { overflow-x: auto; }
table.orders { width: 100%; border-collapse: collapse; }
table.orders th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3);
  font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
table.orders td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.orders tr.row { cursor: pointer; }
table.orders tr.row:hover td { background: var(--surface-2); }
table.orders tr.selected td { background: var(--accent-soft) !important; }
table.orders .num { font-weight: 650; }
table.orders .r { text-align: right; white-space: nowrap; }
.cell-check { width: 36px; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.store-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.store-chip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.items { display: flex; gap: 8px; align-items: flex-start; min-width: 220px; }
.thumbs { display: flex; flex: none; }
.thumbs img, .thumb-ph {
  width: 34px; height: 34px; border-radius: 6px; object-fit: cover; border: 2px solid var(--surface); background: var(--surface-2);
}
.thumbs img + img, .thumbs img + .thumb-ph { margin-left: -12px; }
.thumb-ph { display: inline-block; border: 1px solid var(--border); }
.items .t { font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 550; padding: 2px 8px;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }

.status-pill {
  appearance: none; -webkit-appearance: none; border: 0; border-radius: 999px; padding: 4px 26px 4px 10px; min-height: 0; width: auto;
  font-size: 12.5px; font-weight: 600; cursor: pointer; color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='white' stroke-width='1.6' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.status-pill:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
.status-pill option { color: var(--text); background: var(--surface); }

.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* karty na telefonie */
.order-cards { display: none; }
.ocard { display: block; padding: 12px 14px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none !important; }
.ocard .line { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.ocard .line + .line { margin-top: 6px; }
.ocard .dotname { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.ocard .dotname i { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- szczegóły zamówienia ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-weight: 500; margin-bottom: 10px; }
.lines { width: 100%; border-collapse: collapse; }
.lines td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.lines tr:last-child td { border-bottom: 0; }
.lines img, .lines .thumb-ph { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); display: block; }
.lines .qty { font-weight: 700; font-variant-numeric: tabular-nums; }
.lines .removed td { opacity: .5; text-decoration: line-through; }
.totals { padding: 12px 16px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 15px; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 4px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }
.address { white-space: pre-line; line-height: 1.55; }
.note-box { background: var(--warn-soft); border-radius: 8px; padding: 10px 12px; color: var(--text); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 13.5px; }
.timeline li.comment { background: var(--surface-2); }
.timeline .when { color: var(--text-3); font-size: 12px; }
.comment-form { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.comment-form .btn { align-self: flex-end; }

/* ---------- pulpit ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-3); font-size: 12.5px; font-weight: 550; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .value.sm { font-size: 18px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding: 16px 16px 0; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.bars .bar span { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.bars .bar div { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar.today div { background: var(--ok); }
.bar-labels { display: flex; gap: 6px; padding: 6px 16px 14px; }
.bar-labels span { flex: 1; text-align: center; font-size: 10.5px; color: var(--text-3); min-width: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }

/* ---------- ustawienia ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.store-card { display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; padding: 14px 16px; align-items: center; }
.store-card .stripe { align-self: stretch; border-radius: 3px; }
.store-card .err { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.status-row { display: grid; grid-template-columns: auto 44px 1fr auto auto; gap: 10px; align-items: center; padding: 9px 16px; border-top: 1px solid var(--border); }
.status-row:first-child { border-top: 0; }
.status-row .role { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.radio-cards { display: grid; gap: 8px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; font-weight: 450; margin: 0; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 3px; accent-color: var(--accent); }
.steps { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.steps li { margin-bottom: 3px; }
.callout { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 13px; color: var(--text-2); }

/* ---------- okno modalne i komunikaty ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal .card-head h2 { font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; font-weight: 500; }
.toast.error { background: var(--danger); color: #fff; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; display: grid; place-items: center; }

/* ---------- telefon i tablet ---------- */
@media (max-width: 1100px) {
  .detail { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .sidebar { transform: none; }
  .shell.menu-open::after { content: ''; position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 30; }
  .topbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--sidebar); color: #fff;
    position: sticky; top: 0; z-index: 20;
  }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; display: grid; cursor: pointer; }
  .topbar svg { width: 22px; height: 22px; }
  .main { padding: 14px 12px 60px; }
  .filters { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .filters > *, .filters .dates { max-width: none; }
  .filters .search { grid-column: auto; }
  .filters .dates { grid-column: 1 / -1; }
  .filters > :not(.search):not(.filters-toggle) { grid-column: 1 / -1; }
  .filters:not(.open) > :not(.search):not(.filters-toggle) { display: none; }
  .filters .filters-toggle { display: inline-flex !important; }
  .filters-toggle .dot-on { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
  .lines .unit { display: none; }
  .lines td { padding: 10px 12px; }
  .status-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px 0; scrollbar-width: none; }
  .status-tabs a { flex: none; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); font-size: 13px; font-weight: 550; text-decoration: none; }
  .status-tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .table-wrap { display: none; }
  .order-cards { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
  .store-card { grid-template-columns: 6px 1fr; }
  .store-card .actions { grid-column: 2; }
  .status-row { grid-template-columns: auto 40px 1fr auto; }
  .status-row .role { display: none; }
  .kv { grid-template-columns: 96px 1fr; }
}
