/* ──────── Deliver dashboard ──────── */
/* Every direct child of the page must be allowed to shrink (min-width:0) so a
   wide table or long token can never push the page wider than the viewport. */
#deliverInsights,
#deliverKpis,
.deliver-alerts,
#deliverRoutesCard,
#deliverRoutesBody {
  min-width: 0;
  max-width: 100%;
}
#deliverRoutesCard,
#deliverRoutesBody { overflow: hidden; }
#deliverRoutesCard .card-head,
.deliver-filters {
  min-width: 0;
  flex-wrap: wrap;
}
.deliver-filters input[type="search"] { min-width: 0; }
.deliver-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
table.deliver-table {
  width: max-content;
  min-width: 100%;
}
table.deliver-table thead th,
table.deliver-table tbody td {
  padding-left: 14px;
  padding-right: 14px;
  vertical-align: middle;
}
.deliver-table tbody tr { cursor: pointer; }
.deliver-table tbody tr:hover { background: var(--bfc-soft); }
.deliver-route-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.code-chip-muted { background: var(--bfc-soft-2); color: var(--bfc-muted); }
.deliver-cell-sub { font-size: 11px; color: var(--bfc-muted); margin-top: 3px; }

.deliver-wc-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--bfc-muted); white-space: nowrap; cursor: pointer;
}
.deliver-wc-toggle input { cursor: pointer; }
.code-chip-wc { background: var(--bfc-warn-bg); color: var(--bfc-warn-text); }

/* Route-table toolbar: expand-all, drivers, export + the TV auto-refresh control. */
.deliver-table-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.deliver-refresh {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--bfc-muted); white-space: nowrap; cursor: pointer;
}
.deliver-refresh input { cursor: pointer; }
.deliver-refresh-secs { padding: 4px 6px; }
.deliver-refresh-secs:disabled { opacity: 0.5; }
.deliver-refresh-stamp { font-size: 12px; color: var(--bfc-muted); font-variant-numeric: tabular-nums; min-width: 84px; }

/* Inline stop expander (the side panel doesn't have room for stop detail). */
.deliver-exp-col { width: 34px; }
.deliver-exp-cell { width: 34px; padding-right: 0 !important; }
.deliver-exp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--bfc-muted); cursor: pointer;
  font-size: 12px; line-height: 1; transition: transform 0.12s ease, background 0.12s ease;
}
.deliver-exp-btn:hover { background: var(--bfc-soft-2); color: var(--bfc-ink); }
.deliver-exp-btn.open { transform: rotate(90deg); color: var(--bfc-indigo-dark); }
.deliver-stop-subrow > td { padding: 0 !important; background: var(--bfc-soft); }
.deliver-stop-subrow:hover { background: var(--bfc-soft); }
.deliver-substops { padding: 8px 14px 12px 48px; border-bottom: 1px solid var(--bfc-line); }
.deliver-substops-empty { color: var(--bfc-muted); font-size: 13px; padding: 4px 0; }
.deliver-substops-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
table.deliver-substops-table { width: max-content; min-width: 100%; background: var(--bfc-surface); }
.deliver-substops-table thead th { background: var(--bfc-soft-2); font-size: 11px; white-space: nowrap; }
.deliver-substops-table th, .deliver-substops-table td { padding: 6px 10px; vertical-align: middle; }
.deliver-substop-cust { display: flex; flex-direction: column; gap: 1px; min-width: 150px; }
.deliver-ns-flag { background: var(--bfc-warn-bg); color: var(--bfc-warn-text); font-weight: 600; }
.deliver-substop-memo {
  display: inline-block; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: bottom; color: var(--bfc-copy);
}
.deliver-substop-thumb-link { display: inline-block; margin: 0 3px 0 0; line-height: 0; }
.deliver-substop-thumb {
  width: 30px; height: 30px; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--bfc-line-strong); background: var(--bfc-soft-2);
}
.deliver-scan-detail {
  border: 0; background: transparent; padding: 0; cursor: pointer; white-space: nowrap;
  color: var(--bfc-indigo-dark); font-size: 12px; font-weight: 600;
}
.deliver-scan-detail:hover { text-decoration: underline; }

/* Scan-% meter (route table, stops, drivers): number stacked over a rescaled
   bar, both right-aligned to sit cleanly in the numeric column. */
