/* ==========================================================================
   MS GROUP — extensions to the design system (app.css is the verbatim copy).
   Only components the reference does not have: tables, coloured status pills,
   lifecycle stepper, key/value lists, permission matrix, photo grid, map frame,
   mobile bottom navigation. Same tokens, radii, borders and motion.
   ========================================================================== */

/* ---------- Topbar extras ---------- */
.tabs .tab .badge { margin-inline-start: 2px; }
.bell { position: relative; }
.bell .badge { position: absolute; top: -5px; inset-inline-end: -5px; }
.user-chip { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 10px 0 4px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font: 600 12.5px/1 var(--font); }
.user-chip .avatar { width: 32px; height: 32px; font-size: 11px; }
@media (max-width: 640px) { .user-chip .uname { display: none; } .user-chip { padding: 0 4px; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: start; font: 600 10.5px/1.2 var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.is-link { cursor: pointer; }
.table .num { text-align: end; font-family: var(--mono); white-space: nowrap; }
.table .actions-cell { text-align: end; white-space: nowrap; }
.table .tight { width: 1%; white-space: nowrap; }
.table-compact td, .table-compact th { padding: 8px 10px; }
@media (max-width: 720px) {
  .table.stack-sm thead { display: none; }
  .table.stack-sm tr { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .table.stack-sm td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; }
  .table.stack-sm td::before { content: attr(data-label); color: var(--text-3); font-size: 12px; }
  .table.stack-sm .actions-cell { justify-content: flex-end; }
}

/* ---------- Status pill with any colour (job lifecycle) ---------- */
.spill { display: inline-flex; align-items: center; gap: 6px; padding: 0 9px; min-height: 24px; border-radius: 999px; font: 600 11.5px/1 var(--font); white-space: nowrap;
  color: var(--c, var(--text-2)); background: color-mix(in srgb, var(--c, var(--text-3)) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c, var(--text-3)) 30%, var(--surface)); }
.spill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
[data-theme="dark"] .spill { color: color-mix(in srgb, var(--c) 70%, #fff); background: color-mix(in srgb, var(--c) 20%, var(--surface)); border-color: color-mix(in srgb, var(--c) 40%, var(--surface)); }

/* ---------- Lifecycle stepper ---------- */
.flow { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.flow::-webkit-scrollbar { display: none; }
.flow-step { flex: 1 0 auto; min-width: 72px; display: flex; flex-direction: column; gap: 6px; }
.flow-step .bar { height: 5px; border-radius: 999px; background: var(--surface-3); }
.flow-step.done .bar { background: var(--green); }
.flow-step.current .bar { background: var(--accent); }
.flow-step .lbl { font: 500 11px/1.2 var(--font); color: var(--text-3); white-space: nowrap; }
.flow-step.current .lbl { color: var(--accent); font-weight: 600; }
.flow-step.done .lbl { color: var(--text-2); }

/* ---------- Key / value ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: 8px; } }

/* ---------- Checks (invoice-ready, compliance) ---------- */
.checks { display: grid; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); font-size: 13.5px; }
.check-row .ok { color: var(--green); }
.check-row .ko { color: var(--red); }
.check-row.is-ok { background: var(--green-soft); border-color: var(--green-border); }
.check-row.is-ko { background: var(--red-soft); border-color: var(--red-border); }

/* ---------- Filter chips (re-uses .task-filters look) ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: 600 12px/1 var(--font); white-space: nowrap; }
.chip:hover { color: var(--text); border-color: var(--text-4); }
.chip.on { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.chip .n { font-family: var(--mono); font-weight: 500; color: var(--text-3); }
.chip.on .n { color: var(--accent); }
.tag { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font: 500 11.5px/1 var(--font); }
.tag.missing { background: var(--red-soft); color: var(--red); }

/* ---------- Permission matrix ---------- */
.matrix { width: 100%; border-collapse: collapse; font-size: 13px; }
.matrix th, .matrix td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: start; }
.matrix thead th { font: 600 10.5px/1.2 var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); }
.matrix input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.matrix .na { color: var(--text-4); }

/* ---------- Score bar (dispatch ranking) ---------- */
.score { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.score .progress { flex: 1; }
.score b { font: 600 13px/1 var(--mono); }
.breakdown { display: grid; gap: 3px; font-size: 12px; color: var(--text-2); }
.breakdown span { display: flex; justify-content: space-between; gap: 10px; }
.breakdown b { font-family: var(--mono); color: var(--text); font-weight: 500; }

/* ---------- Photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: var(--surface-3); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .pill { position: absolute; top: 6px; inset-inline-start: 6px; }
.photo form { position: absolute; top: 4px; inset-inline-end: 4px; }

/* ---------- Code ---------- */
.codeblock { position: relative; background: var(--ink); color: var(--on-ink); border-radius: var(--radius-md); padding: 14px 16px; font: 12.5px/1.6 var(--mono); overflow-x: auto; white-space: pre; }
[data-theme="dark"] .codeblock { background: #0B0D11; color: #E6E9EF; border: 1px solid var(--border); }
.codeblock .copy { position: absolute; top: 8px; inset-inline-end: 8px; }
code.inline { font: 12.5px/1 var(--mono); background: var(--surface-3); padding: 2px 6px; border-radius: 6px; }
.secret { font: 600 14px/1.4 var(--mono); word-break: break-all; padding: 12px 14px; border-radius: var(--radius); background: var(--amber-soft); border: 1px dashed var(--amber-border); }

/* ---------- Misc ---------- */
.section-title { font: 600 10.5px/1.2 var(--font); letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.inline-form { display: inline; }
.mini { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-red { color: var(--red); } .text-green { color: var(--green); } .text-amber { color: var(--amber); }
.box { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; background: var(--surface-2); }
.stat-grid { display: grid; gap: clamp(10px, 1.4vw, 14px); grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .track { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar-row .track > span { display: block; height: 100%; border-radius: inherit; background: var(--c, var(--accent)); }
.bar-row .n { font: 500 12.5px/1 var(--mono); color: var(--text-2); min-width: 28px; text-align: end; }
.list-check { display: grid; gap: 6px; }
.list-check label { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-size: 14px; min-height: 48px; }
.list-check label:has(input:checked) { border-color: var(--green-border); background: var(--green-soft); }
.list-check input { width: 20px; height: 20px; accent-color: var(--green); flex: none; margin-top: 1px; }
.dl-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-zone { border-color: var(--red-border); }
.empty-row td { text-align: center; color: var(--text-3); padding: 28px 14px; }
details.more > summary { list-style: none; cursor: pointer; color: var(--accent); font: 600 12.5px/1.2 var(--font); display: inline-flex; gap: 5px; align-items: center; min-height: 30px; }
details.more > summary::-webkit-details-marker { display: none; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c); border: 1px solid var(--border); vertical-align: -2px; }
input[type=color].input { padding: 4px; min-height: 46px; width: 64px; }
.select[multiple] { min-height: 120px; padding: 8px; background-image: none; }

/* ---------- Map page (the Mapper runs in an iframe) ---------- */
.map-shell { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.map-frame { flex: 1; width: 100%; border: 0; min-height: calc(100dvh - var(--topbar-h)); display: block; background: var(--bg); }
body.is-map .footer { display: none; }
body.is-map .main { padding: 0; display: flex; }

/* ---------- Mobile (technician) layout ---------- */
.m-body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.m-top { position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--border); }
.m-top .container { display: flex; align-items: center; gap: 10px; min-height: 58px; }
.m-nav { position: fixed; z-index: 45; inset-inline: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(4, 1fr); padding-bottom: env(safe-area-inset-bottom); }
.m-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 62px; color: var(--text-3); font: 600 11px/1 var(--font); position: relative; }
.m-nav a.active { color: var(--accent); }
.m-nav a .badge { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); }
.m-card { display: flex; flex-direction: column; gap: 10px; }
.m-actions { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.m-actions .btn { min-height: 52px; font-size: 14.5px; }
.m-actions .full { grid-column: 1 / -1; }
.btn-lg { min-height: 54px; font-size: 15px; border-radius: 13px; }
.nav-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.nav-links .btn { flex-direction: column; gap: 4px; min-height: 64px; font-size: 12px; }

/* ---------- Print (documents) ---------- */
@media print { .no-print { display: none !important; } }

/* two columns with the narrow one on the left (dispatch board) */
@media (min-width: 960px) { .grid-2.grid-left { grid-template-columns: 340px minmax(0, 1fr); } }

/* ---------- Shared media helpers (public/js/media.js) ---------- */
.ms-recorder { display: flex; flex-direction: column; gap: 8px; }
.ms-recorder-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ms-rec-live { display: inline-flex; align-items: center; gap: 8px; }
.ms-rec-live[hidden] { display: none; }
.ms-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: pulse 1.2s ease infinite; }
.ms-rec-time { font-size: 13px; color: var(--text-2); }
.ms-rec-list { display: flex; flex-direction: column; gap: 6px; }
.ms-rec-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.ms-rec-item audio { height: 36px; flex: 1; min-width: 0; max-width: 100%; }
[data-sortable] > [data-id] { touch-action: auto; }
[data-sortable] [data-drag-handle] { cursor: grab; touch-action: none; color: var(--text-4); display: inline-grid; place-items: center; min-width: 32px; min-height: 40px; }
[data-sortable] [data-drag-handle]:hover { color: var(--text-2); }
.sort-dragging { position: fixed; z-index: 80; pointer-events: none; box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .35); opacity: .96; transform: rotate(.6deg); }
.sort-placeholder { border: 2px dashed var(--accent-border); border-radius: var(--radius); background: var(--accent-soft); list-style: none; }
body.sorting, body.sorting * { cursor: grabbing !important; user-select: none; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: 12.5px; color: var(--text-2); }
.file-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }

/* ---------- Main navigation (partials/nav.blade.php): dropdowns ≥1100px, slide-in menu below ---------- */
.badge[hidden], .nav-dot[hidden] { display: none !important; }
.nav-burger { display: none; }
.mainnav { display: flex; }
.mainnav-head { display: none; }
.mainnav-groups { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.nav-group, .user-menu { position: relative; }
.nav-btn { display: inline-flex; align-items: center; gap: 7px; min-height: 46px; padding: 0 12px; border: 0; border-bottom: 2.5px solid transparent; background: none; color: var(--text-2); font: 500 13.5px/1 var(--font); white-space: nowrap; cursor: pointer; text-decoration: none; }
.nav-btn:hover { color: var(--text); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.nav-btn .nav-chev { transition: transform .15s; opacity: .7; }
.nav-group.open > .nav-btn .nav-chev, .user-menu.open .nav-chev { transform: rotate(180deg); }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.nav-menu { display: none; position: absolute; z-index: 60; top: calc(100% + 4px); inset-inline-start: 0; min-width: 290px; max-width: min(360px, 92vw); padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 18px 44px -18px rgba(0, 0, 0, .35); }
.nav-menu-end { inset-inline-start: auto; inset-inline-end: 0; }
.nav-group.open > .nav-menu, .user-menu.open > .nav-menu { display: block; }
.nav-menu-title { padding: 8px 10px 6px; font: 600 11px/1.2 var(--font); letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 50px; padding: 7px 10px; border-radius: 10px; color: var(--text); text-decoration: none; background: none; border: 0; text-align: start; cursor: pointer; font: inherit; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .nav-ico { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 9px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.nav-item.active .nav-ico { background: var(--accent); color: var(--on-accent, #fff); border-color: var(--accent); }
.nav-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.nav-txt b { font: 600 13.5px/1.2 var(--font); }
.nav-txt small { font: 400 12px/1.25 var(--font); color: var(--text-3); white-space: normal; }
.nav-item-plain { cursor: default; gap: 8px; }
.nav-item-plain:hover { background: none; }
.nav-item-danger { color: var(--red); }
.nav-item-danger:hover { background: var(--red-soft); color: var(--red); }
.user-menu .user-chip { cursor: pointer; }
.user-menu .nav-menu { min-width: 250px; }
.show-xs { display: none !important; }
.nav-backdrop { position: fixed; inset: 0; z-index: 69; background: rgba(10, 12, 16, .45); }
.nav-backdrop[hidden] { display: none; }

@media (max-width: 1099px) {
  .nav-burger { display: grid; }
  .mainnav { position: fixed; z-index: 70; top: 0; bottom: 0; inset-inline-start: 0; width: min(360px, 90vw); flex-direction: column; background: var(--surface); border-inline-end: 1px solid var(--border); box-shadow: 0 0 60px -20px rgba(0, 0, 0, .5); transform: translateX(-105%); transition: transform .2s ease; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
  [dir="rtl"] .mainnav { transform: translateX(105%); }
  .mainnav.open { transform: none; }
  .mainnav-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 18px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
  .mainnav-groups { flex-direction: column; align-items: stretch; gap: 0; padding: 4px 10px 18px; }
  .nav-btn { border-bottom: 0; min-height: 40px; padding: 14px 8px 4px; pointer-events: none; color: var(--text-3); font: 600 11.5px/1.2 var(--font); letter-spacing: .06em; text-transform: uppercase; }
  .nav-btn svg, .nav-btn .nav-chev, .nav-btn .badge, .nav-btn .nav-dot { display: none !important; }
  .nav-btn.active { color: var(--text-3); }
  .nav-single { pointer-events: auto; text-transform: none; letter-spacing: 0; font: 600 14px/1.2 var(--font); color: var(--text); min-height: 50px; padding: 8px 10px; border-radius: 10px; margin-top: 8px; gap: 11px; }
  .nav-single svg { display: block !important; }
  .nav-single .badge { display: inline-grid !important; }
  .nav-single.active { background: var(--accent-soft); color: var(--accent); }
  .nav-group > .nav-menu { display: block; position: static; min-width: 0; max-width: none; padding: 0; border: 0; box-shadow: none; background: none; }
  .nav-group .nav-menu-title { display: none; }
  body.nav-open { overflow: hidden; }
}
@media (max-width: 520px) {
  .hide-xs { display: none !important; }
  .show-xs { display: flex !important; }
  .topbar-row { gap: 6px; }
  .brand-name { font-size: 15px; }
}

/* ---------- Mobile (technician) bottom bar: 5 entries + "More" sheet ---------- */
.m-nav { grid-template-columns: repeat(5, 1fr); }
.m-more { position: relative; display: flex; }
.m-more > summary { list-style: none; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 62px; color: var(--text-3); font: 600 11px/1 var(--font); cursor: pointer; }
.m-more > summary::-webkit-details-marker { display: none; }
.m-more > summary.active, .m-more[open] > summary { color: var(--accent); }
.m-more-sheet { position: absolute; bottom: calc(100% + 8px); inset-inline-end: 8px; min-width: 230px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 18px 44px -14px rgba(0, 0, 0, .4); display: flex; flex-direction: column; }
.m-more-sheet a, .m-more-sheet button { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px; border-radius: 10px; color: var(--text); font: 500 14px/1 var(--font); background: none; border: 0; width: 100%; text-align: start; cursor: pointer; }
.m-more-sheet a:hover, .m-more-sheet button:hover { background: var(--surface-3); }
.m-more-sheet form { margin: 0; }
input[type=file].input { padding: 8px 10px; line-height: 28px; }

/* ---------- dialogs (msDialog: confirm / prompt / alert / copy) — sheet on phones, card on desktop ---------- */
.ms-dlg { z-index: 91; }
.ms-dlg-backdrop { z-index: 90; }
html.ms-dlg-open { overflow: hidden; }
.ms-dlg-card { max-width: 440px; padding: 20px 20px calc(18px + env(safe-area-inset-bottom)); }
.ms-dlg-head { display: flex; gap: 14px; align-items: flex-start; }
.ms-dlg-ico { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.ms-dlg-warn { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber-border); }
.ms-dlg-danger { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-border); }
.ms-dlg-info, .ms-dlg-edit, .ms-dlg-copy { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-border); }
.ms-dlg-text { min-width: 0; flex: 1; padding-top: 2px; }
.ms-dlg-title { margin: 0 0 4px; line-height: 1.3; }
.ms-dlg-msg { margin: 0; color: var(--text-2); font-size: 14.5px; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }
.ms-dlg-msg-strong { color: var(--text); font-weight: 600; font-size: 15.5px; padding-top: 10px; }
.ms-dlg-field { margin-top: 16px; }
.ms-dlg-field .textarea[readonly] { font: 13px/1.5 var(--mono); background: var(--surface-2); }
.ms-dlg-error { margin-top: 6px; color: var(--red); font-size: 13px; }
.ms-dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.ms-dlg-btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.ms-dlg-btn-danger:hover { filter: brightness(1.08); color: #fff; }
.ms-dlg-btn-danger:focus-visible { box-shadow: 0 0 0 3px var(--red-soft); }
.ms-dlg.ms-dlg-out .ms-dlg-card { animation: fadeOut .14s ease both; }
.ms-dlg-backdrop.ms-dlg-out { opacity: 0; transition: opacity .14s; }
@media (max-width: 639px) {
  .ms-dlg-actions { flex-direction: column-reverse; }
  .ms-dlg-actions .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .ms-dlg-card { animation: none; } }
