:root {
  --bg: #0f1a12;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #eafaf0;
  --text-dim: #a9c4b3;
  --accent: #4ade80;
  --accent-2: #22c55e;
  --danger: #f87171;
  --navbar-h: 64px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  position: relative;
}

/* ---------- animated background blobs ---------- */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: drift 18s ease-in-out infinite;
}

.blob-1 { width: 380px; height: 380px; background: #22c55e; top: -100px; left: -80px; }
.blob-2 { width: 320px; height: 320px; background: #4ade80; bottom: -100px; right: -60px; animation-delay: -6s; }
.blob-3 { width: 260px; height: 260px; background: #86efac; top: 40%; left: 55%; animation-delay: -12s; }

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -40px) scale(1.1); }
  66% { transform: translate(-20px, 30px) scale(0.95); }
}

/* ---------- navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(15, 26, 18, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--card-border);
}

.nav-brand {
  font-weight: 700;
  font-size: 1.15rem;
}

.nav-tabs {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  padding: 4px;
  border-radius: 12px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06240f;
}

/* ---------- page / workspace layout ---------- */
.page {
  position: relative;
  z-index: 1;
  height: calc(100vh - var(--navbar-h));
  padding: 24px 28px;
}

.workspace {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  height: 100%;
}

.workspace[hidden] {
  display: none;
}

.panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 28px;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: cardIn 0.4s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}

h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 18px;
  font-size: 0.88rem;
  line-height: 1.4;
}

.subtitle + .photo-tips { margin-top: -10px; }

.photo-tips {
  margin: 0 0 8px;
  padding-left: 20px;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.6;
}

.photo-hint {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.photo-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.photo-count.complete { color: var(--accent); }

/* ---------- upload box ---------- */
.upload-box {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(74, 222, 128, 0.4);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 12px;
  cursor: pointer;
  min-height: 140px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.upload-box:hover { border-color: var(--accent); background: rgba(74, 222, 128, 0.06); }
.upload-box.drag-over { border-color: var(--accent); background: rgba(74, 222, 128, 0.12); transform: scale(1.01); }

.upload-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
}

.upload-icon { font-size: 2rem; animation: float 3s ease-in-out infinite; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.upload-text { font-size: 0.95rem; color: var(--text); }
.upload-subtext { font-size: 0.78rem; }

/* ---------- thumbnails ---------- */
.thumb-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  animation: cardIn 0.25s ease both;
}

.thumb.flagged { border: 2px solid var(--danger); box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.35); }

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 18px;
  cursor: pointer;
  padding: 0;
}

/* ---------- button ---------- */
button#btn-detect, button#btn-finder {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06240f;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.15s, opacity 0.2s;
}

button#btn-detect:hover:not(:disabled), button#btn-finder:hover:not(:disabled) {
  transform: translateY(-1px);
}

button#btn-detect:disabled, button#btn-finder:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(6, 36, 15, 0.3);
  border-top-color: #06240f;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- agent steps ---------- */
.agent-steps {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.agent-step {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  animation: stepIn 0.35s ease forwards;
}

.agent-step.done { color: var(--accent); }
.agent-step .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.agent-steps[hidden] { display: none; }

@keyframes stepIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}

.status-error {
  margin-top: 12px;
  min-height: 20px;
  color: var(--danger);
  font-size: 0.88rem;
}

/* ---------- result panel ---------- */
.result-panel {
  display: flex;
  flex-direction: column;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 10px;
  text-align: center;
  min-height: 100%;
}

.empty-icon { font-size: 2.6rem; opacity: 0.6; }

.empty-state[hidden] { display: none; }

.result { animation: cardIn 0.4s ease both; }

.result-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--card-border);
}

.result-block { display: flex; flex-direction: column; gap: 4px; }
.result-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.result-value { font-size: 1.15rem; font-weight: 600; }

.meter {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-top: 4px;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.meter-label { font-size: 0.75rem; color: var(--text-dim); }

#extraDetails, #finderDetails { margin-top: 16px; }
#extraDetails div, #finderDetails div { margin-bottom: 14px; animation: cardIn 0.35s ease both; }
#extraDetails h4, #finderDetails h4 { margin: 0 0 4px; font-size: 0.9rem; color: var(--accent); }
#extraDetails p, #finderDetails p { margin: 0; font-size: 0.9rem; color: var(--text-dim); line-height: 1.5; }

/* ---------- result tabs (plant.id vs Gemini) ---------- */
.result-tabs {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 18px;
}

.result-tabs[hidden] { display: none; }

.result-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.result-tab:hover { color: var(--text); }

.result-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06240f;
}

