/* ==========================================================================
   Site -- construction site management
   Mobile first. Big targets, high contrast, readable in sunlight and gloves.
   ========================================================================== */

:root {
  --ink:        #12171F;
  --ink-2:      #3C4657;
  --ink-3:      #6B7688;
  --line:       #DFE4EC;
  --line-2:     #EDF0F5;
  --bg:         #F4F6FA;
  --card:       #FFFFFF;

  --brand:      #1B3A5C;
  --brand-2:    #2C5F94;
  --accent:     #F5A524;
  --accent-ink: #4A3000;

  --ok:         #15803D;
  --ok-bg:      #E7F6EC;
  --warn:       #B45309;
  --warn-bg:    #FDF2E2;
  --bad:        #C0271F;
  --bad-bg:     #FCECEA;
  --info:       #1D4ED8;
  --info-bg:    #E8EEFD;

  --r:          14px;
  --r-sm:       9px;
  --shadow:     0 1px 2px rgba(18,23,31,.06), 0 4px 14px rgba(18,23,31,.07);
  --shadow-lg:  0 8px 40px rgba(18,23,31,.18);

  --tap:        50px;
  --safe-b:     env(safe-area-inset-bottom, 0px);
  --safe-t:     env(safe-area-inset-top, 0px);
  --nav-h:      calc(62px + var(--safe-b));

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #EEF1F6; --ink-2: #B4BDCC; --ink-3: #7F8A9C;
    --line: #2A3240; --line-2: #222935;
    --bg: #0E1219; --card: #171D27;
    --brand: #E8EEF7; --brand-2: #8FB4DC;
    --ok-bg: #10281A; --warn-bg: #2B1E0A; --bad-bg: #2C1412; --info-bg: #121D38;
    --ok: #4ADE80; --warn: #FBBF24; --bad: #F87171; --info: #93B4FF;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1,h2,h3,h4 { margin: 0; line-height: 1.25; letter-spacing: -0.015em; }
p { margin: 0 0 12px; }
a { color: var(--brand-2); }

/* ------------------------------------------------------------------ shell -- */

#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: var(--brand);
  color: #fff;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: #111722; color: var(--ink); border-bottom: 1px solid var(--line); }
}
.topbar h1 { font-size: 19px; font-weight: 650; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 12.5px; opacity: .72; font-weight: 500; margin-top: 1px; }
.topbar-btn {
  appearance: none; border: 0; background: rgba(255,255,255,.14);
  color: inherit; width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; flex: none; cursor: pointer;
}
.topbar-btn:active { background: rgba(255,255,255,.26); }
@media (prefers-color-scheme: dark) { .topbar-btn { background: rgba(255,255,255,.08); } }

main {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + 24px);
  max-width: 720px; width: 100%; margin: 0 auto;
}

/* --------------------------------------------------------------- bottom nav */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr);
  max-width: 720px; margin: 0 auto;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  backdrop-filter: saturate(180%) blur(12px);
}
.nav button {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 9px 2px 7px; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: 10.5px; font-weight: 600; font-family: inherit;
  letter-spacing: .01em;
}
.nav.n6 { grid-template-columns: repeat(6, 1fr); }
.nav.n6 button { font-size: 9.5px; letter-spacing: 0; padding-left: 0; padding-right: 0; }
.nav.n6 button svg { width: 21px; height: 21px; }
.nav button svg { width: 23px; height: 23px; }
.nav button[aria-current="page"] { color: var(--brand-2); }
@media (prefers-color-scheme: dark) { .nav button[aria-current="page"] { color: var(--accent); } }

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

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-h h3 { font-size: 15.5px; font-weight: 650; flex: 1; }

.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-3);
  margin: 22px 2px 9px;
}
.section-title:first-child { margin-top: 4px; }

.muted { color: var(--ink-3); font-size: 13.5px; }
.tiny  { font-size: 12px; color: var(--ink-3); }
.stack > * + * { margin-top: 10px; }

