:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #d8e2dc;
  --text-primary: #142019;
  --text-secondary: #405249;
  --text-muted: #65776d;
  --accent: #14684b;
  --accent-strong: #0b3d2e;
  --accent-soft: #e6f4ee;
  --success: #15803d;
  --warning: #b45309;
  --error: #b91c1c;
  --info: #0369a1;
  --gold: #d4a017;
  --text-on-accent: #ffffff;
  --text-on-status: #ffffff;
  --text-on-gold: #211a05;
  --text-on-sidebar: #ffffff;
  --national-green: #008751;
  --overlay: rgba(4, 15, 9, 0.68);
  --shadow-color: rgba(15, 23, 42, 0.12);
  --shadow-soft: rgba(15, 23, 42, 0.06);
  --focus-ring: color-mix(in srgb, var(--accent) 28%, transparent);
  --ease-agrow: cubic-bezier(0.2, 0.8, 0.2, 1);
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0a120e;
  --surface: #101a14;
  --surface-raised: #17241c;
  --border: #304238;
  --text-primary: #f2f7f4;
  --text-secondary: #c7d3cc;
  --text-muted: #9fafa5;
  --accent: #34d399;
  --accent-strong: #1f8f5f;
  --accent-soft: #143a2a;
  --success: #15803d;
  --warning: #b45309;
  --error: #b91c1c;
  --info: #0369a1;
  --gold: #d4a017;
  --text-on-accent: #07120d;
  --text-on-status: #ffffff;
  --text-on-gold: #211a05;
  --text-on-sidebar: #f2f7f4;
  --national-green: #19a86c;
  --overlay: rgba(1, 8, 4, 0.78);
  --shadow-color: rgba(0, 0, 0, 0.34);
  --shadow-soft: rgba(0, 0, 0, 0.2);
  --focus-ring: color-mix(in srgb, var(--accent) 34%, transparent);
}

[data-app='dashboard'] {
  --accent: #14684b;
  --accent-strong: #0b3d2e;
  --accent-soft: #e6f4ee;
}

[data-app='field-agent'] {
  --accent: #b45309;
  --accent-strong: #92400e;
  --accent-soft: #fff7ed;
}

[data-app='farmer'] {
  --accent: #15803d;
  --accent-strong: #166534;
  --accent-soft: #dcfce7;
}

html[data-theme='dark'] [data-app='dashboard'] {
  --accent: #34d399;
  --accent-strong: #10b981;
  --accent-soft: #143a2a;
}

html[data-theme='dark'] [data-app='field-agent'] {
  --accent: #f59e0b;
  --accent-strong: #d97706;
  --accent-soft: #3a260f;
}

html[data-theme='dark'] [data-app='farmer'] {
  --accent: #4ade80;
  --accent-strong: #22c55e;
  --accent-soft: #123923;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: Inter, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

[x-cloak] { display: none !important; }

.agrow-display { font-family: Sora, sans-serif; }
.agrow-tabular { font-variant-numeric: tabular-nums; }

.agrow-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  transition: background-color 150ms var(--ease-agrow), border-color 150ms var(--ease-agrow), color 150ms var(--ease-agrow), transform 150ms var(--ease-agrow), box-shadow 150ms var(--ease-agrow);
  cursor: pointer;
}

.agrow-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 5px 16px var(--shadow-color); }
.agrow-button:active:not(:disabled) { transform: translateY(0); }
.agrow-button:disabled { cursor: not-allowed; opacity: 0.62; }
.agrow-button--primary { background: var(--accent); color: var(--text-on-accent); }
.agrow-button--primary:hover:not(:disabled) { background: var(--accent-strong); }
.agrow-button--secondary { border-color: var(--border); background: var(--surface-raised); color: var(--text-secondary); }
.agrow-button--secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.agrow-button--danger { border-color: var(--error); background: var(--surface-raised); color: var(--error); }

.agrow-input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  padding: 11px 14px;
  color: var(--text-primary);
  transition: border-color 150ms var(--ease-agrow), box-shadow 150ms var(--ease-agrow);
}

.agrow-input::placeholder { color: var(--text-muted); opacity: 0.78; }
.agrow-input:hover { border-color: var(--text-muted); }
.agrow-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); outline: none; }
.agrow-input[aria-invalid='true'] { border-color: var(--error); box-shadow: 0 0 0 4px color-mix(in srgb, var(--error) 18%, transparent); }

.agrow-spinner {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 2px solid color-mix(in srgb, currentColor 34%, transparent);
  border-top-color: currentColor;
  border-radius: 999px;
  animation: agrow-spin 700ms linear infinite;
}

.agrow-spinner--accent { border-color: color-mix(in srgb, var(--accent) 22%, transparent); border-top-color: var(--accent); }

.agrow-toast-region {
  position: fixed;
  z-index: 100;
  top: 20px;
  right: 20px;
  display: grid;
  width: min(380px, calc(100vw - 32px));
  gap: 10px;
  pointer-events: none;
}

.agrow-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  background: var(--surface-raised);
  padding: 12px 14px;
  color: var(--text-primary);
  box-shadow: 0 12px 28px var(--shadow-color);
  animation: agrow-toast-in 250ms var(--ease-agrow) both;
  pointer-events: auto;
}

