/* EMC Field: Fieldwire-style shell (navy sidebar, light grey content, blue primary action), big targets
   (gloves, sun), light/dark via prefers-color-scheme. Orange stays the EMC brand + "open" status colour. */
:root {
  --bg: #f2f4f7; --panel: #ffffff; --ink: #0f172a; --muted: #475569; --line: #d5dbe3; --soft: #e8ecf1;
  --head: #1c2b3f; --head-ink: #f8fafc; --accent: #f97316; --accent-ink: #111827; --accent-strong: #c2410c;
  --nav: #1c2b3f; --nav-ink: #b9c4d3; --nav-hover: #26384f; --nav-on: #2d4566; --nav-line: #2c3d55;
  --primary: #1f6fd8; --primary-ink: #ffffff; --primary-strong: #1858ad;
  --danger: #b91c1c; --ok: #15803d;
  --st-open: #ea580c; --st-in_progress: #2563eb; --st-ready: #7c3aed; --st-closed: #64748b;
  --tap: 48px; --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --panel: #111a2c; --ink: #f1f5f9; --muted: #a3b0c2; --line: #2b3a52; --soft: #1b263a;
    --head: #0f172a; --head-ink: #f8fafc; --accent: #fb923c; --accent-ink: #111827; --accent-strong: #fdba74;
    --nav: #0c1626; --nav-ink: #a9b6c8; --nav-hover: #16243a; --nav-on: #213656; --nav-line: #1d2c44;
    --primary: #3b82f6; --primary-ink: #ffffff; --primary-strong: #2563eb;
    --danger: #f87171; --ok: #4ade80;
    --st-open: #fb923c; --st-in_progress: #60a5fa; --st-ready: #c084fc; --st-closed: #94a3b8;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "main" "nav";
  height: 100dvh; overflow: hidden; -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 1rem; margin: 10px 0 0; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .86rem; } .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pad { padding: 14px 16px; } .pad-x { padding: 0 16px; } .error { color: var(--danger); font-weight: 600; }
