:root {
  color-scheme: dark;
  --bg: #0b1017;
  --panel: #111923;
  --panel-2: #162130;
  --line: #263447;
  --text: #e9eef6;
  --muted: #98a7ba;
  --accent: #2ea66f;
  --warn: #d99532;
  --danger: #d85f5f;
  --info: #5d8fd8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-panel,
.metric,
.farm-row,
.json-panel,
.device-table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel {
  padding: 28px;
}

.brand-lockup,
.brand-line,
.topbar,
.page-head,
.toolbar-row,
.farm-row {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 14px;
  margin-bottom: 24px;
}

.brand-lockup h1 {
  margin: 0;
  font-size: 1.6rem;
}

.brand-lockup p,
.page-head p,
.farm-row small,
.muted {
  color: var(--muted);
}

.brand-lockup p,
.page-head p {
  margin: 4px 0 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #07120c;
  font-weight: 850;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  font-size: .8rem;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .92rem;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #090e14;
  color: var(--text);
  padding: 11px 12px;
}

.primary-action {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #07120c;
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
}

.alert {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

.alert.danger {
  background: rgba(216, 95, 95, .14);
  color: #ffaaaa;
  border: 1px solid rgba(216, 95, 95, .35);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 16, 23, .94);
  backdrop-filter: blur(12px);
}

.brand-line {
  gap: 10px;
  font-weight: 800;
}

.topbar nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: .95rem;
}

.user-chip,
.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--text);
  background: var(--panel-2);
}

.page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px 16px 44px;
}

.page-head {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 1.55rem;
}

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

.metric {
  padding: 14px;
  min-height: 84px;
}

.metric span {
  color: var(--muted);
  font-size: .86rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 1.45rem;
}

.toolbar-row {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.toolbar-row label {
  width: min(280px, 100%);
}

.section-title {
  margin: 16px 0 10px;
  font-size: 1.1rem;
}

.device-table-wrap {
  overflow-x: auto;
}

.device-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

.device-table th,
.device-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.device-table th {
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  background: var(--panel-2);
}

.device-table tbody tr:last-child td {
  border-bottom: 0;
}

.device-name {
  display: grid;
  gap: 2px;
}

.device-name small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: .78rem;
  font-weight: 760;
  white-space: nowrap;
}

.badge.on {
  background: rgba(46, 166, 111, .16);
  color: #74d89e;
}

.badge.off {
  background: rgba(216, 95, 95, .16);
  color: #ffaaaa;
}

.badge.idle {
  background: rgba(93, 143, 216, .16);
  color: #a9c7f7;
}

.farm-list {
  display: grid;
  gap: 10px;
}

.farm-row {
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.farm-row span:first-child {
  display: grid;
  gap: 4px;
}

.arrow {
  color: var(--muted);
  font-size: 1.8rem;
}

.empty-state {
  color: var(--muted);
  padding: 22px 0;
}

.json-panel {
  padding: 12px;
}

.json-panel textarea {
  min-height: 70vh;
  resize: vertical;
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: .88rem;
  line-height: 1.5;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-head,
  .toolbar-row {
    align-items: stretch;
    flex-direction: column;
  }

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

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