/* Punch List styles. Mobile first; colors are defined once here. */

:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #5f6b7a;
  --border: #d5dae1;
  --header: #1a315d;          /* logo navy */
  --accent: #2463a7;          /* logo blue: buttons, highlights */
  --accent-text: #2463a7;     /* accent used as text (links) */
  --accent-soft: #eaf1fa;     /* selected-option background */
  --accent-ring: rgba(36, 99, 167, .18);
  --danger: #c62828;
  --danger-fill: #c62828;
  --stage-bg: #b8bec8;
  --field: #ffffff;           /* text boxes and dropdowns */
  --table-head: #f5f6f8;
  --placeholder: #b0b7c1;
  --note-bg: #1f2933;         /* toast */
  --hint-bg: rgba(31,41,51,.88);
  --link-on-dark: #9cc4f5;
  --error-bg: #fdecea; --error-text: #a1231b;
  --warn-bg: #fff4e0;  --warn-text: #7a4a00;
  --pending-text: #9a4a00;
  --saved-bg: #e1ecf9;
  color-scheme: light;

  /* Status colors — used by pins, status buttons, and (later) the list view */
  --st-open: #d93025;
  --st-progress: #e37400;
  --st-review: #1a73e8;
  --st-closed: #188038;
  --pin-group: #59636e;       /* "+N" pin for overlapping pins */

  --person-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c0-4 3.6-7 8-7s8 3 8 7'/%3E%3C/svg%3E");
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark mode: follows the phone's setting (Auto), or forced by ☰ › This device › Appearance
   (html[data-theme=light|dark], see setTheme in js/ui.js). The two dark blocks must stay identical.
   Drawings stay white paper; photos, PDFs and Excel files are not affected. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0f141b; --surface: #1a212b; --field: #121820; --text: #e6eaf0; --muted: #9aa5b4; --border: #344050;
    --header: #132544; --accent-text: #8ab8f5; --accent-soft: #1b2b42; --accent-ring: rgba(138, 184, 245, .2);
    --danger: #f07167; --danger-fill: #c62828; --stage-bg: #2a313b; --table-head: #222a35; --placeholder: #5d6878;
    --note-bg: #2c3542; --hint-bg: rgba(8,11,15,.88);
    --error-bg: #3a1d1d; --error-text: #ffb4ab; --warn-bg: #3a2c12; --warn-text: #f5c46b; --pending-text: #f0a050;
    --saved-bg: #1b2b42;
    --seg-open: #ff8a80; --seg-progress: #f0a050; --seg-review: #8ab8f5; --seg-closed: #5cc47a;
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --bg: #0f141b; --surface: #1a212b; --field: #121820; --text: #e6eaf0; --muted: #9aa5b4; --border: #344050;
  --header: #132544; --accent-text: #8ab8f5; --accent-soft: #1b2b42; --accent-ring: rgba(138, 184, 245, .2);
  --danger: #f07167; --danger-fill: #c62828; --stage-bg: #2a313b; --table-head: #222a35; --placeholder: #5d6878;
  --note-bg: #2c3542; --hint-bg: rgba(8,11,15,.88);
  --error-bg: #3a1d1d; --error-text: #ffb4ab; --warn-bg: #3a2c12; --warn-text: #f5c46b; --pending-text: #f0a050;
  --saved-bg: #1b2b42;
  --seg-open: #ff8a80; --seg-progress: #f0a050; --seg-review: #8ab8f5; --seg-closed: #5cc47a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- Buttons & inputs ---------- */

.btn {
  font: inherit; font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: 14px; }

input[type=text], input[type=search], select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iPhone from zooming in on focus */
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--field); color: var(--text);
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.invalid { border-color: var(--danger); }

/* ---------- Top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--header); color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Logo = home button (see BRAND in js/ui.js) */
.brand {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-height: 40px;
  color: #fff; text-decoration: none; font-weight: 700; font-size: 18px;
}
.brand-logo { height: 36px; width: auto; display: block; }
.brand-back { font-size: 26px; font-weight: 400; line-height: 1; margin: -2px -2px 0 0; }
.brand + h1 { margin-left: 4px; }
/* Projects screen: logo + name centered */
.topbar-home { justify-content: center; position: relative; }
/* ☰ menu + account buttons (nav.js), top right of every screen. On the Projects screen they're
   pinned to the right so the logo stays centered. */
