/* ==========================================================================
   pages.css — shared pieces of the redesigned pages (Oct 2026, pages v2)
   --------------------------------------------------------------------------
   Linked after style.css + mobile.css (+ contracts.css) by the pages that
   use these pieces. Builds only on the style.css tokens: no new colours,
   sizes or radii. The behaviour lives in app.js ("pages v2 helpers").

     1. Sortable table heads ............ .th-sort (rpsSort)
     2. Bulk selection .................. .col-check + .bulk-bar
     3. Searchable picker ............... .picker (rpsPicker)
     4. Date fields with a label ........ .date-field (rpsDateFields)
     5. Two delivery dates .............. .dl-pair (rpsDeadlines)
     6. Map pins ........................ .rps-pin (rpsMapPin)
     7. Page toolbar + CSV button ....... .page-tools, .btn-csv
     8. Print
   ========================================================================== */

/* ---- 1. Sortable table heads ------------------------------------------------
   <th data-sort="price" data-sort-type="number">Owner price</th>
   rpsSort.attach(table, …) wraps the label in a button and keeps aria-sort. */
.th-sort {
  display: inline-flex; align-items: center; gap: 4px;
  margin: -4px -6px; padding: 4px 6px;
  border: 0; border-radius: 6px;
  background: none; color: inherit;
  font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: inherit;
  cursor: pointer;
  transition: color var(--dur-1) var(--ease-out), background var(--dur-1) var(--ease-out);
}
.th-sort__label { min-width: 0; }
.th-sort__icon { flex: none; display: inline-grid; opacity: .45; transition: opacity var(--dur-1), transform var(--dur-2) var(--ease-out); }
.th-sort__icon svg { display: block; transition: transform var(--dur-2) var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .th-sort:hover { color: var(--text); background: var(--surface-muted); }
  .th-sort:hover .th-sort__icon { opacity: .8; }
}
.th-sort:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.th-sort.is-active { color: var(--text); }
.th-sort.is-active .th-sort__icon { opacity: 1; }
th[aria-sort="ascending"] .th-sort__icon svg { transform: rotate(180deg); }
th.num .th-sort { flex-direction: row-reverse; }

/* ---- 2. Bulk selection -------------------------------------------------------
   A checkbox column (.col-check) and a bar that appears while rows are
   picked. The bar sits at the bottom of the viewport (above the phone tab
   bar), holds the count, the actions and a Clear button. */
th.col-check, td.col-check { width: 1%; padding-right: 0 !important; white-space: nowrap; }
td.col-check input, th.col-check input { vertical-align: middle; }
tr.is-picked > td { background-color: color-mix(in srgb, var(--text) 5%, var(--surface)); }
.bulk-bar {
  position: fixed;
  /* Centred with auto margins, not a transform: the entrance animation
     animates transform and would undo a translateX(-50%). */
  left: 0; right: 0; margin: 0 auto;
  bottom: calc(var(--tabbar-h) + var(--sp-4));
  z-index: var(--z-menu);
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3);
  width: min(760px, calc(100vw - 32px));
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--elev-3);
  animation: rps-rise var(--dur-3) var(--ease-out) both;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar__count { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: auto; }
.bulk-bar__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
/* Rows behind the bar stay reachable: the page grows by the bar's height. */
body:has(.bulk-bar:not([hidden])) .main { padding-bottom: 96px; }
@media (min-width: 901px) {
  /* Centred on the content column, not the whole window (the sidebar is 248px). */
  .bulk-bar { left: 248px; width: min(760px, calc(100vw - 280px)); }
}
@media (max-width: 640px) {
  .bulk-bar { padding: 10px 12px; }
  .bulk-bar__count { flex: 1 1 100%; margin: 0; }
  .bulk-bar__actions { flex: 1 1 100%; }
  .bulk-bar__actions .btn { flex: 1 1 0; min-height: 44px; justify-content: center; }
  body:has(.bulk-bar:not([hidden])) .main { padding-bottom: calc(var(--tabbar-h) + 150px); }
}
/* Per-item results after a bulk action. */
.bulk-results { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; max-height: 50vh; overflow-y: auto; }
.bulk-results li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: var(--fs-sm); line-height: 1.4;
}
.bulk-results .br-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.bulk-results .br-sub { color: var(--text-muted); font-size: var(--fs-xs); }
.bulk-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

