@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
  color-scheme: light;
  --navy: #083b66;
  --navy-soft: #0c527f;
  --blue: #238ac5;
  --cream: #f5f2eb;
  --paper: #faf9f6;
  --pale: #e8f1f5;
  --line: #083b6618;
  --line-strong: #083b6626;
  --muted: #4d6574;
  --danger: #8d2f2a;
  --danger-bg: #fdeceb;
  --ok: #0d6b45;
  --shadow: 0 18px 50px #083b6614;
  font-family: 'DM Sans', 'Segoe UI', sans-serif;
  color: var(--navy);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1, h2, .stat strong {
  font-family: Manrope, 'DM Sans', sans-serif;
  letter-spacing: -.04em;
}
h1 { font-size: clamp(1.7rem, 3vw, 2.5rem); line-height: 1.12; }
h2 { font-size: 1.35rem; line-height: 1.2; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea, .primary, .outline, .danger { min-height: 44px; }
textarea { min-height: 96px; resize: vertical; }
input, select, textarea {
  width: 100%;
  border: 1px solid #c9d7de;
  background-color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--navy);
  outline: none;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23083B66' stroke-width='1.6' stroke-linecap='round' d='M1 1.5 6 6.5 11 1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
#search {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'><circle cx='7' cy='7' r='4.2' fill='none' stroke='%234d6574' stroke-width='1.6'/><path d='M10.4 10.4 14 14' fill='none' stroke='%234d6574' stroke-width='1.6' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  padding-left: 40px;
}
::placeholder { color: #5c7384; opacity: 1; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #238ac533; }
button:focus-visible, a:focus-visible, .stat:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
label { display: block; font-weight: 700; font-size: .875rem; margin: 14px 0 6px; }
.eyebrow {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #0c648c;
  margin-bottom: 8px;
}
.brand-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--blue);
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 22px;
}
.primary, .outline, .danger { border-radius: 12px; padding: 12px 16px; font-weight: 700; border: 0; }
.primary { background: var(--navy); color: #fff; }
.primary:hover { background: var(--navy-soft); }
.outline { background: #fff; color: var(--navy); border: 1px solid #c5d5de; }
.outline:hover { background: var(--pale); }
.danger { background: var(--danger-bg); color: var(--danger); }
.danger:hover { background: #fbdcd9; }
button:disabled { cursor: wait; opacity: .65; }
.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 80;
  background: #fff;
  color: var(--navy);
  padding: 8px 12px;
  border-radius: 10px;
}
.skip:focus { top: 12px; }

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 10%, #d7e7ef 0, transparent 32%),
    var(--cream);
  color: var(--muted);
}

.login {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(280px, 1.15fr) minmax(300px, .85fr);
  background: var(--navy);
}
.login-aside {
  color: #fff;
  padding: clamp(28px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  background:
    radial-gradient(circle at 18% 16%, #238ac55c, transparent 42%),
    var(--navy);
}
.login-aside .brand-icon { margin-bottom: 28px; }
.login-aside .eyebrow { color: #b7d9ec; }
.login-aside h1 { max-width: 11ch; color: #fff; font-size: clamp(2.5rem, 5vw, 4.1rem); }
.login-aside h1::after {
  content: "";
  display: block;
  width: 64px;
  height: 3px;
  margin-top: 22px;
  background: var(--blue);
}
.login-aside p { max-width: 36ch; margin-top: 18px; line-height: 1.6; color: #d5e4ee; }
.aside-foot { margin-top: 0; font-size: .85rem; letter-spacing: .04em; color: #9fb8c9; }
.login-panel { background: var(--cream); display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); }
.login-card h2 { font-size: 1.7rem; }
.lede { color: var(--muted); line-height: 1.5; margin: 8px 0 18px; }
.login-card form .primary { width: 100%; margin-top: 16px; }
.login-card small { display: block; color: var(--muted); line-height: 1.45; margin-top: 8px; }
.password-field { position: relative; }
.password-field input { padding-right: 96px; }
.password-field .text-button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 36px;
  padding: 6px 8px;
}
.error { color: var(--danger); font-size: .875rem; margin: 0; }
.error:not(:empty) {
  background: var(--danger-bg);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 12px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  flex-wrap: wrap;
  padding: max(14px, env(safe-area-inset-top)) max(4vw, 20px) 14px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Manrope, sans-serif; letter-spacing: -.03em; }
.brand small {
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  font-size: .62rem;
  margin-top: 2px;
}
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; margin-left: auto; }
#user-name {
  background: var(--pale);
  color: var(--navy);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: .8rem;
  font-weight: 700;
}
.text-button, .close, .view-tab, .stat, .legend-item, .visit-detail {
  background: none;
  border: 0;
  color: inherit;
}
.text-button, .close { color: var(--navy); font-weight: 700; border-radius: 999px; }
.top-actions .text-button { padding: 8px 10px; }
.top-actions .text-button:hover { background: var(--pale); }
#logout { color: var(--danger); }

.layout { max-width: 1440px; margin: auto; padding: 28px max(4vw, 20px) max(48px, env(safe-area-inset-bottom)); }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.intro > div > p:last-child { color: var(--muted); margin-top: 8px; max-width: 46ch; line-height: 1.5; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent, var(--navy));
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 1px 0 #083b6608;
}
.stat:hover { background: #fff; border-color: #083b6630; }
.stat.is-active { background: var(--pale); border-color: #238ac566; }
.stat span, .stat strong { display: block; }
.stat span { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat strong { font-size: clamp(1.5rem, 2vw, 1.9rem); margin-top: 6px; }
.view-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: min(100%, 380px);
  padding: 4px;
  margin-bottom: 16px;
  background: #e6eeea;
  border-radius: 14px;
}
.view-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 11px;
  padding: 10px 14px;
  font-weight: 700;
  color: var(--muted);
}
.view-tab.active { background: #fff; color: var(--navy); box-shadow: 0 1px 2px #083b6618; }
.tab-count {
  min-width: 1.5rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--pale);
  color: var(--navy);
  font-size: .75rem;
}
.workspace { min-width: 0; }
.map-card, .list-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.section-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.section-title .eyebrow { margin-bottom: 4px; }
.section-summary { color: var(--muted); font-size: .85rem; margin-top: 4px; white-space: nowrap; }
.title-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.title-actions .outline { padding: 10px 12px; white-space: nowrap; }
.map-controls, .list-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.map-controls select, .list-tools select { width: auto; min-width: 0; flex: 1; }
.list-tools { display: grid; grid-template-columns: 1fr 1fr; }
#search { grid-column: 1 / -1; }
.map-frame { position: relative; }
#map { height: min(68dvh, 640px); min-height: 340px; border-radius: 14px; background: #d5e3ea; z-index: 0; }
.map-frame .location-status {
  position: absolute;
  z-index: 650;
  left: 12px;
  right: 12px;
  bottom: 28px;
  margin: 0;
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 10px 28px #083b6630;
}
.map-frame .location-status.location-error { color: var(--danger); background: #fff6f5; }
.location-status:empty { display: none; }
.location-error { color: var(--danger); }
#location-label.is-set, #pick-label.is-set {
  background: var(--pale);
  color: var(--navy);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
}
label .hint { margin: 0; font-weight: 500; }
#location-label.location-error {
  background: #fff6f5;
  border-radius: 12px;
  padding: 10px 12px;
}
.map-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 32px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: capitalize;
}
.legend-item.is-active { background: var(--pale); border-color: var(--blue); }
.legend-static { cursor: default; text-transform: none; }
.legend-dot, .badge-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.legend-church {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 9px;
  line-height: 1;
}
.map-note, .hint { font-size: .82rem; line-height: 1.5; color: var(--muted); margin: 10px 0; }
.callout { background: var(--pale); border-radius: 12px; padding: 10px 12px; color: #3e5666; }
.visits-list { overflow: auto; max-height: min(68dvh, 720px); overscroll-behavior: contain; }
.visit-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "check info badge" "check info map";
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  border-bottom: 1px solid #edf2f1;
  border-left: 4px solid var(--row-color, var(--blue));
  border-radius: 12px;
  background: #fff;
  padding: 12px 10px;
  color: var(--navy);
}
.visit-row:hover { background: #f6faf8; }
.visit-row.is-selected { background: var(--pale); border-color: #238ac540; }
.home-check { grid-area: check; width: 22px; height: 22px; margin: 0; accent-color: var(--navy); }
.visit-detail { grid-area: info; text-align: left; padding: 0; min-width: 0; }
.visit-detail strong, .visit-meta { display: block; }
.visit-detail strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visit-meta {
  color: var(--muted);
  margin-top: 3px;
  font-size: .8rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: normal;
}
.badge {
  grid-area: badge;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: capitalize;
  padding: 5px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.map-link { grid-area: map; justify-self: end; padding: 6px 2px; white-space: nowrap; font-size: .82rem; }
.empty { text-align: center; padding: 36px 12px 28px; color: var(--muted); }
.empty strong { display: block; font-family: Manrope, sans-serif; font-size: 1.15rem; color: var(--navy); margin-bottom: 6px; }
.empty p { margin-bottom: 4px; }
.empty .primary, .empty .outline { margin-top: 14px; }
.more-rows { width: 100%; margin-top: 8px; }

.pdf-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 2px 0 14px;
  padding: 14px;
  background: var(--pale);
  border-radius: 14px;
}
.pdf-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pdf-actions .primary, .pdf-actions .outline { flex: 1 1 140px; }
.pdf-actions .text-button { padding: 8px; }
.selection-count { margin: 0; font-weight: 700; color: var(--navy); }
.privacy-note { margin: 0; }
.pdf-message:empty { display: none; }
.pdf-message.is-ready { color: var(--ok); font-weight: 700; }
.pdf-message.is-error { color: var(--danger); font-weight: 700; }

dialog {
  border: 0;
  border-radius: 18px;
  padding: 22px 22px calc(22px + env(safe-area-inset-bottom));
  width: min(560px, calc(100vw - 24px));
  max-height: min(92dvh, 880px);
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--navy);
  box-shadow: 0 24px 80px #001e3759;
}
dialog::backdrop { background: #083b66c4; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.close { font-size: 28px; line-height: 1; width: 40px; height: 40px; }
.close:hover { background: var(--pale); }
.location-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#confirm-pick { width: 100%; margin-top: 8px; }
#visit-dialog[open] {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
#visit-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(92dvh, 880px);
  overflow: hidden;
}
.dialog-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 22px 22px 8px; }
.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}
#visit-error { margin: 0 22px; }
#visit-error:not(:empty) { margin: 8px 22px; }
.dialog-actions .primary { margin-left: auto; }
#history:empty { display: none; }
#history:not(:empty) { margin-top: 8px; }
.history-title { margin: 8px 0 12px; font-weight: 700; }
.history-item {
  position: relative;
  margin-left: 8px;
  padding: 0 0 14px 16px;
  border-left: 2px solid #d5e4ee;
  font-size: .84rem;
}
.history-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
}
.history-item p { margin-top: 4px; color: var(--muted); white-space: pre-wrap; }
.new-code {
  background: #e7f6ee;
  border: 1px solid #b7dfc8;
  border-radius: 14px;
  padding: 14px;
  margin: 14px 0;
}
.new-code p {
  white-space: pre-line;
  overflow-wrap: anywhere;
  margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95rem;
  font-weight: 700;
  color: var(--navy);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
}
#user-form .primary, #status-form .primary { margin-top: 12px; }
#status-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 10px;
  align-items: end;
}
#status-form label[for="new-color"] { grid-column: 2; }
#status-form .primary { grid-column: 1 / -1; justify-self: start; }
#new-color { width: 64px; height: 44px; padding: 4px; }
#users-list, #statuses-list { max-height: 42dvh; overflow: auto; }
.team-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #edf1ef;
  padding: 12px 0;
}
.team-row small { display: block; color: var(--muted); margin-top: 2px; text-transform: capitalize; }
.team-row.is-inactive { opacity: .62; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px 8px; }
.team-row input[type="color"] { width: 52px; height: 40px; padding: 3px; }
#statuses-list .team-row strong { text-transform: capitalize; }

