:root {
  --background: #0c1119;
  --foreground: #f4f7fb;
  --surface: #151d29;
  --surface-2: #1c2634;
  --popover: #182231;
  --muted-foreground: #9aa8ba;
  --border: #2a3748;
  --primary: #62e6bd;
  --online: #5fe1b1;
  --offline: #f06f72;
  --accent: #62bde6;
  --grid: rgba(89, 107, 132, 0.28);
  --chart-ppfd: #f4d35e;
  --chart-temp: #f1865b;
  --chart-rh: #62bde6;
  --chart-vpd: #62e6bd;
  --chart-dli: #b58cff;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-sans: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background:
    radial-gradient(1000px 600px at 0 0, rgba(50, 180, 151, 0.12), transparent 60%),
    radial-gradient(800px 600px at 100% 0, rgba(148, 86, 220, 0.12), transparent 60%),
    var(--background);
  background-attachment: fixed;
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

canvas {
  display: block;
  max-width: 100%;
}

.page {
  min-height: 100vh;
}

.shell {
  width: min(1280px, 100%);
  margin: auto;
  padding: 24px 16px 40px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.brand-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: none;
  border: 1px solid rgba(98, 230, 189, 0.4);
  border-radius: 16px;
  background: rgba(98, 230, 189, 0.1);
  color: var(--primary);
  font: 700 28px var(--font-display);
}

.brand h1,
.section-head h2,
.install h2,
.devices h2 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

.brand h1 {
  font-size: 23px;
}

.brand p,
.section-head p,
.install > p {
  margin: 3px 0 0;
  color: var(--muted-foreground);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(21, 29, 41, 0.75);
  color: var(--muted-foreground);
  cursor: pointer;
  font-size: 18px;
}

.icon-btn:hover {
  color: var(--foreground);
  border-color: rgba(98, 230, 189, 0.35);
}

.spin {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill.online {
  border-color: rgba(95, 225, 177, 0.35);
  background: rgba(95, 225, 177, 0.1);
  color: var(--online);
}

.status-pill.offline {
  border-color: rgba(240, 111, 114, 0.35);
  background: rgba(240, 111, 114, 0.1);
  color: var(--offline);
}

.status-pill em {
  color: var(--muted-foreground);
  font-style: normal;
  font-weight: 400;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent);
}

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(240, 173, 78, 0.35);
  border-radius: 14px;
  background: rgba(240, 173, 78, 0.08);
  color: #f3c47b;
  font-size: 13px;
}

.ranges {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}

.range-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ranges button,
.metric-tabs button {
  border: 1px solid rgba(42, 55, 72, 0.85);
  background: rgba(21, 29, 41, 0.55);
  color: var(--muted-foreground);
  cursor: pointer;
  transition: 0.2s;
}

.ranges button {
  min-height: 36px;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.ranges button:hover,
.metric-tabs button:hover {
  color: var(--foreground);
}

.ranges button.selected,
.metric-tabs button.selected {
  border-color: rgba(98, 230, 189, 0.6);
  background: rgba(98, 230, 189, 0.13);
  color: var(--primary);
}

.ranges > span {
  margin-left: auto;
  color: var(--muted-foreground);
  font-size: 11px;
  text-align: right;
}

main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 20px;
}

.panel {
  min-width: 0;
  border: 1px solid rgba(48, 63, 82, 0.82);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(30, 41, 56, 0.9), rgba(20, 29, 41, 0.96));
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.04),
    0 24px 60px -35px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(14px);
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 26px;
  border-color: rgba(244, 211, 94, 0.25);
  background:
    radial-gradient(700px 300px at 0 0, rgba(244, 211, 94, 0.12), transparent 65%),
    linear-gradient(180deg, rgba(30, 41, 56, 0.94), rgba(20, 29, 41, 0.98));
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(70% 65% at 50% 0, #000, transparent 75%);
}

.hero-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  align-items: center;
  gap: 30px;
}

.hero-info {
  min-width: 0;
}

.hero-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--chart-ppfd);
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hero-number {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-top: 16px;
  color: var(--chart-ppfd);
  font-family: var(--font-display);
  font-size: clamp(58px, 7vw, 82px);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

.hero-number small {
  padding-bottom: 8px;
  color: var(--muted-foreground);
  font: 400 13px var(--font-sans);
}

.progress {
  height: 6px;
  margin-top: 24px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--chart-ppfd);
  transition: width 0.7s;
}

