/* Plant Doctor — senior-friendly, offline-first, WCAG AA */

:root {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --text: #1a241c;
  --text-muted: #3d4f42;
  --border: #c5d4c8;
  --accent: #1b6b3a;
  --accent-hover: #145530;
  --accent-soft: #e6f3ea;
  --accent-text: #ffffff;
  --danger: #9b1c1c;
  --danger-hover: #7f1616;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #145530;
  --ok-soft: #e6f3ea;
  --shadow: 0 1px 3px rgba(26, 36, 28, 0.08), 0 4px 16px rgba(26, 36, 28, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --space: 1rem;
  --space-lg: 1.5rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-base: 1.125rem; /* 18px */
  --fs-sm: 1rem;
  --fs-lg: 1.35rem;
  --fs-xl: 1.65rem;
  --touch: 48px;
  --nav-h: 4.5rem;
  --header-h: 4.25rem;
  --z-nav: 20;
  --z-header: 30;
  --z-toast: 40;
  --z-dialog: 50;
  --max: 42rem;
  --focus: 0 0 0 3px #ffffff, 0 0 0 6px var(--accent);
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 1rem);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* Accessibility helpers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
  outline: none;
  box-shadow: var(--focus);
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem var(--space);
  padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--accent);
  text-wrap: balance;
}

.brand-tagline {
  margin: 0.1rem 0 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Bottom nav */
.main-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.25rem 0.15rem;
  padding-bottom: max(0.25rem, env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -2px 12px rgba(26, 36, 28, 0.06);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: var(--touch);
  padding: 0.35rem 0.15rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.nav-btn .nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.nav-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--space-lg) var(--space);
}

.view[hidden] {
  display: none !important;
}

.view-title {
  margin: 0 0 0.35rem;
  font-size: var(--fs-xl);
  font-weight: 700;
  text-wrap: balance;
  color: var(--text);
}

.view-lead {
  margin: 0 0 var(--space-lg);
  color: var(--text-muted);
  text-wrap: pretty;
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space);
  margin-bottom: 0.25rem;
}

.view-head .view-lead {
  margin-bottom: 0;
}

/* Cards & lists */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-lg);
  box-shadow: var(--shadow);
  margin-bottom: var(--space);
}

.card-title {
  margin: 0 0 0.75rem;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
  text-wrap: balance;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.card-head .card-title {
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.list-empty {
  margin: 0;
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.list-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.list-item-row {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

.list-item-body {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text);
}

.list-item-meta {
  margin: 0.2rem 0 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.list-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--accent);
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: var(--space);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  display: block;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-label {
  display: block;
  margin-top: 0.35rem;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 600;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
}

.badge-ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-neutral {
  background: #eef1ef;
  color: var(--text-muted);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field label {
  font-weight: 600;
  color: var(--text);
}

.field-hint {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space);
}

@media (min-width: 520px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }

  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.input {
  min-height: var(--touch);
  padding: 0.65rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.input:hover {
  border-color: #9bb5a4;
}

.input:focus {
  border-color: var(--accent);
}

.input.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%231B6B3A' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.5rem;
}

.input.textarea {
  min-height: 5.5rem;
  resize: vertical;
  line-height: 1.5;
}

.input.file {
  padding: 0.75rem;
  font-size: var(--fs-sm);
}

.field label:has(input[type="checkbox"]) {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-weight: 600;
  min-height: var(--touch);
  padding: 0.5rem 0;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.15rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  margin-bottom: var(--space);
}

@media (min-width: 520px) {
  .filter-bar {
    grid-template-columns: 1.4fr 1fr;
  }
}

.form-error {
  margin: 0;
  padding: 0.75rem 1rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.success-msg {
  margin: 0;
  padding: 0.75rem 1rem;
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Symptoms */
.symptom-fieldset {
  border: none;
  margin: 0;
  padding: 0;
}

.symptom-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

@media (min-width: 520px) {
  .symptom-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.symptom-chip {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}

.symptom-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.symptom-chip:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.symptom-chip input {
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.15s ease-out, border-color 0.15s ease-out, color 0.15s ease-out;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: #d4ebd9;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: #eef1ef;
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  min-height: var(--touch);
  padding: 0.35rem 0.5rem;
  font-weight: 700;
}

.btn-text:hover {
  text-decoration: underline;
  background: var(--accent-soft);
}

.btn-sm {
  min-height: var(--touch);
  padding: 0.5rem 0.85rem;
  font-size: var(--fs-sm);
}

.btn-block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.linkish {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  padding: 0;
  min-height: auto;
  cursor: pointer;
}

/* Photo preview */
.photo-preview {
  margin-top: 0.5rem;
}

.photo-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Diagnosis result */
.severity-panel {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--space-lg);
  box-shadow: var(--shadow);
}

.severity-panel h3 {
  margin: 0 0 0.35rem;
  font-size: var(--fs-xl);
  color: var(--accent);
  text-wrap: balance;
}

.severity-panel .match-note {
  margin: 0 0 1rem;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.steps {
  margin: 0;
  padding-left: 1.35rem;
}

.steps li {
  margin-bottom: 0.55rem;
  padding-left: 0.25rem;
}

.prose {
  margin: 0;
  color: var(--text);
  text-wrap: pretty;
}

.prose + .prose {
  margin-top: 0.75rem;
}

.prose ul {
  margin: 0.5rem 0 0;
  padding-left: 1.35rem;
}

.prose li {
  margin-bottom: 0.4rem;
}

.section-label {
  margin: 0 0 0.35rem;
  font-size: var(--fs-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* Dialogs */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(32rem, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(26, 36, 28, 0.2);
  color: var(--text);
  background: var(--surface);
}

.dialog::backdrop {
  background: rgba(26, 36, 28, 0.55);
}

.dialog-body {
  padding: var(--space-lg);
}

.dialog-title {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 700;
  text-wrap: balance;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.25rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.85rem 1.15rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow);
  text-align: center;
}

/* Footer */
.app-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.5rem var(--space) 1.5rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* Severity strip */
.severity-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Care checkbox row */
.care-check {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.care-check input[type="checkbox"] {
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.2rem;
}

.care-check.is-done .list-item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Progress bar for match confidence */
.meter {
  height: 0.55rem;
  background: #e0e8e2;
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0 1rem;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}
