:root {
  --bg-color: #0a0a0a;
  --widget-bg-color: #1a1a1d;
  --text-color: #e0e0e0;
  --text-secondary: #b0b0b0;
  --main-text-color: #ffffff;
  --secondary-text-color: #cccccc;
  --accent-color: #00d4ff;
  --accent-secondary: #7c3aed;
  --border-color: #333336;
  --hover-bg-color: #252528;
  --glass-bg: rgba(26, 26, 29, 0.8);
  --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
  background: var(--bg-color);
  background-image: radial-gradient(circle at 20% 20%, rgba(0, 212, 255, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 60%, rgba(102, 126, 234, 0.05) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text-color);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, transparent 49%, rgba(0, 212, 255, 0.02) 50%, transparent 51%),
    linear-gradient(-45deg, transparent 49%, rgba(124, 58, 237, 0.02) 50%, transparent 51%);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: -1;
}

.header {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
  color: var(--main-text-color);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  background: var(--gradient-3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
}

.back-button {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--main-text-color);
  text-decoration: none;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 212, 255, 0.1);
}

@media (hover: hover) {
  .back-button:hover {
    color: var(--accent-color);
    background: rgba(0, 212, 255, 0.2);
    transform: translateY(-50%) translateX(-2px);
  }
}

.time-selector {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  background: var(--glass-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.time-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
}

.time-btn:hover {
  color: var(--main-text-color);
  background: rgba(0, 212, 255, 0.1);
}

.time-btn.active {
  background: var(--gradient-3);
  color: #ffffff;
  font-weight: 600;
}

.dashboard-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: 1.5rem;
  padding: 0 20px 20px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.widget {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: 100%;
  position: relative;
  overflow: hidden;
}

.widget::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--gradient-3);
  opacity: 0.6;
}

.charts-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex-grow: 1;
}

.chart-widget {
  display: flex;
  flex-direction: column;
  height: 450px;
  min-height: 450px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.current-value {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.current-value .icon {
  font-size: 2rem;
  background: var(--gradient-3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(0, 212, 255, 0.4));
}

.humidity-widget .current-value .icon {
  background: var(--gradient-2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(124, 58, 237, 0.4));
}

.distance-widget .current-value .icon {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(34, 197, 94, 0.4));
}

.value-info {
  display: flex;
  flex-direction: column;
}

.value-info .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--main-text-color);
  text-shadow: 0 2px 8px rgba(0, 212, 255, 0.3);
  line-height: 1.1;
}

.value-info .label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}

.timestamp {
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.8;
  font-style: italic;
  text-align: right;
}

.chart-widget h2 {
  margin: 0 0 1.5rem 0;
  text-align: left;
  font-size: 1.1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.chart-canvas-container {
  position: relative;
  flex: 1;
  background: rgba(0, 212, 255, 0.02);
  border-radius: 12px;
  padding: 15px;
  border: 1px solid rgba(0, 212, 255, 0.1);
  width: 100%;
  overflow: hidden;
  min-height: 300px;
}

.humidity-widget .chart-canvas-container {
  background: rgba(124, 58, 237, 0.02);
  border: 1px solid rgba(124, 58, 237, 0.1);
}

.distance-widget .chart-canvas-container {
    background: rgba(34, 197, 94, 0.02);
    border: 1px solid rgba(34, 197, 94, 0.1);
}

.chart-canvas-container canvas {
  border-radius: 8px;
  max-width: 100% !important;
  height: 100% !important;
}

.no-data-message {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-secondary);
  font-size: 1.1rem;
  flex-direction: column;
  gap: 10px;
}

.no-data-message i {
  font-size: 2rem;
  opacity: 0.5;
}

@media (min-width: 901px) {
    .charts-container .widget:last-child:nth-child(odd) {
        grid-column: span 2;
    }
}

