/* ============================================================
   Farm Operations Dashboard — Design System v2
   Matches mockup: Page 9 – Farm Operations Dashboard
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Variables ── */
:root {
  --green:        #0B5D3A;
  --green-mid:    #0D7045;
  --green-light:  #1A9A63;
  --green-pale:   #E8F5EE;
  --olive:        #4A7C59;
  --caramel:      #C98A2E;
  --caramel-pale: #FEF3DC;
  --orange:       #E07B30;
  --orange-pale:  #FEF0E6;
  --red:          #C0392B;
  --red-pale:     #FDECEC;
  --blue:         #2471A3;
  --blue-pale:    #EBF5FB;
  --teal:         #148F77;
  --teal-pale:    #E8F8F5;
  --purple:       #7D3C98;
  --purple-pale:  #F5EEF8;

  --sidebar-w:    240px;
  --sidebar-col:  64px;
  --topbar-h:     56px;

  --bg:           #F2F4F7;
  --card:         #FFFFFF;
  --border:       #E2E6EA;
  --text:         #1A2332;
  --muted:        #6B7889;
  --shadow:       0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 3px 10px rgba(0,0,0,0.10);
  --r:            10px;
  --r-sm:         6px;
}

[data-theme="dark"] {
  --bg:    #111827;
  --card:  #1F2937;
  --border:#2D3748;
  --text:  #F1F5F9;
  --muted: #94A3B8;
  --green-pale: #0f3122;
  --blue-pale: #0c2340;
  --teal-pale: #072a20;
  --orange-pale: #2d1a06;
  --red-pale: #2d0f0f;
  --caramel-pale: #2d1f06;
  --purple-pale: #1f0d2d;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 13px; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  transition: background .2s, color .2s;
}

/* ════════════════════════════
   SIDEBAR
   ════════════════════════════ */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--green);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .22s ease;
  overflow: hidden;
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  height: 100%;
}
#sidebar.collapsed { width: var(--sidebar-col); }

.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px;
  min-height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,0.10);
  flex-shrink: 0;
}
.sb-brand-icon {
  width: 34px; height: 34px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 17px;
  flex-shrink: 0;
}
.sb-brand-text { line-height: 1.25; overflow: hidden; white-space: nowrap; }
.sb-brand-name  { font-size: 12px; font-weight: 700; color: #fff; letter-spacing: .2px; }
.sb-brand-sub   { font-size: 10px; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .6px; }

.sb-nav { flex: 1; padding: 8px 0; overflow-y: auto; overflow-x: hidden; }
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 3px; }

.sb-section {
  font-size: 9px; font-weight: 700;
  color: rgba(255,255,255,.40);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 14px 16px 4px;
  white-space: nowrap;
}

.sb-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 16px;
  color: rgba(255,255,255,.78);
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.sb-item:hover  { background: rgba(255,255,255,.08); color: #fff; }
.sb-item.active { background: rgba(255,255,255,.14); color: #fff; border-left-color: var(--caramel); }
.sb-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sb-label { }
.sb-badge {
  margin-left: auto; background: var(--red);
  color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 10px; padding: 1px 6px;
}

.sb-footer {
  padding: 10px 14px 14px;
  font-size: 10px; color: rgba(255,255,255,.4);
  border-top: 1px solid rgba(255,255,255,.10);
  white-space: nowrap; overflow: hidden;
}

/* hide text when collapsed */
#sidebar.collapsed .sb-brand-text,
#sidebar.collapsed .sb-label,
#sidebar.collapsed .sb-section,
#sidebar.collapsed .sb-badge,
#sidebar.collapsed .sb-footer-text { display: none; }

/* ════════════════════════════
   MAIN WRAPPER
   ════════════════════════════ */
#app {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .22s ease;
}
#app.expanded { margin-left: var(--sidebar-col); }

/* ════════════════════════════
   TOP BAR
   ════════════════════════════ */
#topbar {
  height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

#menuBtn {
  background: none; border: none;
  font-size: 18px; padding: 6px; border-radius: 6px;
  color: var(--muted); cursor: pointer;
  flex-shrink: 0;
}
#menuBtn:hover { background: var(--bg); }

.tb-title { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; }

.tb-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

.tb-filters { display: flex; align-items: center; gap: 8px; flex: 1; overflow-x: auto; }
.tb-filters::-webkit-scrollbar { height: 2px; }

.f-select {
  height: 30px; padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 12px; font-weight: 500;
  outline: none; cursor: pointer;
  min-width: 100px;
}
.f-select:focus { border-color: var(--green); }

