/* Import shared base (reset, fonts, CSS variables, dark mode) */
@import url("/shared/base.css");

/* ── Member Map additional variables ──────────────────────────────────────── */
:root {
  --bg-input-focus: #fff;
  --bg-selected: #e8eefc;
  --bg-muted: #fafafa;
  --text-subtle: #555d6b;
  --text-dark: #555;
  --border-divider: #f5f5f5;
  --border-btn: #ddd;
  --accent-bg-hover: #dde6ff;
  --accent-resize: rgba(37, 85, 239, 0.3);
  --orange-hover: #a85a10;
  --btn-secondary-bg: #e0e0e0;
  --btn-secondary-text: #333;
  --btn-secondary-hover: #ccc;
  --shadow-heavy: rgba(0,0,0,0.2);
  --progress-bg: #002e5c;
  --progress-track: rgba(255,255,255,0.15);
  --tooltip-bg: #002e5c;
  --popup-location: #5a6370;
  --shul-border: #fff;
  --logo-filter: none;
  --map-filter: none;
  --leaflet-attribution-bg: rgba(255,255,255,0.8);
  --leaflet-container-bg: #f3f6f9;
}

html.dark {
  --bg-input-focus: #1a1a2e;
  --bg-selected: #253a5e;
  --bg-muted: #1e2a3a;
  --text-subtle: #9eaabb;
  --text-dark: #b0bec5;
  --border-divider: #22304a;
  --border-btn: #3a4a6c;
  --accent-bg-hover: #253a5e;
  --accent-resize: rgba(64, 104, 215, 0.3);
  --orange-hover: #e67e22;
  --btn-secondary-bg: #2a3a5c;
  --btn-secondary-text: #c0c8d4;
  --btn-secondary-hover: #3a4a6c;
  --shadow-heavy: rgba(0,0,0,0.5);
  --progress-bg: #0f3460;
  --progress-track: rgba(255,255,255,0.1);
  --tooltip-bg: #0f3460;
  --popup-location: #a8b4c6;
  --shul-border: #16213e;
  --logo-filter: brightness(1.5) saturate(0.8);
  --map-filter: brightness(0.85) contrast(1.1) saturate(0.9);
  --leaflet-attribution-bg: rgba(22, 33, 62, 0.8);
  --leaflet-container-bg: #1a1a2e;
}

@media (prefers-color-scheme: dark) {
  html:not(.light):not(.dark) {
    --bg-input-focus: #1a1a2e;
    --bg-selected: #253a5e;
    --bg-muted: #1e2a3a;
    --text-subtle: #9eaabb;
    --text-dark: #b0bec5;
    --border-divider: #22304a;
    --border-btn: #3a4a6c;
    --accent-bg-hover: #253a5e;
    --accent-resize: rgba(64, 104, 215, 0.3);
    --orange-hover: #e67e22;
    --btn-secondary-bg: #2a3a5c;
    --btn-secondary-text: #c0c8d4;
    --btn-secondary-hover: #3a4a6c;
    --shadow-heavy: rgba(0,0,0,0.5);
    --progress-bg: #0f3460;
    --progress-track: rgba(255,255,255,0.1);
    --tooltip-bg: #0f3460;
    --popup-location: #a8b4c6;
    --shul-border: #16213e;
    --logo-filter: brightness(1.5) saturate(0.8);
    --map-filter: brightness(0.85) contrast(1.1) saturate(0.9);
    --leaflet-attribution-bg: rgba(22, 33, 62, 0.8);
    --leaflet-container-bg: #1a1a2e;
  }
}

