/* Reporting / JSA. Every colour reads the Manage portal tokens (manage_theme.css):
   base tokens + the shared status palette (--st-*, data-status-key: complete =
   "ready" green, incomplete = "manager" amber). The page opts into dark content
   in Dark with .mp-main--dark-content (jsa.html). */

.jsa-manage { max-width: 1500px; color: var(--text-primary); }
.jsa-manage [hidden] { display: none !important; }

/* -- Work type switcher + refresh ------------------------------------------ */
/* 1fr | switcher | 1fr: the switcher sits in the page centre, refresh at the right. */
.jsa-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin: 4px 0 16px; }
.jsa-topbar > .jsa-seg { grid-column: 2; }
.jsa-topbar > .jsa-icon-btn { grid-column: 3; justify-self: end; }

/* Segmented pill control (work type tabs; small variant = Cards / Table). */
.jsa-seg { display: inline-flex; flex: 0 1 auto; min-width: 0; max-width: 100%; gap: 4px; padding: 4px; overflow-x: auto; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-raised); box-shadow: var(--shadow-sm); scrollbar-width: none; }
.jsa-seg::-webkit-scrollbar { display: none; }
.jsa-seg__option { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--text-secondary); font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: background-color 200ms ease, color 200ms ease, box-shadow 200ms ease; }
.jsa-seg__option:hover:not(.is-active) { background: var(--surface-hover); color: var(--text-primary); }
.jsa-seg__option.is-active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(238, 122, 59, 0.35); }
.jsa-seg__option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.jsa-seg__count { margin-left: 0; color: var(--text-muted); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.jsa-seg__option.is-active .jsa-seg__count { color: rgba(255, 255, 255, 0.85); }
.jsa-seg--sm { padding: 3px; gap: 3px; }
.jsa-seg--sm .jsa-seg__option { height: 30px; padding: 0 12px; font-size: 12px; }
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-seg { border-color: rgba(255, 255, 255, 0.08); background: #1f1c21; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); }
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-seg__option.is-active { box-shadow: 0 4px 12px rgba(238, 122, 59, 0.3); }

/* Round refresh button (same look as the notifications bell). */
.jsa-icon-btn { display: inline-flex; flex: 0 0 36px; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-raised); color: var(--text-secondary); cursor: pointer; transition: background-color 150ms ease, color 150ms ease; }
.jsa-icon-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.jsa-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.jsa-icon-btn svg { width: 16px; height: 16px; }
.jsa-icon-btn.is-refreshing svg { animation: jsa-spin 800ms linear infinite; }
@keyframes jsa-spin { to { transform: rotate(360deg); } }

/* -- Filter bar (same styling as the OSP Reports toolbar) ------------------- */
.jsa-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface-raised); box-shadow: var(--shadow-sm); }
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-toolbar { box-shadow: none; }
.jsa-search { display: flex; align-items: center; gap: 9px; flex: 1 1 240px; min-width: 180px; min-height: 42px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 11px; background: var(--surface-input); color: var(--text-secondary); transition: border-color .18s, box-shadow .18s; }
.jsa-search:focus-within { border-color: var(--accent); box-shadow: var(--focus-ring); }
.jsa-search svg { width: 17px; height: 17px; flex: 0 0 17px; }
.jsa-search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; color: var(--text-primary); }
.jsa-manage input::placeholder { color: var(--text-muted); }
.jsa-today { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; color: var(--text-primary); font-size: .86rem; font-weight: 800; cursor: pointer; }
.jsa-today input { position: absolute; opacity: 0; }
.jsa-today__track { position: relative; display: inline-block; width: 36px; height: 21px; border-radius: 99px; background: var(--border-strong); transition: background .16s; }
.jsa-today__track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .16s; }
.jsa-today input:checked + .jsa-today__track { background: var(--accent); }
.jsa-today input:checked + .jsa-today__track::after { transform: translateX(15px); }
.jsa-today input:focus-visible + .jsa-today__track { box-shadow: var(--focus-ring); }
.jsa-crew { position: relative; }
.jsa-filter-btn, .jsa-date-mode select, .jsa-date-input input { min-height: 42px; border: 1px solid var(--border-strong); border-radius: 11px; background: var(--surface-input); color: var(--text-primary); font: inherit; transition: border-color .18s, box-shadow .18s, background-color .18s; }
.jsa-filter-btn:hover, .jsa-date-mode select:hover:not(:disabled), .jsa-date-input input:hover:not(:disabled) { background: var(--surface-hover); }
.jsa-filter-btn:focus-visible, .jsa-date-mode select:focus, .jsa-date-input input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.jsa-date-mode select:disabled, .jsa-date-input input:disabled { background: var(--surface-input-disabled); color: var(--text-muted); cursor: not-allowed; }
.jsa-filter-btn { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-width: 160px; max-width: 240px; padding: 0 12px; cursor: pointer; font-size: .88rem; font-weight: 700; }
#jsaCrewLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jsa-crew__menu { position: absolute; z-index: 15; right: 0; top: calc(100% + 6px); width: min(320px, calc(100vw - 32px)); max-height: 380px; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-raised); box-shadow: var(--shadow-lg); }
.jsa-crew__menu input { width: 100%; min-height: 38px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-input); color: var(--text-primary); font: inherit; }
.jsa-crew__menu input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.jsa-crew__options { padding-top: 5px; }
.jsa-crew__heading { padding: 11px 9px 4px; color: var(--text-secondary); font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.jsa-crew__option { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 38px; padding: 6px 9px; border: 0; border-radius: 8px; background: transparent; color: var(--text-primary); text-align: left; font: inherit; font-size: .86rem; cursor: pointer; }
.jsa-crew__option:hover { background: var(--surface-hover); }
.jsa-crew__option.is-active { background: var(--accent-soft); color: var(--accent-text); }
.jsa-crew__avatar { display: grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; background: var(--surface-hover); color: var(--text-secondary); overflow: hidden; font-size: .64rem; font-weight: 800; }
.jsa-crew__avatar img { width: 100%; height: 100%; object-fit: cover; }
.jsa-dates { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.jsa-date-mode, .jsa-date-input { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: .8rem; font-weight: 700; white-space: nowrap; }
.jsa-date-mode select { min-width: 128px; padding: 0 8px; font-size: .82rem; }
.jsa-date-input input { width: 138px; padding: 0 8px; font-size: .82rem; }
.jsa-clear { min-height: 36px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface-input); color: var(--text-secondary); font: inherit; font-size: .8rem; font-weight: 800; cursor: pointer; }
.jsa-clear:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-primary); }
.jsa-clear:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.jsa-clear:disabled { border-color: var(--border); background: var(--surface-input-disabled); color: var(--text-muted); cursor: not-allowed; }

