/* =========================================================
   Site Inspections – styles
   Mobile-first. Light, professional, restrained blue accent.
   ========================================================= */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a2129;
  --text-muted: #5f6b77;
  --border: #dde2e7;
  --border-strong: #c5ccd3;
  --accent: #1f4e79;
  --accent-hover: #183d5f;
  --accent-soft: #e8f0f8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --open: #b54708;
  --open-soft: #fff4e5;
  --closed: #157f3d;
  --closed-soft: #e8f6ee;
  --radius: 10px;
  --tap: 48px;            /* minimum touch target height */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 8px;
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}
.topbar-title.home { font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: var(--tap);
  height: var(--tap);
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}
.icon-btn:active, .icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Page layout ---------- */
.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 16px calc(110px + var(--safe-bottom));
}
.section-title {
  margin: 24px 2px 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.muted { color: var(--text-muted); }
.small { font-size: 14px; }
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- Cards ---------- */
.card {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  color: inherit;
  text-decoration: none;
  text-align: left;
  font: inherit;
}
a.card, button.card { cursor: pointer; }
a.card:active, button.card:active { background: #f8fafc; border-color: var(--border-strong); }
.card-title { font-weight: 650; font-size: 17px; margin: 0 0 2px; word-break: break-word; }
.card-sub { color: var(--text-muted); font-size: 14px; word-break: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; color: var(--text-muted); }
.card-meta strong { color: var(--text); font-weight: 600; }

.info-card dl { margin: 0; display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.info-card dt { color: var(--text-muted); font-size: 14px; }
.info-card dd { margin: 0; font-weight: 500; word-break: break-word; }
.info-card .card-title { font-size: 19px; margin-bottom: 10px; }
.info-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* Snag card */
.snag-card { display: flex; gap: 12px; align-items: flex-start; }
.snag-card .snag-body { flex: 1; min-width: 0; }
.snag-no { font-weight: 700; font-size: 17px; letter-spacing: 0.02em; color: var(--accent); }
.snag-area { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text); margin: 2px 0 4px; word-break: break-word; }
.snag-obs {
  font-size: 14px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.snag-thumb {
  width: 76px; height: 76px; flex: none;
  border-radius: 8px; object-fit: cover; background: #e9edf1; border: 1px solid var(--border);
}
.snag-thumb.none { display: flex; align-items: center; justify-content: center; color: #9aa5b1; font-size: 12px; }
.snag-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.open { color: var(--open); background: var(--open-soft); }
.badge.closed { color: var(--closed); background: var(--closed-soft); }

/* ---------- Summary counters ---------- */
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 6px; }
.counter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; text-align: center; }
.counter b { display: block; font-size: 22px; line-height: 1.2; }
.counter span { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.counter.open b { color: var(--open); }
.counter.closed b { color: var(--closed); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.btn:active { filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #f0b8b2; background: var(--surface); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn.lg { min-height: 56px; font-size: 17px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 15px; }

/* Bottom action bar – keeps main actions within thumb reach on iPhone */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + var(--safe-bottom));
}
.actionbar-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar-inner .btn { flex: 1; }
.actionbar-inner .btn.grow2 { flex: 2; }

/* ---------- Forms ---------- */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label, .field .label {
  display: block;
  font-size: 14px;
  font-weight: 650;
  margin-bottom: 6px;
  color: var(--text);
}
.field .hint { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.req { color: var(--danger); }
input[type="text"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px;      /* 16px+ stops iPhone zooming in on focus */
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"] { display: block; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235f6b77' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.field.invalid input, .field.invalid textarea, .field.invalid select { border-color: var(--danger); }
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; min-width: 0; }

/* Segmented control (Open / Closed, filters) */
.segmented { display: flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: #fff; }
.segmented button {
  flex: 1;
  min-height: var(--tap);
  border: 0;
  border-right: 1px solid var(--border-strong);
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--accent); color: #fff; }
.segmented.status button.active[data-value="Open"] { background: var(--open); }
.segmented.status button.active[data-value="Closed"] { background: var(--closed); }
.segmented.large button { min-height: 56px; font-size: 17px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.toolbar .segmented { flex: 1; }
.toolbar select { width: auto; min-width: 128px; }

/* ---------- Photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.photo-tile { position: relative; aspect-ratio: 1 / 1; border-radius: 8px; overflow: hidden; background: #e9edf1; border: 1px solid var(--border); padding: 0; cursor: pointer; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .tag {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(21, 127, 61, 0.92); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.04em;
}
.photo-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-buttons .btn { flex: 1; }
.btn.photo { min-height: 64px; font-size: 17px; border-style: dashed; border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- Banner ---------- */
.banner {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  background: #fff8e6; border: 1px solid #f3d48a; color: #6b4d00;
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}
.banner.info { background: var(--accent-soft); border-color: #b9cfe4; color: var(--accent); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 31, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 520px;
  max-height: 92vh; overflow: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(18px + var(--safe-bottom));
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 14px; padding-bottom: 18px; }
}
.modal h2 { margin: 0 0 8px; font-size: 19px; }
.modal p { margin: 0 0 12px; color: var(--text-muted); white-space: pre-line; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.modal .choice { display: flex; flex-direction: column; gap: 8px; }
.modal .choice label {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius); font-weight: 600; cursor: pointer;
}
.modal .choice input { width: 20px; height: 20px; accent-color: var(--accent); }
.modal .confirm-input { margin-top: 4px; }
.photo-viewer img { width: 100%; height: auto; border-radius: 8px; display: block; background: #e9edf1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  z-index: 200;
  background: #1a2129; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 15px; font-weight: 500;
  max-width: calc(100% - 32px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

/* ---------- Loading overlay ---------- */
.loading { position: fixed; inset: 0; z-index: 300; background: rgba(255,255,255,0.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-weight: 600; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Photo mark-up editor (full screen) ---------- */
.markup {
  position: fixed; inset: 0; z-index: 90;      /* below dialogs (100) so "Discard?" shows on top */
  background: #111; color: #fff;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}
.markup-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; }
.markup-title { font-weight: 650; font-size: 16px; }
.markup-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.markup-stage canvas {
  display: block; border-radius: 4px;
  touch-action: none;                           /* drawing must not scroll or zoom the page */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.markup-tools {
  background: #1c1c1e; padding: 12px 16px calc(12px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.markup-row { display: flex; align-items: center; gap: 10px; }
.markup .segmented { background: #2c2c2e; border-color: #48484a; }
.markup .segmented button { color: #d1d1d6; border-right-color: #48484a; }
.markup .segmented button.active { background: var(--accent); color: #fff; }
.markup .btn.dark { background: #2c2c2e; border-color: #48484a; color: #fff; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #48484a; padding: 0; cursor: pointer; flex: none; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.markup-hint { font-size: 13px; color: #a1a1a6; text-align: center; }

/* Settings logo preview */
.logo-preview { max-width: 220px; max-height: 80px; display: block; margin: 8px 0; border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: #fff; }

.danger-zone { margin-top: 28px; }
.mt { margin-top: 12px; }
.stack > * + * { margin-top: 10px; }

@media (min-width: 700px) {
  .page { padding-top: 24px; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
