/* AgronIQ — design tokens */
:root {
  --bg: #FAFAF7;
  --bg-elev: #FFFFFF;
  --bg-sunken: #F2F1EC;
  --ink: #0A0A0A;
  --ink-2: #2A2A2A;
  --ink-3: #6B6B66;
  --ink-4: #A8A8A2;
  --line: #E6E5DE;
  --line-strong: #C9C8C0;

  --accent: oklch(0.52 0.14 145);       /* agri green */
  --accent-soft: oklch(0.94 0.05 145);
  --accent-ink: oklch(0.32 0.10 145);

  --warn: oklch(0.72 0.16 70);          /* amber — MSP trigger */
  --warn-soft: oklch(0.95 0.06 80);
  --warn-ink: oklch(0.42 0.14 60);

  --danger: oklch(0.58 0.20 27);
  --danger-soft: oklch(0.95 0.04 27);

  --info: oklch(0.55 0.13 245);
  --info-soft: oklch(0.95 0.04 245);

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;

  --shadow-1: 0 1px 0 rgba(10,10,10,0.04), 0 1px 2px rgba(10,10,10,0.04);
  --shadow-2: 0 1px 0 rgba(10,10,10,0.04), 0 8px 24px -6px rgba(10,10,10,0.10);

  --font-sans: 'Inter Tight', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  --font-serif: 'Instrument Serif', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

.mono { font-family: var(--font-mono); font-feature-settings: "zero"; }
.serif { font-family: var(--font-serif); font-weight: 400; }

/* App shell */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 24px;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--ink);
  display: grid; place-items: center;
  color: var(--bg);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
}
.brand-mark.accent { background: var(--accent); color: white; }

.nav {
  display: flex;
  gap: 2px;
  align-items: center;
}
.nav button {
  background: transparent;
  border: none;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
}
.nav button:hover { color: var(--ink); background: var(--bg-sunken); }
.nav button.active { color: var(--ink); background: var(--bg-sunken); }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--ink-3);
}
.live-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
}
.live-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 oklch(0.52 0.14 145 / 0.6); }
  70% { box-shadow: 0 0 0 8px oklch(0.52 0.14 145 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.52 0.14 145 / 0); }
}

.persona-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px 4px 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink-2);
}
.persona-chip .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  transition: all 0.12s ease;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn.primary:hover { background: #1f1f1f; }
.btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn.accent:hover { background: var(--accent-ink); }
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover { background: var(--bg-sunken); color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.card-pad { padding: 20px; }

/* Tag/Pill */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  background: var(--bg-sunken);
  color: var(--ink-2);
  border: 1px solid var(--line);
  text-transform: uppercase;
  font-weight: 500;
}
.tag.accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: transparent; }
.tag.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag.solid { background: var(--ink); color: var(--bg); border-color: transparent; }

/* Layout helpers */
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.between { display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--ink-3); }
.muted-2 { color: var(--ink-4); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.vdivider { width: 1px; background: var(--line); align-self: stretch; }

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: calc(100vh - 52px);
  border-bottom: 1px solid var(--line);
}
.hero-left {
  padding: 64px 56px 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  position: relative;
  background:
    radial-gradient(ellipse at top right, oklch(0.94 0.05 145 / 0.5), transparent 60%),
    var(--bg);
}
.hero-right {
  padding: 36px;
  background: var(--bg-sunken);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.h-display {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 64px;
  line-height: 1.02;
  letter-spacing: -0.035em;
  color: var(--ink);
  text-wrap: balance;
}
.h-display .accent-word {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  color: var(--accent-ink);
}

.h-lead {
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink-2);
  max-width: 540px;
  text-wrap: pretty;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.kpi {
  padding: 16px 0;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}
.kpi:last-child { border-right: 0; }
.kpi-num {
  font-family: var(--font-sans);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1;
}
.kpi-num .unit { color: var(--ink-3); font-weight: 400; font-size: 14px; margin-left: 2px; }
.kpi-label {
  margin-top: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Module gallery */
.modules {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.module-card {
  padding: 28px 24px 24px;
  border-right: 1px solid var(--line);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  min-height: 280px;
}
.module-card:last-child { border-right: 0; }
.module-card:hover { background: var(--bg-sunken); }
.module-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.05em;
}
.module-name {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.module-desc {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.5;
  flex: 1;
}
.module-bullets {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.module-bullets li {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.module-bullets li::before {
  content: "—";
  color: var(--ink-4);
}
.module-cta {
  margin-top: auto;
  padding-top: 12px;
  font-size: 12px;
  color: var(--accent-ink);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}
.module-card:hover .module-cta { color: var(--accent); }

/* Section */
.section {
  padding: 64px 56px;
  border-bottom: 1px solid var(--line);
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 32px;
  gap: 24px;
}
.section-title {
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.025em;
  margin: 0;
}
.section-lead {
  color: var(--ink-3);
  font-size: 15px;
  max-width: 480px;
  margin-top: 6px;
}

/* Hero right — terminal / dashboard preview */
.dash-preview {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-2);
}
.dash-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.dash-dots {
  display: flex; gap: 4px;
}
.dash-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }

.split-card {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.split-card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elev);
}
.split-card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  font-family: var(--font-mono);
}

/* Photo placeholder — striped */
.photo-ph {
  background:
    repeating-linear-gradient(
      135deg,
      transparent 0 14px,
      oklch(0.93 0 0 / 0.5) 14px 15px
    ),
    var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  padding: 12px;
}

/* Tables */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  color: var(--ink-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.tbl td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--bg); }