.tb-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: none; border-radius: var(--r-sm);
  font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: opacity .15s, transform .12s;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-green   { background: var(--green); color: #fff; padding: 7px 14px; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 6px 10px; }
.btn-outline:hover { border-color: var(--green); color: var(--green); background: var(--green-pale); }
.btn-icon    { padding: 7px 8px; }
.btn-caramel { background: var(--caramel); color: #fff; padding: 7px 12px; }
.btn-red     { background: transparent; border: 1px solid var(--red); color: var(--red); padding: 6px 10px; }
.btn-red:hover { background: var(--red); color: #fff; }

/* ════════════════════════════
   PAGE BODY
   ════════════════════════════ */
#page {
  flex: 1;
  padding: 16px 18px 24px;
  overflow-x: hidden;
}

/* ════════════════════════════
   KPI STRIP
   ════════════════════════════ */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--card);
  border-radius: var(--r);
  padding: 13px 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.kpi-icon-wrap {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 16px;
  flex-shrink: 0;
}
.kpi-label {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); line-height: 1.25;
  margin-top: 2px;
}
.kpi-val {
  font-size: 22px; font-weight: 800;
  color: var(--text); letter-spacing: -.5px;
  line-height: 1.1;
}
.kpi-bottom {
  display: flex; align-items: center; justify-content: space-between;
  gap: 4px;
}
.kpi-target { font-size: 10.5px; color: var(--muted); }
.kpi-badge {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 10.5px; font-weight: 700;
  padding: 2px 6px; border-radius: 20px;
}
.kpi-badge.up   { background: var(--green-pale); color: var(--green); }
.kpi-badge.down { background: var(--red-pale);   color: var(--red); }
.kpi-badge.warn { background: var(--caramel-pale); color: var(--caramel); }

.kpi-bar { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 3px; }
.kpi-bar-fill { height: 100%; border-radius: 2px; transition: width .6s ease; }

/* Icon colour variants */
.ic-teal   { background: var(--teal-pale);   color: var(--teal);   }
.ic-orange { background: var(--orange-pale);  color: var(--orange); }
.ic-blue   { background: var(--blue-pale);    color: var(--blue);   }
.ic-green  { background: var(--green-pale);   color: var(--green);  }
.ic-caramel{ background: var(--caramel-pale); color: var(--caramel);}
.ic-red    { background: var(--red-pale);     color: var(--red);    }
.ic-purple { background: var(--purple-pale);  color: var(--purple); }

.bar-green   { background: var(--green); }
.bar-caramel { background: var(--caramel); }
.bar-blue    { background: var(--blue); }
.bar-red     { background: var(--red); }
.bar-teal    { background: var(--teal); }
.bar-orange  { background: var(--orange); }
.bar-purple  { background: var(--purple); }

/* ════════════════════════════
   CHART GRIDS
   ════════════════════════════ */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.row-4 {
  display: grid;
  grid-template-columns: 1.6fr 1.4fr 1.4fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 12px 14px 0;
  display: flex; align-items: flex-start; justify-content: space-between;
}
.card-title { font-size: 12.5px; font-weight: 700; color: var(--text); }
.card-sub   { font-size: 11px; color: var(--muted); margin-top: 1px; }
.card-body  { padding: 10px 14px 14px; }

.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-wrap.h180 { height: 180px; }
.chart-wrap.h200 { height: 200px; }
.chart-wrap.h220 { height: 220px; }
.chart-wrap.h240 { height: 240px; }

/* ════════════════════════════
   HARVEST PROGRESS CARD
   ════════════════════════════ */