/* -- Section header + view switch ------------------------------------------ */
.jsa-results-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 22px 0 13px; }
.jsa-results-head h2 { margin: 0; color: var(--text-primary); font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.jsa-results-head p { margin: 4px 0 0; color: var(--text-secondary); font-size: .83rem; font-weight: 600; }
.jsa-results-head__controls { display: flex; align-items: center; gap: 12px; }
.jsa-sync-pill { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 34px; flex: 0 0 20px; border-radius: 50%; cursor: help; outline: none; }
.jsa-sync-dot { width: 10px; height: 10px; flex: 0 0 10px; border-radius: 50%; background: #30d158; box-shadow: 0 0 0 3px rgba(69, 192, 138, .25); }
.jsa-sync-pill.is-delayed .jsa-sync-dot { background: #ffd60a; box-shadow: 0 0 0 3px rgba(255, 214, 10, .22); }
.jsa-sync-pill.is-error .jsa-sync-dot { background: #ff3b30; box-shadow: 0 0 0 3px rgba(255, 59, 48, .2); }
.jsa-sync-pill:focus-visible .jsa-sync-dot { box-shadow: 0 0 0 4px var(--accent-soft); }
#jsaSyncText { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.jsa-sync-pill::after { content: attr(data-tooltip); position: absolute; top: calc(100% + 7px); right: 0; z-index: 80; width: max-content; max-width: min(340px, calc(100vw - 32px)); padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; background: rgba(24,24,27,.96); box-shadow: 0 8px 24px rgba(0,0,0,.18); color: #fff; font-size: 12px; font-weight: 500; line-height: 1.45; text-align: left; white-space: pre-line; opacity: 0; visibility: hidden; transform: translateY(-3px); pointer-events: none; transition: opacity .14s, visibility .14s, transform .14s; }
.jsa-sync-pill:hover::after, .jsa-sync-pill:focus-visible::after { opacity: 1; visibility: visible; transform: translateY(0); }

/* -- Cards (status tint from the shared palette) ---------------------------- */
.jsa-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 13px; }
.jsa-card { display: flex; flex-direction: column; gap: 12px; min-height: 244px; padding: 17px; border: 1px solid var(--st-border, var(--border)); border-radius: 15px; background: var(--st-bg, var(--surface-raised)); box-shadow: var(--shadow-sm); transition: box-shadow 150ms ease, transform 150ms ease, border-color 150ms ease; }
@media (hover: hover) and (pointer: fine) {
  .jsa-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
  html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-card:hover { box-shadow: none; border-color: color-mix(in srgb, var(--st-text) 45%, transparent); }
}
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-card { box-shadow: none; }
.jsa-card__top, .jsa-card__footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
/* Work-type chip: the amber chip of the shared palette. */
.jsa-pill { display: inline-flex; align-items: center; max-width: 100%; padding: 5px 9px; border-radius: 999px; background: var(--st-manager-approval-chip); color: var(--st-manager-approval-text); font-size: .7rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jsa-card__date { color: var(--text-secondary); font-size: .76rem; font-weight: 700; white-space: nowrap; }
.jsa-card h3 { margin: 0; color: var(--text-primary); font-size: 1rem; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.jsa-card__customer { margin: -8px 0 0; color: var(--text-secondary); font-size: .8rem; font-weight: 600; }
.jsa-safety { display: inline-flex; align-items: center; gap: 7px; width: fit-content; max-width: 100%; padding: 6px 9px; border: 0; border-radius: 999px; background: var(--st-chip); color: var(--st-text); font-size: .72rem; font-weight: 800; line-height: 1.2; white-space: normal; }
.jsa-safety__dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: currentColor; }
.jsa-card__target { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-raised); }
.jsa-card__target > span { color: var(--text-secondary); font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.jsa-card__target strong { color: var(--text-primary); font-size: .88rem; font-weight: 700; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.jsa-card__meta { display: grid; gap: 5px; color: var(--text-secondary); font-size: .8rem; }
.jsa-card__meta strong { color: var(--text-primary); font-weight: 700; }
.jsa-card__footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.jsa-card__action { padding: 0; border: 0; background: transparent; color: var(--accent-text); font: inherit; font-size: .82rem; font-weight: 800; cursor: pointer; }
.jsa-manage a.jsa-card__action { text-decoration: none; }
.jsa-card__action:hover { text-decoration: underline; }
.jsa-card__action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* -- Table view ---------------------------------------------------------------- */
.jsa-table-wrap { max-width: 100%; overflow: auto; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-raised); box-shadow: var(--shadow-sm); }
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-table-wrap { box-shadow: none; }
.jsa-table { width: 100%; min-width: 1060px; border-collapse: separate; border-spacing: 0; text-align: left; }
.jsa-table th { position: sticky; top: 0; z-index: 1; padding: 13px 15px; border-bottom: 1px solid var(--border-strong); background: var(--surface-card); color: var(--text-secondary); font-size: .68rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.jsa-table td { padding: 15px; border-top: 1px solid var(--border); background: var(--surface-raised); color: var(--text-primary); font-size: .82rem; line-height: 1.4; vertical-align: middle; transition: background-color 120ms ease; }
.jsa-table tbody tr:first-child td { border-top: 0; }
.jsa-table__row:hover td { background: var(--surface-hover); }
.jsa-table__project { min-width: 190px; }
.jsa-table__project strong, .jsa-table__project span { display: block; overflow-wrap: anywhere; }
.jsa-table__project strong { font-size: .86rem; font-weight: 700; }
.jsa-table__project span { margin-top: 3px; color: var(--text-secondary); font-size: .76rem; }
.jsa-table__date { white-space: nowrap; color: var(--text-secondary); }
.jsa-table__location { min-width: 165px; max-width: 260px; white-space: pre-wrap; overflow-wrap: anywhere; }
.jsa-table__target { min-width: 160px; max-width: 280px; white-space: pre-wrap; overflow-wrap: anywhere; }
.jsa-table__actions { display: flex; flex-wrap: wrap; gap: 8px 14px; white-space: nowrap; }

/* -- Detail dialog ---------------------------------------------------------- */
/* Only the body scrolls, inside the window: header and footer stay put. */
.jsa-detail { width: min(650px, calc(100vw - 28px)); max-height: min(900px, calc(100vh - 48px)); padding: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: var(--surface-raised); color: var(--text-primary); box-shadow: var(--shadow-lg); }
.jsa-detail[open] { display: flex; flex-direction: column; }
html.jsa-modal-open, html.jsa-modal-open body { overflow: hidden; }
.jsa-detail::backdrop { background: rgba(30, 25, 20, .35); }
html[data-portal="manage"][data-theme="dark"] .mp-main--dark-content .jsa-detail::backdrop { background: rgba(0, 0, 0, .55); }
.jsa-detail__head { display: flex; flex-shrink: 0; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--border); background: var(--surface-raised); }
.jsa-detail__scroll { flex: 1 1 auto; min-height: 0; margin-right: 4px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.jsa-detail__scroll::-webkit-scrollbar { width: 6px; }
.jsa-detail__scroll::-webkit-scrollbar-track { background: transparent; }
.jsa-detail__scroll::-webkit-scrollbar-thumb { border-radius: 3px; background: var(--border-strong); }
.jsa-detail__foot { flex-shrink: 0; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-raised); }
.jsa-detail__foot:empty { display: none; }
.jsa-detail__head h2 { margin: 0; color: var(--text-primary); font-size: 1.25rem; overflow-wrap: anywhere; }
.jsa-detail__head .mp-eyebrow { color: var(--text-secondary); }
.jsa-detail__close { align-self: flex-start; border: 0; background: transparent; color: var(--text-secondary); font-size: 1.6rem; cursor: pointer; }
.jsa-detail__close:hover { color: var(--text-primary); }
.jsa-detail__body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; margin: 0; padding: 20px 14px 24px 22px; }
.jsa-detail__field { min-width: 0; }
.jsa-detail__field.is-wide { grid-column: 1 / -1; }
.jsa-detail__field dt { margin-bottom: 4px; color: var(--text-secondary); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.jsa-detail__field dd { margin: 0; color: var(--text-primary); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }
.jsa-detail__links { display: flex; align-items: center; gap: 10px; }
.jsa-detail .mp-btn--primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.jsa-manage .mp-pager__btn { border-color: var(--border-strong); background: var(--surface-raised); color: var(--text-primary); }
.jsa-manage .mp-pager__btn:hover:not(:disabled) { background: var(--surface-hover); }

@media (prefers-reduced-motion: reduce) {
  .jsa-seg__option, .jsa-card, .jsa-icon-btn { transition: none; }
  .jsa-icon-btn.is-refreshing svg { animation: none; }
  .jsa-card:hover { transform: none; }
}
/* Phones: refresh on its own row at the right, the switcher below it across the
   full row (centred; scrolls sideways if it does not fit). */
@media (max-width: 768px) {
  .jsa-topbar { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .jsa-topbar > .jsa-icon-btn { grid-column: 1; grid-row: 1; }
  .jsa-topbar > .jsa-seg { grid-column: 1; grid-row: 2; justify-self: center; }
  .jsa-detail { max-height: calc(100dvh - 32px); }
}
@media (max-width: 640px) { .jsa-toolbar { align-items: stretch; } .jsa-search { flex-basis: 100%; } .jsa-dates { width: 100%; } .jsa-results-head { align-items: flex-start; flex-wrap: wrap; } .jsa-results-head__controls { width: 100%; justify-content: space-between; flex-wrap: wrap; } .jsa-detail__body { grid-template-columns: 1fr; } }