/* ------------------------------------------------------------------- list -- */

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line-2); }
.list li:last-child { border-bottom: 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; min-height: var(--tap);
  background: none; border: 0; font: inherit; color: inherit;
  text-align: left; cursor: pointer;
}
.row:active { background: var(--line-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chev { color: var(--ink-3); flex: none; }
.row-icon {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 17px;
  background: var(--line-2);
}

/* ------------------------------------------------------------------ pills -- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .01em;
  background: var(--line-2); color: var(--ink-2);
  white-space: nowrap;
}
.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad  { background: var(--bad-bg);  color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }

/* ---------------------------------------------------------------- buttons -- */

.btn {
  appearance: none; font: inherit; font-weight: 650;
  border-radius: var(--r-sm); border: 1px solid transparent;
  min-height: var(--tap); padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; width: 100%;
  background: var(--brand); color: #fff;
  transition: transform .06s ease;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn.ghost { background: none; color: var(--brand-2); }
.btn.sm { min-height: 38px; padding: 0 13px; font-size: 13.5px; width: auto; }
.btn-row { display: flex; gap: 9px; }
.btn-row .btn { flex: 1; }
@media (prefers-color-scheme: dark) {
  .btn { background: var(--accent); color: var(--accent-ink); }
  .btn.secondary { background: var(--card); color: var(--ink); }
}

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 14px); z-index: 45;
  width: 58px; height: 58px; border-radius: 19px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 6px 22px rgba(245,165,36,.42);
}
.fab:active { transform: scale(.94); }
.fab svg { width: 27px; height: 27px; }

/* ----------------------------------------------------------------- fields -- */

.field { margin-bottom: 15px; }
.field > label {
  display: block; font-size: 14px; font-weight: 620;
  margin-bottom: 6px; color: var(--ink);
}
.field .req { color: var(--bad); margin-left: 2px; }
.field .help { font-size: 12.5px; color: var(--ink-3); margin: -2px 0 7px; }

input[type=text], input[type=number], input[type=date], input[type=time],
input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 13px; min-height: var(--tap);
  appearance: none;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7688' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 38px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(44,95,148,.16);
}
.input-unit { position: relative; }
.input-unit .unit {
  position: absolute; right: 13px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: 14px; font-weight: 600; pointer-events: none;
}
.input-unit input { padding-right: 56px; }

/* -------------------------------------------------------- check / segments -- */

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg button {
  appearance: none; font: inherit; font-size: 14px; font-weight: 670;
  min-height: 48px; border-radius: var(--r-sm); cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink-2);
}
.seg button:active { transform: scale(.97); }
.seg button[aria-pressed="true"].v-pass    { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.seg button[aria-pressed="true"].v-defect  { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }
.seg button[aria-pressed="true"].v-na      { background: var(--line-2);  border-color: var(--ink-3); color: var(--ink-2); }
.seg button[aria-pressed="true"].v-yes     { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.seg button[aria-pressed="true"].v-no      { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }

.check-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line-2);
}
.check-row:last-child { border-bottom: 0; }
.check-row .cl { flex: 1; font-size: 14.5px; font-weight: 550; line-height: 1.35; }
.check-row .seg { grid-template-columns: repeat(3, 54px); gap: 6px; flex: none; }
.check-row .seg button { min-height: 42px; font-size: 12.5px; padding: 0; }

/* Long ITP wording: label on its own line, buttons full width underneath. */
.check-row.stacked { display: block; padding: 13px 0; }
.check-row.stacked .cl { margin-bottom: 10px; }
.check-row.stacked .seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.check-row.stacked .seg button { min-height: 46px; font-size: 14px; }

/* ----------------------------------------------------------------- photos -- */

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photo-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--line-2); border: 1px solid var(--line);
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .rm {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.62); color: #fff;
  display: grid; place-items: center; cursor: pointer; font-size: 15px; line-height: 1;
}
.photo-add {
  aspect-ratio: 1; border-radius: 10px; cursor: pointer;
  border: 1.5px dashed var(--line); background: var(--card); color: var(--ink-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; font-weight: 650;
}

/* -------------------------------------------------------------- signature -- */

.sigpad {
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--card); position: relative; touch-action: none;
}
.sigpad canvas { display: block; width: 100%; height: 168px; border-radius: var(--r-sm); }
.sigpad .hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-3); font-size: 13.5px; pointer-events: none;
}
.sigpad.signed .hint { display: none; }
.sig-list { display: flex; flex-direction: column; gap: 9px; }
.sig-chip {
  display: flex; align-items: center; gap: 11px;
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 11px;
  background: var(--card);
}
.sig-chip img { height: 34px; width: auto; max-width: 110px; object-fit: contain; }
.sig-chip .n { flex: 1; font-weight: 600; font-size: 14px; }

