/*
  Material Design 3 (m3.material.io), dense variant for a work tool.
  Tonal colour roles from a blue seed, rounded surfaces, pill buttons,
  chips for status, segmented buttons for views.
*/
:root {
  --primary: #415f91;
  --on-primary: #ffffff;
  --primary-container: #d6e3ff;
  --on-primary-container: #001b3e;
  --secondary-container: #dae2f9;
  --on-secondary-container: #131c2b;
  --tertiary: #705575;
  --tertiary-container: #fad8fd;
  --on-tertiary-container: #28132e;
  --error: #ba1a1a;
  --error-container: #ffdad6;
  --on-error-container: #410002;
  --success: #3b6939;
  --success-container: #bcf0b4;
  --on-success-container: #002204;
  --warn: #7c5800;
  --warn-container: #ffdea6;
  --on-warn-container: #271900;
  --surface: #f9f9ff;
  --surface-lowest: #ffffff;
  --surface-low: #f3f3fa;
  --surface-container: #ededf4;
  --surface-high: #e7e8ee;
  --surface-highest: #e2e2e9;
  --on-surface: #191c20;
  --on-surface-variant: #44474e;
  --outline: #74777f;
  --outline-variant: #c4c6d0;
  --shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  --row: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #aac7ff; --on-primary: #0a305f; --primary-container: #284777; --on-primary-container: #d6e3ff;
    --secondary-container: #3e4759; --on-secondary-container: #dae2f9;
    --tertiary: #ddbce0; --tertiary-container: #573e5c; --on-tertiary-container: #fad8fd;
    --error: #ffb4ab; --error-container: #93000a; --on-error-container: #ffdad6;
    --success: #a1d39a; --success-container: #235024; --on-success-container: #bcf0b4;
    --warn: #f6be48; --warn-container: #5e4200; --on-warn-container: #ffdea6;
    --surface: #111318; --surface-lowest: #0c0e13; --surface-low: #191c20; --surface-container: #1d2024;
    --surface-high: #282a2f; --surface-highest: #33353a; --on-surface: #e2e2e9; --on-surface-variant: #c4c6d0;
    --outline: #8e9099; --outline-variant: #44474e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--surface); color: var(--on-surface);
  font: 14px/20px "Roboto Flex", Roboto, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1; letter-spacing: .015em;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
main { max-width: 1360px; margin: 0 auto; padding: 20px 24px 48px; }
h1 { font-size: 24px; line-height: 32px; font-weight: 400; margin: 0; letter-spacing: 0; }
h1 .count { font-size: 14px; font-weight: 500; color: var(--on-secondary-container); background: var(--secondary-container); border-radius: 8px; padding: 2px 8px; margin-left: 8px; vertical-align: middle; }
h2 { font-size: 16px; line-height: 24px; font-weight: 500; margin: 24px 0 10px; letter-spacing: .01em; }
p { margin: 6px 0; }
.dim, .muted { color: var(--on-surface-variant); }
.small { font-size: 12px; }
.hint { color: var(--on-surface-variant); font-size: 13px; max-width: 900px; }
.error { color: var(--error); }
.right { text-align: right; }
.center { text-align: center; }
code, .code { font-family: "Roboto Mono", ui-monospace, Consolas, monospace; }
code { font-size: 13px; }

/* ---- top app bar + navigation (tabs with pill indicator) ---- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; min-height: 64px; padding: 0 24px;
  background: var(--surface-container); color: var(--on-surface);
}
.top a { color: inherit; text-decoration: none; }
.top .brand { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 500; letter-spacing: 0; }
.seal {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px;
  background: var(--primary); color: var(--on-primary); font-size: 18px; font-weight: 600;
}
.top nav { display: flex; gap: 4px; }
.top nav a {
  display: flex; align-items: center; height: 40px; padding: 0 16px; border-radius: 20px;
  color: var(--on-surface-variant); font-weight: 500;
}
.top nav a:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.top nav a.active { background: var(--secondary-container); color: var(--on-secondary-container); }
.top .account { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--on-surface-variant); }
.top .account .link { color: var(--primary); font-weight: 500; }

/* ---- page parts ---- */
.crumbs { font-size: 13px; color: var(--on-surface-variant); margin: 0 0 4px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.flash {
  display: flex; align-items: center; min-height: 48px; padding: 12px 16px; margin: 0 0 16px; border-radius: 4px;
  background: #2e3036; color: #eff0f7; box-shadow: var(--shadow-2); font-size: 14px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .flash { background: #e2e2e9; color: #2e3036; } }
.card, .panel { background: var(--surface-low); border-radius: 12px; padding: 16px 20px; margin: 12px 0; }
.narrow { max-width: 520px; }
.empty { color: var(--on-surface-variant); }

/* key figures: filled cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 16px; }
.kpis a {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-radius: 12px;
  background: var(--surface-container); color: var(--on-surface); text-decoration: none; transition: background .15s, box-shadow .15s;
}
.kpis a:hover { box-shadow: var(--shadow-1); }
.kpis .label { font-size: 12px; font-weight: 500; color: var(--on-surface-variant); white-space: nowrap; letter-spacing: .03em; }
.kpis .value { font-size: 28px; line-height: 36px; font-weight: 400; }
.kpis a.active { background: var(--primary-container); color: var(--on-primary-container); }
.kpis a.active .label { color: var(--on-primary-container); }
.kpis a.warn { background: var(--warn-container); color: var(--on-warn-container); }
.kpis a.warn .label { color: var(--on-warn-container); }
.kpis a.alert { background: var(--error-container); color: var(--on-error-container); }
.kpis a.alert .label { color: var(--on-error-container); }

/* facts (order header) */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 0 0 8px; }
.facts div { padding: 10px 16px; border-radius: 12px; background: var(--surface-container); }
.facts dt { font-size: 12px; font-weight: 500; color: var(--on-surface-variant); letter-spacing: .03em; }
.facts dd { margin: 2px 0 0; font-size: 16px; line-height: 24px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 0 24px; align-items: start; }
.side .timeline { background: var(--surface-low); border-radius: 12px; padding: 4px 16px; }

/* ---- controls ---- */
input, select, textarea, button, .button { font: inherit; color: inherit; }
input, select, textarea {
  height: 36px; padding: 0 12px; max-width: 100%;
  background: transparent; border: 1px solid var(--outline); border-radius: 4px; color: var(--on-surface);
}
input:hover, select:hover, textarea:hover { border-color: var(--on-surface); }
input:focus, select:focus, textarea:focus { outline: none; border: 2px solid var(--primary); padding: 0 11px; }
select { padding-right: 6px; background: var(--surface); }
textarea { height: auto; width: 100%; padding: 8px 12px; line-height: 1.45; }
textarea:focus { padding: 7px 11px; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 24px;
  border-radius: 20px; cursor: pointer; white-space: nowrap; font-weight: 500; letter-spacing: .01em;
  background: transparent; border: 1px solid var(--outline); color: var(--primary); text-decoration: none;
  transition: background .15s, box-shadow .15s;
}
button:hover, .button:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); text-decoration: none; }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.primary:hover, .button.primary:hover { background: color-mix(in srgb, var(--on-primary) 8%, var(--primary)); box-shadow: var(--shadow-1); }
button.small { height: 32px; padding: 0 16px; font-size: 13px; }
button.link { height: auto; padding: 0; border: none; background: none; border-radius: 0; }
button.link:hover { text-decoration: underline; background: none; }
button:disabled { opacity: .38; cursor: default; box-shadow: none; }
label { display: block; margin: 12px 0; font-size: 12px; font-weight: 500; color: var(--on-surface-variant); letter-spacing: .02em; }
label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea { display: block; width: 100%; margin-top: 4px; font-size: 14px; font-weight: 400; letter-spacing: normal; }
label.check { display: inline-flex; align-items: center; gap: 8px; margin: 0; color: var(--on-surface); font-size: 14px; font-weight: 400; }
fieldset.choice { border: none; padding: 0; margin: 8px 0; }
fieldset.choice label { display: flex; gap: 10px; align-items: center; margin: 6px 0; font-size: 14px; font-weight: 400; color: var(--on-surface); }
form.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 16px; align-items: end; }
.formgrid .wide { grid-column: span 2; }
.formactions { margin: 16px 0 4px; }
form.danger { margin-top: 20px; font-size: 13px; }
form.danger .link { color: var(--error); }
.copyrow { display: flex; gap: 8px; }
.copyrow input { flex: 1; min-width: 0; font-family: "Roboto Mono", ui-monospace, Consolas, monospace; font-size: 13px; }
input.missing { border-color: var(--warn); background: var(--warn-container); color: var(--on-warn-container); }
input.qty { width: 72px; text-align: right; }

