/* BC1 Inspections.
   Tokens mirror the claims and HR portals so the shell embed looks native.
   Brand accent #00B2BB. Light is the default because the primary user is on a
   phone in someone's living room or a basement, and light stays readable in
   daylight where the office dark theme washes out. */

/* Self-hosted Montserrat: one variable woff2 covers 400-700, so the app renders
   in its own face with no signal. font-display swap keeps first paint fast. */
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/fonts/montserrat-var.woff2') format('woff2');
}

:root[data-theme="light"] {
  color-scheme: light;
  --accent: #008b94;
  --accent-bright: #00B2BB;
  --accent-soft: rgba(0,139,148,0.12);

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --shadow: 0 1px 2px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);

  --text: #16181d;
  --text-dim: rgba(22,24,29,0.62);
  --text-faint: rgba(22,24,29,0.42);

  --input-bg: #ffffff;
  --input-border: rgba(0,0,0,0.18);

  --danger: #c72d20;
  --success: #15803d;
  --warn: #b45309;
  --info: #1d4ed8;
  --violet: #6d28d9;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #00B2BB;
  --accent-bright: #2dd4dd;
  --accent-soft: rgba(0,178,187,0.15);

  --bg: #0a0a0c;
  --surface: rgba(255,255,255,0.045);
  --surface-2: rgba(255,255,255,0.03);
  --border: rgba(255,255,255,0.12);
  --border-strong: rgba(255,255,255,0.22);
  --shadow: 0 8px 32px rgba(0,0,0,0.3);

  --text: #f5f5f7;
  --text-dim: rgba(245,245,247,0.65);
  --text-faint: rgba(245,245,247,0.40);

  --input-bg: rgba(255,255,255,0.05);
  --input-border: rgba(255,255,255,0.15);

  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --info: #60a5fa;
  --violet: #a78bfa;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Montserrat', system-ui, -apple-system, sans-serif;
  font-size: 16px; /* never below 16 on inputs, or iOS zooms on focus */
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font-family: inherit; font-size: 1rem; color: inherit; }
button { cursor: pointer; }

/* Topbar ------------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.5rem;
  padding: max(0.65rem, env(safe-area-inset-top)) 0.85rem 0.65rem;
  padding-top: calc(0.65rem + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }

.icon-btn {
  min-width: 44px; min-height: 44px;
  display: grid; place-items: center;
  background: none; border: none; color: var(--text-dim);
  font-size: 1.35rem; border-radius: 10px;
}
.icon-btn:active { background: var(--accent-soft); }
.back-btn { font-size: 2rem; line-height: 1; margin-left: -0.35rem; }

main {
  padding: 0.85rem 0.85rem calc(5.5rem + env(safe-area-inset-bottom));
  max-width: 46rem; margin-inline: auto;
}

/* Tabs and search --------------------------------------------------------- */

.tabs { display: flex; gap: 0.4rem; margin-bottom: 0.75rem; }
.tabs button {
  flex: 1; min-height: 44px;
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 10px;
  font-weight: 600; font-size: 0.9rem;
}
.tabs button[aria-selected="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.searchbar { position: relative; margin-bottom: 0.85rem; }
.searchbar input {
  width: 100%; min-height: 46px; padding: 0 2.5rem 0 0.9rem;
  background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: 10px;
}
.searchbar button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 38px; height: 38px; border: none; border-radius: 8px;
  background: none; color: var(--text-faint); font-size: 1.1rem;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent-bright); outline-offset: 1px;
}

/* Preview cards ----------------------------------------------------------- */

.card-list { display: flex; flex-direction: column; gap: 0.6rem; }