.leaflet-tooltip.home-map-label {
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  font: 600 11px/1.3 'DM Sans', sans-serif;
  padding: 3px 6px;
  box-shadow: 0 1px 4px #001e3740;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leaflet-tooltip.home-map-label::before { display: none; }
.labels-hidden .leaflet-tooltip.home-map-label { visibility: hidden; }
.church-marker {
  background: var(--navy);
  color: #fff;
  border: 3px solid #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 18px;
  box-shadow: 0 2px 8px #083b6655;
}
.leaflet-bar { border: 0 !important; box-shadow: 0 8px 24px #083b6624 !important; overflow: hidden; }
.leaflet-bar a {
  background: #fff;
  color: var(--navy) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
}
.leaflet-control-attribution { font-size: 10px !important; background: #ffffffd4 !important; max-width: 68%; }

@media (min-width: 1100px) {
  .workspace { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, .9fr); gap: 18px; align-items: start; }
  .view-tabs { display: none; }
  .map-card { position: sticky; top: 84px; }
}

@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-aside { padding: 28px 22px 8px; min-height: auto; }
  .login-aside h1 { font-size: 2.4rem; }
  .login-aside h1::after { margin-top: 14px; }
  .login-panel { padding: 8px 16px 28px; align-items: start; }
  .aside-foot { display: none; }
}

@media (max-width: 800px) {
  .intro { align-items: stretch; flex-direction: column; margin-bottom: 14px; }
  .intro h1 { font-size: 1.6rem; }
  .add { width: 100%; }
  .stats { gap: 8px; margin-bottom: 12px; }
  .stat { padding: 12px; }
  .stat span { font-size: .72rem; }
  .list-tools { grid-template-columns: 1fr; }
  #map { height: min(62dvh, 460px); min-height: 280px; }
  .layout { padding-top: 16px; }
}

@media (max-width: 640px) {
  dialog[open] {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  #visit-form { max-height: none; flex: 1; }
  #pick-dialog[open] { display: flex; flex-direction: column; }
  #pick-map { flex: 1; height: auto; min-height: 220px; }
  .location-actions { grid-template-columns: 1fr; }
  .section-title { flex-direction: column; }
  .title-actions { width: 100%; justify-content: flex-start; }
  .title-actions .outline { flex: 1; }
  #map-layer { flex: 0 0 112px; width: 112px; }
  .pdf-actions { flex-direction: column; align-items: stretch; }
  .pdf-actions .text-button { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