/* toolbar + segmented buttons */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; height: 40px; border-radius: 20px; padding: 0 20px; border-color: transparent; background: var(--surface-high); }
.toolbar input[type=search]:focus { padding: 0 19px; }
.toolbar select { height: 40px; border-radius: 8px; }
.toolbar .reset { font-size: 13px; font-weight: 500; margin-left: 4px; }
.seg, .tabs { display: inline-flex; border: 1px solid var(--outline); border-radius: 20px; overflow: hidden; }
.seg > *, .tabs > * {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 16px; margin: 0; cursor: pointer;
  color: var(--on-surface); font-size: 14px; font-weight: 500; letter-spacing: .01em; text-decoration: none; border-right: 1px solid var(--outline);
}
.seg > *:hover, .tabs > *:hover { background: color-mix(in srgb, var(--on-surface) 8%, transparent); text-decoration: none; }
.seg > *:last-child, .tabs > *:last-child { border-right: none; }
.seg > .active, .tabs > .active { background: var(--secondary-container); color: var(--on-secondary-container); }
.seg > .active::before, .tabs > .active::before { content: "✓"; font-size: 13px; }
.seg input { display: none; }
.tabs { margin: 4px 0 12px; }
.langs { display: flex; gap: 4px; font-size: 13px; }
.langs a { padding: 4px 10px; border-radius: 8px; color: var(--on-surface-variant); border: 1px solid var(--outline-variant); }
.langs a.active { color: var(--on-secondary-container); border-color: transparent; background: var(--secondary-container); }

