:root {
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f1f1ee;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --accent: #2a78d6;
  --accent-ink: #1d5fae;
  --series-1: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --neutral: #a8a7a1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 620; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--critical); min-height: 1em; }

/* Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; background: linear-gradient(to right, #fff 219px, var(--border) 219px, var(--border) 220px, var(--bg) 220px); }
.collapsed tbody tr:nth-child(n+16) { display: none; }
.sidebar { background: #fff; border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 4px 10px 18px; }
.sidebar a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.sidebar a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.sidebar a.active { background: #e8f0fb; color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.main { padding: 24px 28px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--text-2); }
.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); padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1000px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } .layout { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } .sidebar-foot { margin: 0; } }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
a.tile { color: inherit; display: block; }
a.tile:hover { text-decoration: none; border-color: #c9c8c2; }

/* Buttons & forms */
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--critical); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font: inherit; text-align: left; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
input, select, textarea { font: inherit; border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d3f3; border-color: var(--accent); }
textarea { width: 100%; min-height: 120px; font-family: ui-monospace, monospace; font-size: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { width: 260px; }
input.qty { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th .arrow { color: var(--muted); font-size: 10px; }
tbody tr:hover td { background: #f7f7f5; }
tr.clickable { cursor: pointer; }
td .thumb { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; background: var(--surface-2); vertical-align: middle; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.name-cell .sub { color: var(--muted); font-size: 12px; }
.diff-pos { color: var(--good); font-weight: 600; }
.diff-neg { color: var(--critical); font-weight: 600; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Status: väri + teksti, ei koskaan pelkkä väri */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 550; color: var(--text-2); white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); flex: none; }
.status.out::before { background: var(--critical); }
.status.reorder::before { background: var(--serious); }
.status.soon::before { background: var(--warning); }
.status.ok::before { background: var(--good); }
.status.overstock::before { background: transparent; border: 2px solid var(--serious); width: 6px; height: 6px; }
.status.dead::before { background: var(--text-2); border-radius: 2px; }
.status.inactive::before { background: var(--border); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.draft { background: #eef0f3; }
.pill.ordered, .pill.partial { background: #e8f0fb; color: var(--accent-ink); }
.pill.received, .pill.applied { background: #e6f5e6; color: #1b6b1b; }
.pill.cancelled { background: #f6e9e9; color: #8a2a2a; }
.pill.open { background: #fff5dd; color: #7a5600; }

/* Cover bar */
.cover { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.cover-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 50px; }
.cover-bar span { display: block; height: 100%; background: var(--series-1); border-radius: 0 3px 3px 0; }

.banner { border: 1px solid #f3d999; background: #fffaf0; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.banner.info { border-color: #c7dbf4; background: #f3f8fe; }

ul.acts { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); }
ul.acts li { margin: 2px 0; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--series-1); }
.chart .bar:hover, .chart .hit:hover + .bar { opacity: .8; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.tooltip { position: fixed; z-index: 100; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.08); pointer-events: none; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Modal & toast */
.modal { position: fixed; inset: 0; background: rgba(20,20,18,.35); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal-box { width: min(760px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #1f1f1e; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 420px; }
.toast.err { background: var(--critical); }

.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }

.scan { display: flex; gap: 8px; align-items: center; }
.scan input { width: 280px; font-size: 16px; padding: 10px 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 12px; font: inherit; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 550; }
.tabs button.active { color: var(--accent-ink); border-color: var(--accent); }

@media print {
  .sidebar, .no-print, .toolbar { display: none !important; }
  .layout { display: block; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body, :root { background: #fff; }
}
.scan input.qty { width: 90px; }

.help .steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--text-2); }
.help .steps b { color: var(--text); }
.help { margin-bottom: 16px; }
tr.group-row td { background: var(--surface-2); font-weight: 650; font-size: 12px; color: var(--text-2); padding: 6px 10px; }
input.loc-in { width: 120px; text-transform: uppercase; font-variant-numeric: tabular-nums; }
input.saved { border-color: var(--good); outline: 2px solid #cdeccd; }
tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #e6f5e6; } to { background: transparent; } }
.print-box { display: none; }
@media print {
  input.loc-in, input.qty { border: 0; padding: 0; background: none; }
  tr.group-row td { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
input.loc-in::placeholder { text-transform: none; }

.tile-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pill.issue { background: #fdecea; color: #8a2a2a; margin: 1px 0; }
table.mf td { vertical-align: top; padding: 6px 8px; }
table.mf td:first-child { width: 38%; word-break: break-word; }
span.thumb { display: inline-block; width: 32px; height: 32px; border-radius: 6px; background: var(--surface-2); }

.aisle-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }
.aisle-row > b { width: 70px; }
.shelf-chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; font-size: 12px; background: #fff; cursor: pointer; }
.shelf-chip:hover { border-color: var(--accent); }
input.invalid { border-color: var(--critical); color: var(--critical); }

tr.row-bad td { background: #fff5f5; }

/* Navigaatio ryhmineen */
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sidebar .nav a, .nav-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; font: inherit; font-weight: 500; }
.nav a svg, .nav-head svg { flex: none; color: var(--muted); }
.nav a.active svg { color: var(--accent-ink); }
.nav-head { width: 100%; background: none; border: 0; cursor: pointer; text-align: left; }
.nav-head:hover { background: var(--surface-2); color: var(--text); }
.nav-head .chev { margin-left: auto; transition: transform .15s; color: var(--muted); font-size: 16px; line-height: 1; }
.nav-group.open .chev { transform: rotate(90deg); }
.nav-group.has-active > .nav-head { color: var(--text); }
.nav-kids { display: none; flex-direction: column; gap: 1px; margin: 1px 0 6px; }
.nav-group.open .nav-kids { display: flex; }
.sidebar .nav-kids a { padding: 6px 10px 6px 37px; font-weight: 450; font-size: 13.5px; }
.nav-badge { margin-left: auto; background: var(--critical); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600; padding: 1px 7px; line-height: 16px; }
.sidebar-foot .whoami { text-align: left; color: var(--text-2); font-size: 12px; }

/* Työlista */
.worklist { display: flex; flex-direction: column; }
.work-area { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: none; margin: 14px 0 4px; }
.work-area:first-child { margin-top: 0; }
.work-row { display: grid; grid-template-columns: 10px 64px 1fr auto; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--text); border-bottom: 1px solid var(--surface-2); }
.work-row:hover { background: var(--surface-2); text-decoration: none; }
.work-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.work-row.high .dot { background: var(--critical); }
.work-row.medium .dot { background: var(--warning); }
.work-row .cnt { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.work-row .go { color: var(--accent-ink); font-size: 13px; white-space: nowrap; }
.work-row .det { color: var(--muted); font-size: 12px; }
.all-done { padding: 24px; text-align: center; color: var(--text-2); }
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 7px 8px; border-bottom: 1px solid var(--surface-2); text-align: left; vertical-align: middle; }
.perm-table th { font-size: 12px; font-weight: 600; }
.perm-table tr.group-row td { font-size: 12px; color: var(--muted); font-weight: 600; padding-top: 14px; }
.perm { font-size: 12px; border-radius: 6px; padding: 3px 6px; }
span.perm.edit, select.perm.edit { background: #e6f4e6; color: #1f6b1f; }
span.perm.view, select.perm.view { background: #e8f0fb; color: var(--accent-ink); }
span.perm.none, select.perm.none { background: var(--surface-2); color: var(--muted); }
select.perm { border: 1px solid var(--border); }

/* Asiakaspalvelu */
body[data-page="asiakaspalvelu"] .main { max-width: none; padding-bottom: 16px; }
.sp-head { margin-bottom: 12px; }
.sp { display: grid; grid-template-columns: 300px minmax(0, 1fr) 330px; height: calc(100vh - 130px); min-height: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sp-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sp-tabs { display: flex; gap: 4px; padding: 10px 10px 6px; }
.sp-tab { flex: 1; border: 1px solid var(--border); background: #fff; border-radius: 7px; padding: 5px 6px; font: inherit; font-size: 12px; cursor: pointer; color: var(--text-2); }
.sp-tab.on { background: #e8f0fb; border-color: #c5d9f3; color: var(--accent-ink); font-weight: 600; }
.sp-filter { padding: 0 10px 8px; display: flex; flex-direction: column; gap: 6px; border-bottom: 1px solid var(--border); }
.sp-filter input[type=search] { width: 100%; }
.sp-items { overflow-y: auto; flex: 1; }
.sp-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--surface-2); color: var(--text); }
.sp-item:hover { background: var(--surface-2); text-decoration: none; }
.sp-item.on { background: #e8f0fb; box-shadow: inset 3px 0 0 var(--accent); }
.sp-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.sp-subj { margin: 2px 0; }
.sp-prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-empty { color: var(--muted); padding: 30px 16px; text-align: center; }
.sp-conv { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.sp-conv-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sp-title { font-weight: 650; font-size: 15px; }
.sp-threads { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 82%; border-radius: 10px; padding: 9px 12px; background: var(--surface-2); }
.msg.message { align-self: flex-end; background: #e8f0fb; }
.msg.note { align-self: center; background: #fff8e6; border: 1px dashed #e8c66a; max-width: 92%; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.msg-body { line-height: 1.5; overflow-wrap: anywhere; }
.sp-compose { border-top: 1px solid var(--border); padding: 10px 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.sp-compose.note textarea { background: #fffbef; border-color: #e8c66a; }
.sp-compose textarea { width: 100%; resize: vertical; font: inherit; }
.sp-mode { display: flex; gap: 14px; font-size: 13px; }
.sp-side { border-left: 1px solid var(--border); overflow-y: auto; padding: 14px; background: #fbfbfa; }
.sp-cust { margin-bottom: 10px; }
.sp-osearch { display: flex; gap: 6px; margin-bottom: 12px; }
.sp-osearch input { flex: 1; min-width: 0; }
.ord { border: 1px solid var(--border); border-radius: 9px; background: #fff; margin-bottom: 8px; }
.ord-toggle { width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.ord-body { display: none; padding: 0 10px 10px; flex-direction: column; gap: 8px; }
.ord.open .ord-body { display: flex; }
.ord-line { border-top: 1px solid var(--surface-2); padding-top: 7px; display: flex; flex-direction: column; gap: 3px; }
.stock-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 12px; color: var(--text-2); }
.stock-row > span:first-child { flex: 1 1 100%; }
.loc-chip { background: #e8f0fb; color: var(--accent-ink); border-radius: 5px; padding: 1px 6px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sr { border-bottom: 1px solid var(--surface-2); padding-bottom: 8px; }
ol.steps { padding-left: 18px; line-height: 1.6; }
ol.steps pre { background: var(--surface-2); padding: 8px 10px; border-radius: 6px; font-size: 12px; }
@media (max-width: 1200px) { .sp { grid-template-columns: 260px minmax(0, 1fr); } .sp-side { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--border); } .sp { height: auto; } .sp-threads { max-height: 60vh; } }
.pill.ok { background: #e6f4e6; color: #1f6b1f; }
.pill { white-space: nowrap; }
.pill.warn { background: #fff4dc; color: #8a5a00; }
.kv-list > div { padding: 2px 0; }
tr.done-row td { background: #f3faf3; }
.ok-text { color: #1f6b1f; }
@media print { .nav, .sidebar { display: none !important; } }
