/* ============================================================
   Punchlist — mobile-first styles
   ============================================================ */
:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface-2: #273449;
  --line:      #334155;
  --text:      #e2e8f0;
  --text-dim:  #94a3b8;
  --primary:   #2563eb;
  --primary-d: #1d4ed8;
  --accent:    #f59e0b;
  --success:   #22c55e;
  --danger:    #ef4444;
  --radius:    14px;
  --shadow:    0 6px 20px rgba(0,0,0,.35);
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, select, a, .chip, .icon-btn { touch-action: manipulation; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  overflow-x: hidden;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
.header-inner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px;
}
.header-title { flex: 1; min-width: 0; }
.header-title h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-sub { font-size: .75rem; color: var(--text-dim); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px; flex: 0 0 auto;
  border: none; border-radius: 10px;
  background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 12px;
}
.plans-entry {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px 6px 11px; border-radius: 999px; font-size: .82rem; font-weight: 700;
  background: var(--primary); color: #fff; border: none;
}
.plans-entry:active { background: var(--primary-d); }
.plans-entry svg { width: 17px; height: 17px; }
.filters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; padding-bottom: 2px; flex: 1 1 auto; }
.filters::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; flex: 0 0 auto; }
.chip {
  border: 1px solid var(--line);
  background: transparent; color: var(--text-dim);
  padding: 6px 14px; border-radius: 999px; font-size: .82rem; font-weight: 600;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.progress-wrap { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

/* Search bar */
.searchbar { padding: 0 12px 8px; gap: 8px; }
#selectBtn { flex: 0 0 auto; }
#selectBtn.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.search-wrap { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }
.search-wrap svg { width: 18px; height: 18px; color: var(--text-dim); flex: 0 0 auto; }
.search-wrap input { flex: 1; min-width: 0; border: none; background: transparent; color: var(--text); font-size: .95rem; padding: 10px 0; outline: none; }
.search-wrap input::placeholder { color: var(--text-dim); }
.search-wrap button { flex: 0 0 auto; border: none; background: transparent; color: var(--text-dim); display: grid; place-items: center; width: 28px; height: 28px; }
.search-wrap button svg { width: 16px; height: 16px; }

/* Filter bar (trade + person + area) */
.filterbar { padding: 0 12px 10px; gap: 8px; flex-wrap: wrap; }
.filterbar .filter-select { flex: 1 1 28%; min-width: 92px; }
.filter-select {
  flex: 1 1 0; min-width: 0; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-size: .82rem; font-weight: 600;
}
.filter-select.on { border-color: var(--primary); color: var(--primary); }
#clearFilters { flex: 0 0 auto; }

/* Directory group headers */
.dir-group { font-size: .72rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--text-dim); margin: 14px 0 6px; }
.dir-group:first-child { margin-top: 2px; }

/* One-time Plans tip */
.plan-tip[hidden] { display: none; }
.plan-tip {
  display: flex; align-items: center; gap: 12px;
  background: rgba(37,99,235,.12); border: 1px solid rgba(37,99,235,.35);
  border-radius: var(--radius); padding: 12px 12px 12px 14px; margin-bottom: 12px;
}
.plan-tip > svg { width: 26px; height: 26px; flex: 0 0 auto; color: var(--primary); }
.plan-tip-text { flex: 1; font-size: .84rem; color: var(--text); }
.plan-tip-text strong { color: var(--primary); }
.plan-tip-x { flex: 0 0 auto; width: 30px; height: 30px; border: none; background: transparent; color: var(--text-dim); display: grid; place-items: center; border-radius: 8px; }
.plan-tip-x svg { width: 18px; height: 18px; }
.progress-bar { width: 90px; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0%; background: var(--success); transition: width .3s ease; }
.progress-text { font-size: .75rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Content / list ---------- */
.content { padding: 12px 12px 120px; max-width: 760px; margin: 0 auto; }
.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.item-card {
  display: flex; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
  transition: opacity .2s;
}
.item-card.done { opacity: .62; }
.item-thumb {
  width: 76px; height: 76px; flex: 0 0 auto;
  border-radius: 10px; object-fit: cover; background: var(--surface-2);
  border: 1px solid var(--line);
}
.item-thumb.placeholder { display: grid; place-items: center; color: var(--text-dim); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 1rem; font-weight: 600; word-break: break-word; }
.item-card.done .item-title { text-decoration: line-through; }
.item-notes { font-size: .84rem; color: var(--text-dim); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tag {
  font-size: .7rem; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); display: inline-flex; align-items: center; gap: 4px;
}
.tag.prio-high { background: rgba(239,68,68,.18); color: #fca5a5; }
.tag.prio-med  { background: rgba(245,158,11,.18); color: #fcd34d; }
.tag.prio-low  { background: rgba(34,197,94,.16); color: #86efac; }
.tag.assignee { background: rgba(37,99,235,.18); color: #93c5fd; }
.tag.cat { background: rgba(148,163,184,.16); color: var(--text-dim); }
.tag.due { background: rgba(148,163,184,.16); color: var(--text-dim); }
.tag.due.overdue { background: rgba(239,68,68,.2); color: #fca5a5; }
/* status badge — colored dot + label */
.tag.status { color: #fff; }
.tag.status.st-open     { background: #64748b; }
.tag.status.st-progress { background: #2563eb; }
.tag.status.st-done     { background: #16a34a; }
.tag.status.st-verified { background: #7c3aed; }

/* status ring on the check button */
.item-check.st-progress { border-color: #3b82f6; color: #3b82f6; }
.item-check.st-progress svg { width: 12px; height: 12px; }
.item-check.st-done     { background: #22c55e; border-color: #22c55e; color: #06240f; }
.item-check.st-verified { background: #7c3aed; border-color: #7c3aed; color: #fff; }

.item-check {
  flex: 0 0 auto; align-self: flex-start;
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent;
  display: grid; place-items: center; color: transparent;
}
.item-check.checked { background: var(--success); border-color: var(--success); color: #06240f; }
.item-card.selected { outline: 2px solid var(--primary); outline-offset: -1px; }
.item-check.selbox { border-color: var(--primary); }
.item-check.selbox.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Bulk action bar */
.bulk-bar[hidden] { display: none; }
.bulk-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + var(--safe-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.25);
  display: flex; align-items: center; gap: 10px;
}
.bulk-bar #bulkCount { font-weight: 700; font-size: .78rem; flex: 0 0 auto; white-space: nowrap; }
.bulk-actions { display: flex; gap: 5px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.bulk-actions::-webkit-scrollbar { display: none; }
.bulk-actions button { flex: 0 0 auto; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .8rem; }
.bulk-actions button[data-act="delete"] { color: #fca5a5; background: rgba(239,68,68,.12); border-color: transparent; }
.bulk-bar #bulkDone { flex: 0 0 auto; width: 38px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: none; background: var(--surface-2); color: var(--text); }
.bulk-bar #bulkDone svg { width: 18px; height: 18px; }
.item-check svg { width: 18px; height: 18px; stroke-width: 3; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-icon { width: 64px; height: 64px; stroke-width: 1.5; margin-bottom: 12px; color: var(--line); }
.empty-state h2 { font-size: 1.1rem; color: var(--text); }
.empty-state p { max-width: 320px; margin: 8px auto 0; font-size: .9rem; }

/* ---------- FAB ---------- */
.fab-group {
  position: fixed; right: 16px; z-index: 40;
  bottom: calc(20px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.fab { border: none; border-radius: 50%; display: grid; place-items: center; box-shadow: var(--shadow); color: #fff; }
.fab-primary { width: 62px; height: 62px; background: var(--primary); }
.fab-primary:active { background: var(--primary-d); }
.fab-primary svg { width: 28px; height: 28px; }
.fab-secondary { width: 48px; height: 48px; background: var(--surface-2); border: 1px solid var(--line); }
.fab-secondary:active { background: var(--line); }

/* ---------- Drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 60;
  width: min(84vw, 340px);
  background: var(--surface); border-right: 1px solid var(--line);
  transform: translateX(-105%); transition: transform .25s ease;
  display: flex; flex-direction: column;
  padding: calc(12px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head h2 { font-size: 1.1rem; }
.project-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.project-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid transparent;
}
.project-row.active { border-color: var(--primary); }
.project-row .pr-main { flex: 1; min-width: 0; }
.project-row .pr-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-row .pr-sub { font-size: .74rem; color: var(--text-dim); }
.project-row .pr-del { color: var(--text-dim); }
.btn-block {
  margin-top: 12px; width: 100%; padding: 13px; border-radius: 10px;
  border: 1px dashed var(--line); background: transparent; color: var(--text); font-weight: 600;
}
.btn-block:active { background: var(--surface-2); }
.drawer-footer { display: flex; gap: 16px; justify-content: center; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.link-btn { background: none; border: none; color: var(--primary); font-size: .82rem; font-weight: 600; padding: 6px; }

/* ---------- Modal / sheet ---------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  max-height: 92vh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 5; }
.sheet-head .icon-btn { width: 46px; height: 46px; }
.sheet-head h2 { font-size: 1.05rem; }
.sheet-body { padding: 16px; overflow-y: auto; }
.sheet-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 10px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .03em; }
.field input, .field textarea, .field select {
  width: 100%; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-size: 1rem; font-family: inherit;
}
.field textarea { min-height: 88px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.btn { padding: 13px 18px; border-radius: 10px; border: none; font-weight: 700; font-size: .95rem; flex: 1; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-d); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: rgba(239,68,68,.15); color: #fca5a5; }

/* Detail preview image */
.detail-photo { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; margin-bottom: 6px; background: var(--bg); }
.detail-photo-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.mini-btn { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .82rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.mini-btn svg { width: 16px; height: 16px; }

/* ---------- Annotation editor ---------- */
.annot-scrim { position: fixed; inset: 0; background: #000; z-index: 110; display: flex; flex-direction: column; }
.annot-top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-top)) 14px 10px; color: #fff; gap: 8px; }
.annot-top .link-btn { color: #fff; font-size: .95rem; }
.annot-stage { flex: 1; display: grid; place-items: center; overflow: hidden; position: relative; }
#annotCanvas { max-width: 100%; max-height: 100%; touch-action: none; box-shadow: 0 0 0 1px rgba(255,255,255,.1); }
.annot-tools { display: flex; align-items: center; gap: 6px; padding: 10px 12px calc(12px + var(--safe-bottom)); background: #111; overflow-x: auto; }
.tool-btn { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 10px; background: #222; border: 2px solid transparent; color: #fff; display: grid; place-items: center; }
.tool-btn.active { border-color: var(--primary); background: #1e3a8a; }
.color-dot { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.color-dot.active { border-color: #fff; }
.tool-sep { width: 1px; height: 30px; background: #333; flex: 0 0 auto; margin: 0 2px; }

/* ---------- Plans view ---------- */
.plans-scrim { position: fixed; inset: 0; background: #0b0f19; z-index: 85; display: flex; flex-direction: column; }
.plans-top { display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-top)) 10px 8px; background: var(--surface); border-bottom: 1px solid var(--line); }
.plans-top .plan-title { flex: 1; min-width: 0; font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plans-top select { max-width: 45vw; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-weight: 600; }
.plan-stage { flex: 1; position: relative; overflow: hidden; background:
  repeating-conic-gradient(#0e1524 0% 25%, #0b0f19 0% 50%) 50% / 28px 28px; touch-action: none; }
.plan-content { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.plan-content img { display: block; -webkit-user-select: none; user-select: none; pointer-events: none; }
.plan-pin {
  position: absolute; transform-origin: bottom center; transform: translate(-50%, -100%);
  display: grid; place-items: center; cursor: pointer; z-index: 2;
}
.plan-pin .pin-body {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: #64748b; border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.5);
  display: grid; place-items: center;
}
.plan-pin .pin-body span { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 800; }
.plan-pin.st-open .pin-body     { background: #64748b; }
.plan-pin.st-progress .pin-body { background: #2563eb; }
.plan-pin.st-done .pin-body     { background: #16a34a; }
.plan-pin.st-verified .pin-body { background: #7c3aed; }

.plan-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--text-dim); padding: 24px; }
.plan-empty svg { width: 60px; height: 60px; stroke-width: 1.5; color: var(--line); }

.plans-fabs { position: absolute; right: 16px; bottom: calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 12px; z-index: 4; }
.plan-hint { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 4;
  background: rgba(37,99,235,.95); color: #fff; padding: 8px 16px; border-radius: 999px; font-size: .85rem; font-weight: 600; box-shadow: var(--shadow); }
.fab.active-mode { background: var(--accent); }
.zoom-controls { position: absolute; left: 16px; bottom: calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; z-index: 4; }
.zoom-btn { width: 44px; height: 44px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--text); display: grid; place-items: center; box-shadow: var(--shadow); }

/* ---------- Contacts list ---------- */
.contact-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; background: var(--surface-2); margin-bottom: 8px; }
.contact-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
.contact-info { flex: 1; min-width: 0; }
.contact-info .cn { font-weight: 600; }
.contact-info .cc { font-size: .78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-actions { display: flex; gap: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom)); z-index: 130;
  background: #0b1220; color: #fff; border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 999px; font-size: .88rem; box-shadow: var(--shadow);
  max-width: 90vw; text-align: center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.helper { font-size: .78rem; color: var(--text-dim); margin: -6px 0 14px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.checkbox-row input { width: 20px; height: 20px; }
.checkbox-row label { text-transform: none; letter-spacing: 0; font-size: .95rem; color: var(--text); margin: 0; }

/* Light-mode support for people who prefer it */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9; --surface: #ffffff; --surface-2: #eef2f7; --line: #d5dce6;
    --text: #0f172a; --text-dim: #64748b; --shadow: 0 4px 14px rgba(15,23,42,.08);
  }
}