.card {
  display: flex; gap: 0.75rem; align-items: stretch;
  width: 100%; text-align: left;
  padding: 0.8rem; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card:active { border-color: var(--accent); }

/* Thumbnail slot. Reserved since session 2 so cards do not reflow once photos
   started appearing; img.thumb is the real one, div.thumb the placeholder. */
.card .thumb {
  flex: 0 0 62px; width: 62px; height: 62px; border-radius: 9px;
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--text-faint); font-size: 1.3rem;
}
.card div.thumb { border: 1px dashed var(--border); }
.card img.thumb { object-fit: cover; border: 1px solid var(--border); }
.card .body { flex: 1; min-width: 0; }
.card .row1 { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.15rem; }
.card .name {
  flex: 1; min-width: 0; font-weight: 700; font-size: 0.98rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .meta { font-size: 0.82rem; color: var(--text-dim); }
.card .concerns { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.25rem; }
.card .summary {
  margin-top: 0.3rem; font-size: 0.85rem; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge.s-draft         { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.badge.s-scheduled     { background: color-mix(in srgb, var(--info) 15%, transparent);   color: var(--info); }
.badge.s-on_site       { background: color-mix(in srgb, var(--warn) 18%, transparent);   color: var(--warn); }
.badge.s-in_analysis   { background: color-mix(in srgb, var(--violet) 16%, transparent); color: var(--violet); }
.badge.s-reports_ready { background: color-mix(in srgb, var(--success) 16%, transparent);color: var(--success); }
.badge.s-closed        { background: var(--accent-soft); color: var(--accent); }
.badge.s-archived      { background: var(--surface-2); color: var(--text-faint); border: 1px solid var(--border); }

.chip-sm {
  display: inline-block; padding: 0.1rem 0.45rem; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.7rem; font-weight: 600;
}

/* Forms ------------------------------------------------------------------- */

.section { margin-bottom: 1.1rem; }
.section > h2 {
  margin: 0 0 0.5rem; font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint);
}
.section-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}

.field { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field > label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text-dim); margin-bottom: 0.2rem;
}
.field input, .field select, .field textarea {
  width: 100%; min-height: 40px; padding: 0.4rem 0;
  background: none; border: none; border-radius: 0;
}
.field textarea { min-height: 68px; resize: vertical; padding-top: 0.3rem; }
.field select { min-height: 40px; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.15rem 0 0.35rem; }
.chip {
  min-height: 40px; padding: 0.35rem 0.75rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.85rem; font-weight: 600;
}
.chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* Buttons ----------------------------------------------------------------- */

.btn {
  min-height: 48px; padding: 0 1.15rem; border-radius: 11px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 600; font-size: 0.95rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.block   { width: 100%; }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.85rem; }

.fab {
  position: fixed; right: 1rem; z-index: 25;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  min-height: 56px; padding: 0 1.4rem; border-radius: 28px; border: none;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Detail ------------------------------------------------------------------ */

.detail-head {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.85rem; margin-bottom: 0.85rem;
}
.detail-head h2 { margin: 0.3rem 0 0.15rem; font-size: 1.15rem; }
.detail-head .sub { font-size: 0.85rem; color: var(--text-dim); }

.subtabs { display: flex; gap: 0.35rem; margin-bottom: 0.85rem; overflow-x: auto; }
.subtabs button {
  flex: 0 0 auto; min-height: 42px; padding: 0 0.9rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text-dim); font-weight: 600; font-size: 0.87rem;
}
.subtabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.subtabs button:disabled { opacity: 0.45; }

.reading {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border);
}
.reading:last-child { border-bottom: none; }
.reading .val { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.reading .who { flex: 1; min-width: 0; font-size: 0.82rem; color: var(--text-dim); }
.reading .del { min-width: 40px; min-height: 40px; border: none; background: none; color: var(--text-faint); font-size: 1.15rem; }

/* Feedback ---------------------------------------------------------------- */

.empty { padding: 3rem 1rem; text-align: center; color: var(--text-dim); }
.empty .big { font-size: 2.2rem; margin-bottom: 0.5rem; opacity: 0.5; }

.notice { padding: 0.7rem 0.9rem; border-radius: 10px; font-size: 0.88rem; margin-bottom: 0.85rem; }
.notice.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.notice.info  { background: var(--accent-soft); color: var(--accent); }

/* Save state for the autosaving detail form. */
.savestate {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(1.1rem + env(safe-area-inset-bottom));
  padding: 0.4rem 0.9rem; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 0.8rem; font-weight: 600;
  opacity: 0; transition: opacity 0.18s; pointer-events: none;
}
.savestate.show { opacity: 0.92; }
.savestate.error { background: var(--danger); color: #fff; }

.skeleton { height: 84px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 0.6rem; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .savestate { transition: none; }
}

/* iPad and desktop: the plan calls for both layouts to be first class. */
@media (min-width: 46rem) {
  .card-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.85rem; }
  .form-grid .section.full { grid-column: 1 / -1; }
}

/* Media gallery ----------------------------------------------------------- */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 0.5rem;
}
.media-grid .empty { grid-column: 1 / -1; }

