:root {
  --bg: #f2f5ef;
  --surface: rgba(255,255,255,.9);
  --surface-solid: #ffffff;
  --surface-2: #e7eee7;
  --ink: #18332c;
  --muted: #62736d;
  --primary: #173f35;
  --primary-2: #2e6a57;
  --accent: #d8f16b;
  --danger: #a94438;
  --warning: #8a5a00;
  --success: #27734f;
  --border: rgba(24,51,44,.12);
  --shadow: 0 18px 50px rgba(24,51,44,.10);
  --radius: 24px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0f1916;
  --surface: rgba(24,39,34,.94);
  --surface-solid: #182722;
  --surface-2: #20342d;
  --ink: #edf7f1;
  --muted: #a6b9b1;
  --primary: #c7f1db;
  --primary-2: #8bc9ad;
  --accent: #cfea5f;
  --danger: #ff9b8f;
  --warning: #ffd17a;
  --success: #88d7af;
  --border: rgba(237,247,241,.12);
  --shadow: 0 20px 60px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 0%, rgba(216,241,107,.22), transparent 28rem),
    radial-gradient(circle at 95% 20%, rgba(94,170,137,.18), transparent 25rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  padding-bottom: calc(84px + var(--safe-bottom));
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }

.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 8px 16px; text-align: center; background: #7a3f14; color: white; font-size: 13px;
}
.offline-banner:not([hidden]) + .toast + .topbar { top: 34px; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  height: 74px; padding: 12px max(18px, calc((100vw - 1120px)/2));
  background: color-mix(in srgb, var(--bg) 76%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--ink); text-align: left; }
