:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #17201d;
  --muted: #5d6a66;
  --line: #d7dedb;
  --accent: #1d5c4b;
  --accent-text: #ffffff;
  --accent-soft: #e2efeb;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #2e7d32;
  --radius: 12px;
  --tabbar-h: 60px;
  /* Always light, even when the phone is in dark mode. */
  color-scheme: only light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; }
.event-label { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.offline-badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn-text); }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

h2 { font-size: 17px; margin: 28px 0 8px; }

.muted { color: var(--muted); }
.small, small { font-size: 13px; }
.center { text-align: center; }
.lead-in { margin-top: 0; }

/* Banners */
.banner {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  margin-bottom: 12px;
}
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.export-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--warn-bg); color: var(--warn-text); }
.export-banner.ok { background: var(--accent-soft); color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; margin-bottom: 16px; }
.btn.full { width: 100%; margin-top: 12px; }
.export-banner .btn { background: var(--surface); }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
}

.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1; }
.actions.column { flex-direction: column; }
.actions.sticky {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
  padding: 8px 0;
}

/* Forms */
.field { display: block; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend, .field > .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field small { font-weight: 400; color: var(--muted); }

input[type="text"], input[type="email"], input[type="tel"], input[type="url"],
input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming into inputs */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.row { display: flex; gap: 6px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.row select { flex: none; width: 112px; }

.two { display: flex; gap: 10px; }
.two > * { flex: 1; min-width: 0; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center;
  min-height: 46px; background: var(--surface); font-weight: 600; cursor: pointer;
  border-right: 1px solid var(--line);
}
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -3px; }

.more { margin: 0 0 14px; }
.more summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); padding: 8px 0; }
.more[open] summary { margin-bottom: 8px; }

.radio, .check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.radio input, .check input { width: 20px; height: 20px; accent-color: var(--accent); }

.warnings { list-style: none; padding: 0; margin: 0 0 8px; }
.warnings li { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); margin-bottom: 6px; font-size: 14px; }
.warnings li.block { background: var(--danger-soft); color: var(--danger); }

/* Lead list */
.search { margin-bottom: 12px; }
.lead-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lead-item {
  display: block;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
}
.lead-main { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lead-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.type-tag { flex: none; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); }
.not-exported { color: var(--warn-text); background: var(--warn-bg); padding: 0 6px; border-radius: 6px; flex: none; }
.exported { color: var(--ok); flex: none; }

/* Tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}

/* Capture buttons and list tools */
.actions.capture { margin-top: 0; }
.actions.capture .btn.big { margin-bottom: 16px; }
.list-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.list-tools select { flex: 1; min-width: 0; }
.list-tools .search { flex: 1; min-width: 0; margin: 0; }

/* Scanner */
.scanner {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  margin: 0 auto 12px;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute;
  inset: 18%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
}
.error { color: var(--danger); }
p.error { font-weight: 600; }

.raw {
  white-space: pre-wrap;
  word-break: break-all;
  font: 13px/1.4 ui-monospace, Menlo, monospace;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin: 0;
}

/* Events */
h2.first { margin-top: 0; }
.event-list { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 8px; }
.event-item {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.event-item.active { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.event-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.active-tag { font-size: 13px; font-weight: 700; color: var(--accent); padding: 0 6px; }
.event-form { padding: 12px 14px; border: 1px dashed var(--line); border-radius: var(--radius); }
.event-form .btn.full { margin-top: 0; }
.event-label { text-decoration: none; }

/* Capture tiles on the Leads screen */
.actions.capture { gap: 10px; }
.btn.tile { flex-direction: column; gap: 2px; min-height: 76px; margin-bottom: 10px; }
.tile-title { font-size: 18px; }
.tile-sub { font-size: 12.5px; font-weight: 500; opacity: 0.85; }
.btn.type-in { margin: 0 0 16px; }

/* Business card */
.segmented.small { margin-bottom: 14px; }
.segmented.small span { min-height: 38px; font-size: 14px; }
.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 10px; }
.steps li {
  counter-increment: step;
  position: relative;
  padding: 12px 12px 12px 50px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  line-height: 1.6;
}
.steps li::before {
  content: counter(step);
  position: absolute; left: 12px; top: 12px;
  width: 26px; height: 26px; border-radius: 99px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 700; font-size: 14px; line-height: 26px; text-align: center;
}
.steps small { display: block; color: var(--muted); line-height: 1.4; margin-top: 4px; }
/* A picture of the iPhone edit menu, so people know what to look for. */
.ios-menu {
  display: inline-flex; vertical-align: middle; margin: 2px 0;
  background: #2c2c2e; color: #fff; border-radius: 9px; overflow: hidden;
  font-size: 14px; font-weight: 500; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.ios-menu > span { padding: 5px 11px; display: inline-flex; align-items: center; gap: 5px; }
.ios-menu > span + span { border-left: 1px solid #48484a; }
.ios-scan { background: #0a84ff; }
.ios-scan svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.key {
  display: inline-block; padding: 0 8px; border-radius: 6px; line-height: 1.6;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
}
.card-box { margin-bottom: 8px; }
.card-box textarea { min-height: 170px; font-size: 15px; line-height: 1.4; }
.card-status { margin: 0 0 8px; padding: 8px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.card-status.ok { background: var(--accent-soft); color: var(--accent); }
.card-status.warn { background: var(--warn-bg); color: var(--warn-text); }
#view-card .actions { margin-top: 0; margin-bottom: 10px; }
#card-fill { margin-bottom: 10px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.attention { animation: attention 1.4s ease-in-out 3; }
@keyframes attention {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29, 92, 75, 0); }
  50% { box-shadow: 0 0 0 6px rgba(29, 92, 75, 0.25); }
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

[hidden] { display: none !important; }
