/* Light theme. A subtle nod to AEP's site: white, airy pages; charcoal type; deep red for actions;
   light grey tiles and soft blue / green / aqua tints; blue line icons; DIN-like type (Barlow). */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --tile: #f3f3f3;
  --ink: #3b3d3f;
  --muted: #676a6e;
  --line: #e3e3e3;
  --line-strong: #c9cacc;
  --red: #af2218;
  --red-hover: #8e1a12;
  --red-soft: #fbeceb;
  --icon: #0b5ea8;
  --focus: #0b5ea8;

  --tint-blue: #d8e5ef;
  --tint-green: #e8f1da;
  --tint-aqua: #d9eef2;
  --blue-ink: #1f4f7a;
  --green: #1b852a;
  --green-ink: #2f6b12;
  --amber: #8a4b00;
  --amber-soft: #fdf0dc;

  --radius: 12px;
  --radius-btn: 6px;
  --font: Barlow, "Segoe UI", Arial, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1rem/1.5 var(--font);
}
h1, h2, h3 { color: var(--ink); font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: 2rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
p { margin: 0; }
a { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ico { width: 24px; height: 24px; flex: none; color: var(--icon); vertical-align: middle; }
.ico.sm { width: 18px; height: 18px; margin-top: -3px; }
.ico.lg { width: 36px; height: 36px; }
.ico.xl { width: 64px; height: 64px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
main:focus, h1:focus { outline: none; }
.skip { position: absolute; left: 1rem; top: -3rem; z-index: 30; background: #fff; padding: .5rem 1rem; border-radius: var(--radius-btn); }
.skip:focus { top: .5rem; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: #fff; box-shadow: 0 2px 6px rgba(59, 61, 63, .08); }
.topbar-inner { max-width: 960px; margin: 0 auto; padding: .75rem 16px; display: flex; align-items: center; gap: .75rem; min-height: 68px; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; }
.mark {
  display: grid; place-items: center; width: 1.9rem; height: 1.9rem;
  border: 2px solid var(--red); color: var(--red); border-radius: 4px; font-weight: 700; transform: skewX(-8deg);
}
.pill { margin-right: auto; font-size: .75rem; font-weight: 600; color: var(--muted); padding: .2rem .6rem; border-radius: 99px; background: var(--tile); }
.pill::before { content: "●"; margin-right: .3rem; }
.pill.online::before { color: var(--green); }
.pill.offline { background: var(--amber-soft); color: var(--amber); }
.pill.offline::before { color: #d98a00; }
.topbar .btn { min-height: 42px; padding: .4rem .9rem; }
.avatar {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: var(--tint-blue); color: var(--blue-ink); text-decoration: none; font-weight: 700; font-size: .9rem;
}
.avatar:hover { background: #c7d9e8; }
.offline-bar { background: var(--amber-soft); color: var(--amber); text-align: center; font-size: .9rem; font-weight: 600; padding: .5rem 16px; }

main { max-width: 960px; margin: 0 auto; padding: 2rem 16px 1rem; }
.foot { max-width: 960px; margin: 0 auto; padding: 2.5rem 16px 3rem; color: var(--muted); font-size: .85rem; text-align: center; display: grid; gap: .25rem; }
.foot a, .foot .link { color: var(--muted); font-weight: 500; }

body.setup-mode #newTop, body.setup-mode #me, body.setup-mode .foot { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: 1rem; font-weight: 700; cursor: pointer; text-decoration: none;
  min-height: 48px; padding: .6rem 1.4rem;
  border: 2px solid var(--line-strong); border-radius: var(--radius-btn);
  background: #fff; color: var(--ink);
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-hover); border-color: var(--red-hover); }
.btn.secondary { border-color: var(--red); color: var(--red); }
.btn.secondary:hover:not(:disabled) { background: var(--red-soft); border-color: var(--red); }
.btn.ghost { border: 2px dashed var(--line-strong); color: var(--muted); }
.btn.warn { border-color: var(--amber); color: var(--amber); }
.btn.warn:hover:not(:disabled) { background: var(--amber-soft); border-color: var(--amber); }
.btn.danger { border-color: transparent; background: transparent; color: var(--red); padding-inline: .75rem; }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); border-color: transparent; }
.btn.small { min-height: 40px; padding: .35rem .9rem; font-size: .9rem; }
.icon { flex: none; width: 44px; height: 44px; border: 0; border-radius: var(--radius-btn); background: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; }
.icon:hover { color: var(--red); background: var(--red-soft); }
.link { border: 0; background: none; color: var(--red); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; padding: .5rem .25rem; }

/* ---------- home / list ---------- */
.intro { margin-bottom: 1.75rem; }
.eyebrow { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-weight: 600; font-size: .9rem; margin-bottom: .5rem; }
.lead { margin-top: .6rem; color: var(--muted); font-size: 1.1rem; max-width: 42rem; }
.lead b { color: var(--ink); font-weight: 600; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-top: 1.25rem; }
.tile {
  display: grid; gap: .1rem; align-content: start; text-align: left;
  font: inherit; color: var(--ink); border: 0; border-radius: var(--radius); padding: 1rem 1.1rem;
}
button.tile { cursor: pointer; transition: filter .15s; }
button.tile:hover { filter: brightness(.97); }
.tile b { font-size: 2rem; line-height: 1.1; }
.tile span { font-size: .9rem; font-weight: 500; }
.t-blue { background: var(--tint-blue); }
.t-aqua { background: var(--tint-aqua); }
.t-green { background: var(--tint-green); }
.t-grey { background: var(--tile); }

.scope { display: inline-flex; background: var(--tile); border-radius: var(--radius-btn); padding: 4px; margin-bottom: 1rem; }
.seg {
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  min-height: 40px; padding: .3rem .9rem; border: 0; border-radius: 4px; background: transparent; color: var(--muted);
}
.seg b { font-weight: 600; opacity: .8; margin-left: .2rem; }
.seg[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(59, 61, 63, .15); }

.toolbar { display: grid; gap: .75rem; margin-bottom: 1.5rem; }
.filters { display: flex; gap: .5rem; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.chip {
  flex: none; font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: .35rem .9rem; border-radius: var(--radius-btn);
  border: 0; background: var(--tile); color: var(--ink);
}
.chip b { color: var(--muted); font-weight: 600; margin-left: .25rem; }
.chip:hover { background: #e8e8e8; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }
.chip[aria-pressed="true"] b { color: #d5d6d8; }

input, select, textarea { font: inherit; color: var(--ink); }
.search, .field input, .field select, .field textarea, .steps input, .crew input, .hazard textarea {
  width: 100%; min-height: 48px; padding: .65rem .85rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-btn); background: #fff;
}
.search { padding-left: 2.5rem; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23676a6e' stroke-width='2'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='m13 13 4 4'/%3E%3C/svg%3E") no-repeat .85rem center; }
::placeholder { color: #909397; }
textarea { resize: vertical; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.card {
  display: block; position: relative; text-decoration: none; color: var(--ink); font-weight: 400;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.1rem 1.45rem; transition: border-color .15s, box-shadow .15s;
}
.card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--line-strong); }
.card.st-review::before { background: var(--icon); }
.card.st-active::before { background: #d98a00; }
.card.st-closed::before { background: var(--green); }
.card:hover { border-color: var(--line-strong); box-shadow: 0 4px 14px rgba(59, 61, 63, .08); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.card-title { font-size: 1.2rem; margin: .6rem 0 .25rem; }
.card-meta { color: var(--muted); font-size: .95rem; }
.card-meta .ico { color: var(--icon); }
.card-next { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--line); font-size: .95rem; font-weight: 600; }
.card.st-closed .card-next { color: var(--muted); font-weight: 400; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); display: grid; gap: 1rem; justify-items: center; background: var(--tile); border-radius: var(--radius); }

.status { display: inline-block; font-size: .78rem; font-weight: 700; letter-spacing: .02em; padding: .2rem .65rem; border-radius: 4px; }
.s-draft { background: var(--tile); color: var(--ink); }
.s-review { background: var(--tint-blue); color: var(--blue-ink); }
.s-active { background: var(--amber-soft); color: var(--amber); }
.s-closed { background: var(--tint-green); color: var(--green-ink); }

/* ---------- brief ---------- */
.back { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; margin: -1rem 0 .25rem; }
.brief-head { margin-bottom: 1.5rem; }
.brief-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .5rem; }

.stepper { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; }
.stepper li { display: flex; flex-direction: column; align-items: center; gap: .35rem; text-align: center; font-size: .78rem; font-weight: 600; color: var(--muted); position: relative; }
.stepper li::after { content: ""; position: absolute; top: 14px; left: calc(50% + 18px); right: calc(-50% + 18px); height: 2px; background: var(--line); }
.stepper li:last-child::after { display: none; }
.stepper .dot { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 2px solid var(--line-strong); font-size: .8rem; }
.stepper li.done { color: var(--green-ink); }
.stepper li.done .dot { border-color: var(--green); background: var(--green); color: #fff; }
.stepper li.done::after { background: var(--green); }
.stepper li.now { color: var(--ink); }
.stepper li.now .dot { border-color: var(--red); background: var(--red); color: #fff; }

.jump {
  position: sticky; top: 68px; z-index: 5; display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 1.25rem; padding: .6rem 16px; background: rgba(255, 255, 255, .95); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.jump-btn { flex: none; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; min-height: 36px; padding: .3rem .8rem; border-radius: var(--radius-btn); border: 0; background: var(--tile); color: var(--muted); }
.jump-btn::before { content: "○ "; }
.jump-btn.done { background: var(--tint-green); color: var(--green-ink); }
.jump-btn.done::before { content: "✓ "; }

.lockmsg { font-size: .95rem; background: var(--tint-blue); color: var(--blue-ink); border-radius: var(--radius-btn); padding: .85rem 1rem; margin-bottom: 1.25rem; }
.notice { background: var(--amber-soft); border-left: 4px solid #d98a00; color: #5c3200; border-radius: var(--radius-btn); padding: .9rem 1rem; margin-bottom: 1.25rem; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem 1.1rem; margin-bottom: 1.25rem; scroll-margin-top: 140px; }
.panel.incomplete { border-color: #d98a00; box-shadow: 0 0 0 3px var(--amber-soft); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1.1rem; }
.sec-head h2 { display: flex; align-items: center; gap: .65rem; }
.num { display: grid; place-items: center; flex: none; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--tile); font-size: .9rem; }
.sec-state { flex: none; font-size: .78rem; font-weight: 700; color: var(--muted); background: var(--tile); padding: .2rem .6rem; border-radius: 4px; }
.sec-state.done { color: var(--green-ink); background: var(--tint-green); }
.hint { color: var(--muted); margin: -.6rem 0 1.1rem; }

.grid { display: grid; gap: 1rem; }
.field { display: block; }
.panel > .field, .panel > .grid { margin-bottom: 1rem; }
.panel > .field:last-child, .panel > .grid:last-child { margin-bottom: 0; }
.field > span { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .35rem; }
.req { color: var(--red); font-style: normal; }

.panel :is(input, select, textarea):disabled {
  background: transparent; border-color: transparent; padding-left: 0; padding-right: 0;
  min-height: 0; color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); resize: none;
}
.panel select:disabled { appearance: none; }
.panel input:disabled::placeholder, .panel textarea:disabled::placeholder { color: transparent; }

.steps { margin: 0 0 1rem; padding-left: 1.5rem; display: grid; gap: .5rem; }
.steps li { padding-left: .25rem; }
.steps li::marker { color: var(--muted); font-weight: 700; }
.steps li > input { width: calc(100% - 48px); }
.steps li > .icon { vertical-align: middle; }

.hazards { display: grid; gap: .5rem; margin-bottom: 1.5rem; }
.hazard { border-radius: var(--radius-btn); padding: .3rem .9rem; background: var(--tile); border: 2px solid transparent; transition: border-color .15s, background-color .15s; }
.hazard.on { background: #fff; border-color: var(--ink); padding-bottom: .9rem; }
.hazard textarea { margin-top: .35rem; min-height: 0; }
.check { display: flex; align-items: center; gap: .65rem; min-height: 44px; cursor: pointer; }
.check input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--red); }
.tag { margin-left: auto; font-size: .72rem; font-weight: 700; color: var(--blue-ink); background: var(--tint-blue); border-radius: 4px; padding: .1rem .5rem; }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-size: .9rem; font-weight: 600; margin-bottom: .25rem; padding: 0; }
.ppe { display: grid; gap: 0 1rem; }

.crew { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .75rem; }
.crew-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; align-items: center; padding-bottom: .75rem; border-bottom: 1px solid var(--line); }
.crew-row:last-child { border-bottom: 0; padding-bottom: 0; }
.crew-sign { grid-column: 1 / 3; grid-row: 2; }
.crew-sign:empty { display: none; }
.crew-row .icon { grid-column: 3; grid-row: 1; }
.ok { color: var(--green-ink); font-size: .95rem; font-weight: 600; }
.log { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; }

.actions {
  position: sticky; bottom: 0; z-index: 5; display: grid; gap: .6rem;
  margin: 1.75rem -16px 0; padding: .85rem 16px calc(.85rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .97); backdrop-filter: blur(6px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(59, 61, 63, .06);
}
.next { font-weight: 600; }
.action-btns { display: flex; gap: .5rem; }
.action-btns .btn { flex: 1; }
.action-btns .btn.danger { flex: 0 0 auto; }

/* ---------- dialog ---------- */
dialog { width: min(480px, calc(100% - 32px)); border: 0; border-radius: var(--radius); padding: 1.75rem; color: var(--ink); box-shadow: 0 20px 50px rgba(59, 61, 63, .25); }
dialog::backdrop { background: rgba(40, 42, 44, .5); }
dialog h2 { font-size: 1.4rem; margin-bottom: .35rem; }
dialog > form > p { margin-bottom: 1.25rem; }
dialog fieldset { margin-bottom: 1rem; }
.reasons { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .35rem; }
.radio { display: flex; align-items: center; gap: .5rem; min-height: 48px; padding: 0 .8rem; cursor: pointer; border-radius: var(--radius-btn); background: var(--tile); border: 2px solid transparent; font-weight: 600; }
.radio:has(input:checked) { border-color: var(--red); background: #fff; }
.radio input { accent-color: var(--red); width: 18px; height: 18px; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.5rem; }

/* ---------- onboarding ---------- */
.ob { max-width: 600px; margin: 0 auto; padding-bottom: 6rem; }
.ob h1 { font-size: 2rem; }
.ob .lead { margin-bottom: 1.75rem; }
.ob-progress { margin-bottom: 2rem; }
.ob-progress ol { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin: .5rem 0 0; padding: 0; }
.ob-progress li { padding-top: .5rem; border-top: 4px solid var(--line); font-size: .85rem; font-weight: 600; color: var(--muted); }
.ob-progress li.done { border-color: var(--green); color: var(--green-ink); }
.ob-progress li.now { border-color: var(--red); color: var(--ink); }

.concepts { list-style: none; margin: 0 0 1.5rem; padding: 0; display: grid; gap: 1.25rem; }
.concepts li { display: flex; gap: 1rem; align-items: flex-start; }
.concepts h2 { font-size: 1.1rem; margin-bottom: .15rem; }
.concepts p { color: var(--muted); }
.note { display: flex; gap: .5rem; align-items: center; background: var(--tint-aqua); border-radius: var(--radius-btn); padding: .8rem 1rem; font-weight: 500; }

.choices { display: grid; gap: .6rem; }
.choice {
  position: relative; display: flex; align-items: center; gap: 1rem; cursor: pointer;
  padding: 1rem 1.1rem; border-radius: var(--radius); background: var(--tile); border: 2px solid transparent;
  transition: border-color .15s, background-color .15s;
}
.choice:hover { background: #ececec; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice > span { display: grid; gap: .15rem; }
.choice b { font-size: 1.05rem; }
.choice > span > span { color: var(--muted); font-size: .95rem; }
.choice:has(input:checked) { background: #fff; border-color: var(--red); }
.choice:has(input:checked)::after {
  content: "✓"; position: absolute; top: .6rem; right: .7rem; display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%; background: var(--red); color: #fff; font-size: .75rem; font-weight: 700;
}
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.choice.compact { padding: .85rem 1rem; }
.ob .field { margin-top: .5rem; }
.ob .field input { font-size: 1.15rem; min-height: 56px; }

.done-mark { color: var(--green); margin-bottom: 1rem; }
.done-mark .ico { color: var(--green); }
.recap { margin: 1.5rem 0; padding: 0; display: grid; gap: 0; border-top: 1px solid var(--line); }
.recap div { display: grid; grid-template-columns: 5rem 1fr; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.recap dt { color: var(--muted); font-weight: 600; }
.recap dd { margin: 0; font-weight: 500; }

.ob-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8;
  display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .85rem max(16px, calc((100% - 600px) / 2)) calc(.85rem + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(59, 61, 63, .06);
}
.ob-actions .btn.primary { margin-left: auto; min-width: 9rem; }

/* ---------- larger screens ---------- */
@media (min-width: 640px) {
  h1, .ob h1 { font-size: 2.5rem; }
  main { padding-top: 2.75rem; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .cards { grid-template-columns: 1fr 1fr; }
  .card { height: 100%; display: flex; flex-direction: column; }
  .card-meta { margin-bottom: .75rem; }
  .card-next { margin-top: auto; }
  .panel { padding: 2rem; }
  .grid { grid-template-columns: 1fr 1fr; }
  .ppe { grid-template-columns: 1fr 1fr; }
  .stepper li { font-size: .85rem; }
  .crew-row { grid-template-columns: 1.3fr 1fr 1.2fr auto; }
  .crew-sign, .crew-sign:empty { grid-column: 3; grid-row: 1; display: block; }
  .crew-row .icon { grid-column: 4; }
  .actions { grid-template-columns: 1fr auto; align-items: center; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; box-shadow: none; }
  .action-btns .btn { flex: 0 0 auto; }
  .jump { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .choices.grid-2 { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .offline-bar, .foot, .actions, .back, .stepper, .jump, .skip { display: none; }
  .panel { break-inside: avoid; }
}

/* Compact header on narrow phones */
.brand, .btn { white-space: nowrap; }
@media (max-width: 400px) {
  .hide-sm { display: none; }
  .topbar-inner { gap: .5rem; }
  .brand { font-size: 1rem; }
}

/* ---------- progressive disclosure ---------- */
/* Draft sections fold: one open at a time, the rest show a one-line recap. */
.panel.acc { padding: 0; }
.acc-h { margin: 0; font-size: 1.2rem; }
.acc-btn {
  width: 100%; display: flex; align-items: center; gap: .75rem; text-align: left;
  font: inherit; color: var(--ink); background: none; border: 0; cursor: pointer;
  padding: 1.1rem 1.1rem; border-radius: var(--radius); min-height: 64px;
}
.acc-btn:hover { background: #fafafa; }
.acc-title { flex: 1; min-width: 0; display: grid; gap: .1rem; font-weight: 700; }
.acc-sum { font-size: .9rem; font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc.open .acc-sum { display: none; }
.num.done { background: var(--green); color: #fff; }
.chev { flex: none; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -4px .25rem 0; transition: transform .15s; }
.acc.open .chev { transform: rotate(-135deg); margin-top: 4px; }
.acc-body { padding: 0 1.1rem 1.25rem; }
.acc.open { border-color: var(--line-strong); }
.acc-foot { display: flex; justify-content: flex-end; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }

details.more { margin-top: 1rem; }
details.more > summary {
  cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: .4rem;
  min-height: 44px; font-weight: 600; color: var(--red);
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "+"; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--red-soft); font-weight: 700; }
details.more[open] > summary::before { content: "−"; }
.more-body { margin-top: .5rem; }

/* Brief cards: the next decision up front, the rest behind Quick look. */
.cards { align-items: start; }
.card { display: flex; flex-direction: column; }
.card-link { color: inherit; text-decoration: none; font-weight: 700; }
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.card-link:focus-visible { outline: none; }
.card:has(.card-link:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.decision { margin-top: .85rem; padding-top: .85rem; border-top: 1px solid var(--line); display: grid; gap: .45rem; }
.decision-label { font-size: .92rem; font-weight: 600; }
.meter { height: 8px; border-radius: 99px; background: var(--tile); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 99px; background: var(--icon); }
.st-draft .meter span { background: var(--ink); }
.hz-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.hz-chips li { font-size: .78rem; font-weight: 600; background: var(--amber-soft); color: var(--amber); border-radius: 4px; padding: .15rem .5rem; }
.flag { font-size: .9rem; background: var(--tint-blue); color: var(--blue-ink); border-radius: var(--radius-btn); padding: .5rem .75rem; }
.peek-btn {
  position: relative; z-index: 1; align-self: flex-start; margin-top: .6rem;
  font: inherit; font-size: .9rem; font-weight: 600; color: var(--red); background: none; border: 0;
  min-height: 40px; padding: 0; cursor: pointer; text-decoration: underline;
}
.peek-body { position: relative; z-index: 1; }
.peek { margin: .25rem 0 0; display: grid; gap: .75rem; font-size: .92rem; background: var(--tile); border-radius: var(--radius-btn); padding: .9rem 1rem; cursor: auto; }
.peek dt { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .15rem; }
.peek dd { margin: 0; }
.peek ol, .peek ul { margin: 0; padding-left: 1.1rem; }

/* One-question pulse after a job */
.pulse { background: var(--tint-aqua); border-color: transparent; }
.pulse h2 { font-size: 1.05rem; margin-bottom: .85rem; }
.pulse-opts { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (min-width: 640px) {
  .card { height: auto; }
  .acc-btn { padding: 1.25rem 1.75rem; }
  .acc-body { padding: 0 2rem 1.75rem; }
}

/* On phones the tick in the number already says "done"; keep the badge for screen readers only. */
@media (max-width: 639px) {
  .acc .sec-state { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- five-questions pass ---------- */
/* Home: today first */
.group-h { display: flex; align-items: baseline; gap: .5rem; font-size: 1.1rem; margin: 1.75rem 0 .85rem; }
.group-h:first-of-type { margin-top: 0; }
.group-h span { font-size: .9rem; color: var(--muted); font-weight: 600; }
.filter-note { background: var(--tint-green); border-radius: var(--radius-btn); padding: .6rem 1rem; margin-bottom: 1rem; }
.filter-note .link { padding: 0 .25rem; }
.card-title { font-size: 1.2rem; margin: .6rem 0 .25rem; }
.flag.done { background: var(--tint-green); color: var(--green-ink); }

/* Brief header: copy link */
.copy-link { padding: .25rem 0; margin-top: .35rem; font-size: .95rem; }

/* At a glance (work in progress) */
.glance { border: 2px solid var(--ink); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.glance h2 { font-size: 1.1rem; margin-bottom: .9rem; }
.glance-grid { display: grid; gap: 1.25rem; }
.g-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .5rem 0 .2rem; }
.g-label:first-child { margin-top: 0; }
.g-emerg { background: var(--red-soft); border-radius: var(--radius-btn); padding: 1rem; display: grid; gap: .25rem; justify-items: start; }
.g-emerg .call { margin-top: .6rem; }

/* Crew member: review before you sign */
.signpanel { border: 2px solid var(--icon); }
.signpanel h2 { margin-bottom: .6rem; }
.signpanel .peek { background: var(--tint-blue); margin-bottom: 1.1rem; }
.sign-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.sign-actions .btn { flex: 1 1 auto; }
.askform { margin-top: 1rem; display: grid; gap: .75rem; }
.signed-msg { font-size: 1.05rem; }

/* Questions from the crew */
.questions { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.questions h3 { font-size: 1rem; margin-bottom: .6rem; }
.questions ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.questions li { background: var(--amber-soft); border-radius: var(--radius-btn); padding: .75rem 1rem; display: grid; gap: .3rem; justify-items: start; }
.questions li.answered { background: var(--tile); }

/* Control suggestions under a hazard */
.ctl-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.ctl-chip {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  min-height: 36px; padding: .25rem .7rem; border-radius: 99px;
  border: 1px dashed var(--line-strong); background: #fff; color: var(--ink);
}
.ctl-chip:hover { border-color: var(--icon); color: var(--icon); }

/* Follow-up status on a completed brief */
.followup { margin-top: 1rem; background: var(--tint-blue); color: var(--blue-ink); border-radius: var(--radius-btn); padding: .85rem 1rem; display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.followup.done { background: var(--tint-green); color: var(--green-ink); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; z-index: 50; transform: translate(-50%, 150%);
  display: flex; align-items: center; gap: 1rem; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; border-radius: var(--radius-btn); padding: .8rem 1.1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-weight: 500; opacity: 0;
  transition: transform .25s ease, opacity .25s ease; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
body:has(.actions) .toast, body:has(.ob-actions) .toast { bottom: 9rem; }
.toast-undo { font: inherit; font-weight: 700; color: #ffb4ad; background: none; border: 0; cursor: pointer; text-decoration: underline; min-height: 36px; }

/* Signed: a small, satisfying pop */
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
.ok.pop { display: inline-block; animation: pop .35s ease-out; }

@media (min-width: 640px) {
  .glance-grid { grid-template-columns: 1fr 1fr; }
  .sign-actions .btn { flex: 0 0 auto; }
  body:has(.actions) .toast { bottom: 6.5rem; }
}

.topbar .btn { gap: .25rem; }

/* =========================================================
   Phase 1: records, admin, sync, smart form additions
   ========================================================= */

/* Header */
.navlink { display: inline-flex; align-items: center; gap: .35rem; min-height: 42px; padding: 0 .6rem; border-radius: var(--radius-btn); color: var(--ink); text-decoration: none; font-weight: 600; }
.navlink:hover { background: var(--tile); }
.navlink[aria-current="page"] { background: var(--tint-blue); color: var(--blue-ink); }
.pill.syncing { background: var(--tint-blue); color: var(--blue-ink); }
.pill.syncing::before { color: var(--icon); }
.pill.conflict { background: var(--red-soft); color: var(--red); }
.pill.conflict::before { color: var(--red); }
.records-link { margin-top: 1rem; }
.records-link a { display: inline-flex; align-items: center; gap: .4rem; }
.conflict-tag { color: var(--red); }

/* Assigned work orders */
.assigned { margin-bottom: 2rem; }
.wo-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.wo { display: grid; grid-template-columns: auto 1fr; gap: .75rem 1rem; align-items: center; background: var(--tile); border-radius: var(--radius); padding: 1rem 1.1rem; }
.wo h3 { font-size: 1.05rem; margin: .1rem 0; }
.wo-id { font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .03em; }
.wo .btn { grid-column: 1 / -1; }

/* Brief: work order lookup, SIF tag, error traps, triggers */
.head-links { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin-top: .35rem; }
.head-links .link { padding: .25rem 0; }
.wo-lookup { margin-bottom: 1rem; }
.wo-hint { display: grid; grid-template-columns: auto 1fr; gap: .5rem .75rem; align-items: center; margin-top: .6rem; background: var(--tint-blue); border-radius: var(--radius-btn); padding: .8rem 1rem; }
.wo-hint .btn { grid-column: 1 / -1; justify-self: start; }
.sif { margin-left: auto; font-size: .68rem; font-weight: 700; letter-spacing: .05em; color: var(--red); border: 1px solid var(--red); border-radius: 4px; padding: 0 .35rem; }
.tag + .sif { margin-left: .4rem; }
.checks { display: grid; gap: 0 1rem; }
.checks .link { justify-self: start; }
.none-check { margin-top: .5rem; padding-top: .5rem; border-top: 1px dashed var(--line); }
.triggers { margin-top: 1.25rem; }
.ro { margin: 0; padding: .65rem 0; }

/* Crew row with company */
.crew-row { grid-template-columns: 1fr 1fr auto; }
.crew-row > select, .crew-row > .company { grid-column: 1; grid-row: 2; }
.crew-row > select { width: 100%; min-height: 48px; padding: .6rem .7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); background: #fff; }
.crew-row .crew-sign { grid-column: 2 / 4; grid-row: 2; }
.crew-row .crew-sign:empty { display: block; }

/* Conflict and reviews */
.panel.conflict { border: 2px solid var(--red); }
.panel.conflict h2 { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.panel.conflict h2 .ico { color: var(--red); }
.conf-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .75rem; }
.conf-opts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.conf-opts > div { background: var(--tile); border-radius: var(--radius-btn); padding: .6rem .8rem; }
.review-form h2, .review-done h2 { margin-bottom: .6rem; }
.review-form .reasons { margin-bottom: 1rem; }
.review-done { background: var(--tint-green); border-color: transparent; }
.initials { font-size: 1.5rem; letter-spacing: .2em; text-transform: uppercase; max-width: 10rem; }
.ease { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: .4rem; margin-top: .35rem; }
.ease .radio { justify-content: center; padding: 0 .4rem; font-size: .85rem; position: relative; }
.ease .radio input { position: absolute; opacity: 0; }
dialog .field { margin-bottom: 1rem; }

/* ---------- admin ---------- */
.admin-head { margin-bottom: 1.25rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); margin: 0 -16px 1.5rem; padding: 0 16px; }
.tabs a { flex: none; padding: .75rem .9rem; color: var(--muted); font-weight: 600; text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--red); }

.filterbar { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.filterbar label > span { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .2rem; }
.filterbar select { width: 100%; min-height: 44px; padding: .5rem .6rem; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); background: #fff; }
.fb-search { grid-column: 1 / -1; }
.results-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.rb-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.table-wrap { overflow-x: auto; }
.rtable, .qtable { width: 100%; border-collapse: collapse; font-size: .95rem; }
.rtable th, .rtable td, .qtable th, .qtable td { text-align: left; padding: .7rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.rtable thead th, .qtable thead th { font-size: .8rem; color: var(--muted); font-weight: 700; border-bottom: 2px solid var(--line-strong); }
.rtable tbody tr:hover { background: #fafafa; }
.rflag { display: inline-block; font-size: .72rem; font-weight: 700; border-radius: 4px; padding: .1rem .45rem; margin: 0 .15rem .2rem 0; background: var(--tile); }
.f-warn { background: var(--amber-soft); color: var(--amber); }
.f-bad, .f-conflict { background: var(--red-soft); color: var(--red); }
.f-pending { background: var(--tint-blue); color: var(--blue-ink); }
.s-archived { background: #e9e9e9; color: var(--muted); }

/* Stack tables into cards on phones */
@media (max-width: 719px) {
  .rtable thead, .qtable thead { display: none; }
  .rtable tr, .qtable tr { display: grid; gap: .15rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
  .rtable td, .rtable th, .qtable td, .qtable th { border: 0; padding: .1rem 0; }
  .rtable td[data-label]::before, .qtable td[data-label]::before { content: attr(data-label) ": "; font-size: .8rem; color: var(--muted); font-weight: 600; }
  .rtable td[data-label="Job"]::before, .rtable td[data-label="What"]::before { content: none; }
  .qtable td { display: flex; align-items: center; gap: .4rem; }
}

.map { height: 460px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--tile); display: grid; place-items: center; overflow: hidden; }
.map.leaflet-container { display: block; }
.map-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .6rem; font-size: .85rem; }
.map-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: .35rem; vertical-align: -1px; }
.dot-draft { background: #676a6e; } .dot-review { background: #0b5ea8; } .dot-active { background: #d98a00; } .dot-closed { background: #1b852a; } .dot-archived { background: #9aa0a6; }
.map-fallback { padding: 1.5rem; width: 100%; align-self: start; }

.privacy-note { display: flex; align-items: center; gap: .5rem; background: var(--tint-aqua); border-radius: var(--radius-btn); padding: .7rem 1rem; margin-bottom: 1rem; font-weight: 500; }
.kpis { margin: 0 0 1.5rem; }
.kpis small { font-size: .9rem; font-weight: 600; }
.qbar { display: inline-block; width: 70px; height: 8px; border-radius: 99px; background: var(--tile); overflow: hidden; margin-right: .45rem; vertical-align: middle; }
.qbar i { display: block; height: 100%; border-radius: 99px; }
.qbar.ok i { background: var(--green); } .qbar.mid i { background: #d98a00; } .qbar.low i { background: var(--red); }
.two-col { display: grid; gap: 0 1.25rem; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.hbars li { display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: .6rem; font-size: .92rem; }
.hbars i { display: block; height: 10px; border-radius: 99px; background: var(--icon); }
.catches { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.catches li { border-left: 3px solid var(--green); padding-left: .85rem; }
.health { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.health li { display: grid; grid-template-columns: 3rem 1fr; gap: .75rem; align-items: start; padding: .6rem .8rem; border-radius: var(--radius-btn); background: var(--tile); }
.health li > b { font-size: 1.5rem; line-height: 1; }
.health li.has { background: var(--amber-soft); }
.health li.ok > b { color: var(--green); }

.lists-layout { display: grid; gap: 1rem; }
.list-nav { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
.list-pick { flex: none; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; min-height: 40px; padding: .35rem .8rem; border: 0; border-radius: var(--radius-btn); background: var(--tile); color: var(--ink); text-align: left; }
.list-pick span { color: var(--muted); margin-left: .25rem; }
.list-pick[aria-current="true"] { background: var(--ink); color: #fff; }
.list-pick[aria-current="true"] span { color: #d5d6d8; }
.li-rows { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: .6rem; }
.li-rows li { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: start; padding: .75rem; border: 1px solid var(--line); border-radius: var(--radius-btn); }
.li-rows li.retired { opacity: .6; background: var(--tile); }
.li-fields { display: grid; gap: .5rem; }
.field.sm > span { font-size: .8rem; margin-bottom: .2rem; }
.field.sm input, .field.sm select { min-height: 42px; padding: .45rem .6rem; width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-btn); background: #fff; }
.field.narrow { max-width: 14rem; }
.check.sm { min-height: 32px; font-size: .9rem; }
.check.sm input { width: 18px; height: 18px; }
fieldset.mini { display: flex; flex-wrap: wrap; gap: 0 .9rem; }
fieldset.mini legend { font-size: .8rem; }
.add-item { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem 1.25rem; margin: 0 0 1.25rem; padding: 1rem 1.1rem; background: var(--tile); border-radius: var(--radius); }
.facts dt { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: .1rem 0 0; font-weight: 500; }
.rec-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .85rem; }
.versions { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.versions li { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .75rem .9rem; border: 1px solid var(--line); border-radius: var(--radius-btn); }
.versions li.key { border: 2px solid var(--icon); }
.ver-doc { grid-column: 1 / -1; }
.doc { margin: 0; display: grid; gap: .8rem; }
.doc > div { display: grid; gap: .15rem; }
.doc dt { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.doc dd { margin: 0; }
.doc ul { margin: 0; padding-left: 1.1rem; }
.fb-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.fb-list li { display: grid; gap: .35rem; margin: 0; }
.demo-tools { background: #fafafa; border-style: dashed; }
.conf-demo { display: grid; gap: .5rem; margin-top: 1rem; align-items: end; }

/* Help */
.guide { counter-reset: g; list-style: none; margin: 0 0 1.5rem; padding: 0; display: grid; gap: 1rem; }
.guide li { counter-increment: g; display: grid; grid-template-columns: 2.25rem 1fr; gap: .1rem .9rem; }
.guide li::before { content: counter(g); grid-row: span 2; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--red); color: #fff; font-weight: 700; }
.guide h2 { font-size: 1.1rem; }
.guide p { color: var(--muted); }
.field-check { background: var(--tint-blue); border-color: transparent; }
.field-check ol { margin: 0; padding-left: 1.2rem; display: grid; gap: .4rem; }
.faq { border-bottom: 1px solid var(--line); padding: .25rem 0; }
.faq summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.faq p, .faq ol { margin: 0 0 .75rem; color: var(--ink); }
.panel h2 { margin-bottom: .85rem; }

@media (min-width: 640px) {
  .wo { grid-template-columns: auto 1fr auto; }
  .wo .btn { grid-column: auto; }
  .wo-hint { grid-template-columns: auto 1fr auto; }
  .wo-hint .btn { grid-column: auto; }
  .checks { grid-template-columns: 1fr 1fr; }
  .crew-row { grid-template-columns: 1.2fr 1fr 1fr 1.1fr auto; }
  .crew-row > select, .crew-row > .company { grid-column: 3; grid-row: 1; }
  .crew-row .crew-sign { grid-column: 4; grid-row: 1; }
  .crew-row .icon { grid-column: 5; }
  .filterbar { grid-template-columns: repeat(5, 1fr); }
  .fb-search { grid-column: 1 / -1; }
  .two-col { grid-template-columns: 1fr 1fr; }
  .li-fields { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .conf-demo { grid-template-columns: 1fr auto; }
  .tabs { margin-left: 0; margin-right: 0; padding: 0; }
}
@media (min-width: 900px) {
  .lists-layout { grid-template-columns: 220px 1fr; align-items: start; }
  .list-nav { flex-direction: column; overflow: visible; }
}
@media print {
  .tabs, .rec-actions, .filterbar, .results-bar { display: none; }
  .ver-doc[hidden] { display: none; }
}

/* The hidden attribute always wins over display rules. */
[hidden] { display: none !important; }

.rtable td[data-label="Date"], .rtable td[data-label="When"] { white-space: nowrap; }
.pill { white-space: nowrap; }
.map { position: relative; z-index: 0; isolation: isolate; }