.brand-mark { width: 42px; height: 42px; border-radius: 15px; display: grid; place-items: center; background: var(--primary); color: var(--bg); font-family: Georgia, serif; font-weight: 800; font-size: 25px; transform: rotate(-6deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; letter-spacing: -.02em; }
.brand small { font-size: 11px; color: var(--muted); margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }

.app-shell { width: min(1120px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 44px; outline: none; }
.page { animation: enter .24s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(34px, 7vw, 68px); letter-spacing: -.055em; line-height: .98; max-width: 850px; }
h2 { font-size: clamp(25px, 4vw, 38px); letter-spacing: -.035em; }
h3 { font-size: 18px; letter-spacing: -.015em; }
.lead { max-width: 700px; color: var(--muted); font-size: 18px; line-height: 1.6; }
.eyebrow { margin-bottom: 12px; color: var(--primary-2); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .13em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.hero { display: grid; grid-template-columns: 1.35fr .65fr; gap: 24px; align-items: stretch; margin-bottom: 32px; }
.hero-copy, .hero-card, .card { border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); }
.hero-copy { padding: clamp(26px, 5vw, 58px); overflow: hidden; position: relative; }
.hero-copy::after { content: ""; width: 280px; height: 280px; position: absolute; right: -105px; bottom: -125px; border: 44px solid color-mix(in srgb, var(--accent) 72%, transparent); border-radius: 50%; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero-card { padding: 24px; display: flex; flex-direction: column; justify-content: space-between; background: var(--primary); color: var(--bg); min-height: 320px; }
.hero-card .muted { color: color-mix(in srgb, var(--bg) 75%, transparent); }
.health-orb { width: 145px; aspect-ratio: 1; border-radius: 50%; margin: auto; display: grid; place-items: center; border: 18px solid color-mix(in srgb, var(--accent) 82%, transparent); box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); font-size: 30px; font-weight: 800; }

.button { border: 0; border-radius: 14px; min-height: 48px; padding: 12px 18px; background: var(--primary); color: var(--bg); font-weight: 750; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.button:hover { transform: translateY(-1px); }
.button.secondary { background: var(--accent); color: #18332c; }
.button.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.button.danger { background: var(--danger); color: white; }
.button.compact { min-height: 40px; padding: 8px 13px; font-size: 13px; }
.button.full { width: 100%; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { padding: 22px; }
.card.flat { box-shadow: none; }
.card.clickable { text-align: left; color: inherit; transition: .2s ease; }
.card.clickable:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--primary-2) 45%, var(--border)); }
.card-header { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.card-header h2, .card-header h3 { margin-bottom: 4px; }
.metric { font-size: 34px; font-weight: 850; letter-spacing: -.04em; }
.icon-tile { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); font-size: 23px; }

.section { margin: 34px 0; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-head h2 { margin-bottom: 0; }

.scan-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(280px, .7fr); gap: 20px; align-items: start; }
.upload-zone { border: 1.5px dashed color-mix(in srgb, var(--primary-2) 45%, var(--border)); border-radius: 22px; min-height: 260px; padding: 30px; display: grid; place-items: center; text-align: center; background: color-mix(in srgb, var(--surface) 75%, transparent); }
.upload-zone.dragging { background: color-mix(in srgb, var(--accent) 25%, var(--surface)); }
.upload-zone input { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-top: 14px; }
.photo-item { position: relative; overflow: hidden; border-radius: 18px; background: var(--surface-2); aspect-ratio: 1; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item button { position: absolute; right: 7px; top: 7px; width: 30px; height: 30px; border: 0; border-radius: 50%; background: rgba(12,20,17,.75); color: white; }
.photo-item select { position: absolute; left: 7px; right: 7px; bottom: 7px; width: calc(100% - 14px); border: 0; border-radius: 10px; padding: 7px; background: rgba(255,255,255,.9); color: #18332c; font-size: 12px; }

.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field label, .field > span { font-size: 13px; font-weight: 750; }
input[type="text"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-solid); color: var(--ink); padding: 12px 13px; min-height: 46px;
}
textarea { min-height: 105px; resize: vertical; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.check-option, .radio-option { display: flex; gap: 9px; align-items: center; border: 1px solid var(--border); border-radius: 13px; padding: 10px 12px; background: var(--surface-solid); }
.check-option input, .radio-option input { accent-color: var(--primary-2); }

.steps { display: grid; gap: 12px; counter-reset: step; }
.step { display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: start; }
.step::before { counter-increment: step; content: counter(step); width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #18332c; font-weight: 850; }
.step strong { display: block; margin: 5px 0 3px; }

.status-pill, .tag { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; background: var(--surface-2); color: var(--ink); }
.status-pill.good { background: rgba(39,115,79,.12); color: var(--success); }
.status-pill.warn { background: rgba(176,116,0,.12); color: var(--warning); }
.status-pill.bad { background: rgba(169,68,56,.12); color: var(--danger); }
.tag-row { display: flex; flex-wrap: wrap; gap: 7px; }

.result-hero { display: grid; grid-template-columns: 250px 1fr; gap: 22px; align-items: stretch; }
.result-photo { min-height: 290px; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.result-photo img { width: 100%; height: 100%; object-fit: cover; }
.candidate { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.candidate:last-child { border-bottom: 0; }
.confidence-bar { grid-column: 1 / -1; height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.confidence-bar span { display: block; height: 100%; background: var(--primary-2); border-radius: inherit; }

.diagnosis-card { border-left: 5px solid var(--warning); }
.diagnosis-card.high { border-left-color: var(--danger); }
.diagnosis-card.low { border-left-color: var(--success); }
.evidence-list, .plain-list { padding-left: 20px; line-height: 1.55; }
.recovery-timeline { display: grid; gap: 12px; }
.recovery-item { display: grid; grid-template-columns: 100px 1fr; gap: 13px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.recovery-item:last-child { border-bottom: 0; }
.recovery-item strong { color: var(--primary-2); }

.plant-card { overflow: hidden; padding: 0; }
.plant-image { height: 175px; background: var(--surface-2); position: relative; }
.plant-image img { width: 100%; height: 100%; object-fit: cover; }
.plant-body { padding: 18px; }
.plant-title { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.empty-state { text-align: center; padding: 50px 24px; }
.empty-state .icon-tile { margin: 0 auto 14px; width: 65px; height: 65px; font-size: 32px; }

.journal-row { display: grid; grid-template-columns: 88px 40px 1fr auto; gap: 12px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--border); }
.journal-row:last-child { border-bottom: 0; }
.journal-icon { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; background: var(--surface-2); }

.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(5,12,9,.58); display: grid; align-items: end; padding: 18px; }
.modal { width: min(650px, 100%); max-height: 88vh; overflow: auto; margin: 0 auto; padding: 22px; border-radius: 25px 25px 18px 18px; background: var(--surface-solid); box-shadow: 0 30px 90px rgba(0,0,0,.3); }

.bottom-nav { position: fixed; z-index: 60; left: 50%; bottom: max(10px, var(--safe-bottom)); transform: translateX(-50%); width: min(630px, calc(100% - 20px)); height: 68px; border-radius: 23px; display: grid; grid-template-columns: repeat(5, 1fr); padding: 7px; background: color-mix(in srgb, var(--surface-solid) 91%, transparent); border: 1px solid var(--border); box-shadow: 0 16px 50px rgba(10,25,20,.18); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.nav-item { border: 0; border-radius: 16px; background: none; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 2px; }
.nav-item span { font-size: 21px; line-height: 1; }
.nav-item small { font-size: 10px; font-weight: 750; }
.nav-item.active { background: var(--primary); color: var(--bg); }

.toast { position: fixed; z-index: 120; top: 84px; left: 50%; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; background: #10251f; color: white; border-radius: 13px; padding: 11px 15px; box-shadow: var(--shadow); transition: .2s ease; max-width: calc(100% - 28px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { display: inline-block; width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { border-radius: 12px; min-height: 20px; background: linear-gradient(90deg,var(--surface-2),var(--surface-solid),var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 820px) {
  .hero, .scan-layout, .result-hero { grid-template-columns: 1fr; }
  .hero-card { min-height: 240px; }
  .health-orb { width: 115px; }
  .grid.four, .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-photo { min-height: 240px; }
}
@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 1120px); padding-top: 18px; }
  .topbar { padding-inline: 12px; }
  .brand small { display: none; }
  h1 { font-size: 42px; }
  .hero-copy, .card { padding: 18px; }
  .hero-copy { padding-block: 30px; }
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
  .check-grid { grid-template-columns: 1fr; }
  .section-head { align-items: start; }
  .recovery-item { grid-template-columns: 82px 1fr; }
  .journal-row { grid-template-columns: 72px 36px 1fr; }
  .journal-row > :last-child { grid-column: 3; }
}
