:root {
  --primary: #6C35E0;
  --primary-soft: #F3EEFF;
  --text: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --border: #E6E8EE;
  --border-soft: #F0F1F4;
  --canvas: #EEF0F4;
  --chip: #F3F4F6;
  --success: #16A34A;
  --success-bright: #22C55E;
  --success-soft: #E8F8EE;
  --whatsapp: #25D366;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --tab: #9CA3AF;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
.icon { display: block; flex: 0 0 auto; }

.app-shell { min-height: 100dvh; display: flex; justify-content: center; }
.app-column {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  background: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
@media (max-width: 520px) {
  body { background: #fff; }
  .app-column { border: 0; }
}

.page-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.page-scroll::-webkit-scrollbar { display: none; }
.screen-fill { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.screen-fill.cream { background: #F7F1E4; }
#calculator-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #F7F1E4; }

.topbar, .screen-header { flex: none; background: #fff; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 8px;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--primary); }
.brand-text { font-weight: 700; font-size: 15px; line-height: 18px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.bell {
  position: relative;
  width: 32px;
  height: 32px;
  border: 0;
  background: none;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.bell-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #EF4444;
  border: 1.5px solid #fff;
}
.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}
.screen-header { height: 52px; display: flex; align-items: center; justify-content: center; position: relative; }
.screen-header h1 {
  max-width: 68%;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back {
  position: absolute;
  left: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-decoration: none;
}

.pad { padding: 4px 20px 28px; }
.pad-form { padding: 12px 20px 16px; }
.login-pad { padding: 28px 20px 24px; }
.intro { padding: 4px 20px 8px; flex: none; }
.list { padding: 8px 20px 88px; }
.lead-pad { padding-bottom: 32px; }

.page-heading { margin: 0 0 16px; }
.page-heading h1 { margin: 0; font-size: 28px; line-height: 34px; letter-spacing: -0.4px; font-weight: 700; }
.page-heading p { margin: 4px 0 0; font-size: 14px; line-height: 20px; color: var(--text-secondary); }

.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; color: var(--primary); font-weight: 700; font-size: 16px; line-height: 20px; }
.login-title { margin: 0; font-size: 28px; line-height: 34px; letter-spacing: -0.4px; }
.login-sub { margin: 4px 0 24px; font-size: 14px; line-height: 20px; color: var(--text-secondary); }
.login-error { margin: -6px 0 16px; }

.field { margin-bottom: 18px; }
.label-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.field-icon { display: inline-flex; color: var(--text); }
.label { font-size: 14px; font-weight: 600; }
.optional { font-weight: 400; color: var(--text-muted); }
.input, .select-input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  background: #fff;
}
.input.multiline { height: 118px; padding: 14px; resize: none; }
.input.invalid { border-color: var(--danger); }
.select-label { color: var(--primary); }
.select-label .label { color: var(--text); }
.select-input { display: flex; align-items: center; gap: 10px; text-align: left; color: var(--text-muted); }
.select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 15px; }
.select-value.placeholder { color: var(--text-muted); }
.muted-icon { display: inline-flex; color: var(--text-muted); }
.field-error { margin-top: 6px; font-size: 12px; color: var(--danger); }
.form-error { margin: 0 0 8px; font-size: 13px; line-height: 18px; color: var(--danger); }
.action-error { margin-top: 12px; }

.mpin-boxes { display: flex; gap: 12px; position: relative; }
.mpin-box {
  flex: 1;
  height: 58px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 32px;
  font-weight: 700;
}
.mpin-box.filled { border-color: #D4D4D8; }
.mpin-box.active { border-color: var(--primary); border-width: 1.5px; }
.mpin-boxes.invalid .mpin-box { border-color: var(--danger); }
.mpin-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; }

.btn {
  height: 54px;
  width: 100%;
  border-radius: 14px;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.outline { background: #fff; color: var(--primary); border: 1px solid #DDD6FE; }
.btn:active { opacity: 0.88; }
.btn:disabled { opacity: 0.6; }
.form-footer { padding: 8px 20px 16px; background: #fff; }
.form-screen { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.btn-stack { display: flex; flex-direction: column; gap: 12px; margin-top: 36px; align-self: stretch; width: 100%; }

.search {
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  color: var(--text-muted);
  background: #fff;
}
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 15px; color: var(--text); padding: 0; }
.search-clear { border: 0; background: none; color: var(--text-muted); padding: 0; display: flex; }

.filters { display: flex; align-items: center; margin-top: 12px; }
.chips { display: flex; gap: 8px; overflow: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip, .bucket {
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: var(--chip);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip { padding: 0 14px; }
.chip.active, .bucket.active { background: var(--primary); color: #fff; }
.chip:disabled { opacity: 1; cursor: default; }
.filter-btn {
  width: 36px;
  height: 36px;
  margin-left: 8px;
  border: 0;
  border-radius: 12px;
  background: var(--chip);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.filter-btn.active { background: var(--primary-soft); color: var(--primary); }
.buckets { display: flex; gap: 8px; margin: 14px 0 16px; }
.bucket { flex: 1; padding: 0 8px; font-weight: 700; }

.lead-card {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 12px 6px 12px 12px;
  margin-bottom: 12px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.05);
}
.lead-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.lead-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lead-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone-row { display: flex; align-items: center; gap: 4px; color: var(--text-muted); }
.phone-text { color: var(--text-secondary); font-size: 13px; }
.lead-city { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-actions { display: flex; align-items: center; }
.icon-btn {
  width: 32px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: none;
}
.icon-btn.call, .round.call, .action-row a.call { color: var(--success-bright); }
.action-row a.call { color: var(--success); }
.icon-btn.wa, .round.wa, .action-row a.wa { color: var(--whatsapp); }
.icon-btn.muted { color: var(--text-muted); }
.round.call { color: var(--success); }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 700;
  flex: none;
}

.fab {
  position: absolute;
  right: 20px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 29px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 6px 10px rgba(108, 53, 224, 0.35);
  z-index: 6;
}

.tabbar {
  flex: none;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border-soft);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  text-decoration: none;
  color: var(--tab);
  font-size: 11px;
  font-weight: 600;
}
.tabbar a.active { color: var(--primary); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { border: 1px solid var(--border-soft); border-radius: 16px; padding: 14px; }
.stat-icon {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat b { display: block; margin-top: 12px; font-size: 26px; }
.stat > span:last-child { display: block; margin-top: 2px; font-size: 13px; color: var(--text-secondary); }
.section-row { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.section-row h2 { margin: 0; font-size: 18px; }
.section-row a { color: var(--primary); font-weight: 700; font-size: 14px; text-decoration: none; }
.dash-empty h3 { margin: 0; font-size: 16px; }
.dash-empty p { margin: 6px 0 16px; font-size: 14px; color: var(--text-secondary); }

.empty { padding: 48px 24px; }
.empty.center { text-align: center; }
.empty h2, .follow-empty h2 { margin: 0; font-size: 17px; }
.empty p, .follow-empty p { margin: 6px 0 0; font-size: 14px; line-height: 20px; color: var(--text-secondary); }
.follow-empty { padding: 28px 0; }
.retry {
  margin-top: 16px;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.missing {
  min-height: 60%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 16px;
}
.missing h2 { margin: 0 0 8px; color: var(--text); font-size: 18px; }

.follow-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fff;
  text-align: left;
  color: inherit;
}
.follow-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.follow-title { display: flex; align-items: center; gap: 8px; }
.follow-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-visit { background: var(--primary-soft); color: var(--primary); }
.badge-good { background: #E8F8EE; color: var(--success); }
.badge-wa { background: #E7F8EF; color: #128C7E; }
.badge-call { background: #FEF3C7; color: #D97706; }
.meta-line, .when { display: flex; align-items: center; gap: 4px; color: var(--text-secondary); font-size: 13px; }
.meta-line .icon, .when .icon { color: var(--text-muted); }
.follow-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.follow-actions { display: flex; gap: 8px; }
.round {
  width: 32px;
  height: 32px;
  border-radius: 16px;
  background: #F0FDF4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.round.lg { width: 40px; height: 40px; border-radius: 20px; border: 1px solid #D1FAE5; }
.follow-note {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lead-strip { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.lead-strip .lead-name { font-size: 16px; }
.lead-strip .phone-text { margin-top: 2px; }

.hero { text-align: center; padding-top: 8px; }
.hero .avatar { margin: 0 auto; }
.hero h2 { margin: 14px 0 0; font-size: 22px; }
.hero .phone { margin-top: 4px; color: var(--text-secondary); font-size: 15px; }
.hero .meta { margin-top: 4px; color: var(--text-muted); font-size: 13px; }
.action-row { display: flex; gap: 12px; margin-top: 20px; }
.action-row a {
  flex: 1;
  height: 48px;
  border-radius: 12px;
  border: 1px solid #D1FAE5;
  background: #F0FDF4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}
.kicker { margin: 24px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-muted); }
.statuses { display: flex; flex-wrap: wrap; gap: 8px; }
.detail { padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail small { display: block; font-size: 12px; color: var(--text-muted); }
.detail p { margin: 3px 0 0; font-size: 15px; line-height: 21px; white-space: pre-wrap; }
.detail p.muted { color: var(--text-muted); }
.delete-btn {
  margin-top: 28px;
  height: 48px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 8px;
}
.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex: none;
}
.profile b { display: block; font-size: 16px; }
.profile span span { display: block; margin-top: 2px; font-size: 13px; color: var(--text-secondary); font-weight: 400; }
.menu { border: 1px solid var(--border-soft); border-radius: 16px; overflow: hidden; }
.menu-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  background: none;
  border: 0;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
}
.menu-icon {
  width: 32px;
  height: 32px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.menu-row > span:nth-child(2) { flex: 1; }
.chev { color: var(--text-muted); display: inline-flex; margin-left: auto; }
.menu-divider { height: 1px; background: var(--border); margin-left: 58px; }
.about { margin: 0; font-size: 14px; line-height: 21px; color: var(--text-secondary); }
.version { margin: 28px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); }

.success { display: flex; flex-direction: column; align-items: center; padding: 72px 24px 24px; }
.success-mark {
  width: 104px;
  height: 104px;
  border-radius: 52px;
  background: var(--success-soft);
  color: var(--success-bright);
  display: flex;
  align-items: center;
  justify-content: center;
}
.success h1 { margin: 28px 0 0; font-size: 22px; line-height: 28px; text-align: center; }
.success p { margin: 8px 0 0; font-size: 15px; line-height: 22px; text-align: center; color: var(--text-secondary); }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(17, 24, 39, 0.45);
  display: flex;
  align-items: flex-end;
}
.sheet {
  width: 100%;
  max-height: 86%;
  overflow: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
}
.handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 14px; }
.sheet-title { margin: 0 0 12px; font-size: 18px; }
.sheet-empty { margin: 0 0 12px; color: var(--text-secondary); font-size: 15px; }
.sheet-meta { margin: 4px 0 0; font-size: 13px; color: var(--text-secondary); }
.sheet-kicker { margin: 18px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-muted); }
.sheet-note { margin: 0 0 8px; font-size: 15px; line-height: 22px; white-space: pre-wrap; }
.city-list { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 8px; }
.notice-list, .option-list { max-height: 360px; overflow: auto; }
.notice { display: flex; align-items: center; gap: 12px; padding: 10px 0; text-decoration: none; color: inherit; }
.notice-copy { flex: 1; min-width: 0; }
.notice-name { display: block; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notice-meta { display: block; margin-top: 2px; font-size: 13px; color: var(--text-secondary); }
.notice .icon { color: var(--text-muted); }
.option-row {
  min-height: 48px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font-size: 16px;
  color: var(--text);
  padding: 0;
  text-align: left;
}
.option-row.active { color: var(--primary); font-weight: 700; }
.month-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-label { font-size: 16px; font-weight: 700; }
.month-arrow {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: var(--chip);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.weekdays { display: flex; }
.weekdays span { flex: 1; text-align: center; font-size: 12px; font-weight: 700; color: var(--text-muted); padding: 6px 0; }
.date-grid { display: flex; flex-wrap: wrap; margin-bottom: 8px; }
.date-grid span, .date-grid button {
  width: calc(100% / 7);
  aspect-ratio: 1;
  border: 0;
  background: none;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0;
}
.date-grid button.active { background: var(--primary); color: #fff; font-weight: 700; }

#lead-menu-backdrop { position: absolute; inset: 0; z-index: 35; }
.popup-menu {
  position: absolute;
  z-index: 40;
  width: 188px;
  background: #fff;
  border-radius: 16px;
  padding: 6px 0;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.16);
}
.popup-menu a, .popup-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: none;
  border: 0;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
}
.popup-menu .mi { display: inline-flex; }
.popup-menu .tone-primary .mi { color: var(--primary); }
.popup-menu .tone-danger, .popup-menu .tone-danger .mi { color: var(--danger); }
.popup-menu .menu-divider { margin: 0 0 0 42px; }
#delete-form { display: none; }
