/* WCPR Crew. Tokens tuned for glare and gloves on crew screens, density on manager screens.
   CSP is style-src 'self': no inline style attributes; dynamic colors are set from JS via el.style. */
:root {
  --red: #C8102E; --red-dark: #9e0c24; --ink: #1f1f1f; --char: #2b2b2b;
  --muted: #5c5c5c; --line: #dddcd8; --field: #8a8984; --bg: #f4f4f2; --card: #fff;
  --ok: #155d2c; --ok-tint: #dff1e4; --warn: #8a4b00; --warn-tint: #fdefd6; --bad: #a50d26; --bad-tint: #fbe0e5;
  --info: #1d3f73; --info-tint: #e6eef8;
  --state-on: #155d2c; --state-break: #a35400;
  --focus: #1f1f1f; --focus-on-dark: #ffd23f;
  --tap: 56px; --tap-hero: 88px; --radius: 10px; --gap: 12px;
  --font: Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); }
body.crew { font-size: 17px; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 0 0 6px; line-height: 1.2; }
h2 { font-size: 19px; margin: 0 0 10px; line-height: 1.25; }
h3 { font-size: 14px; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
p { margin: 8px 0; }
.muted { color: var(--muted); } .small { font-size: 14px; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-weight: 700; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.top :focus-visible, .dark:focus-visible, .band :focus-visible { outline-color: var(--focus-on-dark); }

/* ---------- Top bar ---------- */
.top { position: sticky; top: 0; z-index: 1000; background: var(--ink); color: #fff; padding-top: env(safe-area-inset-top); }
.top-in { max-width: 1180px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; }
.brand { display: flex; gap: 8px; align-items: baseline; }
.mark { font-weight: 700; letter-spacing: .08em; background: var(--red); padding: 2px 8px; border-radius: 4px; }
.sub { font-weight: 700; }
.who { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; padding: 8px 4px; min-height: 44px; }
.net { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.net::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #3fb468; }
.net.off::before { background: #f0a020; }

/* Language toggle */
.lang { display: inline-flex; border: 2px solid currentColor; border-radius: 8px; overflow: hidden; }
.lang button { border: 0; border-radius: 0; background: transparent; min-height: 40px; min-width: 48px; padding: 6px 10px; font-weight: 700; }
.lang button[aria-pressed=true] { background: var(--red); color: #fff; }
.top .lang { color: #fff; }
.card .lang { color: var(--ink); }

main { max-width: 1180px; margin: 0 auto; padding: 16px; padding-bottom: 120px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.narrow { max-width: 440px; margin: 6vh auto; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.cardhead h1, .cardhead h2 { margin: 0; }

/* ---------- Forms ---------- */
label { display: block; font-size: 15px; font-weight: 700; margin: 14px 0 0; }
input, select, textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; min-height: 48px; border: 1px solid var(--field); border-radius: 8px; background: #fff; }
body.crew input, body.crew select { min-height: var(--tap); font-size: 18px; }
input.pinbox { font: 700 28px/1 ui-monospace, Menlo, monospace; letter-spacing: .5em; text-align: center; padding-left: .5em; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--red); vertical-align: middle; }
.field-help { font-size: 14px; color: var(--muted); margin-top: 4px; font-weight: 400; }

/* ---------- Buttons ---------- */
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--field); background: #fff; color: var(--ink); padding: 10px 16px; min-height: 44px; font-weight: 700; }
a.block, .row > a, .cardhead a, .pagehead a { text-decoration: none; display: inline-block; }
a.block { display: block; }
button:disabled { cursor: default; background: #e9e8e4; border-color: #cfcdc7; color: var(--muted); }
.primary { background: var(--red); border-color: var(--red); color: #fff; }
.primary:hover:not(:disabled) { background: var(--red-dark); }
.dark { background: var(--char); border-color: var(--char); color: #fff; }
.ghost { background: transparent; border-color: transparent; text-decoration: underline; }
.top button { color: #fff; }
.lang button[aria-pressed=false] { color: inherit; }
.danger { color: var(--bad); border-color: var(--bad); background: #fff; }
.danger.solid { background: var(--bad); color: #fff; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.block { width: 100%; }
.big { width: 100%; min-height: var(--tap); font-size: 18px; margin-top: 16px; }
.hero { width: 100%; min-height: var(--tap-hero); font-size: 24px; border-radius: 14px; }
.mid { width: 100%; min-height: 72px; font-size: 20px; border-radius: 12px; }
button[aria-busy=true]::before { content: ""; display: inline-block; width: 18px; height: 18px; margin-right: 10px; vertical-align: -3px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > h1, .row > h2 { margin: 0; }
.spacer { flex: 1; }

/* ---------- Pills ---------- */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: #ecebe8; color: var(--char); white-space: nowrap; }
.pill.ok { background: var(--ok-tint); color: var(--ok); }
.pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.bad { background: var(--bad-tint); color: var(--bad); }
.pill.info { background: var(--info-tint); color: var(--info); }
.pill.dark { background: var(--char); color: #fff; }

/* ---------- Banner + toast ---------- */
.banner { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 900; display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-bottom: 2px solid; }
.banner.bad { background: var(--bad-tint); color: var(--bad); border-color: var(--bad); }
.banner.warn { background: var(--warn-tint); color: var(--warn); border-color: var(--warn); }
.banner .b-text { flex: 1; max-width: 1148px; }
.banner b { display: block; }
.banner button { min-height: 40px; }
.toast { position: fixed; left: 50%; top: calc(72px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 3000; max-width: 92vw; font-weight: 700; }
.toast.show { opacity: 1; }
.success { position: fixed; inset: 0; z-index: 3500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: var(--state-on); color: #fff; font-size: 22px; font-weight: 700; text-align: center; padding: 24px; }
.success .check { width: 96px; height: 96px; border-radius: 50%; border: 6px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 56px; }

/* ---------- Dialog (bottom sheet on phones) ---------- */
dialog { border: 0; border-radius: 12px; padding: 18px; width: min(560px, 94vw); max-height: 92vh; overflow: auto; color: var(--ink); }
dialog::backdrop { background: #0008; }
#dlgActions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
@media (max-width: 560px) {
  dialog { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 16px 16px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  #dlgActions { position: sticky; bottom: 0; background: #fff; padding-top: 8px; }
  #dlgActions button { flex: 1; min-height: 52px; }
}
.secret { font: 700 30px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .12em; background: var(--bg); padding: 14px; border-radius: 8px; text-align: center; user-select: all; }

/* ---------- Crew home ---------- */
.dateline { font-size: 14px; color: var(--muted); }
.jobcard { display: flex; gap: 12px; align-items: flex-start; min-height: 72px; padding: 14px; margin: 8px 0 0; border: 2px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 400; }
.jobcard input { margin-top: 3px; }
.jobcard:has(input:checked) { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.jobcard b { display: block; font-size: 18px; }
.statecard { padding: 0; overflow: hidden; }
.band { padding: 16px; color: #fff; }
.band.on { background: var(--state-on); } .band.break { background: var(--state-break); }
.band .label { font-size: 14px; font-weight: 700; letter-spacing: .08em; }
.band .since { font-size: 20px; font-weight: 700; margin-top: 2px; }
.band .timer { font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.1; }
.statebody { padding: 16px; }
.punchbar { position: sticky; bottom: 0; z-index: 800; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to bottom, #f4f4f200, var(--bg) 18%); }
.punchbar .divider { height: 1px; background: var(--line); margin: 0 0 12px; }
.photo-row { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.gpspanel { border: 2px solid var(--warn); background: var(--warn-tint); color: var(--ink); border-radius: 12px; padding: 16px; }
.gpspanel h2 { color: var(--warn); }
.gpspanel ol { padding-left: 20px; margin: 8px 0; }
.summary-big { font-size: 34px; font-weight: 700; line-height: 1.1; }
.iconbtn { min-width: 48px; min-height: 48px; padding: 0; font-size: 20px; }

/* Member list (foreman) */
.seg { display: flex; border: 2px solid var(--char); border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; border-radius: 0; min-height: 52px; background: #fff; }
.seg button[aria-pressed=true] { background: var(--char); color: #fff; }
label.member { display: flex; align-items: center; gap: 14px; min-height: 64px; margin: 0; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 18px; cursor: pointer; }
label.member input { width: 28px; height: 28px; }
label.member .name { flex: 1; }

/* ---------- Lists / tables ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .r { text-align: right; white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; background: var(--char); color: #fff; padding: 8px; white-space: nowrap; font-weight: 700; }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 4px; }
tr.group td { background: #efeeea; font-weight: 700; border-top: 2px solid var(--char); }
tr.sel td { background: #fff6f7; }
@media (max-width: 720px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: #fff; padding: 6px 0; }
  table.stack tr.group { background: none; border: 0; padding: 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 5px 12px; text-align: right; }
  table.stack td[data-label]::before { content: attr(data-label); font-weight: 700; color: var(--muted); text-align: left; }
  table.stack tr.group td { display: block; text-align: left; padding: 8px 4px; background: none; border-top: 0; }
  table.stack, table.stack tbody { display: block; width: 100%; }
  .table-wrap { overflow-x: visible; }
  .card.table-wrap { padding: 8px; background: transparent; border: 0; }
  .toolbar label { flex: 1 1 140px; }
  .toolbar input, .toolbar select, .toolbar input[type=date] { width: 100%; min-width: 0; }
  table.stack td.actions { justify-content: flex-end; }
  table.stack td { flex-wrap: wrap; } table.stack td .pill { white-space: normal; }
}

/* ---------- Manager shell ---------- */
.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 2px solid var(--line); }
.tabs button { border: 0; border-radius: 8px 8px 0 0; background: none; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected=true] { color: var(--ink); box-shadow: inset 0 -3px 0 var(--red); }
.tabsel { display: none; }
@media (max-width: 720px) { .tabs { display: none; } .tabsel { display: block; margin-bottom: 14px; } }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; flex-wrap: wrap; }
.pagehead h1 { margin: 0; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar label { margin: 0; font-size: 13px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; min-height: 40px; padding: 6px 10px; }
.toolbar input[type=date] { width: 165px; }
.toolbar .rangelabel { font-weight: 700; min-width: 140px; text-align: center; }
.chip { border-radius: 999px; min-height: 36px; padding: 4px 14px; font-size: 14px; }
.chip[aria-pressed=true] { background: var(--char); color: #fff; border-color: var(--char); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: left; font-weight: 400; min-height: 0; }
.kpi b { display: block; font-size: 26px; line-height: 1.15; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi.zero b { color: var(--muted); }
.kpi.alert { border-left: 5px solid var(--bad); } .kpi.alert b { color: var(--bad); }
button.kpi { cursor: pointer; }

.livegrid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .livegrid { grid-template-columns: 1fr; } }
#map { height: calc(100vh - 280px); min-height: 380px; border-radius: var(--radius); border: 1px solid var(--line); }
.pin { width: 32px; height: 32px; border-radius: 50%; background: var(--state-on); color: #fff; border: 2px solid #fff; box-shadow: 0 1px 4px #0006; display: flex; align-items: center; justify-content: center; font: 700 12px var(--font); }
.pin.out { background: var(--warn); } .pin.brk { background: var(--state-break); } .pin.hl { box-shadow: 0 0 0 4px var(--focus-on-dark), 0 1px 4px #0006; }
.alertbox { border: 2px solid var(--bad); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; background: #fff; }
.alertbox h3 { color: var(--bad); margin-top: 0; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { background: #faf9f7; }

/* Schedule week grid */
.week { display: grid; grid-template-columns: 170px repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.week > div { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px; min-height: 64px; min-width: 0; }
.week .wh { background: var(--char); color: #fff; font-weight: 700; font-size: 13px; min-height: 0; }
.week .wh.today { background: var(--red); }
.week .rowname { font-weight: 700; font-size: 14px; background: #faf9f7; }
.week .today { background: #fff6f7; }
.wchip { display: block; width: 100%; text-align: left; font-size: 12px; font-weight: 700; padding: 4px 6px; min-height: 0; margin-bottom: 4px; border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 6px; background: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wadd { width: 100%; min-height: 28px; padding: 0; border: 1px dashed #cfcdc7; color: var(--muted); background: transparent; font-weight: 400; }
@media (max-width: 900px) { .week { display: none; } .weeklist { display: block; } }
@media (min-width: 901px) { .weeklist { display: none; } }

.photo { display: block; max-width: 100%; border-radius: 8px; }
.trail { height: 360px; border-radius: 8px; }
.bar { height: 8px; background: var(--red); border-radius: 4px; min-width: 2px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.crewcard { border-top: 5px solid var(--muted); }
.form640 { max-width: 640px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 480px) {
  .top-in { padding: 8px 12px; gap: 6px; }
  .net { font-size: 0; gap: 0; }
  #whoName { display: none; }
  .top .lang button { min-width: 42px; padding: 6px 8px; }
}