.header-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.topbar-home .header-actions { position: absolute; right: 10px; bottom: 8px; }
.account-btn, .menu-btn {
  width: 40px; height: 40px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1.5px solid rgba(255,255,255,.55); background: transparent; color: #fff; font: inherit; font-weight: 700; font-size: 17px;
}
.menu-btn { border-color: transparent; }
.ui-icon { display: block; width: 22px; height: 22px; }
.ui-icon svg { display: block; width: 100%; height: 100%; }
.account-icon:empty {
  width: 18px; height: 18px; display: block;
  background: currentColor; -webkit-mask: var(--person-icon) center / contain no-repeat; mask: var(--person-icon) center / contain no-repeat;
}
.account-btn.signed-in { background: var(--accent); border-color: var(--accent); }
.account-body { gap: 14px; }
.account-form { display: flex; flex-direction: column; gap: 14px; }
.account-input { font: inherit; font-size: 16px; width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--field); color: var(--text); }
.account-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.account-submit { width: 100%; min-height: 46px; }
.account-links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.account-big { margin: 0; font-size: 17px; line-height: 1.4; }
.account-who { display: flex; flex-direction: column; gap: 4px; font-size: 17px; word-break: break-all; }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--error-bg); color: var(--error-text); font-size: 14px; line-height: 1.4; }
.head-spacer { width: 64px; flex: 0 0 auto; }
.topbar-home .brand-logo { height: 40px; width: auto; }
.brand-name { font-weight: 700; font-size: 18px; line-height: 1.1; } /* same as the screen titles (.topbar h1) */
/* Narrow phones (e.g. iPhone SE): a centered name would run into the ☰ / account buttons. */
@media (max-width: 399px) { .topbar-home { justify-content: flex-start; } }
@media (max-width: 479px) {
  .tab { padding: 4px 9px; font-size: 13px; }
}

