:root {
  --bg: #f4f4f1; --card: #ffffff; --text: #1c1c1e; --muted: #6b6b72; --line: #e3e3de; --soft: #f0f0ec;
  --accent: #0d9488; --accent-ink: #ffffff; --accent-soft: #d5f2ee;
  --ok: #16a34a; --ok-soft: #dcfce7; --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626; --bad-soft: #fee2e2; --info: #2563eb; --info-soft: #dbeafe;
  --k-cleaning: #0d9488; --k-deep_clean: #7c3aed; --k-maintenance: #d97706; --k-other: #64748b;
  --c1: #ff5a5f; --c2: #00a699; --c3: #fc9d4a; --c4: #6a5acd; --c5: #2e86de; --c6: #c2185b;
  --radius: 14px; --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --card: #1c1c1f; --text: #ececf0; --muted: #9a9aa3; --line: #2d2d32; --soft: #232327;
    --accent-soft: #11332f; --ok-soft: #12301d; --warn-soft: #3a2a0c; --bad-soft: #3b1515; --info-soft: #14254a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* stops iOS zoom on focus */
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.brand { font-weight: 700; font-size: 17px; margin-right: auto; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 12px; border-radius: 10px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 6px; position: relative; }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.nav svg { width: 20px; height: 20px; }
.nav .dot { position: absolute; top: 4px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--bad); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 120px; }
@media (max-width: 760px) {
  .topbar .nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
    justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 0; z-index: 30; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; }
  .nav a.on { background: none; }
  main { padding-bottom: calc(var(--nav-h) + 110px); }
}

/* ---------- building blocks ---------- */
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stack > * + * { margin-top: 10px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: none; }
.iconbtn:hover { background: var(--soft); color: var(--text); }
.iconbtn svg { width: 21px; height: 21px; }
.iconbtn.need { color: var(--warn); }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.input { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--soft);
  color: var(--muted); white-space: nowrap; }