@media (max-width: 900px) {
  .charts-container {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    min-height: auto;
  }

  .header {
    padding: 15px;
    display: grid;
    grid-template-areas:
      "back title"
      "selector selector";
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
  }

  .header h1 {
    grid-area: title;
    grid-column: 1 / 3;
    font-size: 1.2rem;
    text-align: center;
  }

  .back-button {
    grid-area: back;
    position: static;
    transform: none;
    align-self: center;
    font-size: 0.9rem;
    justify-self: start;
    z-index: 1;
  }

  .back-button:hover {
    transform: none;
    color: var(--main-text-color);
    background: rgba(0, 212, 255, 0.1);
  }

  .time-selector {
    grid-area: selector;
    position: static;
    transform: none;
    justify-self: center;
  }

  .time-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .back-button .back-text {
    display: none;
  }

  .dashboard-container {
    padding: 0 10px 20px;
    gap: 1rem;
    flex-grow: 0;
    min-height: auto;
  }

  .widget {
    padding: 15px;
  }

  .chart-widget {
    height: auto;
    min-height: 350px;
    max-height: none;
  }

  .chart-canvas-container {
    padding: 10px;
    min-height: 250px;
    max-height: 250px;
  }

  .chart-header {
    gap: 10px;
  }

  .current-value .icon {
    font-size: 1.8rem;
  }

  .value-info .value {
    font-size: 1.5rem;
  }

  .timestamp {
    font-size: 0.7rem;
  }
}

@media (max-width: 480px) {
  .dashboard-container {
    padding: 0 8px 15px;
  }

  .widget {
    padding: 12px;
  }

  .chart-widget {
    height: auto;
    min-height: 320px;
    max-height: none;
  }

  .chart-canvas-container {
    padding: 8px;
    min-height: 220px;
    max-height: 220px;
  }

  .current-value .icon {
    font-size: 1.6rem;
  }

  .value-info .value {
    font-size: 1.4rem;
  }
}

/* Для очень маленьких экранов */
@media (max-width: 360px) {
  .header {
    padding: 12px;
    gap: 12px;
  }
  
  .dashboard-container {
    padding: 0 6px 12px;
  }
  
  .widget {
    padding: 10px;
  }
  
  .chart-widget {
    min-height: 300px;
  }
  
  .chart-canvas-container {
    padding: 6px;
    min-height: 200px;
    max-height: 200px;
  }
}

/* Анимации загрузки */
@keyframes pulse {
  0% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.6;
  }
}

.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Улучшенные переходы */
.chart-canvas-container {
  transition: all 0.3s ease;
}

.widget:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

/* --- Light Theme --- */
body[data-theme="light"] {
    --bg-color: #f0f2f5;
    --widget-bg-color: #ffffff;
    --text-color: #1f1f1f;
    --text-secondary: #606060;
    --main-text-color: #1f1f1f;
    --secondary-text-color: #606060;
    --accent-color: #1877f2;
    --accent-secondary: #8a3ffc;
    --border-color: #d9d9d9;
    --hover-bg-color: #e9ebee;
    --glass-bg: rgba(255, 255, 255, 0.75);
    
    background-image: none;
    background-color: var(--bg-color);
}

body[data-theme="light"]::before {
    background: none;
}

body[data-theme="light"] .header h1 {
    background: var(--accent-color);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
}

body[data-theme="light"] .back-button {
    color: var(--text-secondary);
    background: rgba(24, 119, 242, 0.1);
}

body[data-theme="light"] .time-btn.active {
    background: var(--accent-color);
    color: #ffffff;
}

body[data-theme="light"] .widget {
    border-color: var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

body[data-theme="light"] .widget::before {
    background: var(--accent-color);
}

body[data-theme="light"] .current-value .icon {
    filter: none;
}

body[data-theme="light"] .value-info .value {
    text-shadow: none;
}

body[data-theme="light"] .chart-canvas-container {
    background: rgba(24, 119, 242, 0.05);
    border: 1px solid rgba(24, 119, 242, 0.2);
}

body[data-theme="light"] .humidity-widget .chart-canvas-container {
    background: rgba(138, 63, 252, 0.05);
    border: 1px solid rgba(138, 63, 252, 0.2);
}

body[data-theme="light"] .distance-widget .chart-canvas-container {
    background: rgba(66, 183, 42, 0.05);
    border: 1px solid rgba(66, 183, 42, 0.2);
}