/* Swaye Solar and Electrical — site survey form
   Phone-first wizard: navy / white / solar accent */

:root {
  --navy: #0a2540;
  --navy-mid: #123456;
  --navy-soft: #1a4468;
  --solar: #f0a202;
  --solar-soft: #fce7b2;
  --white: #ffffff;
  --off-white: #f5f7fa;
  --border: #d0d7e2;
  --text: #122033;
  --muted: #5a6a7e;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --success: #067647;
  --success-bg: #ecfdf3;
  --radius: 14px;
  --touch: 52px;
  --shadow: 0 2px 10px rgba(10, 37, 64, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 60px;
  --banner-h: 36px;
  --nav-h: 86px;
  --wizard-h: 72px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--off-white);
  padding-bottom: calc(var(--wizard-h) + 28px + var(--safe-bottom));
  overscroll-behavior-y: none;
  overscroll-behavior: none;
}

/* Header */
.site-header {
  position: sticky;
  top: var(--banner-h);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--header-h);
  padding: 8px 14px;
  background: var(--navy);
  color: var(--white);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--solar), #ffc94a);
  color: var(--navy);
  font-size: 20px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tagline {
  margin: 0;
  font-size: 12px;
  color: rgba(255,255,255,0.72);
}

.job-badge {
  flex-shrink: 0;
  text-align: right;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 88px;
}

.job-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.65);
}

.job-value {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--solar);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Progress */
.progress-nav {
  position: sticky;
  top: calc(var(--header-h) + var(--banner-h));
  z-index: 30;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 8px;
  box-shadow: var(--shadow);
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--solar), #ffc94a);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.step-dots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.step-dots::-webkit-scrollbar { display: none; }

.dot {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--white);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dot.active {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--white);
}

.dot.done {
  border-color: var(--solar);
  background: var(--solar-soft);
  color: var(--navy);
}

.step-label {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

/* Main form */
.form-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px 24px;
}

.form-section {
  display: none;
  animation: fadeIn 0.2s ease;
}

.form-section.is-active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.form-section h2 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--navy);
}

.section-intro {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--muted);
}

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
}

.field.required > span::after,
.choice-group.required > legend .req,
.field-label.required::after {
  content: " *";
  color: var(--danger);
}


.optional-tag {
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.req { color: var(--danger); font-weight: 700; }

.field input[type="text"],
.field input[type="tel"],
.field input[type="email"],
.field input[type="number"],
.field input[type="date"],
.field input[type="url"],
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%235a6a7e' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--navy-soft);
  box-shadow: 0 0 0 3px rgba(26, 68, 104, 0.15);
}

.field input.is-invalid,
.field select.is-invalid,
.field textarea.is-invalid,
.choice-group.is-invalid .yn-row {
  border-color: var(--danger);
}

.field input.is-invalid,
.field select.is-invalid,
.field textarea.is-invalid {
  background: var(--danger-bg);
}

.helper {
  font-size: 12px;
  color: var(--muted);
}

.uppercase { text-transform: uppercase; }

/* Choice / Yes-No */
.choice-group {
  margin: 0 0 16px;
  padding: 0;
  border: none;
}

.choice-group > legend {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 8px;
  padding: 0;
}

.yn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.yn-btn {
  position: relative;
  flex: 1 1 calc(50% - 4px);
  min-width: 120px;
  cursor: pointer;
}

.yn-btn input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.yn-btn > span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 10px 12px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.yn-btn input:checked + span {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--white);
}

.yn-btn input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(26, 68, 104, 0.25);
}

.yn-btn.yn-wide { flex: 1 1 100%; }

.yn-btn.yn-third { flex: 1 1 calc(33.33% - 6px); min-width: 90px; }

/* Cards / panels */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--navy);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-header h3 { margin: 0; }

.sub-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.sub-block > h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--navy-soft);
}

.hidden { display: none !important; }

/* Photo controls — per field */
.photo-control {
  margin-top: 8px;
  padding: 10px;
  background: var(--off-white);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.photo-control-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.photo-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-photo {
  flex: 1 1 140px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--navy);
  background: var(--white);
  border: 1.5px solid var(--navy);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-photo.secondary {
  border-color: var(--border);
  color: var(--text);
}

.btn-photo:active { transform: scale(0.98); }

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.photo-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #ddd;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb .remove-photo {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(10, 37, 64, 0.85);
  color: white;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.photo-empty {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 0;
}

/* Dim / row helpers */
.dim-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.dim-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

@media (max-width: 380px) {
  .dim-row-3 { grid-template-columns: 1fr 1fr; }
}

/* Roof cards */
.roof-card {
  border: 2px solid var(--navy-soft);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  background: var(--white);
}

.roof-card .roof-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.roof-card .roof-title h3 {
  margin: 0;
  font-size: 17px;
  color: var(--navy);
}

.btn-text {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  min-height: 44px;
  font-family: inherit;
}

.btn-add {
  width: 100%;
  min-height: var(--touch);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  color: var(--navy);
  background: var(--solar-soft);
  border: 2px dashed var(--solar);
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-add:active { background: #f9d98a; }

/* Sticky wizard bar */
.wizard-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: var(--white);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(10, 37, 64, 0.1);
}

.wizard-bar .btn {
  flex: 1;
  min-height: var(--touch);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-back {
  background: var(--off-white);
  color: var(--navy);
  border: 1.5px solid var(--border) !important;
}

.btn-next {
  background: var(--navy);
  color: var(--white);
}

.btn-next:active { background: var(--navy-mid); }

.btn-back:disabled,
.btn-next:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Review / submit */
.review-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.review-box h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--navy);
}

.missing-list {
  margin: 0;
  padding-left: 18px;
  color: var(--danger);
  font-size: 14px;
}

.missing-list:empty::after,
.missing-ok {
  color: var(--success);
  font-weight: 600;
  list-style: none;
  padding: 0;
  margin: 0;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  min-height: var(--touch);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: none;
  padding: 12px 16px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--solar);
  color: var(--navy);
}

