:root {
  --navy: #0f2540;
  --navy-light: #1c3a5e;
  --slate-50: #f7f9fb;
  --slate-100: #eef1f5;
  --slate-200: #dde3ea;
  --slate-400: #8a97a8;
  --slate-600: #4c5b6e;
  --slate-800: #1f2937;
  --amber: #b8860b;
  --amber-bg: #fdf3d9;
  --red: #b3261e;
  --red-bg: #fbe4e2;
  --green: #1a7f4b;
  --green-bg: #e2f5eb;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 37, 64, 0.08), 0 1px 6px rgba(15, 37, 64, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--slate-50);
  color: var(--slate-800);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font-family: inherit; font-size: 16px; }

#app { min-height: 100vh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-light) 100%);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.2rem; margin: 0 0 4px; color: var(--navy); }
.login-card p.subtitle { margin: 0 0 20px; color: var(--slate-600); font-size: 0.9rem; }
.login-card label { display: block; font-size: 0.85rem; margin: 12px 0 4px; color: var(--slate-600); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--slate-200); border-radius: 8px; }
.login-card button { width: 100%; margin-top: 18px; }
.error-text { color: var(--red); font-size: 0.85rem; margin-top: 10px; }

/* ---------- Header ---------- */
header.app-header {
  background: var(--navy);
  color: var(--white);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.app-header h1 { font-size: 1rem; margin: 0; font-weight: 600; letter-spacing: 0.2px; }
header.app-header .logout-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.3); color: var(--white);
  border-radius: 6px; padding: 6px 10px; font-size: 0.8rem;
}

/* ---------- Main content ---------- */
main { flex: 1; padding: 12px 12px 84px; max-width: 720px; width: 100%; margin: 0 auto; }
section.tab-panel { display: none; }
section.tab-panel.active { display: block; }

/* ---------- Bottom nav ---------- */
nav.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--slate-200);
  display: flex;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom-nav button {
  flex: 1; background: none; border: none; padding: 10px 4px 8px;
  color: var(--slate-600); font-size: 0.72rem; display: flex; flex-direction: column;
  align-items: center; gap: 3px; position: relative;
}
nav.bottom-nav button.active { color: var(--navy); font-weight: 600; }
nav.bottom-nav .nav-icon { font-size: 1.15rem; }
nav.bottom-nav .badge {
  position: absolute; top: 2px; right: 22%; background: var(--red); color: white;
  font-size: 0.6rem; border-radius: 8px; padding: 1px 5px; min-width: 14px; text-align: center;
}

/* ---------- Cards ---------- */
.card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 0.95rem; margin: 0 0 10px; color: var(--navy); }
.card h3 { font-size: 0.85rem; margin: 14px 0 8px; color: var(--slate-600); text-transform: uppercase; letter-spacing: 0.4px; }
.empty-note { color: var(--slate-400); font-size: 0.85rem; padding: 6px 0; }

/* ---------- Buttons ---------- */
button.primary {
  background: var(--navy); color: white; border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
button.secondary {
  background: var(--slate-100); color: var(--navy); border: 1px solid var(--slate-200);
  border-radius: 8px; padding: 9px 14px; font-size: 0.85rem; cursor: pointer;
}
button.danger { background: var(--red-bg); color: var(--red); border: 1px solid #f3c7c3; border-radius: 8px; padding: 9px 14px; font-size: 0.85rem; }
button.link { background: none; border: none; color: var(--navy); text-decoration: underline; padding: 4px 0; font-size: 0.85rem; }
button:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.78rem; color: var(--slate-600); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--slate-200); border-radius: 7px; background: var(--white);
}
.field textarea { min-height: 64px; resize: vertical; }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }

/* ---------- Lists / rows ---------- */
.contact-row {
  border: 1px solid var(--slate-200); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  cursor: pointer;
}
.contact-row:active { background: var(--slate-50); }
.contact-row .row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.contact-row .name { font-weight: 600; font-size: 0.92rem; }
.contact-row .meta { font-size: 0.78rem; color: var(--slate-600); margin-top: 2px; }
.contact-row .next-action { font-size: 0.78rem; color: var(--slate-600); margin-top: 4px; }

.badge-pill {
  display: inline-block; font-size: 0.68rem; font-weight: 600; padding: 2px 7px; border-radius: 20px;
  white-space: nowrap;
}
.badge-stale { background: var(--red-bg); color: var(--red); }
.badge-approaching { background: var(--amber-bg); color: var(--amber); }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-stage { background: var(--slate-100); color: var(--slate-600); }
.badge-dup { background: var(--amber-bg); color: var(--amber); }

/* ---------- Stage tabs ---------- */
.stage-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.stage-tabs button {
  flex-shrink: 0; background: var(--slate-100); border: none; border-radius: 20px; padding: 7px 12px;
  font-size: 0.78rem; color: var(--slate-600);
}
.stage-tabs button.active { background: var(--navy); color: white; }

/* ---------- Detail overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15,37,64,0.45); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.overlay .sheet {
  background: var(--white); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 16px 28px;
}
.overlay .sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.overlay .sheet-header h2 { margin: 0; font-size: 1rem; color: var(--navy); }
.overlay .close-btn { background: none; border: none; font-size: 1.3rem; color: var(--slate-600); line-height: 1; }

/* ---------- Digest ---------- */
.digest-summary-box { background: var(--slate-100); border-radius: 8px; padding: 10px 12px; font-size: 0.82rem; color: var(--slate-600); margin-bottom: 12px; white-space: pre-wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.stat-tile { background: var(--slate-50); border-radius: 8px; padding: 10px 8px; text-align: center; }
.stat-tile .num { font-size: 1.2rem; font-weight: 700; color: var(--navy); }
.stat-tile .label { font-size: 0.65rem; color: var(--slate-600); margin-top: 2px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%);
  background: var(--slate-800); color: white; padding: 10px 16px; border-radius: 8px; font-size: 0.85rem;
  z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

@media (min-width: 640px) {
  nav.bottom-nav { max-width: 720px; left: 50%; transform: translateX(-50%); border-radius: 12px 12px 0 0; }
}
