:root {
  --ink: #1c2733;
  --muted: #6b7885;
  --line: #d6dce2;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --accent: #1f6f8b;
  --accent-dark: #17576d;
  --warn: #9a6b00;
  --danger: #a3342f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
}

.brand { font-weight: 600; font-size: 16px; color: var(--ink); }

.mainnav { display: flex; gap: 16px; flex: 1; }
.mainnav a { color: var(--muted); padding: 4px 0; border-bottom: 2px solid transparent; }
.mainnav a.active { color: var(--ink); border-bottom-color: var(--accent); }

.userbox { display: flex; align-items: center; gap: 12px; color: var(--muted); }

.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px;
  margin-bottom: 18px;
}

.data { width: 100%; border-collapse: collapse; background: var(--panel); }
.data th, .data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.data th { background: #eef1f4; font-weight: 600; font-size: 13px; }
.data .empty { color: var(--muted); }

.actions form { display: inline; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; vertical-align: middle; text-decoration: none; }
.button[hidden] { display: none; }
.subtabs.button-row { margin-bottom: 18px; }
[data-return-fallback] { margin-bottom: 18px; }

button, .button {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover, .button.primary:hover { background: var(--accent-dark); }
button.danger { color: var(--danger); border-color: #e0c3c1; }
button.small { padding: 3px 8px; font-size: 12px; }
.linklike { border: none; background: none; color: var(--accent-dark); padding: 0; }

.form .field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
/* The ``display: flex`` above outranks the browser's own ``[hidden]`` rule,
   so the billing-only e-invoice block needs an explicit hidden state. */
.form [data-e-invoice-fields][hidden] { display: none; }
.form label { font-weight: 600; font-size: 13px; }
.form input, .form select, .form textarea {
  font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px;
  background: #fff; max-width: 520px;
}
.form-actions { margin-top: 8px; display: flex; gap: 8px; }

.inline-form { display: inline-flex; align-items: center; gap: 8px; margin-top: 12px; }
.inline-form select, .inline-form input { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; }
/* Product / package picker: a wrapping row with the label above its control,
   so the three selects and the two buttons never overflow on a narrow page. */
.inline-form.picker { flex-wrap: wrap; align-items: flex-end; }
.inline-form.picker .field { display: flex; flex-direction: column; gap: 4px; }
.inline-form.picker .field label { font-weight: 600; font-size: 13px; }
.inline-form.picker select, .inline-form.picker input { max-width: 260px; }

.searchbar { display: flex; gap: 8px; margin-bottom: 14px; }
.searchbar input { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; width: 280px; }

/* List visibility filter: the default view hides test and archived rows, and
   each other view is one explicit link. */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters .filter {
  font-size: 13px; padding: 4px 10px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--panel); color: var(--muted);
}
.filters .filter.active { border-color: var(--accent); color: var(--ink); font-weight: 600; }

/* Compact carrier record: a native disclosure keeps the status line visible
   and puts the frozen facts one click away. */
.posti-details > summary {
  cursor: pointer; font-weight: 600; display: flex; align-items: center;
  gap: 8px; flex-wrap: wrap;
}
.posti-details[open] > summary { margin-bottom: 10px; }
.posti-details .meta { margin-top: 4px; }

.meta { display: grid; grid-template-columns: 200px 1fr; gap: 4px 12px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.totals { display: grid; grid-template-columns: 260px 140px; gap: 4px 12px; justify-content: end; margin: 16px 0 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }

.badge {
  display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 3px;
  background: #eef1f4; color: var(--muted); margin-left: 6px;
}
.badge.status-draft { background: #fdf3dc; color: var(--warn); }
.badge.status-confirmed { background: #dff0e4; color: #256b3a; }
.badge.superseded { background: #f6e2e0; color: var(--danger); }
.badge.current { background: #dff0e4; color: #256b3a; }
/* Manual price override: a real, accessible red marker. The dark text on the
   pale red keeps AA contrast, and the title/text carries the explanation. */
.badge.badge-override {
  background: #f6e2e0; color: #8b1f1a; border: 1px solid #d8a9a4;
  font-weight: 600;
}
.price-override-note { margin: 8px 0; }
/* Row actions: keep the Muokkaa link and the Poista form on one line without
   collapsing the table cell, and give each control a visible focus ring. */
.row-actions { display: inline-flex; gap: 6px; align-items: center; }
.row-actions form { display: inline; margin: 0; }
.row-actions a:focus-visible,
.row-actions button:focus-visible {
  outline: 3px solid #1f6f8b;
  outline-offset: 2px;
}

/* Same-page row editor. Muokkaa turns the row's own cells into controls and
   writes the computed GTIN, piece count, unit price and total back into those
   same cells, so the table never grows a trailing editor column or a second
   row. Every control is associated with the row's one form through
   form="row-edit-form-<pk>"; the form element itself stays inside the actions
   cell and never wraps a tr or a td. */
tr[data-inline-row] .cell-edit {
  display: none;
}
tr[data-inline-row][data-inline-editing] .cell-display {
  display: none;
}
tr[data-inline-row][data-inline-editing] .cell-edit {
  display: block;
}
/* ``shipments/layout.css`` loads after this sheet and still carries a
   narrow-screen stack written for the old details-based editor; the
   row-scoped selectors keep this editor's sizing authoritative. */
tr[data-inline-row] .row-edit-form {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  width: auto;
  max-width: 16rem;
}
tr[data-inline-row] .row-edit-control {
  font: inherit;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  max-width: 100%;
}
tr[data-inline-row] .row-edit-product {
  width: 12rem;
}
tr[data-inline-row] .row-edit-package {
  width: 5.5rem;
}
tr[data-inline-row] .row-edit-qty {
  width: 4.5rem;
}
tr[data-inline-row] .row-edit-price {
  width: 7rem;
  text-align: right;
}
tr[data-inline-row] .row-edit-computed {
  display: inline-block;
  min-width: 0;
}
tr[data-inline-row] .row-edit-form .field.checkbox {
  display: inline-flex;
  flex-direction: row;
  align-items: baseline;
  flex-basis: 100%;
  max-width: 14rem;
  font-size: 13px;
}
tr[data-inline-row] .row-edit-form .field.checkbox label {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
tr[data-inline-row] .row-edit-buttons {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
tr[data-inline-row] .row-edit-form [data-inline-error] {
  flex-basis: 100%;
  color: var(--danger);
}
/* The saved action controls keep a bounded trailing area: the Muokkaa trigger
   and the row's own forms wrap inside the cell instead of stretching the last
   column. */
tr[data-inline-row]:not([data-inline-editing]) .row-actions-cell .cell-display.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 14rem;
}

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.message { padding: 10px 14px; border-radius: 4px; margin-bottom: 8px; border: 1px solid var(--line); background: var(--panel); }
.message.error { border-color: #e0c3c1; color: var(--danger); }
.message.success { border-color: #bcd9c6; color: #256b3a; }

/* Floating feedback: pinned to the viewport so a scrolled page never hides a
   success or validation message. Rendered server-side, so it is visible even
   without JavaScript. */
.messages.floating {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  width: min(680px, calc(100% - 24px));
  margin: 0;
  pointer-events: none;
}
.messages.floating .message {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(28, 39, 51, 0.18);
}
/* ``display: flex`` above would otherwise outrank the browser's own
   ``[hidden]`` rule, so dismissing one of several messages must hide it
   explicitly while the others stay visible. */
.messages.floating[hidden],
.messages.floating .message[hidden] { display: none; }
.messages.floating .message-text { flex: 1 1 auto; }
.message-dismiss {
  flex: 0 0 auto;
  padding: 2px 8px;
  font-size: 12px;
  border: 1px solid currentColor;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.message-dismiss:hover { background: rgba(28, 39, 51, 0.08); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.help { color: var(--muted); font-size: 12px; margin: 0; }
.empty { color: var(--muted); padding: 12px 0; }

/* Ambiguous legacy package factor: a stable, non-alarming explanation instead
   of a guessed quantity. The page is read-only; nothing here is an action. */
.conflict-banner {
  border: 1px solid #e0c3c1;
  border-left: 4px solid var(--danger);
  border-radius: 4px;
  background: var(--panel);
  color: var(--danger);
  padding: 10px 14px;
  margin: 0 0 12px;
}
.conflict-banner p { margin: 0; }
.conflict-list { margin: 0 0 12px; padding-left: 20px; }
.conflict-list li { margin-bottom: 4px; }

.logo-thumb { max-height: 32px; max-width: 90px; }
.logo-placeholder {
  display: inline-block; padding: 4px 10px; border: 1px dashed var(--line);
  border-radius: 3px; color: var(--muted); font-size: 12px;
}

.status-card.state-ok { border-left: 4px solid #256b3a; }
.status-card.state-stale { border-left: 4px solid var(--warn); }
.status-card.state-error { border-left: 4px solid var(--danger); }
.status-card.state-never { border-left: 4px solid var(--line); }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  padding: 28px; width: 340px;
}
.login-card h1 { font-size: 20px; margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.stack input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; }
.stack button { margin-top: 10px; }

.errorlist { color: var(--danger); font-size: 12px; list-style: none; padding: 0; margin: 0; }

/* Customer price grid: the effective-price source under each entry and the
   per-shipment header row of the draft repricing preview. */
.price-source { display: block; margin-top: 2px; }
.preview-head td { background: rgba(28, 39, 51, 0.05); font-weight: 600; }

/* ---------------------------------------------------------------------------
   Narrow viewports (proven by the local browser QA pass: the document width
   equals the viewport at 390 px, nothing is clipped on the left).

   * the top bar was one non-wrapping flex row, so every page was wider than a
     phone screen; the navigation now moves to its own row;
   * a wide data table scrolls inside its own card (wrap the table in
     ``.table-scroll``) instead of stretching the document;
   * the page-head action row wraps instead of running off the screen.
   --------------------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto;
}

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 6px 16px;
  }

  .mainnav {
    order: 3;
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .userbox {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .page-head {
    flex-wrap: wrap;
  }

  /* Action rows inside cards (prices, stock, Posti) wrap like the page head. */
  .button-row {
    flex-wrap: wrap;
  }

  /* ``shipments/layout.css`` (loaded after this sheet) still stacks the old
     details-based editor with ``.row-edit-form input { width: 100% }`` at this
     width; a checkbox must keep its intrinsic size. */
  tr[data-inline-row] .row-edit-form .field.checkbox input {
    width: auto;
    max-width: none;
    flex: 0 0 auto;
    margin: 0;
    box-sizing: content-box;
  }

  tr[data-inline-row]:not([data-inline-editing]) .row-actions-cell .cell-display.row-actions {
    max-width: 12rem;
  }
}

/* ---------------------------------------------------------------------------
   Working-warehouse forms and tables at phone widths (360/390/430 px).

   * the reservation/transfer line editor becomes a stacked card per row so
     the product selector, the package count and the computed pieces fit
     without horizontal clipping;
   * the ledger filter grid drops to a single column;
   * the reusable package controls keep a usable tap target (44 px).
   --------------------------------------------------------------------------- */
.ledger-filters .filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px 16px;
}

.card-subheading {
  margin: 12px 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
}

/* The final stock-consumption action is visually the destructive last step. */
.consume-final {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
}

.consume-final:hover {
  background: #6f1d1a;
  border-color: #6f1d1a;
  color: #fff;
}

@media (max-width: 480px) {
  .ledger-filters .filter-grid {
    grid-template-columns: 1fr;
  }

  .line-editor table.data,
  .line-editor table.data thead,
  .line-editor table.data tbody,
  .line-editor table.data tr,
  .line-editor table.data td,
  .line-editor table.data th {
    display: block;
    width: 100%;
  }

  .line-editor table.data thead {
    display: none;
  }

  .line-editor table.data tr[data-line-row] {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 8px;
  }

  .line-editor table.data td {
    border: none;
    padding: 4px 0;
  }

  .line-editor select,
  .line-editor input[type="number"],
  .card .inline-form select,
  .card .inline-form input[type="text"],
  .card .inline-form input[type="number"] {
    width: 100%;
    max-width: none;
    min-height: 44px;
  }

  /* The row editor keeps a definite control width so a long product label
     cannot blow up its column; only the tap target grows. */
  tr[data-inline-row] .row-edit-control {
    min-height: 44px;
  }

  tr[data-inline-row] .row-edit-product {
    width: 10rem;
  }
}

/* W2 freshness: an honest, quiet indicator without changing the data layout. */
.freshness-strip {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 13px;
}

.stock-cell.is-dirty {
  background: #fff7e6;
}

.stock-cell.is-unknown {
  background: #f3f5f7;
}

.stock-cell.is-error {
  background: #fdeceb;
}

.freshness-flag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fdf3dc;
  color: var(--warn);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.freshness-note {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stock-states {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.stock-states summary {
  cursor: pointer;
  color: var(--accent-dark);
}

.stock-states dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 2px 8px;
  margin: 4px 0 0;
}

.stock-states dt {
  color: var(--muted);
}

.stock-availability {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef1f4;
  color: var(--muted);
  font-size: 11px;
}

.stock-availability[data-stock-state="clean"] {
  background: #e7f3ec;
  color: #1c6b46;
}

.stock-availability[data-stock-state="updating"],
.stock-availability[data-stock-state="last_known"] {
  background: #fdf3dc;
  color: var(--warn);
}

/* ---------------------------------------------------------------------------
   Final polish: persistent error states, unsaved preview markers, the logout
   control and the in-page dirty-navigation dialog. Errors never rely on colour
   alone: a leading "Virhe:" word and a border carry the meaning too.
   --------------------------------------------------------------------------- */
.error,
.errorlist,
[data-inline-error] {
  color: #8a1f1f;
}

p.error,
div.error,
.card .error,
.inline-error {
  background: #fdecec;
  border: 1px solid #d99a9a;
  border-left: 4px solid var(--danger);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0;
}

p.error::before,
div.error::before,
.card .error::before,
.inline-error::before {
  content: "Virhe: ";
  font-weight: 600;
}

[data-inline-error] {
  background: #fdecec;
  border: 1px solid #d99a9a;
  border-radius: 4px;
  padding: 6px 10px;
}

[data-inline-error]::before {
  content: "Virhe: ";
  font-weight: 600;
}

.message.error {
  background: #fdecec;
  border: 1px solid #d99a9a;
  border-left: 4px solid var(--danger);
  color: #8a1f1f;
}

.logout-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.logout-link .icon-power {
  flex: 0 0 auto;
}

/* An unsaved customer / price-group preview written onto the saved cells. It
   never mutates a reservation or a stored price: the values are marked and
   revert when the selection is discarded. */
[data-inline-preview],
.cell-display.is-preview,
[data-price-preview-cell] {
  position: relative;
}

.is-preview::after {
  content: "Esikatselu";
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0;
  color: #8a5a12;
}

.preview-value {
  color: #8a5a12;
}

[data-freight-grand].is-preview,
[data-freight-cost].is-preview {
  color: #8a5a12;
}

/* Three-choice exit dialog: Tallenna ja jatka / Poistu tallentamatta /
   Jatka muokkausta. Shown over the page for an in-page link, Palaa or the
   logout form while an editable form is dirty. */
.dirty-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 33, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}

.dirty-dialog {
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(15, 23, 32, 0.28);
  max-width: 26rem;
  width: 100%;
  padding: 18px 20px;
}

.dirty-dialog h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.dirty-dialog p {
  margin: 0 0 14px;
}

.dirty-dialog .dirty-dialog-error {
  background: #fdecec;
  border: 1px solid #d99a9a;
  border-left: 4px solid var(--danger);
  border-radius: 4px;
  color: #8a1f1f;
  padding: 8px 10px;
  margin: 0 0 12px;
}

.dirty-dialog .dirty-dialog-error::before {
  content: "Virhe: ";
  font-weight: 600;
}

.dirty-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* Readable audit detail, independent of narrow ledger columns. */
.audit-dialog { width: min(900px, calc(100vw - 32px)); max-height: 85vh; overflow: auto; padding: 24px; border: 1px solid #d3dce5; border-radius: 14px; box-sizing: border-box; color: #18384b; }
.audit-dialog::backdrop { background: rgba(12, 30, 45, .45); }
.audit-dialog dd, .audit-dialog td, .audit-dialog p { overflow-wrap: anywhere; white-space: normal; }
.audit-dialog .table-scroll { overflow-x: auto; max-width: 100%; }
.audit-dialog .meta { display: grid; grid-template-columns: minmax(110px, 30%) minmax(0, 1fr); }
.audit-dialog dd { min-width: 0; margin-left: 0; }

.unified-lines .price-override { color: var(--danger); }
.unified-header { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 24px; }
.unified-header .field { min-width: 0; }
.unified-header .field-wide, .unified-header > .error { grid-column: 1 / -1; }
.unified-header input, .unified-header select, .unified-header textarea { width: 100%; max-width: none; }
.unified-header > p { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.unified-header > p input, .unified-header > p select { margin-top: 4px; }
.unified-add-line { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.unified-add-line .form-grid { display: grid; grid-template-columns: minmax(180px, 2fr) repeat(4, minmax(100px, 1fr)); gap: 12px; align-items: end; }
.unified-add-line .form-grid label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.unified-add-line .form-grid input, .unified-add-line .form-grid select { width: 100%; min-width: 0; }
.delivery-batch > summary { cursor: pointer; font-weight: 600; }
.delivery-batch[open] > summary { margin-bottom: 16px; }
.delivery-batch > form, .delivery-batch > .button { margin-top: 12px; margin-right: 8px; }
.delivery-batch > form { display: inline-flex; vertical-align: middle; }
.document-links { margin: 16px 0 8px; }
.badge.delivery-complete { color: #256b3a; background: #dff0e4; }
.badge.delivery-backorder { color: #805400; background: #fdf3dc; }
.badge.delivery-ready { color: #17576d; background: #e2f0f7; }
.badge.delivery-review { color: #a32121; background: #fdeaea; }
.badge.delivery-draft { color: #1e40af; background: #dbeafe; }
.badge.delivery-cancelled { color: #596575; background: #eef1f4; }
.shipment-delivery-state { margin-top: 8px; }
.dialog-piece-summary { padding: 10px 12px; background: #e2f0f7; border-radius: 4px; color: #17576d; font-weight: 600; font-size: 14px; }
.actions a { display: inline-block; margin: 3px 8px 3px 0; }
@media (max-width: 1000px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; }
  .brand { white-space: nowrap; }
  .topbar-inner .userbox { margin-left: auto; }
  .mainnav { flex-basis: 100%; order: 3; flex-wrap: wrap; }
}
@media (max-width: 760px) {
  .unified-header { grid-template-columns: minmax(0, 1fr); }
  .unified-add-line .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .unified-add-line .form-grid label:first-child { grid-column: 1 / -1; }
}
.unified-lines .inline-form { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.unified-lines td input[type="number"] { width: 100%; max-width: 7rem; box-sizing: border-box; font: inherit; }
.unified-lines td select { width: 100%; min-width: 0; max-width: 100%; font: inherit; }
@media (min-width: 761px) {
  .unified-lines { table-layout: fixed; }
  .unified-lines th, .unified-lines td { overflow-wrap: anywhere; }
  .unified-lines th:nth-child(1) { width: 20%; }
  .unified-lines th:nth-child(2) { width: 9%; }
  .unified-lines th:nth-child(3) { width: 10%; }
  .unified-lines th:nth-child(4) { width: 12%; }
  .unified-lines th:nth-child(5) { width: 12%; }
  .unified-lines th:nth-child(6) { width: 10%; }
  .unified-lines th:nth-child(7) { width: 8%; }
  .unified-lines th:nth-child(8) { width: 19%; }
  .preparing-lines th:nth-child(1) { width: 22%; }
  .preparing-lines th:nth-child(2) { width: 10%; }
  .preparing-lines th:nth-child(3) { width: 13%; }
  .preparing-lines th:nth-child(4) { width: 12%; }
  .preparing-lines th:nth-child(5) { width: 16%; }
  .preparing-lines th:nth-child(6) { width: 13%; }
  .preparing-lines th:nth-child(7) { width: 14%; }
}

/* The existing list moves into the native modal top layer. */
dialog .messages.floating.dialog-feedback { position: sticky; top: 0; left: auto; transform: none; width: 100%; padding: 0; max-height: 35dvh; overflow: auto; }
.messages.floating { max-height: min(45dvh, 380px); overflow: auto; }
.messages.floating .message-text { min-width: 0; overflow-wrap: anywhere; }

/* Grouped stock navigation (Varasto): five top-level group tabs, and only the
   active group's children. Plain document flow only (no order/reorder), so the
   reading order stays the same at 200% zoom, on mobile and in the DOM. */
.stock-nav { margin: 0 0 16px; }
.stock-nav-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 2px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.stock-nav-tab { display: inline-flex; align-items: center; padding: 5px 11px; border-radius: 4px 4px 0 0; text-decoration: none; color: var(--muted); font-weight: 600; }
.stock-nav-tab:hover { background: #eef2f4; color: var(--ink); }
.stock-nav-tab.active { color: var(--accent-dark); background: #eaf3f6; box-shadow: inset 0 -2px 0 var(--accent); }
.stock-nav-children { padding: 10px 0 2px; }
.stock-nav-children .button-row { gap: 4px; margin: 0; }
.stock-nav-children .button { padding: 4px 9px; }
.stock-nav-admin { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.stock-nav-admin > summary { cursor: pointer; font-size: 11px; font-weight: 700; color: #5b6b73; }
.stock-nav-admin .button-row { gap: 4px; margin: 8px 0 0; }
@media (max-width: 760px) {
  .stock-nav-tab { padding: 5px 8px; }
}