/* Sidebar layout for module screens */
.module-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 52px);
}
.sidebar {
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar h4 {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-4);
  margin: 16px 8px 8px;
}
.sidebar h4:first-child { margin-top: 0; }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}
.sidebar-item:hover { background: var(--bg-sunken); }
.sidebar-item.active { background: var(--bg-sunken); color: var(--ink); font-weight: 500; }
.sidebar-item .num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-4);
  margin-left: auto;
}

.workspace {
  padding: 32px 40px;
  overflow-x: hidden;
}
.ws-head { margin-bottom: 24px; }
.ws-head h1 {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 6px 0 4px;
}
.ws-head .breadcrumb {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* AgriTest kiosk specific */
.kiosk-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}
.qc-row {
  display: grid;
  grid-template-columns: 180px 1fr 90px 80px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.qc-row:last-child { border-bottom: 0; }
.qc-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.qc-name .sub {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-3);
  font-weight: 400;
  margin-top: 2px;
}
.qc-bar {
  height: 6px;
  background: var(--bg-sunken);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.qc-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(.2,.8,.3,1);
}
.qc-bar-fill.warn { background: var(--warn); }
.qc-bar-fill.danger { background: var(--danger); }
.qc-bar-thresh {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 1px;
  background: var(--ink-3);
}
.qc-value {
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
  color: var(--ink);
  font-weight: 500;
}
.qc-status {
  text-align: right;
}

input[type="range"].slim {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--line);
  border-radius: 999px;
  outline: none;
}
input[type="range"].slim::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  border: 2px solid var(--bg-elev);
  box-shadow: 0 0 0 1px var(--line-strong);
}

/* Grade badge */
.grade-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1.4;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid oklch(0.52 0.14 145 / 0.2);
  padding: 16px;
}
.grade-badge .label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.8;
}
.grade-badge .grade {
  font-family: var(--font-sans);
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
  margin-top: 4px;
}
.grade-badge .meta {
  font-family: var(--font-mono);
  font-size: 11px;
  margin-top: 8px;
}
.grade-badge.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: oklch(0.72 0.16 70 / 0.25); }
.grade-badge.danger { background: var(--danger-soft); color: var(--danger); border-color: oklch(0.58 0.20 27 / 0.2); }

/* Provenance chain */
.chain {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.chain-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 16px;
  padding: 16px 0;
  position: relative;
}
.chain-step + .chain-step { border-top: 1px dashed var(--line); }
.chain-step .marker {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1.5px solid var(--line-strong);
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  position: relative;
  z-index: 1;
}
.chain-step.done .marker {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.chain-step.active .marker {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
  box-shadow: 0 0 0 4px oklch(0.52 0.14 145 / 0.15);
}
.chain-line {
  position: absolute;
  left: 14px;
  top: 44px;
  bottom: -16px;
  width: 1px;
  background: var(--line-strong);
  z-index: 0;
}
.chain-step:last-child .chain-line { display: none; }
.chain-step.done .chain-line { background: var(--accent); }

.chain-content h4 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
}
.chain-content .data {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-3);
  line-height: 1.7;
}
.chain-content .data .k { color: var(--ink-4); }
.chain-content .data .v { color: var(--ink-2); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

/* Stat tile */
.stat-tile {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-elev);
}
.stat-tile .label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}
.stat-tile .num {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-tile .delta {
  font-size: 11.5px;
  font-family: var(--font-mono);
  margin-top: 6px;
  color: var(--accent-ink);
}
.stat-tile .delta.down { color: var(--danger); }

/* Animations */
@keyframes flash {
  0% { background: oklch(0.94 0.05 145); }
  100% { background: transparent; }
}
.flash { animation: flash 0.8s ease; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up { animation: slideUp 0.3s ease; }

/* Smart contract card */
.contract-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.contract-card.firing {
  border-color: var(--accent);
  background: var(--accent-soft);
  animation: flash 1.4s ease;
}
.contract-card .name {
  font-weight: 500;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.contract-card .logic {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.5;
  background: var(--bg-sunken);
  padding: 8px 10px;
  border-radius: 4px;
}

/* Map placeholder */
.map-ph {
  position: relative;
  background: var(--bg-sunken);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
  min-height: 280px;
}
.map-dot {
  position: absolute;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 0 oklch(0.52 0.14 145 / 0.5);
  animation: mappulse 2s infinite;
}
@keyframes mappulse {
  0% { box-shadow: 0 0 0 0 oklch(0.52 0.14 145 / 0.5); }
  70% { box-shadow: 0 0 0 12px oklch(0.52 0.14 145 / 0); }
  100% { box-shadow: 0 0 0 0 oklch(0.52 0.14 145 / 0); }
}

/* Hash ticker */
.ticker {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toggle row */
.seg {
  display: inline-flex;
  background: var(--bg-sunken);
  border-radius: 6px;
  padding: 2px;
  gap: 0;
}
.seg button {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-3);
  border-radius: 4px;
}
.seg button.active {
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
