/* Quick Contacts: iOS-flavoured styling, light + dark */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.22);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(118, 118, 128, 0.2);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --bar: rgba(249, 249, 249, 0.86);
  --avatar-a: #a5abb6;
  --avatar-b: #868c96;
  --radius: 12px;
  --tabbar-h: 50px;
  --topbar-h: 44px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.36);
    --blue: #0a84ff;
    --red: #ff453a;
    --green: #30d158;
    --bar: rgba(22, 22, 24, 0.86);
    --avatar-a: #6d717a;
    --avatar-b: #4d5159;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--label);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--blue); text-decoration: none; }
[hidden] { display: none !important; }
.vh { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; opacity: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: var(--sat) calc(8px + var(--sar)) 0 calc(8px + var(--sal));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
.topbar-inner { height: var(--topbar-h); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.nav-slot { display: flex; }
.nav-slot.right { justify-content: flex-end; }
.nav-btn {
  appearance: none; border: 0; background: none; color: var(--blue);
  min-height: 44px; min-width: 44px; padding: 0 8px; font-size: 17px;
  display: inline-flex; align-items: center; gap: 2px; cursor: pointer;
}
.nav-btn.bold { font-weight: 600; }
.nav-btn:disabled { opacity: .4; }
.nav-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Main ---------- */
main {
  padding: 12px calc(16px + var(--sar)) calc(var(--tabbar-h) + var(--sab) + 28px) calc(16px + var(--sal));
  max-width: 680px; margin: 0 auto; outline: none;
}
.large-title { font-size: 34px; font-weight: 700; letter-spacing: .01em; margin: 4px 4px 12px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 0 var(--sar) var(--sab) var(--sal);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.tabbar a {
  height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--label-2); font-size: 10px; font-weight: 500;
}
.tabbar a svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[data-tab="new"] svg { stroke-width: 2.4; }
.tabbar a.active { color: var(--blue); }

/* ---------- Cards / grouped lists ---------- */
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; margin: 0 0 22px; }
.card > * + * { border-top: 0.5px solid var(--sep); }
.section-label { font-size: 13px; text-transform: uppercase; color: var(--label-2); margin: 0 16px 7px; letter-spacing: .02em; }
.section-foot { font-size: 13px; color: var(--label-2); margin: -14px 16px 22px; line-height: 1.4; }

.field { display: flex; align-items: center; min-height: 48px; padding: 0 0 0 16px; }
.field > span { flex: 0 0 84px; color: var(--label); font-size: 15px; }
.field input, .field textarea {
  flex: 1; min-width: 0; border: 0; outline: none; background: transparent; padding: 12px 16px 12px 0;
  font-size: 17px; -webkit-appearance: none; appearance: none;
}
.field textarea { resize: none; min-height: 88px; line-height: 1.35; }
.field.top { align-items: flex-start; }
.field.top > span { padding-top: 13px; }
.field input::placeholder, .field textarea::placeholder { color: var(--label-3); }
.field.invalid > span { color: var(--red); }
.field.invalid input::placeholder { color: var(--red); opacity: .7; }

/* Other contact info rows */
.other-row { display: flex; align-items: center; min-height: 48px; padding-left: 10px; }
.other-row .minus {
  flex: 0 0 auto; width: 34px; height: 44px; border: 0; background: none; padding: 0; display: grid; place-items: center; cursor: pointer;
}
.other-row .minus i { width: 22px; height: 22px; border-radius: 50%; background: var(--red); position: relative; display: block; }
.other-row .minus i::after { content: ""; position: absolute; left: 5px; right: 5px; top: 10px; height: 2px; background: #fff; border-radius: 1px; }
.other-row input { border: 0; outline: none; background: transparent; padding: 12px 8px; font-size: 17px; min-width: 0; }
.other-row input.olabel { flex: 0 0 104px; color: var(--blue); font-size: 15px; border-right: 0.5px solid var(--sep); }
.other-row input.ovalue { flex: 1; padding-right: 16px; }
.add-row {
  width: 100%; border: 0; background: none; color: var(--blue); text-align: left; min-height: 48px; padding: 0 16px;
  display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 17px;
}
.add-row i { width: 22px; height: 22px; border-radius: 50%; background: var(--green); position: relative; display: block; flex: 0 0 auto; }
.add-row i::before, .add-row i::after { content: ""; position: absolute; background: #fff; border-radius: 1px; }
.add-row i::before { left: 5px; right: 5px; top: 10px; height: 2px; }
.add-row i::after { top: 5px; bottom: 5px; left: 10px; width: 2px; }
.quick-adds { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 12px; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  appearance: none; border: 0; border-radius: 999px; background: var(--fill); color: var(--label);
  min-height: 34px; padding: 6px 14px; font-size: 15px; white-space: nowrap; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"] { background: var(--blue); color: #fff; }
.chip.add { color: var(--blue); background: transparent; box-shadow: inset 0 0 0 1px var(--fill-2); }
.chip.small { min-height: 30px; font-size: 14px; padding: 4px 12px; }
.chip.static { cursor: default; }

/* ---------- Photo block ---------- */
.photo-block { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: 6px 0 22px; }
.avatar {
  --size: 44px;
  width: var(--size); height: var(--size); border-radius: 50%; flex: 0 0 auto; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: calc(var(--size) * .4);
  background: linear-gradient(180deg, var(--avatar-a), var(--avatar-b)); letter-spacing: .02em;
  position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.xl { --size: 128px; }
.avatar svg { width: 46%; height: 46%; fill: none; stroke: #fff; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.avatar.busy::after {
  content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.35) ;
}
.avatar.busy::before {
  content: ""; position: absolute; z-index: 1; width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill {
  appearance: none; border: 0; border-radius: 999px; background: var(--card); color: var(--blue);
  min-height: 40px; padding: 8px 16px; font-size: 15px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; user-select: none; -webkit-user-select: none;
}
.pill svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill.danger { color: var(--red); }
.pill:active, .chip:active, .btn:active, .add-row:active { opacity: .6; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 0; width: 100%; min-height: 50px; border-radius: var(--radius); cursor: pointer;
  background: var(--blue); color: #fff; font-size: 17px; font-weight: 600; padding: 0 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: .5; }
.btn.secondary { background: var(--card); color: var(--blue); font-weight: 500; }
.btn.danger { background: var(--card); color: var(--red); font-weight: 500; }
.btn + .btn { margin-top: 10px; }
.card .btn { border-radius: 0; margin: 0; background: transparent; color: var(--blue); font-weight: 400; justify-content: flex-start; }
.card .btn.danger { color: var(--red); }
.card .btn + .btn { margin-top: 0; }
.save-bar { margin: 4px 0 18px; }

/* ---------- People list ---------- */
.search {
  display: flex; align-items: center; gap: 6px; background: var(--fill); border-radius: 10px; height: 38px; padding: 0 10px; margin-bottom: 10px;
}
.search svg { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: var(--label-2); stroke-width: 2.2; stroke-linecap: round; }
.search input { flex: 1; border: 0; outline: none; background: transparent; font-size: 17px; min-width: 0; -webkit-appearance: none; appearance: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search .clear { border: 0; background: var(--label-3); color: var(--card); width: 18px; height: 18px; border-radius: 50%; font-size: 12px; line-height: 18px; padding: 0; cursor: pointer; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li a { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 16px; color: var(--label); }
.plist li a:active { background: var(--fill); }
.plist .avatar { --size: 46px; }
.plist .meta { flex: 1; min-width: 0; }
.plist .meta b { display: block; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plist .meta small { display: block; color: var(--label-2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.chev { width: 9px; height: 15px; flex: 0 0 auto; fill: none; stroke: var(--label-3); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.letter { font-size: 13px; font-weight: 600; color: var(--label-2); margin: 0 16px 6px; }
.count-line { font-size: 13px; color: var(--label-2); text-align: center; margin: 6px 0 18px; }
.group-tools { display: flex; justify-content: space-between; align-items: center; margin: -2px 4px 12px; font-size: 14px; color: var(--label-2); gap: 10px; }
.linkish.danger { color: var(--red); margin-top: -8px; }
.linkish { appearance: none; border: 0; background: none; color: var(--blue); font-size: 15px; padding: 8px 0; cursor: pointer; }

.empty { text-align: center; color: var(--label-2); padding: 44px 24px; }
.empty h2 { color: var(--label); font-size: 22px; margin: 0 0 6px; }
.empty p { margin: 0 0 22px; line-height: 1.4; }
.empty .btn { max-width: 320px; margin: 0 auto; }

/* Big "new person" call to action */
.hero-new {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 56px; border-radius: 14px; background: var(--blue); color: #fff; font-size: 18px; font-weight: 600; margin-bottom: 16px;
}
.hero-new svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.6; stroke-linecap: round; }

/* ---------- Detail ---------- */
.detail-hero { text-align: center; margin: 4px 0 18px; }
.detail-hero .avatar { --size: 132px; margin: 0 auto 12px; }
.detail-hero .avatar.has-photo { cursor: zoom-in; }
.detail-hero h2 { font-size: 28px; font-weight: 700; margin: 0; word-wrap: break-word; }
.detail-hero p { margin: 4px 0 0; color: var(--label-2); font-size: 16px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.act {
  background: var(--card); border-radius: var(--radius); min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--blue); font-size: 12px; font-weight: 500;
}
.act svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act.disabled { color: var(--label-3); pointer-events: none; }
.act:active { opacity: .6; }
.info { padding: 10px 16px; min-height: 48px; }
.info small { display: block; font-size: 14px; color: var(--label); margin-bottom: 2px; }
.info div, .info a { font-size: 17px; word-break: break-word; white-space: pre-wrap; }
.info a { color: var(--blue); }
.stamp { text-align: center; font-size: 12px; color: var(--label-3); margin-top: -8px; }

.photo-viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: grid; place-items: center; padding: var(--sat) 0 var(--sab); }
.photo-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Groups ---------- */
.inline-add { display: flex; gap: 8px; margin-bottom: 22px; }
.inline-add input {
  flex: 1; min-width: 0; height: 48px; border-radius: var(--radius); border: 0; outline: none; background: var(--card); padding: 0 14px; font-size: 17px;
}
.inline-add .btn { width: auto; min-width: 72px; min-height: 48px; }
.glist li { display: flex; align-items: center; min-height: 52px; }
.glist li a { flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 0 10px 16px; color: var(--label); min-width: 0; }
.glist li a span.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glist li a span.n { color: var(--label-2); }
.glist .more { border: 0; background: none; color: var(--blue); width: 52px; height: 52px; display: grid; place-items: center; cursor: pointer; }
.glist .more svg { width: 22px; height: 22px; fill: currentColor; }
.gdot { width: 30px; height: 30px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: 0 0 auto; }

/* ---------- Backup ---------- */
.stat { display: flex; justify-content: space-between; align-items: center; min-height: 46px; padding: 0 16px; gap: 12px; }
.stat span:last-child { color: var(--label-2); text-align: right; }
.stat .warn { color: var(--red) !important; }
.card label.btn { cursor: pointer; }
.select-row { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 16px; min-height: 48px; }
.select-row select { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 17px; height: 44px; outline: none; color: var(--label); }
.select-row .linkish { padding: 8px 8px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--sab) + 18px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 15px; font-weight: 500;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 40px); text-align: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dialog (iOS alert style) ---------- */
dialog#dlg {
  border: 0; padding: 0; border-radius: 14px; width: min(290px, calc(100vw - 48px)); color: var(--label);
  background: var(--bar); -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  box-shadow: 0 10px 40px rgba(0,0,0,.25); overflow: hidden;
}
@media (prefers-color-scheme: dark) { dialog#dlg { background: rgba(44, 44, 46, 0.96); } }
dialog#dlg::backdrop { background: rgba(0, 0, 0, 0.35); }
.dlg-body { padding: 19px 16px 16px; text-align: center; }
.dlg-body h3 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.dlg-body p { margin: 0; font-size: 13px; line-height: 1.38; color: var(--label); }
.dlg-body input {
  width: 100%; margin-top: 14px; height: 34px; border-radius: 7px; border: 0.5px solid var(--sep); background: var(--card); padding: 0 8px; font-size: 16px; outline: none;
}
.dlg-btns { display: flex; flex-direction: row-reverse; border-top: 0.5px solid var(--sep); }
.dlg-btns.stack { flex-direction: column; }
.dlg-btns button {
  flex: 1; appearance: none; border: 0; background: none; min-height: 44px; font-size: 17px; color: var(--blue); cursor: pointer; padding: 0 8px;
}
.dlg-btns:not(.stack) button + button { border-right: 0.5px solid var(--sep); }
.dlg-btns.stack button + button { border-top: 0.5px solid var(--sep); }
.dlg-btns button.primary { font-weight: 600; }
.dlg-btns button.danger { color: var(--red); }
.dlg-btns button:active { background: var(--fill); }

@media (min-width: 700px) { main { padding-top: 24px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
