:root {
  --bg-color: #0f172a;
  --text-color: #f8fafc;
  --primary-color: #3b82f6;
  --primary-glow: #60a5fa;
  --accent-color: #8b5cf6;
  --accent-glow: #a78bfa;
  --glass-bg: rgba(15, 23, 42, 0.80);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 8px 32px 0 rgba(0,0,0,0.36);
  --danger-color: #ef4444;
  --success-color: #10b981;
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none; }

body {
  font-family: var(--font-main);
  background: var(--bg-color);
  color: var(--text-color);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow: hidden;
}

#app { width: 100vw; height: 100vh; position: relative; overflow: hidden; }

/* MAP */
#map-container { position: absolute; inset: 0; z-index: 0; }
#map { width: 100%; height: 100%; }
.leaflet-container { width: 100%; height: 100%; z-index: 0; }

/* GLASS */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
}

/* OVERLAY BASE */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 100px; /* keep bottom nav from covering the panel */
  pointer-events: none;
}
.overlay.hidden { display: none; }
.overlay > * { pointer-events: auto; }

/* FORM PANEL */
.form-panel {
  margin: 70px 12px 0;
  padding: 12px;
  width: calc(100% - 24px);
  max-width: 440px;
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: flex-start;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 18px;
}
.form-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.form-panel h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; text-align: center; }

td .input-field, .input-field {
  font-size: 0.9rem;
}
textarea.input-field { min-height: 56px; }
.row-group { gap: 8px; }
.btn, .btn-sm, .btn-icon { padding: 10px 16px; }
.btn-icon { width: 42px; height: 42px; }

#form-overlay, #import-confirm, #list-overlay {
  align-items: flex-start;
}

#import-confirm .import-confirm-panel {
  margin: 70px 16px 0;
  width: calc(100% - 32px);
  max-width: 380px;
  padding: 26px 22px;
  border-radius: 20px;
}

/* INPUT FIELDS */
.input-field {
  padding: 12px 14px;
  color: white;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--glass-border) !important;
  border-radius: 12px;
  font-family: var(--font-main);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
.input-field::placeholder { color: rgba(255,255,255,0.35); }
.input-field:focus { border-color: rgba(59,130,246,0.5) !important; }

textarea.input-field { resize: vertical; min-height: 40px; }

.input-wrapper { position: relative; }
.row-group { display: flex; gap: 10px; align-items: center; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.8rem; opacity: 0.75; margin-left: 4px; }

/* SUGGESTIONS */
.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 200;
  background: rgba(15,23,42,0.97);
  border: 1px solid var(--glass-border);
  max-height: 200px;
  overflow-y: auto;
  border-radius: 12px;
}
.suggestions-dropdown.hidden { display: none; }
.suggestion-item {
  padding: 10px 15px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: rgba(255,255,255,0.07); }
.suggestion-name { font-size: 0.9rem; font-weight: 600; }
.suggestion-sub { font-size: 0.75rem; opacity: 0.6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* BUTTONS */
.btn {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  color: white;
  font-size: 0.95rem;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  box-shadow: 0 4px 15px rgba(59,130,246,0.35);
}
.btn-secondary {
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--glass-border) !important;
}
.btn-danger {
  background: rgba(239,68,68,0.2);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,0.3) !important;
}
.btn-icon {
  background: rgba(139,92,246,0.25);
  padding: 0 14px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; width: 44px; flex-shrink: 0;
}
.btn-location {
  background: rgba(59,130,246,0.2);
  border: 1px solid rgba(255,255,255,0.15) !important;
  text-align: center;
}
.btn-location.selected { background: rgba(16,185,129,0.2); font-size: 0.75rem; }

.btn-sm {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  color: white;
}
.btn-primary.btn-sm { background: linear-gradient(135deg, var(--primary-color), var(--accent-color)); }
.btn-secondary.btn-sm { background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border) !important; }