.bulkbar {
  position: sticky; top: 72px; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--surface-high); border-radius: 16px; padding: 8px 12px; margin-bottom: 8px;
}
.bulkbar select { background: var(--surface-lowest); }
.bulkbar .count { font-size: 13px; font-weight: 500; color: var(--on-surface-variant); margin-right: 4px; }

/* ---- data table inside a card ---- */
.tablewrap { overflow-x: auto; background: var(--surface-lowest); border: 1px solid var(--outline-variant); border-radius: 12px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th {
  text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .03em; color: var(--on-surface-variant);
  padding: 10px 12px; border-bottom: 1px solid var(--outline-variant); white-space: nowrap; background: var(--surface-low);
}
table.grid td { padding: 6px 12px; border-bottom: 1px solid var(--outline-variant); vertical-align: middle; height: var(--row); }
table.grid tbody.order:last-child tr:last-child td { border-bottom: none; }
table.grid tr.item:hover td { background: color-mix(in srgb, var(--on-surface) 4%, transparent); }
table.grid tr.item:has(input[name=ids]:checked) td { background: color-mix(in srgb, var(--primary) 12%, transparent); }
tr.ordrow td { background: var(--surface-container); height: 40px; font-size: 13px; border-bottom: 1px solid var(--outline-variant); }
.ordline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
tr.ordrow .ordno { font-weight: 600; font-size: 14px; color: var(--primary); }
tr.ordrow .shoplink { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 8px; border: 1px solid var(--outline-variant); color: var(--on-surface-variant); text-decoration: none; }
tr.ordrow .shoplink:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--primary); }
tr.ordrow .meta { color: var(--on-surface-variant); }
tr.ordrow .total { margin-left: auto; font-weight: 500; color: var(--on-surface); }
tr.ordrow .shopnote { color: var(--on-surface-variant); font-style: italic; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.ordrow form.refresh { margin: 0 0 0 auto; }
tr.ordrow form.refresh button.icon { min-height: 32px; height: 32px; width: 32px; padding: 0; border-radius: 50%; font-size: 17px; line-height: 1; }
tr.ordrow .ordline .total ~ form.refresh { margin-left: 0; }
tbody.order[id] { scroll-margin-top: 140px; }
td.sel, th.sel { width: 40px; padding-right: 0; text-align: center; }
td.img, th.img { width: 64px; padding-top: 4px; padding-bottom: 4px; }
td.img img, .noimg { display: block; width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--surface-high); }
td.desc { min-width: 220px; }
td.desc .name { display: block; color: var(--on-surface); line-height: 20px; }
td.desc .sub, td .sub { display: block; font-size: 12px; color: var(--on-surface-variant); line-height: 16px; }
td.num, th.num { text-align: right; white-space: nowrap; width: 80px; }
td.strong { font-weight: 600; font-size: 16px; }
td.ssku, th.ssku { width: 130px; white-space: nowrap; }
td.ssku input { width: 130px; font-family: "Roboto Mono", ui-monospace, Consolas, monospace; }
td.sup, th.sup { width: 120px; color: var(--on-surface-variant); }
td.state, th.state { width: 130px; }
td.sstate, th.sstate { width: 180px; }
td.notecell input { width: 100%; min-width: 160px; }
.code { font-size: 13px; font-weight: 500; padding: 2px 8px; border-radius: 6px; background: var(--surface-high); color: var(--on-surface); }
.code.big { font-size: 15px; }
a.missing { display: inline-block; font-size: 12px; font-weight: 500; padding: 1px 10px; border-radius: 8px; background: var(--warn-container); color: var(--on-warn-container); }
.note { display: block; font-size: 12px; color: var(--on-surface-variant); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
tr.stage-done td:not(.sel), tr.stage-stock td:not(.sel) { color: var(--on-surface-variant); }
tr.stage-done img, tr.stage-stock img { opacity: .5; }

/* status chips */
.tag {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 8px; white-space: nowrap;
  font-size: 12px; font-weight: 500; letter-spacing: .02em;
  border: 1px solid var(--outline-variant); background: transparent; color: var(--on-surface-variant);
}
.tag.stage-released, .tag.sst-confirmed, .tag.sst-production, .tag.sst-ready { background: var(--primary-container); border-color: transparent; color: var(--on-primary-container); }
.tag.stage-received, .tag.stage-done, .tag.sst-shipped { background: var(--success-container); border-color: transparent; color: var(--on-success-container); }
.tag.stage-stock { background: var(--surface-high); border-color: transparent; color: var(--on-surface-variant); }
.tag.sst-problem { background: var(--error-container); border-color: transparent; color: var(--on-error-container); }
.tag.shop { background: var(--tertiary-container); border-color: transparent; color: var(--on-tertiary-container); }
select.status { border-radius: 8px; }
select.status.sst-problem { border-color: var(--error); color: var(--error); }
select.status.sst-shipped { border-color: var(--success); color: var(--success); }

/* lists */
table.list { width: 100%; border-collapse: collapse; background: var(--surface-lowest); border: 1px solid var(--outline-variant); border-radius: 12px; overflow: hidden; }
table.list th { text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .03em; color: var(--on-surface-variant); padding: 10px 16px; background: var(--surface-low); border-bottom: 1px solid var(--outline-variant); }
table.list td { padding: 10px 16px; border-bottom: 1px solid var(--outline-variant); }
table.list tr:last-child td { border-bottom: none; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--outline-variant); }
.timeline li:last-child { border-bottom: none; }
.timeline time { display: block; font-size: 12px; color: var(--on-surface-variant); }
.timeline span { font-weight: 500; }
.timeline p { margin: 2px 0 0; color: var(--on-surface-variant); white-space: pre-line; }
.log { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow: auto; font-size: 13px; font-family: "Roboto Mono", ui-monospace, Consolas, monospace; }
.log .ok { color: var(--success); }
.log .warn { color: var(--warn); }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; font-size: 14px; font-weight: 500; }