.muted {
  margin: 8px 0 0;
  color: var(--muted-foreground);
  font-size: 12px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.hero-stats > div {
  min-width: 0;
  padding: 11px 12px;
  border-radius: 13px;
  background: rgba(21, 29, 41, 0.72);
}

.hero-stats span,
.hero-stats small {
  display: block;
  color: var(--muted-foreground);
  font-size: 10px;
}

.hero-stats span {
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hero-stats strong {
  display: block;
  margin: 3px 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 19px;
}

.chip {
  display: inline-flex;
  max-width: 100%;
  margin: 16px 0 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(28, 38, 52, 0.75);
  color: var(--muted-foreground);
  font-size: 12px;
  white-space: normal;
}

.hero-chart {
  width: 100%;
  min-width: 0;
  height: 250px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  min-width: 0;
  padding: 18px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.25s, border-color 0.25s;
}

.metric-card:hover {
  transform: translateY(-2px);
}

.metric-card.active {
  border-color: var(--metric-color);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.04),
    0 0 0 1px color-mix(in srgb, var(--metric-color) 35%, transparent);
}

.metric-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.metric-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted-foreground);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 12px;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.metric-value small {
  margin-left: 6px;
  color: var(--muted-foreground);
  font: 400 11px var(--font-sans);
}

