/* =============================================
   SMART HYDROPONIC DASHBOARD - CUSTOM CSS
   Watercress Monitoring System
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&family=Playfair+Display:wght@600;700&family=JetBrains+Mono:wght@400;600&display=swap');

/* ---- CSS Variables ---- */
:root {
  --green-50:  #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;
  --green-900: #14532d;
  --glass-bg:  rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(22,101,52,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 40px rgba(22,101,52,0.15), 0 4px 12px rgba(0,0,0,0.08);
  --shadow-glow: 0 0 30px rgba(34,197,94,0.25);
  --radius-xl: 1.25rem;
  --radius-2xl: 1.5rem;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--green-800);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.font-display { font-family: 'Playfair Display', serif; }
.font-mono    { font-family: 'JetBrains Mono', monospace; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar              { width: 7px; height: 7px; }
::-webkit-scrollbar-track        { background: rgba(200,230,201,0.3); border-radius: 10px; }
::-webkit-scrollbar-thumb        { background: linear-gradient(135deg, #4ade80, #22c55e); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover  { background: linear-gradient(135deg, #22c55e, #16a34a); }

/* ============================================
   BACKGROUND & LAYOUT
   ============================================ */

.nature-gradient {
  background: linear-gradient(135deg,
    #e8f5e9 0%, #c8e6c9 20%,
    #a5d6a7 40%, #c8e6c9 60%,
    #b2dfdb 80%, #e8f5e9 100%
  );
  background-size: 400% 400%;
  animation: bgShift 20s ease infinite;
  position: relative;
}

.nature-gradient::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(187,247,208,0.5) 0%, transparent 60%),
    radial-gradient(ellipse 40% 50% at 80% 80%, rgba(167,243,208,0.4) 0%, transparent 60%),
    radial-gradient(ellipse 50% 30% at 50% 50%, rgba(220,252,231,0.3) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.leaf-pattern {
  background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M40 8C32 18 20 24 10 30c10 6 22 12 30 22 8-10 20-16 30-22C60 24 48 18 40 8z' fill='%2381c784' fill-opacity='0.06'/%3E%3Cpath d='M15 50C10 58 8 65 12 72c6-4 14-8 18-15-4-2-10-4-15-7z' fill='%234ade80' fill-opacity='0.04'/%3E%3Cpath d='M65 15C70 22 72 30 68 37c-5-3-12-7-15-14 4-2 9-5 12-8z' fill='%2334d399' fill-opacity='0.05'/%3E%3C/svg%3E");
}

/* ============================================
   GLASS CARDS
   ============================================ */

.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.glass-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.8), transparent);
}

.glass-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  border-color: rgba(74,222,128,0.35);
}

/* ============================================
   SENSOR VALUE CARDS
   ============================================ */

.sensor-card {
  position: relative;
  overflow: hidden;
}

