:root {
  --surface: #ffffff;
  --surface-soft: #f6faf7;
  --ink: #07130d;
  --muted: #6d7a72;
  --line: rgba(7, 19, 13, 0.1);
  --green: #176b43;
  --green-2: #21ba72;
  --lime: #d8ff8a;
  --amber: #f3c85e;
  --red: #d84b43;
  --shadow: 0 24px 70px rgba(25, 55, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(216, 255, 138, 0.24), transparent 28%),
    linear-gradient(135deg, #e4f0eb, #fbfdf9 54%, #e7f6f0);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app,
.dashboard {
  width: min(1460px, calc(100% - 32px));
  margin: 16px auto;
  padding: clamp(16px, 2.2vw, 34px);
  border: 1px solid rgba(23, 107, 67, 0.14);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.64);
  box-shadow: var(--shadow);
}

.dashboard {
  width: 100%;
  margin: 0;
  padding: clamp(12px, 1.4vw, 20px);
}

.app:has(#detailScreen.active) {
  width: min(1500px, calc(100% - 16px));
  margin: 8px auto;
  padding: 8px;
  border-radius: 24px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.topbar,
.dashboard-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
}

.dashboard-head {
  margin-bottom: 10px;
}

.detail-topbar {
  margin-bottom: 16px;
}

.detail-nav,
.plants-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.detail-nav {
  margin: -2px 0 10px;
}

.detail-nav .compact-button {
  min-height: 34px;
}

.plants-nav {
  margin: -8px 0 16px;
}

.eyebrow,
.label {
  display: block;
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2.2rem, 6vw, 5.6rem);
  line-height: 1.03;
  text-transform: uppercase;
}

.detail-title {
  max-width: 820px;
  font-size: clamp(1.7rem, 2.6vw, 2.65rem);
  line-height: 1.06;
}

.dashboard-head .subtitle {
  display: none;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.8rem);
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

p {
  color: var(--muted);
}

.subtitle {
  margin-bottom: 0;
  line-height: 1.45;
}

.primary-button,
.ghost-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.primary-button {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.ghost-button {
  color: var(--green);
  background: white;
}

.compact-button {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.92rem;
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

input,
select {
  min-height: 44px;
  min-width: 0;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

.slots-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(170px, 1fr));
  gap: 18px;
}

.slot-card,
.plant-list-card,
.category-section,
.plant-form,
.current-card,
.plant-stage,
.sensor-card,
.chart-card,
.summary-card,
.diagnostics,
.system-health-card,
.settings-card,
.dialog-card {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 16px 38px rgba(25, 55, 38, 0.08);
}

.slot-card {
  display: grid;
  gap: 18px;
  min-height: 230px;
  padding: 22px;
  text-align: left;
}

.slot-card strong {
  display: block;
  font-size: 1.8rem;
}

.slot-state {
  justify-self: start;
  padding: 7px 11px;
  border-radius: 999px;
  color: var(--green);
  background: #eaffde;
  font-size: 0.82rem;
  font-weight: 800;
}

.slot-state.claimed {
  color: white;
  background: var(--green);
}

.toolbar,
.inline-form,
.image-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.inline-form {
  flex: 1;
}

.inline-form input {
  flex: 1 1 180px;
}

.plant-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 220px minmax(220px, 1fr) auto;
  gap: 10px;
  margin-bottom: 16px;
  padding: 16px;
}

.settings-stack {
  display: grid;
  gap: 14px;
}

.settings-card {
  padding: 14px 16px;
}

.settings-card > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  cursor: pointer;
  list-style-position: inside;
}

.settings-card > summary strong {
  color: var(--ink);
  font-size: 1.04rem;
  line-height: 1.25;
}

.password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 10px;
  margin-top: 12px;
}