.btn-primary:active { filter: brightness(0.95); }

.btn-secondary {
  background: var(--white);
  color: var(--navy);
  border: 2px solid var(--navy);
}

.status-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--wizard-h) + 16px + var(--safe-bottom));
  z-index: 80;
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  display: none;
  box-shadow: 0 8px 24px rgba(10, 37, 64, 0.18);
  pointer-events: none;
}

.status-toast.show { display: block; }
body.mode-saved .status-toast {
  bottom: calc(16px + var(--safe-bottom));
}
.status-toast.ok { background: var(--success-bg); color: var(--success); }
.status-toast.err { background: var(--danger-bg); color: var(--danger); }

.inline-error {
  font-size: 13px;
  color: var(--danger);
  margin: 4px 0 0;
  display: none;
}

.inline-error.show { display: block; }

.section-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  display: none;
}

.section-error.show { display: block; }

/* Checkboxes for elevations etc */
.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-btn {
  position: relative;
  flex: 1 1 calc(50% - 4px);
  min-width: 110px;
  cursor: pointer;
}

.check-btn input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.check-btn > span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 600;
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.check-btn input:checked + span {
  border-color: var(--navy);
  background: var(--navy);
  color: var(--white);
}

.prefill-note {
  font-size: 13px;
  color: var(--muted);
  background: var(--solar-soft);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

@media (min-width: 480px) {
  .brand h1 { font-size: 16px; }
  .form-wrap { padding: 20px 18px 32px; }
}


/* National Grid MPAN callout */
.ng-callout {
  margin: 14px 0 8px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #eef5ff 0%, #fff8e8 100%);
  border: 2px solid var(--navy-soft);
  box-shadow: 0 2px 10px rgba(10, 37, 64, 0.08);
}
.ng-callout-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}
.ng-callout-title a {
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ng-callout-title a:hover { color: var(--solar); }
.ng-steps {
  margin: 0 0 8px;
  padding-left: 1.25rem;
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
}
.ng-steps li { margin-bottom: 4px; }
.ng-warn {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--danger);
}
.choice-group.is-invalid {
  outline: 2px solid var(--danger);
  outline-offset: 4px;
  border-radius: 10px;
}
.photo-control.is-invalid {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
  border-radius: 10px;
}
.status-toast.info {
  background: #eef5ff;
  color: var(--navy);
}

/* ---- PWA / offline ---- */
.connectivity-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--banner-h);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.35;
}
.connectivity-banner.online {
  background: #ecfdf3;
  color: var(--success);
  border-bottom: 1px solid #abefc6;
}
.connectivity-banner.offline {
  background: #fff7ed;
  color: #9a3412;
  border-bottom: 1px solid #fdba74;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-install {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.45);
  background: var(--solar);
  color: var(--navy);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-install:active { filter: brightness(0.95); }
.btn-install.hidden { display: none; }

.ng-offline-note {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}
.ng-offline-note.hidden { display: none; }

.mpan-offline-warn {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fffbeb;
  border: 1px solid #f59e0b;
  color: #92400e;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}
.mpan-offline-warn.hidden { display: none; }

#mpanReqStar.soft-optional {
  color: #b45309;
}
#mpanReqStar.soft-optional::after {
  content: " (optional offline)";
  font-weight: 600;
  font-size: 12px;
  color: #b45309;
}

.install-box .install-steps {
  margin: 0 0 10px;
  padding-left: 1.2rem;
  font-size: 14px;
  color: var(--text);
}
.install-box .install-steps li { margin-bottom: 4px; }

.email-queue-box #btnRetryEmails:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}


.app-version {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #0a2540;
  background: #e8f0fe;
  vertical-align: middle;
}


/* ---- Mode tabs (Survey form / Saved surveys) ---- */
.mode-tabs {
  position: sticky;
  top: calc(var(--banner-h) + var(--header-h));
  z-index: 35;
  display: flex;
  gap: 0;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
}
.mode-tab {
  appearance: none;
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  padding: 12px 8px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.mode-tab.active {
  color: var(--navy);
  border-bottom-color: var(--solar);
}
.mode-tab:active { background: var(--off-white); }

body.mode-saved .progress-nav,
body.mode-saved .form-wrap,
body.mode-saved .wizard-bar {
  display: none !important;
}
body.mode-saved {
  padding-bottom: calc(28px + var(--safe-bottom));
}

.saved-surveys-view {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 14px 40px;
}
.saved-surveys-view.hidden { display: none; }
.saved-surveys-view h2 {
  margin: 0 0 6px;
  color: var(--navy);
  font-size: 1.35rem;
}
.saved-empty {
  margin: 28px 0;
  padding: 20px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--white);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.45;
}
.saved-empty.hidden { display: none; }

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.saved-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.saved-card-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
}
.saved-card-meta {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}
.saved-card-meta strong { color: var(--text); font-weight: 600; }
.saved-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.saved-card-actions .btn-saved {
  appearance: none;
  border: 1.5px solid var(--navy);
  background: var(--white);
  color: var(--navy);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
}
.saved-card-actions .btn-saved.primary {
  background: var(--navy);
  color: var(--white);
}
.saved-card-actions .btn-saved.danger {
  border-color: var(--danger);
  color: var(--danger);
}
.saved-card-actions .btn-saved:active { filter: brightness(0.96); }

.form-wrap, .progress-nav, .wizard-bar, .saved-surveys-view {
  overscroll-behavior-y: none;
  overscroll-behavior: none;
}
