:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --ink: #1b1714;
  --ink-2: #5a524b;
  --line: #e4dcd2;
  --brand: #e2531d;
  --green: #17803d;
  --amber: #f2b01e;
  --amber-ink: #3a2a00;
  --red: #c4231c;
  --stop: #3b0c10;
  --emergency: #e5001b;
  --grey: #7b746d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 23, 20, .06), 0 4px 16px rgba(27, 23, 20, .06);
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-rtl: "Noto Naskh Arabic", "Noto Nastaliq Urdu", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f; --surface: #1f1b18; --ink: #f3ede6; --ink-2: #b4aaa0; --line: #352f2a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[dir="rtl"] .question, [dir="rtl"] .answer, [dir="rtl"] .symptom, [dir="rtl"] .instruction { font-family: var(--font-rtl); }
:lang(ur), :lang(ar) { font-family: var(--font-rtl); line-height: 1.8; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; margin-top: 1em; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.center { text-align: center; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

#main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 40px; min-height: 70vh; }
.foot { text-align: center; color: var(--ink-2); font-size: .8rem; padding: 20px 16px 32px; }

/* --- chrome ---------------------------------------------------------------- */
#chrome { position: sticky; top: 0; z-index: 20; background: #14110f; color: #f3ede6; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1100px; margin: 0 auto; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; font-size: 1.1rem; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: conic-gradient(from 200deg, #f2b01e, #e2531d, #c4231c, #f2b01e); }
.roles { display: flex; gap: 4px; margin-left: auto; }
.roles a { text-decoration: none; padding: 6px 10px; border-radius: 8px; color: #cfc6bd; font-weight: 600; }
.roles a.on, .roles a:hover { background: #2c2622; color: #fff; }
.mode { display: flex; background: #2c2622; border-radius: 10px; padding: 3px; }
.seg { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; min-height: 36px; }
.mode .seg { color: #cfc6bd; }
.mode .seg.on { background: var(--brand); color: #fff; }
.statusbar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 6px 16px 10px; max-width: 1100px; margin: 0 auto; font-size: .85rem; color: #cfc6bd; }
.statusbar .heat { color: #fff; font-weight: 700; }
.statusbar .store.warn { color: #ffb84d; }
.site-select { background: #2c2622; border: 1px solid #3e3631; border-radius: 8px; padding: 4px 8px; color: #fff; }
.sim-badge { background: #f2b01e; color: #241a00; font-weight: 800; font-size: .72rem; letter-spacing: .08em; padding: 3px 8px; border-radius: 6px; }
.sim-badge.inline { margin-left: 8px; vertical-align: middle; }
.demobar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; background: #2c2622; justify-content: center; }
.demo-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: #cfc6bd; }
.demo-clock { font: 800 1.4rem/1 var(--font); font-variant-numeric: tabular-nums; color: #fff; min-width: 4ch; }
.speed { background: #1b1714; color: #fff; border: 1px solid #3e3631; border-radius: 8px; padding: 6px; }

/* --- buttons --------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 12px; font-weight: 700; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.demobar .btn { background: #1b1714; border-color: #3e3631; color: #fff; }
.btn.primary, .demobar .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.huge { display: flex; width: 100%; font-size: 1.35rem; padding: 20px; margin: 18px 0 10px; border-radius: 18px; }
.btn.big { font-size: 1.1rem; padding: 14px 20px; }
.btn.ghost { background: transparent; display: flex; width: 100%; }
.btn.ghost.light { color: #fff; border-color: rgba(255,255,255,.5); }
.btn.action { background: #14110f; color: #fff; border-color: #14110f; }
@media (prefers-color-scheme: dark) { .btn.action { background: #f3ede6; color: #14110f; } }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(226, 83, 29, .25); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 14px 0; box-shadow: var(--shadow); }
.chip { display: inline-block; font-size: .8rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: rgba(127,127,127,.14); margin: 2px 4px 2px 0; }
.chip-new { background: #ffe1d6; color: #7a2300; }
.chip-warn { background: #fff0c2; color: #5a3d00; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; background: #14110f; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 100; transition: .25s; font-weight: 600; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- colours --------------------------------------------------------------- */
.c-green { --c: var(--green); --c-ink: #fff; }
.c-amber { --c: var(--amber); --c-ink: var(--amber-ink); }
.c-red { --c: var(--red); --c-ink: #fff; }
.c-stop { --c: var(--stop); --c-ink: #fff; }
.c-emergency { --c: var(--emergency); --c-ink: #fff; }
.c-grey { --c: var(--grey); --c-ink: #fff; }

/* --- home ------------------------------------------------------------------ */
.hero { padding: 18px 0 6px; max-width: 760px; }
.lede { font-size: 1.1rem; color: var(--ink-2); }
.note { background: #fff4d6; color: #3a2a00; border-left: 4px solid var(--amber); padding: 10px 14px; border-radius: 8px; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.role-card { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); transition: transform .15s; }
.role-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.role-card h2 { font-size: 1.4rem; }
.role-card p { color: var(--ink-2); margin: 0 0 10px; }
.pin-hint { font-size: .8rem; font-weight: 700; color: var(--brand); }
.honest ul { margin: 0; padding-left: 1.2em; }
.pin { max-width: 360px; margin: 40px auto; text-align: center; }
.pin-input { width: 100%; font-size: 2rem; text-align: center; letter-spacing: .4em; padding: 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); margin: 8px 0; }
.pin-err { color: var(--red); min-height: 1.2em; font-weight: 700; }

/* --- worker ---------------------------------------------------------------- */
.tri { display: flex; flex-direction: column; gap: 2px; }
.tri span + span { font-size: .8em; color: var(--ink-2); }
.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.name-btn { display: flex; flex-direction: column; text-decoration: none; background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 16px; min-height: 76px; justify-content: center; }
.name-btn:active, .name-btn:hover { border-color: var(--brand); }
.name-btn .name { font-size: 1.25rem; font-weight: 800; }
.name-btn .role { color: var(--ink-2); font-size: .9rem; }
.lang-switch { display: flex; gap: 6px; margin: 4px 0 14px; flex-wrap: wrap; }
.lang-switch .seg { border: 1px solid var(--line); background: var(--surface); }
.lang-switch .seg.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.who h1 { margin: 0 8px 0 0; }
.status-block { background: var(--c); color: var(--c-ink); border-radius: 22px; padding: 22px; margin: 14px 0; }
.status-label { font-size: .85rem; text-transform: uppercase; letter-spacing: .1em; opacity: .85; font-weight: 700; }
.status-big { font-size: clamp(3rem, 14vw, 5rem); font-weight: 800; line-height: 1; margin: 6px 0; }
.status-ratio { font-size: 2rem; font-weight: 800; }
.status-ratio small { font-size: .9rem; font-weight: 600; opacity: .9; }
.instruction { font-size: 1.25rem; font-weight: 600; margin: 12px 0 0; }
.instruction.water { font-size: 1.05rem; background: rgba(255,255,255,.18); padding: 8px 12px; border-radius: 10px; }
.why { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.why summary { font-weight: 700; cursor: pointer; }
.progress { display: flex; gap: 6px; margin-bottom: 18px; }
.progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.progress span.on { background: var(--brand); }
.question { font-size: clamp(1.7rem, 6vw, 2.4rem); margin: 6px 0 20px; }
.answer-col, .answer-row { display: grid; gap: 12px; }
.answer-row { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 14px; }
.answer { border: 0; border-radius: 20px; padding: 26px 16px; font-size: 1.6rem; font-weight: 800; cursor: pointer; min-height: 96px; }
.answer.good { background: var(--green); color: #fff; }
.answer.bad { background: var(--red); color: #fff; }
.answer.neutral { background: var(--surface); border: 2px solid var(--line); font-size: 1.2rem; }
.answer.primary { background: var(--brand); color: #fff; font-size: 1.3rem; }
.symptom-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
[dir="rtl"] { font-family: var(--font-rtl); }
.symptom { width: 100%; border: 2px solid var(--line); background: var(--surface); border-radius: 16px; padding: 16px 10px; font-size: 1.15rem; font-weight: 700; cursor: pointer; min-height: 70px; }
.symptom.redflag { border-color: #f1b3ad; }
.symptom.on { background: #ffe3cf; border-color: var(--brand); color: #3d1500; }
.symptom.redflag.on { background: var(--red); border-color: var(--red); color: #fff; }

.emergency { background: var(--emergency); color: #fff; border-radius: 22px; padding: 22px; }
.emergency h1 { font-size: clamp(1.8rem, 7vw, 2.6rem); }
.em-who { font-weight: 700; opacity: .95; }
.em-call { font-size: 1.4rem; font-weight: 800; background: #fff; color: var(--emergency); border-radius: 12px; padding: 12px 14px; }
.em-steps { font-size: 1.15rem; font-weight: 600; padding-inline-start: 1.4em; }
.em-steps li { margin: 8px 0; }
.em-alerted { font-weight: 700; background: rgba(0,0,0,.2); padding: 8px 12px; border-radius: 10px; }
.em-source { font-size: .8rem; opacity: .85; }
.emergency .lang-switch .seg { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.4); }
.emergency .lang-switch .seg.on { background: #fff; color: var(--emergency); }

/* --- supervisor ------------------------------------------------------------ */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; margin-top: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; flex: 1; max-width: 720px; margin: 8px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.kpi-v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-l { font-size: .78rem; color: var(--ink-2); }
.kpi.warn { border-color: var(--red); }
.kpi.warn .kpi-v { color: var(--red); }
.section-title { margin-top: 18px; }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.wcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.wcard-top { display: flex; justify-content: space-between; gap: 8px; background: var(--c); color: var(--c-ink); padding: 12px 14px; }
.wname { font-weight: 800; font-size: 1.1rem; }
.wmeta { font-size: .8rem; opacity: .9; }
.wlevel { text-align: right; font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.wlevel small { display: block; font-size: .9rem; }
.wcard-body { padding: 10px 14px 0; }
.wcard.c-emergency { animation: flash 1s steps(2) infinite; border-color: var(--emergency); }
@keyframes flash { 50% { box-shadow: 0 0 0 4px var(--emergency); } }
.wcard.flagged { border: 2px dashed var(--red); }
.slots { display: flex; gap: 4px; padding: 10px 14px 4px; }
.slot { flex: 1; text-align: center; font-size: .72rem; font-weight: 700; border-radius: 6px; padding: 3px 0; background: var(--line); color: var(--ink-2); }
.slot.s-done { background: var(--green); color: #fff; }
.slot.s-missed { background: var(--red); color: #fff; }
.slot.s-due { background: transparent; outline: 2px solid var(--brand); color: var(--brand); }
.slot.s-none { opacity: .5; }
.slot.s-off { opacity: .35; text-decoration: line-through; }
.flag { margin: 6px 14px 0; font-size: .85rem; font-weight: 800; color: var(--red); }
.card-why { padding: 6px 14px 12px; font-size: .88rem; }
.card-why summary { cursor: pointer; font-weight: 700; color: var(--ink-2); }
.card-why p { margin: 6px 0 0; }
.warn-text { color: var(--red); font-weight: 700; }

.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 420px; overflow: auto; }
.alert { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-left: 6px solid var(--grey); border-radius: 12px; padding: 10px 12px; }
.alert.open { background: rgba(196, 35, 28, .05); }
.alert.t-emergency { border-left-color: var(--emergency); }
.alert.t-stop { border-left-color: var(--stop); }
.alert.t-symptoms { border-left-color: var(--amber); }
.alert.t-missed { border-left-color: var(--red); }
.alert.done { opacity: .75; }
.alert-main b { margin-right: 6px; }
.alert-type, .tag { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin-right: 8px; }
.alert-time { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.alert-why { margin: 2px 0 0; font-size: .85rem; color: var(--ink-2); }
.alert-done { text-align: right; font-weight: 700; font-size: .9rem; white-space: nowrap; }
.alert-done small { display: block; font-weight: 500; color: var(--ink-2); }
.tag.t-emergency { color: var(--emergency); } .tag.t-missed { color: var(--red); }

.fc-scroll, .table-scroll { overflow-x: auto; }
.fc { border-collapse: separate; border-spacing: 3px; font-size: .78rem; min-width: 560px; }
.fc th { font-weight: 700; color: var(--ink-2); text-align: left; white-space: nowrap; padding-right: 6px; }
.fc thead th { text-align: center; }
.fc-num { text-align: center; font-variant-numeric: tabular-nums; }
.fc-cell { background: var(--c); color: var(--c-ink); text-align: center; border-radius: 5px; padding: 6px 2px; font-weight: 700; min-width: 34px; }

.overlay { position: fixed; inset: 0; background: rgba(20, 0, 0, .65); z-index: 50; display: grid; place-items: center; padding: 14px; overflow: auto; }
.overlay-box { max-width: 640px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.overlay-actions { display: grid; gap: 10px; margin-top: 12px; }
.overlay .btn.action { background: #fff; color: var(--emergency); border-color: #fff; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.form label { display: block; font-weight: 600; font-size: .9rem; margin: 8px 0; }
.form input:not([type=checkbox]), .form select { display: block; width: 100%; margin-top: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); min-height: 44px; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label.check { display: flex; gap: 8px; align-items: center; }
.form input[type=checkbox] { width: 22px; height: 22px; }

/* --- HSE / charts ---------------------------------------------------------- */
.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--ink-2); font-size: 11px; }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.chart .bar { fill: var(--ink-2); }
.chart .band { opacity: .16; }
.chart .b-amber { fill: var(--amber); } .chart .b-red { fill: var(--red); } .chart .b-stop { fill: var(--stop); }
@media (prefers-color-scheme: dark) { .chart .b-stop { fill: #ff8a8a; } }
.chart .now-line { stroke: var(--brand); stroke-width: 2; stroke-dasharray: 4 3; }
.chart .now-dot { fill: var(--brand); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart-tip { position: absolute; transform: translate(-50%, -130%); background: #14110f; color: #fff; font-size: .8rem; padding: 5px 8px; border-radius: 6px; pointer-events: none; white-space: nowrap; z-index: 2; }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--ink-2); font-weight: 700; }
.tbl tr.open td { background: rgba(196, 35, 28, .06); }
.why-cell { min-width: 220px; color: var(--ink-2); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.boot { display: grid; place-items: center; min-height: 60vh; gap: 12px; color: var(--ink-2); }
.boot-mark { width: 40px; height: 40px; border-radius: 10px; background: conic-gradient(from 200deg, #f2b01e, #e2531d, #c4231c, #f2b01e); animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .roles { order: 3; width: 100%; margin-left: 0; }
  .roles a { flex: 1; text-align: center; }
  .mode { margin-left: auto; }
  .answer { font-size: 1.35rem; padding: 22px 10px; }
  .alert { flex-direction: column; align-items: stretch; }
  .alert-done { text-align: left; }
  .statusbar { font-size: .78rem; padding-top: 2px; gap: 2px 10px; }
  .statusbar .store { display: none; }
  .demobar { gap: 6px; padding: 6px 10px; }
  .demo-label, .speed { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .roles a { padding: 4px 6px; }
}
@media (prefers-reduced-motion: reduce) { .pulse, .wcard.c-emergency, .boot-mark { animation: none; } }

/* --- advanced: briefing, plan, vitals, sites, what-if, voice ---------------- */
.brief-lines { margin: .2em 0 .4em; padding-left: 1.1em; }
.brief-lines li { margin: .25em 0; }
.plan { margin-top: 1em; border-top: 1px solid var(--line); padding-top: .4em; }
.chip.vitals { font-variant-numeric: tabular-nums; }
.chip.vitals.v-elevated { background: #fdf0d5; color: var(--amber-ink); border-color: var(--amber); }
.chip.vitals.v-high { background: #fbe3e1; color: var(--red); border-color: var(--red); font-weight: 700; }
.vitals-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 12px 0; }
.vitals-panel.v-elevated { border-color: var(--amber); }
.vitals-panel.v-high { border-color: var(--red); border-width: 2px; }
.vitals-nums { display: flex; gap: 22px; align-items: baseline; flex-wrap: wrap; }
.vitals-nums b { font-size: 1.7rem; font-weight: 800; }
.vitals-nums small { color: var(--ink-2); margin-left: 4px; }
.vitals-zone { margin-left: auto; font-weight: 700; }
.vitals-panel.v-high .vitals-zone { color: var(--red); }
.vitals-panel.v-elevated .vitals-zone { color: var(--amber-ink); }
.site-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.site-card { border: 1px solid var(--line); border-top: 5px solid var(--grey); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.site-card.c-green { border-top-color: var(--green); }
.site-card.c-amber { border-top-color: var(--amber); }
.site-card.c-red { border-top-color: var(--red); }
.site-card.c-stop, .site-card.c-emergency { border-top-color: var(--stop); }
.site-wbgt { font-size: 1.15rem; font-weight: 800; margin: .2em 0; }
.whatif-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-bottom: 12px; }
.whatif-controls label { display: block; font-weight: 600; }
.whatif-controls input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--brand); }
.btn.mic { display: inline-block; margin: 0 0 12px; background: var(--surface); border: 2px solid var(--brand); color: var(--brand); font-weight: 700; border-radius: 999px; padding: 10px 18px; cursor: pointer; min-height: 48px; }
