/* ══════════════════════════════════════
   DASHBOARD TAB
══════════════════════════════════════ */
#tab-dashboard {
  height: calc(100vh - 56px);
  overflow: hidden;
  flex-wrap: wrap;
}
#tab-dashboard > footer {
  flex-basis: 100%;
  flex-shrink: 0;
  height: auto;
  order: 99;
}
#tab-dashboard .d-left,
#tab-dashboard .d-right {
  height: calc(100vh - 56px - 47px);
}

/* Left panel */
.d-left {
  width: 360px; flex-shrink:0;
  background: #fff;
  border-right: 1px solid var(--border);
  display:flex; flex-direction:column;
  overflow-y:auto;
}
.d-right {
  flex:1; display:flex; flex-direction:column; overflow:hidden; min-width:0;
}

/* Generic panel section */
.sec { padding:10px 16px; border-bottom:1px solid var(--border); }
.sec-title {
  font-size:10.5px; font-weight:700; text-transform:uppercase;
  letter-spacing:.07em; color:var(--g2); margin-bottom:6px;
  display:flex; align-items:center; gap:5px;
}

/* Farm header strip */
.farm-strip {
  background: var(--navy);
  padding: 10px 16px;
  display:flex; justify-content:space-between; align-items:center; flex-shrink:0;
}
.farm-name { color:#fff; font-weight:800; font-size:13px; }
.farm-meta { color:rgba(255,255,255,.5); font-size:10px; margin-top:2px; }
.farm-stat-row { display:flex; gap:16px; }
.fstat { text-align:right; }
.fstat-n { color:var(--teal); font-size:16px; font-weight:800; line-height:1; }
.fstat-l { color:rgba(255,255,255,.45); font-size:9px; margin-top:2px; }

/* Field grid */
.field-compass {
  display:flex; justify-content:space-between; align-items:center;
  font-size:10px; color:var(--g3); margin-bottom:3px;
}
.field-3d-wrap {
  perspective: 900px;
  perspective-origin: 50% 60%;
  filter: drop-shadow(0 14px 18px rgba(0,0,0,.55));
  margin-top: -105px;
}
.field-3d-object {
  position: relative;
  transform: rotateX(42deg) rotateY(-6deg);
  transform-origin: center bottom;
  transform-style: preserve-3d;
}
.field-grid {
  display:grid; grid-template-columns:repeat(6,1fr);
  gap:2px; border-radius:6px 6px 0 0; overflow:hidden;
  border:2px solid var(--navy); border-bottom:none; background:var(--navy);
}
.field-soil-edge {
  position:absolute; top:100%; left:0; right:0;
  height:26px;
  transform-origin: top center;
  transform: rotateX(-90deg);
  background: linear-gradient(to bottom, #5c3a12 0%, #3a2208 55%, #1c0f02 100%);
  border-radius:0 0 4px 4px;
}
.gc {
  aspect-ratio:1/1.3; cursor:pointer; position:relative;
  background-image: repeating-linear-gradient(
    0deg, rgba(0,0,0,.18) 0, rgba(0,0,0,.18) 1px,
    transparent 1px, transparent 6px
  );
  display:flex; align-items:flex-end; justify-content:flex-start;
  padding:3px; transition:filter .12s, outline .1s;
}
.gc:hover { filter:brightness(1.18); }
.gc.sel { outline:2.5px solid #fff; outline-offset:-2px; z-index:2; }
.gc-label { font-size:8px; color:rgba(255,255,255,.75); font-weight:700; line-height:1; }
.gc-battery { font-size:7px; color:rgba(255,255,255,.65); font-weight:600; line-height:1; margin-top:2px; }
.gc-dot {
  position:absolute; top:3px; right:3px;
  width:5px; height:5px; border-radius:50%;
  background:#fff; opacity:.9;
  box-shadow: 0 0 4px rgba(255,255,255,.6);
}
.gc-dot-lowbat {
  position:absolute; top:1px; right:1px;
  width:4px; height:4px; border-radius:50%;
  background:#f97316; border:1px solid rgba(0,0,0,.25);
  z-index:3;
}

/* Zone detail */
.zone-hdr {
  display:flex; justify-content:space-between; align-items:flex-start;
  margin-bottom:10px;
}
.zone-id { font-weight:800; font-size:15px; }
.zone-sub { font-size:10px; color:var(--g2); margin-top:2px; }
.health-pill {
  font-size:10px; font-weight:700; padding:3px 10px; border-radius:20px;
}
.hp-ok   { background:#dcfce7; color:#15803d; }
.hp-warn { background:#fef3c7; color:#b45309; }
.hp-bad  { background:#fee2e2; color:#b91c1c; }

.zone-metrics { display:grid; grid-template-columns:1fr 1fr; gap:7px; }
.zm {
  background:var(--cream); border-radius:8px; padding:9px 11px;
  border-left:3px solid transparent; transition:border-color .2s;
}
.zm.st-ok   { border-left-color:var(--green); }
.zm.st-warn { border-left-color:var(--orange); }
.zm.st-bad  { border-left-color:#ef4444; }
.zm-name { font-size:9.5px; color:var(--g2); margin-bottom:3px; }
.zm-val  { font-size:19px; font-weight:800; line-height:1; }
.zm-unit { font-size:9px; color:var(--g2); }
.zm-status { font-size:9px; font-weight:700; margin-top:3px; }
.st-ok   .zm-status { color:#15803d; }
.st-warn .zm-status { color:var(--orange); }
.st-bad  .zm-status { color:#dc2626; }

/* Legend */
.legend { display:flex; gap:10px; flex-wrap:wrap; }
.li { display:flex; align-items:center; gap:5px; font-size:10px; color:var(--g2); }
.lc { width:12px; height:12px; border-radius:3px; flex-shrink:0; }

/* KPI row */
.kpi-row {
  display:grid; grid-template-columns:repeat(6,1fr);
  gap:9px; padding:12px 14px;
  background:#fff; border-bottom:1px solid var(--border); flex-shrink:0;
}
.kpi {
  background:var(--cream); border-radius:10px; padding:11px 12px;
  cursor:pointer; border:2px solid transparent; transition:all .18s;
}
.kpi:hover { box-shadow:var(--sh); transform:translateY(-1px); }
.kpi.active { border-color:var(--teal); background:#eef9fa; }
.kpi-icon { font-size:16px; margin-bottom:5px; }
.kpi-val  { font-size:20px; font-weight:800; line-height:1; }
.kpi-unit { font-size:10px; color:var(--g2); margin-left:1px; }
.kpi-name { font-size:10px; font-weight:600; color:var(--g2); margin-top:4px; }
.kpi-badge {
  display:inline-block; font-size:9px; font-weight:700;
  padding:1px 7px; border-radius:10px; margin-top:5px;
}
.kb-ok   { background:#dcfce7; color:#15803d; }
.kb-warn { background:#fef3c7; color:#b45309; }
.kb-bad  { background:#fee2e2; color:#b91c1c; }

@keyframes valflash {
  0%   { color:var(--teal); }
  100% { color:var(--g1); }
}
.val-flash { animation:valflash .7s ease-out; }

/* Chart area */
.chart-area {
  flex:1; padding:12px 14px;
  display:flex; flex-direction:column; gap:10px; overflow:hidden;
  min-height:0;
}
.chart-card {
  background:#fff; border-radius:var(--r); padding:15px 16px;
  box-shadow:var(--sh); display:flex; flex-direction:column;
  flex:1; min-height:0;
}
.cc-hdr {
  display:flex; align-items:baseline; justify-content:space-between;
  margin-bottom:10px; flex-shrink:0;
}
.cc-title { font-size:12.5px; font-weight:700; color:var(--g2); }
.cc-range { font-size:10px; color:var(--g3); }
.cc-body { flex:1; position:relative; min-height:0; }
.cc-body canvas { position:absolute; inset:0; }

/* Recommendations */
.recs {
  padding:10px 14px 12px;
  background:#fff; border-top:1px solid var(--border); flex-shrink:0;
}
.rec-row {
  display:flex; gap:9px; overflow-x:auto; padding-bottom:2px;
  scrollbar-width:thin; scrollbar-color:var(--border) transparent;
}
.rec {
  background:var(--cream); border-radius:9px;
  padding:9px 13px; min-width:205px; max-width:240px;
  border-left:3px solid var(--teal); flex-shrink:0;
}
.rec.warn { border-left-color:var(--orange); }
.rec.bad  { border-left-color:#dc2626; }
.rec-h { font-size:11px; font-weight:700; margin-bottom:3px; }
.rec-p { font-size:10px; color:var(--g2); line-height:1.45; }

/* N₂O hotspot overlay */
.n2o-layer {
  position:absolute; inset:0;
  display:grid; grid-template-columns:repeat(6,1fr);
  gap:2px; pointer-events:none; overflow:visible; z-index:20;
}
.n2o-cell {
  display:flex; align-items:center; justify-content:center;
  overflow:visible;
}
.n2o-arrow-wrap {
  display:flex; flex-direction:column; align-items:center;
  animation: n2o-float 1.8s ease-in-out infinite;
}
.n2o-tri {
  width:0; height:0;
  border-left:7px solid transparent;
  border-right:7px solid transparent;
  border-bottom:13px solid rgba(220,38,38,.80);
  filter:drop-shadow(0 0 5px rgba(220,38,38,.55));
}
.n2o-lbl {
  font-size:7.5px; font-weight:800; color:rgba(220,38,38,.90);
  margin-top:2px; letter-spacing:.05em;
  text-shadow:0 1px 3px rgba(0,0,0,.45);
}
@keyframes n2o-float {
  0%,100% { transform:translateY(0);   opacity:.75; }
  50%      { transform:translateY(-5px); opacity:1;  }
}

/* Nitrogen flux panel */
.nflux-panel {
  padding:10px 14px 8px;
  background:#f8fafc;
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}
.nflux-title {
  font-size:9.5px; font-weight:700; text-transform:uppercase;
  letter-spacing:.07em; color:var(--g2); margin-bottom:8px;
}
.nflux-row {
  display:flex; gap:6px; align-items:stretch;
}
.nflux-card {
  flex:1; background:#fff; border-radius:8px;
  border:1px solid var(--border); padding:7px 9px;
  display:flex; flex-direction:column; gap:2px;
}
.nflux-card-in  { border-top:3px solid var(--teal); }
.nflux-card-out { border-top:3px solid #f97316; flex:1.4; }
.nflux-card-net { border-top:3px solid var(--navy); }
.nflux-head {
  display:flex; align-items:center; gap:5px;
  font-size:10px; font-weight:700; color:var(--g1);
}
.nflux-arrow {
  font-size:16px; line-height:1;
}
.nflux-val {
  font-size:17px; font-weight:800; line-height:1; margin-top:2px;
}
.nflux-unit { font-size:9px; color:var(--g2); margin-left:2px; font-weight:600; }
.nflux-sub {
  margin-top:4px; display:flex; flex-direction:column; gap:2px;
  border-top:1px solid var(--border); padding-top:4px;
}
.nflux-sub-row {
  display:flex; align-items:center; justify-content:space-between;
  font-size:9.5px; color:var(--g2);
}
.nflux-sub-lbl { display:flex; align-items:center; gap:3px; }
.nflux-sub-arr { font-size:11px; color:#f97316; }
.nflux-sub-val { font-weight:700; color:var(--g1); }
.nflux-net-val { color:var(--navy); }
.nflux-net-pct {
  font-size:9.5px; color:var(--g2); margin-top:1px;
}

/* Log application button inside N Input card */
.fert-report-btn {
  margin-top:8px; width:100%; padding:5px 0; border-radius:6px;
  border:1.5px solid rgba(45,160,166,.4); background:rgba(45,160,166,.07);
  color:var(--teal); font-size:9.5px; font-weight:700; cursor:pointer;
  transition:all .15s; letter-spacing:.02em;
}
.fert-report-btn:hover { background:rgba(45,160,166,.18); border-color:var(--teal); }

@media (max-width: 768px) {
  #tab-dashboard { height:auto; overflow-y:auto; flex-direction:column; flex-wrap:nowrap; }
  #tab-dashboard .d-left,
  #tab-dashboard .d-right { height:auto; }
  .d-left { width:100%; border-right:none; border-bottom:1px solid var(--border); overflow-y:visible; }
  .d-right { overflow:visible; flex-direction:column; }

  /* Nitrogen balance — stack cards */
  .nflux-row { flex-direction:column; }
  .nflux-card-out { flex:none; }

  /* KPI row — 3 columns instead of 6 */
  .kpi-row { grid-template-columns:repeat(3,1fr); }

  /* Chart — give it a defined height instead of flex-fill */
  .chart-area { overflow:visible; flex:none; padding-bottom:16px; }
  .chart-card  { flex:none; }
  .cc-body     { height:220px; flex:none; }

  /* Recommendations — already horizontal-scroll, just ensure padding */
  .recs { flex-shrink:0; }
}