.low-confidence {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(250, 204, 21, 0.08);
  border: 1px solid rgba(250, 204, 21, 0.35);
}

.low-confidence[hidden] { display: none; }
.low-confidence h4 { margin: 0 0 6px; font-size: 0.95rem; color: #facc15; }
.low-confidence > p { margin: 0 0 12px; font-size: 0.88rem; color: var(--text-dim); line-height: 1.5; }

.switch-tab-btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06240f;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.switch-tab-btn[hidden] { display: none; }

.switch-tab-btn.secondary {
  margin-top: 14px;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(74, 222, 128, 0.4);
}

.low-confidence + #extraDetails { margin-top: 16px; }
.source-note { margin: 14px 0 0; font-size: 0.75rem; color: var(--text-dim); opacity: 0.8; }

.fallback-section {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.25);
  animation: cardIn 0.4s ease both;
}

.fallback-section h4 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fallback-section p { margin: 0; font-size: 0.88rem; color: var(--text-dim); line-height: 1.45; white-space: pre-wrap; }
.fallback-section p + p { margin-top: 6px; }

/* ---------- plant finder header ---------- */
.finder-header {
  display: flex;
  gap: 16px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 4px;
}

.finder-img {
  width: 88px;
  height: 88px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
}

/* ---------- photo guide modal ---------- */
.guide-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease both;
}

.modal-backdrop[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: #14231a;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: cardIn 0.3s ease both;
}

.modal h2 { margin: 0 0 6px; font-size: 1.3rem; padding-right: 32px; }
.modal-sub { margin: 0 0 18px; color: var(--text-dim); font-size: 0.88rem; line-height: 1.4; }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.guide-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.guide-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px;
}

.guide-card svg { display: block; width: 100%; max-width: 120px; height: auto; margin: 0 auto 10px; }

.guide-card .step {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #06240f;
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 6px;
}

.guide-card h4 { margin: 0 0 4px; font-size: 0.92rem; }
.guide-card p { margin: 0; font-size: 0.8rem; color: var(--text-dim); line-height: 1.4; }

.guide-rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}

.guide-rules h4 { margin: 0 0 6px; font-size: 0.9rem; }
.guide-rules ul { margin: 0; padding-left: 18px; color: var(--text-dim); font-size: 0.82rem; line-height: 1.6; }

.modal-ok {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06240f;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

body.modal-open { overflow: hidden; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .page { height: auto; padding: 16px; }
  .workspace { grid-template-columns: 1fr; height: auto; }
  .panel { overflow-y: visible; }
  .navbar { padding: 0 16px; }
}

.nav-brand { white-space: nowrap; }
.on-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
  .on-desktop { display: none; }
  .on-touch { display: inline; }
  .thumb .remove { width: 26px; height: 26px; font-size: 13px; line-height: 26px; }
}

@media (max-width: 600px) {
  .navbar { height: auto; flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .nav-brand { font-size: 1rem; }
  .nav-tabs { width: 100%; }
  .nav-tab { flex: 1; white-space: nowrap; padding: 10px 8px; font-size: 0.88rem; }

  .page { padding: 12px; }
  .workspace { gap: 12px; }
  .panel { padding: 20px 16px; border-radius: 16px; }
  h1 { font-size: 1.3rem; }
  .upload-box { min-height: 120px; }
  .thumb { width: 76px; height: 76px; }
  .result-row { grid-template-columns: 1fr; gap: 14px; }
  .result-tab { font-size: 0.82rem; padding: 10px 4px; white-space: nowrap; }
  .tab-icon { display: none; }
  .empty-state { padding: 24px 0; }

  .modal { padding: 22px 16px; }
  .guide-cards { grid-template-columns: 1fr; }
  .guide-card { display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; }
  .guide-card svg { margin: 0; }
  .guide-rules { grid-template-columns: 1fr; }
}
