:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem;
}

header {
  text-align: center;
  margin-bottom: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.75rem;
}

header p {
  color: var(--muted);
  margin: 0.25rem 0 0;
}

section {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

h2, h3 {
  margin-top: 0;
  font-size: 1.1rem;
}

label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

input, select {
  width: 100%;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
  color: var(--text);
  font-size: 1rem;
}

button {
  margin-top: 0.75rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  opacity: 0.9;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  background: transparent;
  padding: 0;
}

.tile {
  background: var(--panel);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.tile .value {
  font-size: 1.8rem;
  font-weight: 700;
}

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

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

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

.chart-controls button {
  margin: 0;
  background: #334155;
  color: var(--text);
}

.chart-controls button.active {
  background: var(--accent);
  color: #0f172a;
}

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

.chart-actions button {
  margin: 0;
  background: #334155;
  color: var(--text);
}

.device-name-row {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}

.device-name-row input {
  max-width: 220px;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
  color: var(--text);
  font-size: 0.9rem;
}

.device-name-row button {
  margin: 0;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.chart-legend-bar {
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0.35rem;
}

.temp-label { color: #f87171; }
.hum-label  { color: #60a5fa; }

.chart-wrapper {
  position: relative;
  width: 100%;
  min-height: 360px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

button.secondary {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: 1px solid #334155;
}

.stats h2 {
  margin-bottom: 0.75rem;
}

@media (max-width: 600px) {
  .container {
    padding: 0.5rem;
  }

  section {
    padding: 0.75rem;
  }

  .chart-wrapper {
    min-height: 460px;
  }

  .chart-toolbar {
    gap: 0.75rem;
  }

  .chart-controls button,
  .chart-actions button {
    padding: 0.45rem 0.6rem;
    font-size: 0.85rem;
  }

  .tiles {
    grid-template-columns: repeat(2, 1fr);
  }

  .tile .value {
    font-size: 1.4rem;
  }
}

.range {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.range input {
  flex: 1;
}

.range span {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.25rem 0 0;
}