.trend {
  height: max-content;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.trend.up {
  background: rgba(95, 225, 177, 0.1);
  color: var(--online);
}

.trend.down {
  background: rgba(98, 189, 230, 0.1);
  color: var(--accent);
}

.spark {
  height: 58px;
  margin-top: 12px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0 0;
  padding-top: 11px;
  border-top: 1px solid rgba(42, 55, 72, 0.65);
}

.mini-stats dt {
  color: var(--muted-foreground);
  font-size: 10px;
}

.mini-stats dd {
  margin: 2px 0 0;
  font: 500 14px var(--font-display);
}

.target {
  margin: 10px 0 0;
  color: var(--muted-foreground);
  font-size: 10px;
}

.target b {
  color: rgba(244, 247, 251, 0.82);
}

.history,
.devices,
.install {
  padding: 22px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-head h2 {
  font-size: 18px;
}

.section-head > span {
  color: var(--muted-foreground);
  font-size: 12px;
}

.metric-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.metric-tabs button {
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 9px;
  font-size: 10px;
}

.chart-main {
  height: 320px;
  margin-top: 14px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 12px 0 0;
}

.summary > div {
  min-width: 0;
  padding: 11px 12px;
  border-radius: 12px;
  background: rgba(21, 29, 41, 0.65);
}

.summary dt {
  color: var(--muted-foreground);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.summary dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font: 600 21px var(--font-display);
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.device {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 13px;
  border: 1px solid rgba(98, 230, 189, 0.45);
  border-radius: 13px;
  background: rgba(98, 230, 189, 0.05);
  color: inherit;
  text-align: left;
}

.device > div {
  min-width: 0;
}

.device strong {
  font-size: 14px;
}

.device p {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 5px 0 0;
  color: var(--muted-foreground);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.placeholder {
  margin-top: 9px;
  padding: 13px;
  border: 1px dashed rgba(42, 55, 72, 0.8);
  border-radius: 13px;
  color: var(--muted-foreground);
  font-size: 11px;
  line-height: 1.5;
}

.install-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 18px;
}

.install-grid > div {
  padding: 15px;
  border: 1px solid rgba(42, 55, 72, 0.75);
  border-radius: 13px;
  background: rgba(21, 29, 41, 0.6);
}

.install-grid h3 {
  margin: 0 0 12px;
  font-size: 13px;
}

.install-grid p {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 11px;
  line-height: 1.45;
}

.readings {
  overflow: hidden;
}

.readings > .section-head {
  padding: 18px 22px;
  border-bottom: 1px solid rgba(42, 55, 72, 0.65);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}

.readings table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 13px;
}

.readings th {
  padding: 12px 22px;
  border-bottom: 1px solid rgba(42, 55, 72, 0.6);
  color: var(--muted-foreground);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.readings td {
  padding: 10px 22px;
  border-bottom: 1px solid rgba(42, 55, 72, 0.38);
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.readings td:first-child {
  color: var(--muted-foreground);
  font-family: var(--font-sans);
}

.readings td.ppfd {
  color: var(--chart-ppfd);
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 28px;
  color: var(--muted-foreground);
  font-size: 10px;
}

.hidden {
  display: none !important;
}

.status-pill.mini em {
  display: none;
}

.status-pill.mini {
  padding: 6px 9px;
}

.device .status-pill {
  flex: none;
}

@media (max-width: 1000px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }

  .hero-chart {
    height: 240px;
  }

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

  .two-cols {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .shell {
    padding:
      max(14px, env(safe-area-inset-top))
      12px
      max(30px, env(safe-area-inset-bottom));
  }

  header {
    align-items: flex-start;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }

  .brand h1 {
    font-size: 19px;
    line-height: 1.15;
  }

  .brand p {
    display: -webkit-box;
    max-width: min(58vw, 330px);
    overflow: hidden;
    font-size: 11px;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .header-actions {
    flex-direction: column;
    gap: 7px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .status-pill {
    padding: 6px 9px;
    font-size: 10px;
  }

  .status-pill em {
    display: none;
  }

  .ranges {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    margin-top: 18px;
  }

  .range-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 7px;
  }

  .ranges button {
    min-width: 0;
    padding: 7px 4px;
  }

  .ranges > span {
    width: 100%;
    margin-left: 0;
    text-align: left;
  }

  main {
    gap: 14px;
    margin-top: 14px;
  }

  .panel {
    border-radius: 18px;
  }

  .hero {
    padding: 20px 16px;
  }

  .hero-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
  }

  .hero-label {
    font-size: 11px;
    letter-spacing: 0.16em;
  }

  .hero-number {
    gap: 7px;
    font-size: clamp(62px, 18vw, 86px);
  }

  .hero-number small {
    width: 100%;
    padding-bottom: 0;
    font-size: 12px;
  }

  .progress {
    margin-top: 18px;
  }

  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-top: 18px;
  }

  .hero-stats > div {
    padding: 12px;
  }

  .hero-stats strong {
    font-size: 22px;
  }

  .chip {
    font-size: 11px;
  }

  .hero-chart {
    height: 220px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .metric-card {
    min-height: 210px;
    padding: 16px;
  }

  .metric-value {
    font-size: 34px;
  }

  .spark {
    height: 70px;
  }

  .history,
  .devices,
  .install {
    padding: 18px 15px;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric-tabs button {
    min-height: 38px;
    width: 100%;
  }

  .metric-tabs button:first-child {
    grid-column: 1 / -1;
  }

  .chart-main {
    height: 330px;
    margin-top: 16px;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .summary > div {
    padding: 12px;
  }

  .summary dd {
    font-size: 23px;
  }

  .install-grid {
    grid-template-columns: 1fr;
  }

  .device {
    align-items: flex-start;
    flex-direction: column;
  }

  .readings > .section-head {
    padding: 16px;
  }

  .readings table {
    min-width: 560px;
  }

  .readings th,
  .readings td {
    padding-right: 16px;
    padding-left: 16px;
  }

  footer {
    flex-direction: column;
    gap: 6px;
  }
}

@media (max-width: 420px) {
  .shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  header {
    gap: 8px;
  }

  .brand {
    gap: 9px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
    font-size: 24px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .brand p {
    max-width: 55vw;
    font-size: 10px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .status-pill {
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .range-buttons {
    gap: 5px;
  }

  .ranges button {
    min-height: 34px;
    font-size: 11px;
  }

  .hero {
    padding: 18px 14px;
  }

  .hero-number {
    font-size: clamp(58px, 20vw, 74px);
  }

  .hero-chart {
    height: 190px;
  }

  .metric-card {
    min-height: 200px;
    padding: 15px;
  }

  .history,
  .devices,
  .install {
    padding: 16px 13px;
  }

  .chart-main {
    height: 300px;
  }

  .summary dd {
    font-size: 21px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  }

  .hero-chart {
    height: 220px;
  }

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