/* SPINNER */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
.spinner.hidden { display: none; }

/* SMART IMPORT CONFIRM */
.import-confirm-panel {
  width: 280px;
  padding: 20px 16px;
  display: flex; flex-direction: row; align-items: flex-start;
  margin: auto;
  margin-top: 120px;
  gap: 10px;
}
.import-main {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px;
  min-width: 0;
}
.form-tags {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  width: 72px;
  padding-top: 2px;
}
.tags-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.45;
  text-align: center;
  margin-bottom: 2px;
}
.tag-chip {
  font-size: 0.63rem;
  padding: 5px 3px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.15);
  text-align: center;
  color: rgba(255,255,255,0.6);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
}
.tag-chip.selected {
  border-color: #10b981;
  color: #10b981;
  background: rgba(16,185,129,0.15);
}
.import-location-name { font-size: 1.1rem; font-weight: 700; color: var(--success-color); }
.import-action-btn { flex: 1; padding: 7px 4px; font-size: 0.75rem; }
.import-title-approximate { color: #eab308; }

/* LIST PANEL */
.list-panel {
  margin: 16px;
  margin-top: 80px;
  padding: 20px;
  width: calc(100% - 32px);
  max-width: 480px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 14px;
}
.list-header { display: flex; justify-content: space-between; align-items: center; }
.list-header h2 { font-size: 1.2rem; font-weight: 700; }
.list-header-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-tag-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.list-tag-chip { font-size: 0.6rem; padding: 3px 7px; border-radius: 10px; cursor: pointer; border: 1px solid rgba(255,255,255,0.2); color: rgba(255,255,255,0.5); user-select: none; transition: all 0.15s; }
.list-tag-chip.active { border-color: #10b981; color: #10b981; background: rgba(16,185,129,0.15); }

.search-row { display: flex; gap: 8px; align-items: center; }
.search-input-wrapper { position: relative; flex: 1; }
.search-input-wrapper input {
  width: 100%;
  padding: 10px 30px 10px 34px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.07);
  color: white;
  font-family: var(--font-main);
  font-size: 0.9rem;
  outline: none;
}
.search-input-wrapper input::placeholder { color: rgba(255,255,255,0.35); }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); opacity: 0.5; pointer-events: none; }
.search-clear-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-size: 0.85rem; cursor: pointer; padding: 2px 4px; line-height: 1;
}
.search-clear-btn:hover { color: white; }

#radius-select {
  height: 40px; padding: 0 8px; border-radius: 8px;
  background: rgba(255,255,255,0.08); color: white;
  border: 1px solid var(--glass-border); font-size: 0.85rem;
  flex-shrink: 0; cursor: pointer;
}
#radius-select option { background: #1e293b; }

.filter-info { font-size: 0.85rem; color: var(--success-color); }
.filter-info.hidden { display: none; }
.search-error { font-size: 0.82rem; color: var(--danger-color); }
.search-error.hidden { display: none; }

