:root {
  --g: #3d9b35; --g-d: #1d5c27; --g-l: #e8f4e6;
  --bg: #f4f6f5; --card: #fff; --ink: #14201a; --mut: #5f6d66; --line: #e2e8e4; --hover: #f0f4f1;
  --red: #c92a2a; --red-l: #fdecec; --amber: #b7791f; --amber-l: #fdf4e3; --blue: #2563a8; --blue-l: #e8f0fa;
  --shadow: 0 1px 2px rgba(16, 32, 24, .06), 0 4px 16px rgba(16, 32, 24, .05);
  --r: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --g: #5cb954; --g-d: #9bd88f; --g-l: #1d3320;
    --bg: #0f1512; --card: #172019; --ink: #e6eee8; --mut: #93a39a; --line: #26332b; --hover: #1d2a22;
    --red: #ff6b6b; --red-l: #3a1b1b; --amber: #f0b44c; --amber-l: #33281a; --blue: #6aa8ea; --blue-l: #1a2838;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--g-d); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--mut); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--mut); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand svg { width: 34px; height: 28px; }
.brand b { display: block; color: var(--g); font-size: 17px; letter-spacing: .02em; line-height: 1.1; }
.brand small { color: var(--mut); font-size: 11px; }
nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink); font-weight: 500; }
nav a i { font-style: normal; width: 18px; text-align: center; color: var(--mut); }
nav a:hover { background: var(--hover); text-decoration: none; }
nav a.on { background: var(--g-l); color: var(--g-d); }
nav a.on i { color: var(--g-d); }
nav .pill { margin-left: auto; }
.side-foot { margin-top: auto; padding: 14px 18px; }
.demo-tag { font-size: 11px; background: var(--amber-l); color: var(--amber); padding: 3px 8px; border-radius: 99px; font-weight: 600; }
.mainwrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
main { padding: 24px; max-width: 1400px; width: 100%; outline: none; }
.only-m { display: none; }

/* Controls */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--g); border-color: var(--g); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.iconbtn { font: inherit; border: 1px solid var(--line); background: var(--card); border-radius: 8px; width: 38px; height: 38px; cursor: pointer; position: relative; color: var(--ink); }
.iconbtn .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; border-radius: 99px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; padding: 0 4px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--g); outline-offset: -1px; }
input[type=checkbox] { width: auto; accent-color: var(--g); }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--mut); margin-bottom: 12px; }
label.f > input, label.f > select, label.f > textarea { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 0 12px; }
.checks label { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--ink); font-size: 13px; }

.search { flex: 1; max-width: 480px; position: relative; }
.search input { background: var(--bg); }
.search-res { position: absolute; top: 44px; left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 360px; overflow: auto; }
.search-res a { display: block; padding: 9px 12px; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-res a:hover { background: var(--hover); text-decoration: none; }
.mebtn { display: flex; align-items: center; gap: 8px; font: inherit; font-weight: 600; color: var(--ink); background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 8px; }
.mebtn:hover { background: var(--hover); }
.auth { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.auth[hidden] { display: none; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 400px; margin: auto; }
.auth-brand { display: grid; grid-template-columns: 40px 1fr; align-items: center; column-gap: 10px; margin-bottom: 20px; }
.auth-brand svg { width: 40px; height: 32px; grid-row: span 2; }
.auth-brand b { color: var(--g); font-size: 18px; letter-spacing: .02em; line-height: 1.1; }
.auth-brand small { color: var(--mut); font-size: 12px; }
.auth h2 { font-size: 18px; }
.bellwrap { position: relative; }
.pop { position: absolute; right: 0; top: 46px; width: 380px; max-width: 92vw; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.15); z-index: 40; max-height: 70vh; overflow: auto; }
.pop-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.note { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.note:hover { background: var(--hover); text-decoration: none; }
.note.unread { background: var(--g-l); }

/* Cards & layout */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--mut); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.cols > div { min-width: 0; }
.cols > div > .card + .card { margin-top: 16px; }
select { max-width: 100%; }
pre { overflow-x: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); }
.kpi:hover { text-decoration: none; border-color: var(--g); }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.kpi .l { font-size: 12px; color: var(--mut); font-weight: 500; }
.kpi .s { font-size: 12px; color: var(--g-d); font-weight: 600; }