/* landing + auth */
.hero { max-width: 680px; margin: 64px auto; }
.hero h1 { font-size: 36px; line-height: 44px; margin-bottom: 16px; }
.hero p { font-size: 16px; line-height: 24px; color: var(--on-surface-variant); }
.hero .actions { margin-top: 24px; }
form.card.narrow, div.card.narrow { margin: 48px auto; padding: 24px; border-radius: 28px; background: var(--surface-container); }
form.card h1 { margin-bottom: 12px; }
.promo { background: var(--tertiary-container); color: var(--on-tertiary-container); }
.promo h2 { margin-top: 0; }

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px 32px; }
  .top { gap: 0 8px; padding: 8px 16px; min-height: 56px; }
  .top .brand { font-size: 18px; }
  .seal { width: 32px; height: 32px; font-size: 16px; }
  .top nav { order: 3; width: 100%; overflow-x: auto; }
  .top nav a { height: 36px; padding: 0 14px; }
  .top .account span { display: none; }
  .bulkbar { top: 108px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis .value { font-size: 24px; line-height: 32px; }
  .formgrid .wide { grid-column: auto; }
}

/* narrow screens: table rows become stacked cards (no sideways scrolling) */
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; }
  table.stack td { border: none; height: auto; padding: 0; width: auto; min-width: 0; }
  table.stack tr.ordrow td.sel { display: none; }
  table.stack tr.ordrow td { padding: 8px 12px; }
  table.stack tr.item { display: grid; grid-template-columns: 28px 56px minmax(0, 1fr); gap: 4px 10px; padding: 10px 12px; border-bottom: 1px solid var(--outline-variant); }
  table.stack tr.item td.sel, table.stack tr.item td.img { grid-row: 1 / span 4; }
  table.stack tr.item td:not(.sel):not(.img) { grid-column: 3; text-align: left; }
  table.stack td.num::before { content: "× "; color: var(--on-surface-variant); }
  table.stack td.sstate select, table.stack td.notecell input { width: 100%; }
  table.stack td.sup:empty, table.stack .dim { display: none; }
}

