/* ============================================================
   Plant30 — mobile-first, dark-mode-aware stylesheet
   ============================================================ */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #2d7a4f;
  --primary-light: #d1fae5;
  --primary-dark: #1e5e3a;
  --accent: #d97706;       /* custom plant - amber */
  --accent-light: #fef3c7;
  --promoted: #7c3aed;     /* promoted plant - purple */
  --promoted-light: #ede9fe;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --success: #10b981;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --surface-2: #111827;
    --border: #374151;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --primary: #34d399;
    --primary-light: #064e3b;
    --primary-dark: #6ee7b7;
    --accent: #fbbf24;
    --accent-light: #451a03;
    --promoted: #a78bfa;
    --promoted-light: #2e1065;
    --danger: #f87171;
    --danger-light: #450a0a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ---- Layout ---- */
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }

.screen { flex: 1; display: flex; flex-direction: column; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); gap: 16px; }
.screen.hidden { display: none !important; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 18px; font-weight: 700; color: var(--primary); }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--border); }

/* ---- Progress bar ---- */
.progress-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.progress-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.progress-score { font-size: 28px; font-weight: 800; color: var(--primary); }
.progress-goal { font-size: 14px; color: var(--text-muted); }
.progress-bar-track {
  height: 10px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
  max-width: 100%;
}
.progress-bar-fill.goal-met { background: var(--success); }

/* ---- Plant list ---- */
.search-bar {
  position: relative;
}
.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab-btn.active {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}

.plant-list { display: flex; flex-direction: column; gap: 6px; padding-bottom: 80px; }

.plant-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.plant-item:active { transform: scale(0.98); }
.plant-item.checked { border-color: var(--primary); background: var(--primary-light); }
.plant-item.checked-custom { border-color: var(--accent); background: var(--accent-light); }
.plant-item.checked-promoted { border-color: var(--promoted); background: var(--promoted-light); }

.plant-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  transition: all 0.15s;
}
.plant-item.checked .plant-check { background: var(--primary); border-color: var(--primary); color: #fff; }
.plant-item.checked-custom .plant-check { background: var(--accent); border-color: var(--accent); color: #fff; }
.plant-item.checked-promoted .plant-check { background: var(--promoted); border-color: var(--promoted); color: #fff; }

.plant-info { flex: 1; min-width: 0; }
.plant-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-meta { display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.plant-category {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--border);
  color: var(--text-muted);
  text-transform: capitalize;
}
.plant-points { font-size: 11px; color: var(--text-muted); }
.plant-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 99px;
  font-weight: 600;
}
.badge-custom { background: var(--accent-light); color: var(--accent); }
.badge-promoted { background: var(--promoted-light); color: var(--promoted); }

/* ---- Floating add button ---- */
.fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.15s;
  z-index: 20;
}
.fab:active { transform: scale(0.93); }

/* ---- Leaderboard ---- */
.leaderboard-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.leaderboard-card h2 { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.leaderboard-row:last-child { border-bottom: none; }
.lb-rank { font-size: 13px; font-weight: 700; color: var(--text-muted); min-width: 20px; }
.lb-name { flex: 1; font-size: 15px; font-weight: 500; }
.lb-score { font-size: 15px; font-weight: 700; color: var(--primary); }
.lb-bar-track { width: 60px; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.lb-bar-fill { height: 100%; background: var(--primary); border-radius: 99px; }

/* ---- Profile screen ---- */
.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
.profile-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.profile-card:active { transform: scale(0.97); }
.profile-card:hover { border-color: var(--primary); }
.profile-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.profile-name { font-size: 17px; font-weight: 600; }
.profile-score { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ---- PIN screen ---- */
.pin-screen { align-items: center; justify-content: center; min-height: 100dvh; }
.pin-title { font-size: 22px; font-weight: 700; text-align: center; }
.pin-subtitle { font-size: 15px; color: var(--text-muted); text-align: center; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 24px 0; }
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all 0.15s;
}
.pin-dot.filled { background: var(--primary); border-color: var(--primary); }
.pin-error { color: var(--danger); font-size: 14px; text-align: center; font-weight: 500; }
.pin-lockout { color: var(--warning); font-size: 14px; text-align: center; }
.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  width: 100%;
}
.pin-key {
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.pin-key:active { background: var(--primary-light); transform: scale(0.93); }
.pin-key.delete { font-size: 16px; color: var(--text-muted); }
.pin-back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 15px;
  cursor: pointer;
  padding: 8px;
  margin-top: 8px;
}

/* ---- Analytics ---- */
.analytics-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1.2; }
.stat-unit { font-size: 13px; color: var(--text-muted); }
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.chart-title { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.chart-container { width: 100%; overflow: hidden; }

/* ---- Help modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(4px);
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 24px 20px 40px;
  max-height: 90dvh;
  overflow-y: auto;
  width: 100%;
  max-width: 480px;
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.modal h2 { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.modal h3 { font-size: 15px; font-weight: 600; margin: 16px 0 6px; color: var(--primary); }
.modal p, .modal li { font-size: 14px; color: var(--text-muted); line-height: 1.6; }
.modal ul { padding-left: 20px; }
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.color-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}
.swatch-standard { background: var(--primary); }
.swatch-custom { background: var(--accent); }
.swatch-promoted { background: var(--promoted); }

/* ---- Custom plant modal ---- */
.add-plant-modal .modal { border-radius: 24px 24px 0 0; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 14px; font-weight: 500; }
.form-group input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}
.toggle-label { font-size: 14px; }
.toggle {
  position: relative;
  width: 46px;
  height: 26px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle-track::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track::before { transform: translateX(20px); }

.btn {
  padding: 14px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

/* ---- Loading ---- */
.loading-screen { align-items: center; justify-content: center; min-height: 100dvh; }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ---- Offline banner ---- */
.offline-banner {
  background: var(--warning);
  color: #000;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
}
.offline-banner.hidden { display: none; }

/* ---- Utility ---- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.gap-8 { gap: 8px; }