.sensor-card::after {
  content: '';
  position: absolute;
  bottom: -20px; right: -20px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(74,222,128,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.sensor-icon {
  background: linear-gradient(135deg, rgba(34,197,94,0.12), rgba(21,128,61,0.08));
  border: 1px solid rgba(74,222,128,0.2);
  transition: var(--transition);
}

.sensor-card:hover .sensor-icon {
  background: linear-gradient(135deg, rgba(34,197,94,0.22), rgba(21,128,61,0.15));
  transform: scale(1.08) rotate(5deg);
}

/* Big numeric value */
.sensor-value {
  font-size: clamp(2.2rem, 5vw, 3rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--green-800);
  transition: var(--transition);
  letter-spacing: -0.02em;
}

.sensor-value.updated {
  animation: valuePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Progress bars */
.sensor-bar-track {
  height: 6px;
  background: rgba(34,197,94,0.12);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.sensor-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sensor-bar-fill::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 8px; height: 100%;
  background: rgba(255,255,255,0.6);
  border-radius: 999px;
  filter: blur(2px);
}

.bar-temp   { background: linear-gradient(90deg, #fca5a5, #ef4444, #dc2626); }
.bar-light  { background: linear-gradient(90deg, #fde68a, #fbbf24, #f59e0b); }
.bar-ph     { background: linear-gradient(90deg, #93c5fd, #3b82f6, #2563eb); }
.bar-tds    { background: linear-gradient(90deg, #d8b4fe, #a855f7, #7c3aed); }

/* ============================================
   STATUS BADGES
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: var(--transition);
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
}

.badge-optimal { background: linear-gradient(135deg, #4ade80, #22c55e); }
.badge-warning { background: linear-gradient(135deg, #fbbf24, #f59e0b); }
.badge-danger  { background: linear-gradient(135deg, #f87171, #ef4444); }

.badge-optimal::before { animation: pulseDot 2s ease infinite; }

/* ============================================
   CONTROL PANEL
   ============================================ */

.pulse-glow { animation: pulseGlow 3s ease-in-out infinite; }

.btn-nature {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border: none;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.btn-nature::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.btn-nature:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(34,197,94,0.35);
}

.btn-nature:hover::before { opacity: 1; }

.btn-nature:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(34,197,94,0.2);
}

.btn-outline {
  background: white;
  border: 2px solid rgba(74,222,128,0.3);
  color: var(--green-700);
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  transition: var(--transition);
}

.btn-outline:hover {
  border-color: var(--green-400);
  background: var(--green-50);
  transform: translateY(-1px);
}

/* Device toggle buttons */
.device-btn-on {
  background: var(--green-100);
  color: var(--green-700);
  border: 1.5px solid var(--green-200);
  transition: var(--transition);
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

.device-btn-on:hover, .device-btn-on.active {
  background: var(--green-500);
  color: white;
  border-color: var(--green-500);
  box-shadow: 0 4px 14px rgba(34,197,94,0.35);
}

.device-btn-off {
  background: #fef2f2;
  color: #dc2626;
  border: 1.5px solid #fecaca;
  transition: var(--transition);
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

.device-btn-off:hover, .device-btn-off.active {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
  box-shadow: 0 4px 14px rgba(239,68,68,0.3);
}

/* ============================================
   FORM INPUTS
   ============================================ */

.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid rgba(74,222,128,0.25);
  border-radius: var(--radius-xl);
  background: rgba(255,255,255,0.9);
  color: var(--green-800);
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  transition: var(--transition);
  appearance: none;
}

.input-field:focus {
  border-color: var(--green-400);
  box-shadow: 0 0 0 3px rgba(74,222,128,0.15);
  background: white;
}

.input-field::placeholder { color: rgba(22,101,52,0.4); font-weight: 500; }

input[type="time"].input-field { cursor: pointer; }
input[type="number"].input-field { font-family: 'JetBrains Mono', monospace; }

/* ============================================
   MINI CHART (sparkline)
   ============================================ */

.sparkline-wrap {
  position: relative;
  height: 48px;
  margin-top: 8px;
  overflow: hidden;
}

.sparkline-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ============================================
   REALTIME CHART SECTION
   ============================================ */

.chart-section {
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-top: 1.5rem;
}

.chart-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.chart-tab {
  padding: 6px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  background: rgba(255,255,255,0.7);
  color: var(--green-700);
  border-color: rgba(74,222,128,0.2);
}

.chart-tab:hover { border-color: var(--green-400); }

.chart-tab.active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(34,197,94,0.3);
}

.chart-canvas-wrap {
  position: relative;
  height: 200px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(240,253,244,0.6);
  border: 1px solid rgba(74,222,128,0.12);
}

canvas#realtimeChart {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ============================================
   SYSTEM STATUS BAR
   ============================================ */

.status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--green-700);
  font-weight: 600;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green-500);
  animation: pulseDot 2s ease infinite;
  flex-shrink: 0;
}

.status-dot.warning { background: #f59e0b; }
.status-dot.danger  { background: #ef4444; animation: none; }

/* ============================================
   NOTIFICATION TOASTS
   ============================================ */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08);
  font-size: 14px;
  font-weight: 600;
  color: white;
  min-width: 220px;
  max-width: 340px;
  pointer-events: all;
  backdrop-filter: blur(10px);
  transform: translateX(110%);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  opacity: 0;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast.hide {
  transform: translateX(110%);
  opacity: 0;
}

.toast-success { background: linear-gradient(135deg, rgba(34,197,94,0.95), rgba(21,128,61,0.95)); }
.toast-warning { background: linear-gradient(135deg, rgba(245,158,11,0.95), rgba(217,119,6,0.95)); }
.toast-error   { background: linear-gradient(135deg, rgba(239,68,68,0.95), rgba(220,38,38,0.95)); }
.toast-info    { background: linear-gradient(135deg, rgba(59,130,246,0.95), rgba(37,99,235,0.95)); }

.toast-icon {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.toast-close {
  margin-left: auto;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  cursor: pointer;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toast-close:hover { background: rgba(255,255,255,0.35); }

/* ============================================
   DEVICE STATUS INDICATORS
   ============================================ */

.device-row {
  background: white;
  border-radius: var(--radius-xl);
  padding: 14px 16px;
  border: 1.5px solid rgba(74,222,128,0.12);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.device-row:hover {
  border-color: rgba(74,222,128,0.3);
  box-shadow: 0 4px 16px rgba(34,197,94,0.1);
}

.device-led-indicator {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #d1d5db;
  transition: var(--transition);
  flex-shrink: 0;
}

.device-led-indicator.on {
  background: var(--green-500);
  box-shadow: 0 0 8px var(--green-400), 0 0 16px rgba(34,197,94,0.4);
  animation: ledPulse 1.5s ease infinite;
}

/* ============================================
   ALERT SECTION
   ============================================ */

.alert-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  animation: slideInAlert 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.alert-warning {
  background: linear-gradient(135deg, rgba(254,243,199,0.9), rgba(253,230,138,0.7));
  border: 1.5px solid rgba(251,191,36,0.4);
  color: #92400e;
}

.alert-danger {
  background: linear-gradient(135deg, rgba(254,226,226,0.9), rgba(252,165,165,0.7));
  border: 1.5px solid rgba(248,113,113,0.4);
  color: #991b1b;
}

.alert-success {
  background: linear-gradient(135deg, rgba(220,252,231,0.9), rgba(187,247,208,0.7));
  border: 1.5px solid rgba(74,222,128,0.4);
  color: var(--green-800);
}

/* ============================================
   HEADER ANIMATIONS
   ============================================ */

.float-animation {
  animation: floatBounce 4s ease-in-out infinite;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.section-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--green-600);
  opacity: 0.75;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(74,222,128,0.3), transparent);
  margin: 1rem 0;
}

/* ============================================
   KEYFRAME ANIMATIONS
   ============================================ */

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50%       { background-position: 100% 50%; }
}

@keyframes floatBounce {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  25%       { transform: translateY(-8px) rotate(-2deg); }
  75%       { transform: translateY(-4px) rotate(2deg); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 20px rgba(34,197,94,0.2), var(--shadow-md); }
  50%       { box-shadow: 0 0 40px rgba(34,197,94,0.4), var(--shadow-lg); }
}

@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

@keyframes ledPulse {
  0%, 100% { box-shadow: 0 0 6px var(--green-400), 0 0 12px rgba(34,197,94,0.3); }
  50%       { box-shadow: 0 0 12px var(--green-400), 0 0 24px rgba(34,197,94,0.5); }
}

@keyframes valuePop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); color: var(--green-600); }
  100% { transform: scale(1); }
}

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

@keyframes slideInAlert {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   PAGE LOAD ANIMATION
   ============================================ */

.glass-card, .chart-section, header {
  animation: fadeInUp 0.6s cubic-bezier(0.4,0,0.2,1) both;
}

.glass-card:nth-child(1) { animation-delay: 0.05s; }
.glass-card:nth-child(2) { animation-delay: 0.10s; }
.glass-card:nth-child(3) { animation-delay: 0.15s; }
.glass-card:nth-child(4) { animation-delay: 0.20s; }

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .sensor-value { font-size: 2rem; }
  .chart-tabs   { gap: 6px; }
  .chart-tab    { padding: 5px 12px; font-size: 12px; }
  #toast-container { right: 1rem; bottom: 1rem; left: 1rem; }
  .toast        { min-width: unset; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