/* Drawing | List tabs */
.tabs { display: flex; flex: 0 0 auto; padding: 3px; gap: 2px; border-radius: 10px; background: rgba(255,255,255,.14); }
.tab {
  font: inherit; font-size: 14px; font-weight: 600; min-height: 34px; padding: 4px 12px;
  border: none; border-radius: 8px; background: transparent; color: #fff; cursor: pointer;
}
.tab.active { background: #fff; color: var(--header); }

/* ---------- Projects screen ---------- */

.scroll { flex: 1; overflow: auto; padding: 16px; padding-bottom: calc(16px + var(--safe-bottom)); }
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 12px; }
.new-project { display: flex; gap: 8px; margin-bottom: 16px; }
.project-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: block; padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  color: inherit; text-decoration: none;
}
.card-title { font-weight: 600; font-size: 17px; }
.card-meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.project-card { display: flex; align-items: stretch; padding: 0; }
.card-link { flex: 1; min-width: 0; padding: 14px 16px; color: inherit; text-decoration: none; }
.card-menu {
  flex: 0 0 auto; width: 52px; border: none; border-left: 1px solid var(--border); background: none;
  font: inherit; font-size: 22px; font-weight: 700; color: var(--muted); cursor: pointer; border-radius: 0 12px 12px 0;
}
.project-card.archived { opacity: .75; }
.archive { margin-top: 24px; }
.archive > summary {
  cursor: pointer; padding: 10px 2px; font-size: 14px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.archive .project-list { margin-top: 8px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }
.backup-tools { margin-top: 32px; }
.backup-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.backup-buttons .btn { flex: 1 1 160px; }
.backup-note { color: var(--muted); font-size: 13px; margin: 10px 2px 0; line-height: 1.4; }
.app-version { color: var(--muted); font-size: 12px; text-align: center; margin: 32px 0 0; opacity: .8; }

/* ---------- Project / drawing screen ---------- */

.toolbar {
  display: flex; gap: 8px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.sheet-select { flex: 1; min-width: 0; }

.stage-wrap { flex: 1; position: relative; min-height: 0; }
.stage {
  position: absolute; inset: 0; overflow: hidden;
  background: var(--stage-bg);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.stage.loading::after {
  content: 'Loading sheet…'; position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.7); color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 14px;
}
/* The sheet is painted onto one screen-sized canvas (never CSS-enlarged: see drawing-view.js);
   the pins sit on top, in screen pixels. */
.sheet-screen { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.pin-layer { position: absolute; inset: 0; overflow: hidden; }

.stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; padding: 24px; text-align: center;
  background: var(--bg); color: var(--muted);
}
.stage-empty .empty-title { color: var(--text); font-weight: 600; font-size: 18px; margin: 0; }
.stage-empty .btn { margin-top: 12px; }

.fab {
  position: absolute; right: 12px; bottom: calc(12px + var(--safe-bottom));
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
/* "Tap the drawing where item #5 goes" (placing an existing item) */
.place-hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.place-hint .btn { flex: 0 0 auto; }
.stage.placing { cursor: crosshair; }
.hint {
  position: absolute; left: 12px; bottom: calc(12px + var(--safe-bottom)); max-width: calc(100% - 100px);
  background: var(--hint-bg); color: #fff; font-size: 13px;
  padding: 8px 12px; border-radius: 10px; pointer-events: none;
}

/* ---------- Filter bar (trade dropdown + status chips) ---------- */

.filterbar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.filterbar::-webkit-scrollbar { display: none; }
.trade-filter { width: auto; max-width: 170px; flex: 0 0 auto; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.trade-filter.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.chips { display: flex; gap: 6px; flex: 0 0 auto; }
.chip {
  font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 4px 10px; border-radius: 18px;
  border: 1.5px solid var(--chip-color); background: var(--chip-color); color: #fff; cursor: pointer;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.chip .count { font-weight: 500; opacity: .9; }
.chip[aria-pressed=false] { background: var(--surface); color: var(--muted); border-color: var(--border); }
.chip[aria-pressed=false] .dot { background: var(--chip-color); opacity: .5; }
.chip[data-status=open]     { --chip-color: var(--st-open); }
.chip[data-status=progress] { --chip-color: var(--st-progress); }
.chip[data-status=review]   { --chip-color: var(--st-review); }
.chip[data-status=closed]   { --chip-color: var(--st-closed); }

.chip .label-short { display: none; }
/* Phones: all four chips in one row (so none hide off-screen), trade picker underneath. */
@media (max-width: 599px) {
  .filterbar { flex-wrap: wrap; overflow: visible; }
  .chips { order: -1; width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); }
  .chip { justify-content: center; gap: 4px; padding: 4px; font-size: 13px; }
  .chip .dot { display: none; }
  .chip .label-long { display: none; }
  .chip .label-short { display: inline; }
  .trade-filter { max-width: none; flex: 1 1 100%; }
}

.filter-note {
  position: absolute; left: 12px; bottom: calc(12px + var(--safe-bottom)); max-width: calc(100% - 100px);
  background: var(--hint-bg); color: #fff; font-size: 13px;
  padding: 6px 6px 6px 12px; border-radius: 10px; display: flex; align-items: center; flex-wrap: wrap;
}
.link-btn.dark { color: var(--accent-text); }
.link-btn { font: inherit; font-weight: 600; background: none; border: none; color: var(--link-on-dark); padding: 4px 6px; cursor: pointer; text-decoration: underline; }

/* Long-press feedback: a ring that fills in while the finger is held down. */
.press-ring {
  position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%;
  border: 3px solid var(--accent); background: var(--accent-ring);
  pointer-events: none; transform: scale(.3); opacity: .4;
  animation: press-grow .5s linear forwards;
}
@keyframes press-grow { to { transform: scale(1); opacity: 1; } }

/* ---------- Pins ---------- */
/* A pin is a 0x0 point at the exact spot; the marker is drawn above it.
   Pins live in a screen-pixel layer, so they stay the same size (and sharp) at any zoom. */

.pin {
  position: absolute; left: 0; top: 0; width: 0; height: 0; /* moved into place by drawing-view.js */
  --pin-color: var(--st-open);
}
.pin[data-status=progress] { --pin-color: var(--st-progress); }
.pin[data-status=review]   { --pin-color: var(--st-review); }
.pin[data-status=closed]   { --pin-color: var(--st-closed); }
.pin[data-status=pending]  { --pin-color: #1f2933; }
.pin[data-status=group]    { --pin-color: var(--pin-group); }
.pin > span {
  /* A circle for numbers; stretches into a pill for custom tags like CB-12. */
  position: absolute; left: 0; translate: -50% 0; top: -42px; min-width: 32px; height: 32px; padding: 0 6px;
  border-radius: 16px; border: 2px solid #fff; background: var(--pin-color); white-space: nowrap;
  color: #fff; font-weight: 700; font-size: 13px; line-height: 28px; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.45); cursor: pointer;
}
.pin::after {
  content: ''; position: absolute; left: -7px; top: -13px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 13px solid var(--pin-color);
}
.pin.pending > span { animation: pulse 1s ease-in-out infinite alternate; }
/* Not synced yet: the number could still change (db.isNumberPending). */
.pin[data-unsynced] > span, .num-badge[data-unsynced] { border-style: dashed; }
.unsynced-hint { display: block; margin-top: 4px; color: var(--pending-text); }
.pin.flash > span { animation: flash .6s ease-in-out 4 alternate; }
@keyframes flash { to { transform: scale(1.6); box-shadow: 0 0 0 8px rgba(36, 99, 167, .5); } }
@keyframes pulse { to { transform: scale(1.15); } }

/* ---------- Item form (bottom sheet on phones, centered dialog on wide screens) ---------- */

.pl-layer {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0,0,0,.45);
}
.pl-sheet {
  width: 100%; max-width: 560px; max-height: calc(100% - var(--safe-top) - 24px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px 16px 0 0;
}
@media (min-width: 640px) {
  .pl-layer { align-items: center; }
  .pl-sheet { border-radius: 16px; max-height: 90%; }
}
.pl-sheet-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.pl-sheet-head h2 { flex: 1; margin: 0; font-size: 17px; text-align: center; }
.pl-sheet-body {
  overflow: auto; padding: 16px; padding-bottom: calc(20px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.meta { margin: 0; font-size: 13px; color: var(--muted); }
.field-hint { font-size: 12px; color: var(--muted); }
.sheet-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.place-btn { flex: 0 0 auto; }
.pin-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.status-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 6px;
  border: 2px solid var(--seg-color); border-radius: 10px;
  color: var(--seg-text, var(--seg-color)); font-weight: 600; font-size: 14px; text-align: center; cursor: pointer;
}
.seg input:checked + span { background: var(--seg-color); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 2px; }
.seg[data-status=open]     { --seg-color: var(--st-open);     --seg-text: var(--seg-open); }
.seg[data-status=progress] { --seg-color: var(--st-progress); --seg-text: var(--seg-progress); }
.seg[data-status=review]   { --seg-color: var(--st-review);   --seg-text: var(--seg-review); }
.seg[data-status=closed]   { --seg-color: var(--st-closed);   --seg-text: var(--seg-closed); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--bg); }
.thumb-open { all: unset; display: block; width: 100%; height: 100%; cursor: pointer; }
.thumb-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1; cursor: pointer;
}
.add-photo {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 2px dashed var(--border); color: var(--muted); cursor: pointer;
}
.add-photo span { font-size: 26px; line-height: 1; }

/* ---------- Trades manager ---------- */

.head-spacer { width: 70px; }
.trade-add { display: flex; gap: 8px; }
.trade-list { display: flex; flex-direction: column; }
.trade-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.trade-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.trade-name small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }

/* ---------- List (spreadsheet) tab ---------- */

.list-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.list-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  padding: 8px 12px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border);
}
.summary-tip { margin-left: auto; }
@media (max-width: 599px) { .summary-tip { display: none; } }
.warn { color: var(--danger); font-weight: 600; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; cursor: pointer; }
.check-row input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--accent); }
.no-pin { font-size: 13px; padding: 0 6px; }

