@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Noto+Sans+SC:wght@400;500;600&display=swap');

:root {
  --bg: #f6f1e8;
  --bg-accent: #e2effc;
  --surface: #ffffff;
  --surface-alt: #fbf7ef;
  --text: #0f172a;
  --muted: #52616b;
  --accent: #0ea5a4;
  --accent-strong: #0f766e;
  --accent-warm: #f97316;
  --border: #e7e2d6;
  --shadow: rgba(15, 23, 42, 0.12);
  font-family: 'Space Grotesk', 'Noto Sans SC', sans-serif;
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #fff8ed 0%, var(--bg) 45%, var(--bg-accent) 100%);
  position: relative;
  overflow-x: hidden;
}

.background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.glow {
  position: absolute;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  filter: blur(0px);
  opacity: 0.6;
  animation: float 14s ease-in-out infinite;
}

.glow--one {
  top: -80px;
  left: -60px;
  background: rgba(249, 115, 22, 0.22);
}

.glow--two {
  bottom: -120px;
  right: -80px;
  background: rgba(14, 165, 164, 0.2);
  animation-delay: 2s;
}

.glow--three {
  top: 40%;
  right: 10%;
  width: 220px;
  height: 220px;
  background: rgba(59, 130, 246, 0.15);
  animation-delay: 4s;
}

.hero {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1.5rem;
}

.hero-text {
  flex: 1 1 360px;
}

.hero-text h1 {
  font-size: clamp(2rem, 3vw, 2.8rem);
  margin: 0.25rem 0 0.6rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.25rem;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--accent-strong);
  margin: 0;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.hero-status {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 18px 40px var(--shadow);
  border: 1px solid var(--border);
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  position: relative;
  overflow: hidden;
}

.span-full {
  grid-column: 1 / -1;
}

.card h2 {
  margin: 0 0 1rem;
}

.reveal {
  opacity: 0;
  transform: translateY(16px);
  animation: reveal 0.7s ease forwards;
}

.layout .card:nth-child(1) { animation-delay: 0.05s; }
.layout .card:nth-child(2) { animation-delay: 0.1s; }
.layout .card:nth-child(3) { animation-delay: 0.15s; }
.layout .card:nth-child(4) { animation-delay: 0.2s; }
.layout .card:nth-child(5) { animation-delay: 0.25s; }
.layout .card:nth-child(6) { animation-delay: 0.3s; }
.layout .card:nth-child(7) { animation-delay: 0.35s; }
.layout .card:nth-child(8) { animation-delay: 0.4s; }
.layout .card:nth-child(9) { animation-delay: 0.45s; }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

label {
  font-weight: 600;
  min-width: 90px;
}

input,
textarea,
button {
  font-size: 1rem;
  font-family: inherit;
}

input,
textarea {
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

button {
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: 0 10px 20px rgba(14, 165, 164, 0.25);
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent-strong);
  box-shadow: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: #ffe8cc;
  color: #9a3412;
}

.badge.online {
  background: #bbf7d0;
  color: #14532d;
}

.badge.offline {
  background: #fecaca;
  color: #7f1d1d;
}

.meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.sensor-card {
  background: linear-gradient(135deg, #fff8ed, #ffffff);
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}

.sensor-item {
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.03);
}

.sensor-item .label {
  color: var(--muted);
  font-size: 0.9rem;
}

.sensor-item .value {
  font-size: 2rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.sensor-item .unit {
  font-size: 1rem;
  color: var(--muted);
}

.sensor-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.sensor-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.control-card {
  background: var(--surface);
}

.control-card--led {
  background: linear-gradient(135deg, #eff9f9, #ffffff);
}

.control-card--motor {
  background: linear-gradient(135deg, #fff4e6, #ffffff);
}

.control-card--buzzer {
  background: linear-gradient(135deg, #f0f4ff, #ffffff);
}

.led-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.led-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.block-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.motor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.led-tile {
  background: var(--surface);
  padding: 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.led-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.led-buttons {
  display: flex;
  gap: 0.6rem;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot-blue { background: #3b82f6; }
.dot-green { background: #22c55e; }
.dot-pink { background: #ec4899; }

#log-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 280px;
  overflow-y: auto;
}

#log-list li {
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.ota-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.ota-side {
  background: var(--surface-alt);
  border-radius: 16px;
  padding: 1.25rem;
  border: 1px solid var(--border);
}

.ota-side .form-row {
  flex-direction: column;
  align-items: stretch;
}

.ota-side button {
  align-self: flex-start;
}

.ota-main {
  min-width: 0;
}

.ota-side-media {
  margin-top: 1rem;
}

.ota-side-media img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  display: block;
}

.ota-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.progress {
  margin-top: 0.75rem;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.ota-log {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.ota-log li {
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
}

.chart-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 40;
}

.chart-modal.is-open {
  display: flex;
}

.chart-panel {
  width: min(1200px, 96vw);
  height: min(820px, 92vh);
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.3);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.chart-header h3 {
  margin: 0 0 0.35rem;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  width: 14px;
  height: 6px;
  border-radius: 999px;
  display: inline-block;
}

.legend-temp {
  background: var(--accent-warm);
}

.legend-hum {
  background: #3b82f6;
}

.chart-body {
  flex: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 1rem;
}

.chart-block {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chart-title {
  font-weight: 600;
  color: var(--muted);
}

.chart-block canvas {
  flex: 1;
  width: 100%;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes float {
  0% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(18px) translateX(-12px);
  }
  100% {
    transform: translateY(0) translateX(0);
  }
}

@media (max-width: 720px) {
  .hero {
    padding-top: 2rem;
  }

  .hero-status {
    width: 100%;
  }

  label {
    min-width: auto;
    width: 100%;
  }

  .form-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ota-layout {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
    padding: 1rem;
  }

  .chart-body {
    grid-template-rows: minmax(180px, 1fr);
  }
}
