/* ============================================
   Agri Nexus — Design System
   Mobile-first, low-literacy-friendly, high contrast
   ============================================ */

:root {
  /* Earth-tone palette */
  --c-bg:        #fff8e7;
  --c-surface:   #ffffff;
  --c-surface-2: #fdf3d8;
  --c-text:      #1f2a1f;
  --c-text-soft: #506250;
  --c-muted:     #8a9a8a;

  /* Brand */
  --c-primary:        #2e7d32;
  --c-primary-dark:   #1b5e20;
  --c-primary-soft:   #c8e6c9;
  --c-accent:         #f57c00;
  --c-accent-soft:    #ffe0b2;

  /* Severity */
  --c-safe:    #2e7d32;
  --c-caution: #ed6c02;
  --c-urgent:  #c62828;
  --c-info:    #1565c0;

  /* Nutrient colors */
  --c-n: #1565c0;
  --c-p: #ef6c00;
  --c-k: #6a1b9a;

  /* Layout */
  --radius:    18px;
  --radius-lg: 26px;
  --radius-pill: 999px;
  --tap:       56px;
  --shadow:    0 2px 6px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Noto Sans Bengali", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

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

/* App shell */
.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: 96px; /* room for bottom nav */
  position: relative;
  background: var(--c-bg);
}

/* ============================================
   App bar + global chrome
   ============================================ */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.app-bar__title {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.app-bar__back {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: rgba(255,255,255,.15);
  color: #fff;
}
.app-bar__back:hover, .app-bar__back:focus-visible {
  background: rgba(255,255,255,.28);
  outline: none;
}

.demo-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  background: var(--c-accent);
  color: #fff;
  border-radius: var(--radius-pill);
}