/* ---------- Trade chips (trade-picker.js) ---------- */
.trade-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.trade-chip {
  font: inherit; font-size: 14px; font-weight: 600; min-height: 40px; padding: 6px 14px;
  border-radius: 20px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.trade-chip[aria-pressed=true] { background: var(--header); border-color: var(--header); color: #fff; }
.trade-chip[aria-pressed=true]::before { content: '✓ '; }
.trade-chip-tool { border-style: dashed; color: var(--muted); font-weight: 500; }
.trade-cell {
  all: unset; box-sizing: border-box; display: block; width: 100%; min-height: 40px; padding: 10px 8px;
  cursor: pointer; border: 1px solid transparent; border-radius: 8px; font-size: 15px; line-height: 1.3;
}
.trade-cell:hover { border-color: var(--border); }
.trade-cell.empty-cell { color: var(--placeholder); }

/* ---------- Pick-then-confirm options (ui.js optionCards) ---------- */
.option-cards { display: flex; flex-direction: column; gap: 8px; }
.option-card {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 14px;
  font: inherit; text-align: left; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 12px; cursor: pointer;
}
.option-card[aria-checked=true] { border-color: var(--accent); background: var(--accent-soft); }
.option-card:disabled { opacity: .5; cursor: default; }
.option-dot {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface);
}
.option-card[aria-checked=true] .option-dot { border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--surface); background: var(--accent); }
.option-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.option-text strong { font-size: 15px; }
.option-text small { font-size: 13px; color: var(--muted); }

