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

:root {
  --green-900: #1b4332;
  --green-800: #2d6a4f;
  --green-600: #40916c;
  --green-400: #52b788;
  --green-200: #95d5b2;
  --green-100: #d8f3dc;
  --green-50:  #f0faf4;
  --white:     #ffffff;
  --gray-50:   #f8f9fa;
  --gray-100:  #f1f3f5;
  --gray-200:  #e9ecef;
  --gray-400:  #ced4da;
  --gray-600:  #6c757d;
  --gray-900:  #212529;
  --red-100:   #ffe3e3;
  --red-600:   #e03131;
  --shadow:    0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --radius:    14px;
  --radius-sm: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--green-50);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--white);
  border-bottom: 1px solid var(--green-100);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-800);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .4rem;
}

nav {
  display: flex;
  gap: .25rem;
  flex: 1;
}

nav a {
  padding: .4rem .8rem;
  border-radius: 8px;
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--gray-600);
  transition: background .15s, color .15s;
}

nav a:hover   { background: var(--green-50); color: var(--green-800); }
nav a.active  { background: var(--green-100); color: var(--green-800); }

.user-area {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
}

.user-area img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--green-200);
}

.user-name {
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-600);
  display: none;
}

@media (min-width: 480px) { .user-name { display: block; } }

.btn-logout {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: .3rem .7rem;
  font-size: .8rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-logout:hover { background: var(--gray-100); }

/* ── Login overlay ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,67,50,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow-md);
}

.login-card .plant-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.login-card h2 { color: var(--green-800); margin-bottom: .5rem; }
.login-card p  { color: var(--gray-600); font-size: .9rem; margin-bottom: 1.5rem; }

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: .7rem 1.2rem;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--gray-900);
  text-decoration: none;
  transition: background .15s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.btn-google:hover { background: var(--gray-50); box-shadow: var(--shadow-md); }
.btn-google svg  { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Main layout ── */
main {
  max-width: 700px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .75rem 1.5rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--green-800); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--green-900); }

.btn-secondary { background: var(--green-100); color: var(--green-800); }
.btn-secondary:hover:not(:disabled) { background: var(--green-200); }

.btn-danger    { background: var(--red-100); color: var(--red-600); }
.btn-danger:hover { background: #ffc9c9; }

.btn-full { width: 100%; }

/* ── Upload zone ── */
.upload-zone {
  border: 2px dashed var(--green-200);
  border-radius: var(--radius);
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--white);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--green-400);
  background: var(--green-50);
}

.upload-icon { font-size: 3rem; margin-bottom: .75rem; }
.upload-zone h3 { color: var(--green-800); margin-bottom: .4rem; }
.upload-zone p  { color: var(--gray-600); font-size: .9rem; margin-bottom: 1.25rem; }

.upload-buttons { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

/* ── Preview ── */
.preview-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--gray-100);
  display: none;
}
.preview-wrap.visible { display: block; }

.preview-wrap img {
  width: 100%;
  max-height: 340px;
  object-fit: cover;
  display: block;
}

.preview-change {
  position: absolute;
  top: .75rem;
  right: .75rem;
  background: rgba(0,0,0,.55);
  color: white;
  border: none;
  border-radius: 6px;
  padding: .35rem .7rem;
  font-size: .8rem;
  cursor: pointer;
}

/* ── Results card ── */
.results-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: none;
}
.results-card.visible { display: block; }

.results-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.plant-name { font-size: 1.5rem; font-weight: 700; color: var(--green-800); }
.plant-sci  { font-size: .9rem; color: var(--gray-600); font-style: italic; margin-top: .2rem; }

.confidence-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 100px;
  font-size: .75rem;
  font-weight: 600;
  margin-top: .5rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.confidence-high   { background: var(--green-100); color: var(--green-800); }
.confidence-medium { background: #fff3bf; color: #865a00; }
.confidence-low    { background: var(--red-100); color: var(--red-600); }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
}

.info-cell {
  background: var(--white);
  padding: 1rem 1.25rem;
}
.info-cell .label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  margin-bottom: .3rem;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.info-cell .value { font-size: .9rem; color: var(--gray-900); line-height: 1.4; }

.care-section {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}
.care-section .label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  margin-bottom: .5rem;
}
.care-section .value { font-size: .9rem; line-height: 1.6; color: var(--gray-900); }

.results-actions {
  padding: 1.25rem 1.5rem;
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}

/* ── Spinner ── */
.spinner-wrap {
  display: none;
  text-align: center;
  padding: 2.5rem;
  background: var(--white);
  border-radius: var(--radius);
}
.spinner-wrap.visible { display: block; }

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--green-100);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto .75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-wrap p { color: var(--gray-600); font-size: .9rem; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(6rem);
  background: var(--green-800);
  color: var(--white);
  padding: .75rem 1.5rem;
  border-radius: 100px;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transition: transform .3s ease;
  z-index: 300;
  white-space: nowrap;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error    { background: var(--red-600); }

/* ── Collection page ── */
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--green-800);
  margin-bottom: .25rem;
}
.page-subtitle { color: var(--gray-600); font-size: .95rem; margin-bottom: 1.5rem; }

.plant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.plant-card {
  background: var(--white);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.plant-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.plant-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.plant-card-body { padding: .75rem; }
.plant-card-name { font-weight: 600; font-size: .95rem; color: var(--green-800); margin-bottom: .2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card-sci  { font-size: .78rem; color: var(--gray-600); font-style: italic; margin-bottom: .5rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card-date { font-size: .75rem; color: var(--gray-400); }

.plant-card-delete {
  float: right;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0 .2rem;
  line-height: 1;
  transition: color .15s;
}
.plant-card-delete:hover { color: var(--red-600); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  display: none;
}
.empty-state.visible { display: block; }
.empty-state .icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state h3 { color: var(--green-800); margin-bottom: .5rem; }
.empty-state p  { color: var(--gray-600); font-size: .9rem; margin-bottom: 1.5rem; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.visible { display: flex; }

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

@media (min-width: 600px) {
  .modal { border-radius: var(--radius); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  background: var(--white);
}
.modal-header h3 { font-size: 1.1rem; color: var(--green-800); }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gray-600); padding: 0 .25rem; }

.modal-image {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
}

.modal-body { padding: 1.25rem 1.5rem; }
.modal-plant-name { font-size: 1.4rem; font-weight: 700; color: var(--green-800); }
.modal-plant-sci  { font-size: .9rem; color: var(--gray-600); font-style: italic; margin-bottom: 1rem; }

.modal-section       { margin-bottom: 1rem; }
.modal-section-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  margin-bottom: .3rem;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.modal-section-value { font-size: .9rem; line-height: 1.6; color: var(--gray-900); }

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: .75rem;
}

/* ── Utilities ── */
.gap-top { margin-top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
