:root {
  --navy: #1B1A4E;
  --navy-soft: #423F7A;
  --blue-start: #6FA8F5;
  --blue-end: #1E3A8A;
  --pink: #FF5C7A;
  --pink-soft: #FFE1E7;
  --green: #2ECC8F;
  --green-soft: #E3FBF2;
  --amber: #FFB648;
  --amber-soft: #FFF3E0;
  --bg: #F0F2F8;
  --surface: #FFFFFF;
  --surface-2: #F5F6FB;
  --text: #1B1A4E;
  --text2: #8A8AA3;
  --border: #ECEDF5;
  --danger: #FF5C7A;
  --radius-card: 20px;
  --radius-input: 14px;
  --radius-pill: 999px;
  --shadow-card: 0 4px 20px rgba(27, 26, 78, 0.06);
  --shadow-btn: 0 6px 16px rgba(30, 58, 138, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Poppins", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px calc(16px + env(safe-area-inset-top)) 18px;
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }

.icon-btn {
  background: var(--surface-2);
  border: none;
  color: var(--navy);
  font-size: 18px;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  transition: transform 0.15s ease;
}
.icon-btn:active { transform: scale(0.93); }

#app { padding: 16px; padding-bottom: 96px; max-width: 560px; margin: 0 auto; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}

.card h2 {
  font-size: 15px;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--navy);
  font-weight: 700;
}

/* ---------- Form fields (Flutter/Material-style filled inputs) ---------- */
label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 6px;
  margin-top: 14px;
  font-weight: 500;
}
label:first-child { margin-top: 0; }

input[type=text], input[type=tel], input[type=email], input[type=date],
input[type=number], input[type=password], input[type=time],
select, textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-input);
  font-size: 15px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #B3B3C6; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue-end);
  background: var(--surface);
}
textarea { resize: vertical; min-height: 70px; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- Toggle switch ---------- */
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #DEDFEC; border-radius: 28px; transition: 0.2s;
}
.slider:before {
  content: ""; position: absolute; height: 22px; width: 22px;
  left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider { background: linear-gradient(135deg, var(--blue-start), var(--blue-end)); }
input:checked + .slider:before { transform: translateX(20px); }

/* ---------- Buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: linear-gradient(135deg, var(--blue-start), var(--blue-end));
  color: white;
  margin-top: 8px;
  box-shadow: var(--shadow-btn);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: scale(0.98); box-shadow: 0 3px 10px rgba(30, 58, 138, 0.25); }
.btn.secondary { background: var(--surface-2); color: var(--navy); box-shadow: none; }
.btn.whatsapp { background: linear-gradient(135deg, #34D67A, #1FA855); box-shadow: 0 6px 16px rgba(31, 168, 85, 0.28); }
.btn.outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
  box-shadow: none;
}
.btn.outline.danger { color: var(--danger); border-color: var(--pink-soft); }

.small-btn {
  border: none;
  background: none;
  color: var(--blue-end);
  font-size: 13px;
  font-weight: 600;
}

.btn-sm {
  padding: 11px 6px;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gps-status { font-size: 13px; color: var(--text2); margin-top: 6px; }

.photo-preview {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius-input);
  margin-bottom: 10px;
}

/* ---------- Phone input (joined prefix chip) ---------- */
.phone-input-row {
  display: flex;
  border-radius: var(--radius-input);
  overflow: hidden;
  background: var(--surface-2);
}
.phone-prefix {
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--navy-soft);
  background: #E9EBF7;
}
.phone-input-row input {
  border: none;
  border-radius: 0;
  flex: 1;
  background: transparent;
}
.phone-input-row input:focus { outline: none; }

