/* ============================================================
   SolarTrack 360° — Premium Dark Dashboard Theme
   ============================================================ */

/* ---- Design System: Custom Properties ---- */
:root {
  --primary: #02385A;
  --primary-light: #04527D;
  --primary-dark: #011E33;
  --accent: #00D4FF;
  --accent-glow: rgba(0, 212, 255, 0.3);
  --bg-dark: #0A0E17;
  --bg-card: rgba(2, 56, 90, 0.15);
  --bg-card-hover: rgba(2, 56, 90, 0.25);
  --text-primary: #E8F0F8;
  --text-secondary: #8BA3B8;
  --text-muted: #5A7A90;
  --success: #00E676;
  --warning: #FFB300;
  --danger: #FF5252;
  --border: rgba(0, 212, 255, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --radius: 16px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-dark);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(2, 56, 90, 0.35) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(0, 212, 255, 0.08) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-dark);
}
::-webkit-scrollbar-thumb {
  background: var(--primary-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ============================================================
   HEADER
   ============================================================ */
#app-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-icon {
  color: var(--accent);
  filter: drop-shadow(0 0 10px var(--accent-glow));
  animation: pulse 3s ease-in-out infinite;
}

.logo-text h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.logo-text p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  border-radius: 100px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s ease;
}

.status-online .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s ease-in-out infinite;
}

.status-offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-text {
  color: var(--text-secondary);
}

/* ============================================================
   MAIN DASHBOARD
   ============================================================ */
#dashboard {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

/* ---- Status Cards Row ---- */
.status-cards {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

/* ---- Generic Card ---- */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  animation: fadeInUp 0.5s ease both;
  animation-delay: calc(var(--card-index, 0) * 0.08s);
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(0, 212, 255, 0.25);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 0 20px rgba(0, 212, 255, 0.05);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  letter-spacing: -0.01em;
}

.card-title svg {
  color: var(--accent);
  flex-shrink: 0;
}

/* ---- Status Card (individual sensor cards) ---- */
.status-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}

.card-icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  flex-shrink: 0;
}

.card-icon-time {
  background: rgba(0, 212, 255, 0.1);
  color: var(--accent);
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.08);
}

.card-icon-temp {
  background: rgba(255, 109, 0, 0.1);
  color: #FF6D00;
  box-shadow: 0 0 20px rgba(255, 109, 0, 0.08);
}

.card-icon-humidity {
  background: rgba(33, 150, 243, 0.1);
  color: #2196F3;
  box-shadow: 0 0 20px rgba(33, 150, 243, 0.08);
}

.card-icon-rain {
  background: rgba(0, 188, 212, 0.1);
  color: #00BCD4;
  box-shadow: 0 0 20px rgba(0, 188, 212, 0.08);
}

.card-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}

.card-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ============================================================
   LDR SENSOR GRID
   ============================================================ */
.ldr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.75rem;
  position: relative;
}

.ldr-cell {
  background: rgba(0, 212, 255, 0.04);
  border: 1px solid rgba(0, 212, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: all 0.3s ease;
}

.ldr-cell:hover {
  background: rgba(0, 212, 255, 0.08);
  border-color: rgba(0, 212, 255, 0.15);
}

.ldr-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ldr-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.ldr-bar-track {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.ldr-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--primary-light), var(--accent));
  transition: width 0.5s ease;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Center sun icon */
.ldr-center-sun {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 23, 0.9);
  border-radius: 50%;
  border: 1px solid rgba(0, 212, 255, 0.2);
  color: var(--accent);
  z-index: 2;
  animation: rotate 20s linear infinite;
  box-shadow: 0 0 20px rgba(0, 212, 255, 0.15);
}

/* ============================================================
   CHART SECTION
   ============================================================ */
.chart-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.chart-tab {
  padding: 0.45rem 1.1rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chart-tab:hover {
  background: rgba(0, 212, 255, 0.08);
  color: var(--text-primary);
  border-color: rgba(0, 212, 255, 0.2);
}

.chart-tab.active {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.2), rgba(0, 212, 255, 0.08));
  color: var(--accent);
  border-color: rgba(0, 212, 255, 0.35);
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.1);
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 280px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.chart-wrapper canvas {
  border-radius: var(--radius-sm);
}

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

/* Mode Section */
.mode-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.mode-toggle-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.mode-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color 0.3s ease;
}

.mode-label-auto.active-mode {
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
}

.mode-label-manual.active-mode {
  color: var(--warning);
  text-shadow: 0 0 10px rgba(255, 179, 0, 0.3);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 60px;
  height: 30px;
  cursor: pointer;
  display: inline-block;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.3), rgba(0, 212, 255, 0.15));
  border: 1px solid rgba(0, 212, 255, 0.3);
  border-radius: 30px;
  transition: all 0.4s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: var(--accent);
  border-radius: 50%;
  transition: all 0.4s ease;
  box-shadow: 0 0 10px var(--accent-glow);
}

