:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ea;
  --text: #1c241d;
  --muted: #5d6a5f;
  --border: #dde3d8;
  --accent: #2f6b3c;
  --accent-text: #ffffff;
  --accent-soft: #dcefd8;
  --client: #2f6b3c;
  --client-soft: #dcefd8;
  --prospect: #8a5a00;
  --prospect-soft: #fbecc8;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 4px 16px rgba(20, 30, 20, .06);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121612;
    --surface: #1b211c;
    --surface-2: #232b24;
    --text: #e8ede6;
    --muted: #9aa79c;
    --border: #2e382f;
    --accent: #7cc48a;
    --accent-text: #0f1a11;
    --accent-soft: #24402a;
    --client: #8fd39c;
    --client-soft: #24402a;
    --prospect: #f0c46a;
    --prospect-soft: #3d3218;
    --danger: #ff8a80;
    --danger-soft: #3d1f1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--border);
}
.topbar-row { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; }

.search-row { display: flex; gap: 8px; padding-bottom: 10px; }
.search {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 0 12px; height: 44px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 100%; font-size: 16px; }
.sort {
  height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); padding: 0 8px; font-size: 15px;
}

.chips { display: flex; gap: 8px; padding-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 500;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .count { opacity: .7; margin-left: 4px; }

/* ---------- Demo banner ---------- */
.demo-banner {
  background: var(--prospect-soft); color: var(--prospect);
  font-size: 13px; text-align: center; padding: 6px 16px;
}

/* ---------- Contact list ---------- */
.list { padding: 8px 0 calc(110px + var(--safe-bottom)); }
.letter {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted);
  padding: 14px 4px 6px; text-transform: uppercase;
}
.card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.card:active { background: var(--surface-2); }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 15px;
}
.avatar.lg { width: 72px; height: 72px; font-size: 24px; }
.card-main { flex: 1; min-width: 0; }
.card-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-call {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); text-decoration: none;
}
.card-call svg { width: 20px; height: 20px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px; text-transform: uppercase; vertical-align: middle;
}
.badge.client { background: var(--client-soft); color: var(--client); }
.badge.prospect { background: var(--prospect-soft); color: var(--prospect); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

.fab {
  position: fixed; z-index: 20;
  right: max(16px, calc((100vw - 640px) / 2 + 16px));
  bottom: calc(20px + var(--safe-bottom));
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.fab svg { width: 22px; height: 22px; }

/* ---------- Detail ---------- */
.detail-head { text-align: center; padding: 20px 0 8px; }
.detail-head h2 { margin: 12px 0 2px; font-size: 1.4rem; }
.detail-head .sub { color: var(--muted); }
.detail-head .badge { margin-top: 8px; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--accent); text-decoration: none;
  font-size: 13px; font-weight: 600;
}
.action svg { width: 22px; height: 22px; }
.action[aria-disabled="true"] { opacity: .35; pointer-events: none; }

.fields { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.field-row { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.field-row:last-child { border-bottom: 0; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.field-value { word-break: break-word; white-space: pre-wrap; }
.field-value a { text-decoration: none; }

.meta { color: var(--muted); font-size: 13px; text-align: center; margin: 16px 0; }

.btn-row { display: flex; gap: 10px; margin: 16px 0 calc(32px + var(--safe-bottom)); }
.btn {
  flex: 1; height: 48px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; }

/* ---------- Form ---------- */
form.contact-form { padding: 12px 0 0; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.form-group .req { color: var(--danger); }
.input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea.input { min-height: 110px; resize: vertical; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  margin: 0; height: 40px; display: grid; place-items: center;
  border-radius: 9px; font-weight: 600; color: var(--muted);
}
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); }

.warn {
  background: var(--prospect-soft); color: var(--prospect);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px;
}
.warn a { color: inherit; font-weight: 700; }
.error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px;
}
.link-btn {
  border: 0; background: transparent; color: var(--accent); font-weight: 600;
  padding: 10px 0; display: inline-flex; align-items: center; gap: 6px;
}
.link-btn svg { width: 18px; height: 18px; }

/* ---------- Sign in ---------- */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.signin-card { width: 100%; max-width: 400px; text-align: center; }
.signin-card img { width: 72px; height: 72px; }
.signin-card h1 { margin: 12px 0 4px; font-size: 1.5rem; }
.signin-card p { color: var(--muted); margin: 0 0 20px; }
.signin-card form { text-align: left; }
.signin-card .btn { width: 100%; flex: none; }
.code-input { letter-spacing: .4em; text-align: center; font-size: 22px; font-variant-numeric: tabular-nums; }

/* ---------- Toast & loading ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + var(--safe-bottom)); z-index: 50;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.loading { text-align: center; color: var(--muted); padding: 64px 16px; }
