:root {
  --brand: #B0312A;
  --brand-dark: #8A241F;
  --brand-soft: #F8E8E7;
  --ink: #1a1a1a;
  --muted: #666;
  --line: #ddd;
  --bg: #f4f4f5;
  --card: #fff;
  --ok: #1b7a3d;
  --warn: #b35c00;
  --danger: #9b1c1c;
  --radius: 12px;
  --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;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  padding-bottom: calc(88px + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.app-header .row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header img.logo {
  height: 40px;
  width: auto;
  background: #fff;
  border-radius: 8px;
  padding: 3px 6px;
}
.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.app-header .sub {
  font-size: .7rem;
  opacity: .92;
  margin-top: 2px;
}
.status-pills {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.pill {
  font-size: .68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
}
.pill.online { background: #1b7a3d; }
.pill.offline { background: #5a5a5a; }
.pill.saved { background: rgba(255,255,255,.25); }

.wrap { max-width: 720px; margin: 0 auto; padding: 12px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border: 1px solid #eee;
}
.card h2 {
  margin: 0 0 10px;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #fff;
  background: var(--brand);
  padding: 7px 10px;
  border-radius: 8px;
}
.card h3 {
  margin: 12px 0 6px;
  font-size: .8rem;
  color: var(--brand-dark);
  text-transform: uppercase;
  letter-spacing: .03em;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 520px) {
  .grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}
label.field.full { grid-column: 1 / -1; }
input[type="text"],
input[type="tel"],
input[type="email"],
input[type="date"],
input[type="number"],
select,
textarea {
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(176,49,42,.15);
}

.chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (min-width: 480px) {
  .chip-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
  .chip-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

.chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  border: 2px solid var(--brand);
  border-radius: 10px;
  background: var(--brand-soft);
  font-weight: 700;
  font-size: .88rem;
  color: var(--brand-dark);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}
.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip .box {
  width: 20px;
  height: 20px;
  border: 2px solid var(--brand-dark);
  border-radius: 4px;
  background: #fff;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.chip .box::after {
  content: "";
  width: 10px;
  height: 10px;
  background: transparent;
  border-radius: 2px;
}
.chip:has(input:checked),
.chip.checked {
  background: var(--brand);
  color: #fff;
}
.chip:has(input:checked) .box,
.chip.checked .box {
  background: #fff;
  border-color: #fff;
}
.chip:has(input:checked) .box::after,
.chip.checked .box::after {
  background: var(--brand);
}
.chip .sub {
  display: block;
  font-size: .68rem;
  font-weight: 500;
  opacity: .85;
}
.chip.small {
  font-size: .78rem;
  padding: 10px 8px;
  min-height: 42px;
  background: #fff;
  border-width: 1.5px;
  border-color: #ccc;
  color: var(--ink);
  font-weight: 600;
}
.chip.small:has(input:checked),
.chip.small.checked {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
}
.chip.small:has(input:checked) .box::after,
.chip.small.checked .box::after {
  background: var(--brand);
}

.hint {
  font-size: .75rem;
  color: var(--muted);
  background: #faf6f0;
  border-left: 3px solid var(--brand);
  padding: 8px 10px;
  margin: 8px 0 4px;
  border-radius: 0 8px 8px 0;
}
.hint strong { color: var(--brand-dark); }

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.photo-slot {
  border: 2px dashed #ccc;
  border-radius: 12px;
  background: #fafafa;
  overflow: hidden;
  position: relative;
  min-height: 140px;
}
.photo-slot.has-photo {
  border-style: solid;
  border-color: var(--brand);
}
.photo-slot .slot-label {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  text-transform: uppercase;
}
.photo-slot img.preview {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}
.photo-slot .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px;
  background: #fff;
}
.photo-slot .actions label,
.photo-slot .actions button {
  flex: 1 1 calc(50% - 6px);
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  padding: 10px 6px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  text-align: center;
  box-sizing: border-box;
}
.photo-slot .actions .clear-btn {
  flex: 1 1 100%;
}
.photo-slot .capture-btn {
  background: var(--brand);
  color: #fff;
}
.photo-slot .gallery-btn {
  background: #2c5f8a;
  color: #fff;
}
.photo-slot .clear-btn {
  background: #eee;
  color: var(--ink);
}
.photo-slot input[type="file"] { display: none; }
.photo-slot .empty {
  display: grid;
  place-items: center;
  height: 140px;
  color: var(--muted);
  font-size: .78rem;
  text-align: center;
  padding: 12px;
}

.gate-banner {
  display: none;
  background: #fff3cd;
  border: 1px solid #f0c36d;
  color: #6b4a00;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: .85rem;
}
.gate-banner.show { display: block; }
.gate-banner ul { margin: 6px 0 0; padding-left: 18px; }

.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: #fff;
  border-top: 1px solid #e5e5e5;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  gap: 6px;
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.bottom-bar button {
  flex: 1;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  padding: 12px 6px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-save { background: var(--brand); color: #fff; }
.btn-export { background: #222; color: #fff; }
.btn-print { background: #eee; color: #222; }
.btn-new { background: #fff; color: var(--brand); border: 1.5px solid var(--brand) !important; }
.btn-done { background: var(--ok); color: #fff; }

.survey-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.survey-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 10px;
  cursor: pointer;
}
.survey-item .meta { font-size: .78rem; color: var(--muted); }
.survey-item .title { font-weight: 700; font-size: .92rem; }
.survey-item .badge {
  font-size: .65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.survey-item .badge.done { background: #d4edda; color: var(--ok); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: .25s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 70;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff;
  width: 100%;
  max-width: 520px;
  border-radius: 16px 16px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  max-height: 85vh;
  overflow: auto;
}
.modal h3 { margin: 0 0 8px; color: var(--brand); }
.modal .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.modal .actions button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}
.modal .btn-cancel { background: #eee; }
.modal .btn-confirm { background: var(--brand); color: #fff; }

.bid-box {
  background: #f8f8f8;
  border: 1px dashed #ccc;
  border-radius: 10px;
  padding: 10px;
  font-size: .85rem;
}
.bid-box li { margin-bottom: 4px; }
.bid-box .note { color: var(--muted); font-size: .75rem; margin-top: 6px; }

.screens { display: none; }
.screens.active { display: block; }

.footer-brand {
  text-align: center;
  font-size: .7rem;
  color: var(--muted);
  padding: 8px 12px 20px;
}

/* Print / export HTML */
@media print {
  .app-header, .bottom-bar, .toast, .modal-backdrop, .no-print { display: none !important; }
  body { padding: 0; background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}


/* Install tip banner */
.install-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #1a1a1a;
  color: #fff;
  padding: 10px 14px;
  font-size: .82rem;
  line-height: 1.35;
}
.install-banner strong { color: #ffd7d4; }
.install-dismiss {
  border: none;
  background: rgba(255,255,255,.15);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

/* Email status panel */
.email-status {
  display: none;
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  font-size: .82rem;
}
.email-status.show { display: block; }
.email-status .detail { margin-top: 4px; color: var(--muted); font-size: .78rem; word-break: break-word; }
.email-status.ok { background: #e8f6ec; border-color: #b7e0c2; }
.email-status.fail { background: #fdeaea; border-color: #f0b4b4; }
.email-status.queued { background: #fff6e5; border-color: #f0d9a8; }
.email-status.sending { background: #eef3ff; border-color: #c5d2f5; }
.email-status.warn { background: #fff6e5; border-color: #f0d9a8; }
.email-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.email-actions button {
  flex: 1 1 30%;
  min-width: 100px;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: .78rem;
  cursor: pointer;
}
.btn-email { background: var(--brand); color: #fff; }
.btn-mailto { background: #2b4c7e; color: #fff; }
.btn-dl { background: #222; color: #fff; }

code {
  font-size: .85em;
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 4px;
}

/* Fill checklist from photos */
.fill-from-photos {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--brand-soft);
  border: 1px solid #e6c8c5;
}
.btn-fill-photos {
  width: 100%;
  padding: 14px 12px;
  border: 1.5px dashed var(--brand);
  border-radius: 10px;
  background: #fff;
  color: var(--brand-dark);
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: none;
}
.btn-fill-photos:active { background: var(--brand-soft); }
.btn-fill-photos:disabled {
  opacity: .65;
  cursor: wait;
}
.fill-hint {
  margin: 8px 0 0;
  font-size: .76rem;
  color: var(--muted);
  font-weight: 500;
}
.fill-summary {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e8d0ce;
  font-size: .82rem;
  color: var(--ink);
  white-space: pre-wrap;
}
.fill-summary.ok { border-color: #9ccc9c; background: #f3faf3; }
.fill-summary.warn { border-color: #e0c08a; background: #fff8ee; }
.fill-summary.fail { border-color: #e0a0a0; background: #fff5f5; }
.fill-summary .fill-title {
  font-weight: 800;
  color: var(--brand-dark);
  margin-bottom: 4px;
}
.fill-summary ul {
  margin: 6px 0 0;
  padding-left: 1.1rem;
}
.fill-summary li { margin: 2px 0; }
.chip.needs-confirm,
label.field.needs-confirm input,
label.field.needs-confirm {
  outline: 2px solid var(--warn);
  outline-offset: 1px;
}
.chip.needs-confirm {
  box-shadow: 0 0 0 2px rgba(179,92,0,.25);
  background: #fff8ee;
}
.chip.needs-confirm::after {
  content: "confirm";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: .55rem;
  font-weight: 800;
  color: var(--warn);
  text-transform: uppercase;
}
.chip { position: relative; }

/* Production polish */
.lede {
  font-size: .85rem;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.45;
}
.empty-state {
  text-align: center;
  padding: 22px 14px;
  border: 1.5px dashed #e0c8c6;
  border-radius: 12px;
  background: #faf7f6;
  color: var(--muted);
}
.empty-state-icon {
  font-size: 1.6rem;
  margin-bottom: 6px;
}
.empty-state strong {
  display: block;
  color: var(--brand-dark);
  font-size: .95rem;
  margin-bottom: 4px;
}
.empty-state p {
  margin: 0;
  font-size: .82rem;
  line-height: 1.4;
}
.btn-install {
  border: none;
  background: #fff;
  color: var(--brand-dark);
  font-weight: 800;
  font-size: .78rem;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.install-banner .install-banner-text {
  flex: 1;
  min-width: 0;
}