/* ---------- Choice pop-up (ui.js choose) ---------- */
.pl-choose { max-width: 440px; }
.pl-choose .pl-sheet-body { gap: 10px; }
.choose-title { margin: 0; font-size: 18px; text-align: center; }
.choose-message { white-space: pre-line; margin: 0 0 6px; color: var(--muted); font-size: 15px; text-align: center; line-height: 1.4; }
.choose-btn { width: 100%; min-height: 48px; flex-direction: column; gap: 2px; }
.choose-btn small { font-size: 12px; font-weight: 400; opacity: .85; }
.btn-danger.choose-btn { background: var(--danger-fill); border-color: var(--danger-fill); color: #fff; font-weight: 600; }
.toolbar input[type=search] { flex: 1 1 auto; min-width: 0; }
@media (max-width: 479px) {
  .toolbar:has(input[type=search]) { flex-wrap: wrap; }
  .toolbar input[type=search] { flex-basis: 100%; }
  .list-sheet-filter { flex: 1; min-width: 0; }
}
.list-sheet-filter { width: auto; max-width: 34%; flex: 0 1 auto; }
.table-wrap { flex: 1; min-height: 0; overflow: auto; padding-bottom: var(--safe-bottom); }
.punch-table { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 15px; }
.punch-table th {
  position: sticky; top: 0; z-index: 2; padding: 0; text-align: left; white-space: nowrap;
  background: var(--table-head); border-bottom: 1px solid var(--border);
}
.punch-table th button {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 10px 8px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.punch-table th[aria-sort] button { color: var(--text); }
.sort-arrow { font-size: 10px; }
.punch-table td { padding: 3px 4px; border-bottom: 1px solid var(--border); background: var(--surface); vertical-align: middle; }
/* Keep the # column visible while scrolling sideways */
.punch-table .col-number { position: sticky; left: 0; z-index: 1; text-align: center; padding: 3px 6px; }
.punch-table th.col-number { z-index: 3; }
.punch-table th.col-number button { justify-content: center; }
.col-title { min-width: 220px; }
.col-status { min-width: 160px; }
.col-trade { min-width: 170px; }
.col-location { min-width: 170px; }
.col-description { min-width: 280px; }
.col-sheet { white-space: nowrap; }
.col-updatedAt { white-space: nowrap; padding-right: 12px !important; }
.muted { color: var(--muted); font-size: 14px; }
.table-empty { padding: 32px 16px !important; text-align: center; color: var(--muted); }

.punch-table .cell-input, .punch-table .cell-select {
  width: 100%; min-height: 40px; padding: 6px 8px; border-color: transparent; background: transparent;
}
.punch-table .cell-input:hover, .punch-table .cell-select:hover { border-color: var(--border); }
.cell-input::placeholder { color: var(--placeholder); }
.punch-table .status-select { font-weight: 600; color: #fff; border: none; background: var(--sel-color); }
.status-select option { color: var(--text); background: var(--surface); font-weight: 400; }
.status-select[data-status=open]     { --sel-color: var(--st-open); }
.status-select[data-status=progress] { --sel-color: var(--st-progress); }
.status-select[data-status=review]   { --sel-color: var(--st-review); }
.status-select[data-status=closed]   { --sel-color: var(--st-closed); }

.num-badge {
  min-width: 34px; height: 34px; padding: 0 6px; border-radius: 17px; white-space: nowrap; border: 2px solid #fff; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 700; color: #fff; background: var(--pin-color, var(--st-open));
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.num-badge[data-status=progress] { --pin-color: var(--st-progress); }
.num-badge[data-status=review]   { --pin-color: var(--st-review); }
.num-badge[data-status=closed]   { --pin-color: var(--st-closed); }
.sheet-link {
  all: unset; cursor: pointer; padding: 8px 6px; color: var(--accent-text); font-size: 14px; font-weight: 600;
}
.sheet-link:hover { text-decoration: underline; }
tr.filtered-out td > * { opacity: .4; }
tr.saved td { animation: saved 1.2s ease-out; }
@keyframes saved { from { background: var(--saved-bg); } }

/* ---------- Photos tab ---------- */

.photos-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.photos-scroll { flex: 1; min-height: 0; overflow: auto; padding: 12px; padding-bottom: calc(16px + var(--safe-bottom)); }
.photo-version { width: auto; flex: 1 1 auto; min-width: 0; }
.photo-items { display: flex; flex-direction: column; gap: 12px; max-width: 1000px; margin: 0 auto; }
.photo-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px 12px; }
.photo-item-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-item-title { flex: 1; min-width: 140px; display: flex; flex-direction: column; }
.photo-item-title small { color: var(--muted); font-size: 13px; }
.photo-item-actions { display: flex; gap: 6px; }
.photo-strip { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; }
.photo-thumb { flex: 0 0 auto; width: 120px; height: 120px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photos { text-align: center; }

/* ---------- Photo markup editor ---------- */

.markup { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: #111; color: #fff; }
.markup-bar { display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 6px) 10px 6px; }
.markup-bar .btn-ghost { color: #fff; }
.markup-title { flex: 1; text-align: center; font-weight: 600; }
.markup-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.markup-canvas { touch-action: none; display: block; }
.markup-tools { padding: 8px 10px calc(10px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; }
.tool-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.tool {
  font: inherit; font-size: 14px; min-height: 40px; padding: 6px 12px;
  border-radius: 10px; border: 1px solid #444; background: #222; color: #fff; cursor: pointer;
}
.tool.active { background: #fff; color: #111; }
.tool:disabled { opacity: .4; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.active { border-color: #fff; }

/* ---------- Toast & busy overlay ---------- */

.pl-note {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; transition: opacity .2s, transform .2s;
  background: var(--note-bg); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); pointer-events: none;
}
.pl-note.show { opacity: 1; transform: translate(-50%, 0); }

.pl-working { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.35); }
.pl-working-box { display: flex; align-items: center; gap: 12px; background: var(--surface); padding: 16px 20px; border-radius: 12px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.account-details { display: flex; flex-direction: column; gap: 14px; }
.account-company { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.account-company strong { font-size: 17px; }
.account-company .account-submit { margin-top: 8px; }
/* Sync status line under "Projects" */
.sync-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin: -4px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.35; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: #9aa3ae; }
.sync-line[data-state=idle] .sync-dot { background: var(--st-closed); }
.sync-line[data-state=syncing] .sync-dot { background: var(--st-review); animation: pulse 1s ease-in-out infinite alternate; }
.sync-line[data-state=offline] .sync-dot { background: var(--st-progress); }
.sync-line[data-state=error] .sync-dot { background: var(--danger); }
.sync-line[data-state=error] { color: var(--danger); }
.sync-line .link-btn { padding: 0; }
.device-mode { width: 100%; }
/* People / company / owner screens (people.js) */
.people-body { gap: 14px; }
.people-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.person-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  padding: 10px 14px; min-height: 52px; border: none; border-bottom: 1px solid var(--border);
  background: var(--surface); color: inherit; font: inherit; text-align: left;
}
.people-list > :last-child { border-bottom: none; }
button.person-row { cursor: pointer; }
.person-main { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.person-main small { color: var(--muted); font-size: 13px; }
.person-role { flex: 0 0 auto; font-size: 13px; font-weight: 600; color: var(--muted); text-align: right; max-width: 45%; }
.person-role.invited { color: var(--st-progress); }
.people-subtitle { margin: 6px 0 0; font-size: 15px; }
.people-add { padding-top: 6px; border-top: 1px solid var(--border); }
.role-help summary { cursor: pointer; font-size: 14px; color: var(--muted); }
.role-help ul { margin: 8px 0 0; padding-left: 18px; font-size: 14px; line-height: 1.5; }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.4; }
.check-row input { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 1px; }
.check-row small { color: var(--muted); }
.owner-request { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.owner-actions { display: flex; gap: 6px; }
.view-only-note { padding: 6px 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); }

/* Project header on phones: name + ☰/account on the first row, the four tabs full width below. */
@media (max-width: 599px) {
  .topbar:not(.topbar-home) { flex-wrap: wrap; row-gap: 8px; }
  .topbar:not(.topbar-home) .tabs { order: 3; flex: 1 1 100%; }
  .topbar:not(.topbar-home) .tab { flex: 1; padding: 4px 6px; }
}

/* ☰ menu */
.menu-body { gap: 18px; }
.menu-section { display: flex; flex-direction: column; gap: 10px; }
.menu-section .section-title { margin: 0; }
.menu-section .backup-note { margin: 0; }
.menu-wide { width: 100%; }

/* Sync button, bottom left of every screen */
.sync-fab {
  position: fixed; left: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 40;
  width: 44px; height: 44px; border-radius: 50%; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.22);
}
.sync-fab .ui-icon { width: 20px; height: 20px; }
.sync-fab[data-state=syncing] .ui-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-fab-dot {
  position: absolute; top: 2px; right: 2px; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--st-closed);
}
.sync-fab[data-state=syncing] .sync-fab-dot { background: var(--st-review); }
.sync-fab[data-state=offline] .sync-fab-dot { background: var(--st-progress); }
.sync-fab[data-state=error] .sync-fab-dot { background: var(--danger); }
.sync-fab[data-state=signed-out] .sync-fab-dot { background: #9aa3ae; }
/* keep things clear of it */
.hint, .filter-note { left: 66px; max-width: calc(100% - 150px); }
.scroll, .photos-scroll { padding-bottom: calc(68px + var(--safe-bottom)); }
.table-wrap { padding-bottom: calc(60px + var(--safe-bottom)); }

/* People tab inside a project */
.people-tab { flex: 1; min-height: 0; overflow: auto; padding: 16px; padding-bottom: calc(68px + var(--safe-bottom)); }
.people-tab-inner { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.view-only-note.in-form { margin: 0; border-radius: 10px; border: none; }

/* Old GitHub address only: "we've moved" (app.js movedNote). */
.moved-note { margin: 12px 0; padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-text); }
.moved-note p { margin: 6px 0 0; font-size: 14px; }
.moved-note a:not(.btn) { color: inherit; font-weight: 700; }
.moved-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Photo preview (photo-preview.js) */
.photo-preview {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  background: #111418; color: #fff; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom);
}
.preview-head, .preview-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; }
.preview-title { display: flex; flex-direction: column; min-width: 0; }
.preview-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-title small { color: #aab3bd; font-size: 13px; }
.preview-close { color: #fff; }
.preview-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }
.preview-img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.preview-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px;
  border: none; border-radius: 10px; background: rgba(0,0,0,.45); color: #fff; font-size: 34px; cursor: pointer;
}
.preview-nav.prev { left: 8px; }
.preview-nav.next { right: 8px; }
.preview-count { color: #aab3bd; font-size: 14px; }
.preview-actions { display: flex; gap: 8px; margin-left: auto; }
.sync-line > span:not(.sync-dot) { flex: 1 1 200px; min-width: 0; }
