/* =====================================================================
   RRIV THEME — giao diện mới cho phần NỘI DUNG (không đụng thanh công cụ)
   Nạp sau styles.css và mobile.css.
   ===================================================================== */
:root {
  --rv-bg: #F4F6F2;
  --rv-surface: #FFFFFF;
  --rv-ink: #15211A;
  --rv-muted: #5B6B60;
  --rv-line: #E2E8E0;
  --rv-line-soft: #EDF1EC;
  --rv-brand: #2D6A0F;
  --rv-brand-ink: #1F4D0A;
  --rv-brand-soft: #E8F2E1;
  --rv-band: #CFE6C1;
  --rv-temp: #B45309;
  --rv-water: #1F6FB2;
  --rv-ph: #6D28D9;
  --rv-ec: #0F766E;
  --rv-warn-bg: #FEF3C7;
  --rv-warn-ink: #92400E;
  --rv-font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Font + nền cho vùng nội dung và các trang dạng lớp phủ */
.main-content, #stationDetail, #ndviView, #allChartsView, .rv-scope {
  font-family: var(--rv-font);
  color: var(--rv-ink);
}
.main-content { background: var(--rv-bg); }

/* ---------- Thành phần dùng chung ---------- */
.rv-card {
  background: var(--rv-surface);
  border: 1px solid var(--rv-line);
  border-radius: 16px;
}
.rv-h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.rv-h2 { margin: 0; font-size: 15px; font-weight: 600; }
.rv-sub { font-size: 13px; color: var(--rv-muted); }
.rv-label { font-size: 12px; color: var(--rv-muted); font-weight: 500; }
.rv-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  background: var(--rv-brand-soft); color: var(--rv-brand-ink); white-space: nowrap;
}
.rv-chip.warn { background: var(--rv-warn-bg); color: var(--rv-warn-ink); }
.rv-chip.info { background: #E6F0F8; color: #1A5A91; }
.rv-chip.muted { background: #EEF0EE; color: #4A5650; }
.rv-btn {
  height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--rv-line);
  background: var(--rv-surface); color: var(--rv-ink); font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  transition: background .15s, transform .15s;
}
.rv-btn:hover { background: #F7F9F6; }
.rv-btn.icon { width: 40px; padding: 0; }
.rv-btn.primary { background: var(--rv-brand); border-color: var(--rv-brand); color: #fff; font-weight: 600; }
.rv-btn.primary:hover { background: var(--rv-brand-ink); }
.rv-seg { display: inline-flex; background: #EEF1EC; border-radius: 10px; padding: 3px; gap: 2px; }
.rv-seg button {
  height: 30px; padding: 0 14px; border: none; border-radius: 8px; background: transparent;
  color: #3E4C43; font: inherit; font-size: 12px; cursor: pointer;
}
.rv-seg button.active { background: #fff; color: var(--rv-brand-ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* Thanh vùng tốt: dải xanh = ngưỡng, vạch đen = giá trị hiện tại */
.rv-range { position: relative; height: 8px; border-radius: 4px; background: #EEF1EC; }
.rv-range .band { position: absolute; top: 0; bottom: 0; background: var(--rv-band); border-radius: 4px; }
.rv-range .mark { position: absolute; top: -4px; width: 4px; height: 16px; border-radius: 2px; background: var(--rv-ink); transition: left .6s ease; }
.rv-range-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--rv-muted); }

/* ---------- Ô số liệu ---------- */
.rv-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.rv-kpi { padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; }
.rv-kpi-val { font-size: 28px; font-weight: 700; letter-spacing: -0.6px; line-height: 1.1; }
.rv-kpi-val small { font-size: 15px; font-weight: 500; color: var(--rv-muted); }
.rv-kpi-val.alert-value { color: #B42318 !important; }

/* =====================================================================
   CHI TIẾT TRẠM
   ===================================================================== */
#stationDetail.rv-station { background: var(--rv-bg); padding: 20px 24px 32px; box-sizing: border-box; }
.rv-station .rv-wrap { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.rv-station-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.rv-station-head .title { display: flex; flex-direction: column; gap: 2px; flex: 1 1 240px; min-width: 0; }
.rv-battery { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.rv-battery-shell { width: 30px; height: 15px; border: 2px solid #3E4C43; border-radius: 4px; padding: 1px; position: relative; }
.rv-battery-shell::after { content: ''; position: absolute; right: -5px; top: 3px; width: 3px; height: 5px; background: #3E4C43; border-radius: 0 2px 2px 0; }
.rv-battery-shell .battery-level-bar { height: 100%; border-radius: 2px; }
.rv-station-body { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.rv-station-main { flex: 999 1 560px; min-width: 0; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.rv-station-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.rv-chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.rv-mini-map { height: 140px; border-radius: 12px; overflow: hidden; }
.rv-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: #3E4C43; }

/* =====================================================================
   BẢN ĐỒ: ô số liệu + danh sách trạm
   ===================================================================== */
#mainDashboard.rv-dash { display: flex; flex-direction: column; gap: 14px; padding: 14px 16px 16px; box-sizing: border-box; background: var(--rv-bg); }
.rv-dash-body { flex: 1; min-height: 0; display: flex; gap: 14px; }
.rv-dash-body #map { flex: 1; min-width: 0; height: auto; border-radius: 16px; overflow: hidden; border: 1px solid var(--rv-line); }
.rv-dash-body .leaflet-container { border-radius: 16px; }
.rv-station-list { width: 340px; flex-shrink: 0; padding: 14px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.rv-st-item {
  display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--rv-line-soft); background: #fff; cursor: pointer; text-align: left; font: inherit; color: inherit;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.rv-st-item:hover { border-color: #CFE0C6; box-shadow: 0 6px 16px rgba(21,33,26,.06); transform: translateY(-1px); }
.rv-st-row { display: flex; align-items: center; gap: 10px; }
.rv-st-name { font-weight: 600; font-size: 14px; flex: 1; }
.rv-dot { width: 10px; height: 10px; border-radius: 5px; flex-shrink: 0; background: #2D9A4B; }
.rv-dot.warn { background: #D97706; }
.rv-dot.off { background: #8A9690; }
.rv-st-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; font-size: 12px; color: var(--rv-muted); }

/* =====================================================================
   NDVI
   ===================================================================== */
#ndviView .ndvi-page { font-family: var(--rv-font); }
#ndviView .ndvi-card { border-radius: 16px !important; border: 1px solid var(--rv-line) !important; box-shadow: none !important; }
#ndviView #ndvi-crop-card { border-radius: 16px; }
#ndviView .ndvi-reco-section { display: none !important; }

/* =====================================================================
   Máy tính bảng & điện thoại
   ===================================================================== */
@media (max-width: 1100px) {
  .rv-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rv-station-list { width: 290px; }
}
@media (max-width: 768px) {
  #stationDetail.rv-station { padding: 12px 12px 20px; }
  .rv-station .rv-wrap { gap: 12px; }
  .rv-h1 { font-size: 19px; }
  .rv-kpis { gap: 10px; }
  .rv-kpi { padding: 12px 14px; }
  .rv-kpi-val { font-size: 22px; }

  /* Bản đồ trên điện thoại: ô số liệu cuộn ngang, danh sách trạm nằm dưới bản đồ */
  #mainDashboard.rv-dash { padding: 0; gap: 0; overflow-y: auto; }
  #mainDashboard.rv-dash > .rv-kpis {
    display: flex; overflow-x: auto; gap: 8px; padding: 10px 10px 8px; scroll-snap-type: x mandatory;
  }
  #mainDashboard.rv-dash > .rv-kpis .rv-kpi { flex: 0 0 46%; scroll-snap-align: start; padding: 10px 12px; }
  .rv-dash-body { flex-direction: column; gap: 0; }
  .rv-dash-body #map { flex: none; height: 58vh; min-height: 320px; border-radius: 0; border: none; }
  .rv-dash-body .leaflet-container { border-radius: 0; }
  .rv-station-list { width: auto; border-radius: 0 !important; border: none !important; padding: 12px 10px; overflow: visible; }
}

/* Ghim trạm trên bản đồ: bỏ ô vuông trắng mặc định của Leaflet */
.leaflet-marker-icon.rv-pin { background: transparent; border: none; }
.rv-pin .custom-marker { box-sizing: border-box; }
/* Nút chọn Vệ tinh / Bản đồ */
.leaflet-control-layers { border-radius: 10px !important; border: none !important; box-shadow: 0 2px 8px rgba(0,0,0,.2) !important; font-family: var(--rv-font); font-size: 12px; }
.leaflet-control-layers-expanded { padding: 6px 10px 6px 8px; }

/* ---------- Phóng to biểu đồ ---------- */
.acv-expand {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--rv-line); background: #fff;
  color: #3E4C43; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; font-size: 13px;
  transition: background .15s, color .15s;
}
.acv-expand:hover { background: var(--rv-brand-soft); color: var(--rv-brand-ink); border-color: #CFE0C6; }
#acvZoomOverlay {
  position: fixed; inset: 0; z-index: 20000; background: rgba(15, 23, 42, .55);
  display: flex; align-items: stretch; justify-content: center; padding: 24px; box-sizing: border-box;
  font-family: var(--rv-font); animation: acvzIn .18s ease-out;
}
@keyframes acvzIn { from { opacity: 0; } to { opacity: 1; } }
.acvz-panel { background: #fff; border-radius: 18px; width: 100%; max-width: 1600px; display: flex; flex-direction: column; padding: 16px 18px 10px; box-sizing: border-box; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.acvz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.acvz-title { font-size: 20px; font-weight: 700; color: var(--rv-ink); }
.acvz-sub { font-size: 13px; color: var(--rv-muted); }
.acvz-chart { flex: 1; min-height: 300px; width: 100%; }
.acvz-hint { font-size: 12px; color: var(--rv-muted); text-align: center; padding-top: 4px; }
@media (max-width: 700px) {
  #acvZoomOverlay { padding: 0; }
  .acvz-panel { border-radius: 0; padding: 12px 10px 8px; }
  .acvz-title { font-size: 17px; }
  .acvz-btn-txt { display: none; }
  .acvz-hint { display: none; }
}