.agrow-toast svg { width: 20px; height: 20px; flex: none; }
.agrow-toast--success { border-left-color: var(--success); }
.agrow-toast--success svg { background: var(--success); color: var(--text-on-status); }
.agrow-toast--error { border-left-color: var(--error); }
.agrow-toast--error svg { background: var(--error); color: var(--text-on-status); }
.agrow-toast--info { border-left-color: var(--info); }
.agrow-toast--info svg { background: var(--info); color: var(--text-on-status); }
.agrow-toast--warning { border-left-color: var(--warning); }
.agrow-toast--warning svg { background: var(--warning); color: var(--text-on-status); }
.agrow-toast--leaving { animation: agrow-toast-out 250ms var(--ease-agrow) both; }

.agrow-avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.agrow-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.agrow-badge svg { width: 15px; height: 15px; }
.agrow-badge--verified { background: var(--gold); color: var(--text-on-gold); animation: agrow-badge-shine 700ms var(--ease-agrow) both; }
.agrow-badge--pending { background: var(--warning); color: var(--text-on-status); }
.agrow-badge--unverified { background: color-mix(in srgb, var(--text-muted) 14%, var(--surface-raised)); color: var(--text-secondary); }
.agrow-badge--rejected { background: var(--error); color: var(--text-on-status); }

.agrow-modal-backdrop {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--overlay);
  padding: 20px;
  backdrop-filter: blur(4px);
}

.agrow-modal {
  width: min(440px, 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-raised);
  padding: 24px;
  color: var(--text-primary);
  box-shadow: 0 24px 70px var(--shadow-color);
}

.agrow-error {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}

.agrow-error svg { width: 16px; height: 16px; flex: none; border-radius: 999px; background: var(--error); color: var(--text-on-status); }
.agrow-shake { animation: agrow-shake 400ms var(--ease-agrow); }

.theme-toggle {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 150ms var(--ease-agrow), color 150ms var(--ease-agrow), background-color 150ms var(--ease-agrow);
}

.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 19px; height: 19px; }
.theme-icon--when-dark { display: none; }
html[data-theme='dark'] .theme-icon--when-light { display: none; }
html[data-theme='dark'] .theme-icon--when-dark { display: block; }

.token-icon-chip {
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.app-sidebar { background: var(--accent-strong); color: var(--text-on-sidebar); box-shadow: 0 -8px 24px var(--shadow-color); }
html[data-theme='dark'] .app-sidebar { background: color-mix(in srgb, var(--accent-strong) 24%, var(--bg)); }
.app-drawer-overlay { background: var(--overlay); }
.app-brand-chip { border: 1px solid color-mix(in srgb, var(--text-on-sidebar) 22%, transparent); background: color-mix(in srgb, var(--text-on-sidebar) 10%, transparent); color: var(--text-on-sidebar); }
.app-product-mark { color: var(--accent); }
.app-status-pill { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; background: color-mix(in srgb, var(--success) 14%, var(--surface-raised)); padding: 8px 12px; color: var(--success); font-size: 12px; font-weight: 700; }
.app-progress-ring { border-color: var(--accent-soft); background: var(--surface-raised); }

.status-icon--success { background: var(--success); color: var(--text-on-status); }
.status-icon--warning { background: var(--warning); color: var(--text-on-status); }
.status-icon--info { background: var(--info); color: var(--text-on-status); }
.status-icon--error { background: var(--error); color: var(--text-on-status); }

.app-nav-link {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 10px;
  color: color-mix(in srgb, var(--text-on-sidebar) 76%, transparent);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 150ms var(--ease-agrow), color 150ms var(--ease-agrow);
}

.app-nav-link svg { width: 21px; height: 21px; flex: none; }
.app-nav-link:hover { background: color-mix(in srgb, var(--text-on-sidebar) 10%, transparent); color: var(--text-on-sidebar); }
.app-nav-link[aria-current='page'] { background: var(--accent-soft); color: var(--accent-strong); }
.app-nav-link[aria-current='page']::after {
  position: absolute;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  content: '';
}

.app-content-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: 0 1px 3px var(--shadow-soft);
}

.credential-card[data-app] .credential-icon,
.credential-card[data-app] .use-credential { background: var(--accent-soft); color: var(--accent-strong); }
.credential-card[data-app] .credential-mark { color: var(--accent); }

html[data-theme='dark'] .leaflet-tile-pane {
  filter: brightness(0.64) invert(0.88) hue-rotate(108deg) saturate(0.72) contrast(1.08);
}

.leaflet-tile-pane { transition: filter 250ms var(--ease-agrow); }

@keyframes agrow-spin { to { transform: rotate(360deg); } }
@keyframes agrow-toast-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes agrow-toast-out { to { opacity: 0; transform: translateY(-10px); } }
@keyframes agrow-badge-shine { 0% { transform: scale(0.94); box-shadow: 0 0 0 color-mix(in srgb, var(--gold) 0%, transparent); } 65% { transform: scale(1.03); box-shadow: 0 0 20px color-mix(in srgb, var(--gold) 30%, transparent); } 100% { transform: scale(1); box-shadow: 0 0 0 color-mix(in srgb, var(--gold) 0%, transparent); } }
@keyframes agrow-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }

@media (max-width: 640px) {
  .agrow-toast-region { top: 12px; right: 50%; transform: translateX(50%); }
}

@media (min-width: 768px) {
  .app-nav-link {
    width: 52px;
    flex-direction: row;
    justify-content: center;
    font-size: 14px;
  }
  .app-nav-link[aria-current='page']::after {
    inset: 50% auto auto 0;
    width: 4px;
    height: 28px;
    border-radius: 0 999px 999px 0;
    transform: translateY(-50%);
  }
}

@media (min-width: 1024px) {
  .app-nav-link { width: 100%; justify-content: flex-start; padding: 0 14px; }
}

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