/* Crew & Site Map (web/crewmap.js). Everything under .cm, plus the Leaflet
   marker classes (cm-jmark, cm-pmark, cm-tag) that live inside the map.
   Same design language as Gantt and HR: gradient-underlined title, KPI tiles
   with a gradient cap, 12px cards. Brand tokens only (light + dark). */

#main:has(> .cm) { max-width: none; }
.cm { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cm > * { min-width: 0; }
.cm-soft { color: var(--muted); font-size: .76rem; margin: 0; }
.cm-warnt { color: var(--warn); font-weight: 600; }

/* head + tiles */
.cm-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.cm-titles h1 { margin: 0; font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; position: relative; padding-bottom: 9px; }
.cm-titles h1::after { content: ""; position: absolute; left: 0; bottom: 0; width: 72px; height: 3px; border-radius: 3px; background: var(--gradient); }
.cm-titles p { margin: 8px 0 0; color: var(--muted); font-size: .84rem; max-width: 780px; line-height: 1.45; }
.cm-fresh { font-size: .74rem; color: var(--muted); }
.cm-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.cm-kpi { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 15px 16px 12px; }
.cm-kpi::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--gradient); }
.cm-kpi.t-crit::before { background: var(--crit); }
.cm-kpi.t-warn::before { background: var(--warn); }
.cm-kpi .k { font-size: .63rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.cm-kpi .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.cm-kpi.t-crit .v { color: var(--crit); }
.cm-kpi.t-warn .v { color: var(--warn); }
.cm-kpi .s { font-size: .72rem; color: var(--muted); line-height: 1.35; }

/* map + side panel */
.cm-main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: stretch; }
.cm-mapcard, .cm-side, .cm-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 0; }
.cm-mapcard { overflow: hidden; display: flex; flex-direction: column; }
.cm-map { height: 640px; width: 100%; background: var(--surface-2); z-index: 0; }
.cm-legend { display: flex; flex-wrap: wrap; gap: 10px 0; align-items: stretch; padding: 10px 4px; border-top: 1px solid var(--line); font-size: .76rem; color: var(--ink-2); }
.cm-lg { display: flex; flex-direction: column; gap: 6px; padding: 0 16px; border-left: 1px solid var(--line); }
.cm-lg:first-child { border-left: 0; }
.cm-lg-k { font-size: .62rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.cm-lg-items { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.cm-lg-i { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cm-lg-note { font-size: .7rem; color: var(--muted); font-style: italic; white-space: nowrap; }
.cm-ring { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid; display: inline-block; }
.cm-line { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.cm-pin-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line-strong); }
.cm-pin-dot.big { width: 16px; height: 16px; margin-top: 6px; }
.h-crit { background: var(--crit); } .h-warn { background: var(--warn); } .h-good { background: var(--good); } .h-teal { background: var(--teal); } .h-muted { background: var(--muted); }

.cm-side { display: flex; flex-direction: column; max-height: 682px; overflow: hidden; }
.cm-tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); flex: none; }
.cm-tab { appearance: none; border: 0; background: none; font: inherit; font-weight: 600; font-size: .84rem; color: var(--muted); padding: 11px 10px 12px; position: relative; cursor: pointer; }
.cm-tab:hover, .cm-tab[aria-selected="true"] { color: var(--ink); }
.cm-tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--gradient); }
.cm-sbody { overflow: auto; flex: 1; min-height: 0; }
.cm-list { display: flex; flex-direction: column; }
.cm-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; font: inherit; color: inherit; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; cursor: pointer; }
.cm-item:hover, .cm-item:focus-visible { background: var(--surface-2); outline: none; }
.cm-item-t { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cm-item-t b { font-size: .86rem; font-weight: 600; }
.cm-item-t small { font-size: .72rem; color: var(--muted); }
.cm-item-t small b { color: var(--ink-2); font-size: inherit; }
.cm-onsite { color: var(--accent-2) !important; font-weight: 600; }
.cm-pill { font-size: .64rem; font-weight: 700; border-radius: 6px; padding: 2px 7px; white-space: nowrap; }
.p-crit { background: var(--crit-soft); color: var(--crit); } .p-warn { background: var(--warn-soft); color: var(--warn); } .p-good { background: var(--good-soft); color: var(--good); }
.p-teal { background: var(--accent-soft); color: var(--accent-2); } .p-muted { background: var(--surface-3); color: var(--ink-2); }
.cm-num { display: flex; flex-direction: column; align-items: flex-end; font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }
.cm-num small { font-size: .62rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
/* role badge: the role's glyph on its colour (crew hard hat, PM clipboard, RM flag, COO star) */
.cm-av { --c: var(--series-1); width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-grid; place-items: center; color: #fff; background: var(--c); box-shadow: 0 0 0 2px var(--surface); }
.cm-av svg { width: 68%; height: 68%; }
.cm-av.sm { width: 22px; height: 22px; }
.cm-av.xs { width: 18px; height: 18px; box-shadow: none; }
.cm-av.lg { width: 44px; height: 44px; }
/* site pin: teardrop in the Gantt health colour with a charging bolt */
.cm-spin { width: 22px; height: 22px; flex: none; display: inline-grid; place-items: center; color: #fff; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); box-shadow: 0 0 0 2px var(--surface); }
.cm-spin svg { width: 66%; height: 66%; transform: rotate(45deg); }
.cm-spin.sm { width: 18px; height: 18px; }
.cm-spin.xs { width: 15px; height: 15px; box-shadow: none; }
.cm-spin.lg { width: 30px; height: 30px; margin-top: 4px; }

.cm-detail { padding: 12px 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.cm-back { align-self: flex-start; border: 0; background: none; font: inherit; font-size: .76rem; font-weight: 600; color: var(--accent); cursor: pointer; padding: 0; }
.cm-dhead { display: flex; gap: 12px; align-items: flex-start; }
.cm-dhead h2 { margin: 0; font-size: 1.05rem; }
.cm-dhead p { margin: 2px 0 0; font-size: .78rem; color: var(--ink-2); }
.cm-chips { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.cm-chip { font-size: .66rem; font-weight: 700; color: var(--ink-2); background: var(--surface-3); border-radius: 6px; padding: 2px 7px; }
.cm-note { margin: 0; font-size: .76rem; line-height: 1.45; background: var(--accent-soft); color: var(--ink-2); border-radius: 8px; padding: 7px 10px; }
.cm-note.warn { background: var(--warn-soft); }
.cm-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .8rem; }
.cm-kv dt { color: var(--muted); font-weight: 600; font-size: .72rem; }
.cm-kv dd { margin: 0; }
.cm-detail h3 { margin: 6px 0 0; font-size: .66rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.cm-rank { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cm-rrow { display: grid; grid-template-columns: auto auto 1fr auto 52px; gap: 8px; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: .8rem; cursor: pointer; background: var(--surface); text-align: left; font-family: inherit; color: inherit; border-left: 0; border-right: 0; border-top: 0; }
.cm-rrow:last-child { border-bottom: 0; }
.cm-rrow:hover { background: var(--surface-2); }
.cm-rrow.on { background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface)); }
.cm-rrow.btn { grid-template-columns: auto 1fr auto 52px; }
.cm-rrow input { margin: 0; accent-color: var(--teal); }
.cm-rname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-rname small { font-size: .66rem; }
.cm-time { font-weight: 700; font-variant-numeric: tabular-nums; border-radius: 6px; padding: 1px 6px; text-align: right; }
.cm-time.b1 { color: var(--good); } .cm-time.b2 { color: var(--warn); } .cm-time.b3 { color: var(--series-2); } .cm-time.b4 { color: var(--crit); }
.cm-mi { color: var(--muted); font-size: .72rem; text-align: right; font-variant-numeric: tabular-nums; }
.cm-est { margin-top: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.cm-est h3 { margin: 0; }
.cm-days { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.cm-days input { width: 72px; font: inherit; font-size: .86rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 7px; padding: 5px 8px; }
.cm-est-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.cm-est-out > div { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.cm-est-out small { font-size: .64rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.cm-est-out b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.cm-est-out .big b { font-size: 1.35rem; color: var(--accent-2); }

/* matrix */
.cm-card { padding: 16px 0 0; overflow: hidden; }
.cm-card-h { padding: 0 18px 12px; }
.cm-card-h h2 { margin: 0; font-size: .98rem; }
.cm-card-h p { margin: 4px 0 0; font-size: .78rem; color: var(--muted); }
/* the matrix fills the card's width (scrolls sideways only when it can't fit) */
.cm-mxwrap { overflow: auto; max-height: 760px; border-top: 1px solid var(--line); }
.cm-mx { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .82rem; font-variant-numeric: tabular-nums; }
.cm-mx th, .cm-mx td { padding: 11px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.cm-mx thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: .76rem; font-weight: 700; color: var(--ink-2); vertical-align: bottom; height: 160px; padding: 10px 4px; }
.cm-mx thead th span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; max-height: 148px; overflow: hidden; text-overflow: ellipsis; }
.cm-mx tbody th { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 600; font-size: .9rem; min-width: 196px; padding-left: 16px; }
.cm-mx-who { display: inline-flex; gap: 10px; align-items: center; }
.cm-mx thead th.cm-mx-corner { left: 0; z-index: 3; }
.cm-mx td { text-align: center; cursor: pointer; min-width: 56px; height: 46px; padding: 11px 5px; }
.cm-mx tbody tr:hover th { background: var(--surface-2); }
.cm-mx td.b1 { background: color-mix(in srgb, var(--good) 22%, var(--surface)); }
.cm-mx td.b2 { background: color-mix(in srgb, var(--series-4) 22%, var(--surface)); }
.cm-mx td.b3 { background: color-mix(in srgb, var(--series-2) 18%, var(--surface)); }
.cm-mx td.b4 { background: color-mix(in srgb, var(--crit) 12%, var(--surface)); color: var(--muted); }
.cm-mx td.here { outline: 2px solid var(--accent-2); outline-offset: -3px; font-weight: 800; }
.cm-mx td:hover { filter: brightness(.94); }

/* Leaflet markers */
.cm-jmark span { display: grid; place-items: center; width: 28px; height: 28px; margin: 1px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2.5px solid #fff; box-shadow: 0 2px 7px rgba(6, 33, 65, .5); color: #fff; }
.cm-jmark span i { display: grid; place-items: center; transform: rotate(45deg); width: 17px; height: 17px; }
.cm-jmark span svg { width: 100%; height: 100%; }
.cm-pmark { position: relative; }
.cm-pmark .cm-pm-i { --c: #2a78d6; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--c); color: #fff; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(6, 33, 65, .45); box-sizing: border-box; }
.cm-pmark .cm-pm-i svg { width: 17px; height: 17px; }
.cm-pmark.r-COO .cm-pm-i { width: 34px; height: 34px; margin: -2px; }
.cm-pmark .cm-pm-i svg { width: 19px; height: 19px; }
.cm-pmark .cm-pm-tag { position: absolute; left: 50%; top: 25px; transform: translateX(-50%); background: var(--c); color: #fff; border: 1.5px solid #fff; border-radius: 5px; padding: 0 3px; font: 800 8px/1.35 Montserrat, sans-serif; font-style: normal; letter-spacing: .02em; white-space: nowrap; box-shadow: 0 1px 3px rgba(6, 33, 65, .35); }
.cm-pmark.r-COO .cm-pm-tag { top: 28px; }
.cm-pmark .cm-pm-n { position: absolute; left: 24px; top: -6px; background: #fff; color: #062141; border-radius: 6px; padding: 1px 4px; font: 800 9px/1.2 Montserrat, sans-serif; box-shadow: 0 1px 3px rgba(6, 33, 65, .35); white-space: nowrap; }
.cm-tag span { --c: #062141; display: inline-block; transform: translate(-50%, -50%); background: #fff; color: #062141; border: 2px solid var(--c); border-radius: 7px; padding: 2px 6px; font: 700 11px/1.2 Montserrat, sans-serif; white-space: nowrap; box-shadow: 0 1px 4px rgba(6, 33, 65, .3); }
.cm .leaflet-container { font-family: Montserrat, system-ui, sans-serif; }
.leaflet-tooltip { font-family: Montserrat, system-ui, sans-serif; font-size: 12px; }

@media (max-width: 1100px) {
  .cm-main { grid-template-columns: minmax(0, 1fr); }
  .cm-side { max-height: none; }
  .cm-sbody { max-height: 620px; }
}
@media (max-width: 640px) {
  .cm-titles h1 { font-size: 1.3rem; }
  .cm-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .cm-kpi { padding: 12px 12px 10px; }
  .cm-kpi .v { font-size: 1.3rem; }
  .cm-map { height: 62vh; }
  .cm-mx { font-size: .78rem; }
  .cm-mx tbody th { min-width: 150px; font-size: .8rem; padding-left: 10px; }
  .cm-mx td { min-width: 60px; height: 40px; padding: 8px 6px; }
  .cm-mx thead th { height: 130px; }
}
/* OSM tiles are light only: soften them in light mode, invert them for dark */
.cm-map .leaflet-tile-pane { filter: saturate(.55) contrast(.95) brightness(1.03); }
.cm-map.cm-dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.4); }
.cm-map.cm-dark { background: #0b1d33; }
@media (max-width: 640px) {
  .cm-lg { border-left: 0; padding: 0 12px; flex-basis: 100%; }
  .cm-legend { gap: 12px 0; }
}