.harvest-layout {
  display: flex; gap: 12px;
  align-items: center;
  padding: 10px 14px 14px;
}
.harvest-donut { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
.harvest-donut canvas { width: 140px !important; height: 140px !important; }
.harvest-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.harvest-pct  { font-size: 22px; font-weight: 800; color: var(--green); line-height: 1; }
.harvest-lbl  { font-size: 10px; color: var(--muted); font-weight: 500; }

.harvest-stats { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.harvest-stat-row { display: flex; flex-direction: column; gap: 1px; }
.harvest-stat-label { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.harvest-stat-val { font-size: 14px; font-weight: 700; color: var(--text); }
.harvest-stat-note { font-size: 10px; color: var(--muted); }

/* ════════════════════════════
   COST BREAKDOWN CARD
   ════════════════════════════ */
.cost-layout {
  display: flex; gap: 8px;
  align-items: flex-start;
  padding: 10px 14px 14px;
}
.cost-donut { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.cost-donut canvas { width: 130px !important; height: 130px !important; }
.cost-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.cost-total-label { font-size: 9px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.cost-total-val   { font-size: 14px; font-weight: 800; color: var(--text); }

.cost-legend { flex: 1; display: flex; flex-direction: column; gap: 5px; padding-top: 4px; }
.cost-leg-item { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cost-leg-dot  { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.cost-leg-name { font-size: 11px; color: var(--muted); flex: 1; }
.cost-leg-pct  { font-size: 11px; font-weight: 700; color: var(--text); }
.cost-leg-amt  { font-size: 10px; color: var(--muted); text-align: right; min-width: 40px; }

/* ════════════════════════════
   BOTTOM ROW
   ════════════════════════════ */

/* Performance Table */
.perf-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.perf-table th {
  background: var(--bg);
  color: var(--muted);
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px;
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.perf-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.perf-table tr:last-child td { border-bottom: none; }
.perf-table tr:hover td { background: var(--bg); }
.perf-table td strong { font-weight: 700; }

/* Equipment utilization bars */
.equip-list { display: flex; flex-direction: column; gap: 9px; }
.equip-item { }
.equip-top  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.equip-name { font-size: 11.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 5px; }
.equip-icon { font-size: 13px; }
.equip-pct  { font-size: 11.5px; font-weight: 700; color: var(--text); }
.equip-bar  { height: 7px; background: var(--border); border-radius: 4px; overflow: hidden; }
.equip-fill { height: 100%; border-radius: 4px; transition: width .6s ease; }

/* Alerts */
.alert-list { display: flex; flex-direction: column; gap: 7px; }
.alert-row {
  display: flex; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
}
.alert-row.warn   { background: var(--caramel-pale); border-left: 3px solid var(--caramel); }
.alert-row.danger { background: var(--red-pale);     border-left: 3px solid var(--red); }
.alert-row.info   { background: var(--blue-pale);    border-left: 3px solid var(--blue); }
.alert-row.ok     { background: var(--green-pale);   border-left: 3px solid var(--green); }
.alert-ico  { font-size: 14px; flex-shrink: 0; margin-top: 1px; }
.alert-body .a-title { font-weight: 700; margin-bottom: 1px; }
.alert-body .a-action { font-size: 10.5px; color: var(--muted); margin-top: 2px; font-weight: 500; }

/* Quick Overview */
.quick-card {
  background: var(--green);
  border-radius: var(--r);
  padding: 14px;
  color: #fff;
  box-shadow: var(--shadow-md);
}
.quick-title { font-size: 12px; font-weight: 700; margin-bottom: 12px; opacity: .9; text-transform: uppercase; letter-spacing: .4px; }
.quick-items { display: flex; flex-direction: column; gap: 9px; }
.quick-item  { display: flex; align-items: flex-start; gap: 8px; font-size: 11.5px; line-height: 1.4; }
.q-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.q-green  { background: #6BCB77; }
.q-yellow { background: #FFD93D; }
.q-red    { background: #FF6B6B; }
.q-blue   { background: #74B9FF; }

/* Badge */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px;
}
.badge-ok  { background: var(--green-pale); color: var(--green); }
.badge-bad { background: var(--red-pale);   color: var(--red); }
.badge-warn{ background: var(--caramel-pale); color: var(--caramel); }

/* ════════════════════════════
   SECTION LABEL
   ════════════════════════════ */
.section-label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.section-label::before {
  content: '';
  width: 3px; height: 14px;
  background: var(--green);
  border-radius: 2px;
  display: block;
}

/* ════════════════════════════
   MANAGEMENT INSIGHTS STRIP
   ════════════════════════════ */
.insights-strip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.insights-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.insight-item {
  font-size: 11.5px; line-height: 1.5;
  color: var(--text);
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--green);
}

/* ════════════════════════════
   TOAST
   ════════════════════════════ */
#toasts {
  position: fixed; bottom: 18px; right: 18px;
  z-index: 9999; display: flex; flex-direction: column; gap: 7px;
}
.toast {
  padding: 10px 16px; border-radius: 8px;
  background: #1a2332; color: #fff;
  font-size: 12.5px; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(8px);
  transition: opacity .3s, transform .3s;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok   { background: var(--green); }
.toast-err  { background: var(--red); }
.toast-info { background: var(--blue); }

/* ════════════════════════════
   PRINT
   ════════════════════════════ */
@media print {
  #sidebar, #topbar, #toasts { display: none !important; }
  #app { margin-left: 0 !important; }
  .card { break-inside: avoid; }
}

/* ════════════════════════════
   RESPONSIVE
   ════════════════════════════ */
@media (max-width: 1300px) {
  .kpi-strip { grid-template-columns: repeat(4, 1fr); }
  .row-4 { grid-template-columns: 1fr 1fr; }
  .insights-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  .row-2 { grid-template-columns: 1fr; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  .row-4 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  :root { --sidebar-w: 240px; }
  #sidebar { transform: translateX(-100%); }
  #sidebar.mobile-open { transform: translateX(0); }
  #app { margin-left: 0 !important; }
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .row-3 { grid-template-columns: 1fr; }
  .insights-grid { grid-template-columns: 1fr; }
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