/* ---- activity, catalogue, badge ---- */
.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 9px; background: var(--error); color: #fff; font-size: 11px; font-weight: 600; line-height: 1;
}
.top .account form { display: flex; align-items: center; }
.top .account select { height: 32px; border-radius: 16px; padding: 0 8px; background: transparent; }
table.activity td.time { width: 150px; white-space: nowrap; color: var(--on-surface-variant); font-size: 13px; }
table.activity td.who { width: 220px; }
table.activity td.who .name { display: block; }
table.activity td.who .sub { display: block; font-size: 12px; color: var(--on-surface-variant); }
table.activity td.what { width: 260px; }
table.activity tr.by-supplier td.what .evtext { color: var(--primary); font-weight: 500; }
table.grid tr.fresh td { background: color-mix(in srgb, var(--warn-container) 45%, transparent); }
table.grid tr.fresh td.time { color: var(--on-surface); font-weight: 500; }
.tag.fresh { background: var(--error); border-color: transparent; color: #fff; height: 18px; padding: 0 6px; font-size: 11px; }
.timeline li.by-supplier span { color: var(--primary); }
.tag.av-available { background: var(--success-container); border-color: transparent; color: var(--on-success-container); }
.tag.av-limited { background: var(--warn-container); border-color: transparent; color: var(--on-warn-container); }
.tag.av-unavailable { background: var(--error-container); border-color: transparent; color: var(--on-error-container); }
td.ssku .tag { margin-top: 4px; }
td.ssku .sub { margin-top: 2px; }
select.status.av-limited { border-color: var(--warn); color: var(--warn); }
select.status.av-unavailable { border-color: var(--error); color: var(--error); }
td.from input { width: 150px; }
table.products a.code { text-decoration: none; }
img.preview { max-width: 240px; max-height: 240px; border-radius: 12px; }
.formgrid h1 { margin: 0 0 4px; }
.formgrid .error { margin: 0; }

@media print {
  .top, .bulkbar, .kpis, .toolbar, .tabs, .actions, .promo, form.danger, .formactions, .langs, td.sel, th.sel { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  main { padding: 0; max-width: none; }
  .tablewrap { border: none; overflow: visible; }
  select, input { border: none; padding: 0; height: auto; appearance: none; background: none; }
  tr { break-inside: avoid; }
}
