/* ===================== THEME TOKENS ===================== */
:root {
  --brand: #AD1D28;
  --brand-hover: #8A151F;
  --brand-light: #fbe9ea;

  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e3e6ec;
  --text: #1f2430;
  --text-muted: #667085;
  --text-faint: #98a2b3;

  --success: #17a34a;
  --warn: #d97706;
  --danger: #dc2626;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1c1f28;
  --surface-alt: #22252f;
  --border: #313543;
  --text: #eef0f4;
  --text-muted: #a3a9b8;
  --text-faint: #6b7280;
  --brand-light: #3a1418;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

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

html {
  scroll-behavior: smooth;
  --sticky-offset: 150px; /* JS measures the real topbar+toolbar height and overrides this */
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* safety net: nothing should ever force horizontal scroll on the page */
}

body.no-scroll { overflow: hidden; height: 100%; }

section[data-section] { scroll-margin-top: calc(var(--sticky-offset) + 16px); }

button, .tbtn, .icon-btn, .chip, .switch, a {
  touch-action: manipulation; /* removes the ~300ms tap delay and stops double-tap zoom on repeated taps (e.g. counters) */
}

/* ===================== TOP BAR ===================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow-md);
}

.topbar-brand, .topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0; /* lets brand-title truncate instead of pushing the bar wider than the screen */
}

.brand-title { min-width: 0; }
.brand-title h1 { min-width: 0; }
.brand-title-text, .brand-subtitle {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.brand-logo {
  height: 38px;
  border-radius: 4px;
  background: #fff;
  padding: 2px;
  flex-shrink: 0; /* keep aspect ratio intact under a squeeze instead of getting distorted */
}

.brand-logo--round { border-radius: 50%; object-fit: cover; }

.led-logo { background: transparent; padding: 0; height: 32px; }

.brand-title h1 {
  font-size: 19px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  letter-spacing: -.01em;
}

.brand-subtitle {
  font-size: 12px;
  opacity: .85;
  font-weight: 500;
}

.icon-btn {
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background .2s;
}

.icon-btn:hover, .icon-btn:active { background: rgba(255, 255, 255, .3); }

.only-mobile { display: none; }

/* ===================== TOOLBAR ===================== */
.toolbar {
  position: sticky;
  top: 62px;
  z-index: 35;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  box-shadow: var(--shadow-sm);
}

.toolbar-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.toolbar-row--main { justify-content: space-between; }
.toolbar-row--status { margin-top: 8px; justify-content: space-between; }

.location-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--brand);
  font-weight: 600;
}

.location-picker select {
  min-width: 220px;
}

.toolbar-btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tbtn-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  font-family: var(--font);
}

.tbtn:hover, .tbtn:active { background: var(--border); }
.tbtn:hover { transform: translateY(-1px); }
.tbtn:disabled { opacity: .4; cursor: not-allowed; }
.tbtn:disabled:hover { background: var(--surface-alt); transform: none; }
.tbtn--sm { padding: 6px 10px; font-size: 12.5px; min-height: 40px; }
.tbtn--block { width: 100%; justify-content: center; }
.tbtn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.tbtn--primary:hover, .tbtn--primary:active { background: var(--brand-hover); }
.tbtn--danger { color: var(--danger); }
.tbtn--danger:hover, .tbtn--danger:active { background: #fdeaea; border-color: #f3b9b9; }
:root[data-theme="dark"] .tbtn--danger:hover, :root[data-theme="dark"] .tbtn--danger:active { background: #3a1a1a; border-color: #5c2626; }

.save-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--success);
  font-weight: 600;
}
.save-status.unsaved { color: var(--warn); }
.save-status.error { color: var(--danger); }

.progress-wrap { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.progress-track {
  width: 160px;
  height: 8px;
  border-radius: 8px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), #e0555f);
  border-radius: 8px;
  transition: width .35s ease;
}
.progress-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

/* ===================== SHELL LAYOUT ===================== */
.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  max-width: 1300px;
  margin: 0 auto;
  gap: 24px;
  padding: 24px 20px 80px;
  align-items: start;
}