.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--ink); }
.li:last-child { border-bottom: 0; }
a.li:hover { text-decoration: none; background: var(--hover); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 6px; }
.li .grow { flex: 1; min-width: 0; }
.li .t { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--mut); padding: 14px 0; text-align: center; font-size: 13px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--hover); color: var(--mut); white-space: nowrap; }
.chip.g { background: var(--g-l); color: var(--g-d); }
.chip.r { background: var(--red-l); color: var(--red); }
.chip.a { background: var(--amber-l); color: var(--amber); }
.chip.b { background: var(--blue-l); color: var(--blue); }
.pill { background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 0 7px; line-height: 18px; }
.pill:empty { display: none; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.avs { display: inline-flex; }
.avs .avatar { margin-left: -6px; border: 2px solid var(--card); }
.avs .avatar:first-child { margin-left: 0; }

/* Phase bars */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 96px 1fr 34px; gap: 10px; align-items: center; font-size: 13px; color: var(--ink); }
.bar:hover { text-decoration: none; }
.bar .track, .bar .fill { display: block; }
.bar .track { background: var(--hover); border-radius: 6px; height: 22px; overflow: hidden; }
.bar .fill { background: var(--g); height: 100%; border-radius: 6px; min-width: 3px; }
.bar b { text-align: right; }