.lang-picker {
  display: inline-flex;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.lang-picker button {
  min-width: 38px;
  padding: 6px 10px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  border-radius: var(--radius-pill);
  opacity: 0.7;
}
.lang-picker button[aria-pressed="true"] {
  background: #fff;
  color: var(--c-primary-dark);
  opacity: 1;
}

/* Page container */
.page {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.page__title {
  font-size: 26px;
  font-weight: 800;
  margin: 0;
}
.page__sub {
  color: var(--c-text-soft);
  margin: 0;
}

/* ============================================
   Bottom nav
   ============================================ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--c-surface);
  border-top: 1px solid #eee;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  min-height: var(--tap);
  height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--c-text-soft);
  font-size: 12px;
  font-weight: 600;
}
.bottom-nav button .icon {
  font-size: 26px;
  line-height: 1;
}
.bottom-nav button[aria-current="page"] {
  color: var(--c-primary);
}
.bottom-nav button[aria-current="page"] .icon {
  transform: translateY(-2px);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 18px;
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow);
  transition: transform .08s ease;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible {
  outline: 3px solid var(--c-accent);
  outline-offset: 2px;
}
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--accent  { background: var(--c-accent); color: #fff; }
.btn--block   { width: 100%; }
.btn--lg {
  font-size: 20px;
  padding: 18px 24px;
  border-radius: var(--radius-lg);
}
.btn--ghost {
  background: transparent;
  box-shadow: none;
  border: 2px solid var(--c-primary);
  color: var(--c-primary);
}
.btn .icon { font-size: 22px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--c-surface);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 600;
  min-height: 40px;
}
.chip--soft  { background: var(--c-primary-soft); color: var(--c-primary-dark); box-shadow: none; }
.chip--accent{ background: var(--c-accent-soft); color: #8a4a00; box-shadow: none; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: var(--c-surface);
  box-shadow: var(--shadow);
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}
.card--hero {
  background: linear-gradient(135deg, #2e7d32 0%, #43a047 100%);
  color: #fff;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.card--accent {
  background: var(--c-accent);
  color: #fff;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}

.tile {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  min-height: 110px;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
}
.tile .icon {
  font-size: 34px;
}
.tile__title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.tile__sub {
  font-size: 13px;
  color: var(--c-text-soft);
  margin: 0;
}

/* ============================================
   Severity badge
   ============================================ */
.severity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  color: #fff;
  font-size: 15px;
}
.severity--safe    { background: var(--c-safe); }
.severity--caution { background: var(--c-caution); }
.severity--urgent  { background: var(--c-urgent); }

.severity-banner {
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.severity-banner--safe    { background: linear-gradient(135deg,#43a047,#2e7d32); }
.severity-banner--caution { background: linear-gradient(135deg,#fb8c00,#ef6c00); }
.severity-banner--urgent  { background: linear-gradient(135deg,#e53935,#c62828); }

/* ============================================
   Toast
   ============================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2a1f;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   Voice mic button (big circular)
   ============================================ */
.mic-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 38px;
  box-shadow: var(--shadow-lg);
}
.mic-btn--listening {
  animation: pulse 1.2s infinite;
  background: var(--c-urgent);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(198,40,40,.45); }
  50%      { box-shadow: 0 0 0 18px rgba(198,40,40,0); }
}

/* ============================================
   Forms
   ============================================ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label { font-weight: 600; }
.field input, .field select, .field textarea {
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 2px solid #d6d6c8;
  padding: 12px 14px;
  background: var(--c-surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--c-primary);
}

/* ============================================
   Onboarding overlay
   ============================================ */
.onboard {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.55);
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.onboard__card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.onboard__title {
  font-size: 24px;
  font-weight: 800;
  margin: 0;
}
.onboard__step {
  font-size: 13px;
  color: var(--c-text-soft);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0;
}
.opt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.opt-grid button {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--c-surface-2);
  font-weight: 700;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 15px;
}
.opt-grid button .icon { font-size: 28px; }
.opt-grid button.selected {
  background: var(--c-primary);
  color: #fff;
}

/* ============================================
   Plant Doctor module
   ============================================ */
.capture-hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
  text-align: center;
  padding: var(--space-5) var(--space-4);
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.capture-hero .big-emoji { font-size: 80px; }
.capture-btn {
  width: 100%;
  min-height: 84px;
  border-radius: var(--radius-lg);
  background: var(--c-primary);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
}
.capture-btn .icon { font-size: 32px; }
.capture-input { display: none; }

.preview-img {
  width: 100%;
  border-radius: var(--radius-lg);
  background: #eee;
  aspect-ratio: 4/3;
  object-fit: cover;
}
.analyzing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  text-align: center;
}
.spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 6px solid var(--c-primary-soft);
  border-top-color: var(--c-primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.diagnosis-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 10px 0;
  border-top: 1px solid #eee;
}
.diagnosis-stat:first-child { border-top: 0; }
.diagnosis-stat__label { color: rgba(255,255,255,.85); font-size: 14px; }
.diagnosis-stat__value { font-size: 22px; font-weight: 800; }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}
.tabs button {
  min-height: 44px;
  border-radius: calc(var(--radius) - 4px);
  font-weight: 700;
  font-size: 15px;
  color: var(--c-text-soft);
}
.tabs button[aria-selected="true"] {
  background: var(--c-primary);
  color: #fff;
}

.step-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.step-list li {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}
.step-num {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
  display: grid;
  place-items: center;
  font-weight: 800;
}

/* ============================================
   Farm Assistant module
   ============================================ */
.chat {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: 100px;
}
.bubble {
  max-width: 85%;
  padding: 14px 16px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  font-size: 17px;
  line-height: 1.5;
}
.bubble--me {
  align-self: flex-end;
  background: var(--c-primary);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble--bot {
  align-self: flex-start;
  background: var(--c-surface);
  border-bottom-left-radius: 6px;
}
.bubble__source {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  opacity: .8;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.quick-chips button {
  background: var(--c-surface);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow);
  min-height: 44px;
}

.composer {
  position: sticky;
  bottom: 84px;
  background: var(--c-bg);
  padding: var(--space-3) 0;
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.composer input {
  flex: 1;
  min-height: var(--tap);
  border-radius: var(--radius-pill);
  border: 2px solid #d6d6c8;
  padding: 0 18px;
  background: var(--c-surface);
}
.composer input:focus { outline: none; border-color: var(--c-primary); }
.context-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  font-size: 14px;
}

/* ============================================
   Fertilizer Scanner module
   ============================================ */
.npk-bars {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.npk-bar {
  display: grid;
  grid-template-columns: 28px 1fr 56px;
  gap: var(--space-2);
  align-items: center;
}
.npk-bar__label {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}
.npk-bar__label.n { background: var(--c-n); }
.npk-bar__label.p { background: var(--c-p); }
.npk-bar__label.k { background: var(--c-k); }
.npk-bar__track {
  height: 16px;
  background: #eee;
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.npk-bar__fill {
  height: 100%;
  border-radius: inherit;
}
.npk-bar__fill.n { background: var(--c-n); }
.npk-bar__fill.p { background: var(--c-p); }
.npk-bar__fill.k { background: var(--c-k); }
.npk-bar__value {
  font-weight: 800;
  text-align: right;
}

.verdict {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}
.verdict .icon { font-size: 36px; }
.verdict--good { background: var(--c-safe); }
.verdict--bad  { background: var(--c-urgent); }
.verdict--meh  { background: var(--c-caution); }

.fert-list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  min-height: var(--tap);
}
.fert-list-item .icon { font-size: 28px; }
.fert-list-item__name { font-weight: 700; }
.fert-list-item__npk { color: var(--c-text-soft); font-size: 13px; }

/* ============================================
   Weather module
   ============================================ */
.weather-hero {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.weather-hero__icon { font-size: 84px; line-height: 1; }
.weather-hero__temp { font-size: 56px; font-weight: 800; line-height: 1; }
.weather-hero__cond { font-size: 18px; opacity: .9; }
.weather-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: 14px;
}
.weather-meta div {
  background: rgba(255,255,255,.18);
  border-radius: var(--radius);
  padding: 8px;
  text-align: center;
}
.weather-meta strong { display: block; font-size: 16px; }

.forecast-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  scroll-snap-type: x mandatory;
}
.forecast-day {
  flex: 0 0 92px;
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: var(--space-3);
  text-align: center;
  box-shadow: var(--shadow);
  scroll-snap-align: start;
}
.forecast-day__name { font-size: 13px; color: var(--c-text-soft); font-weight: 700; }
.forecast-day__icon { font-size: 30px; margin: 4px 0; }
.forecast-day__hi { font-weight: 800; font-size: 18px; }
.forecast-day__lo { color: var(--c-text-soft); font-size: 14px; }
.forecast-day__rain { color: var(--c-info); font-size: 12px; margin-top: 4px; }

.alert-card {
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: #fff;
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}
.alert-card .icon { font-size: 32px; flex-shrink: 0; }
.alert-card--rain     { background: linear-gradient(135deg,#1976d2,#0d47a1); }
.alert-card--storm    { background: linear-gradient(135deg,#5e35b2,#311b92); }
.alert-card--heatwave { background: linear-gradient(135deg,#e53935,#b71c1c); }
.alert-card--frost    { background: linear-gradient(135deg,#039be5,#01579b); }

/* ============================================
   Mandi module
   ============================================ */
.price-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.price-hero__amount { font-size: 48px; font-weight: 800; line-height: 1; }
.price-hero__unit   { font-size: 16px; opacity: .8; }
.price-hero__where  { font-size: 18px; font-weight: 600; }

.price-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--c-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
  min-height: var(--tap);
}
.price-row__name { font-weight: 700; }
.price-row__sub  { font-size: 12px; color: var(--c-text-soft); }
.price-row__price { font-size: 20px; font-weight: 800; }
.price-row__trend {
  font-size: 14px;
  font-weight: 700;
  min-width: 64px;
  text-align: right;
}
.trend-up   { color: var(--c-safe); }
.trend-down { color: var(--c-urgent); }
.trend-flat { color: var(--c-text-soft); }

.history-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 100px;
  padding: var(--space-2) 0;
}
.history-bars div {
  flex: 1;
  background: var(--c-primary-soft);
  border-radius: 4px 4px 0 0;
  position: relative;
  min-height: 8px;
}
.history-bars div:last-child { background: var(--c-primary); }
.history-bars div::after {
  content: attr(data-day);
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--c-text-soft);
}

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

/* ============================================
   Reduced motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast nudges */
@media (prefers-contrast: more) {
  :root {
    --c-text-soft: #2a3528;
    --c-muted: #455444;
  }
  .card { border: 1px solid #c9c9b8; }
}