.sidenav {
  position: sticky;
  top: calc(var(--sticky-offset) + 8px);
  max-height: calc(100vh - var(--sticky-offset) - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overview-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.overview-title { font-weight: 700; font-size: 13px; margin-bottom: 10px; color: var(--text); }
.mini-label { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 700; margin: 10px 0 6px; }

.status-select { width: 100%; }

.star-rating { display: flex; gap: 2px; }
.star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--border);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.star.active { color: #f5a623; }

.section-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.section-list li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  transition: background .15s, color .15s;
}

.section-list li a:hover { background: var(--surface-alt); color: var(--text); }
.section-list li a.active { background: var(--brand-light); color: var(--brand); }

.section-list .snum {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.section-list li a.active .snum { background: var(--brand); color: #fff; }
.section-list li a.complete .snum { background: var(--success); color: #fff; }
.section-list li a.complete .snum::before { content: "\f00c"; font-family: "Font Awesome 6 Free"; font-weight: 900; }

.section-list .sname { flex: 1; }
.section-list .sfrac { font-size: 11px; color: var(--text-faint); font-weight: 700; }

.sidenav-footer { border-top: 1px solid var(--border); padding-top: 12px; }
.sidenav-backdrop { display: none; }

/* ===================== FORM CARDS ===================== */
.content { min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 26px 28px;
  margin-bottom: 22px;
}

.card h2 {
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  color: var(--text);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.card h2 i { color: var(--brand); }

.sec-num {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--brand-light);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
}

.grid { display: grid; gap: 18px; margin-bottom: 4px; }
.grid-2 { grid-template-columns: 1fr 1fr; }

.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }

label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 7px; color: var(--text); }
.group-label { font-weight: 700; margin-bottom: 10px; }

input[type="text"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 11px 13px;
  /* 16px minimum stops iOS Safari from auto-zooming the page on focus */
  font-size: 16px;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}

textarea { resize: vertical; min-height: 44px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23667085' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
}

/* Field + inline action button (geolocation / compass) */
.input-with-btn { display: flex; gap: 8px; align-items: stretch; }
.input-with-btn input, .input-with-btn select { flex: 1; min-width: 0; }
.input-with-btn .tbtn--sm { flex-shrink: 0; padding: 0 14px; }

.mobile-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 7px;
  line-height: 1.4;
}
.mobile-hint a { color: var(--brand); font-weight: 700; text-decoration: none; }
.mobile-hint a:hover { text-decoration: underline; }

/* Toggle switches */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  gap: 12px;
  margin-bottom: 0;
}
.switch-row--field {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.switch-row span:first-child { font-weight: 600; font-size: 13.5px; }

.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 34px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 19px; width: 19px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(19px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px var(--brand-light); }

/* Counters */
.counter { display: inline-flex; align-items: center; gap: 0; border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.counter input[type="number"] {
  width: 56px; padding: 11px 4px; text-align: center; border: none; border-left: 1.5px solid var(--border); border-right: 1.5px solid var(--border);
  border-radius: 0; -moz-appearance: textfield;
}
.counter input[type="number"]::-webkit-outer-spin-button, .counter input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.counter-btn {
  background: var(--surface-alt); border: none; color: var(--brand); width: 44px; height: 44px; cursor: pointer; font-size: 13px; transition: background .15s; flex-shrink: 0;
}
.counter-btn:hover, .counter-btn:active { background: var(--brand-light); }

/* Chips (checkbox groups) */
.chip-group { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px; border: 1.5px solid var(--border);
  border-radius: 30px; cursor: pointer; font-size: 13.5px; font-weight: 600; background: var(--surface-alt); transition: all .15s;
}
.chip input { accent-color: var(--brand); width: 16px; height: 16px; cursor: pointer; }
.chip:has(input:checked) { background: var(--brand-light); border-color: var(--brand); color: var(--brand); }

/* Photo docs */
.doc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.doc-card { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; }
.photo-tools { margin-top: 10px; }
.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-thumb { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); margin: 6px 6px 0 0; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .rm {
  position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border: 2px solid var(--surface); border-radius: 50%; width: 26px; height: 26px;
  font-size: 11px; cursor: pointer; line-height: 1;
}

/* ===================== BOTTOM ACTIONS ===================== */
.bottom-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 10px 0 30px; }

/* ===================== MODAL ===================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 17, 22, .55); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 380px; width: 100%;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal p { margin: 0 0 14px; color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.modal-input-wrap { display: none; margin-bottom: 16px; }
.modal-input-wrap.open { display: block; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ===================== TOASTS ===================== */
.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  padding: 12px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 600;
  min-width: 220px; animation: toastIn .25s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===================== RESPONSIVE ===================== */
/* Tablets in portrait get the width back once the sidebar becomes a drawer,
   so photo docs and location logos get a real 2-up layout instead of stacking full-width. */
@media (min-width: 560px) and (max-width: 980px) {
  .doc-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .only-mobile { display: flex; }
  .sidenav {
    position: fixed; top: 0; left: 0; z-index: 90;
    height: 100vh; max-height: 100vh; /* fallback for browsers without dvh support */
    height: 100dvh; max-height: 100dvh; /* real visible height, ignores the address-bar show/hide jump on iOS/Android */
    width: min(280px, 85vw);
    transform: translateX(-100%); transition: transform .25s ease; border-radius: 0;
  }
  .sidenav.open { transform: translateX(0); }
  .sidenav-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 80; }
  .sidenav-backdrop.open { display: block; }
}

/* Narrow phones only — tablets keep the 2-up doc-grid from the rule above */
@media (max-width: 559px) {
  .doc-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .brand-subtitle { display: none; }
  .brand-title h1 { font-size: 15px; }
  .brand-logo { height: 30px; }
  .toolbar { top: 58px; padding: 10px 14px; }
  .toolbar-row--main { flex-direction: column; align-items: stretch; }
  .location-picker select { flex: 1; min-width: 0; }
  .toolbar-btns { gap: 6px; }
  .toolbar-btns span { display: none; }
  .toolbar-btns .tbtn { padding: 10px; min-width: 40px; min-height: 40px; justify-content: center; }
  .toolbar-row--status { flex-direction: column; align-items: stretch; gap: 8px; }
  .progress-wrap { width: 100%; }
  .progress-track { flex: 1; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 20px 16px; }
  .app-shell { padding: 16px 14px 60px; }
  .input-with-btn .tbtn--sm { min-width: 44px; padding: 0 12px; }
  .bottom-actions .tbtn { flex: 1 1 45%; justify-content: center; }
}

/* ===================== PRINT ===================== */
@media print {
  .topbar, .toolbar, .sidenav, .sidenav-backdrop, .bottom-actions, .toast-stack, .modal-backdrop, .photo-tools,
  .input-with-btn .tbtn, #btnNoiseMeter, .mobile-hint { display: none !important; }
  .app-shell { display: block; padding: 0; max-width: 100%; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 14px; }
  input, select, textarea { border: 1px solid #ccc !important; color: #000 !important; }
  .switch { display: none; }
  .switch-row::after { content: attr(data-print-state); font-weight: 700; }
}