.pill.open { background: var(--soft); color: var(--muted); }
.pill.in_progress { background: var(--info-soft); color: var(--info); }
.pill.submitted { background: var(--ok-soft); color: var(--ok); }
.pill.overdue { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.bar { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s; }
.bar.done > i { background: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.err { color: var(--bad); font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { text-align: center; }
.login .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center;
  margin: 0 auto 12px; }
.login .logo svg { width: 30px; height: 30px; }

/* ---------- calendar ---------- */
.cal { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.dow, .cgrid { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow div { padding: 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
.day { position: relative; min-height: 100px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px 8px; }
.day:nth-child(7n) { border-right: 0; }
.day.other { background: var(--soft); color: var(--muted); }
.num { font-size: 13px; font-weight: 500; }
.day.today .num { background: var(--c1); color: #fff; border-radius: 999px; padding: 1px 7px; }
.bk { position: absolute; top: 30px; height: 24px; left: -1px; right: -1px; z-index: 1; opacity: .9; }
.bk.first { left: 50%; border-radius: 12px 0 0 12px; }
.bk.last { right: 50%; border-radius: 0 12px 12px 0; }
.bk.first.last { border-radius: 12px; }
.bklabel { position: absolute; top: 30px; z-index: 2; height: 24px; line-height: 24px; color: #fff; font-size: 12px; font-weight: 600;
  white-space: nowrap; pointer-events: none; padding-left: 8px; }
.chip { position: absolute; left: 6px; right: 6px; top: 60px; z-index: 3; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 6px;
  border: 0; cursor: pointer; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip + .chip { top: 82px; }
.chip.open { background: var(--warn-soft); color: var(--warn); }
.chip.in_progress { background: var(--info-soft); color: var(--info); }
.chip.submitted { background: var(--ok-soft); color: var(--ok); }
@media (max-width: 640px) {
  .day { min-height: 92px; padding: 4px; }
  .bklabel { font-size: 10px; padding-left: 4px; }
  .dow div { padding: 6px 4px; font-size: 10px; }
  .chip { font-size: 10px; left: 2px; right: 2px; padding: 1px 3px; }
}

/* ---------- task list ---------- */
.dategroup { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 20px 0 8px; }
.tcard { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-left: 5px solid var(--k-other); border-radius: var(--radius); padding: 12px 14px; }
.tcard + .tcard { margin-top: 8px; }
.tcard:hover { border-color: var(--muted); }
.tcard.cleaning { border-left-color: var(--k-cleaning); }
.tcard.deep_clean { border-left-color: var(--k-deep_clean); }
.tcard.maintenance { border-left-color: var(--k-maintenance); }
.tcard .title { font-weight: 700; font-size: 16px; }
.tcard .bar { margin-top: 10px; }

/* ---------- task detail ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 6px; }
.back svg { width: 18px; height: 18px; }
.info dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.info dd { margin: 0 0 8px; }
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 4px 16px; margin: 0; }
.sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-top: 10px; overflow: hidden; }
.sec > summary { list-style: none; cursor: pointer; padding: 13px 14px; display: flex; align-items: center; gap: 10px; font-weight: 700; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary > svg { width: 18px; height: 18px; color: var(--muted); transition: transform .15s; flex: none; }
.sec[open] > summary > svg { transform: rotate(90deg); }
.sec .count { font-size: 13px; font-weight: 600; color: var(--muted); }
.sec.complete > summary .count { color: var(--ok); }
.item { display: flex; align-items: flex-start; gap: 6px; padding: 8px 8px 8px 6px; border-top: 1px solid var(--line); }
.item .body { flex: 1; min-width: 0; padding-top: 9px; }
.item .text { word-wrap: break-word; }
.item.done .text { color: var(--muted); }
.item .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item .tag { font-size: 11px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 1px 6px;
  margin-left: 4px; white-space: nowrap; }
.item .tag.ok { color: var(--ok); background: var(--ok-soft); }
.check { width: 44px; height: 44px; flex: none; border: 0; background: none; cursor: pointer; display: grid; place-items: center; padding: 0; }
.check i { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; transition: all .12s; }
.check svg { width: 16px; height: 16px; color: #fff; opacity: 0; }
.item.done .check i { background: var(--ok); border-color: var(--ok); }
.item.done .check svg { opacity: 1; }
.check:disabled { cursor: default; }
.qmark { width: 44px; height: 44px; flex: none; display: grid; place-items: center; }
.qmark i { width: 26px; height: 26px; border-radius: 50%; border: 2px dashed var(--muted); display: grid; place-items: center;
  font-style: normal; font-weight: 700; color: var(--muted); font-size: 13px; }
.item.done .qmark i { background: var(--ok); border: 2px solid var(--ok); color: #fff; }
.qmark svg { width: 16px; height: 16px; color: #fff; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.opts button { min-width: 44px; min-height: 38px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; }
.opts button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.opts button:disabled { cursor: default; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.thumbs img, .thumbs .up { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--soft); cursor: pointer; display: block; }
.thumbs .up { display: grid; place-items: center; cursor: default; }
.addrow { padding: 10px 12px; border-top: 1px solid var(--line); }
.del { color: var(--bad); }
.stickybar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
.stickybar .inner { max-width: 980px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
@media (max-width: 760px) { .stickybar { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: 10px; } }
.banner { border-radius: var(--radius); padding: 14px 16px; background: var(--ok-soft); color: var(--text); border: 1px solid transparent; }
.banner img.sig { max-width: 260px; width: 100%; background: #fff; border-radius: 8px; margin-top: 8px; display: block; }

/* ---------- supplies / issues ---------- */
.entry { display: flex; align-items: flex-start; gap: 6px; padding: 8px 8px 8px 6px; }
.entry + .entry { border-top: 1px solid var(--line); }
.entry .body { flex: 1; min-width: 0; padding-top: 9px; }
.entry.done .desc { color: var(--muted); text-decoration: line-through; }
.entry .desc { white-space: pre-wrap; word-wrap: break-word; }
.entry .check i { border-radius: 8px; }
.entry.done .check i { background: var(--ok); border-color: var(--ok); }
.entry.done .check svg { opacity: 1; }
.listcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.staged { display: flex; gap: 6px; flex-wrap: wrap; }
.staged div { position: relative; }
.staged img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.staged button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 22px; cursor: pointer; padding: 0; }

/* ---------- template editor ---------- */
.tpl-item { display: flex; gap: 6px; align-items: flex-start; padding: 8px 10px; border-top: 1px solid var(--line); }
.tpl-item .grow > * + * { margin-top: 6px; }
.tpl-item .acts { display: flex; flex-direction: column; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
  user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- overlays ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow: auto; }
@media (min-width: 600px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }
.sigpad { width: 100%; height: 170px; background: #fff; border: 1px dashed var(--muted); border-radius: 10px; touch-action: none; display: block; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; flex-direction: column; }
.lightbox img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.lightbox .row { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); justify-content: space-between; color: #fff; }
.lightbox .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 80px); transform: translateX(-50%); z-index: 70; background: var(--text);
  color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }
