/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #0066CC;
  --blue-dark: #004fa0;
  --green: #28a745;
  --red: #dc3545;
  --gray-light: #f4f5f7;
  --gray-mid: #d0d3d8;
  --gray-dark: #6c757d;
  --text: #1a1a1a;
  --sidebar-w: 240px;
  --header-h: calc(56px + env(safe-area-inset-top));
  --footer-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 8px;
  --touch: 44px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--gray-light);
  font-size: 16px;
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh; /* accounts for browser chrome on mobile/iPad */
  overflow: hidden;
}

/* ── Header ── */
#header {
  grid-column: 1 / -1;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  padding: env(safe-area-inset-top, 0) 16px 0;
  gap: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

#header h1 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
}

.header-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

#site-summary {
  font-size: 13px;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* Sync dot */
.sync-status {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sync-status.online  { background: #4caf50; }
.sync-status.offline { background: #f44336; }

#btn-settings {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  min-width: var(--touch);
  min-height: var(--touch);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Progress bar ── */
#progress-wrap {
  background: rgba(255,255,255,.2);
  height: 4px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}
#progress-bar-fill {
  height: 100%;
  background: #fff;
  transition: width .3s ease;
  width: 0%;
}

/* ── Sidebar ── */
#sidebar {
  background: #1e2a3a;
  color: #ccc;
  overflow-y: auto;
  border-right: 1px solid #111;
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  padding: 12px 14px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #88a0b8;
  border-bottom: 1px solid #2d3f52;
}

#progress-label {
  font-size: 11px;
  color: #88a0b8;
  padding: 6px 14px;
  border-bottom: 1px solid #2d3f52;
}

#section-nav {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #2a3a4e;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: #ccc;
  text-align: left;
  padding: 12px 14px;
  font-size: 13px;
  cursor: pointer;
  min-height: var(--touch);
  line-height: 1.3;
}
.nav-btn:hover { background: #2a3a4e; color: #fff; }

.nav-item.active .nav-btn { color: #fff; background: var(--blue); }
.nav-item.complete .nav-btn { color: #5cd85c; }
.nav-item.skipped { opacity: .45; }

.nav-badge {
  font-size: 11px;
  color: #88a0b8;
  padding-right: 10px;
  white-space: nowrap;
}

/* ── Main content ── */
#main {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}


#section-main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.section-heading {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: #1e2a3a;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ── Questions ── */
.question-wrapper {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  border-left: 4px solid transparent;
  transition: border-color .2s;
}

.question-wrapper.required {
  border-left-color: var(--blue);
}

.question-wrapper.hidden {
  display: none;
}

.question-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  line-height: 1.4;
}

/* ── Inputs ── */
.input-date,
.input-number,
.input-text,
.input-select {
  border: 1px solid var(--gray-mid);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 16px;
  min-height: var(--touch);
  width: 100%;
  max-width: 360px;
}

.input-date:focus,
.input-number:focus,
.input-text:focus,
.input-select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
  border-color: var(--blue);
}

.input-with-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 360px;
}

.input-with-hint .input-number {
  max-width: 160px;
}

.input-hint {
  font-size: 13px;
  color: var(--gray-dark);
}

/* ── Yes/No toggle ── */
.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-toggle {
  border: 2px solid var(--gray-mid);
  background: #fff;
  border-radius: var(--radius);
  padding: 8px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
  min-width: var(--touch);
  transition: all .15s;
}

.btn-toggle:hover { border-color: var(--blue); color: var(--blue); }
.btn-toggle.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ── Checkboxes ── */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  cursor: pointer;
  min-height: var(--touch);
  padding: 4px 0;
}

.checkbox-label input[type=checkbox] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

/* ── Options pending ── */
.options-pending {
  font-size: 12px;
  color: var(--gray-dark);
  font-style: italic;
  margin-bottom: 4px;
}

.input-other { margin-top: 6px; }

/* ── Photos ── */
.photo-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-photo {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
  align-self: flex-start;
}

.btn-photo:hover { background: var(--blue-dark); }

.photo-limit {
  font-size: 12px;
  color: var(--gray-dark);
}

.photo-thumbnails {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.photo-thumb {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gray-mid);
}

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