/* ── Theme toggle ─────────────────────────────────── */
.theme-toggle {
  display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  font-size: 12px; flex-shrink: 0;
}
.theme-toggle button {
  background: var(--bg-input); border: none; color: var(--text-secondary); padding: 4px 10px;
  cursor: pointer; font-family: inherit; font-size: 12px; transition: all .15s;
  border-right: 1px solid var(--border); line-height: 1;
}
.theme-toggle button:last-child { border-right: none; }
.theme-toggle button:hover { background: var(--bg-hover); }
.theme-toggle button.active { background: var(--accent); color: #fff; }

/* ── Login ─────────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg-page);
}
.login-card {
  background: var(--bg-surface); border-radius: 12px; padding: 40px;
  box-shadow: 0 0 30px var(--shadow-card); width: 400px; max-width: 92vw; text-align: center;
}
.login-card img.logo { height: 36px; margin-bottom: 16px; filter: var(--logo-filter); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; color: var(--text-heading); font-weight: 600; }
.login-card p.sub { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; font-weight: 300; }
.login-card input[type="email"], .login-card input[type="password"] {
  width: 100%; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 16px; margin-bottom: 12px; outline: none; transition: border-color .2s, background .2s;
  background: var(--bg-input); font-family: inherit; color: var(--text-primary);
}
.login-card input:focus { border-color: var(--accent); background: var(--bg-input-focus); }
.login-card input::placeholder { color: var(--text-muted); }
.login-card button[type="submit"] {
  width: 100%; padding: 12px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; transition: background .2s;
  font-family: inherit;
}
.login-card button[type="submit"]:hover { background: var(--accent-hover); }
.login-card button[type="submit"]:disabled { background: var(--accent-disabled); cursor: not-allowed; }
.login-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.error-msg { color: var(--error); font-size: 12px; margin-bottom: 10px; min-height: 16px; font-weight: 400; }
.conn-status { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-muted); font-weight: 400; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.conn-dot.connected { background: var(--success); }
.conn-dot.disconnected { background: var(--error); }
.conn-dot.checking { background: var(--warning); }

/* ── App layout ───────────────────────────────────── */
#app-screen { display: none; height: 100vh; flex-direction: column; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: var(--bg-surface); color: var(--text-primary); gap: 8px; z-index: 10;
  border-bottom: 1px solid var(--border); height: 48px; flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-left img { height: 24px; filter: var(--logo-filter); }
header h1 { font-size: 15px; font-weight: 600; color: var(--text-heading); white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 6px; }
#user-display { font-size: 11px; color: var(--text-secondary); font-weight: 400; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hdr-btn {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-secondary); padding: 5px 8px;
  border-radius: 6px; font-size: 13px; cursor: pointer; font-family: inherit; transition: all .15s;
  text-decoration: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; line-height: 1;
}
.hdr-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#status-bar { display: flex; align-items: center; gap: 4px; font-size: 10px; color: var(--text-muted); flex-wrap: nowrap; flex-shrink: 1; overflow: hidden; }
#status-bar .stat { background: var(--bg-input); padding: 2px 8px; border-radius: 10px; color: var(--text-secondary); white-space: nowrap; font-size: 10px; }

/* ── Header overflow menu ────────────────────────── */
.hdr-menu-wrap { position: relative; }
.hdr-menu {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow-heavy); min-width: 180px; padding: 4px 0;
  z-index: 100;
}
.hdr-menu.open { display: block; }
.hdr-menu button, .hdr-menu a {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px;
  border: none; background: none; font-size: 13px; color: var(--text-primary);
  cursor: pointer; font-family: inherit; text-decoration: none; text-align: left;
  transition: background .1s;
}
.hdr-menu button:hover, .hdr-menu a:hover { background: var(--bg-hover); }
.hdr-menu hr {
  border: none; border-top: 1px solid var(--border-light); margin: 4px 0;
}
#app-body { flex: 1; display: flex; overflow: hidden; position: relative; }

/* ── Mobile panel toggle ──────────────────────────── */
#panel-toggle {
  display: none; position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  z-index: 1001; background: var(--accent); color: #fff; border: none; border-radius: 28px;
  padding: 10px 20px; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 16px var(--shadow-heavy); font-family: inherit;
}

