/* ==========================================================================
   Jade Eye — app shell stylesheet
   Reset · tokens · layout · bottom nav · shared primitives.

   OWNER: Package A.
   Package B styles its screens in src/styles/circle.css.
   Package C styles its screens in src/styles/card.css.
   Neither edits this file. Both may use every class defined here.
   ========================================================================== */

@import url('../public/fonts/fonts.css');

/* --------------------------------------------------------------------------
   Fallback token values. main.js re-applies these from theming/tokens.js, but
   defining them here means the app is never unstyled, even if JS is slow.
   -------------------------------------------------------------------------- */
:root {
  --jade: #00D4AA;
  --jade-light: #33E0BD;
  --jade-dark: #00775F;
  --ink: #0D1B2A;
  --color-primary: #00A67E;
  --color-primary-light: #33C4A0;
  --color-primary-dark: #00775F;
  --color-bg: #FAF9F6;
  --color-surface: #FFFFFF;
  --color-surface-2: #F2EFE9;
  --color-border: #E4E0D8;
  --color-text: #16242E;
  --color-text-2: #5C6B75;
  --color-text-3: #8B98A1;
  --color-accent: #FDCB6E;
  --color-success: #2FA37D;
  --color-warning: #E8A87C;
  --color-error: #D4726A;
  --tier-inner-circle: #00D4AA;
  --tier-circle: #4CC9F0;
  --tier-outer-circle: #F4A259;
  --tier-outside: #7A8B99;
  --bucket-overdue: #D4726A;
  --bucket-drifting: #F4A259;
  --bucket-watching: #4CC9F0;
  --bucket-quiet: #8B98A1;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 18px;
  --radius-sm: 10px;
  --radius-lg: 28px;
  --shadow: 0 2px 14px rgba(13, 27, 42, 0.07);
  --shadow-lg: 0 10px 36px rgba(13, 27, 42, 0.14);
  --transition: 180ms cubic-bezier(0.2, 0, 0, 1);
  --nav-height: 64px;
  --page-max: 520px;
  --gutter: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* --------------------------------------------------------------------------
   Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

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

body {
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.45;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

body.font-large  { font-size: 18px; }
body.font-xlarge { font-size: 20px; }
body.low-stim *  { animation: none !important; transition: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  /* The extra clearance (vs. the bare nav height) keeps the last bit of
     scrollable content — "See all N people", a commit button, etc. — from
     sitting under the quick-add-fab, which floats 16px above the nav at
     58px tall. */
  padding: calc(var(--safe-top) + 14px) var(--gutter) calc(var(--nav-height) + var(--safe-bottom) + 86px);
  animation: screen-in 220ms ease both;
}

@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Screen header — every screen uses this so the app reads as one thing */
.screen-head { margin-bottom: 20px; }
.screen-eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--jade-dark);
}
.screen-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.screen-sub { color: var(--color-text-2); font-size: 0.9rem; margin-top: 3px; }

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-3);
  margin: 24px 0 10px;
}

/* --------------------------------------------------------------------------
   Bottom navigation
   -------------------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--color-border);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-3);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--transition);
  position: relative;
  min-height: 44px;
}
.nav-item .material-symbols-rounded { font-size: 23px; }
.nav-item.active { color: var(--jade-dark); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 26px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--jade);
}
.nav-item:active { transform: scale(0.94); }

/* --------------------------------------------------------------------------
   Quick Add FAB — the one-tap "+ add someone", present on every screen.
   -------------------------------------------------------------------------- */
/*
 * Docked INSIDE the bottom nav's own footprint (a raised accent button on
 * the tab bar), not floating in the content zone above it. Screens with very
 * short content (Today, by design, is often just a headline + a "see all"
 * button — nowhere near a full page) end their last element wherever their
 * natural content height happens to land; padding-bottom on .screen cannot
 * reliably push that element clear of a FAB that floats above the nav, so
 * the FAB instead lives entirely within the nav's already-reserved height,
 * the one zone every screen already guarantees is content-free.
 */
.quick-add-fab {
  position: fixed;
  right: calc(var(--gutter) - 2px);
  bottom: calc(var(--safe-bottom) + 5px);
  z-index: 70; /* above .bottom-nav (60) so it is always reachable */
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--jade);
  color: #062018;
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition);
}
.quick-add-fab:active { transform: scale(0.92); }
.quick-add-fab .material-symbols-rounded { font-size: 26px; }

@media (min-width: 720px) {
  .quick-add-fab { right: calc(50% - (var(--page-max) / 2) + var(--gutter) - 2px); }
}

/* --------------------------------------------------------------------------
   Encrypted vault — the "Unlock my contacts" banner.
   Deliberately a small floating pill, not a screen. It sits just clear of
   the bottom nav and the FAB (see components/vault-unlock.js) so it is
   always reachable but never blocks Quick Add, vCard import, or anything
   else in the app. Only renders when this device has zero contacts AND an
   encrypted payload is actually deployed.
   -------------------------------------------------------------------------- */
.vault-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 10px);
  z-index: 65; /* above .bottom-nav (60), clear of the FAB (70) and any modal (200) */
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  min-height: 44px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition), opacity var(--transition);
}
.vault-banner .material-symbols-rounded { font-size: 19px; color: var(--jade); }
.vault-banner:active { transform: translateX(-50%) scale(0.96); }

.vault-error {
  color: var(--color-error);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: -4px 0 0;
}

