/* ---------- Design tokens ----------
   System font stack on purpose: no web font to fetch or cache,
   so text renders instantly even on first offline load. */
:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-sunken: #ECEEF1;
  --border: #DADFE3;
  --text: #1C2430;
  --text-secondary: #5B6472;
  --text-muted: #8A919C;
  --accent: #2F6F5E;
  --accent-dark: #234F42;
  --accent-contrast: #FFFFFF;
  --danger: #B3261E;
  --danger-bg: #FBECEB;
  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, no matter what display value another
   rule sets for the same element (this is what broke the camera view). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 76px; /* space for bottom nav */
  min-height: 100dvh;
}

h1, h2, h3 { font-weight: 600; margin: 0 0 4px; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; color: var(--text-secondary); }

p { margin: 0 0 8px; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Layout shell ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px var(--gap);
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .back-btn {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-size: 16px;
  padding: 4px 8px 4px 0;
  cursor: pointer;
}

.view { display: none; padding: var(--gap); max-width: 640px; margin: 0 auto; }
.view.active { display: block; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 10;
}

.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0 8px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  cursor: pointer;
}

.bottom-nav button.active { color: var(--accent-dark); font-weight: 600; }
.bottom-nav .nav-dot {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.bottom-nav button.active .nav-dot { background: var(--accent); color: var(--accent-contrast); }

/* ---------- Cards / lists ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.list-item:active { background: var(--surface-sunken); }

.list-item .title { font-weight: 600; font-size: 16px; }
.list-item .meta { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.status-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 100px;
  margin-top: 6px;
}
.status-pill.draft { background: var(--surface-sunken); color: var(--text-secondary); }
.status-pill.complete { background: #E4F0EC; color: var(--accent-dark); }
.status-pill.sent { background: #E4F0EC; color: var(--accent-dark); margin-left: 6px; }
.status-pill.failed { background: var(--danger-bg); color: var(--danger); margin-left: 6px; }

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

input[type="text"], input[type="email"], input[type="date"], select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

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

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.choice-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.choice-group input { position: absolute; opacity: 0; width: 0; height: 0; }
.choice-group input:checked + span {}
.choice-group label:has(input:checked) {
  border-color: var(--accent);
  background: #E4F0EC;
  color: var(--accent-dark);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); width: 100%; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--surface-sunken); color: var(--text); width: 100%; }
.btn-text { background: none; color: var(--accent-dark); padding: 8px 4px; }
.btn-danger-text { background: none; color: var(--danger); padding: 8px 4px; }
.btn-fab {
  position: fixed;
  right: 20px;
  bottom: 92px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 26px;
  border: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
  cursor: pointer;
  z-index: 9;
}

.btn-row { display: flex; gap: 10px; margin-top: 20px; }
.btn-row .btn { flex: 1; }

/* ---------- Stepper (visit form sections) ---------- */
.step-rail {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
}
.step-rail .rung {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-sunken);
}
.step-rail .rung.done { background: var(--accent); }
.step-rail .rung.current { background: var(--accent-dark); }

.step-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

/* ---------- Chip list (profile account managers) ---------- */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.chip-list:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-sunken);
  border-radius: 100px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.chip button {
  background: none;
  border: none;
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.am-add-row {
  display: flex;
  gap: 8px;
}
.am-add-row input { flex: 1; }
.am-add-row .btn { width: auto; padding: 11px 16px; }

/* ---------- Photos ---------- */
.photo-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.photo-grid:empty { display: none; }

.photo-thumb {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Camera view (full-bleed, overrides .view padding) ---------- */
#view-camera {
  padding: 0;
  max-width: none;
  margin: 0;
}
#camera-video, #camera-preview-img {
  width: 100%;
  max-height: 65vh;
  object-fit: contain;
  background: #000;
  display: block;
}
.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px var(--gap);
  gap: 12px;
}
.shutter-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 4px solid var(--surface);
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--border);
  flex-shrink: 0;
}
.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  white-space: nowrap;
}

/* ---------- Voice capture ---------- */
.voice-wrap { position: relative; }
.voice-wrap textarea { padding-right: 46px; }

.mic-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-sunken);
  color: var(--text-secondary);
  cursor: pointer;
}

.mic-btn[data-state="recording"] {
  background: var(--danger);
  color: #fff;
  animation: mic-pulse 1.4s ease-in-out infinite;
}

.mic-btn[data-state="transcribing"] {
  background: var(--accent);
  color: #fff;
  opacity: 0.85;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(179, 38, 30, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .mic-btn[data-state="recording"] { animation: none; }
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