/* ── Side panel ───────────────────────────────────── */
#side-panel {
  width: 340px; min-width: 200px; max-width: 600px; background: var(--bg-surface); display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden; position: relative; z-index: 5;
}
#panel-resize-handle {
  position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
  cursor: col-resize; z-index: 20; background: transparent;
}
#panel-resize-handle:hover, #panel-resize-handle.dragging { background: var(--accent); opacity: 0.3; }
#panel-header { padding: 12px; border-bottom: 1px solid var(--border); }
#panel-filter {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 16px; outline: none; margin-bottom: 8px; background: var(--bg-input); font-family: inherit;
  color: var(--text-primary);
}
#panel-filter:focus { border-color: var(--accent); background: var(--bg-input-focus); }
#panel-filter::placeholder { color: var(--text-muted); }
#panel-count { font-size: 11px; color: var(--text-muted); font-weight: 400; }
#panel-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel-item {
  padding: 10px 12px; border-bottom: 1px solid var(--border-divider); cursor: pointer;
  display: flex; align-items: center; gap: 10px; transition: background .15s;
}
.panel-item:hover { background: var(--bg-hover); }
.panel-item.selected { background: var(--bg-selected); }
.panel-item .pi-info { flex: 1; min-width: 0; }
.panel-item .pi-name { font-size: 13px; font-weight: 600; color: var(--text-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-item .pi-addr { font-size: 11px; color: var(--text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-item .pi-walk { font-size: 11px; color: var(--accent); white-space: nowrap; }
.panel-item .pi-actions { display: flex; gap: 4px; flex-shrink: 0; }
.pi-btn {
  background: none; border: 1px solid var(--border-btn); border-radius: 6px; padding: 3px 7px;
  font-size: 11px; cursor: pointer; color: var(--text-dark); transition: all .15s;
}
.pi-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#panel-walk-mode {
  padding: 10px 12px; border-top: 1px solid var(--border-light); background: var(--bg-muted);
}
#walk-info { font-size: 12px; color: var(--text-body); line-height: 1.6; min-height: 20px; }
.walk-btn {
  padding: 6px 12px; border: none; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-weight: 600; transition: background .15s; margin-right: 6px; margin-top: 6px;
}
.walk-btn-primary { background: var(--accent); color: #fff; }
.walk-btn-primary:hover { background: var(--accent-hover); }
.walk-btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); }
.walk-btn-secondary:hover { background: var(--btn-secondary-hover); }

/* ── Map ───────────────────────────────────────────── */
#map-container { flex: 1; position: relative; }
#map { height: 100%; width: 100%; filter: var(--map-filter); }

/* ── Progress banner ──────────────────────────────── */
#progress-banner {
  display: none; position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: var(--progress-bg); color: #fff; padding: 10px 20px;
  border-radius: 8px; box-shadow: 0 4px 20px var(--shadow-heavy);
  font-size: 12px; max-width: 420px; text-align: center; pointer-events: none;
}
#progress-banner .bar-track { height: 3px; background: var(--progress-track); border-radius: 2px; margin-top: 8px; overflow: hidden; }
#progress-banner .bar-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s ease; width: 0%; }

/* ── Popup ─────────────────────────────────────────── */
.member-popup { min-width: 220px; max-width: 340px; max-height: 360px; overflow-y: auto; }
.member-popup .location-header { font-size: 12px; color: var(--popup-location); margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border-light); }
.member-card { padding: 8px 0; }
.member-card + .member-card { border-top: 1px solid var(--border-card); }
.member-card h3 { font-size: 13px; margin-bottom: 2px; color: var(--text-heading); font-weight: 600; }
.member-card .family { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.member-card .detail { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.member-card .detail a { color: var(--accent); text-decoration: none; }
.member-card .detail a:hover { text-decoration: underline; }
.member-count-badge { display: inline-block; background: var(--accent); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; margin-left: 6px; vertical-align: middle; }
.admin-link { display: inline-block; margin-top: 4px; font-size: 11px; color: var(--accent); text-decoration: none; background: var(--accent-bg); padding: 2px 8px; border-radius: 4px; }
.admin-link:hover { background: var(--accent-bg-hover); text-decoration: none; }
.walk-link { display: inline-block; margin-top: 4px; margin-left: 4px; font-size: 11px; color: #fff; text-decoration: none; background: var(--accent); padding: 2px 8px; border-radius: 4px; cursor: pointer; }
.walk-link:hover { background: var(--accent-hover); }
.walk-link-orange { background: var(--orange); }
.walk-link-orange:hover { background: var(--orange-hover); }

/* ── Family grouping ──────────────────────────────── */
.family-group { border-bottom: 1px solid var(--border-light); }
.family-header {
  padding: 10px 12px 4px; font-size: 13px; font-weight: 600; color: var(--text-heading);
  cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.family-header .fh-count { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.family-header .fh-addr { font-size: 11px; color: var(--text-faint); font-weight: 400; margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.family-actions { padding: 2px 12px 8px; display: flex; gap: 4px; }
.family-member {
  padding: 2px 12px 2px 28px; font-size: 12px; color: var(--text-secondary);
}
.family-member:last-child { padding-bottom: 8px; }
.family-member .fm-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Walk selection mode ──────────────────────────── */
.walk-pick-badge {
  display: inline-block; background: var(--orange); color: #fff; font-size: 10px;
  padding: 0 6px; border-radius: 8px; margin-left: 4px;
}
.shul-popup { min-width: 200px; text-align: center; }
.shul-popup h3 { font-size: 16px; color: var(--text-heading); margin-bottom: 4px; }
.shul-popup .addr { font-size: 12px; color: var(--popup-location); }
.shul-icon { background: var(--accent); border: 3px solid var(--shul-border); border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; font-size: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

/* ── Marker tooltip ───────────────────────────────── */
.marker-tooltip {
  background: var(--tooltip-bg); color: #fff; border: none; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; font-weight: 500; box-shadow: 0 2px 8px var(--shadow-heavy);
  font-family: 'Poppins', sans-serif;
}
.marker-tooltip::before { border-top-color: var(--tooltip-bg) !important; }

/* ── Leaflet overrides (always, via variables) ───── */
.leaflet-popup-content-wrapper { background: var(--bg-surface); color: var(--text-primary); }
.leaflet-popup-tip { background: var(--bg-surface); }
.leaflet-bar a { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--bg-hover); }
.leaflet-control-attribution { background: var(--leaflet-attribution-bg) !important; color: var(--text-muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-container { background: var(--leaflet-container-bg); }
.login-card label { color: var(--remember-label); }

/* ── Tag filter bar ──────────────────────────────── */
#tag-filter-bar {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; min-height: 0;
}
#tag-filter-bar:empty { display: none; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px;
  border-radius: 12px; font-size: 11px; cursor: pointer; transition: all .15s;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text-secondary);
  user-select: none;
}
.tag-chip:hover { background: var(--bg-hover); }
.tag-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Member detail panel ─────────────────────────── */
#member-detail {
  padding: 12px; border-bottom: 1px solid var(--border); background: var(--bg-muted);
  max-height: 50%; overflow-y: auto;
}
#member-detail .detail-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
#member-detail .detail-header h3 { font-size: 14px; color: var(--text-heading); font-weight: 600; }
#member-detail .detail-close {
  background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted); padding: 2px 6px;
}
#member-detail .detail-close:hover { color: var(--text-primary); }
#member-detail .detail-row { font-size: 12px; color: var(--text-secondary); line-height: 1.8; }
#member-detail .detail-row a { color: var(--accent); text-decoration: none; }
#member-detail .detail-row a:hover { text-decoration: underline; }
#member-detail .detail-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
#member-detail .detail-tag {
  padding: 1px 8px; border-radius: 10px; font-size: 10px;
  background: var(--accent-bg); color: var(--accent); border: 1px solid var(--border);
}

/* ── Map overlay controls ────────────────────────── */
#map-overlay-controls {
  position: absolute; top: 10px; right: 10px; z-index: 1000;
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 12px; color: var(--text-secondary);
  box-shadow: 0 2px 8px var(--shadow-card);
}
#map-overlay-controls label { display: flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
#map-overlay-controls select {
  font-size: 11px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg-input); color: var(--text-primary); font-family: inherit;
}