.warn { color: var(--accent-strong); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; } .row.end { justify-content: flex-end; margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
[hidden] { display: none !important; }

/* ---- controls ------------------------------------------------------------------------------- */
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  min-height: var(--tap); padding: 0 16px; border-radius: var(--r); border: 2px solid var(--line);
  background: var(--panel); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; text-decoration: none; font-weight: 600; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.ghost { background: transparent; }
.danger { color: var(--danger); border-color: transparent; }
.big { min-height: 56px; font-size: 1.05rem; }
.icon { min-width: var(--tap); padding: 0; border-color: transparent; background: transparent; font-size: 1.5rem; }
.toggle[aria-pressed="true"] { background: var(--head); color: var(--head-ink); border-color: var(--head); }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r);
  background: var(--panel);
}
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-weight: 400; font-size: 1rem; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-size: 1rem; color: var(--ink); min-height: var(--tap); }
label.check input { width: 26px; height: 26px; min-height: 0; accent-color: var(--primary); }
fieldset { border: 2px solid var(--line); border-radius: var(--r); padding: 8px 10px 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 700; padding: 0 6px; }
.rowedit input.hours { width: 84px; flex: none; }
.search { min-height: 48px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip {
  min-height: 40px; padding: 0 12px; border-radius: 999px; border: 2px solid var(--line); background: var(--panel);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: .9rem; font-weight: 600; text-decoration: none;
}
span.chip { min-height: 30px; font-size: .8rem; }
.chip[aria-pressed="true"] { background: var(--head); color: var(--head-ink); border-color: var(--head); }
.chip .n, .seg .n { font-size: .8rem; opacity: .75; font-weight: 700; }
.chip.cite { border-color: var(--accent); }
.chip.warn { border-color: var(--accent); color: var(--accent-strong); }
.chip[class*="st-"] { border-color: currentColor; }
.st-open { color: var(--st-open); } .st-in_progress { color: var(--st-in_progress); }
.st-ready { color: var(--st-ready); } .st-closed { color: var(--st-closed); }
.seg { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.seg button { flex: 1 0 auto; padding: 0 10px; font-size: .88rem; flex-direction: column; gap: 0; line-height: 1.1; min-height: 52px; }
.seg button[aria-pressed="true"] { background: var(--head); color: var(--head-ink); border-color: var(--head); }
.seg.big button { min-height: 56px; font-size: .95rem; }
.seg.big button[aria-pressed="true"] { color: #fff; }
.seg.big button.st-open[aria-pressed="true"] { background: var(--st-open); border-color: var(--st-open); }
.seg.big button.st-in_progress[aria-pressed="true"] { background: var(--st-in_progress); border-color: var(--st-in_progress); }
.seg.big button.st-ready[aria-pressed="true"] { background: var(--st-ready); border-color: var(--st-ready); }
.seg.big button.st-closed[aria-pressed="true"] { background: var(--st-closed); border-color: var(--st-closed); }

/* ---- chrome: phone = navy top bar + bottom tab bar; desktop = Fieldwire-style navy sidebar ------- */
.top {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--head); color: var(--head-ink); min-height: 60px;
}
.brand-btn { background: transparent; border: 0; padding: 0; min-width: 52px; }
.logo { background: var(--accent); color: #111827; font-weight: 900; letter-spacing: .02em; padding: 6px 8px; border-radius: 6px; font-size: .95rem; }
.top-mid { flex: 1; min-width: 0; }
#title { font-weight: 700; font-size: 1.05rem; }
#title .page { display: none; }
.loc { font-size: .82rem; color: #cbd5e1; display: flex; gap: 4px; }
.loc .gps { color: var(--accent); font-weight: 900; }
.loc .muted { color: #94a3b8; }
.sync { background: transparent; color: var(--head-ink); border: 1px solid #334155; min-height: 40px; font-size: .82rem; font-weight: 600; padding: 0 10px; }
.sync .dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; }
.sync[data-state="syncing"] .dot { background: #fbbf24; animation: pulse 1s infinite alternate; }
.sync[data-state="offline"] .dot { background: #94a3b8; }
.sync[data-state="error"] .dot { background: #ef4444; }
@keyframes pulse { to { opacity: .3; } }

.nav { grid-area: nav; display: flex; background: var(--nav); color: var(--nav-ink); padding-bottom: env(safe-area-inset-bottom); }
body:not(.in-project) .nav { display: none; }
.side-head, .side-section, .side-foot, .tab .lbl { display: none; }
.tab { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60px; text-decoration: none; font-size: .74rem; font-weight: 700; color: var(--nav-ink); gap: 2px; }
.tab svg { width: 24px; height: 24px; flex: none; }
.tab.on { color: #fff; box-shadow: inset 0 3px 0 var(--primary); background: var(--nav-on); }

.panes { grid-area: main; min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.pane { min-height: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); }
.detail-pane { display: none; }
body.show-detail .list-pane { display: none; }
body.show-detail .detail-pane { display: block; }

.page { max-width: 760px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.page.flush { padding: 0 0 24px; gap: 10px; }
.page.center { min-height: 100%; justify-content: center; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 4; }
.toolbar .tb-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .tb-right .search { width: 240px; min-height: 42px; }
.toolbar button, .toolbar .button, .toolbar select { min-height: 42px; }
.toolbar select { width: auto; }
@media (max-width: 999px) { .toolbar .tb-right { flex: 1 1 100%; margin-left: 0; } .toolbar .tb-right .search { flex: 1; width: auto; } }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 16px; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); }
.fatal { padding: 16px; color: var(--danger); white-space: pre-wrap; }

.enroll { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 440px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.6rem; font-weight: 800; }

/* ---- lists ---------------------------------------------------------------------------------- */
.list { display: flex; flex-direction: column; }
.group { padding: 14px 16px 6px; font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.row-link {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; text-decoration: none;
  background: var(--panel); border-bottom: 1px solid var(--soft);
}
.row-link:active, .row-link.sel { background: var(--soft); box-shadow: inset 4px 0 0 var(--primary); }
.row-link .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chev { font-size: 1.6rem; color: var(--muted); }
.sheetno { font-weight: 800; min-width: 64px; font-variant-numeric: tabular-nums; }
.sheet.superseded { opacity: .45; } .sheet.superseded .sheetno { text-decoration: line-through; }
.count { background: var(--st-open); color: #fff; border-radius: 999px; min-width: 28px; height: 28px; display: grid; place-items: center; font-weight: 800; font-size: .85rem; padding: 0 6px; }
.kind, .pin {
  --c: var(--st-open); width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 900; font-size: .95rem; border: 3px solid var(--panel); box-shadow: 0 0 0 2px var(--c);
}
.pending { color: var(--accent); }
.date { display: flex; flex-direction: column; align-items: center; width: 44px; line-height: 1; }
.date b { font-size: 1.4rem; } .date span { font-size: .75rem; text-transform: uppercase; color: var(--muted); }

/* ---- plans grid (Fieldwire-style: folders, thumbnails, badges) ------------------------------- */
.page.wide-page { max-width: none; }
.small-check { min-height: 42px; font-size: .9rem; font-weight: 600; white-space: nowrap; }
.small-check input { width: 20px; height: 20px; }
.viewtoggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.viewtoggle button { border: 0; border-radius: 0; min-height: 40px; padding: 0 10px; font-size: .85rem; gap: 5px; color: var(--muted); }
.viewtoggle button + button { border-left: 1px solid var(--line); }
.viewtoggle button[aria-pressed="true"] { background: var(--soft); color: var(--primary); }
.folder-head { width: 100%; justify-content: flex-start; gap: 8px; border: 0; border-radius: 0; background: transparent; min-height: 44px; padding: 10px 16px 4px; font-size: .95rem; font-weight: 700; text-align: left; }
.folder-head .caret { width: 14px; color: var(--muted); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; padding: 6px 16px 14px; }
.plan-card { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; text-decoration: none; transition: box-shadow .12s; }
.plan-card:hover { box-shadow: 0 4px 14px rgba(15, 23, 42, .14); border-color: var(--primary); }
.plan-thumb { position: relative; aspect-ratio: 3 / 2; background: #fff; border-bottom: 1px solid var(--soft); }
.plan-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.plan-thumb img:not([src]) { visibility: hidden; }
.plan-thumb .count { position: absolute; top: 6px; right: 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.plan-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.plan-card.superseded { opacity: .5; }
@media (prefers-color-scheme: dark) { .plan-thumb img { filter: invert(.88) hue-rotate(180deg); } .plan-thumb { background: #0b1220; } }
@media (max-width: 599px) { .plan-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 6px 12px 12px; } .viewtoggle span { display: none; } }

/* ---- tasks board ------------------------------------------------------------------------------ */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 12px; padding: 4px 16px 16px; align-items: start; }
.board-col { background: var(--soft); border-radius: 10px; padding: 8px; min-height: 120px; border: 2px dashed transparent; }
.board-col.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--soft)); }
.board-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 8px; }
.board-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.board-cards { display: flex; flex-direction: column; gap: 8px; }
.board-empty { text-align: center; padding: 14px 0; margin: 0; }
.task-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; }
.task-card:hover, .task-card.sel { border-color: var(--primary); box-shadow: 0 2px 8px rgba(15, 23, 42, .1); }
.task-card[draggable="true"]:active { cursor: grabbing; }
.task-card .kind { width: 30px; height: 30px; font-size: .85rem; border-width: 2px; }
.task-card .title { font-weight: 650; font-size: .95rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.card-top { align-items: flex-start; }
.card-status { width: auto; min-height: 32px; padding: 2px 6px; font-size: .8rem; border-width: 1px; }
@media (max-width: 999px) {
  .board { grid-template-columns: repeat(4, 85%); overflow-x: auto; scroll-snap-type: x mandatory; padding: 4px 12px 16px; }
  .board-col { scroll-snap-align: start; }
}

/* ---- photos gallery + viewer ----------------------------------------------------------------- */
label.inline { flex-direction: row; align-items: center; gap: 6px; font-size: .85rem; white-space: nowrap; }
label.inline > input, label.inline > select { min-height: 40px; padding: 4px 8px; width: auto; font-size: .9rem; }
.photo-day { padding: 4px 16px 10px; }
.day-head { font-size: 1rem; margin: 12px 0 8px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.photo-tile { position: relative; padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; aspect-ratio: 1; background: var(--soft); min-height: 0; cursor: zoom-in; }
.photo-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile img:not([src]) { visibility: hidden; }
.photo-tile:hover { border-color: var(--primary); }
.tile-chip { position: absolute; left: 4px; bottom: 4px; background: var(--panel); min-height: 24px; }
@media (max-width: 599px) { .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; } .photo-day { padding: 4px 8px 8px; } }
.photo-viewer { position: fixed; inset: 0; z-index: 25; background: #05080f; color: #f1f5f9; display: flex; flex-direction: column; }
.pv-bar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
.pv-count { font-weight: 700; font-size: .95rem; padding-left: 6px; }
.pv-btn { background: transparent; color: inherit; border-color: transparent; font-size: 1.3rem; min-width: var(--tap); padding: 0; }
.pv-btn:hover { background: rgba(255, 255, 255, .1); }
.pv-main { position: relative; flex: 1; min-height: 0; }
.pv-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; }
.pv-stage.zoomed { cursor: grab; }
.pv-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform-origin: center; }
.pv-prev, .pv-next { position: absolute; top: 50%; transform: translateY(-50%); font-size: 2.6rem; background: rgba(0, 0, 0, .35); border-radius: 50%; width: 56px; height: 56px; }
.pv-prev { left: 10px; } .pv-next { right: 10px; }
.pv-prev:disabled, .pv-next:disabled { visibility: hidden; }
.pv-info { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px; border-top: 1px solid rgba(255, 255, 255, .12); }
.pv-info .muted { color: #94a3b8; }
.pv-caption { font-weight: 600; }
.pv-task { color: #93c5fd; font-weight: 600; }

/* ---- sheet viewer --------------------------------------------------------------------------- */
.viewer { display: flex; flex-direction: column; height: 100%; position: relative; }
.viewer-bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--panel); border-bottom: 2px solid var(--line); min-height: 56px; }
.viewer-bar .back { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; }
.tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stage { position: relative; flex: 1; overflow: hidden; touch-action: none; background: #e5e7eb; user-select: none; -webkit-user-select: none; cursor: grab; }
@media (prefers-color-scheme: dark) { .stage { background: #020617; } .sheet-img { filter: invert(.88) hue-rotate(180deg); } }
.stage.pinmode { cursor: crosshair; box-shadow: inset 0 0 0 4px var(--accent); }
.sheet-img { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; max-width: none; pointer-events: none; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.pins { position: absolute; inset: 0; pointer-events: none; }
.pin { position: absolute; transform: translate(-50%, -50%); pointer-events: auto; padding: 0; min-height: 0; cursor: pointer; width: 34px; height: 34px; }
.pin::after { content: ""; position: absolute; inset: -8px; } /* bigger hit area */
.pin.closed { opacity: .55; }
.pin.sel { width: 46px; height: 46px; font-size: 1.15rem; z-index: 2; box-shadow: 0 0 0 3px var(--c), 0 0 0 8px rgba(249, 115, 22, .35); }
.peek {
  position: absolute; left: 10px; right: 10px; bottom: 10px; background: var(--panel); border: 2px solid var(--line);
  border-radius: 14px; padding: 12px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); display: flex; flex-direction: column; gap: 6px; max-width: 520px; margin: 0 auto;
}

/* ---- detail / timeline ---------------------------------------------------------------------- */
.detail { padding: 0 0 32px; gap: 0; }
.title-in { font-size: 1.25rem; font-weight: 700; border-color: transparent; background: transparent; padding: 6px 4px; min-height: 0; resize: none; field-sizing: content; }
.title-in:focus { border-color: var(--line); background: var(--panel); }
.where { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .95rem; }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.entry { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.entry p { margin: 6px 0 0; white-space: pre-wrap; }
.entry .who { font-weight: 700; }
.entry.change { background: transparent; border-style: dashed; font-size: .9rem; }
.entry.answer { border-left: 5px solid var(--accent); }
.composer { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.composer .row { justify-content: space-between; }
figure.photo { margin: 6px 0 0; cursor: zoom-in; }
.thumb { width: 100%; max-width: 360px; max-height: 260px; object-fit: cover; border-radius: 8px; display: block; background: var(--soft); min-height: 80px; }
figcaption { font-size: .88rem; color: var(--muted); margin-top: 4px; }
img.full { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }
img.broken { min-height: 60px; }

/* ---- ask ------------------------------------------------------------------------------------ */
.ask-row { display: flex; gap: 10px; align-items: stretch; }
.ask-box { font-size: 1.1rem; }
.mic { width: 84px; min-height: 84px; border-radius: 50%; background: var(--head); color: var(--head-ink); border-color: var(--head); flex: none; align-self: center; }
.mic.live { background: var(--danger); border-color: var(--danger); animation: pulse 0.8s infinite alternate; }
.answer .q { color: var(--muted); margin: 0 0 6px; font-style: italic; }
.answer .spoken { font-size: 1.2rem; font-weight: 600; margin: 0 0 8px; }
.answer.err { border-color: var(--danger); color: var(--danger); }
.spinner { width: 28px; height: 28px; border: 4px solid var(--soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- modal / toast -------------------------------------------------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal-card { background: var(--panel); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--head); color: var(--head-ink); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 30; max-width: 90vw; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }

/* ---- desktop: navy sidebar + white top bar + content (list + detail, or one wide pane) --------- */
@media (min-width: 1000px) {
  body { grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "nav top" "nav main"; }
  body:not(.in-project) { grid-template-columns: 0 minmax(0, 1fr); }
  .top { background: var(--panel); color: var(--ink); border-bottom: 1px solid var(--line); min-height: 52px; padding: 4px 16px; }
  body.in-project .brand-btn, body.in-project #title .proj { display: none; }
  body.in-project #title .page { display: inline; font-size: 1.15rem; }
  .loc { color: var(--muted); } .loc .muted { color: var(--muted); }
  .sync { color: var(--ink); border-color: var(--line); }
  .nav { flex-direction: column; justify-content: flex-start; padding: 0 0 8px; overflow-y: auto; border-right: 1px solid var(--nav-line); }
  .side-head { display: flex; flex-direction: column; gap: 10px; padding: 14px 14px 16px; border-bottom: 1px solid var(--nav-line); }
  .side-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: #fff; font-weight: 800; font-size: 1.05rem; }
  .proj-name { color: #fff; font-weight: 700; font-size: 1rem; line-height: 1.25; }
  .proj-switch { min-height: 38px; padding: 4px 8px; font-size: .88rem; border: 1px solid var(--nav-line); border-radius: 8px; background: var(--nav-hover); color: #fff; }
  .side-section { display: block; padding: 18px 18px 6px; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #7f8ea3; }
  .tab { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 42px; margin: 1px 8px; padding: 0 10px; border-radius: 8px; font-size: .95rem; font-weight: 600; }
  .tab svg { width: 20px; height: 20px; }
  .tab:hover { background: var(--nav-hover); color: #fff; }
  .tab.on { box-shadow: inset 3px 0 0 var(--primary); }
  .tab .lbl { display: inline; } .tab .short { display: none; }
  .side-foot { display: flex; flex-direction: column; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--nav-line); }
  .side-foot .tab { font-size: .88rem; min-height: 38px; }
  body.in-project .panes { grid-template-columns: minmax(360px, 420px) minmax(0, 1fr); }
  body.in-project .list-pane { display: block; border-right: 1px solid var(--line); }
  body.in-project .detail-pane { display: block; }
  body.in-project:not(.wide) .viewer-bar .back { visibility: hidden; width: 8px; min-width: 8px; }
  /* A wide view (plans grid, photos, task board) takes the whole content area; its detail replaces it. */
  body.in-project.wide .panes { grid-template-columns: minmax(0, 1fr); }
  body.in-project.wide .list-pane { border-right: 0; }
  body.in-project.wide:not(.show-detail) .detail-pane, body.in-project.wide.show-detail .list-pane { display: none; }
  .toolbar .tb-title { display: none; }
  .modal { align-items: center; }
  .modal-card { border-radius: 18px; }
  .toast { bottom: 32px; }
}

/* ---- map ------------------------------------------------------------------------------------ */
body[data-tab="map"] .panes { grid-template-columns: minmax(0, 1fr) !important; }
body[data-tab="map"] .list-pane { display: block !important; overflow: hidden; border-right: 0 !important; }
body[data-tab="map"] .detail-pane { display: none !important; }
.map-stage { background: #eef1ec; cursor: default; }
@media (prefers-color-scheme: dark) { .map-stage { background: #0b1220; } }
.map-canvas { position: absolute; inset: 0; display: block; }
.map-legend { position: absolute; top: 64px; left: 10px; display: flex; flex-wrap: wrap; gap: 4px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; opacity: .92; pointer-events: none; max-width: calc(100% - 70px); }
.map-legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.clamp { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.viewer .peek { z-index: 5; max-height: calc(100% - 20px); overflow-y: auto; }
.map .map-legend { top: auto; bottom: 46px; left: auto; right: 10px; max-width: calc(100% - 140px); }
.me-dot { position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #2563eb; border: 3px solid #fff; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px rgba(37, 99, 235, .5), 0 2px 6px rgba(0, 0, 0, .35); z-index: 3; pointer-events: none; }

/* Diagnostics (#/debug) */
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; }
.diag-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: .9rem; }
.diag-facts dt { color: var(--muted); font-weight: 600; text-transform: capitalize; }
.diag-facts dd { margin: 0; overflow-wrap: anywhere; }
.diag-scroll { overflow-x: auto; }
table.diag { border-collapse: collapse; width: 100%; font-size: .82rem; }
table.diag th, table.diag td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.diag td:last-child { overflow-wrap: anywhere; }
table.diag tr.bad td { color: var(--danger); }
.diag-link { font-size: .85rem; color: var(--muted); }
