:root {
  --bg: #eef1f6; --card: #ffffff; --ink: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --accent: #2563eb; --accent-ink: #ffffff;
  --ok: #16a34a; --warn: #d97706; --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #dbe7ff 0%, var(--bg) 60%); }
.login-card { background: var(--card); padding: 34px; border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(380px, 92vw); display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line); }
.login-card h1 { font-size: 19px; margin: 0 0 2px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #334155; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.err { color: var(--danger); font-size: 13px; font-weight: 600; background: #fee2e2; padding: 8px 10px; border-radius: 9px; }
.hint { font-size: 12.5px; line-height: 1.6; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  background: #0f172a; color: #fff; padding: 11px 18px; box-shadow: var(--shadow); flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .3px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav button { background: transparent; color: #cbd5e1; border: 0; padding: 7px 13px;
  border-radius: 9px; font-weight: 600; font-size: 13.5px; transition: background .12s; }
.nav button:hover { background: #1e293b; color: #fff; }
.nav button.active { background: var(--accent); color: #fff; }
.spacer { flex: 1; }
.userbox { font-size: 13px; color: #cbd5e1; }
.btn { background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
  padding: 8px 13px; border-radius: 9px; font-weight: 600; font-size: 13.5px; transition: filter .1s; }
.btn:hover { filter: brightness(.93); }
.btn.ghost { background: #eef2f7; color: #334155; border-color: var(--line); }
.btn.ghost:hover { background: #dde5f0; }
.btn.ghost.on-dark { background: transparent; color: #e2e8f0; border-color: #334155; }
.btn.ghost.on-dark:hover { background: #1e293b; color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { display: block; width: 100%; text-align: center; }
.btn.ok { background: var(--ok); } .btn.warn { background: var(--warn); }
.btn.danger { background: var(--danger); }
.btn.icon { padding: 6px 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Toolbar & content (full width) ---------- */
.content { padding: 18px; max-width: 1600px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px; border: 1px solid var(--line); }
.card.flush { padding-bottom: 8px; }
h2 { margin: 0 0 12px; }
h3 { margin: 0 0 10px; font-size: 16px; }
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--line); margin-bottom: 14px; }
.toolbar .field { display: flex; flex-direction: column; gap: 3px; }
.toolbar label { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.field input, .field select { min-width: 150px; }

/* ---------- Table (full width, compact, readable) ---------- */
.wrap { overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 224px);
  border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
th, td { padding: 5px 10px; text-align: left; border-bottom: 1px solid var(--line);
  white-space: nowrap; line-height: 1.3; }
th { background: #f8fafc; position: sticky; top: 0; font-size: 11px; text-transform: uppercase;
  letter-spacing: .3px; color: #475569; user-select: none; z-index: 2; }
th:first-child, td:first-child { padding-left: 12px; }
th.sortable { cursor: pointer; }
th.sortable:hover { background: #eef3fb; color: var(--accent); }
th.sortable::after { content: ' ⇅'; opacity: .35; font-weight: 400; }
th.sortable.asc::after { content: ' ▲'; opacity: 1; }
th.sortable.desc::after { content: ' ▼'; opacity: 1; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.b-ACTIVE { background: #dcfce7; color: #166534; }
.b-SOLD { background: #dbeafe; color: #1e40af; }
.b-SUSPENDED { background: #fef3c7; color: #92400e; }
.b-CANCELLED { background: #f3e4ff; color: #7e22ce; }
.b-FORSALE { background: #e0f2fe; color: #075985; }
.b-NOW { background: #fce7f3; color: #9d174d; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.cat-link { color: var(--accent); text-decoration: none; cursor: pointer;
  background: #eef2f7; border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 9px; font-size: 12px; font-weight: 600; }
.cat-link:hover { background: #dde5f0; }
.cat-link.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.cat-hdr { cursor: pointer; }
.cat-hdr:hover { background: #eef3fb; color: var(--accent); }
.cat-hdr .muted { font-weight: 400; }
.chip { background: #eef2f7; border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; cursor: pointer; color: #334155; }
.chip:hover { background: #fde2e2; border-color: #f5b5b5; }
.pcatfilter { align-items: center; }
.picker-list { border: 1px solid var(--line); border-radius: 10px; padding: 6px; max-height: 320px;
  overflow: auto; background: #fff; display: flex; flex-direction: column; gap: 2px; }
.pk-item { display: flex; flex-direction: row; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-weight: 400; }
.pk-item input[type=checkbox] { flex: 0 0 auto; width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--accent); }
.pk-item > .small { margin-left: auto; white-space: nowrap; }
.pk-item:hover { background: #f8fafc; }
.pk-item.pk-inactive { opacity: .6; }
.pk-item b { min-width: 6px; }
.checkbox-col { width: 30px; text-align: center; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 12px; flex-wrap: wrap; }
.pager button { border: 1px solid var(--line); background: #fff; padding: 6px 11px; border-radius: 8px; font-size: 12.5px; }
.pager button:disabled { opacity: .4; }
.pager b { padding: 0 10px; }
.selbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center; z-index: 35;
  padding: 9px 9px 9px 16px; background: #0f172a; color: #fff;
  border: 1px solid #334155; border-radius: 12px; box-shadow: var(--shadow); }
.selbar strong { color: #fff; font-size: 13px; white-space: nowrap; }
.selbar .btn { white-space: nowrap; }
.selbar .btn.ghost { background: #1e293b; color: #e2e8f0; border-color: #334155; }
.selbar .btn.ghost:hover { background: #334155; }

/* ---------- KPI dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 4px 0 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  box-shadow: var(--shadow); position: relative; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -.3px; }
.kpi .l { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-top: 2px; }
.kpi .delta { font-size: 12.5px; font-weight: 700; margin-top: 6px; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); } .delta.flat { color: var(--muted); }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- Chart (pure CSS bars) ---------- */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 180px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
  gap: 4px; min-height: 0; }
.chart .bar { background: linear-gradient(180deg, #60a5fa, #2563eb); border-radius: 4px 4px 0 0;
  min-height: 2px; transition: height .3s; }
.chart .col:hover .bar { filter: brightness(1.08); }
.chart .lbl { font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart .cap { font-size: 10px; color: var(--muted); text-align: center; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: grid; place-items: center; z-index: 20; }
.modal-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow);
  width: min(520px, 94vw); padding: 22px; max-height: 90vh; overflow: auto; border: 1px solid var(--line); }
.modal-card .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.modal-card label { font-size: 13px; font-weight: 600; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13px; z-index: 40; max-width: 90vw; }
.toast.ok { background: #15803d; } .toast.err { background: #b91c1c; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .brand { font-size: 14px; } .content { padding: 10px; }
  .toolbar .field input, .toolbar .field select { min-width: 100%; }
  .nav button { padding: 6px 8px; font-size: 12px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Refined inventory workspace ---------- */
:root {
  --bg: #f4f6f8; --card: #fff; --ink: #17232f; --muted: #718096;
  --line: #e5eaf0; --accent: #0f766e; --accent-ink: #fff;
  --ok: #16876d; --warn: #c27b24; --danger: #c54f54;
  --shadow: 0 10px 30px rgba(26, 42, 57, .055), 0 1px 3px rgba(26, 42, 57, .04);
  --radius: 16px;
}
body { background: var(--bg); color: var(--ink); font: 14px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.topbar { position: fixed; inset: 0 auto 0 0; width: 248px; height: 100vh; padding: 26px 17px 20px; flex-direction: column; align-items: stretch; gap: 24px; flex-wrap: nowrap; background: #132b32; box-shadow: 6px 0 28px rgba(19,43,50,.08); }
.brand { padding: 6px 10px 19px; font-size: 16px; letter-spacing: -.3px; border-bottom: 1px solid rgba(255,255,255,.12); }
.nav { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.nav button { text-align: left; width: 100%; padding: 11px 13px; border-radius: 10px; color: #c3d2d3; font-size: 13px; }
.nav button:hover { background: rgba(255,255,255,.08); }
.nav button.active { color: white; background: #1e7770; box-shadow: 0 5px 14px rgba(0,0,0,.12); }
.topbar .spacer { flex: 1; }
.userbox { color: #d3e0df; font-size: 12px; padding: 10px; border-top: 1px solid rgba(255,255,255,.12); }
.topbar .btn.ghost { width: 100%; text-align: left; color: #d3e0df; background: transparent; border-color: rgba(255,255,255,.15); }
.brand { display:flex; align-items:center; gap:10px; }
.brand-mark { display:grid; place-items:center; width:31px; height:31px; flex:0 0 31px; border-radius:9px; background:#1e7770; color:#fff; font-size:18px; }
.sidebar-toggle { margin-left:auto; display:grid; place-items:center; width:30px; height:30px; border-radius:8px; border:1px solid rgba(255,255,255,.15); color:#d8e6e4; background:rgba(255,255,255,.06); font-size:20px; line-height:1; cursor:pointer; }
.sidebar-toggle:hover { background:rgba(255,255,255,.13); }
.nav-icon { display:grid; place-items:center; width:20px; height:20px; flex:0 0 20px; }
.nav-icon svg { width:19px; height:19px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.nav button[data-view="dashboard"] .nav-icon svg path:first-child,
.nav button[data-view="categories"] .nav-icon svg path { fill:currentColor; stroke:none; }
.nav button { display:flex; align-items:center; gap:12px; }
.control-icon { display:none; width:20px; text-align:center; font-size:16px; }
.content { box-sizing:border-box; width:calc(100% - 248px); max-width:none; margin:0 0 0 248px; padding:16px 12px; }
.card { border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; border-color: #e8edf1; }
.card.flush { padding: 22px; }
h1,h2,h3 { letter-spacing: -.035em; }
h1 { font-size: clamp(26px, 3vw, 34px); line-height: 1.15; margin: 0 0 8px; }
h2 { font-size: 23px; }
h3 { font-size: 16px; }
.eyebrow { color: var(--accent); font-size: 10px; letter-spacing: .14em; font-weight: 800; margin: 0 0 8px; }
.page-heading { display:flex; align-items:center; justify-content:space-between; gap:18px; margin: 4px 0 24px; }
.page-heading .muted { margin: 0; }
.btn { border-radius: 10px; padding: 9px 15px; font-size: 13px; box-shadow: 0 2px 5px rgba(15,118,110,.12); }
.btn.ghost { background: #f5f7f8; color: #344552; border-color: #e3e9ed; box-shadow: none; }
.btn.ok { background: #16876d; }
input,select,textarea { border-radius: 10px; border-color: #dbe3e8; padding: 10px 12px; }
input:focus,select:focus,textarea:focus { outline: 3px solid rgba(15,118,110,.14); border-color: var(--accent); }
.toolbar { background: #fff; padding: 14px; border-radius: 13px; }
.wrap { border-radius: 13px; background: #fff; max-height: calc(100vh - 160px); }
table { font-size: 11px; }
th { background: #f7f9fa; color: #718096; padding: 6px 8px; font-size: 10px; letter-spacing: .08em; }
td { padding: 4px 8px; }
tbody tr:hover { background: #f5faf9; }
.badge { padding: 4px 9px; font-size: 10px; letter-spacing: .02em; }
.kpis { gap: 13px; }
.kpi { border-radius: 15px; padding: 20px; }
.kpi .v { font-size: 25px; letter-spacing: -.04em; }
.chart { gap: 6px; }
.chart .bar { background: linear-gradient(180deg, #52b2a5, #167b72); border-radius: 5px 5px 2px 2px; }
.modal { background: rgba(13,32,39,.54); backdrop-filter: blur(5px); }
.modal-card { border-radius: 18px; padding: 26px; box-shadow: 0 24px 70px rgba(10,25,31,.25); }
.modal-card h3 { font-size: 20px; margin-bottom: 18px; }
.permission-grid { border: 1px solid var(--line); border-radius: 12px; padding: 13px; margin: 14px 0; display:grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.permission-grid legend { padding: 0 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.permission-option { display:flex; flex-direction:row; align-items:flex-start; gap:9px; padding:9px; border-radius:9px; background:#f7f9fa; cursor:pointer; }
.permission-option span { display:flex; flex-direction:column; gap:1px; }
.permission-option small { color:var(--muted); font-size:10px; }
.permission-option input,.check input { accent-color:var(--accent); }
.group-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(280px,1fr)); gap:16px; }
.group-card { margin:0; min-height:210px; display:flex; flex-direction:column; }
.group-card h3 { margin:0 0 4px; }
.group-card p { margin:0; }
.permission-chips { display:flex; flex-wrap:wrap; gap:6px; margin:18px 0; }
.permission-chip { display:inline-flex; align-items:center; gap:6px; border:1px solid #e5eceb; background:#f5faf9; color:#42635f; padding:4px 8px; border-radius:7px; font:10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.permission-chip-remove { border:0; background:transparent; color:#687b78; padding:0 1px; font:700 14px/1 sans-serif; cursor:pointer; }
.permission-chip-remove:hover { color:#b42318; }
.group-actions { margin-top:auto; }
.login { background: radial-gradient(ellipse at 20% 10%, #e1f1ed, transparent 45%), linear-gradient(135deg,#f4f6f8,#eaf0ef); }
.login-card { border-radius:20px; padding:38px; box-shadow:0 25px 70px rgba(27,58,61,.12); }
.login-card h1 { font-size:25px; letter-spacing:-.045em; }
.login-card .btn { padding:12px; }
.toast { border-radius:12px; box-shadow:0 12px 30px rgba(15,30,35,.2); }
#app.sidebar-collapsed .topbar { width:78px; padding:22px 10px 16px; gap:20px; }
#app.sidebar-collapsed .brand { justify-content:space-between; gap:2px; padding:4px 0 15px; }
#app.sidebar-collapsed .brand-label { display:none; }
#app.sidebar-collapsed .sidebar-toggle { position:static; width:24px; height:24px; flex:0 0 24px; font-size:17px; }
#app.sidebar-collapsed .nav { margin-top:10px; }
#app.sidebar-collapsed .nav button { justify-content:center; gap:0; padding:11px 7px; }
#app.sidebar-collapsed .nav-label { display:none; }
#app.sidebar-collapsed .userbox,
#app.sidebar-collapsed .control-label { display:none; }
#app.sidebar-collapsed .topbar .btn.ghost { display:grid; place-items:center; width:44px; height:42px; margin:0 auto; padding:0; text-align:center; }
#app.sidebar-collapsed .control-icon { display:inline-block; }
#app.sidebar-collapsed .content { width:calc(100% - 78px); margin-left:78px; }
@media(max-width:850px) {
  .topbar { position:sticky; inset:auto; width:auto; height:auto; flex-direction:row; align-items:center; flex-wrap:wrap; padding:12px 14px; gap:10px; }
  .brand { width:100%; padding:3px 4px 10px; }
  .nav { flex-direction:row; overflow:auto; }
  .nav button { width:auto; white-space:nowrap; }
  .topbar .spacer { display:none; }
  .sidebar-toggle { display:none; }
  .userbox { margin-left:auto; border:0; padding:4px; }
  .topbar .btn.ghost { width:auto; text-align:center; padding:7px 10px; }
  .content { width:100%; max-width:none; margin:0; padding:20px 14px; }
  #app.sidebar-collapsed .topbar { width:auto; padding:12px 14px; gap:10px; }
  #app.sidebar-collapsed .brand { justify-content:flex-start; padding:3px 4px 10px; }
  #app.sidebar-collapsed .brand-label { display:inline; }
  #app.sidebar-collapsed .nav { margin-top:0; }
  #app.sidebar-collapsed .nav button { justify-content:flex-start; gap:12px; padding:6px 8px; }
  #app.sidebar-collapsed .nav-label { display:inline; }
  #app.sidebar-collapsed .userbox,
  #app.sidebar-collapsed .control-label { display:initial; }
  #app.sidebar-collapsed .topbar .btn.ghost { display:block; width:auto; height:auto; margin:0; padding:7px 10px; text-align:center; }
  #app.sidebar-collapsed .control-icon { display:none; }
  #app.sidebar-collapsed .content { width:100%; margin-left:0; }
}
@media(max-width:560px) {
  .page-heading { align-items:flex-start; flex-direction:column; }
  .permission-grid { grid-template-columns:1fr; }
  .kpis { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .modal-card { padding:19px; }
}

/* Product list: spend space on records, not padding or low-priority columns. */
.content:has(.card.flush) { padding:10px 8px 12px 14px; }
@media(max-width:850px) {
  .content:has(.card.flush) { padding:10px 10px 12px; }
}
.card.flush { padding:12px; }
.card.flush > .row:first-child { margin-bottom: 6px; }
.card.flush .toolbar { padding: 7px 9px; margin-bottom: 6px; }
.card.flush .wrap { max-height: calc(100vh - 235px); }
.card.flush table { table-layout: fixed; }
.card.flush th, .card.flush td { padding: 3px 6px; overflow-wrap:anywhere; white-space:normal; vertical-align:middle; }
.card.flush th { line-height:1.2; }

.card.flush td:nth-child(3) { white-space: normal; line-height: 1.35; }
.card.flush td.actions { overflow:visible; white-space:normal; }
.card.flush td.actions .row { flex-wrap: wrap; gap: 4px; }
.card.flush td.actions .btn { flex:1 1 56px; max-width:100%; padding: 4px 6px; font-size: 10px; line-height:1.25; white-space:normal; overflow-wrap:anywhere; }
.page-size { display:flex; flex-direction:row; align-items:center; gap:6px; color:var(--muted); font-size:11px; font-weight:600; }
.page-size select { min-width:64px; padding:5px 8px; font-size:12px; }
.pager { padding: 9px 8px 5px; }
@media(max-width:1650px) {
  .card.flush th.col-category, .card.flush td.col-category,
  .card.flush th.col-notes, .card.flush td.col-notes,
  .card.flush th.col-author, .card.flush td.col-author,
  .card.flush th:nth-child(13), .card.flush td:nth-child(13) { display:none; }
  .card.flush th:nth-child(3), .card.flush td:nth-child(3) { width: 220px; }
  .card.flush th:nth-child(12), .card.flush td:nth-child(12) { width: 145px; }
}
@media(max-width:900px) {
  .card.flush .wrap { max-height: calc(100vh - 340px); }
  .card.flush th:nth-child(7), .card.flush td:nth-child(7) { display:none; }
  .card.flush th:nth-child(2), .card.flush td:nth-child(2) { width: 42px; }
  .card.flush th:nth-child(3), .card.flush td:nth-child(3) { width: 130px; }
  .card.flush th:nth-child(8), .card.flush td:nth-child(8) { width: 95px; }
  .card.flush th:nth-child(9), .card.flush td:nth-child(9) { width: 85px; }
  .card.flush th:nth-child(12), .card.flush td:nth-child(12) { width: 100px; }
}
@media(max-width:1100px) {
  .card.flush th:nth-child(6), .card.flush td:nth-child(6) { display:none; }
}
@media(max-width:560px) {
  .card.flush .toolbar .field { width:100%; }
  .card.flush .toolbar .field input { width:100%; }
  .card.flush th:nth-child(2), .card.flush td:nth-child(2),
  .card.flush th:nth-child(5), .card.flush td:nth-child(5),
  .card.flush th:nth-child(7), .card.flush td:nth-child(7),
  .card.flush th:nth-child(8), .card.flush td:nth-child(8) { display:none; }
  .card.flush th:nth-child(1), .card.flush td:nth-child(1) { width:28px; }
  .card.flush th:nth-child(3), .card.flush td:nth-child(3) { width:115px; }
  .card.flush th:nth-child(9), .card.flush td:nth-child(9) { width:72px; }
  .card.flush th:nth-child(12), .card.flush td:nth-child(12) { width:70px; }
  .card.flush td.actions .row { gap:3px; }
  .card.flush td.actions .btn { flex-basis:58px; padding:4px 3px; font-size:9px; }
  .card.flush .pager { gap:4px; }
  .card.flush .pager b { font-size:11px; padding:0 2px; }
}

/* Inventory table refinement: a compact, readable eight-column working view. */
.card.flush table { table-layout:auto; min-width:0; }
.card.flush th:nth-child(1), .card.flush td:nth-child(1) { width:38px; }
.card.flush th:nth-child(8), .card.flush td:nth-child(8) { width: 1%; white-space: nowrap; }
.product-title { display:flex; align-items:flex-start; gap:8px; min-width:0; }
.product-title strong { min-width:0; font-size:13px; line-height:1.35; font-weight:700; overflow-wrap:anywhere; }
.product-id { flex:0 0 auto; color:var(--muted); font:600 10px/1.7 ui-monospace,monospace; }
.product-meta { display:flex; align-items:center; flex-wrap:wrap; gap:3px 10px; margin-top:5px; color:var(--muted); font-size:10.5px; line-height:1.35; }
.sale-revoke-timer { display:block; max-width:100%; margin-top:3px; color:var(--muted); font-size:10px; font-weight:500; line-height:1.3; white-space:normal; overflow-wrap:anywhere; }
.product-note { max-width:36ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.source-prices { display:grid; gap:2px; font-variant-numeric:tabular-nums; }
.source-prices > span { display:flex; align-items:baseline; justify-content:flex-start; gap:7px; }
.source-prices small { color:var(--muted); font-size:10px; }
.source-prices b { font-size:11.5px; font-weight:650; white-space:nowrap; }
.card.flush td.col-status { text-align:center; }
.card.flush td.actions .row { flex-wrap:wrap; gap:5px; justify-content: flex-end; }
.card.flush td.actions .btn { flex:1 1 72px; max-width:100%; padding:5px 7px; font-size:10.5px; line-height:1.25; white-space:normal; overflow-wrap:anywhere; }
.card.flush td.actions .btn.icon-action { display:inline-grid; place-items:center; flex:0 0 30px; width:30px; height:30px; padding:0; border-radius:8px; }
.card.flush td.actions .icon-action svg { display:block; width:15px; height:15px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.card.flush td.actions .icon-action.ghost { background:#f2f6f6; color:#49616a; border-color:#e1e9e9; }
.card.flush td.actions .icon-action.ghost:hover { background:#e3efed; color:#176b62; }

@media(max-width:1650px) {
  .card.flush th.col-category, .card.flush td.col-category,
  .card.flush th.col-shipping, .card.flush td.col-shipping { display:none; }
  .card.flush table { min-width:940px; }
  .card.flush th:nth-child(2), .card.flush td:nth-child(2) { width: auto; }
  .card.flush th:nth-child(4), .card.flush td:nth-child(4) { width: auto; }
  .card.flush th:nth-child(6), .card.flush td:nth-child(6) { width: auto; }
  .card.flush th:nth-child(7), .card.flush td:nth-child(7) { display:table-cell; width:100px; }
  .card.flush th:nth-child(8), .card.flush td:nth-child(8) { width: 1%; white-space: nowrap; }
}
@media(max-width:1100px) {
  .card.flush th.col-category, .card.flush td.col-category,
  .card.flush th.col-shipping, .card.flush td.col-shipping { display:none; }
  .card.flush th:nth-child(6), .card.flush td:nth-child(6) { display:table-cell; width:105px; }
  .card.flush table { min-width:900px; }
}
@media(max-width:760px) {
  .content:has(.card.flush) { padding:12px 10px; }
  .card.flush { padding:12px; }
  .card.flush .wrap { max-height:none; overflow:visible; border:0; background:transparent; }
  .card.flush table, .card.flush tbody { display:block; min-width:0; width:100%; }
  .card.flush thead { display:none; }
  .card.flush tbody { display:grid; gap:10px; }
  .card.flush tbody tr { position:relative; display:grid; grid-template-columns:repeat(2,minmax(0,1fr));
    grid-template-areas:"product product" "category status" "sources sale" "shipping shipping" "actions actions";
    gap:10px 12px; padding:14px; border:1px solid var(--line); border-radius:13px; background:#fff; box-shadow:0 4px 12px rgba(26,42,57,.04); }
  .card.flush tbody tr:has(.empty) { display:block; }
  .card.flush tbody td { display:block; width:auto !important; padding:0; border:0; text-align:left; }
  .card.flush td.checkbox-col { position:absolute; top:14px; right:14px; z-index:1; }
  #app .card.flush tbody td.col-product { display:block; grid-area:product; padding-right:28px; }
  #app .card.flush tbody td.col-category { display:block; grid-area:category; }
  #app .card.flush tbody td.col-sources { display:block; grid-area:sources; }
  #app .card.flush tbody td.col-shipping { display:block; grid-area:shipping; }
  #app .card.flush tbody td.col-sale { display:block; grid-area:sale; }
  #app .card.flush tbody td.col-status { display:block; grid-area:status; text-align:left; }
  #app .card.flush tbody td.actions { display:block; grid-area:actions; padding-top:8px; border-top:1px solid var(--line); }
  .card.flush td[data-label]::before { content:attr(data-label); display:block; margin-bottom:3px; color:var(--muted);
    font-size:9px; font-weight:800; letter-spacing:.09em; text-transform:uppercase; }
  .card.flush td.col-product::before { display:none; }
  .card.flush td.actions .row { display:flex; }
  .card.flush td.actions .btn.icon-action { flex:0 0 36px; width:36px; height:36px; }
  .card.flush .toolbar .field, .card.flush .toolbar .field input { width:100%; }
  .card.flush .pager { justify-content:space-between; }
  .card.flush .pager b { order:3; width:100%; text-align:center; }
  .card.flush .pager .page-size { margin-left:auto; }
}

/* Keep status filters and search on the same compact control row. */
.inventory-head { display:grid; grid-template-columns:max-content minmax(0,1fr) auto; align-items:center; gap:12px; margin-bottom:7px; }
.inventory-title { display:flex; align-items:baseline; gap:9px; min-width:0; }
.inventory-title h2 { margin:0; font-size:22px; }
.inventory-count { color:var(--muted); font-size:11px; white-space:nowrap; }
.inventory-controls { display:flex; align-items:center; gap:10px; min-width:0; }
.inventory-tabs { flex:0 1 auto; flex-wrap:nowrap; gap:4px; min-width:0; margin:0; overflow-x:auto; scrollbar-width:thin; }
.inventory-tabs .btn { flex:0 0 auto; padding:5px 7px; font-size:10.5px; white-space:nowrap; }
.inventory-search { display:flex; flex:1 1 280px; align-items:center; gap:7px; width:auto; min-width:220px; max-width:520px; margin:0; padding:4px 5px 4px 12px; border:1px solid #dfe8e8; border-radius:11px; background:#f7f9f9; }
.inventory-search svg { flex:0 0 17px; width:17px; height:17px; fill:none; stroke:#718096; stroke-width:1.8; stroke-linecap:round; }
.inventory-search input { flex:1 1 auto; width:100%; min-width:0; padding:7px 3px; border:0; outline:0; background:transparent; box-shadow:none; font-size:13px; }
.inventory-search input:focus { outline:0; }
.inventory-search button { box-shadow:none; }
.inventory-actions { display:flex; align-items:center; justify-content:flex-end; gap:7px; white-space:nowrap; }
@media(max-width:1350px) {
  .inventory-head { grid-template-columns:minmax(0,1fr) auto; grid-template-areas:"title actions" "controls controls"; gap:8px 10px; }
  .inventory-title { grid-area:title; }
  .inventory-controls { grid-area:controls; }
  .inventory-actions { grid-area:actions; }
  .inventory-search-wrap { max-width:none; }
}
@media(max-width:760px) {
  .inventory-head { grid-template-columns:minmax(0,1fr) auto; grid-template-areas:"title actions" "controls controls"; gap:8px; }
  .inventory-title { grid-area:title; }
  .inventory-controls { grid-area:controls; flex-wrap:wrap; }
  .inventory-tabs { flex:1 1 100%; width:100%; }
  .inventory-search { flex:1 1 100%; width:100%; min-width:0; max-width:none; }
  .inventory-actions { grid-area:actions; }
  .inventory-actions > .btn { padding:8px 10px; }
  .inventory-tabs .btn { padding:5px 7px; }
}

.product-name-link { padding:0; border:0; background:transparent; color:var(--ink); font:inherit; font-size:13px; line-height:1.35; font-weight:700; text-align:left; overflow-wrap:anywhere; cursor:pointer; }
.product-name-link:hover { color:var(--accent); text-decoration:underline; }
.product-name-link:focus-visible { outline:2px solid var(--accent); outline-offset:3px; border-radius:2px; }
.modal.modal-wide .modal-card { width:min(1060px,96vw); max-height:92vh; }
.product-detail-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:10px; }
.product-detail-grid > div { min-width:0; display:flex; flex-direction:column; gap:4px; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:#f8fafb; }
.product-detail-grid > div > span { color:var(--muted); font-size:9px; font-weight:800; letter-spacing:.08em; text-transform:uppercase; }
.product-detail-grid > div > b { min-width:0; font-size:12px; line-height:1.4; overflow-wrap:anywhere; }
.product-detail-value { display:flex; align-items:baseline; justify-content:space-between; gap:8px; width:100%; min-width:0; padding:2px 4px; border:1px solid transparent; border-radius:6px; background:transparent; color:var(--ink); font-family:inherit; font-size:12px; font-weight:650; line-height:1.4; text-align:left; white-space:normal; overflow-wrap:anywhere; }
.product-detail-value:hover,.product-detail-value:focus-visible { border-color:#dce8e6; background:#fff; }
.product-detail-value span { flex:0 0 auto; color:var(--accent); opacity:.6; }
.product-detail-inline { display:grid; gap:7px; width:100%; }
.product-detail-inline input,.product-detail-inline select,.product-detail-inline textarea { width:100%; min-width:0; padding:7px 9px; font-size:12px; }
.product-detail-inline-actions { display:flex; justify-content:flex-end; gap:6px; }
.product-detail-grid .product-detail-wide { grid-column:1/-1; }
.product-history-section { margin-top:18px; padding-top:14px; border-top:1px solid var(--line); }
.product-history-section h4 { margin:0 0 10px; font-size:15px; }
.product-history-wrap { max-height:48vh; overflow:auto; border:1px solid var(--line); border-radius:10px; }
.product-history { width:100%; min-width:780px; border-collapse:collapse; }
.product-history th,.product-history td { padding:9px 10px; text-align:left; vertical-align:top; white-space:normal; overflow-wrap:anywhere; word-break:normal; }
.product-history th { position:sticky; top:0; z-index:1; background:#f2f6f7; }
.product-history td { max-width:240px; overflow-wrap:anywhere; font-size:11px; }
.product-history td small { display:block; margin-top:3px; color:var(--muted); }
.modal.modal-wide .modal-card h3 { overflow-wrap:anywhere; word-break:normal; }
@media(max-width:760px) {
  .product-detail-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .modal.modal-wide .modal-card { padding:16px; }
  .product-history-wrap { max-height:52vh; }
}

.content:has(.card.flush) { padding-bottom:82px; }
.inventory-search-wrap { position:relative; flex:1 1 280px; min-width:220px; max-width:520px; }
.inventory-search-wrap .inventory-search { width:100%; min-width:0; max-width:none; margin:0; }
.search-suggestions { position:absolute; z-index:18; top:calc(100% + 5px); left:0; right:0; max-height:320px; overflow:auto; border:1px solid var(--line); border-radius:11px; background:#fff; box-shadow:0 14px 30px rgba(20,40,50,.16); }
.search-suggestion { display:flex; align-items:center; justify-content:space-between; gap:12px; width:100%; padding:10px 12px; border:0; border-bottom:1px solid #edf1f3; background:#fff; color:var(--ink); text-align:left; cursor:pointer; }
.search-suggestion:last-child { border-bottom:0; }
.search-suggestion:hover,.search-suggestion:focus-visible { background:#f0f7f6; outline:0; }
.search-suggestion-name { min-width:0; overflow:hidden; font-size:12px; font-weight:700; text-overflow:ellipsis; white-space:nowrap; }
.search-suggestion-meta { flex:0 0 auto; color:var(--muted); font-size:10px; }
.search-suggestion-message { padding:12px; color:var(--muted); font-size:12px; }
.inventory-footer { position:fixed; z-index:15; left:248px; bottom:0; display:flex; justify-content:center; box-sizing:border-box; width:calc(100% - 248px); padding:8px 16px; border-top:1px solid var(--line); background:rgba(255,255,255,.96); box-shadow:0 -6px 20px rgba(20,40,50,.06); backdrop-filter:blur(8px); }
#app.sidebar-collapsed .inventory-footer { left:78px; width:calc(100% - 78px); }
.inventory-footer .pager { width:100%; max-width:900px; margin:0 auto; padding:0; flex-wrap:nowrap; justify-content:center; gap:10px; }
.inventory-footer .pager b { order:0; width:auto; white-space:nowrap; }
.inventory-footer .page-size { margin-left:0; white-space:nowrap; }
#app:has(.card.flush) .selbar { bottom:74px; }
@media(max-width:850px) {
  .content:has(.card.flush) { padding-bottom:82px; }
  .inventory-footer,#app.sidebar-collapsed .inventory-footer { left:0; width:100%; }
}
@media(max-width:760px) {
  .inventory-search-wrap { flex:1 1 100%; width:100%; min-width:0; max-width:none; }
  .inventory-footer { padding:7px 10px; }
  .inventory-footer .pager { flex-wrap:wrap; justify-content:space-between; gap:5px; }
  .inventory-footer .pager b { order:3; flex:1 0 100%; text-align:center; }
  .inventory-footer .page-size { margin-left:auto; }
  #app:has(.card.flush) .selbar { bottom:88px; }
}

@media(min-width:851px) and (min-height:600px) {
  .content:has(.card.flush) {
    display:flex;
    flex-direction:column;
    height:100vh;
    height:100dvh;
    min-height:0;
    overflow:hidden;
    padding-bottom:60px;
  }
  .content:has(.card.flush) > .card.flush {
    display:flex;
    flex:1 1 auto;
    flex-direction:column;
    min-height:0;
    margin-bottom:0;
  }
  .card.flush .wrap {
    flex:1 1 auto;
    min-height:0;
    max-height:none;
  }
}

/* ---------- Anti-flash on refresh ----------
   When a session token exists, pre-reveal the app shell synchronously in the
   document <head> (adds html.has-session) so a refresh never paints the login
   screen for a frame. If /auth/me later fails, boot() removes has-session. */
html.has-session #login { display:none; }
html.has-session #app { display:block !important; }
html.has-session #app:empty::before { content:"Ładowanie…"; }


/* ---------- Excel-like compact product grid + expandable "stopka" (additional info) ----------
   Scoped to desktop so the mobile card layout below is untouched. */
@media (min-width: 851px) {
  /* full-window table: fill the viewport height; compact rows so ~25 fit */
  #app .card.flush .wrap { height: calc(100vh - 150px); max-height: none; }
  /* hide the 3 "additional" columns CONSISTENTLY (header + body) -> no orphan headers / missing cells */
  #app .card.flush th.col-extra, #app .card.flush td.col-extra { display: none; }
  /* compact main rows */
  #app .card.flush tr.row-main { height: 30px; }
  #app .card.flush tr.row-main > td { padding: 3px 8px; line-height: 1.2; vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #app .card.flush tr.row-main .col-product { white-space: normal; }
  #app .card.flush tr.row-main .col-product .product-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
  #app .card.flush tr.row-main .col-product .product-name-link { flex: 1 1 auto; min-width: 60px; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* chevron toggles the stopka */
  #app .card.flush .row-detail-toggle { flex: 0 0 auto; width: 18px; height: 18px; padding: 0; border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 12px; line-height: 1; }
  #app .card.flush .row-detail-toggle:hover { color: var(--accent); }
  /* action icons: a single horizontal row that never wraps */
  #app .card.flush tr.row-main .actions .row { flex-wrap: nowrap !important; gap: 3px; justify-content: flex-end; }
  #app .card.flush tr.row-main .actions .btn.icon-action { flex: 0 0 28px !important; width: 28px; height: 28px; padding: 0; }
  /* stopka = expandable detail row (the additional info) */
  #app .card.flush tr.row-detail[hidden] { display: none !important; }
  #app .card.flush tr.row-detail > td { padding: 0; border-top: 1px solid var(--line); }
  #app .card.flush tr.row-detail td.row-detail-cell { padding: 8px 14px; background: #f6faf8; }
  #app .card.flush tr.row-detail .df { display: flex; gap: 12px; align-items: baseline; padding: 2px 6px; }
  #app .card.flush tr.row-detail .df > span { flex: 0 0 112px; color: var(--muted); font-size: 9.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
  #app .card.flush tr.row-detail .df > b { min-width: 0; font-weight: 600; font-size: 12.5px; }
  #app .card.flush tr.row-detail .df.wide > b { width: 100%; }
  #app .card.flush tr.row-detail .df.foot { display: flex; gap: 8px; padding-top: 8px; }
  #app .card.flush tr.row-detail .source-prices > span { justify-content: space-between; }
}
/* always hide a collapsed stopka row regardless of viewport (robustness) */
#app .card.flush tr.row-detail[hidden] { display: none !important; }

/* ---------- Ustawienia (SMTP) ---------- */
.settings-grid { display:grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap:18px; align-items:start; }
.settings-card h2 { margin: 0 0 14px; font-size: 16px; }
.settings-card .check { margin: 8px 0; }
.settings-card .field { display:flex; flex-direction:column; gap:4px; margin-bottom: 12px; }
.settings-card .field label:not(.check) { font-size: 12px; font-weight: 700; color: var(--muted); }
.settings-card .field input, .settings-card .field textarea { width: 100%; min-width: 0; box-sizing: border-box; }
.settings-fields { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; margin-top: 10px; }
.settings-fields .field.wide { grid-column: 1 / -1; }
.settings-fields .field .check { margin-top: 22px; }
.settings-actions { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .settings-grid, .settings-fields { grid-template-columns: 1fr; }
  .settings-fields .field .check { margin-top: 0; }
}

/* ---------- Historia zmian ---------- */
tr.audit-fail td { background: #fef2f2; }

/* Desktop: sources/shipping live in the row footer, so there is room for the
   category column (older max-width rules above hide it below 1650px). */
@media (min-width: 851px) {
  #app .card.flush th.col-category, #app .card.flush td.col-category { display: table-cell; }
  #app .card.flush th.col-sale { white-space: nowrap; }
  /* the column header is the picker; show the row only for active filter chips */
  #app .cat-pick-mobile, #app .catfilter-empty { display: none; }
}
