/* ===== SKELETON LOADING ===== */
.skeleton-icon {
  width: 24px;
  height: 24px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
}

.skeleton-title {
  height: 20px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
  width: 60%;
}

.skeleton-value {
  height: 32px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 6px;
  width: 80%;
  margin-bottom: 8px;
}

.skeleton-text {
  height: 16px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 4px;
  width: 40%;
}

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--medium-gray);
  border-top: 4px solid var(--primary-green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== OPTIMIZED CARD ANIMATIONS ===== */
.measurement-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.measurement-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.measurement-value .text-success {
  animation: value-update 2s ease-out;
}

@keyframes value-update {
  0% { transform: scale(1.05); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
:root {
  --primary-green: #198754;
  --light-green: #28a745;
  --dark-green: #155724;
  --accent-blue: #0d6efd;
  --light-blue: #17a2b8;
  --water-blue: #20c997;
  --white: #ffffff;
  --off-white: #f8f9fa;
  --light-gray: #f8f9fa;
  --medium-gray: #e9ecef;
  --dark-gray: #6c757d;
  --background: #f0f4f8;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --info: #17a2b8;
  --shadow-light: 0 2px 12px rgba(25, 135, 84, 0.1);
  --shadow-md: 0 4px 20px rgba(25, 135, 84, 0.15);
  --shadow-lg: 0 8px 32px rgba(25, 135, 84, 0.2);
  --border-radius: 12px;
  --border-radius-lg: 16px;
}

/* ===== BASE STYLES ===== */
body {
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  background: linear-gradient(135deg, var(--background) 0%, #e8f5e8 100%);
  margin: 0;
  padding: 0;
  color: #333;
  line-height: 1.6;
}

/* ===== NAVBAR & HAMBURGER MENU ===== */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--medium-gray);
  box-shadow: var(--shadow-light);
  padding: 0.5rem 1.5rem;
}

.navbar-brand {
  color: var(--primary-green) !important;
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: 1px;
}

.navbar-toggler {
  border: none;
  background: transparent;
}

.navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(25,135,84,0.7)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}

.navbar-nav .nav-link {
  color: var(--primary-green) !important;
  font-weight: 500;
  font-size: 1.1rem;
  margin-right: 1rem;
  transition: color 0.2s;
}

.navbar-nav .nav-link.active,
.navbar-nav .nav-link:focus,
.navbar-nav .nav-link:hover {
  color: var(--accent-blue) !important;
  background: var(--off-white);
  border-radius: var(--border-radius);
}

@media (max-width: 991px) {
  .navbar-nav .nav-link {
    margin-right: 0;
    margin-bottom: 0.5rem;
  }
}

/* ===== SIDEBAR (if used for admin) ===== */
.sidebar {
  background: var(--white);
  border-right: 1px solid var(--medium-gray);
  min-height: 100vh;
  padding: 2rem 1rem;
  box-shadow: var(--shadow-light);
}

.sidebar .nav-link {
  color: var(--primary-green);
  font-weight: 500;
  margin-bottom: 1rem;
  border-radius: var(--border-radius);
  transition: background 0.2s;
}

.sidebar .nav-link.active,
.sidebar .nav-link:hover {
  background: var(--light-gray);
  color: var(--accent-blue);
}

/* ===== DASHBOARD HEADER ===== */
.dashboard-header {
  background: linear-gradient(90deg, var(--primary-green), var(--water-blue));
  color: var(--white);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-lg);
}

.header-title {
  font-weight: 700;
  letter-spacing: 1px;
}

#last-update {
  color: var(--white);
  opacity: 0.8;
}

/* ===== CONTROL PANEL ===== */
.control-panel {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

/* ===== MEASUREMENT CARDS/BOXES ===== */
.measurement-grid,
#latest-measurements-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.2rem;
  margin: 1.5rem 0;
}

.measurement-box {
  background: linear-gradient(135deg, var(--white), var(--light-gray));
  border: 1px solid rgba(25, 135, 84, 0.1);
  border-radius: var(--border-radius);
  padding: 1.5rem 1rem;
  text-align: center;
  transition: all 0.3s ease;
  position: relative;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-light);
}

.measurement-box:hover {
  transform: scale(1.03);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-green);
}

.measurement-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.measurement-icon {
  font-size: 2rem;
  margin-right: 0.5rem;
  color: var(--primary-green);
}

.measurement-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark-gray);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.measurement-value {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--primary-green);
  margin: 0.5rem 0;
}

.measurement-unit {
  font-size: 0.9rem;
  color: var(--dark-gray);
  margin-left: 0.25rem;
}

