/* ===== CSS VARIABLES ===== */
:root {
  --bg: #f0f2ee;
  --surface: #ffffff;
  --green-dark: #1a3a1a;
  --green-primary: #2d6a2d;
  --green-bright: #3a8a3a;
  --green-light: #4caf50;
  --green-accent: #5cb85c;
  --green-pale: #e8f5e9;
  --text-dark: #111;
  --text-mid: #444;
  --text-muted: #888;
  --border: #d8ddd4;
  --gold: #c8890a;
  --blue: #1565c0;
  --font-main: 'DM Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
}

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

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text-dark);
  font-size: 13px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ═══════════════════════════════════════
   TOP NAV
═══════════════════════════════════════ */
.topnav {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 48px; position: sticky; top: 0; z-index: 100;
}
.topnav-left { display: flex; align-items: center; gap: 28px; }
.brand { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--text-dark); letter-spacing: -0.3px; }
.top-tabs { display: flex; gap: 2px; }
.tab {
  padding: 4px 14px; font-size: 13px; font-weight: 500; color: var(--text-muted);
  text-decoration: none; border-bottom: 2px solid transparent; transition: all 0.2s;
}
.tab.active, .tab:hover { color: var(--green-primary); border-bottom-color: var(--green-primary); }
.topnav-right { display: flex; align-items: center; gap: 10px; }
.btn-outline {
  padding: 5px 12px; border: 1.5px solid var(--border); background: transparent;
  border-radius: 6px; font-size: 12px; font-family: var(--font-main); cursor: pointer; color: var(--text-dark); transition: 0.2s;
}
.btn-outline:hover { border-color: var(--green-primary); color: var(--green-primary); }
.btn-filled {
  padding: 5px 12px; background: var(--green-primary); color: #fff;
  border: none; border-radius: 6px; font-size: 12px; font-family: var(--font-main); cursor: pointer; font-weight: 600;
}
.icon-btn { cursor: pointer; font-size: 16px; opacity: 0.7; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #ccc; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* ═══════════════════════════════════════
   LAYOUT
═══════════════════════════════════════ */
.layout { display: flex; flex: 1; min-height: calc(100vh - 48px); }

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
  width: 180px; min-width: 180px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 16px 0; position: sticky; top: 48px;
  height: calc(100vh - 48px); overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px 14px; border-bottom: 1px solid var(--border); margin-bottom: 10px;
}
.brand-icon-wrap {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--green-pale); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-icon { font-size: 16px; }
.brand-name { font-size: 10px; font-weight: 700; color: var(--text-dark); text-transform: uppercase; letter-spacing: 0.3px; }
.brand-sub { font-size: 9px; color: var(--green-primary); font-weight: 600; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px;
  border-radius: 8px; color: var(--text-mid); text-decoration: none;
  font-size: 12px; font-weight: 500; transition: 0.15s; margin-bottom: 2px;
}
.nav-item:hover { background: var(--green-pale); color: var(--green-primary); }
.nav-item.active {
  background: var(--green-pale); color: var(--green-primary);
  border-left: 3px solid var(--green-primary);
}
.nav-item.logout { color: #c62828; }
.nav-icon { font-size: 13px; }
.sidebar-bottom { padding: 8px 8px 0; border-top: 1px solid var(--border); margin-top: 8px; }
.new-analysis-btn {
  width: calc(100% - 0px); margin: 0 0 10px; padding: 9px;
  background: var(--green-primary); color: #fff; border: none; border-radius: 8px;
  font-size: 12px; font-family: var(--font-main); font-weight: 700;
  cursor: pointer; letter-spacing: 0.2px; transition: background 0.2s;
}
.new-analysis-btn:hover { background: var(--green-bright); }

/* ═══════════════════════════════════════
   MAIN
═══════════════════════════════════════ */
.main { flex: 1; padding: 28px 28px 36px; overflow-y: auto; }

/* REPORT HEADER */
.report-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.report-title { font-size: 30px; font-weight: 700; color: var(--text-dark); letter-spacing: -0.6px; margin-bottom: 6px; }
.report-meta { font-size: 12px; color: var(--text-muted); }
.status-badge {
  display: flex; align-items: center; gap: 12px;
  background: var(--green-pale); border: 1.5px solid var(--green-primary);
  border-radius: 12px; padding: 12px 18px;
}
.status-icon-wrap { font-size: 22px; }
.status-label { font-size: 9px; font-weight: 700; letter-spacing: 1.2px; color: var(--text-muted); text-transform: uppercase; }
.status-value { font-size: 17px; font-weight: 700; color: var(--green-primary); letter-spacing: 1px; }

/* KPI ROW */
.kpi-row { display: flex; gap: 16px; margin-bottom: 24px; }
.kpi-card {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 8px; }
.kpi-value { font-size: 36px; font-weight: 700; font-family: var(--font-mono); line-height: 1; margin-bottom: 8px; }
.kpi-value.green { color: var(--green-primary); }
.kpi-value.gold { color: var(--gold); }
.kpi-value.blue { color: var(--blue); }
.kpi-sub { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.kpi-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.kpi-dot.green-dot { background: var(--green-primary); }
.kpi-dot.blue-dot { background: var(--blue); }

/* SECTION TITLE */
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 700; color: var(--text-dark); margin-bottom: 12px;
}
.section-line { width: 18px; height: 3px; background: var(--green-primary); border-radius: 2px; }

/* ACTION PLAN */
.action-row { display: flex; gap: 14px; margin-bottom: 14px; }
.action-card {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.action-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.action-label { font-size: 10px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; }
.action-label.irrigation { color: #1565c0; }
.action-label.fertilization { color: var(--gold); }
.action-label.pesticide { color: var(--text-muted); }
.action-name { font-size: 17px; font-weight: 700; color: var(--text-dark); margin-bottom: 8px; }
.action-meta { font-size: 11px; color: var(--text-muted); }
.action-tag {
  font-size: 10px; font-weight: 700; padding: 3px 9px; border-radius: 20px; letter-spacing: 0.4px;
}
.action-tag.queued { background: #e3f2fd; color: #1565c0; }
.action-tag.high-block { background: #fff3e0; color: var(--gold); }
.action-tag.suppressed { background: #f5f5f5; color: #888; }

/* REASONING BAR */
.reasoning-bar {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--green-pale); border: 1px solid var(--green-primary);
  border-left: 4px solid var(--green-primary); border-radius: 8px;
  padding: 12px 16px; margin-bottom: 20px; font-size: 12px; color: var(--text-mid); line-height: 1.55;
}
.reasoning-icon { font-size: 15px; flex-shrink: 0; margin-top: 1px; }

/* AGENT DATA ROW */
.agent-data-row { display: flex; gap: 14px; margin-bottom: 20px; align-items: stretch; }
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 14px; box-shadow: var(--shadow); }
.agent-env { flex: 1.3; }
.agent-risk { flex: 1.3; }
.agent-perf { flex: 1; }
.agent-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.agent-tag { font-size: 9px; font-weight: 700; letter-spacing: 0.7px; color: var(--text-muted); text-transform: uppercase; }
.live-tag { font-size: 9px; font-weight: 700; color: var(--green-primary); background: var(--green-pale); padding: 2px 7px; border-radius: 20px; letter-spacing: 0.5px; }
.growth-tag { font-size: 11px; font-weight: 700; color: var(--green-primary); }

/* Env grid */
.env-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.env-cell { background: var(--bg); border-radius: 8px; padding: 10px; }
.env-label { font-size: 9px; font-weight: 700; letter-spacing: 0.8px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 4px; }
.env-value { font-size: 22px; font-weight: 700; color: var(--text-dark); font-family: var(--font-mono); }
.env-value.small-green { font-size: 14px; color: var(--green-primary); }

/* Risk chart */
.risk-legend { display: flex; gap: 14px; font-size: 10px; color: var(--text-muted); margin-bottom: 6px; }
.risk-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; vertical-align: middle; }
.risk-dot.water-dot { background: #1565c0; }
.risk-dot.heat-dot { background: #e53935; }
.risk-time-labels { display: flex; justify-content: space-between; font-size: 8px; color: var(--text-muted); margin-top: 4px; font-family: var(--font-mono); }

/* Perf labels */
.perf-labels { display: flex; justify-content: space-between; font-size: 8px; color: var(--text-muted); margin-top: 4px; font-family: var(--font-mono); }
.today-lbl { color: var(--green-primary); font-weight: 700; }

/* FUTURE STRATEGY */
.future-card { display: flex; background: #111; border-radius: var(--radius); overflow: hidden; color: #fff; }
.future-left {
  flex: 1; padding: 24px; display: flex; align-items: flex-start; gap: 14px;
  border-right: 1px solid rgba(255,255,255,0.1);
}
.future-icon { font-size: 28px; flex-shrink: 0; }
.future-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.future-desc { font-size: 12px; color: rgba(255,255,255,0.62); line-height: 1.55; }
.future-right {
  flex: 1.2; padding: 24px; background: #1a1a1a;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.future-rec-label { font-size: 9px; font-weight: 700; letter-spacing: 1.2px; color: var(--gold); text-transform: uppercase; margin-bottom: 4px; }
.future-rec-title { font-size: 20px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.future-rec-desc { font-size: 11px; color: rgba(255,255,255,0.55); line-height: 1.5; margin-bottom: 12px; }
.future-actions { display: flex; gap: 10px; }
.apply-btn {
  padding: 8px 18px; background: var(--green-primary); color: #fff;
  border: none; border-radius: 7px; font-size: 12px; font-family: var(--font-main);
  font-weight: 700; cursor: pointer; transition: background 0.2s, transform 0.1s;
}
.apply-btn:hover { background: var(--green-bright); }
.apply-btn:active { transform: scale(0.97); }
.dismiss-btn {
  padding: 8px 18px; background: transparent; color: rgba(255,255,255,0.55);
  border: 1px solid rgba(255,255,255,0.2); border-radius: 7px;
  font-size: 12px; font-family: var(--font-main); cursor: pointer; transition: 0.2s;
}
.dismiss-btn:hover { background: rgba(255,255,255,0.08); }

/* RESPONSIVE — TABLET */
@media (max-width: 900px) {
  .layout { flex-direction: column; min-height: 0; }
  .sidebar {
    width: 100%; min-width: 0;
    /* Base rule pins a full-height sticky column (height: calc(100vh - 48px)) — undo it. */
    height: auto; position: static; overflow-y: visible;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: 12px; padding: 10px 12px;
  }
  .main { padding: 16px 12px 24px; overflow-y: visible; overflow-x: visible; }
  .report-header, .kpi-row, .action-row, .agent-data-row, .future-card { flex-direction: column; }
  /* Canvases carry hardcoded width/height attributes — scale them to the card. */
  canvas { max-width: 100%; height: auto; }
}

/* RESPONSIVE — PHONE */
@media (max-width: 600px) {
  .topnav { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 12px; }
  .top-tabs { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { white-space: nowrap; }
  .env-grid { grid-template-columns: 1fr; }
}
