/* Rx Inspect PWA — phone-first styles. Designed for iOS Safari + Android Chrome.
   No framework. Big touch targets (44pt min). Sky-blue palette to match Rx Doc Studio. */

:root {
  --bg: #e6f0fa;
  --surface: #ffffff;
  --surface-alt: #f4f8fc;
  --border: #d0dce8;
  --navy: #0b3a66;
  --navy2: #1f4e79;
  --blue: #2f6fa3;
  --text: #15263a;
  --text2: #5b6b80;
  --success: #1e8e3e;
  --success-bg: #d6ead9;
  --danger: #c0392b;
  --danger-bg: #f8d4d0;
  --warn: #c98b1b;
  --warn-bg: #fdecc8;
  --na: #d8dde2;
  --na-bg: #ecedf0;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(11, 58, 102, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* iOS safe area insets */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

input, textarea, select, button {
  font-family: inherit;
  font-size: 16px;  /* iOS won't auto-zoom at 16px+ */
}

#app { width: 100%; height: 100vh; height: 100dvh; }

.view {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: absolute;
  inset: 0;
  background: var(--bg);
}

.view[hidden] { display: none !important; }

/* ============================================================
   APP BAR (top of every screen)
   ============================================================ */

.app-bar {
  background: var(--navy);
  color: #fff;
  padding-top: var(--safe-top);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

.app-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px;
  min-height: 44px;
}

.app-bar-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: transparent;
  color: #fff;
  border: none;
  font-size: 28px;
  width: 56px;
  height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: rgba(255,255,255,0.3);
  touch-action: manipulation;
  position: relative;
  z-index: 10;
  user-select: none;
}

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

.icon-btn.placeholder { visibility: hidden; }

.meta-row {
  display: flex;
  gap: 8px;
  padding: 0 12px 10px;
}
.meta-row input {
  flex: 1;
  background: rgba(255,255,255,0.92);
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}
.meta-row input[type="date"] { flex: 0 0 auto; min-width: 130px; }

.progress-row {
  padding: 6px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.18);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #6fb3f0;
  width: 0%;
  transition: width 0.3s ease;
}
.progress-label {
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.3px;
}

/* ============================================================
   ONBOARDING
   ============================================================ */

.onboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 40px);
}
.brand { text-align: center; margin-bottom: 32px; }
.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: var(--navy);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.brand-name {
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: -0.5px;
}
.brand-tag {
  font-size: 14px;
  color: var(--text2);
  margin-top: 4px;
}
.onboard-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.onboard-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--navy);
}
.onboard-card p {
  margin: 0 0 16px;
  color: var(--text2);
  font-size: 14px;
}
.onboard-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  margin-bottom: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.onboard-err {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px !important;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.btn-primary {
  background: var(--navy);
  color: #fff;
}
.btn-primary:active { background: var(--navy2); }
.btn-secondary {
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--border);
}
.btn-secondary:active { background: var(--surface-alt); }
.btn-secondary.danger { color: var(--danger); border-color: var(--danger-bg); }

.btn-link {
  background: none;
  border: none;
  color: var(--blue);
  padding: 12px;
  font-size: 15px;
  cursor: pointer;
}

.btn-primary.big { padding: 18px 16px; font-size: 17px; }

/* ============================================================
   DASHBOARD
   ============================================================ */

.dashboard {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.section-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
  transition: transform 0.1s ease;
}
.section-card:active { transform: scale(0.985); }

.section-info { flex: 1; min-width: 0; }
.section-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 4px;
}
.section-stats {
  font-size: 13px;
  color: var(--text2);
}

.section-dot {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-left: 12px;
  background: var(--na);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
}
.section-dot.complete-clean { background: var(--success); }
.section-dot.complete-issues { background: var(--danger); }
.section-dot.in-progress { background: var(--warn); }

.section-count-pill {
  display: inline-block;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  margin-left: 6px;
}

/* ============================================================
   ACTION BAR (bottom — sync button)
   ============================================================ */

.action-bar {
  background: var(--surface);
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.action-bar.two-col {
  display: flex;
  gap: 10px;
}
.action-bar.two-col > * { flex: 1; }

#syncBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}
.sync-label { font-size: 17px; }
.sync-sub { font-size: 12px; opacity: 0.85; font-weight: 400; }
#syncBtn[disabled] {
  background: var(--text2);
  cursor: not-allowed;
}

/* ============================================================
   QUESTION VIEW
   ============================================================ */

.question {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 24px;
  -webkit-overflow-scrolling: touch;
}

.question-text {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 18px;
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.4;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.answer-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.answer-row .ans {
  border: none;
  border-radius: 12px;
  padding: 18px 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  min-height: 56px;
}
.ans.yes { background: var(--success-bg); color: var(--success); }
.ans.no  { background: var(--danger-bg);  color: var(--danger); }
.ans.partial, .ans.unsure { background: var(--warn-bg); color: var(--warn); }
.ans.na  { background: var(--na-bg); color: var(--text2); grid-column: 1 / -1; }
.ans.selected {
  outline: 3px solid var(--navy);
  outline-offset: -3px;
}

.finding-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.finding-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#findingBox {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  resize: vertical;
  min-height: 110px;
}

.photo-row { margin-top: 12px; }
.photo-btn {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
}
.photo-icon { font-size: 20px; }

.photo-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-alt);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb .remove-x {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.info-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
.info-panel h3 {
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.info-panel h3:first-child { margin-top: 0; }
.info-panel p { margin: 0; font-size: 14px; }
.info-panel ul { margin: 4px 0 0; padding-left: 20px; font-size: 14px; }
.info-panel a { color: var(--blue); text-decoration: none; }

/* ============================================================
   SYNC + DONE
   ============================================================ */

.sync-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 40px);
}
.sync-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 24px;
}
.sync-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.sync-prompt {
  margin: 0 0 16px;
  color: var(--text2);
  font-size: 14px;
}
.sync-field { display:flex; flex-direction:column; gap:6px; margin-bottom:14px; text-align:left; }
.sync-field > span { font-size:11px; color:var(--text2); font-weight:600; text-transform:uppercase; letter-spacing:0.6px; }
.sync-field input { width:100%; border:1px solid var(--border); border-radius:10px; padding:13px 12px; font-size:16px; background:var(--surface); color:var(--text); }
.sync-field input:focus { outline:none; border-color:var(--navy); box-shadow:0 0 0 3px rgba(11,58,102,0.12); }

#pairingInput {
  width: 100%;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 8px;
  margin-bottom: 12px;
}
.sync-status {
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  color: var(--text2);
  min-height: 18px;
}
.sync-status.error { color: var(--danger); }
.sync-status.success { color: var(--success); }

.done-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  text-align: center;
}
.done-check {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}
.done-screen h1 {
  color: var(--navy);
  margin: 0 0 12px;
  font-size: 28px;
}
.done-screen p {
  color: var(--text2);
  margin: 0 0 32px;
  max-width: 320px;
}
.done-screen button {
  max-width: 320px;
  margin-bottom: 10px;
}

/* ============================================================
   SETTINGS
   ============================================================ */

.settings { flex: 1; overflow-y: auto; padding: 16px; }
.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.setting input, .setting select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  color: var(--text);
}
.setting-info {
  text-align: center;
  color: var(--text2);
  font-size: 12px;
  margin-top: 24px;
}
#wipeBtn { margin-top: 24px; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11,38,58,0.94);
  color: #fff;
  padding: 12px 18px;
  border-radius: 22px;
  font-size: 14px;
  z-index: 1000;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