.measurement-timestamp {
  font-size: 0.8rem;
  color: var(--medium-gray);
  margin-top: 0.5rem;
}

.measurement-chart {
  height: 90px;
  margin-top: 1rem;
  position: relative;
}

/* ===== AGGREGATION BOXES ===== */
.aggregation-box-content {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(25,135,84,0.08);
  padding: 1.2rem 1rem 1rem 1rem;
  min-width: 220px;
  min-height: 220px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  transition: box-shadow 0.2s;
  position: relative;
  margin-bottom: 1rem;
}
.aggregation-box-content:hover {
  box-shadow: 0 4px 24px rgba(25,135,84,0.15);
}
.agg-header {
  font-size: 1.1rem;
  font-weight: 600;
  color: #198754;
  width: 100%;
  justify-content: center;
}
.agg-icon {
  font-size: 2.2rem;
  display: inline-block;
  width: 2.5rem;
  text-align: center;
}
.agg-label {
  font-size: 1.1rem;
  color: #198754;
  font-weight: 500;
}
.agg-value-section {
  font-size: 2.2rem;
  font-weight: 700;
  color: #198754;
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  width: 100%;
  justify-content: center;
}
.agg-unit {
  font-size: 1.1rem;
  color: #6c757d;
  font-weight: 400;
}
.agg-type .badge {
  font-size: 0.95rem;
  font-weight: 500;
}
.agg-chart-container {
  width: 100%;
  min-height: 90px;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  height: 90px;
}
.agg-points-count {
  font-size: 0.85rem;
  color: #adb5bd;
  text-align: center;
}

/* ===== CHARTS ===== */
#charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.chart-container {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-light);
  padding: 1rem;
  margin: 1rem 0;
  border: 1px solid rgba(25, 135, 84, 0.1);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--medium-gray);
}

.chart-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-green);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-controls {
  display: flex;
  gap: 0.5rem;
}

.chart-btn {
  padding: 0.25rem 0.75rem;
  border-radius: 15px;
  border: 1px solid rgba(25, 135, 84, 0.3);
  background: var(--white);
  color: var(--primary-green);
  font-size: 0.75rem;
  transition: all 0.3s ease;
  cursor: pointer;
}

.chart-btn:hover,
.chart-btn.active {
  background: var(--primary-green);
  color: var(--white);
  border-color: var(--primary-green);
}

/* ===== CATEGORY HEADERS ===== */
.category-header {
  margin: 1.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--light-gray);
  color: var(--dark-green);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ===== BUTTONS ===== */
.btn {
  border-radius: var(--border-radius);
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
  border: none;
  padding: 0.75rem 1.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-green), var(--light-green));
  color: var(--white);
  box-shadow: var(--shadow-light);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--dark-green), var(--primary-green));
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-outline-primary {
  border: 2px solid var(--primary-green);
  color: var(--primary-green);
  background: transparent;
}

.btn-outline-primary:hover {
  background: var(--primary-green);
  color: var(--white);
  transform: translateY(-2px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), var(--light-green));
  color: var(--white);
}

.btn-info {
  background: linear-gradient(135deg, var(--water-blue), var(--accent-blue));
  color: var(--white);
}

/* ===== FILTER & TIME CONTROLS ===== */
.filter-controls {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-light);
  border: 1px solid rgba(25, 135, 84, 0.1);
}

.filter-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border-radius: 25px;
  border: 2px solid rgba(25, 135, 84, 0.3);
  background: var(--white);
  color: var(--primary-green);
  font-weight: 500;
  transition: all 0.3s ease;
  cursor: pointer;
}

.filter-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-light);
}

.filter-btn.active {
  background: linear-gradient(135deg, var(--primary-green), var(--light-green));
  color: var(--white);
  border-color: transparent;
  transform: translateY(-2px);
}

/* ===== HISTORY & CONTROL VIEWS ===== */
#history-view, #control-view {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-light);
  padding: 2rem 1rem;
  margin-top: 2rem;
  min-height: 300px;
}

#control-view .card {
  background: var(--off-white);
  border: 1px dashed var(--primary-green);
  color: var(--primary-green);
  box-shadow: none;
}

/* ===== ALERTS & NOTIFICATIONS ===== */
.alert {
  border-radius: var(--border-radius);
  border: none;
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
}

.alert-success {
  background: linear-gradient(135deg, rgba(40, 167, 69, 0.1), rgba(25, 135, 84, 0.1));
  color: var(--dark-green);
  border-left: 4px solid var(--success);
}

.alert-info {
  background: linear-gradient(135deg, rgba(23, 162, 184, 0.1), rgba(13, 110, 253, 0.1));
  color: var(--accent-blue);
  border-left: 4px solid var(--info);
}