/* POKE CARDS */
.poke-card {
  background: rgba(255,255,255,0.05);
  padding: 12px 14px;
  border-radius: 12px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
  transition: background 0.2s;
}
.poke-card:hover { background: rgba(255,255,255,0.08); }
.poke-card.nearby { border: 1px solid rgba(16,185,129,0.25); }
.poke-info { cursor: pointer; flex: 1; min-width: 0; }
.poke-name { font-size: 1rem; font-weight: 600; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poke-note { font-size: 0.8rem; opacity: 0.65; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.poke-distance { font-size: 0.75rem; color: var(--success-color); font-weight: 700; }
.poke-actions { display: flex; gap: 6px; flex-shrink: 0; }
.action-btn {
  background: none; border: none; cursor: pointer; padding: 4px;
  opacity: 0.75; transition: opacity 0.15s;
  display: flex; align-items: center;
}
.action-btn:hover { opacity: 1; }

.empty-state { text-align: center; padding: 30px; opacity: 0.55; font-size: 0.9rem; }

/* NAVBAR */
.navbar {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 1.5rem;
  padding: 14px 28px;
  z-index: 1000;
  width: 90%; max-width: 400px;
  justify-content: space-between;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.navbar.hidden { display: none; }
.nav-btn {
  background: none; border: none;
  color: #94a3b8; display: flex; flex-direction: column; align-items: center;
  cursor: pointer; gap: 4px; transition: color 0.2s; padding: 2px;
  font-family: var(--font-main);
}
.nav-btn span { font-size: 0.72rem; font-weight: 500; }
.nav-btn.active { color: var(--primary-color); }

/* ALERT */
.alert-banner {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 900;
  padding: 14px 22px;
  color: var(--success-color);
  font-weight: 700;
  animation: fadeInDown 0.5s ease-out forwards;
  white-space: nowrap;
}
.alert-banner.hidden { display: none; }

/* PICK BANNER */
.pick-banner {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  z-index: 900;
}
.pick-banner.hidden { display: none; }
.pick-hint { padding: 10px 22px; font-size: 0.9rem; font-weight: 500; }

/* ANIMATIONS */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeInDown {
  from { opacity: 0; transform: translate(-50%, -16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }

/* AUTH MODAL */
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.80);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 20px;
}
.auth-modal.hidden { display: none; }

.auth-panel {
  width: 100%;
  max-width: 360px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-radius: 24px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.auth-title {
  font-size: 1.7rem;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-subtitle {
  font-size: 0.82rem;
  opacity: 0.5;
  text-align: center;
}

.auth-tabs {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 3px;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 8px;
  background: none;
  color: rgba(255, 255, 255, 0.45);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.auth-tab.active {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.auth-fields { display: flex; flex-direction: column; gap: 10px; }

.auth-submit-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  font-size: 1rem;
  margin-top: 2px;
}

.auth-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.83rem;
  color: #ef4444;
}
.auth-error.hidden { display: none; }

.auth-success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.83rem;
  color: #10b981;
  text-align: center;
}
.auth-success.hidden { display: none; }

/* USER BUTTON */
.user-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 900;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 20px;
}
.user-btn.hidden { display: none; }
.user-email {
  font-size: 0.75rem;
  opacity: 0.65;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-signout-btn {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  color: #ef4444;
  font-size: 0.73rem;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.2s;
  white-space: nowrap;
}
.auth-signout-btn:hover { background: rgba(239, 68, 68, 0.25); }

/* TOAST */
#toast-container {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-color);
  white-space: nowrap;
  box-shadow: var(--glass-shadow);
  pointer-events: auto;
  animation: toast-in 0.2s ease;
}
.toast.toast-success { border-color: var(--success-color); color: var(--success-color); }
.toast.toast-error   { border-color: var(--danger-color);  color: var(--danger-color); }
.toast.toast-warning { border-color: #f59e0b; color: #f59e0b; }
.toast.toast-info    { border-color: var(--primary-color); color: var(--primary-color); }
.toast.toast-out     { animation: toast-out 0.2s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(8px); } }

/* FIELD ERRORS */
.field-error {
  font-size: 0.8rem;
  color: var(--danger-color);
  margin-top: 4px;
  padding-left: 2px;
}

/* INLINE DELETE CONFIRM */
.delete-confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--danger-color);
  white-space: nowrap;
}
.delete-confirm button {
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-main);
}
.delete-confirm .btn-confirm-yes { color: var(--danger-color); }
.delete-confirm .btn-confirm-no  { color: var(--text-color); border-color: var(--glass-border); }

/* RESPONSIVE */
@media (max-width: 480px) {
  .navbar { padding: 12px 20px; }
  .form-panel, .list-panel { margin: 12px; margin-top: 80px; padding: 16px; }
  .auth-panel { padding: 28px 20px; }
  .user-email { display: none; }
}
