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

[hidden] { display: none !important; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #dce8dc;
  color: #2d3a2d;
  min-height: 100vh;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: #f0f7f0;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.12);
  position: relative;
}

header {
  background: linear-gradient(135deg, #2e7d32, #4caf50);
  color: white;
  padding: 16px 12px 12px;
  text-align: center;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.leaf-icon { font-size: 24px; }
header h1 { font-size: 18px; font-weight: 700; }
.subtitle { font-size: 11px; opacity: 0.85; margin-top: 2px; }

.tab-bar {
  display: flex;
  background: white;
  border-bottom: 2px solid #c8e6c9;
}

.tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.tab.active {
  color: #2e7d32;
  border-bottom-color: #2e7d32;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stats-bar {
  display: flex;
  background: white;
  border-bottom: 1px solid #c8e6c9;
  padding: 8px 4px;
}

.stat { flex: 1; text-align: center; }
.stat-num { display: block; font-size: 20px; font-weight: 700; color: #2e7d32; }
.stat-label { font-size: 10px; color: #666; text-transform: uppercase; letter-spacing: 0.5px; }

.search-bar { padding: 10px 12px 6px; }
.search-bar input {
  width: 100%;
  padding: 8px 12px;
  border: 2px solid #c8e6c9;
  border-radius: 20px;
  font-size: 13px;
  outline: none;
  background: white;
}
.search-bar input:focus { border-color: #4caf50; }

.identify-section { padding: 0 12px 10px; }
.identify-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #2e7d32, #43a047);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 3px 12px rgba(46, 125, 50, 0.3);
}
.identify-btn:active { transform: scale(0.98); }
.camera-icon { font-size: 20px; }

.sightings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 90px;
}

.sighting-card {
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  transition: transform 0.15s;
}
.sighting-card:active { transform: scale(0.97); }

.card-image {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  overflow: hidden;
}
.card-image img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 8px; }
.card-body h3 { font-size: 12px; font-weight: 700; margin-bottom: 3px; line-height: 1.2; }
.card-location { font-size: 10px; color: #777; margin-bottom: 4px; }
.card-badges { display: flex; flex-wrap: wrap; gap: 3px; }

.badge { font-size: 9px; padding: 2px 6px; border-radius: 10px; font-weight: 600; }
.badge-native { background: #e8f5e9; color: #2e7d32; }
.badge-invasive { background: #fff3e0; color: #e65100; }
.badge-endangered { background: #ffebee; color: #c62828; }
.badge-confidence { background: #e3f2fd; color: #1565c0; }

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 30px 12px;
  color: #999;
  font-size: 13px;
}

.ai-identify-panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.ai-panel-content {
  background: white;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px;
  overflow-y: auto;
  position: relative;
}
.ai-panel-content h2 { font-size: 16px; text-align: center; margin-bottom: 12px; color: #2e7d32; }

.close-btn {
  position: absolute;
  top: 12px; right: 14px;
  background: none; border: none;
  font-size: 22px; color: #999;
  cursor: pointer; z-index: 2;
}

.photo-area {
  border-radius: 10px;
  overflow: hidden;
  background: #e8f5e9;
  margin-bottom: 12px;
  min-height: 140px;
  position: relative;
}
.photo-area img { width: 100%; max-height: 200px; object-fit: cover; display: block; }
.photo-prompt {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 30px; color: #888; text-align: center;
}
.photo-prompt span { font-size: 36px; margin-bottom: 6px; }
.photo-prompt p { font-size: 12px; }

.ai-loading { text-align: center; padding: 20px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid #c8e6c9;
  border-top-color: #2e7d32;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ai-loading p { font-size: 13px; color: #666; }

.ai-result { margin-bottom: 14px; }
.result-header { text-align: center; margin-bottom: 8px; }
.result-header h3 { font-size: 18px; color: #2d3a2d; }
.scientific { font-size: 12px; color: #888; font-style: italic; }
.result-badges { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.result-confidence { text-align: center; font-size: 11px; margin-bottom: 10px; color: #666; }
.result-details { background: #f1f8e9; border-radius: 8px; padding: 10px 12px; }
.detail-row { margin-bottom: 8px; }
.detail-row:last-child { margin-bottom: 0; }
.detail-row strong { font-size: 11px; text-transform: uppercase; color: #666; letter-spacing: 0.5px; }
.detail-row p { font-size: 13px; line-height: 1.4; margin-top: 2px; }

.save-section { margin-top: 12px; padding-top: 12px; border-top: 1px solid #e0e0e0; }
.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #555; }
.form-group select, .form-group textarea {
  width: 100%; padding: 8px 10px;
  border: 1.5px solid #ddd; border-radius: 6px;
  font-size: 13px; font-family: inherit; outline: none;
}
.form-group select:focus, .form-group textarea:focus { border-color: #4caf50; }
.form-group select.field-error { border-color: #c62828; }
.field-hint { font-size: 11px; color: #c62828; margin-top: 4px; }
.save-btn {
  width: 100%; padding: 12px;
  background: #2e7d32; color: white;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.save-btn:active { background: #1b5e20; }

.info-panel-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.info-panel {
  background: white; width: 100%;
  max-width: 480px;
  max-height: 85vh;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px;
  overflow-y: auto; position: relative;
}
.info-photo { border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.info-photo img { width: 100%; max-height: 160px; object-fit: cover; display: block; border-radius: 10px; }
.info-emoji { text-align: center; font-size: 48px; padding: 16px; background: #e8f5e9; border-radius: 10px; }
#info-name { font-size: 18px; text-align: center; margin-bottom: 2px; }
#info-scientific { text-align: center; margin-bottom: 8px; }
.info-badges { display: flex; justify-content: center; gap: 6px; margin-bottom: 14px; }
.info-badges .badge { font-size: 11px; padding: 3px 10px; }
.info-section { margin-bottom: 12px; }
.info-section h3 { font-size: 12px; text-transform: uppercase; color: #888; margin-bottom: 4px; letter-spacing: 0.5px; }
.info-section p { font-size: 13px; line-height: 1.5; }
.ai-box {
  background: #f1f8e9;
  border-left: 3px solid #4caf50;
  padding: 10px 12px;
  border-radius: 0 6px 6px 0;
  font-size: 12px; line-height: 1.5;
}

.info-actions { display: flex; gap: 8px; margin-top: 16px; }
.ask-guide-btn {
  flex: 1;
  padding: 11px;
  background: #2e7d32; color: white;
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.ask-guide-btn:active { background: #1b5e20; }
.delete-btn {
  padding: 11px 14px;
  background: white; color: #c62828;
  border: 1.5px solid #ef9a9a; border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.delete-btn:active { background: #ffebee; }

.stats-page { padding: 16px 12px 90px; }
.stats-page h2 { font-size: 15px; color: #2e7d32; margin-bottom: 10px; margin-top: 16px; }
.stats-page h2:first-child { margin-top: 0; }

.chart-container {
  background: white;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  margin-bottom: 8px;
  text-align: center;
}
.chart-container canvas { max-width: 100%; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 0 4px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #555;
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.summary-card {
  background: white;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}
.summary-card .sc-num { font-size: 24px; font-weight: 700; }
.summary-card .sc-label { font-size: 10px; color: #666; text-transform: uppercase; }
.sc-green { color: #2e7d32; }
.sc-orange { color: #e65100; }
.sc-red { color: #c62828; }
.sc-blue { color: #1565c0; }

.history-page { padding: 16px 12px 90px; }
.history-page h2 { font-size: 15px; color: #2e7d32; margin-bottom: 4px; }
.history-subtitle { font-size: 12px; color: #888; margin-bottom: 14px; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  display: flex;
  gap: 10px;
  background: white;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  cursor: pointer;
}
.history-item:active { transform: scale(0.98); }
.history-thumb {
  width: 56px; height: 56px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #e8f5e9;
  display: flex;
  align-items: center; justify-content: center;
  font-size: 28px;
}
.history-thumb img { width: 100%; height: 100%; object-fit: cover; }
.history-info { flex: 1; min-width: 0; }
.history-info h4 { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.history-meta { font-size: 11px; color: #888; }
.history-badges { display: flex; gap: 3px; margin-top: 4px; }
.history-empty { text-align: center; color: #999; padding: 20px; font-size: 13px; }

.chat-fab {
  position: fixed;
  bottom: 18px;
  right: max(16px, calc(50vw - 224px));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2e7d32, #43a047);
  color: white;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(46, 125, 50, 0.45);
  z-index: 90;
  transition: transform 0.15s;
}
.chat-fab:hover { transform: scale(1.06); }
.chat-fab:active { transform: scale(0.95); }

.chat-panel {
  position: fixed;
  bottom: 0;
  right: max(0px, calc(50vw - 240px));
  width: min(420px, 100vw);
  height: min(72vh, 580px);
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
  z-index: 110;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  background: linear-gradient(135deg, #2e7d32, #4caf50);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}
.chat-header h2 { font-size: 15px; }
.chat-header p { font-size: 11px; opacity: 0.85; margin-top: 1px; }
.chat-close { color: white; position: static; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f0f7f0;
}

.chat-msg {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-user {
  align-self: flex-end;
  background: #2e7d32;
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-ai {
  align-self: flex-start;
  background: white;
  color: #2d3a2d;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.typing { display: inline-flex; gap: 4px; align-items: center; height: 14px; }
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #9e9e9e;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
  background: #f0f7f0;
}
.chat-chip {
  border: 1.5px solid #a5d6a7;
  background: white;
  color: #2e7d32;
  border-radius: 14px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.chat-chip:active { background: #e8f5e9; }

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: white;
  border-top: 1px solid #e0e0e0;
}
.chat-input-row input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid #c8e6c9;
  border-radius: 20px;
  font-size: 13px;
  outline: none;
}
.chat-input-row input:focus { border-color: #4caf50; }
.chat-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: #2e7d32;
  color: white;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:disabled { background: #a5d6a7; cursor: default; }
