:root {
  --ink: #0f1b2d;
  --ink-soft: #5b6b80;
  --line: #e6e9f2;
  --surface: #ffffff;
  --bg: #f2f4fb;
  --brand: #1a56db;
  --brand-dark: #123a99;
  --brand-soft: #e8f0fe;
  --accent: #0d9488;
  --danger: #d92d20;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-card: 0 1px 2px rgba(15, 27, 45, 0.04), 0 8px 20px rgba(15, 27, 45, 0.06);
  --shadow-tile: 0 10px 24px -6px rgba(15, 27, 45, 0.28);

  /* Dashboard tile gradients - one identity color per category, reused for
     badges/pills elsewhere so a stage always reads the same color everywhere. */
  --grad-leads: linear-gradient(135deg, #1c4f8c 0%, #3f8fd1 100%);
  --grad-followups: linear-gradient(135deg, #e8613c 0%, #f6a35e 100%);
  --grad-appointments: linear-gradient(135deg, #17877a 0%, #4fc3ac 100%);
  --grad-success: linear-gradient(135deg, #7c3fd6 0%, #b678e8 100%);
  --grad-renewals: linear-gradient(135deg, #b8860b 0%, #e8b93f 100%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.view { display: none; min-height: 100vh; padding-bottom: 24px; }
.view.is-active { display: block; }

.app-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-bar__title { font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; }
.app-bar__spacer { flex: 1; }

.icon-btn {
  border: none; background: var(--line); color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; cursor: pointer; flex: none;
  transition: transform 0.12s ease, background 0.12s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn svg { width: 19px; height: 19px; }
#btn-search { background: var(--brand-soft); color: var(--brand-dark); }
#btn-logout { background: #fde8e8; color: var(--danger); }

.icon-btn--notif { position: relative; background: var(--brand-soft); color: var(--brand-dark); }
.notif-badge {
  position: absolute; top: 3px; right: 3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 0.65rem; font-weight: 800; line-height: 16px; text-align: center;
}

.notif-item { cursor: pointer; }
.notif-item.is-unread { background: var(--brand-soft); }
.notif-item__msg { font-weight: 600; font-size: 0.92rem; }
.notif-item.is-unread .notif-item__msg { font-weight: 800; }
.notif-item__time { color: var(--ink-soft); font-size: 0.78rem; margin-top: 2px; }

.login-panel {
  max-width: 340px; margin: 14vh auto 0; padding: 0 24px; text-align: center;
}
.login-brand { display: block; text-decoration: none; color: inherit; }
.login-mark {
  width: 60px; height: 60px; border-radius: 18px;
  background: var(--grad-leads); color: #fff; box-shadow: var(--shadow-tile);
  font-weight: 800; font-size: 1.25rem; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
}
.login-panel h1 { font-size: 1.3rem; margin: 0 0 2px; letter-spacing: -0.01em; }
.login-sub { color: var(--ink-soft); font-size: 0.95rem; font-weight: 600; margin: 0 0 22px; }
.muted { color: var(--ink-soft); font-size: 0.92rem; margin: 0 0 22px; text-align: left; }
.muted--center { text-align: center; }

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 16px; margin-top: 4px;
  background: #fff; color: #3c4043; border: 1px solid #dadce0; border-radius: 12px;
  font-family: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-card);
}
.google-btn:hover { background: #f8f9fa; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.google-btn:disabled { opacity: 0.6; cursor: default; }
.google-btn__icon { width: 18px; height: 18px; flex: none; }
.signed-in-as { color: var(--ink-soft); font-size: 0.82rem; font-weight: 600; }

.field {
  width: 100%; padding: 13px 16px; font-size: 1rem;
  border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); outline: none; font-family: inherit;
}
.field:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.field-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin: 14px 0 6px; }
.field-error { color: var(--danger); font-size: 0.85rem; margin: 10px 2px; }

.btn {
  padding: 13px 20px; border-radius: 999px; font-size: 0.98rem; font-weight: 700;
  border: none; cursor: pointer; text-decoration: none; text-align: center; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn--block { display: flex; width: 100%; margin-top: 14px; }
.btn--primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px -4px rgba(26, 86, 219, 0.5); }
.btn--primary:hover { background: var(--brand-dark); }
.btn--ghost { background: var(--brand-soft); color: var(--brand-dark); }
.btn--call { background: linear-gradient(135deg, #0d9488, #14b8a6); color: #fff; box-shadow: 0 6px 16px -4px rgba(13, 148, 136, 0.5); }
.btn--message { background: linear-gradient(135deg, #1a56db, #3b82f6); color: #fff; box-shadow: 0 6px 16px -4px rgba(26, 86, 219, 0.5); }
.btn--reschedule { background: linear-gradient(135deg, #d9711a, #f59e42); color: #fff; box-shadow: 0 6px 16px -4px rgba(217, 113, 26, 0.5); }
.btn--success { background: var(--grad-success); color: #fff; box-shadow: 0 6px 16px -4px rgba(124, 63, 214, 0.5); }
.btn__icon { width: 16px; height: 16px; flex: none; }

.home-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 18px 16px;
}
.tile {
  position: relative; overflow: hidden;
  border: none; border-radius: var(--radius-lg);
  padding: 20px 16px; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  color: #fff; box-shadow: var(--shadow-tile);
  transition: transform 0.12s ease;
}
.tile:hover { transform: translateY(-2px); }
.tile--leads { background: var(--grad-leads); }
.tile--followups { background: var(--grad-followups); }
.tile--appointments { background: var(--grad-appointments); }
.tile--success { background: var(--grad-success); }
.tile--renewals { background: var(--grad-renewals); }
.tile__icon {
  position: absolute; top: 14px; right: 14px; width: 22px; height: 22px;
  opacity: 0.85;
}
.tile__count { font-size: 2rem; font-weight: 800; line-height: 1; }
.tile__label { font-size: 0.88rem; font-weight: 600; opacity: 0.95; }
.tile__note {
  align-self: flex-start; margin-top: 2px; padding: 2px 9px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; background: rgba(255,255,255,0.25);
}

.filter-bar {
  padding: 12px 16px 4px;
  display: flex; flex-direction: column; gap: 8px;
}
.filter-row {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 8px 15px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-family: inherit; font-size: 0.82rem; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.is-selected { background: var(--brand); border-color: var(--brand); color: #fff; }

#btn-export {
  margin: 16px 16px 0; width: calc(100% - 32px);
  background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff;
  box-shadow: 0 8px 20px -6px rgba(26, 86, 219, 0.55);
}
#btn-export .btn__icon { width: 20px; height: 20px; }
#export-status { margin: 8px 16px 0; }
#home-error { margin: 12px 16px 0; }

.search-bar { padding: 12px 16px; }

.closed-link {
  display: flex; align-items: center; gap: 12px;
  margin: 4px 16px 0; padding: 12px 14px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-card);
  text-decoration: none; color: var(--ink); font-size: 0.9rem; font-weight: 600;
}
.closed-link:hover { box-shadow: 0 1px 2px rgba(15,27,45,0.04), 0 10px 24px rgba(15,27,45,0.1); }
.closed-link__icon {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--brand-soft); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
}
.closed-link__icon svg { width: 17px; height: 17px; }
.closed-link__label { flex: 1; }
.closed-link__count {
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 800;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
}

.done-check {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.6rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}

.section-label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft);
  margin: 20px 16px 10px; text-transform: uppercase;
}
.section-label:first-of-type { margin-top: 16px; }

.section-label-row {
  display: flex; align-items: center; justify-content: space-between;
  margin: 20px 16px 10px; gap: 10px;
}
.section-label-row .section-label { margin: 0; }

.call-list, .lead-list { list-style: none; margin: 0; padding: 0 16px; }

/* One shared card used everywhere a lead is listed (section lists, Today's
   Calls, ...) - a top row (tap to open detail) plus an optional 2x2 action
   grid whose button set depends on the lead's stage. */
.lead-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-card);
}
.lead-card__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.lead-card__main { min-width: 0; }
.lead-card__name { font-weight: 700; font-size: 0.98rem; }
.lead-card__sub { color: var(--ink-soft); font-size: 0.84rem; margin-top: 2px; }
.lead-card__actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 12px;
}
.lead-card__actions .btn { margin-top: 0; }
.btn--sm { padding: 9px 14px; font-size: 0.85rem; }
.btn--outline { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }
.btn--outline:hover { border-color: var(--danger); color: var(--danger); }
.btn--danger { background: #fde8e8; color: var(--danger); }
.btn--danger:hover { background: #fbd5d5; }

.danger-zone { margin: 28px 16px 8px; padding-top: 16px; border-top: 1px solid var(--line); }

.badge {
  font-size: 0.72rem; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap;
}
.badge--HOT { background: #fee2e2; color: #b91c1c; }
.badge--WARM { background: #ffedd5; color: #c2410c; }
.badge--NURTURE { background: #fef9c3; color: #a16207; }
.badge--INFO-ONLY { background: #e2e8f0; color: #475569; }
.badge--time { background: var(--brand-soft); color: var(--brand-dark); }
.badge--success { background: #ede9fe; color: #6d28d9; }
.badge--stage { background: var(--line); color: var(--ink-soft); }

.empty-state {
  text-align: center; color: var(--ink-soft); margin-top: 32px; font-size: 0.92rem;
  padding: 0 16px;
}
.empty-state__icon {
  width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 14px;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
}
.empty-state__icon svg { width: 24px; height: 24px; }

.detail-card {
  background: var(--surface); border-radius: var(--radius-lg);
  margin: 16px; padding: 20px; box-shadow: var(--shadow-card);
}
.detail-card h2 { margin: 0; font-size: 1.2rem; }
.lead-code { color: var(--ink-soft); font-size: 0.8rem; margin: 0; }

.detail-head { display: flex; align-items: center; gap: 14px; }
.detail-avatar {
  width: 52px; height: 52px; border-radius: 50%; flex: none;
  background: var(--line); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
}
.detail-avatar svg { width: 26px; height: 26px; }

.detail-inline {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  margin: 14px 0 0; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: 0.86rem; font-weight: 600; color: var(--ink-soft);
}
.detail-inline__item { display: flex; align-items: center; gap: 6px; }
.detail-inline__item svg { width: 15px; height: 15px; flex: none; }

.detail-section { margin-top: 16px; }
.detail-section--advisor { border-top: 1px solid var(--line); padding-top: 14px; }
.detail-section__title {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft);
  text-transform: uppercase; margin: 0 0 10px;
}

.detail-field { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.detail-field__icon {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: var(--line); color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
}
.detail-field__icon svg { width: 16px; height: 16px; }
.detail-field__icon--warm { background: #fee2e2; color: #dc2626; }
.detail-field__icon--accent { background: #dcfce7; color: #16a34a; }
.detail-field__icon .status-pill { padding: 3px 9px; font-size: 0.7rem; }
.detail-field__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.detail-field__label { font-size: 0.74rem; color: var(--ink-soft); }
.detail-field__value { font-size: 0.92rem; font-weight: 700; word-break: break-word; }

.status-pill {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); font-size: 0.78rem; font-weight: 700;
}

.detail-appt-card {
  margin-top: 16px; padding: 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--brand-soft), #f3e8ff);
}
.detail-appt-card .detail-field__icon { background: rgba(255,255,255,0.7); }
.detail-appt-card__countdown {
  margin: 10px 0 0; text-align: right; font-size: 0.78rem; font-weight: 800;
  letter-spacing: 0.03em; text-transform: uppercase; color: var(--brand-dark);
}

.detail-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 16px 16px; }
.detail-actions .btn { margin-top: 0; flex: 1 1 150px; }

/* One entry in a customer's contact history - not a lead-card: not clickable,
   no action buttons, just a record of what happened on a past call. */
.history-item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 10px; box-shadow: var(--shadow-card);
}
.history-item__top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.history-item__label { font-weight: 700; font-size: 0.9rem; }
.history-item__date { color: var(--ink-soft); font-size: 0.78rem; white-space: nowrap; }
.history-item__note { margin: 6px 0 0; font-size: 0.88rem; }
.history-item__meta { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.78rem; }

/* Small uppercase label used inside a .sheet - unlike .section-label, no side
   margin, since the sheet's own padding already indents its content. */
.sheet-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft);
  text-transform: uppercase; margin: 18px 0 8px;
}
.sheet-label:first-of-type { margin-top: 4px; }

.reminder-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.reminder-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
}
.reminder-item__label { font-size: 0.85rem; font-weight: 600; }
.reminder-item__date { display: block; color: var(--ink-soft); font-size: 0.76rem; margin-top: 1px; }
.reminder-item.is-contacted { background: #f0fdf4; border-color: #bbf7d0; }
.reminder-item.is-contacted .reminder-item__label { color: #166534; }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15, 27, 45, 0.5);
  display: flex; align-items: flex-end; z-index: 20;
}
.sheet {
  background: var(--surface); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 24px 24px 0 0; padding: 10px 20px 24px;
}
.sheet__handle { width: 40px; height: 4px; background: var(--line); border-radius: 999px; margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 14px; }

.status-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
/* .policy-status-opt shares this look but is a DIFFERENT class from .status-opt
   on purpose - the bare `.status-opt` listener in advisor.js matches by class
   name regardless of what else is on the element, so the policy sheet's status
   buttons must never carry the literal "status-opt" class or they'd silently
   double-fire that listener and corrupt its selectedStatus state. */
.status-opt, .policy-status-opt {
  padding: 12px 10px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.status-opt:hover, .policy-status-opt:hover { border-color: var(--brand); background: var(--brand-soft); }
.status-opt.is-selected, .policy-status-opt.is-selected { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.status-opt--success.is-selected { border-color: var(--accent); background: #ccfbf1; color: #0f766e; }

.sheet__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (min-width: 560px) {
  .login-panel, .home-grid, .lead-list, .call-list, .detail-card, .detail-actions, .sheet, .filter-bar, .search-bar {
    max-width: 480px; margin-left: auto; margin-right: auto;
  }
  .detail-actions { margin-left: auto; margin-right: auto; }
  .section-label { max-width: 480px; margin-left: auto; margin-right: auto; }
  .closed-link { max-width: 480px; margin-left: auto; margin-right: auto; }
  .sheet { border-radius: 24px; margin-bottom: 24px; }
  .sheet-backdrop { align-items: center; justify-content: center; }
}