.alert-warning {
  background: linear-gradient(135deg, rgba(255, 193, 7, 0.1), rgba(255, 152, 0, 0.1));
  color: #856404;
  border-left: 4px solid var(--warning);
}

.alert-danger {
  background: linear-gradient(135deg, rgba(220, 53, 69, 0.1), rgba(255, 107, 107, 0.1));
  color: var(--danger);
  border-left: 4px solid var(--danger);
}

/* ===== LOADING STATES ===== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(25, 135, 84, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(3px);
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-skeleton {
  background: linear-gradient(90deg, var(--light-gray) 25%, var(--medium-gray) 50%, var(--light-gray) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--border-radius);
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== ICON STYLES ===== */
.bi, .measurement-icon {
  vertical-align: middle;
}

.bi-droplet-half, .bi-droplet, .bi-water,
.bi-flower1, .bi-flower2, .bi-flower3,
.bi-tree, .bi-seedling {
  color: var(--primary-green) !important;
}

.bi-cloud-drizzle, .bi-cloud-rain,
.bi-moisture, .bi-waves {
  color: var(--water-blue) !important;
}

.bi-sun, .bi-brightness-high, .bi-sun-fill,
.bi-thermometer, .bi-thermometer-half, .bi-thermometer-sun {
  color: #ff6b35 !important;
}

.bi-speedometer2, .bi-gear, .bi-cpu,
.bi-bar-chart, .bi-graph-up, .bi-activity {
  color: var(--accent-blue) !important;
}

.bi-check-circle, .bi-check-circle-fill {
  color: var(--success) !important;
}

.bi-x-circle, .bi-x-circle-fill {
  color: var(--danger) !important;
}

.bi-exclamation-circle, .bi-exclamation-triangle {
  color: var(--warning) !important;
}

/* ===== REFRESH INDICATOR ===== */
.refresh-indicator {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(0,0,0,0.7);
  color: white;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: all 0.3s ease;
  z-index: 1000;
  cursor: pointer;
}
.refresh-indicator.refreshed {
  opacity: 1;
  transform: rotate(360deg);
  background: rgba(40,167,69,0.9);
}
.refresh-indicator i {
  font-size: 1.2rem;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1200px) {
  .dashboard-header {
    padding: 1.2rem;
  }
  .category-header {
    font-size: 1rem;
  }
}

@media (max-width: 991px) {
  .dashboard-header {
    padding: 1rem;
  }
  .measurement-grid,
  #latest-measurements-row {
    grid-template-columns: repeat(2, 1fr);
  }
  #charts-row {
    grid-template-columns: 1fr;
  }
  .aggregation-box-content {
    min-width: 160px;
    min-height: 160px;
    padding: 1rem 0.7rem;
  }
  .agg-value-section {
    font-size: 1.5rem;
  }
  .agg-icon {
    font-size: 1.7rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0 0.5rem;
    margin: 1rem auto;
  }
  .dashboard-header {
    padding: 0.8rem;
  }
  .measurement-grid,
  #latest-measurements-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .card {
    padding: 1rem;
  }
  .filter-btn-group {
    flex-direction: column;
  }
  .filter-btn {
    width: 100%;
    text-align: center;
  }
  .chart-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
}

@media (max-width: 576px) {
  .measurement-value {
    font-size: 1.5rem;
  }
  .btn {
    width: 100%;
    margin-bottom: 0.5rem;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .aggregation-box-content {
    min-width: 120px;
    min-height: 120px;
    padding: 0.7rem 0.5rem;
  }
  .agg-header {
    font-size: 1rem;
  }
  .agg-value-section {
    font-size: 1.2rem;
  }
  .agg-icon {
    font-size: 1.2rem;
  }
}

/* ===== UTILITY CLASSES ===== */
.text-agriculture {
  color: var(--primary-green) !important;
}
.text-water {
  color: var(--water-blue) !important;
}
.bg-agriculture {
  background: linear-gradient(135deg, var(--primary-green), var(--light-green)) !important;
}
.bg-water {
  background: linear-gradient(135deg, var(--water-blue), var(--accent-blue)) !important;
}
.border-agriculture {
  border-color: var(--primary-green) !important;
}
.shadow-agriculture {
  box-shadow: var(--shadow-md) !important;
}
.hover-scale {
  transition: transform 0.3s ease;
}
.hover-scale:hover {
  transform: scale(1.05);
}

/* ===== SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--light-gray);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, var(--primary-green), var(--light-green));
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, var(--dark-green), var(--primary-green));
}

/* ===== ANIMATION CLASSES ===== */
.fade-in {
  animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.slide-up {
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}