/* NELCON warehouse viewer: white, minimal, compact. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #111111;
  --muted: #8a8a8a;
  --soft: #555555;
  --line: #ededed;
  --line-strong: #dcdcdc;
  --hover: #f7f7f7;
  --green: #1f9d55;
  --red: #d64545;
  --amber: #c98a0a;
  --blue: #2f6fdb;
  --violet: #7c4dcc;
  --grey: #b5b5b5;
  --header-h: 44px;
  --gutter: 24px;
}

* { box-sizing: border-box; }

html, body { background: var(--bg); }
body {
  margin: 0;
  color: var(--text);
  font: 13px/1.4 Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 var(--gutter);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .08em; font-size: 12px; }
.brand span { font-weight: 400; color: var(--muted); letter-spacing: .02em; margin-left: 4px; }
.brand:hover { text-decoration: none; }
.topbar nav a { font-size: 12px; color: var(--muted); }
.topbar nav a.active { color: var(--text); }
.topbar nav a:hover { color: var(--text); text-decoration: none; }

.container { padding: 16px var(--gutter) 24px; }

/* Type */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; font-size: 12px; }
h2 { margin: 0 0 8px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; gap: 8px; }
h3 { margin: 12px 0 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
p { margin: 0 0 2px; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.nowrap { white-space: nowrap; }
.mono { font-family: "JetBrains Mono", Consolas, "Cascadia Mono", monospace; font-size: 12px; }
.pad { padding: 0; }

/* Sections */
.card { padding: 0; margin-bottom: 20px; }
.table-card { margin-bottom: 20px; }

/* Summary numbers */
.cards {
  display: flex; flex-wrap: wrap;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.cards .card { margin: 0; padding: 8px 20px; border-left: 1px solid var(--line); }
.cards .card:first-child { border-left: 0; padding-left: 0; }
.stat { display: flex; align-items: baseline; gap: 8px; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 11px; color: var(--muted); font-weight: 400; }
.stat-value.warn { color: var(--amber); }
.stat-link:hover { text-decoration: none; }
.stat-link:hover .stat-label { color: var(--text); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.filters .grow { flex: 0 1 360px; }
input, select {
  height: 30px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 4px;
  background: #fff; color: var(--text); font: inherit; font-size: 12px;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--text); }
.date-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 4px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text); font: inherit; font-size: 12px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--text); }
.btn.primary { background: var(--text); border-color: var(--text); color: #fff; }
.btn.primary:hover { background: #333; }
.btn.disabled { color: var(--muted); border-color: var(--line); cursor: default; }
.btn.ghost { border-color: transparent; color: var(--muted); padding: 0 6px; }
.btn.ghost:hover { color: var(--text); }

/* Tables */
.table-meta { padding: 0 0 6px; color: var(--muted); font-size: 12px; }
.table-meta strong { color: var(--text); font-weight: 600; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
  padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { padding-left: 0; }
table.data th:last-child, table.data td:last-child { padding-right: 0; }
table.data th {
  position: sticky; top: 0; z-index: 1; background: #fff; box-shadow: inset 0 -1px 0 var(--line-strong);
  border-bottom: 0; font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em;
}
table.data th a:hover { color: var(--text); text-decoration: none; }
table.data tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
td.notes { width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
table.data td.wrap { white-space: normal; min-width: 160px; }
table.data td.wrap-any { white-space: normal; overflow-wrap: anywhere; min-width: 130px; }
td.empty { text-align: center; color: var(--muted); padding: 32px; }
.doc { font-weight: 600; }

/* Totals bar under the list table */
.totals-bar {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 28px;
  padding: 10px 0 12px; border-top: 1px solid var(--line-strong);
  font-size: 12px; font-variant-numeric: tabular-nums; background: #fff;
}
.totals-bar strong { font-weight: 600; font-size: 13px; }
.totals-title { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

/* Badges: dot + text, no fill */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; color: var(--soft); white-space: nowrap;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--grey); flex: none;
}
.status-open::before { background: var(--blue); }
.status-closed::before { background: var(--grey); }
.type-ocean::before { background: var(--blue); }
.type-air::before { background: var(--violet); }
.type-sc::before { background: var(--text); }
.type-pending::before { background: var(--amber); }
.check-ok { color: var(--green); }
.check-ok::before { background: var(--green); }
.check-mismatch { color: var(--red); }
.check-mismatch::before { background: var(--red); }
.check-no-detail { color: var(--muted); }

/* List page: fit the viewport, only the table scrolls */
@media (min-width: 992px) {
  body.fit { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  body.fit .container { flex: 1; min-height: 0; display: flex; flex-direction: column; padding-bottom: 0; }
  body.fit .table-card { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; }
  body.fit .table-wrap { flex: 1; min-height: 0; overflow: auto; }
  body.fit table.data tbody tr:last-child td { border-bottom: 0; }
}

/* Receipt page */
.back { font-size: 12px; color: var(--muted); }
.back:hover { color: var(--text); text-decoration: none; }
.notice { border-left: 2px solid var(--amber); padding: 3px 10px; margin-bottom: 10px; color: var(--soft); }

.detail-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 12px; }
.detail-head .meta { font-size: 12px; }
.detail-head .spacer { flex: 1; }

.detail-top {
  display: grid; grid-template-columns: 1fr 1fr 1fr 1.2fr;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 10px;
}
.detail-top .party { padding: 10px 16px; border-left: 1px solid var(--line); min-width: 0; }
.detail-top .party:first-child { border-left: 0; padding-left: 0; }
.detail-top .party:last-child { padding-right: 0; }
.party h2 { margin-bottom: 6px; }
.notes-block { max-height: 150px; overflow-y: auto; }
.note + .note { margin-top: 6px; }
.note-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.note p { color: var(--text); font-size: 12px; overflow-wrap: anywhere; }
.party-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.party p { color: var(--soft); font-size: 12px; }
.party .party-name { color: var(--text); font-size: 13px; }
.code { font-family: Consolas, monospace; font-size: 10.5px; color: var(--muted); text-transform: none; letter-spacing: 0; font-weight: 400; }
.code::before { content: "("; } .code::after { content: ")"; }

table.totals { width: 100%; border-collapse: collapse; font-size: 12px; }
table.totals th, table.totals td { padding: 2px 0 2px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.totals th:first-child, table.totals td:first-child { padding-left: 0; }
table.totals th { color: var(--muted); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; text-align: left; border-bottom-color: var(--line-strong); }
table.totals td:first-child { color: var(--muted); }
table.totals tr:last-child td { border-bottom: 0; }

.fields {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px 16px;
  padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line);
}
.field { display: flex; flex-direction: column; min-width: 0; }
.field.wide { grid-column: span 3; }
.field-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.field-value { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field.wide .field-value { white-space: normal; }

.detail-bottom { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 28px; }
.doc-links { display: inline-flex; gap: 6px; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane h2 { margin-bottom: 4px; }
.pane p.muted { font-size: 12px; }
.detail table.data th, .detail table.data td { padding: 5px 8px; }
.detail table.data th:first-child, .detail table.data td:first-child { padding-left: 0; }

.image-section { margin-top: 20px; }
.screenshot { max-width: 100%; border: 1px solid var(--line); }
.empty-state { text-align: center; padding: 60px 0; }
.empty-state h1 { justify-content: center; }

/* Receipt page on desktop: fits the viewport; pieces / invoices scroll inside their panes */
@media (min-width: 992px) {
  body.detail .container { padding-bottom: 12px; }
  body.detail .detail-bottom { flex: 1; min-height: 0; }
  body.detail .pane .table-wrap { flex: 1; min-height: 0; overflow: auto; }
  body.detail .image-section { display: none; }
}

@media (max-width: 991.98px) {
  :root { --gutter: 16px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .grid-3 .card { border-left: 0; padding: 12px 0; border-top: 1px solid var(--line); }
  .grid-3 .card:first-child { border-top: 0; }
  .cards .card { padding: 6px 12px; }
  td.notes { max-width: 260px; }
  .detail-top { grid-template-columns: 1fr; }
  .detail-top .party { border-left: 0; padding: 10px 0; border-top: 1px solid var(--line); }
  .detail-top .party:first-child { border-top: 0; }
  .detail-bottom { grid-template-columns: 1fr; gap: 16px; }
  .field.wide { grid-column: 1 / -1; }
}

/* Consignee <-> contact link: × / + are bare symbols shown only while hovering the name */
.consignee { display: inline-flex; align-items: center; gap: 2px; }
.contact-name { border-bottom: 1px dotted var(--line-strong); }
.icon-btn {
  display: inline-grid; place-items: center; width: 16px; height: 16px; padding: 0; line-height: 1;
  border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; flex: none;
}
.icon-btn:hover { color: var(--text); }
.consignee .icon-btn { visibility: hidden; }
.consignee:hover .icon-btn, .consignee .icon-btn:focus-visible { visibility: visible; }
@media (hover: none) { .consignee .icon-btn { visibility: visible; } }  /* touch screens: no hover */

dialog.picker {
  width: min(520px, calc(100vw - 32px)); padding: 16px; border: 1px solid var(--line-strong); border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .12); color: var(--text);
}
dialog.picker::backdrop { background: rgba(0, 0, 0, .15); }
.picker-head { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; }
.picker-head .icon-btn { margin-left: auto; width: 22px; height: 22px; font-size: 14px; }
.picker input { width: 100%; margin: 8px 0; }
.picker-results { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; border-top: 1px solid var(--line); }
.picker-results li { border-bottom: 1px solid var(--line); }
.picker-results li.muted { padding: 10px 0; font-size: 12px; }
.picker-results button {
  display: flex; flex-direction: column; gap: 1px; width: 100%; padding: 7px 4px; text-align: left;
  background: none; border: 0; font: inherit; cursor: pointer; color: var(--text);
}
.picker-results button:hover { background: var(--hover); }
.picker-name { font-weight: 500; }

/* Bulk selection */
table.data th.sel, table.data td.sel { width: 22px; padding-right: 4px; cursor: default; }
table.data td.sel input, table.data th.sel input { margin: 0; vertical-align: middle; cursor: pointer; }
.bulk-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-bottom: 6px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: var(--hover); font-size: 12px;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .btn { height: 26px; }

dl.kv { display: grid; grid-template-columns: 120px 1fr; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Status history card */
.freight { padding-bottom: 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line-strong); }
.freight-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.freight-type { font-weight: 600; font-size: 13px; margin-right: 4px; }
.tag {
  display: inline-block; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 4px;
  font-size: 11px; line-height: 16px; color: var(--soft); background: #fff; white-space: nowrap;
}
.tag.muted { color: var(--muted); border-color: var(--line); }
.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.leg { display: grid; grid-template-columns: auto; gap: 1px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--hover); }
.leg-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.leg-date { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.leg-status { font-size: 12px; color: var(--soft); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.timeline li.day {
  padding: 8px 0 3px; font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .07em;
  border-bottom: 1px solid var(--line-strong);
}
.timeline li.event { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.timeline li.event .time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.timeline li.event .text { overflow-wrap: anywhere; }
.timeline li.event.latest .text { font-weight: 600; }
.timeline .tag { margin-left: 4px; font-weight: 400; }

/* Fetch from NELCON */
.head-actions { display: flex; gap: 8px; }
.fetch-dialog { width: min(560px, calc(100vw - 32px)); }
.fetch-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-top: 8px; }
.fetch-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.fetch-form label.wide { grid-column: 1 / -1; }
.fetch-form label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); grid-column: 1 / -1; }
.fetch-form input, .fetch-form select { width: 100%; }
.fetch-form label.check input { width: auto; height: auto; }
.fetch-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
#fetch-error { color: var(--red); }
.fetch-status {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; margin-bottom: 10px; font-size: 12px;
  border: 1px solid var(--line-strong); border-radius: 4px; background: var(--hover);
}
.fetch-status[hidden] { display: none; }
.fetch-status .bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.fetch-status .bar span { display: block; height: 100%; background: var(--text); width: 0; transition: width .3s; }
.fetch-status.ok { border-color: var(--green); }
.fetch-status.error { border-color: var(--red); color: var(--red); }

/* Airtable-style filter builder */
.btn.active { border-color: var(--text); font-weight: 600; }
.filter-anchor { position: relative; }
.filter-panel {
  position: absolute; top: calc(100% - 6px); left: 0; z-index: 30;
  width: min(880px, calc(100vw - 2 * var(--gutter))); max-height: min(70vh, 640px); overflow: auto;
  padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .14); font-size: 12px;
}
.filter-panel::before {  /* small caret under the Filter button */
  content: ""; position: absolute; top: -6px; left: var(--caret-left, 24px); width: 10px; height: 10px;
  background: #fff; border-left: 1px solid var(--line-strong); border-top: 1px solid var(--line-strong); transform: rotate(45deg);
}
.filter-panel[hidden] { display: none; }
.f-group { display: flex; flex-direction: column; gap: 6px; }
.f-group.nested { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--hover); }
.f-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.f-row > .f-conj { width: 64px; flex: none; color: var(--muted); }
.f-row > .f-conj select { width: 64px; }
.f-row select, .f-row input { height: 28px; padding: 0 6px; font-size: 12px; }
.f-row select.f-field { width: 170px; }
.f-row select.f-op { width: 150px; }
.f-row input.f-value, .f-row select.f-value { width: 180px; }
.f-row input[type=date].f-value { width: 140px; }
.f-row input[type=number].f-value { width: 90px; }
.f-row .f-multi { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; }
.f-row .f-multi label { display: inline-flex; align-items: center; gap: 4px; }
.f-row .f-multi input { width: auto; height: auto; }
.f-row .f-nested { flex: 1; min-width: 0; }
.f-remove { margin-left: auto; }
.f-actions { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.f-actions .spacer { flex: 1; }
.f-add { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 2px 4px; }
.f-add:hover { color: var(--text); }
.f-empty { color: var(--muted); padding: 2px 0 6px; }
.f-error { color: var(--red); }

/* Sign-in page */
.nav-user { font-size: 12px; color: var(--muted); margin: 0 10px 0 16px; }
body.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); }
.login-box { width: min(340px, calc(100vw - 32px)); padding: 32px 28px; border: 1px solid var(--line); border-radius: 8px; }
.login-box .brand { font-size: 12px; margin-bottom: 24px; }
.login-box h1 { font-size: 20px; margin: 0 0 20px; }
.login-box form { display: flex; flex-direction: column; gap: 14px; }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.login-box input { height: 36px; font-size: 14px; }
.login-box .btn { height: 38px; justify-content: center; font-size: 13px; margin-top: 4px; }
.login-error { color: var(--red); font-size: 12px; margin: 0; }

/* Invoices tab: the invoice app fills the page under the header */
body.invoices-tab .container { padding: 0; }
.embedded-app { display: block; width: 100%; height: calc(100vh - var(--header-h) - 1px); border: 0; }
@media (min-width: 992px) { body.invoices-tab .embedded-app { flex: 1; height: auto; min-height: 0; } }

/* Receipts / Invoices switch in the header */
.topbar nav { display: flex; align-items: center; }
.switch { display: inline-flex; padding: 2px; border: 1px solid var(--line-strong); border-radius: 999px; background: #fff; }
.topbar nav .switch a {
  padding: 4px 14px; border-radius: 999px; font-size: 12px; font-weight: 500; color: var(--soft);
  opacity: 1; line-height: 18px; transition: background .15s, color .15s;
}
.topbar nav .switch a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.topbar nav .switch a.on, .topbar nav .switch a.on:hover { background: var(--text); color: #fff; }

/* Quick search runs as you type: dim the table while the results load */
body:has(.filters.loading) .table-wrap { opacity: .55; transition: opacity .15s; }

/* OAuth consent (AI assistant connections) */
.login-note { margin: -8px 0 16px; }
.consent-box { width: min(420px, calc(100vw - 32px)); }
.consent-box h1 { margin-bottom: 10px; }
.consent-box form { gap: 12px; }
.consent-scopes { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin: 4px 0 0; }
.consent-scopes legend { font-size: 11px; color: var(--muted); padding: 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.consent-scopes label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text); }
.consent-scopes input { height: auto; margin-top: 2px; }
.consent-actions { display: flex; gap: 8px; justify-content: flex-end; }
.consent-actions .btn { height: 36px; min-width: 96px; margin: 0; }
.topbar nav .nav-user + a { margin-right: 12px; }
.connections-card { flex: none; }
.connections-card form { margin: 0; }

/* ---------- Track: header button + sheet that folds up from the bottom ---------- */
.topbar nav .track-btn { margin-right: 10px; padding: 4px 14px; height: 28px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: #fff; color: var(--text); font: inherit; font-size: 12px; font-weight: 500; line-height: 18px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: background .15s, color .15s, border-color .15s; }
.topbar nav .track-btn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.topbar nav .track-btn:hover { background: var(--hover); }
.topbar nav .track-btn.on { background: var(--text); border-color: var(--text); color: #fff; }
.topbar nav .track-btn.on::before { background: #fff; }

.track-sheet { position: fixed; z-index: 80; left: 50%; bottom: 0; width: min(1120px, calc(100vw - 32px)); height: min(74vh, 720px);
  display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line-strong); border-bottom: 0;
  border-radius: 14px 14px 0 0; box-shadow: 0 -18px 50px rgba(0, 0, 0, .16);
  transform-origin: 50% 100%; transform: translateX(-50%) perspective(1400px) rotateX(-78deg) translateY(30%); opacity: 0;
  transition: transform .45s cubic-bezier(.2, .85, .25, 1), opacity .3s ease; }
.track-sheet.open { transform: translateX(-50%) perspective(1400px) rotateX(0deg) translateY(0); opacity: 1; }
.track-sheet[hidden] { display: none; }
.track-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 8px auto 0; flex: none; }
.track-head { display: flex; align-items: center; gap: 14px; padding: 10px 16px 12px; border-bottom: 1px solid var(--line); flex: none; }
.track-head strong { font-size: 14px; white-space: nowrap; }
.track-form { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.track-form input[type=search] { flex: 1; min-width: 0; height: 34px; font-size: 14px; letter-spacing: .02em; }
.track-form label.check { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--soft); }
.track-form .btn { height: 34px; }
.track-body { display: grid; grid-template-columns: 230px 1fr; flex: 1; min-height: 0; }
.track-history { border-right: 1px solid var(--line); overflow: auto; padding: 10px 8px; }
.track-history-head { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 6px;
  font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.track-history ul { list-style: none; margin: 0; padding: 0; }
.track-history li { display: flex; align-items: center; border-radius: 6px; }
.track-history li:hover, .track-history li.on { background: var(--hover); }
.track-history li.on .track-history-no { font-weight: 600; }
.track-history-item { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 6px 6px; border: 0;
  background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.track-history-no { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.track-history-meta { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.track-history-x { border: 0; background: none; color: var(--muted); font-size: 15px; padding: 0 8px; cursor: pointer; visibility: hidden; }
.track-history li:hover .track-history-x { visibility: visible; }
.track-history-x:hover { color: var(--text); }
.track-history-empty { padding: 0 6px; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; font-size: 11px; color: var(--soft); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; text-transform: none; letter-spacing: 0; }
.link-btn:hover { color: var(--text); }
.track-result { overflow: auto; padding: 16px 20px 20px; }
.track-placeholder { max-width: 560px; }
.stage-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--grey); }
.stage-dot.stage-done { background: var(--green); }
.stage-dot.stage-panama { background: var(--violet); }
.stage-dot.stage-transit { background: var(--blue); }
.stage-dot.stage-none { background: var(--red); }
.track-status { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; padding: 14px 16px;
  border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 8px; }
.track-status.tone-done { border-left-color: var(--green); }
.track-status.tone-panama { border-left-color: var(--violet); }
.track-status.tone-none { border-left-color: var(--red); }
.track-status h3 { margin: 2px 0 4px; font-size: 18px; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: 0; }
.track-status p { margin: 0; }
.track-no { font-size: 11px; color: var(--muted); letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.track-status-side { display: flex; align-items: center; gap: 8px; flex: none; }
.track-note { margin: 8px 2px 0; }
.track-alerts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge.warn { background: #fff4e0; color: var(--amber); }
.track-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin-top: 12px; }
.track-link { display: flex; flex-direction: column; gap: 2px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  color: inherit; transition: border-color .15s, background .15s; }
a.track-link:hover { border-color: var(--text); background: var(--hover); text-decoration: none; }
div.track-link { opacity: .75; }
.track-link-kind { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.track-link strong { font-size: 14px; }
.track-link .muted { font-size: 12px; }
.track-link-doc { font-size: 11px; color: var(--soft); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; align-self: flex-start; }
.track-section-head { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 6px; font-size: 11px;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.track-message p { margin: 0; padding: 10px 12px; background: var(--hover); border-radius: 8px; font-size: 13px; }
.track-timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.track-timeline li { display: grid; grid-template-columns: 118px 1fr; gap: 12px; padding: 7px 0 7px 14px; position: relative;
  border-left: 2px solid var(--line); }
.track-timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--blue); border: 2px solid #fff; }
.track-timeline li.stage-done::before { background: var(--green); }
.track-timeline li.stage-panama::before { background: var(--violet); }
.track-timeline li.stage-none::before { background: var(--red); }
.track-timeline p { margin: 2px 0 0; }
.track-when { font-size: 12px; color: var(--soft); font-variant-numeric: tabular-nums; padding-top: 1px; }
.track-foot { margin-top: 14px; }
.track-loading, .track-error { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border: 1px dashed var(--line-strong); border-radius: 8px; }
.track-error { flex-direction: column; gap: 6px; border-color: #f0c9c9; }
.track-loading p, .track-error p { margin: 4px 0 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--text); border-radius: 50%;
  animation: track-spin .8s linear infinite; flex: none; margin-top: 1px; }
@keyframes track-spin { to { transform: rotate(360deg); } }

@media (max-width: 991.98px) {
  .track-sheet { width: 100vw; height: 86vh; border-radius: 12px 12px 0 0; }
  .track-head { flex-wrap: wrap; gap: 8px; padding: 8px 12px 10px; }
  .track-form { order: 3; flex-basis: 100%; flex-wrap: wrap; }
  .track-head .icon-btn { margin-left: auto; }
  .track-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .track-history { border-right: 0; border-bottom: 1px solid var(--line); max-height: 118px; }
  .track-result { padding: 12px; }
  .track-timeline li { grid-template-columns: 1fr; gap: 2px; }
  .track-status { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  .track-sheet { transition: opacity .15s; transform: translateX(-50%); }
  .track-sheet.open { transform: translateX(-50%); }
}

/* ---------- Misplaced (DESCONOCIDO / UNKNOWN trackings) ---------- */
.topbar nav .misplaced-btn { text-decoration: none; }
.topbar nav .misplaced-btn::before { background: var(--amber); }
.topbar nav .misplaced-btn .count { margin-left: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--amber); color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.topbar nav .misplaced-btn.on .count { background: #fff; color: var(--text); }
.misplaced-bar { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.misplaced-bar input[type=search] { width: min(320px, 100%); height: 30px; }
.small-switch a { padding: 3px 12px; border-radius: 999px; font-size: 12px; color: var(--soft); }
.small-switch a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.small-switch a.on, .small-switch a.on:hover { background: var(--text); color: #fff; }
.small-switch .n { opacity: .7; margin-left: 3px; font-variant-numeric: tabular-nums; }
#misplaced-table tr.resolved td { color: var(--soft); }
#misplaced-table .status-cell { white-space: nowrap; }
#misplaced-table .track-open-row { font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
#misplaced-table .recheck { height: 26px; padding: 0 10px; font-size: 12px; }

/* unknown package requests (request.js) */
.request-dialog { width: min(600px, calc(100vw - 32px)); }
.request-dialog [hidden] { display: none !important; }   /* the form layout (display: flex/grid) must not undo hidden */
.req-previous { margin: 8px 0 4px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: #fffaf0; display: grid; gap: 4px; font-size: 12px; }
.req-result { margin-top: 10px; display: grid; gap: 4px; }
.req-result p { margin: 0; }
.req-file { margin-left: 6px; font-size: 12px; }
.badge.bad { background: #fdecec; color: var(--red, #b42318); }
.req-cell { white-space: nowrap; }
.req-cell .small { display: block; }

/* ======================================================================================================
   Phones and tablets: below 992 px (iPhone 16 Pro 402 × 874, Galaxy S25 FE 384 × 832, tablets in portrait)
   - header: Track and Misplaced stay, the rest goes into the ☰ menu (.nav-menu)
   - tables marked .m-cards become one card per row (labels from data-label)
   - summaries, totals, documents, parties and the Track history fold away; app.js toggles .m-open
   ====================================================================================================== */
.nav-toggle { display: none; }
.nav-menu { display: contents; }                      /* desktop: the menu items sit inline in the header */
.detail-docs { display: contents; }
.m-acc-trigger { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-transform: inherit;
  letter-spacing: inherit; cursor: default; }
.warn-text { color: var(--amber); }
@media (min-width: 992px) {
  .m-only { display: none !important; }
}

@media (max-width: 991.98px) {
  :root { --gutter: 12px; --header-h: 50px; --radius: 10px; }
  .m-hide { display: none !important; }
  .m-collapsible:not(.m-open) { display: none !important; }
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 13px; }

  /* inputs: 16 px so iOS does not zoom in on focus; taller touch targets */
  input, select, textarea { height: 38px; font-size: 16px; border-radius: 8px; }
  input[type=file] { height: auto; padding: 8px; font-size: 13px; }
  input[type=checkbox], input[type=radio] { height: auto; }
  .btn { height: 36px; padding: 0 14px; border-radius: 8px; font-size: 13px; }
  .btn.ghost { padding: 0 8px; }

  /* ---- header ---- */
  .topbar { position: sticky; top: 0; z-index: 60; gap: 8px; background: rgba(255, 255, 255, .96);
    -webkit-backdrop-filter: saturate(1.4) blur(8px); backdrop-filter: saturate(1.4) blur(8px);
    height: calc(var(--header-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) var(--gutter) 0; }
  .brand { flex: none; }
  .topbar nav { gap: 6px; min-width: 0; }
  .topbar nav .track-btn { margin-right: 0; height: 34px; padding: 0 12px; font-size: 13px; }
  .nav-toggle { display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; flex: none;
    width: 38px; height: 34px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 999px;
    background: #fff; cursor: pointer; }
  .nav-toggle span { display: block; height: 2px; border-radius: 2px; background: var(--text); transition: transform .2s, opacity .2s; }
  .nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .nav-menu { display: none; position: fixed; z-index: 59; left: 0; right: 0;
    top: calc(var(--header-h) + env(safe-area-inset-top)); flex-direction: column; align-items: stretch; gap: 2px;
    padding: 12px var(--gutter) calc(14px + env(safe-area-inset-bottom)); background: #fff;
    border-bottom: 1px solid var(--line); box-shadow: 0 16px 30px rgba(0, 0, 0, .10); }
  .nav-menu.m-open { display: flex; }
  .nav-menu .switch { display: flex; margin-bottom: 8px; }
  .topbar nav .nav-menu .switch a { flex: 1; text-align: center; padding: 8px 0; font-size: 14px; }
  .nav-menu .nav-user { margin: 4px 2px; font-size: 12px; }
  .topbar nav .nav-menu > a { display: block; padding: 11px 2px; margin: 0; border-top: 1px solid var(--line);
    font-size: 15px; color: var(--text); }

  /* ---- page ---- */
  .container { padding: 12px var(--gutter) calc(16px + env(safe-area-inset-bottom)); }
  .page-head { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
  .page-head > div { flex: 1 1 100%; min-width: 0; }
  .page-head p.muted { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  h1 { font-size: 17px; }
  .head-actions { display: flex; width: 100%; gap: 8px; }
  .head-actions .btn { flex: 1; justify-content: center; }

  /* a bar that opens a folded section (Summary) */
  .m-section-toggle, .totals-toggle { display: flex; align-items: center; gap: 10px; width: 100%; cursor: pointer;
    font: inherit; font-size: 12px; color: var(--text); text-align: left; }
  .m-section-toggle { height: 40px; padding: 0 12px; margin-bottom: 8px; border: 1px solid var(--line);
    border-radius: var(--radius); background: var(--hover); }
  .m-section-toggle > span:first-child { font-weight: 600; flex: none; }
  .m-section-toggle .muted { flex: 1; min-width: 0; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-section-toggle::after, .totals-toggle::after, .m-acc-head::after, .m-acc-trigger::after {
    content: ""; flex: none; width: 7px; height: 7px; margin: 0 2px 3px 0; border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); transition: transform .2s; }
  .m-section-toggle[aria-expanded="true"]::after, .m-open > .m-acc-head::after, .m-acc-trigger[aria-expanded="true"]::after,
  .totals-bar.m-open .totals-toggle::after { transform: rotate(-135deg); margin-bottom: -3px; }

  /* summary numbers: a 2-column grid once opened */
  .cards { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: var(--radius);
    margin-bottom: 10px; overflow: hidden; }
  .cards .card, .cards .card:first-child { padding: 8px 12px; border-left: 0; border-top: 1px solid var(--line); }
  .cards .card:nth-child(-n+2) { border-top: 0; }
  .cards .card:nth-child(even) { border-left: 1px solid var(--line); }
  .cards .card:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat { flex-direction: column; gap: 0; }

  /* filters: search + Filter + Clear on one line; the filter builder is a bottom sheet */
  .filters { flex-wrap: nowrap; gap: 6px; margin-bottom: 10px; }
  .filters .grow { flex: 1 1 auto; min-width: 0; }
  .filter-panel { position: fixed; z-index: 70; top: auto; bottom: 0; left: 0 !important; right: 0; width: 100%;
    max-height: 82dvh; border-radius: 16px 16px 0 0; padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -16px 40px rgba(0, 0, 0, .18); }
  .filter-panel::before { display: none; }
  .f-row { gap: 6px; }
  .f-row > .f-conj, .f-row > .f-conj select { width: 72px; }
  .f-row select.f-field, .f-row select.f-op, .f-row input.f-value, .f-row select.f-value,
  .f-row input[type=date].f-value, .f-row input[type=number].f-value { flex: 1 1 140px; width: auto; min-width: 0; }
  .f-row select, .f-row input { height: 38px; font-size: 16px; }
  .bulk-bar { flex-wrap: wrap; position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top) + 4px); z-index: 6; }
  .bulk-bar .btn { height: 32px; }

  /* ---- tables -> cards ---- */
  .table-wrap { overflow: visible; }
  table.m-cards, table.m-cards tbody, table.m-cards tfoot { display: block; }
  table.m-cards thead { display: none; }
  table.m-cards tr { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px 10px; padding: 10px 12px;
    margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
  /* placement stays low-specificity (td: one element), so each table's .c-* rules can size and order the cells */
  .m-cards td { display: block; grid-column: span 12; }
  table.data.m-cards td { min-width: 0; max-width: none; width: auto; padding: 0 !important; border: 0; white-space: normal;
    overflow-wrap: anywhere; text-align: left !important; }
  table.m-cards td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 1px; font-size: 10px;
    font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
  table.m-cards td.m-empty { display: none; }
  table.m-cards td.empty { grid-column: 1 / -1; padding: 24px 0 !important; text-align: center !important; }
  table.m-cards tr.clickable:hover td { background: none; }
  table.m-cards tr.clickable:active { background: var(--hover); }
  table.m-cards tr[hidden] { display: none; }
  table.m-cards tfoot tr { background: var(--hover); }
  table.m-cards tfoot td { border-top: 0; }

  table.data.m-cards td.c-date, table.data.m-cards td.c-recheck, table.data.m-cards td.c-result { text-align: right !important; }
  /* receipts list card: WR + date / badges / shipper / consignee / numbers / notes */
  .receipts-table .c-sel { grid-column: span 1; order: 1; align-self: center; }
  .receipts-table .c-wh { grid-column: span 7; order: 2; font-size: 14px; }
  .receipts-table .c-date { grid-column: span 4; order: 3; color: var(--muted); font-size: 12px; align-self: center; }
  .receipts-table .c-status, .receipts-table .c-type, .receipts-table .c-check { grid-column: span 4; order: 4; }
  .receipts-table .c-shipper { order: 7; } .receipts-table .c-consignee { order: 8; }
  .receipts-table .c-pcs, .receipts-table .c-weight, .receipts-table .c-volume, .receipts-table .c-inv { grid-column: span 3; order: 9; }
  .receipts-table .c-lines { display: none; }
  .receipts-table .c-notes { order: 13; color: var(--soft); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .receipts-table td.c-notes.m-empty { display: none; }
  .receipts-table .c-sel input { width: 18px; height: 18px; }

  /* pieces card */
  .pieces-table .c-line { grid-column: span 2; font-weight: 600; }
  .pieces-table .c-pcs { grid-column: span 2; }
  .pieces-table .c-lb, .pieces-table .c-kg { grid-column: span 4; }
  .pieces-table .c-dims { grid-column: span 6; }
  .pieces-table .c-cf, .pieces-table .c-cbm { grid-column: span 3; }
  .pieces-table tfoot .c-line { grid-column: span 12; }
  .pieces-table tfoot .c-pcs, .pieces-table tfoot .c-cf, .pieces-table tfoot .c-cbm { grid-column: span 2; }
  .pieces-table tfoot .c-lb, .pieces-table tfoot .c-kg { grid-column: span 3; }

  /* misplaced card */
  .misplaced-table .c-tracking .track-open-row { font-size: 15px; font-weight: 600; }
  .misplaced-table .c-tracking { order: 0; } .misplaced-table .c-status { order: 1; }
  .misplaced-table .c-wr, .misplaced-table .c-mode { grid-column: span 6; order: 2; }
  .misplaced-table .c-consignee { order: 3; }
  .misplaced-table .c-first, .misplaced-table .c-checked, .misplaced-table .c-found { grid-column: span 4; order: 4; }
  .misplaced-table .status-cell, .misplaced-table .req-cell { white-space: normal; }
  .misplaced-table .c-found { font-size: 11px; }
  .misplaced-table .c-request { grid-column: span 8; align-self: end; order: 5; }
  .misplaced-table .c-recheck { grid-column: span 4; align-self: end; order: 6; }
  .misplaced-table .request-btn { margin-top: 6px; }
  #misplaced-table .recheck { height: 34px; }

  /* requests card */
  .requests-table td { order: 1; }
  .requests-table .c-sent { grid-column: span 7; order: 0; color: var(--muted); font-size: 12px; }
  .requests-table .c-result { grid-column: span 5; order: 0; }
  .requests-table .c-wr { font-weight: 600; font-size: 14px; }
  .requests-table .c-customer, .requests-table .c-account, .requests-table .c-invoice, .requests-table .c-by { grid-column: span 6; }
  .requests-table .c-followups { white-space: normal; }

  /* connections card */
  .connections-table .c-app { font-size: 14px; }
  .connections-table .c-created, .connections-table .c-used, .connections-table .c-expires { grid-column: span 4; }
  .connections-table .c-revoke .btn { width: 100%; justify-content: center; }

  /* totals: a bar pinned to the bottom, opens upwards */
  .totals-bar { position: sticky; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
    margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter) env(safe-area-inset-bottom);
    border-top: 1px solid var(--line-strong); box-shadow: 0 -8px 20px rgba(0, 0, 0, .06); }
  .totals-bar:not(.m-open) > :not(.totals-toggle) { display: none; }
  .totals-bar.m-open { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .totals-toggle { grid-column: 1 / -1; height: 46px; padding: 0; border: 0; background: none; }
  .totals-toggle > span:last-child { flex: 1; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* ---- receipt page ---- */
  .detail-head { gap: 6px 10px; margin-bottom: 10px; }
  .detail-head .back { flex-basis: 100%; }
  .detail-head .spacer { display: none; }
  .detail-head .meta { order: 4; flex-basis: 100%; }
  .m-docs-toggle { display: inline-flex; order: 3; margin-left: auto; height: 32px; }
  .detail-docs.m-open { display: flex; order: 5; flex-direction: column; gap: 6px; flex-basis: 100%; }
  .detail-docs .doc-links { display: flex; flex-direction: column; gap: 6px; }
  .detail-docs .btn { width: 100%; justify-content: space-between; height: 40px; }
  .detail-top { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
  .detail-top .party, .detail-top .party:first-child, .detail-top .party:last-child { padding: 0 12px; }
  .notes-block { max-height: none; }
  .m-acc-head { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; cursor: pointer;
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
  .m-acc-peek { display: block; flex: 1; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; font-size: 12px; font-weight: 400; color: var(--soft); text-transform: none; letter-spacing: 0; }
  .m-open > .m-acc-head .m-acc-peek { visibility: hidden; }
  .m-acc-head::after { margin-left: auto; }
  .f-actions { flex-wrap: wrap; }
  .f-add { white-space: nowrap; padding: 6px 4px; }
  [data-m-acc]:not(.m-open) > .m-acc-body { display: none; }
  .m-acc-body { padding-bottom: 12px; }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
  .field-value { white-space: normal; overflow-wrap: anywhere; }
  .legs { gap: 8px; }
  .image-section { margin-top: 14px; }

  /* ---- misplaced page ---- */
  .misplaced-bar { gap: 8px; }
  .misplaced-bar .small-switch { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .misplaced-bar .small-switch::-webkit-scrollbar { display: none; }
  .small-switch a { padding: 7px 12px; white-space: nowrap; }
  .misplaced-bar input[type=search] { width: 100%; height: 38px; }
  #recheck-progress:empty { display: none; }

  /* ---- dialogs ---- */
  dialog.picker, .fetch-dialog, .request-dialog { width: calc(100vw - 16px); max-width: 560px;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); overflow: auto; padding: 14px; border-radius: 14px; }
  .picker-head .icon-btn { width: 34px; height: 34px; font-size: 20px; }
  .fetch-form { gap: 10px 12px; }
  .fetch-form label.check input { width: 18px; height: 18px; }
  .fetch-actions .btn { height: 40px; }
  .picker-results button { padding: 10px 4px; }

  /* ---- Track sheet ---- */
  .track-sheet { width: 100vw; height: calc(100dvh - var(--header-h) - env(safe-area-inset-top));
    border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .track-form input[type=search] { flex: 1 1 100%; height: 40px; }
  .track-form .btn { height: 38px; margin-left: auto; }
  .track-head .icon-btn { width: 34px; height: 34px; font-size: 20px; }
  .track-history { max-height: none; padding: 4px 10px; }
  .track-history-head { padding: 6px 2px; }
  .m-acc-trigger { display: inline-flex; align-items: center; gap: 8px; min-height: 30px; cursor: pointer; }
  .track-history:not(.m-open) ul, .track-history:not(.m-open) .track-history-empty { display: none; }
  .track-history.m-open ul { max-height: 34dvh; overflow: auto; }
  .track-history-x { visibility: visible; }
  .track-links { grid-template-columns: 1fr; }
  .track-status h3 { font-size: 17px; }
}

@media (max-width: 420px) {
  .brand span { display: none; }                      /* "NELCON" alone, so Track / Misplaced / ☰ fit on one line */
  .fetch-form { grid-template-columns: 1fr; }
  .cards .card { padding: 8px 10px; }
}