/* ------------------------------------------------------------------ sheet -- */

.sheet-bg {
  position: fixed; inset: 0; z-index: 90; background: rgba(10,14,20,.5);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 720px;
  border-radius: 20px 20px 0 0; max-height: 92vh;
  display: flex; flex-direction: column;
  animation: slideup .22s cubic-bezier(.32,.72,0,1);
  padding-bottom: var(--safe-b);
}
.sheet-h {
  padding: 16px 16px 12px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; flex: none;
  background: var(--card); border-radius: 20px 20px 0 0;
}
.sheet-h h2 { font-size: 17px; font-weight: 680; flex: 1; }
.sheet-body { overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--card); flex: none;
}
@keyframes slideup { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ------------------------------------------------------------------ misc --- */

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--r-sm); font-size: 13.5px;
  margin-bottom: 12px; line-height: 1.4;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad  { background: var(--bad-bg);  color: var(--bad); }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.ok   { background: var(--ok-bg);   color: var(--ok); }
.banner strong { font-weight: 700; }

.empty { text-align: center; padding: 44px 24px; color: var(--ink-3); }
.empty .ico { font-size: 40px; opacity: .35; margin-bottom: 10px; }
.empty h3 { font-size: 16px; color: var(--ink-2); margin-bottom: 5px; }
.empty p { font-size: 13.5px; margin: 0; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 9px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 12px 13px;
}
.stat .v { font-size: 25px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .k { font-size: 11.5px; color: var(--ink-3); font-weight: 600; margin-top: 3px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 16px); z-index: 100;
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 11px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
  animation: fade .15s ease;
}

.offline-bar {
  background: var(--warn-bg); color: var(--warn);
  font-size: 12.5px; font-weight: 650; text-align: center;
  padding: 7px 12px;
}

.divide { height: 1px; background: var(--line); margin: 16px 0; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-bar {
  display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.chip {
  appearance: none; font: inherit; font-size: 13px; font-weight: 620;
  padding: 8px 14px; border-radius: 999px; white-space: nowrap; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  flex: none;
}
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
}

.progress { height: 5px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand-2); border-radius: 99px; }

@media print {
  .nav, .topbar, .fab, .btn { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { break-inside: avoid; box-shadow: none; }
}


/* ==========================================================================
   Office console -- only ever seen on a wide screen
   ========================================================================== */

.office {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.office-side {
  width: 232px; flex: none;
  display: flex; flex-direction: column;
  background: var(--card);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh;
}

.office-nav-btn {
  appearance: none; border: 0; cursor: pointer; font: inherit;
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 11px 13px; border-radius: 9px;
  background: none; color: var(--ink-2);
  font-size: 14.5px; font-weight: 600; text-align: left;
}
.office-nav-btn:hover { background: var(--line-2); }
.office-nav-btn[aria-current="page"] {
  background: var(--brand); color: #fff;
}
@media (prefers-color-scheme: dark) {
  .office-nav-btn[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
}
.office-nav-btn svg { flex: none; }

.office .card { max-width: none; }
.office h1 { letter-spacing: -.02em; }

.office-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.office-table th {
  text-align: left; padding: 9px 12px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); border-bottom: 1.5px solid var(--line); white-space: nowrap;
}
.office-table td {
  padding: 11px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top;
}
.office-table tbody tr:last-child td { border-bottom: 0; }
.office-table tr.clickable { cursor: pointer; }
.office-table tr.clickable:hover { background: var(--line-2); }
.office-table .tiny { margin-top: 2px; }

/* The office console uses wider sheets than the phone does. */
@media (min-width: 1024px) {
  .sheet { max-width: 780px; border-radius: 18px; margin-bottom: 3vh; max-height: 90vh; }
  .sheet-bg { align-items: center; }
  .sheet-h { border-radius: 18px 18px 0 0; }
}