/* Pipeline board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: var(--hover); border-radius: 12px; width: 250px; flex-shrink: 0; padding: 10px; border: 2px solid transparent; }
.col.drop { border-color: var(--g); background: var(--g-l); }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 10px; font-weight: 700; font-size: 13px; }
.col-head .muted { font-weight: 500; font-size: 12px; }
.col-phase { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--mut); padding: 0 4px; }
.jcard { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; color: var(--ink); cursor: grab; box-shadow: var(--shadow); }
.jcard:hover { text-decoration: none; border-color: var(--g); }
.jcard.stuck { border-left: 3px solid var(--red); }
.jcard .num { font-size: 11px; color: var(--mut); font-weight: 600; }
.jcard .nm { font-weight: 600; margin: 2px 0; }
.jcard .ttl { font-size: 12px; color: var(--mut); margin-bottom: 8px; }
.jcard .ft { display: flex; justify-content: space-between; align-items: center; gap: 6px; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--mut); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--hover); }
.tbl input, .tbl select, .tbl textarea { padding: 6px 8px; font-size: 13px; }
.tblwrap { overflow-x: auto; }
.num-r { text-align: right; white-space: nowrap; }

/* Job page */
.job-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.job-head .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.stepper { display: flex; overflow-x: auto; gap: 0; margin-bottom: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 10px; box-shadow: var(--shadow); }
.step { flex: 1; min-width: 92px; text-align: center; position: relative; font-size: 11px; color: var(--mut); cursor: pointer; padding: 0 4px; background: none; border: 0; font-family: inherit; }
.step::before { content: ""; position: absolute; top: 11px; left: -50%; width: 100%; height: 2px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step .c { position: relative; z-index: 1; width: 24px; height: 24px; border-radius: 50%; margin: 0 auto 6px; display: grid; place-items: center; background: var(--card); border: 2px solid var(--line); font-weight: 700; font-size: 11px; }
.step.done { color: var(--ink); }
.step.done .c { background: var(--g); border-color: var(--g); color: #fff; }
.step.done::before, .step.cur::before { background: var(--g); }
.step.cur { color: var(--g-d); font-weight: 700; }
.step.cur .c { border-color: var(--g); color: var(--g-d); box-shadow: 0 0 0 4px var(--g-l); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--mut); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.on { color: var(--g-d); border-color: var(--g); }
.next-box { background: var(--g-l); border: 1px solid var(--g); border-radius: var(--r); padding: 14px 16px; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.next-box b { color: var(--g-d); }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--mut); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 20px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--g); }
.timeline li::after { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.folder { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.folder-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-weight: 600; background: var(--hover); border-radius: 10px 10px 0 0; }
.folder .li { padding: 8px 12px; }
.callout { background: var(--blue-l); color: var(--ink); border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 14px; }
.callout.a { background: var(--amber-l); }

/* Calendar */
.week { display: grid; grid-template-columns: repeat(7, minmax(130px, 1fr)); gap: 8px; overflow-x: auto; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 260px; padding: 8px; }
.day.today { border-color: var(--g); box-shadow: 0 0 0 2px var(--g-l); }
.day-h { font-size: 12px; font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; }
.evt { display: block; border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; font-size: 12px; color: var(--ink); border-left: 3px solid var(--g); background: var(--g-l); cursor: pointer; }
.evt:hover { text-decoration: none; filter: brightness(.97); }
.evt.assessment { border-color: var(--amber); background: var(--amber-l); }
.evt.inspection, .evt.permit { border-color: var(--blue); background: var(--blue-l); }
.evt.meeting, .evt.other { border-color: var(--mut); background: var(--hover); }
.evt b { display: block; }

/* Feed */
.post { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.post:last-child { border-bottom: 0; }
.post .body { flex: 1; min-width: 0; }
.post .body p { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.post.sys .avatar { background: var(--g-l) !important; color: var(--g-d); }

/* Modal & toasts */
.modal { position: fixed; inset: 0; background: rgba(10, 20, 14, .45); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card); border-radius: 14px; width: 560px; max-width: 100%; max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card h2 { font-size: 18px; margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; max-width: 360px; animation: up .2s ease; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* Field tools: photos, markup, AI draft, crew day, phone bottom bar, no-signal banner */
.btn.big { padding: 12px 18px; font-size: 15px; }
.ph-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.ph { position: relative; display: block; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--hover); aspect-ratio: 1; cursor: pointer; font: inherit; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-l { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.ph-m, .ph-c { position: absolute; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 99px; }
.ph-m { right: 6px; } .ph-c { left: 6px; }
.ph-big { width: 100%; max-height: 60vh; object-fit: contain; background: #111; border-radius: 10px; margin: 12px 0; }
.ba { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.ba figure { margin: 0; } .ba figcaption { font-size: 12px; color: var(--mut); margin-top: 4px; }
.modal-card.wide { width: 920px; }
.mk-wrap { margin-top: 12px; background: #111; border-radius: 10px; overflow: auto; max-height: 68vh; text-align: center; }
.mk-wrap canvas { max-width: 100%; height: auto; touch-action: none; cursor: crosshair; display: inline-block; }
.mk-tools .btn.on { background: var(--g); color: #fff; border-color: var(--g); }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.swatch.on { outline: 3px solid var(--g); outline-offset: 1px; }
.mic { margin-left: 6px; padding: 2px 8px; vertical-align: middle; }
.mic.rec { background: var(--red); color: #fff; border-color: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.ai-sec { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ai-sec input { margin-top: 3px; } .ai-sec ul { margin: 4px 0 0; padding-left: 18px; } .ai-sec p { margin: 4px 0 0; }
.stop .stop-time { font-size: 15px; } .stop.is-done { opacity: .6; }
.stop-btns .btn { flex: 1 1 auto; }
.offline-bar { position: sticky; top: 0; z-index: 70; background: var(--amber); color: #fff; text-align: center; font-size: 13px; font-weight: 600; padding: 6px 12px; }
.offline-bar[hidden] { display: none; }
.bottom-nav { display: none; }

@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .only-m { display: inline-block; }
  .bottom-nav { display: flex; flex-direction: row; top: auto; width: auto; height: auto; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--card); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--mut); padding: 6px 0; border-radius: 8px; }
  .bottom-nav a i { font-style: normal; font-size: 18px; }
  .bottom-nav a.on { color: var(--g-d); background: var(--g-l); }
  .bottom-nav a:hover { text-decoration: none; }
  main { padding-bottom: 90px; }
  .toasts { bottom: 80px; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  #newJobBtn { margin-left: auto; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dd { margin-bottom: 8px; }
  #meName { display: none; }
}
@media print { .side, .top { display: none; } }