/* ---------- Lead cards / list items ---------- */
.lead-card { margin-bottom: 10px; }
.lead-title { font-weight: 700; font-size: 16px; color: var(--navy); }
.lead-detail { font-size: 13px; color: var(--text2); margin-top: 3px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
}
.badge.synced { background: var(--green-soft); color: #1FA855; }
.badge.unsynced { background: var(--pink-soft); color: var(--pink); }

.empty-state {
  text-align: center;
  color: var(--text2);
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(27, 26, 78, 0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(27, 26, 78, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: 24px 24px 0 0;
  padding: 22px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.modal-x-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.modal-sheet h3 { margin-top: 0; color: var(--navy); font-weight: 700; }

.field-hint { font-size: 12px; color: var(--text2); margin-top: 4px; }

/* ---------- Auth screens ---------- */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 90vh;
  padding: 20px;
}
.auth-logo { font-size: 52px; margin-bottom: 10px; }
.auth-title {
  margin: 0 0 24px 0;
  color: var(--navy);
  font-size: 26px;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.4px;
}
.auth-screen .card { width: 100%; max-width: 360px; }
.auth-error {
  background: var(--pink-soft);
  color: var(--pink);
  padding: 10px 14px;
  border-radius: var(--radius-input);
  font-size: 13px;
  margin-top: 12px;
  font-weight: 500;
}

/* ---------- Floating add button ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: 84px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-start), var(--blue-end));
  color: white;
  font-size: 28px;
  border: none;
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.35);
  z-index: 15;
  line-height: 1;
}

/* ---------- Install banner ---------- */
.install-banner {
  position: sticky;
  top: 0;
  z-index: 9;
  background: var(--amber-soft);
  color: #96650E;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 13px;
}
.install-banner span { flex: 1; }
.install-banner button {
  border: none;
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
}
.install-banner #installNowBtn { background: var(--navy); color: white; }
.install-banner #installDismissBtn { background: transparent; color: #96650E; font-size: 16px; padding: 6px 8px; }

/* ---------- Roadshow list rows ---------- */
.roadshow-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.roadshow-arrow { font-size: 22px; color: var(--text2); }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
  box-shadow: 0 -4px 20px rgba(27, 26, 78, 0.05);
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 0 8px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 21px;
  color: #C3C4D6;
  font-family: inherit;
}
.tab-btn span { font-size: 11px; font-weight: 600; }
.tab-btn.active { color: var(--pink); }

/* ---------- Calendar ---------- */
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--text2);
  margin-top: 12px;
  font-weight: 600;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-top: 4px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  border-radius: 12px;
  cursor: pointer;
  gap: 3px;
  color: var(--text);
  transition: background 0.15s ease;
}
.cal-cell:not(.cal-empty):hover { background: var(--surface-2); }
.cal-cell.cal-empty { cursor: default; }
.cal-cell.cal-today { font-weight: 700; color: var(--blue-end); }
.cal-cell.cal-selected { background: linear-gradient(135deg, var(--blue-start), var(--blue-end)); color: white; }
.cal-cell.cal-selected.cal-today { color: white; }
.cal-dots { display: flex; gap: 2px; height: 6px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text2);
}
.cal-legend-item { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.cal-legend-item .cal-dot { width: 8px; height: 8px; }

/* ---------- Print ---------- */
@media print {
  .topbar, .tabbar, .toast, #quoteDownloadBtn, #quoteWhatsAppBtn, #quoteBackBtn {
    display: none !important;
  }
  #app { padding: 0; max-width: 100%; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ---------- Responsive: tablet ---------- */
@media (min-width: 700px) {
  #app { max-width: 680px; padding: 24px; }
  .topbar { padding-left: max(18px, calc((100vw - 680px) / 2)); padding-right: max(18px, calc((100vw - 680px) / 2)); }
  .fab { right: calc((100vw - 680px) / 2 + 20px); }
}

/* ---------- Responsive: desktop / laptop - sidebar layout ---------- */
@media (min-width: 1024px) {
  body { background: var(--surface-2); }

  #app { max-width: 780px; margin: 0; margin-left: 240px; padding: 28px 32px 60px 32px; }

  .topbar {
    margin-left: 240px;
    padding-left: 32px;
    padding-right: 32px;
    background: var(--surface-2);
    border-bottom: none;
  }

  .tabbar {
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0; right: auto;
    width: 240px;
    height: 100vh;
    justify-content: flex-start;
    align-items: stretch;
    padding: 28px 14px;
    gap: 4px;
    background: var(--surface);
    border-top: none;
    border-right: 1px solid var(--border);
    box-shadow: none;
  }
  .tabbar::before {
    content: "🚗 DealCraft";
    display: block;
    font-weight: 800;
    font-size: 16px;
    color: var(--navy);
    padding: 8px 14px 24px 14px;
  }
  .tab-btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    padding: 13px 16px;
    font-size: 19px;
    border-radius: 14px;
    color: var(--navy-soft);
  }
  .tab-btn span { font-size: 14px; font-weight: 600; }
  .tab-btn.active { background: linear-gradient(135deg, var(--blue-start), var(--blue-end)); color: white; }
  .tab-btn.active span { color: white; }

  .fab { right: 40px; bottom: 40px; }

  /* Auth views (landing, login, signup) have no sidebar/topbar showing -
     don't reserve sidebar space for them, and let them use a proper wide,
     centered desktop layout instead of the narrow mobile-width column. */
  body.is-auth-view #app {
    margin-left: 0;
    max-width: 100%;
    padding: 40px 0;
  }
  body.is-auth-view .auth-screen {
    max-width: 960px;
    margin: 0 auto;
  }
  .landing-actions {
    max-width: 480px !important;
  }
  .landing-features {
    max-width: 900px !important;
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }

  .modal-sheet {
    border-radius: 24px;
    max-width: 480px;
    margin-bottom: 40px;
  }
  .modal-backdrop { align-items: center; }
}