/* --------------------------------------------------------------------------
   Shared primitives — B and C build with these
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-flush { padding: 0; overflow: hidden; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid transparent;
  transition: transform var(--transition), background var(--transition), opacity var(--transition);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn .material-symbols-rounded { font-size: 20px; }

.btn-primary { background: var(--jade); color: #062018; }
.btn-dark    { background: var(--ink); color: #fff; }
.btn-ghost   { background: transparent; border-color: var(--color-border); }
.btn-danger  { background: var(--color-error); color: #fff; }
.btn-block   { display: flex; width: 100%; }
/* 44px, not 36px. This is a one-handed phone app; `btn-sm` means smaller TYPE,
   not a smaller thumb target. Every secondary action on Me, Nearby and Import
   was a 36px-tall button before this. */
.btn-sm      { min-height: 44px; padding: 0 13px; font-size: 0.85rem; }
.btn-lg      { min-height: 54px; font-size: 1.02rem; padding: 0 24px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 0; min-width: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  color: var(--color-text-2);
  transition: background var(--transition);
}
.icon-btn:active { background: var(--color-surface-2); }

/* Inputs */
.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-3);
  margin-bottom: 6px;
}
.input, .textarea, .select {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--jade);
  box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.16);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

.search-wrap { position: relative; }
.search-wrap .material-symbols-rounded {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--color-text-3); pointer-events: none; font-size: 21px;
}
.search-wrap .input { padding-left: 42px; }

/* Chips */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--color-text-2);
  white-space: nowrap;
  transition: all var(--transition);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip-count { opacity: 0.6; font-weight: 500; }

/* Avatars */
.avatar {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.92rem;
  color: #fff;
  background: var(--color-text-3);
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 96px; height: 96px; font-size: 2rem; }
.avatar-xl { width: 132px; height: 132px; font-size: 2.6rem; }
.avatar-sm { width: 34px; height: 34px; font-size: 0.75rem; }

/* Tier dot / pill */
.tier-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--tier-outside); }
.tier-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
  background: var(--color-surface-2); color: var(--color-text-2);
}
.tier-inner-circle { --tier-color: var(--tier-inner-circle); }
.tier-circle       { --tier-color: var(--tier-circle); }
.tier-outer-circle { --tier-color: var(--tier-outer-circle); }
.tier-outside      { --tier-color: var(--tier-outside); }
.dupe-badge { flex-shrink: 0; background: color-mix(in srgb, var(--color-warning) 20%, var(--color-surface-2)); color: #7A4A1E; }
/* A duplicate-flagged row has more to say than a plain one — let it wrap to a
   second line instead of truncating the name to make room for the badge. */
.list-row:has(.dupe-badge) { flex-wrap: wrap; row-gap: 4px; }
.list-row:has(.dupe-badge) .list-row-main { flex-basis: 100%; }
.tier-dot.tier-inner-circle, .tier-dot.tier-circle,
.tier-dot.tier-outer-circle, .tier-dot.tier-outside { background: var(--tier-color); }

/* List rows */
.list { border-radius: var(--radius); overflow: hidden; background: var(--color-surface); border: 1px solid var(--color-border); }
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: background var(--transition);
}
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: var(--color-surface-2); }
.list-row-main { flex: 1; min-width: 0; }
.list-row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row-sub { font-size: 0.82rem; color: var(--color-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row-end { flex: 0 0 auto; color: var(--color-text-3); font-size: 0.8rem; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 56px 20px;
  color: var(--color-text-2);
}
.empty-state .empty-icon { font-size: 46px; color: var(--color-text-3); }
.empty-state h2 { font-size: 1.1rem; color: var(--color-text); }
.empty-state p { font-size: 0.9rem; max-width: 30ch; }
.empty-state .btn { margin-top: 8px; }

/* Bottom sheet / modal — the mobile pattern for pickers */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(13, 27, 42, 0.44);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 160ms ease both;
}
.modal-content {
  width: 100%;
  max-width: var(--page-max);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 10px var(--gutter) calc(24px + var(--safe-bottom));
  animation: sheet-up 240ms cubic-bezier(0.2, 0, 0, 1) both;
}
.modal-handle {
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--color-border);
  margin: 0 auto 14px;
}
.modal-title { font-size: 1.12rem; font-weight: 700; margin-bottom: 4px; }
.modal-sub { font-size: 0.86rem; color: var(--color-text-2); margin-bottom: 14px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }

/* Toasts */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
  max-width: 100%;
  text-align: center;
}
.toast.toast-in { opacity: 1; transform: none; }
.toast-success { background: var(--color-success); }
.toast-error   { background: var(--color-error); }
.toast-warning { background: #8a5a20; }

/* Progress */
.progress { height: 6px; border-radius: 999px; background: var(--color-surface-2); overflow: hidden; }
.progress-bar { height: 100%; background: var(--jade); border-radius: 999px; transition: width 240ms ease; }

/* Utility */
.muted { color: var(--color-text-2); }
.dim { color: var(--color-text-3); }
.small { font-size: 0.82rem; }
.tiny { font-size: 0.72rem; }
.bold { font-weight: 700; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Boot / mount placeholders — B and C replace these with real screens */
.mount-stub {
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  color: var(--color-text-2);
  background: var(--color-surface);
}
.mount-stub .material-symbols-rounded { font-size: 34px; color: var(--jade); }
.mount-stub h3 { font-size: 1rem; color: var(--color-text); margin: 8px 0 4px; }
.mount-stub code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  background: var(--color-surface-2);
  padding: 2px 6px;
  border-radius: 5px;
}

/* Wide screens: the phone layout, centred, with a little air */
@media (min-width: 720px) {
  body { background: #EFECE5; }
  #app { background: var(--color-bg); max-width: var(--page-max); margin: 0 auto; box-shadow: var(--shadow-lg); min-height: 100dvh; }
  .bottom-nav { max-width: var(--page-max); left: 50%; transform: translateX(-50%); }
}
