:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #f8f8f5;
  --ink: #171a1f;
  --muted: #687074;
  --line: #d9ddd6;
  --green: #18794e;
  --red: #b42318;
  --amber: #b7791f;
  --teal: #0f766e;
  --shadow: 0 10px 24px rgba(23, 26, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

[hidden] {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin-bottom: 6px;
}

.login-button {
  width: 100%;
  margin-top: 4px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand-block h1 {
  font-size: 22px;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-group {
  margin: 14px 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.nav-item {
  min-height: 38px;
  width: 100%;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-soft);
  border-color: var(--line);
}

.nav-item.active {
  background: #eef6f2;
  border-color: #b7dfc8;
  color: var(--teal);
}

.sidebar-footer {
  display: grid;
  gap: 10px;
}

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

.content-shell {
  min-width: 0;
  padding: 22px 24px 32px;
}

.view-section {
  display: grid;
  gap: 16px;
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 750;
}

h2 {
  font-size: 16px;
  font-weight: 720;
}

.toolbar,
.panel-header,
.filters,
.device-title,
.device-meta,
.status-line,
.detail-header,
.event-item {
  display: flex;
  align-items: center;
}

.toolbar {
  justify-content: flex-end;
  gap: 10px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.icon-button:hover {
  border-color: var(--teal);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.command-ok {
  color: var(--green);
}

.command-warn {
  color: var(--amber);
}

.command-error {
  color: var(--red);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.notice {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #f2d49b;
  border-radius: 6px;
  background: #fff7e6;
  color: var(--amber);
  font-size: 13px;
  font-weight: 650;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 14px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.layout,
.operation-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.main-column {
  display: grid;
  gap: 16px;
}

.detail-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

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

.detail-metric,
.detail-field {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.detail-metric {
  min-height: 74px;
  padding: 12px;
}

.detail-metric span,
.detail-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.detail-metric strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.detail-section {
  display: grid;
  gap: 10px;
}

.config-section {
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.detail-section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.detail-section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.detail-field {
  min-height: 58px;
  padding: 10px;
}

.detail-field strong {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.event-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.event-item {
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.event-item:last-child {
  border-bottom: 0;
}

.event-item div {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.event-item strong {
  font-size: 13px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.admin-user-list {
  display: grid;
  gap: 8px;
}

.admin-user {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.admin-user:hover,
.admin-user.selected {
  border-color: var(--teal);
  background: #eef6f2;
}

.admin-user span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.admin-user strong,
.admin-user small {
  overflow-wrap: anywhere;
}

.admin-user small {
  color: var(--muted);
  font-size: 12px;
}

.admin-form {
  display: grid;
  gap: 12px;
}

.admin-form textarea {
  min-height: 76px;
  margin: 0;
  width: 100%;
}

.admin-device-field {
  display: grid;
  gap: 8px;
}

.admin-device-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.admin-device-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.admin-device-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.admin-device-option input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.admin-device-option span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.admin-device-option strong,
.admin-device-option small {
  overflow-wrap: anywhere;
}

.admin-device-option small {
  color: var(--muted);
  font-size: 12px;
}

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

.admin-checks,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-actions {
  justify-content: flex-end;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.check-row span {
  margin: 0;
}

.panel-header {
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.filters {
  gap: 8px;
}

select {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 0 8px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  font: inherit;
}

input {
  height: 34px;
  padding: 0 8px;
}

textarea {
  display: block;
  min-height: 112px;
  margin: 0 14px 14px;
  width: calc(100% - 28px);
  padding: 10px;
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.35;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.command-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
}

.manual-ota-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid #f3bbb4;
  border-radius: 6px;
  background: #fff7f6;
}

.primary-button {
  height: 34px;
  min-width: 92px;
  border: 1px solid #0d5f59;
  border-radius: 6px;
  background: var(--teal);
  color: #ffffff;
  cursor: pointer;
  font-weight: 750;
}

.primary-button:hover {
  background: #0c625c;
}

.primary-button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  padding: 0 10px;
}

.secondary-button:hover {
  border-color: var(--teal);
}

.secondary-button.danger {
  border-color: #f3bbb4;
  color: var(--red);
}

.device-list {
  display: grid;
  gap: 0;
}

.device {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.device:last-child {
  border-bottom: 0;
}

.device:hover,
.device.selected {
  background: #eef6f2;
}

.device-title {
  justify-content: space-between;
  gap: 8px;
  font-weight: 720;
}

.device-meta,
.status-line {
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.pill.online {
  background: #e9f7ef;
  border-color: #b7dfc8;
  color: var(--green);
}

.pill.offline {
  background: #fff0ee;
  border-color: #f3bbb4;
  color: var(--red);
}

.pill.warn {
  background: #fff7e6;
  border-color: #f2d49b;
  color: var(--amber);
}

.summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 150px);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  z-index: 1;
}

td.payload {
  max-width: 480px;
  overflow-wrap: anywhere;
}

.empty {
  padding: 20px 14px;
  color: var(--muted);
}

.empty.compact {
  padding: 12px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    gap: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-group {
    display: none;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    text-align: center;
  }

  .sidebar-footer {
    grid-template-columns: 1fr auto auto;
    align-items: center;
  }

  .content-shell {
    padding: 16px 14px 28px;
  }

  .metrics,
  .layout,
  .operation-layout,
  .detail-metrics,
  .detail-grid,
  .admin-layout,
  .admin-form-grid {
    grid-template-columns: 1fr;
  }

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

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

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

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .sidebar-footer {
    grid-template-columns: 1fr;
  }

  .filters {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .event-item,
  .event-item div {
    align-items: flex-start;
    flex-direction: column;
  }

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