*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-primary: #2563eb;
  --clr-hbc:     #7a1010;
  --clr-danger:  #dc2626;
  --clr-success: #16a34a;
  --clr-warn:    #d97706;
  --clr-muted:   #6b7280;
  --clr-bg:      #f9fafb;
  --clr-card:    #ffffff;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,.12);
}

body { font-family: system-ui, sans-serif; background: var(--clr-bg); color: #111; }

/* ── Auth page ── */
body.login-page {
  background: var(--clr-hbc);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.07) 0%, transparent 60%),
    radial-gradient(ellipse at 75% 80%, rgba(0,0,0,.25) 0%, transparent 60%);
  min-height: 100dvh;
}

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-card {
  background: var(--clr-card);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.35);
  padding: 2.5rem 2rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo-wrap {
  background: var(--clr-hbc);
  border-radius: 12px;
  padding: .75rem 1rem;
  margin: 0 auto 1.25rem;
  display: inline-block;
  width: 100%;
}
.auth-logo {
  display: block;
  max-height: 80px;
  margin: 0 auto;
  object-fit: contain;
}

.auth-subtitle {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--clr-hbc);
  margin-bottom: 1.75rem;
}

.auth-card label { text-align: left; }

/* ── Forms ── */
label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: .6rem .75rem;
  border: 1px solid #d1d5db; border-radius: var(--radius);
  font-size: 1rem; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--clr-hbc); border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }

.form-group { margin-bottom: 1rem; }

/* Ensure the HTML hidden attribute always wins over component display rules */
[hidden] { display: none !important; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; padding: .6rem 1.2rem;
  border: none; border-radius: var(--radius);
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--clr-hbc); color: #fff; }
.btn-danger   { background: var(--clr-danger);  color: #fff; }
.btn-ghost    { background: transparent; color: var(--clr-hbc); }
.btn-block    { width: 100%; }
.btn:hover:not(:disabled) { opacity: .88; }

/* ── App layout ── */
#app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .75rem;
  background: var(--clr-hbc); color: #fff;
  flex-shrink: 0; z-index: 1000;
}
.topbar-logo {
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
}
.topbar h1 { font-size: 1rem; flex: 1; }
.topbar .btn-ghost { color: #fff; font-size: .875rem; padding: .3rem .6rem; }

.search-bar {
  display: flex; gap: .5rem;
  padding: .5rem .75rem;
  background: #fff; border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0; z-index: 999;
}
.search-bar input { flex: 1; }

#map { flex: 1; z-index: 1; position: relative; }

#locateBtn {
  position: absolute;
  bottom: 5.5rem;
  right: .75rem;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .15s, color .15s;
}
#locateBtn:hover { box-shadow: 0 4px 14px rgba(0,0,0,.2); }
#locateBtn.active { color: var(--clr-primary); }

#homeBtn {
  position: absolute;
  bottom: 2rem;
  right: .75rem;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .15s;
}
#homeBtn:hover { box-shadow: 0 4px 14px rgba(0,0,0,.2); }

/* ── Panel (slide-up) ── */
.panel-overlay {
  position: fixed; inset: 0; background: #0a0a0aad;
  z-index: 2000; display: none; align-items: flex-end;
}
.panel-overlay.open { display: flex; }

.panel {
  background: var(--clr-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-height: 85dvh;
  overflow-y: auto; padding: 1.25rem;
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.panel-header {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: 1rem;
}
.panel-header h2 { flex: 1; font-size: 1.1rem; }
.panel-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--clr-muted); }

