:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-light: #14b8a6;
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #1b1f23;
  --muted: #6b7280;
  --line: #e5e7eb;
  --done: #9aa3ab;
  --later: #a16207; /* dark yellow text */
  --later-fill: #eab308; /* yellow progress / accents */
  --na: #dc2626; /* red — N/A */
  --danger: #b91c1c;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.4;
}

body {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: var(--teal);
  color: #fff;
  box-shadow: var(--shadow);
}
.title-wrap { display: flex; align-items: baseline; gap: 8px; }
.app-title { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.2px; }
.app-version {
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 2px 8px;
  letter-spacing: 0.3px;
}
.header-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.3); }

/* Sync indicator (in the top bar) */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
}
.sync-status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}
.sync-status.synced::before { background: #4ade80; }
.sync-status.syncing::before { background: #fbbf24; }
.sync-status.offline::before { background: rgba(255, 255, 255, 0.5); }
.sync-status:empty { display: none; }

.view { padding: 0 14px; padding-bottom: calc(18px + var(--safe-bottom)); }
[hidden] { display: none !important; }

/* Import screen */
.import-view { display: flex; justify-content: center; padding-top: 16px; }
.import-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  max-width: 460px;
  width: 100%;
  text-align: center;
}
.import-icon { font-size: 3rem; margin-bottom: 6px; }
.import-card h2 { margin: 4px 0 8px; font-size: 1.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:active { background: var(--teal-dark); }
.btn-block { display: block; width: 100%; margin: 18px 0 6px; }

.how-to { text-align: left; margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.how-to summary { cursor: pointer; font-weight: 600; color: var(--teal); padding: 6px 0; }
.how-to ol { margin: 10px 0; padding-left: 20px; }
.how-to li { margin-bottom: 8px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: #e9ebed;
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 0;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 3px;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}
.tab[aria-selected="true"] {
  background: var(--card);
  color: var(--teal);
  box-shadow: var(--shadow);
}
.tab-count {
  font-size: 0.74rem;
  font-weight: 700;
  background: rgba(15, 118, 110, 0.12);
  color: var(--teal);
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 18px;
}
.tab[aria-selected="false"] .tab-count { background: rgba(0, 0, 0, 0.06); color: var(--muted); }

/* Later tab — dark yellow */
.tab-later { color: var(--later); }
.tab-later[aria-selected="true"] { color: var(--later); }
.tab-later .tab-count { background: rgba(161, 98, 7, 0.14); color: var(--later); }
.tab-later[aria-selected="false"] .tab-count { background: rgba(161, 98, 7, 0.1); color: var(--later); }

/* N/A tab — red */
.tab-na { color: var(--na); }
.tab-na[aria-selected="true"] { color: var(--na); }
.tab-na .tab-count { background: rgba(220, 38, 38, 0.12); color: var(--na); }
.tab-na[aria-selected="false"] .tab-count { background: rgba(220, 38, 38, 0.09); color: var(--na); }

/* Delete-all bar (N/A tab) */
.na-bar { display: flex; justify-content: flex-end; margin: 8px 0 10px; }
.delete-all-btn {
  border: 1px solid var(--na);
  background: transparent;
  color: var(--na);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
}
.delete-all-btn:active { background: rgba(220, 38, 38, 0.1); }

/* Sort control (Done tab) */
.sort-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 8px 0 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.sort-bar select {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--card);
}

/* Sticky region: progress bar + tabs stay pinned under the header on scroll */
.sticky-top {
  position: sticky;
  top: var(--header-h, 52px);
  z-index: 9;
  background: var(--bg);
  padding: 10px 0;
  box-shadow: 0 6px 6px -6px rgba(0, 0, 0, 0.1);
}

/* Progress (above the tabs, always visible). Label sits beside the bar. */
.progress-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.progress-text {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.progress-track {
  flex: 1;
  display: flex;
  height: 12px;
  background: #e3e6e8;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--teal-light));
  transition: width 0.35s ease;
}
.progress-bar-later {
  height: 100%;
  background: var(--later-fill);
  transition: width 0.35s ease;
}

/* Contact list */
.contact-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.contact {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.contact-main { flex: 1; min-width: 0; overflow: hidden; }
.name-row { display: flex; align-items: center; gap: 6px; }
.source-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}
.source-J { background: #2563eb; } /* blue — mum's set */
.source-R { background: #7c3aed; } /* purple — dad's set */
.contact-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.phones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; }
.phone-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--teal);
  font-weight: 600;
  background: rgba(15, 118, 110, 0.08);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.98rem;
}
.phone-link:active { background: rgba(15, 118, 110, 0.2); }
.phone-type { color: var(--muted); font-weight: 500; font-size: 0.8rem; }

/* Row actions */
.actions { display: flex; flex-direction: row; gap: 6px; flex-shrink: 0; align-items: stretch; }
.action-col { display: flex; flex-direction: column; gap: 6px; }
.actions button {
  border-radius: 10px;
  height: 34px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
  min-width: 58px;
  -webkit-tap-highlight-color: transparent;
}
.done-btn { background: var(--teal); color: #fff; border-color: var(--teal); }
.done-btn:active { background: var(--teal-dark); }
/* Tall Done spans the stacked Later + N/A (override the fixed height above) */
.actions button.done-tall { height: auto; align-self: stretch; }
.later-btn { background: rgba(234, 179, 8, 0.14); color: var(--later); }
.later-btn:active { background: rgba(234, 179, 8, 0.28); }
.na-btn { background: rgba(220, 38, 38, 0.1); color: var(--na); }
.na-btn:active { background: rgba(220, 38, 38, 0.22); }
.call-btn, .undo-btn { background: transparent; color: var(--teal); border-color: var(--teal); }
.call-btn:active, .undo-btn:active { background: rgba(15, 118, 110, 0.1); }

/* Done / Later / N/A row states */
.contact.is-done { opacity: 0.55; background: #fbfbfc; }
.contact.is-done .contact-name { text-decoration: line-through; text-decoration-color: var(--done); }
.contact.is-later { border-left: 4px solid var(--later-fill); }
.contact.is-later .contact-name { color: var(--later); }
.contact.is-na { border-left: 4px solid var(--na); }
.contact.is-na .contact-name { color: var(--na); }

/* Empty state */
.empty-state { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty-state .big { font-size: 2.4rem; margin-bottom: 8px; }

/* Menu sheet */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(14px + var(--safe-bottom));
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}
.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 16px 12px;
  font-size: 1.05rem;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
}
.sheet-item:active { background: #f0f1f2; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.ghost { color: var(--muted); text-align: center; font-weight: 600; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  z-index: 60;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  max-width: 90%;
}
