:root {
  --header: #141414;
  --primary: #1f5c4d;
  --accent: #3aa88a;
  --bg: #eef2f1;
  --surface: #ffffff;
  --ink: #17201d;
  --ink-2: #4d5a56;
  --line: #d3dbd8;
  --field: #f7f9f8;
  --warn: #a8600b;
  --warn-bg: #fdf3e3;
  --danger: #a33a2b;
  --sent: #2e8a70;
  --radius: 10px;
  --tap: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101413;
    --surface: #1a201e;
    --ink: #e8eeec;
    --ink-2: #a3b0ac;
    --line: #2f3936;
    --field: #141917;
    --warn: #f0b45c;
    --warn-bg: #2b2213;
    --danger: #f08a7a;
    --sent: #5cc9a7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px 20px; color: var(--ink-2); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--header); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; flex: 1; letter-spacing: .2px; }
.mark { width: 28px; height: 31px; flex: none; }
.logo { height: 40px; width: auto; flex: none; }
.pill { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.pill--on { background: rgba(58,168,138,.22); color: #8fe0c6; }
.pill--off { background: #f0b45c; color: #2a1c05; }
.back {
  min-height: 44px; padding: 0 14px 0 10px; border: 1px solid rgba(255,255,255,.28);
  background: transparent; color: #fff; border-radius: 8px; font-weight: 600;
}
.back::before { content: "‹ "; font-size: 20px; line-height: 0; }
.tb-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tb-title strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title small { color: #b9c6c2; font-size: 13px; }

/* ---------- banners ---------- */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; font-size: 15px; }
.banner--install { background: var(--warn-bg); color: var(--ink); border-bottom: 1px solid var(--line); }
.banner--update { background: var(--primary); color: #fff; justify-content: space-between; }
.banner--update .btn { background: #fff; color: var(--primary); }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 20px; border-radius: var(--radius);
  border: 0; background: var(--primary); color: #fff; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: .45; }
.btn--small { min-height: 44px; padding: 0 16px; font-size: 15px; }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn--primary { flex: 1; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, label.btn:focus-within {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ---------- home ---------- */
.home { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.start h1 { font-size: 26px; margin: 4px 0 12px; letter-spacing: -.3px; }
.start__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 14px; min-height: 84px; padding: 16px 18px;
  border: 0; border-radius: 12px; background: var(--primary); color: #fff; text-align: left; cursor: pointer;
}
.tile__plus {
  width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.16);
  display: grid; place-items: center; font-size: 26px; line-height: 1; flex: none;
}
.tile__name { font-size: 20px; font-weight: 700; }

.group { margin-top: 30px; }
.group__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.group h2 { font-size: 18px; margin: 0; }
.count { color: var(--ink-2); font-weight: 500; margin-left: 4px; }
.group__hint { font-size: 14px; color: var(--ink-2); }
.empty { color: var(--ink-2); margin: 6px 0; }
.version { margin-top: 40px; font-size: 12px; color: var(--ink-2); text-align: center; }

/* Job cards: the left edge carries the status so a full list reads at a glance. */
.job {
  width: 100%; display: flex; gap: 14px; align-items: stretch; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--ink-2);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer;
}
.job--draft { border-left-color: #8c9a96; }
.job--queued, .job--sending { border-left-color: var(--warn); }
.job--sent { border-left-color: var(--sent); }
.job__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.job__type { font-size: 13px; color: var(--ink-2); }
.job__name { font-weight: 650; font-size: 17px; }
.job__addr { font-size: 15px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job__err { font-size: 13px; color: var(--warn); margin-top: 4px; }
.job__meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: var(--ink-2); text-align: right; flex: none; }
.job__status { font-weight: 700; font-size: 14px; color: var(--ink); }
.job--queued .job__status, .job--sending .job__status { color: var(--warn); }
.job--sent .job__status { color: var(--sent); }

/* ---------- form ---------- */
.secnav {
  position: sticky; top: calc(env(safe-area-inset-top, 0px) + 64px); z-index: 9;
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none;
}
.secnav::-webkit-scrollbar { display: none; }
.secnav button {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface); font-size: 15px; white-space: nowrap;
}
.form, .review { max-width: 760px; margin: 0 auto; padding: 8px 16px 120px; }
.fsec {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 16px 16px; margin-top: 16px; scroll-margin-top: 130px;
}
.fsec h2 { font-size: 20px; margin: 12px 0 4px; }
.fsec__note { margin: 0 0 6px; color: var(--ink-2); font-size: 15px; }
.fsec--internal { border-style: dashed; border-color: var(--warn); }

.field { padding-top: 16px; }
.field > label, .label-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.field__label { font-weight: 600; }
.req { font-size: 12px; color: var(--ink-2); }
.tag {
  font-size: 12px; font-weight: 600; color: var(--warn); border: 1px solid var(--warn);
  border-radius: 4px; padding: 0 5px; line-height: 18px;
}
.help { font-size: 14px; color: var(--ink-2); margin: 6px 0 0; }
.field--flag { animation: flag 1.6s ease-out; border-radius: 8px; }
@keyframes flag { 0% { background: rgba(240,180,92,.35); } 100% { background: transparent; } }

input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; font-size: 18px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--field);
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px;
}
textarea { min-height: 100px; resize: vertical; }
input[type="date"], input[type="time"] { display: block; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  flex: 1 1 auto; min-height: var(--tap); min-width: 96px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--field); font-weight: 600; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }

.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--field); cursor: pointer;
}
.check input {
  width: 24px; height: 24px; min-height: 0; padding: 0; flex: none; border-radius: 6px;
  border: 2px solid var(--ink-2); background: var(--surface); display: grid; place-items: center;
}
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { content: ""; width: 6px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumbs:empty { display: none; }
.thumb { position: relative; margin: 0; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--field); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb__x {
  position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
}
.thumb--busy { display: grid; place-items: center; font-size: 13px; color: var(--ink-2); }
.photos__bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.photos__count { color: var(--ink-2); font-size: 14px; }
.addphoto { cursor: pointer; }

.sig { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 8px; }
.sig canvas { width: 100%; height: 180px; display: block; touch-action: none; }
.sig__line { position: absolute; left: 16px; right: 16px; bottom: 34px; border-top: 1px solid #c9d1ce; font-size: 12px; color: #8c9a96; padding-top: 2px; pointer-events: none; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 10px; padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: var(--surface); border-top: 1px solid var(--line);
}

/* ---------- review ---------- */
.missing { background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 12px; padding: 4px 16px 12px; margin-top: 16px; }
.missing h2 { font-size: 18px; margin: 12px 0 8px; }
.missing ul { list-style: none; margin: 0; padding: 0; }
.missing button {
  width: 100%; text-align: left; min-height: var(--tap); padding: 8px 12px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); display: flex; flex-direction: column;
}
.missing small { color: var(--ink-2); }
.ready { margin-top: 16px; padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--sent); }
.waitbox { margin-top: 16px; padding: 12px 16px; border-radius: 12px; background: var(--warn-bg); border: 1px solid var(--warn); }
.waitbox p { margin: 0 0 10px; }
.waitbox__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sum { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px 16px 10px; margin-top: 12px; }
.sum h2 { font-size: 18px; margin: 12px 0 6px; }
.sum dl { margin: 0; }
.sum__row { display: grid; grid-template-columns: minmax(140px, 38%) 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.sum__row:first-child { border-top: 0; }
.sum dt { color: var(--ink-2); font-size: 15px; }
.sum dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.sum__thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.sum__thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 10px; z-index: 50;
  max-width: calc(100% - 32px); font-size: 15px; transition: opacity .4s;
}
.toast--out { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (max-width: 520px) {
  .sum__row { grid-template-columns: 1fr; gap: 2px; }
  .tile__name { font-size: 18px; }
}
