/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a5276;
  --primary-dark: #154360;
  --primary-light: #d6eaf8;
  --accent: #2980b9;
  --text: #1a1a2e;
  --text-sub: #5d6d7e;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dce3ea;
  --amber: #f39c12;
  --amber-bg: #fef9e7;
  --red: #c0392b;
  --green: #27ae60;
  --tab-height: 60px;
  --header-height: 56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: 0 0 20px rgba(0,0,0,0.08);
  padding-top: env(safe-area-inset-top);
}

#app.hidden { display: none; }
.hidden { display: none; }

#banners { flex-shrink: 0; }

#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* ── Banners ─────────────────────────────────────────────────────────────── */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
}

.banner-update {
  background: var(--amber-bg);
  color: #7d4e00;
  border-bottom: 1px solid var(--amber);
}

.banner-offline {
  background: #fdecea;
  color: var(--red);
  border-bottom: 1px solid #f1948a;
}

.banner-ama {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-bottom: 1px solid #aed6f1;
}

.banner-actions { display: flex; gap: 8px; flex-shrink: 0; }

.banner-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.banner-btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: white;
}

/* ── Tab Bar ─────────────────────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  height: var(--tab-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  padding: 8px 0;
}

.tab-btn .tab-icon { font-size: 20px; }
.tab-btn.active { color: var(--primary); }

/* ── List Header (sticky search + sort) ──────────────────────────────────── */
.list-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.search-input:focus { border-color: var(--primary); }

.sort-toggle {
  display: flex;
  gap: 6px;
}

.sort-btn {
  flex: 1;
  padding: 7px 0;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-sub);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.sort-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── Item List ───────────────────────────────────────────────────────────── */
.item-list {
  padding: 0;
}

.list-item {
  min-height: 60px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
}

.list-item:active { background: var(--primary-light); }

.item-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

.item-sub {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.3;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-sub);
  font-size: 15px;
}

/* ── View Title ──────────────────────────────────────────────────────────── */
.view-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  padding: 4px 0;
}

/* ── Detail View ─────────────────────────────────────────────────────────── */
.detail-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.back-btn:active { background: rgba(255,255,255,0.35); }

.detail-title {
  color: white;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-body {
  padding: 20px 16px 120px; /* room for action bar */
}

.detail-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 20px;
  line-height: 1.2;
}

.detail-photo {
  width: 88px;
  height: 88px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 12px;
}

.detail-photo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  background: var(--border);
  color: var(--text-sub);
}

.detail-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-section:last-child { border-bottom: none; }

.detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
}

.phone-link, .email-link {
  color: var(--accent);
  text-decoration: none;
}

.church-address-link {
  display: block;
  text-decoration: none;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  -webkit-tap-highlight-color: transparent;
}

.church-address-link:active {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.church-address-street {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.church-address-city {
  font-size: 14px;
  color: var(--text-sub);
  margin-top: 2px;
}

.church-directions-hint {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.church-directions-hint::before {
  content: "↗";
  font-size: 13px;
}

.tag {
  font-size: 10px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-volunteer {
  background: var(--amber-bg);
  color: #7d4e00;
}

.volunteer-disclaimer {
  display: block;
  line-height: 1.4;
  padding: 10px 16px;
}

/* ── Action Bar ──────────────────────────────────────────────────────────── */
.action-bar {
  position: fixed;
  bottom: var(--tab-height);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.action-btn {
  flex: 1;
  display: block;
  padding: 11px 4px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.action-btn:active { opacity: 0.75; }

.action-call   { background: var(--green);   color: white; }
.action-text   { background: #8e44ad;        color: white; }
.action-email  { background: var(--accent);  color: white; }
.action-contact{ background: var(--primary); color: white; }


/* ── Support Page ────────────────────────────────────────────────────────── */
.support-body {
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.support-tagline {
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.4;
  font-style: italic;
  text-align: center;
  padding: 8px 0;
}

.support-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.support-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-sub);
}

.support-section-desc {
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.4;
  margin-top: -4px;
}

.support-btn {
  display: block;
  padding: 13px 16px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: var(--primary);
  color: white;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}

.support-btn:active { opacity: 0.75; }

/* ── AMA Meetings ─────────────────────────────────────────────────────────── */
.section-divider {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-sub);
  padding: 8px 16px 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.meetings-section {
  border-bottom: 1px solid var(--border);
}

.meetings-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-sub);
  padding: 10px 16px 4px;
}

.meeting-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.meeting-item:last-child { border-bottom: none; }

.meeting-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  min-width: 52px;
  flex-shrink: 0;
}

.meeting-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.meeting-group {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.meeting-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  width: fit-content;
}

.meeting-badge-ministerial   { background: #e8f8f5; color: #1a7d6e; }
.meeting-badge-administration { background: #fdecea; color: var(--red); }
.meeting-badge-holiday        { background: #eafaf1; color: #1e8449; }
.meeting-badge-local          { background: var(--bg); color: var(--text-sub); }

.meeting-cal-btn {
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.meeting-cal-btn:active { background: var(--primary-light); }

.support-btn-alt {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.support-btn-thai {
  background: var(--amber);
  color: white;
}

.support-story {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.support-story p {
  font-size: 15px;
  color: var(--text);
  line-height: 1.6;
}

.support-story p + p { margin-top: 12px; }

/* ── Login Screen ────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

#login-screen.hidden { display: none; }

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 28px 36px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 4px 32px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  margin-bottom: 4px;
}

.login-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-sub);
  margin: 0 0 12px;
}

.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: white;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.google-btn:active { background: var(--bg); }

.login-error {
  font-size: 13px;
  color: var(--red);
  background: #fdecea;
  border-radius: 8px;
  padding: 10px 14px;
  width: 100%;
  line-height: 1.4;
}

.login-error.hidden { display: none; }

/* ── Admin View ──────────────────────────────────────────────────────────── */
.admin-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-add-row .search-input { flex: 1; }
.admin-add-row .support-btn  { flex-shrink: 0; width: auto; padding: 13px 20px; }

.admin-email-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.admin-email-row:last-child { border-bottom: none; }

.admin-email-info { flex: 1; min-width: 0; }
.admin-email-info .item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.admin-delete-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1.5px solid var(--red);
  border-radius: 8px;
  background: transparent;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.admin-delete-btn:disabled { opacity: 0.5; }

.admin-email-actions { display: flex; gap: 6px; flex-shrink: 0; }

.admin-map-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.admin-no-mapping { color: var(--text-sub); font-style: italic; }

.admin-map-form {
  padding: 8px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.admin-map-form.hidden { display: none; }

.admin-map-row-btns { display: flex; gap: 8px; }
.admin-map-row-btns .support-btn { font-size: 13px; padding: 9px 4px; }

.admin-activity-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.admin-activity-row:last-child { border-bottom: none; }

.admin-activity-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}
.admin-activity-avatar-placeholder { background: var(--border); }

.admin-activity-info { flex: 1; min-width: 0; }
.admin-activity-info .item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.admin-version-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.admin-version-badge.current  { background: #d5f5e3; color: var(--green); }
.admin-version-badge.outdated { background: var(--amber-bg); color: var(--amber); }
.admin-version-badge.unknown  { background: var(--bg); color: var(--text-sub); }

/* ── Group actions (AMA) ─────────────────────────────────────────────────── */
.group-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