.toggle-switch input:checked + .toggle-slider {
  background: linear-gradient(135deg, rgba(255, 179, 0, 0.3), rgba(255, 179, 0, 0.15));
  border-color: rgba(255, 179, 0, 0.3);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(30px);
  background: var(--warning);
  box-shadow: 0 0 10px rgba(255, 179, 0, 0.3);
}

.current-mode {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* D-Pad */
.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.dpad-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.dpad-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  font-family: var(--font);
}

.dpad-btn:not(:disabled):hover {
  background: rgba(0, 212, 255, 0.12);
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: scale(1.08);
}

.dpad-btn:not(:disabled):active {
  transform: scale(0.95);
}

.dpad-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.dpad-btn:disabled:hover {
  transform: none;
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: none;
}

.dpad-btn-stop {
  border-color: rgba(255, 82, 82, 0.3);
}

.dpad-btn-stop:not(:disabled):hover {
  background: rgba(255, 82, 82, 0.12);
  border-color: var(--danger);
  box-shadow: 0 0 20px rgba(255, 82, 82, 0.25);
  color: var(--danger);
}

/* Active direction glow */
.active-direction {
  border-color: var(--accent) !important;
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 10px rgba(0, 212, 255, 0.08) !important;
  animation: pulse 1.5s ease-in-out infinite;
}

.active-direction svg {
  color: var(--accent);
}

/* Motor Status */
.motor-status {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.motor-status-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 212, 255, 0.04);
  border: 1px solid rgba(0, 212, 255, 0.08);
  min-width: 100px;
}

.motor-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.motor-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: capitalize;
}

/* ---- Header Actions (connection + logout) ---- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ---- Logout Button ---- */
.logout-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem;
  border-radius: 100px;
  background: rgba(255, 82, 82, 0.08);
  border: 1px solid rgba(255, 82, 82, 0.2);
  color: var(--danger);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.logout-btn:hover {
  background: rgba(255, 82, 82, 0.15);
  border-color: rgba(255, 82, 82, 0.4);
  box-shadow: 0 0 16px rgba(255, 82, 82, 0.15);
  transform: translateY(-1px);
}

.logout-btn:active {
  transform: translateY(0) scale(0.97);
}

.logout-btn svg {
  flex-shrink: 0;
}

/* ============================================================
   FOOTER
   ============================================================ */
#app-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border);
}

#app-footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

#footer-updated {
  margin-top: 0.25rem;
  font-size: 0.7rem;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes rotate {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to   { transform: translate(-50%, -50%) rotate(360deg); }
}

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

@keyframes valueFlash {
  0%   { background: transparent; }
  30%  { background: rgba(0, 212, 255, 0.12); }
  100% { background: transparent; }
}

/* ---- Utility Classes ---- */
.status-online .status-text { color: var(--success); }
.status-offline .status-text { color: var(--danger); }

.value-update {
  animation: valueFlash 0.6s ease;
  border-radius: 4px;
}

.shimmer {
  background: linear-gradient(90deg, transparent 0%, rgba(0, 212, 255, 0.05) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

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

/* 576px+ — Status cards 2×2 */
@media (min-width: 576px) {
  .status-cards {
    grid-template-columns: 1fr 1fr;
  }
}

/* 768px+ — Desktop-ish layout */
@media (min-width: 768px) {
  .status-cards {
    grid-template-columns: repeat(4, 1fr);
  }

  #dashboard {
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
  }

  .status-cards {
    grid-column: 1 / -1;
  }

  .card-ldr {
    grid-column: 1;
  }

  .card-chart {
    grid-column: 2;
  }

  .card-control {
    grid-column: 1 / -1;
  }

  .chart-wrapper {
    height: 320px;
  }
}

/* 1024px+ — Wider spacing */
@media (min-width: 1024px) {
  #dashboard {
    padding: 2rem;
    gap: 1.75rem;
  }

  .header-inner {
    padding: 1.2rem 2rem;
  }

  .logo-text h1 {
    font-size: 1.55rem;
  }

  .card-value {
    font-size: 1.8rem;
  }

  .chart-wrapper {
    height: 360px;
  }

  .card-control {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr;
  }
}

/* 1400px+ — Max-width container */
@media (min-width: 1400px) {
  #dashboard {
    grid-template-columns: 1fr 1fr 1fr;
    max-width: 1440px;
  }

  .status-cards {
    grid-column: 1 / -1;
  }

  .card-ldr {
    grid-column: 1;
  }

  .card-chart {
    grid-column: 2;
  }

  .card-control {
    grid-column: 3;
  }
}