/* ── Status badge ── */
.badge {
  display: inline-block; padding: .2rem .6rem;
  border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge-not_visited        { background: #e5e7eb; color: #374151; }
.badge-no_answer          { background: #fef3c7; color: #92400e; }
.badge-didnt_want_to_talk { background: #fee2e2; color: #991b1b; }
.badge-responded          { background: #dcfce7; color: #166534; }

/* ── Visit history ── */
.visit-list { margin-top: 1rem; }
.visit-item {
  border-left: 3px solid var(--clr-hbc);
  padding: .5rem .75rem; margin-bottom: .5rem;
  background: #f3f4f6; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .875rem;
}
.visit-item .meta { color: var(--clr-muted); font-size: .75rem; margin-top: .2rem; }

/* ── Error message ── */
.error-msg { color: var(--clr-danger); font-size: .875rem; margin-top: .5rem; }

/* ── Toast notification ── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: #1f2937;
  color: #fff;
  padding: .65rem 1.2rem;
  border-radius: var(--radius);
  font-size: .9rem;
  max-width: calc(100vw - 2rem);
  text-align: center;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: transform .25s ease, opacity .25s ease;
  opacity: 0;
  pointer-events: none;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
#toast.toast-error { background: var(--clr-danger); }

/* ── Admin nav ── */
.admin-nav {
  display: flex;
  gap: .25rem;
  padding: .6rem .75rem;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}
.admin-nav-link {
  padding: .35rem .85rem;
  border-radius: 999px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--clr-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.admin-nav-link:hover { background: #f3f4f6; color: #111; }
.admin-nav-link.active { background: var(--clr-hbc); color: #fff; }

/* ── Stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .75rem;
}
@media (max-width: 500px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

.stat-card {
  background: var(--clr-card);
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem .5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.stat-card:hover { border-color: var(--clr-hbc); }
.stat-card.active {
  border-color: var(--clr-hbc);
  background: var(--clr-hbc);
}
.stat-number {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--clr-hbc);
}
.stat-card.active .stat-number { color: #fff; }
.stat-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat-card.active .stat-label { color: rgba(255,255,255,.8); }

/* ── Bar chart ── */
.bar-chart-wrap {
  overflow-x: auto;
}
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: .4rem;
  height: 160px;
  min-width: 100%;
  padding-bottom: 1.75rem;
  position: relative;
}
.bar-col {
  flex: 1;
  min-width: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
}
.bar {
  width: 100%;
  background: var(--clr-hbc);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  transition: height .3s ease;
}
.bar-count {
  font-size: .7rem;
  font-weight: 700;
  color: var(--clr-muted);
  margin-bottom: .2rem;
  min-height: 1em;
}
.bar-label {
  position: absolute;
  bottom: -1.5rem;
  font-size: .7rem;
  color: var(--clr-muted);
  white-space: nowrap;
}

/* ── Stat section header ── */
.stat-section-header { margin-bottom: .25rem; }
.stat-section-header h2 { font-size: 1rem; font-weight: 700; margin-bottom: .2rem; }
.stat-section-header p  { font-size: .8rem; color: var(--clr-muted); }

/* ── Overview grid ── */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
}
.overview-card {
  background: var(--clr-card);
  border: 2px solid #e5e7eb;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem .75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  text-align: center;
}
.overview-note {
  font-size: .7rem;
  color: var(--clr-muted);
  margin-top: .1rem;
}

/* ── Good houses list ── */
.good-house-item {
  padding: .65rem .75rem;
  border-left: 3px solid var(--clr-success);
  background: #f0fdf4;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: .5rem;
}
.good-house-address {
  font-weight: 600;
  font-size: .9rem;
}
.good-house-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .2rem;
  font-size: .775rem;
  color: var(--clr-muted);
}
.good-house-type {
  background: #e0f2fe;
  color: #0369a1;
  border-radius: 999px;
  padding: .1rem .5rem;
  font-weight: 600;
  font-size: .7rem;
}
.good-house-date { color: var(--clr-muted); }

/* ── Admin page ── */
.admin-wrap {
  max-width: 480px;
  margin: 2rem auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.admin-card {
  background: var(--clr-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}
.admin-card h2 {
  font-size: 1.05rem;
  color: var(--clr-hbc);
  padding-bottom: .75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}

/* ── Confirm dialog ── */
.confirm-overlay {
  position: fixed; inset: 0; background: #0a0a0aad;
  z-index: 3000; display: none;
  align-items: center; justify-content: center; padding: 1rem;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: #fff; border-radius: var(--radius);
  padding: 1.5rem; width: 100%; max-width: 320px;
  box-shadow: var(--shadow);
}
.confirm-box p { margin-bottom: 1rem; }
.confirm-actions { display: flex; gap: .75rem; justify-content: flex-end; }