.tile {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
}
.tile:active { border-color: var(--accent); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-placeholder { width: 100%; height: 100%; display: grid; place-items: center; font-size: 1.6rem; opacity: 0.45; }

.tile-badges {
  position: absolute; top: 4px; left: 4px; right: 4px;
  display: flex; flex-wrap: wrap; gap: 3px;
}
.tb {
  padding: 0.1rem 0.35rem; border-radius: 5px;
  background: rgba(0,0,0,0.62); color: #fff;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.02em;
}
.tb.ok   { background: rgba(21,128,61,0.9); }
.tb.warn { background: rgba(180,83,9,0.9); }
.tb.bad  { background: rgba(199,45,32,0.92); }

.tile-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0.3rem 0.4rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
  color: #fff; font-size: 0.68rem; text-align: left;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* Upload progress. Sequential uploads, so at most one bar is moving. */
.upload-progress:not(:empty) { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.uprow { font-size: 0.8rem; color: var(--text-dim); }
.uprow.failed { color: var(--danger); }
.track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 0.25rem; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }
.bar.failed { background: var(--danger); }

/* Tap-to-view sheet ------------------------------------------------------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.sheet {
  width: 100%; max-width: 34rem;
  max-height: 92vh; overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(0.85rem + env(safe-area-inset-bottom));
}
.sheet-media {
  width: 100%; max-height: 52vh; object-fit: contain;
  background: #000; display: block;
}
.sheet-body { padding: 0.85rem; }
.sheet-body > label {
  display: block; margin-top: 0.6rem; margin-bottom: 0.2rem;
  font-size: 0.75rem; font-weight: 600; color: var(--text-dim);
}
.sheet-body textarea, .sheet-body select {
  width: 100%; min-height: 44px; padding: 0.5rem 0.6rem;
  background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 9px;
}
.sheet-meta { font-size: 0.8rem; color: var(--text-faint); margin: 0.75rem 0 0; }

@media (min-width: 46rem) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; }
  .sheet-media { border-radius: 16px 16px 0 0; }
}

/* Sync pill (plan section 10: persistent sync indicator) -------------------- */

.syncpill {
  min-height: 34px; padding: 0.25rem 0.75rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-dim); font-size: 0.78rem; font-weight: 700;
  white-space: nowrap;
}
.syncpill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: transparent; }
.syncpill.bad  { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: transparent; }

/* Media sheet navigation ---------------------------------------------------
   The sheet browses the whole gallery: swipe on a phone, chevrons elsewhere. */

.sheet-stage {
  /* touch-action tells the browser we handle horizontal panning ourselves, so
     it stops trying to scroll the page sideways mid-swipe. */
  touch-action: pan-y;
  will-change: transform;
  background: #000;
  border-radius: 16px 16px 0 0;
  overflow: hidden;
}

.sheet-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; margin-bottom: 0.35rem;
}
.navbtn {
  min-width: 46px; min-height: 40px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text-dim);
  font-size: 1.4rem; line-height: 1;
}
.navbtn:disabled { opacity: 0.3; }
.navbtn:active:not(:disabled) { background: var(--accent-soft); color: var(--accent); }
.navcount { font-size: 0.8rem; font-weight: 600; color: var(--text-faint); }

@media (min-width: 46rem) {
  .sheet-stage { border-radius: 16px 16px 0 0; }
}