/* ── Hospitality matcher ─────────────────────────── */
.hospitality-match {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; border-bottom: 1px solid var(--border-divider); transition: background .15s;
}
.hospitality-match:hover { background: var(--bg-hover); border-radius: 6px; }
.hospitality-match:last-child { border-bottom: none; }
.hospitality-name { font-size: 13px; font-weight: 500; color: var(--text-heading); }
.hospitality-dist { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ── Modal dialogs ───────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--bg-surface); border-radius: 12px;
  box-shadow: 0 8px 40px var(--shadow-heavy);
  width: 560px; max-width: 95vw; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 600; color: var(--text-heading); margin: 0; }
.modal-close {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-muted); padding: 4px 8px; border-radius: 6px; transition: all .15s;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body {
  padding: 20px; overflow-y: auto; font-size: 13px; color: var(--text-body); line-height: 1.7;
}
.modal-body h3 {
  font-size: 14px; font-weight: 600; color: var(--text-heading);
  margin: 16px 0 8px 0; padding-bottom: 4px; border-bottom: 1px solid var(--border-light);
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body ul { padding-left: 20px; margin: 0 0 8px 0; }
.modal-body li { margin-bottom: 4px; }
.modal-body b { color: var(--text-heading); }

/* ── Print styles ────────────────────────────────── */
@media print {
  #login-screen, header, #panel-walk-mode, #panel-resize-handle,
  #panel-toggle, #map-overlay-controls, #progress-banner,
  .modal-overlay { display: none !important; }
  #app-screen { display: flex !important; height: auto !important; }
  #app-body { flex-direction: column !important; overflow: visible !important; height: auto !important; }
  #side-panel {
    width: 100% !important; max-width: none !important; min-width: 0 !important;
    border-right: none !important; overflow: visible !important; height: auto !important;
    position: static !important; transform: none !important;
  }
  #map-container { height: 400px !important; width: 100% !important; break-before: page; }
  #map { filter: none !important; }
  .family-group { break-inside: avoid; }
  .pi-btn { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  * { color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ── Responsive: tablets (≤900px) ─────────────────── */
@media (max-width: 900px) {
  #status-bar { display: none; }
  #side-panel { width: 260px; min-width: 180px; }
}

/* ── Responsive: mobile (≤640px) ──────────────────── */
@media (max-width: 640px) {
  header { padding: 4px 8px; height: 44px; }
  header h1 { font-size: 13px; }
  .header-left img { height: 20px; }
  .header-right { gap: 4px; }
  .hdr-btn { padding: 4px 6px; font-size: 12px; }
  #user-display { display: none; }
  #app-conn-text { display: none; }
  .theme-toggle { display: none; }

  #app-body { flex-direction: column; }

  #side-panel {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important; max-width: none; min-width: 0;
    z-index: 900; border-right: none;
    transform: translateY(100%); transition: transform .3s ease;
  }
  #side-panel.panel-open {
    transform: translateY(0);
  }
  #panel-resize-handle { display: none; }
  #panel-walk-mode { padding-bottom: 70px; }

  #panel-toggle { display: block; }

  #map-container { flex: 1; width: 100%; }

  #progress-banner { max-width: 90vw; font-size: 11px; padding: 8px 14px; }

  .login-card { padding: 24px 20px; }
  .login-card h1 { font-size: 18px; }
  .login-footer { flex-direction: column; gap: 10px; }

  #map-overlay-controls { font-size: 11px; padding: 4px 8px; gap: 6px; }
}