.deliver-scan { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.deliver-scan-num { font-variant-numeric: tabular-nums; }
.deliver-scan-bar {
  width: 68px;
  height: 6px;
  flex: none;
  border-radius: 999px;
  background: var(--bfc-soft-2);
  overflow: hidden;
}
.deliver-scan-fill { display: block; height: 100%; border-radius: 999px; background: var(--bfc-teal); }
.deliver-scan-fill.is-warn { background: var(--bfc-warn-text); }
.deliver-scan-fill.is-bad { background: var(--bfc-danger-text); }

/* Issue chips (route table) */
.deliver-issues { display: flex; flex-wrap: wrap; gap: 4px; }
.deliver-issue {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.deliver-issue.is-danger { background: var(--bfc-danger-bg); color: var(--bfc-danger-text); }
.deliver-issue.is-warn { background: var(--bfc-warn-bg); color: var(--bfc-warn-text); }
.deliver-none { color: var(--bfc-muted); }

/* Insight meter cards (scan quality, route status, stops) */
.deliver-insight { display: flex; flex-direction: column; gap: 11px; }
.deliver-insight-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.deliver-insight-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--bfc-navy);
}
.deliver-insight-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--bfc-navy);
  font-variant-numeric: tabular-nums;
}
.deliver-insight-value.is-good { color: var(--bfc-success-text); }
.deliver-insight-value.is-warn { color: var(--bfc-warn-text); }
.deliver-insight-value.is-bad { color: var(--bfc-danger-text); }
.deliver-meter {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bfc-soft-2);
}
.deliver-meter-seg { height: 100%; display: block; transition: width 0.3s ease; }
.deliver-meter-seg.seg-a { background: var(--bfc-indigo); }
.deliver-meter-seg.seg-b { background: var(--bfc-teal); }
.deliver-meter-seg.seg-c { background: var(--bfc-line-strong); }
.deliver-meter-seg.seg-warn { background: var(--bfc-warn-text); }
.chart-legend-swatch.seg-warn { background: var(--bfc-warn-text); }
.deliver-insight .chart-legend { padding: 0; }
.deliver-drawer-meter { margin-bottom: 16px; }
.deliver-drawer-meter .chart-card { margin: 0; }

/* Alert lanes -> worklists */
.deliver-alerts .lane { cursor: pointer; }
.lane:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(35, 177, 165, 0.25), var(--shadow-card); }
.deliver-alert.is-danger { border-color: var(--bfc-danger-line); }
.deliver-alert.is-danger .lane-count { color: var(--bfc-danger-text); }
.deliver-alert.is-warn { border-color: var(--bfc-warn-line); }
.deliver-alert.is-warn .lane-count { color: var(--bfc-warn-text); }
.deliver-alert-cta {
  font-size: 12px;
  font-weight: 700;
  color: var(--bfc-indigo);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.deliver-alert:hover .deliver-alert-cta,
.deliver-alert:focus-visible .deliver-alert-cta,
.deliver-alert.active .deliver-alert-cta { opacity: 1; }
.deliver-drawer-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px 18px 4px;
  border-bottom: 1px solid var(--bfc-line);
}
.deliver-tab.active {
  background: var(--bfc-indigo);
  border-color: var(--bfc-indigo);
  color: #fff;
}
.deliver-drawer-body { padding: 14px 18px 18px; }
.deliver-proof-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.deliver-proof-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--bfc-line);
  border-radius: 14px;
  background: #fff;
  padding: 10px;
  box-shadow: var(--shadow-card);
}
.deliver-proof-image-link {
  position: relative;
  display: block;
  height: 120px;
  margin-bottom: 8px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bfc-soft);
}
.deliver-proof-card img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--bfc-line);
  background: var(--bfc-soft);
  transition: opacity .15s ease;
}
.deliver-proof-loading,
.deliver-proof-error {
  position: absolute;
  inset: 0;
  border-radius: 10px;
}
.deliver-proof-loading .skeleton {
  display: block;
  width: 100%;
  height: 100%;
}
.deliver-proof-image-link:not(.is-loading) .deliver-proof-loading { display: none; }
.deliver-proof-image-link.is-loading img { opacity: 0; }
.deliver-proof-error {
  display: none;
  place-items: center;
  border: 1px dashed var(--bfc-line-strong);
  color: var(--bfc-muted);
  font-weight: 700;
  background: linear-gradient(135deg, #fff, var(--bfc-soft));
}
.deliver-proof-image-link.is-error img { display: none; }
.deliver-proof-image-link.is-error .deliver-proof-error { display: grid; }
.deliver-proof-placeholder {
  height: 120px;
  border-radius: 10px;
  border: 1px dashed var(--bfc-line-strong);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--bfc-muted);
  background: linear-gradient(135deg, #fff, var(--bfc-soft));
  margin-bottom: 8px;
}
.deliver-proof-file,
.deliver-proof-card .meta {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.deliver-proof-file {
  display: block;
  line-height: 1.35;
}
.deliver-proof-card .meta { margin-top: 4px; }
@media (max-width: 900px) {
  /* Drop lower-priority columns first; keep route, driver, status, stops,
     delivered, scan %, returns and issues so the page never needs a wide
     horizontal scroll on small screens. */
  .deliver-table th:nth-child(3), .deliver-table td:nth-child(3),    /* Truck */
  .deliver-table th:nth-child(5), .deliver-table td:nth-child(5),    /* Started */
  .deliver-table th:nth-child(6), .deliver-table td:nth-child(6),    /* Finished */
  .deliver-table th:nth-child(9), .deliver-table td:nth-child(9),    /* Scanned */
  .deliver-table th:nth-child(10), .deliver-table td:nth-child(10),  /* Non-scanned */
  .deliver-table th:nth-child(13), .deliver-table td:nth-child(13) { /* PPH */
    display: none;
  }
}