.btn-delete-photo {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Section skipped ── */
.section-skipped-msg {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 15px;
  color: #856404;
}

/* ── Footer nav ── */
#footer {
  grid-column: 1 / -1;
  background: #fff;
  border-top: 1px solid var(--gray-mid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
}

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: var(--radius);
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
}

.btn-primary   { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: var(--gray-light); color: var(--text); border: 1px solid var(--gray-mid); }
.btn-danger    { background: var(--red); color: #fff; }

.btn-submit {
  background: #28a745;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: var(--touch);
  white-space: nowrap;
}
.btn-submit:hover    { background: #218838; }
.btn-submit:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ── Settings overlay ── */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

#settings-overlay.hidden { display: none; }

.settings-panel {
  background: #fff;
  border-radius: 12px;
  width: min(480px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-mid);
}

.settings-header h2 { font-size: 18px; }

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: var(--touch);
  min-height: var(--touch);
}

.settings-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-body label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-dark);
  gap: 4px;
}

.settings-body input {
  border: 1px solid var(--gray-mid);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 15px;
  min-height: var(--touch);
}

.settings-body hr { border: none; border-top: 1px solid var(--gray-mid); }
.app-version { font-size: 12px; color: var(--gray-dark); }

.settings-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-mid);
  display: flex;
  justify-content: flex-end;
}

/* ── Submission history ── */
.submissions-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-dark);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.no-submissions {
  font-size: 13px;
  color: var(--gray-dark);
  font-style: italic;
}

.submission-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-mid);
}

.submission-item:last-child { border-bottom: none; }

.submission-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  min-width: 0;
}

.submission-info strong { font-size: 14px; }

.submission-info span { color: var(--gray-dark); }

.submission-date { font-size: 11px; }

.btn-load {
  flex-shrink: 0;
  padding: 6px 14px;
  font-size: 13px;
}

/* ── Store Info section ── */
.site-info-section {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.site-info-section .input-text,
.site-info-section .input-date,
.site-info-section .input-select {
  max-width: 480px;
  width: 100%;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Mobile (iPhone) — screens narrower than 768px ── */
@media (max-width: 767px) {

  :root {
    --sidebar-w: 100%;   /* sidebar takes full width when open */
    --header-h: calc(52px + env(safe-area-inset-top));
    --footer-h: 60px;
  }

  /* Stack layout: header / main / footer, no side-by-side columns */
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr var(--footer-h);
  }

  /* ── Header ── */
  #header h1 { font-size: 15px; }
  #site-summary { display: none; } /* too cramped on small screen */
  .header-logo { height: 24px; }

  #btn-menu {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    min-width: var(--touch);
    min-height: var(--touch);
    cursor: pointer;
    order: -1; /* put hamburger before the title */
  }

  /* ── Sidebar — hidden off-screen by default, slides in when open ── */
  #sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 85vw;
    max-width: 320px;
    height: calc(100dvh - var(--header-h));
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.3);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  /* Dim overlay behind open sidebar */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 49;
  }

  #sidebar-overlay.visible { display: block; }

  /* ── Main — full width ── */
  #main { grid-column: 1; }

  /* ── Site info bar — stack fields vertically ── */
  #site-info-bar { padding: 10px 12px; }

  #site-info-form {
    flex-direction: column;
    gap: 8px;
  }

  #site-info-form label { width: 100%; }

  #site-info-form input,
  #site-info-form select {
    width: 100%;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }

  /* ── Section main ── */
  #section-main { padding: 12px; }

  .section-heading { font-size: 16px; padding: 10px 12px; }

  /* ── Questions ── */
  .question-wrapper { padding: 12px; }
  .question-label { font-size: 13px; }

  .input-date,
  .input-number,
  .input-text,
  .input-select {
    max-width: 100%;
    font-size: 16px; /* prevents iOS auto-zoom */
  }

  /* ── Yes/No buttons — stretch full width ── */
  .btn-group { width: 100%; }
  .btn-toggle { flex: 1; text-align: center; }

  /* ── Photos ── */
  .photo-thumb { width: 90px; height: 90px; }

  /* ── Footer ── */
  #footer { padding: 0 12px; gap: 8px; }

  .btn-primary,
  .btn-secondary {
    padding: 10px 16px;
    font-size: 14px;
  }

  #footer-section-label { font-size: 11px; }

  /* ── Settings panel ── */
  .settings-panel {
    width: 95vw;
    max-height: 90vh;
  }
}
