/* ---------- Design tokens ---------- */
:root {
  --bg: #0b1020;
  --bg-elev: #121a33;
  --surface: #182241;
  --surface-2: #1f2a4d;
  --text: #e8ecf6;
  --text-dim: #aab2c9;
  --muted: #7b86a6;
  --border: #2a335a;
  --primary: #4f8cff;
  --primary-2: #6aa1ff;
  --accent: #4ad6a0;
  --warn: #ffb454;
  --danger: #ff5d6c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fb;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #eef2fa;
    --text: #0f172a;
    --text-dim: #475569;
    --muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  }
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-2); text-decoration: none; }
button { font: inherit; }
h1 { font-size: 1.75rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
p { margin: 0; color: var(--text-dim); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(180deg, var(--bg) 60%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.brand .logo { font-size: 1.4rem; }

.auth-widget {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem;
}
.auth-widget .auth-email {
  color: var(--text-dim);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.auth-widget .btn { padding: 6px 12px; font-size: 0.85rem; }

.container {
  padding: 8px 16px calc(96px + var(--safe-bottom));
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Hero / home ---------- */
.hero { padding: 8px 4px 16px; }
.hero .sub { color: var(--text-dim); }

.action-grid {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}
.action-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.05s ease, background 0.15s ease;
}
.action-card:active { transform: scale(0.99); }
.action-card .action-icon {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  font-size: 1.4rem;
  background: var(--surface-2);
  border-radius: 12px;
}
.action-card.primary {
  background: linear-gradient(135deg, var(--primary), #7a5cff);
  border-color: transparent; color: white;
}
.action-card.primary p { color: rgba(255,255,255,0.85); }
.action-card.primary .action-icon { background: rgba(255,255,255,0.18); color: white; }
.action-card h2 { margin: 0; }
.action-card p { font-size: 0.9rem; }

.recent { margin-top: 28px; }
.recent-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.recent-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.recent-list li.empty { color: var(--muted); text-align: center; }
.recent-list .meta { color: var(--muted); font-size: 0.85rem; }

.backup-panel {
  margin-top: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.backup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.backup-head h2 { margin: 0; }
.backup-note {
  color: var(--text-dim);
  font-size: 0.92rem;
}

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 1000;
}
.tab {
  display: grid; place-items: center; gap: 2px;
  padding: 10px 6px;
  color: var(--muted);
  font-size: 0.95rem;
}
.tab small { font-size: 0.7rem; }
.tab.active { color: var(--primary-2); }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; margin-top: 8px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--text-dim); }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,140,255,0.25);
}
.field textarea { min-height: 88px; resize: vertical; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  transition: transform 0.05s, background 0.15s;
}
.btn:active { transform: scale(0.99); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), #7a5cff);
  color: white; border-color: transparent;
}
.btn.success { background: var(--accent); color: #06251a; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: white; border-color: transparent; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

/* ---------- Combobox (intellisense) ---------- */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  z-index: 20;
  max-height: 280px; overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  display: none;
}
.combo-list.open { display: block; }
.combo-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.combo-item:hover, .combo-item.active { background: var(--surface-2); }
.combo-item .sci { font-size: 0.8rem; color: var(--muted); font-style: italic; }
.combo-item mark { background: rgba(79,140,255,0.25); color: inherit; padding: 0 2px; border-radius: 3px; }
.combo-empty { padding: 10px 14px; color: var(--muted); }

/* ---------- Map ---------- */
.map {
  width: 100%;
  height: 240px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.map.full { height: calc(100dvh - 220px - var(--safe-bottom)); min-height: 320px; }
.map.tall { height: 360px; }
.map-hint { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-dot,
.sighting-pin {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.legend-dot.own,
.sighting-pin.own {
  background: var(--primary);
}
.legend-dot.other,
.sighting-pin.other {
  background: var(--warn);
}
.sighting-pin-wrap {
  background: transparent;
  border: 0;
}

/* ---------- Filters ---------- */
.filters { display: grid; gap: 10px; margin-bottom: 12px; }
.filters .row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
@media (max-width: 520px) { .filters .row3 { grid-template-columns: 1fr 1fr; } }

/* ---------- Lists ---------- */
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: grid; gap: 4px;
}
.list .title { font-weight: 600; }
.list .meta { color: var(--muted); font-size: 0.85rem; }
.list .actions { display: flex; gap: 8px; margin-top: 6px; }
.list .actions .btn { min-height: 36px; padding: 6px 12px; font-weight: 500; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  box-shadow: var(--shadow);
}
.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}
@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-bottom));
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.error { border-color: var(--danger); }

/* Page heading */
.page-head { padding: 4px 4px 12px; }
.page-head .crumbs { color: var(--muted); font-size: 0.85rem; }

/* Chip */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim);
  font-size: 0.8rem;
}
.chip.accent { background: rgba(74, 214, 160, 0.15); color: var(--accent); }
.chip.warn   { background: rgba(255, 180, 84, 0.15); color: var(--warn); }