.wifi-settings {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.wifi-settings p {
  margin: 0;
  color: var(--muted);
}

.wifi-settings .primary-button {
  justify-self: start;
}

.system-health-incidents {
  color: var(--muted);
  font-size: 0.9rem;
  font-style: normal;
}

.health-log {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.health-log summary {
  cursor: pointer;
  color: var(--green);
  font-weight: 800;
}

.health-days {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.health-week {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  overflow: hidden;
}

.health-week summary {
  padding: 10px 12px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.health-week-days {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.health-day-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: left;
}

.health-day-button span,
.health-day-button strong,
.health-day-button em {
  min-width: 0;
}

.health-day-button em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.86rem;
}

.health-detail-card {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.health-detail-card h3,
.health-detail-card h4 {
  margin-bottom: 8px;
}

.health-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.health-metrics span,
.health-plants section,
.health-events p {
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-soft);
}

.health-metrics strong {
  display: block;
}

.health-plants,
.health-events {
  display: grid;
  gap: 8px;
}

.health-events-list {
  display: grid;
  gap: 8px;
}

.health-show-all {
  justify-self: start;
}

.health-plants p,
.health-events p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

.category-list {
  display: grid;
  gap: 18px;
}

.category-section {
  padding: 18px;
}

.category-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.category-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.text-button {
  border: 0;
  color: var(--green);
  background: transparent;
}

.plants-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.plant-list-card {
  overflow: hidden;
  text-align: left;
  border-radius: 22px;
}

.plant-card-button {
  display: grid;
  grid-template-rows: 190px 1fr;
  width: 100%;
  min-height: 360px;
  padding: 0;
  border: 0;
  text-align: left;
  background: transparent;
}

.plant-thumb {
  display: grid;
  place-items: center;
  min-height: 190px;
  background: linear-gradient(145deg, #f9fbf6, #e7f8ef);
  overflow: hidden;
}

.plant-thumb img,
.plant-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.plant-card-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.plant-card-title {
  display: grid;
  gap: 3px;
}

.plant-card-title strong {
  display: block;
  font-size: clamp(1.05rem, 1.5vw, 1.32rem);
  line-height: 1.1;
}

.plant-card-title span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.plant-card-reading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 4px;
}

.plant-card-reading strong {
  color: var(--green);
  font-size: clamp(3rem, 5vw, 4.7rem);
  line-height: 0.82;
}

.plant-card-reading span {
  max-width: 92px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: right;
  text-transform: uppercase;
}

.plant-card-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pill {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--green);
  background: var(--surface-soft);
  font-size: 0.82rem;
  font-weight: 800;
}

.plant-status,
.plant-communication {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 850;
  line-height: 1;
}

.plant-status {
  color: var(--green);
  background: var(--surface-soft);
}

.plant-communication {
  gap: 7px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
}

.mini-dot {
  width: 9px;
  aspect-ratio: 1;
  border-radius: 999px;
  background: var(--red);
}

.plant-communication[data-state="online"] .mini-dot {
  background: var(--green-2);
}

.plant-communication[data-state="delay"] .mini-dot {
  background: var(--amber);
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.pulse-dot {
  width: 12px;
  aspect-ratio: 1;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 7px rgba(243, 200, 94, 0.16);
}

.connection-pill[data-state="online"] .pulse-dot {
  background: var(--green-2);
  box-shadow: 0 0 0 7px rgba(33, 186, 114, 0.16);
}

.connection-pill[data-state="delay"] .pulse-dot {
  background: var(--amber);
  box-shadow: 0 0 0 7px rgba(243, 200, 94, 0.16);
}

.connection-pill[data-state="offline"] .pulse-dot,
.connection-pill[data-state="error"] .pulse-dot {
  background: var(--red);
  box-shadow: 0 0 0 7px rgba(216, 75, 67, 0.14);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(250px, 0.34fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.hero-grid > * {
  min-width: 0;
}

.plant-stage {
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
  align-content: start;
  padding: 14px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(231, 248, 239, 0.88));
}

.plant-photo {
  display: grid;
  place-items: center;
  height: clamp(120px, 11vw, 140px);
  min-height: 0;
  border-radius: 18px;
  background: linear-gradient(145deg, #fbfdf9, #e7f8ef);
  overflow: hidden;
}

.css-plant {
  position: relative;
  width: min(300px, 70vw);
  height: 300px;
  margin: auto;
  transform: scale(0.54);
}

.leaf {
  position: absolute;
  width: 108px;
  height: 165px;
  border-radius: 108px 10px 108px 10px;
  background: linear-gradient(135deg, #36a566, #0d4c2e);
  transform-origin: 76% 93%;
  box-shadow: inset 18px 0 rgba(255, 255, 255, 0.13);
}

.leaf-a { left: 36px; top: 54px; transform: rotate(-39deg); }
.leaf-b { left: 140px; top: 30px; transform: rotate(28deg); }
.leaf-c { left: 94px; top: 24px; transform: rotate(-6deg) scale(1.12); }
.leaf-d { left: 116px; top: 92px; transform: rotate(48deg) scale(0.92); }

.stem {
  position: absolute;
  bottom: 70px;
  width: 8px;
  height: 165px;
  border-radius: 999px;
  background: #236b40;
}

.stem-a { left: 150px; transform: rotate(4deg); }
.stem-b { left: 134px; transform: rotate(-16deg); }

.pot {
  position: absolute;
  left: 76px;
  bottom: 0;
  width: 145px;
  height: 82px;
  border: 1px solid rgba(7, 19, 13, 0.08);
  border-radius: 16px 16px 44px 44px;
  background: linear-gradient(135deg, #fff8ec, #e7ddcc);
}

.plant-editor {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid rgba(23, 107, 67, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.plant-editor summary {
  cursor: pointer;
  padding: 10px 12px;
  color: var(--green);
  font-weight: 850;
}

.plant-actions {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
  width: 100%;
  min-width: 0;
}

.plant-editor:not([open]) .plant-actions {
  display: none;
}

.plant-editor .inline-form,
.plant-editor .image-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  gap: 8px;
}

.plant-editor input,
.plant-editor select,
.plant-editor button {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.plant-editor input[type="file"] {
  height: auto;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.82rem;
}

.current-card {
  display: grid;
  grid-template-columns: minmax(150px, 0.34fr) minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "humidity status"
    "humidity update";
  column-gap: 22px;
  row-gap: 8px;
  align-content: center;
  padding: clamp(16px, 2vw, 22px);
}

.current-card .card-head {
  grid-area: head;
}

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

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

.humidity-readout {
  display: flex;
  grid-area: humidity;
  align-items: flex-start;
  align-self: center;
  gap: 12px;
  margin: 0;
}

.humidity-readout strong {
  font-size: clamp(3.2rem, 5vw, 4.5rem);
  line-height: 0.86;
}

.humidity-readout span {
  color: var(--green);
  font-size: clamp(1.55rem, 2.4vw, 2.2rem);
  font-weight: 900;
}

.status-row {
  display: grid;
  grid-area: status;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.status-row > div {
  min-height: 60px;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--surface-soft);
}

.status-row strong {
  display: block;
  font-size: clamp(1.1rem, 1.6vw, 1.55rem);
  overflow-wrap: anywhere;
}

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

.sensor-card {
  min-height: 76px;
  padding: 10px 14px;
}

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

.sensor-card strong {
  display: block;
  margin: 4px 0 2px;
  font-size: clamp(1.35rem, 2vw, 1.85rem);
  line-height: 1;
}

.sensor-card p,
.last-update {
  margin-bottom: 0;
}

.last-update {
  grid-area: update;
  align-self: end;
  margin-top: 0;
  font-size: 0.94rem;
}

.sensor-card p {
  font-size: 0.88rem;
  line-height: 1.18;
}

.sensor-card.installed {
  color: white;
  background: linear-gradient(145deg, var(--green), #0c4d31);
}

.sensor-card.installed span,
.sensor-card.installed p {
  color: rgba(255, 255, 255, 0.72);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 12px;
}

.chart-card,
.summary-card {
  padding: 16px;
}

.limit-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.limit-control select {
  min-height: 36px;
}

.chart-card .eyebrow {
  margin-bottom: 3px;
  font-size: 0.68rem;
}

.chart-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}

.chart-meta strong {
  color: var(--ink);
}

.chart-wrap {
  position: relative;
  min-height: 300px;
  margin-top: 8px;
  border-radius: 18px;
  background:
    linear-gradient(rgba(7, 19, 13, 0.055) 1px, transparent 1px) 0 0 / 100% 25%,
    linear-gradient(180deg, #fbfdf9, #edf8ef);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 300px;
  min-height: 300px;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
}

.chart-empty.hidden {
  display: none;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.summary-card strong {
  display: block;
  margin-bottom: 10px;
  font-size: 1.7rem;
}

.diagnostics {
  padding: 8px 0;
}

.diagnostics summary {
  cursor: pointer;
  padding: 18px 22px;
  font-weight: 800;
}

dl {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 22px 22px;
}

dl div {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

dialog {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  border: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(5, 11, 8, 0.44);
}

.dialog-card {
  display: grid;
  gap: 12px;
  padding: 24px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 8px 0 0;
}

.api-error {
  min-height: 24px;
  margin: 18px 0 0;
  color: var(--red);
}

@media (max-width: 1150px) {
  .slots-grid {
    grid-template-columns: repeat(2, minmax(170px, 1fr));
  }

  .hero-grid,
  .content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .plants-grid,
  .sensor-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .password-form {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 700px) {
  .app,
  .dashboard {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .topbar,
  .dashboard-head,
  .status-row,
  .sensor-grid,
  .slots-grid,
  .plants-grid,
  .plant-form,
  .password-form {
    grid-template-columns: 1fr;
  }

  .plant-card-button {
    grid-template-rows: 210px 1fr;
    min-height: 0;
  }

  .card-head,
  .section-head {
    display: grid;
  }

  .detail-title {
    font-size: clamp(1.7rem, 9vw, 2.45rem);
  }

  .detail-nav,
  .plants-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-button {
    width: 100%;
  }

  .plant-stage,
  .current-card,
  .chart-card,
  .summary-card,
  .diagnostics {
    min-width: 0;
  }

  .current-card {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "humidity"
      "status"
      "update";
  }

  .image-actions input[type="file"],
  .plant-actions input,
  .plant-actions select,
  .plant-actions button {
    width: 100%;
    max-width: 100%;
  }

  dl div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