/* ---- 3. Searchable picker ---------------------------------------------------- */
.picker { display: grid; gap: var(--sp-2); min-width: 0; }
.picker-search { width: 100%; }
.picker-list {
  max-height: 280px; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface);
}
.picker-group + .picker-group { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.picker-group__label {
  padding: 8px 10px 4px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted);
}
.picker-opt {
  display: flex; align-items: center; gap: 10px;
  min-height: 40px; padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.picker-opt.is-active { background: var(--surface-muted); }
@media (hover: hover) and (pointer: fine) { .picker-opt:hover { background: var(--surface-muted); } }
.picker-opt.is-selected { box-shadow: inset 0 0 0 1px var(--text); }
.picker-opt[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.picker-opt__main { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
.picker-opt__label { font-weight: 600; overflow-wrap: anywhere; }
.picker-opt__sub { font-size: var(--fs-xs); color: var(--text-muted); }
.picker-opt__warn { flex: none; }
.picker-opt__check { flex: none; display: inline-grid; color: var(--text); }
.picker-empty { padding: 18px 12px; text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }
.picker-note { margin: 0; }
@media (max-width: 640px) {
  .picker-opt { min-height: 44px; }
  .picker-list { max-height: 42vh; }
}

/* ---- 4. Date fields with a label placeholder -----------------------------------
   An empty native date input shows "dd.mm.yyyy" / "dd-----yyyy" segments.
   rpsDateFields() wraps it: while empty and not focused the segments are
   hidden and a plain label ("From", "Pickup date") shows instead. */
.date-field { position: relative; display: inline-flex; min-width: 0; vertical-align: middle; }
.date-field > input { flex: 1 1 auto; min-width: 0; width: 100%; }
.date-field__ph {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); font-size: var(--fs-md); line-height: 1.2;
  pointer-events: none;
}
.date-field:not(.is-empty) .date-field__ph,
.date-field > input:focus ~ .date-field__ph { display: none; }
.date-field.is-empty > input:not(:focus) { color: transparent; }
.date-field.is-empty > input:not(:focus)::-webkit-datetime-edit { color: transparent; }
.form-group .date-field, .field .date-field, .date-field.is-block { display: flex; }
@media (max-width: 640px) { .date-field__ph { font-size: 16px; } }

/* ---- 5. Two delivery dates (+ conflict) ------------------------------------------ */
.dl-pair { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: var(--fs-sm); }
.dl-item { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.dl-label { color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; }
.dl-value { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.dl-item.is-conflict .dl-value { color: var(--tone-danger-fg); }
.dl-pair--compact { flex-direction: column; align-items: flex-start; gap: 2px; }

/* ---- 6. Map pins ------------------------------------------------------------------
   Leaflet divIcons: a crimson dot with initials, a neutral one for stale
   or offline drivers. White edge so it reads on the grey basemap in both
   modes (the marker pane is not filtered). */
.rps-pin { background: none; border: 0; }
.rps-pin__dot {
  position: relative;
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 2px solid #fff; border-radius: 50%;
  background: var(--brand-700); color: #fff;
  font: 700 11px/1 var(--font); letter-spacing: .02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.rps-pin__dot::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  border: 6px solid transparent; border-top: 7px solid #fff; border-bottom: 0;
}
.rps-pin--stale .rps-pin__dot { background: #57555e; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 55%, transparent), 0 2px 8px rgba(0, 0, 0, .35); }
.rps-pin--offline .rps-pin__dot { background: #57555e; }
.rps-pin--start .rps-pin__dot { background: #131316; }
.rps-pin--end .rps-pin__dot { background: var(--brand-700); }
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--elev-3); }
.leaflet-popup-content-wrapper { border-radius: var(--r-md); }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--surface); color: var(--text); border-bottom-color: var(--border); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--text-muted) !important; }
.leaflet-control-attribution a { color: var(--text) !important; }

/* ---- 7. Page toolbar + CSV button ---------------------------------------------------- */
.page-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.btn-csv svg { flex: none; }
/* "N results" next to a filter row. */
.result-count { color: var(--text-muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- 8. Print -----------------------------------------------------------------------
   Pages that offer Print (contract, protocol, payslip-like views) print the
   content, not the shell. An open dialog prints alone. */
@media print {
  @page { margin: 14mm; }
  html, body { background: #fff !important; color: #000 !important; }
  body { font-size: 11pt; }
  .sidebar, .topbar, .tabbar, .toast-wrap, .net-banner, .bulk-bar, .page-actions, .page-tools,
  .filters, .seg, .ac-views, .row-more, .row-actions, .col-actions, .col-check, .m-fab, .m-actionbar,
  .chat-fab, .rps-chat-fab, .leaflet-control-container, .no-print, .skip-link, .drawer-backdrop {
    display: none !important;
  }
  .app { display: block !important; }
  .main, #pageContent { margin: 0 !important; padding: 0 !important; max-width: none !important; }
  .panel, .panel-card, .tile, .kpi, .table-wrap, .modal {
    box-shadow: none !important; border-color: #bbb !important; background: #fff !important; color: #000 !important;
  }
  .panel, .tile, .kpi, tr, .info-grid > div { break-inside: avoid; }
  .table-wrap { overflow: visible !important; max-height: none !important; }
  table { font-size: 9.5pt; }
  thead { display: table-header-group; }
  table thead th { background: #f2f2f2 !important; color: #000 !important; }
  .pill { border: 1px solid #999 !important; background: #fff !important; color: #000 !important; }
  a { color: #000 !important; text-decoration: none !important; }
  /* A dialog that is open prints alone, at full width. */
  body:has(.modal-backdrop.open) > *:not(.modal-backdrop) { display: none !important; }
  .modal-backdrop.open { position: static !important; display: block !important; padding: 0 !important; background: none !important; backdrop-filter: none !important; }
  .modal-backdrop.open .modal { max-width: none !important; width: auto !important; max-height: none !important; overflow: visible !important; border: 0 !important; transform: none !important; animation: none !important; }
  .modal-backdrop.open .modal-foot, .modal-backdrop.open .modal-close { display: none !important; }
}
