:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #17201d;
  background: #f4f6f5;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: #f4f6f5; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  height: 64px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f8fbfa;
  background: #18231f;
  border-bottom: 3px solid #2b8a5f;
}
.topbar h1 { display: inline; margin: 0; font-size: 19px; letter-spacing: 0; }
.subtitle { margin-left: 10px; color: #b8c4bf; font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

button {
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid #aeb8b3;
  border-radius: 5px;
  background: #fff;
  color: #17201d;
}
button:hover { border-color: #277a56; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #2b8a5f;
  outline-offset: 2px;
}
button.primary { border-color: #236f4e; color: #fff; background: #236f4e; }
button.primary:hover { background: #195d40; }
button.secondary { color: #eff5f2; border-color: #51625b; background: transparent; }

.connection, .state-label {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 4px 9px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.connection.connected { color: #b9f2d6; background: #254f3e; }
.connection.warning { color: #ffe6aa; background: #5c4a24; }
.connection.disconnected { color: #ffd7c9; background: #65362c; }
.connection.unknown { color: #d5ddd9; background: #34423c; }

.workspace { min-height: calc(100vh - 64px); display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.device-pane { background: #fff; border-right: 1px solid #d8dfdc; }
.pane-heading { padding: 18px; display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid #e2e7e5; }
.pane-heading h2 { margin: 0; font-size: 15px; }
.pane-heading span { color: #6c7772; font-size: 12px; }
.device-list { padding: 8px; }
.device-row {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  text-align: left;
  border-color: transparent;
  background: transparent;
}
.device-row.active { border-color: #b7d7c8; background: #edf6f1; }
.device-row strong, .device-row small { display: block; overflow: hidden; text-overflow: ellipsis; }
.device-row small { margin-top: 3px; color: #6c7772; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #98a29d; }
.status-dot.online { background: #168653; box-shadow: 0 0 0 3px #d8f0e4; }
.status-dot.offline { background: #b84c35; }

.main-pane { min-width: 0; padding: 22px 26px 48px; }
.empty-state { min-height: 420px; display: grid; place-items: center; color: #82908a; }
.empty-state h2 { font-size: 16px; font-weight: 500; }
.device-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.status-line { display: flex; align-items: center; gap: 10px; }
.status-line h2 { margin: 0; font-size: 22px; }
.muted { margin: 5px 0 0 19px; color: #6c7772; font-size: 13px; }
.state-label { color: #5e4b1e; border: 1px solid #e0c978; background: #fff8da; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid #cdd6d2; }
.tab { min-width: 88px; border: 0; border-radius: 0; color: #52605a; background: transparent; border-bottom: 3px solid transparent; }
.tab.active { color: #1e6849; border-bottom-color: #267a56; font-weight: 600; }
.tab-panel { padding-top: 20px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { min-height: 94px; padding: 16px; background: #fff; border: 1px solid #dbe2df; border-radius: 6px; }
.metric span { color: #69756f; font-size: 12px; }
.metric strong { display: block; margin-top: 12px; font-size: 20px; font-weight: 650; }
.content-section, .form-section { padding: 22px 0; border-bottom: 1px solid #d8dfdc; }
.content-section h3, .form-section h3 { margin: 0 0 14px; font-size: 15px; }
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; }
.detail-grid div { min-width: 0; }
.detail-grid dt { color: #69756f; font-size: 12px; }
.detail-grid dd { margin: 5px 0 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; border: 1px solid #d8dfdc; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { min-height: 42px; padding: 10px 12px; text-align: left; border-bottom: 1px solid #e3e8e6; white-space: nowrap; }
th { color: #52605a; background: #f0f3f2; font-size: 12px; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; overflow-wrap: anywhere; }
td.empty-cell { height: 100px; color: #7a8680; text-align: center; }
.download-button { min-height: 30px; padding: 4px 10px; }

.form-grid { display: grid; gap: 12px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
.form-grid.five { grid-template-columns: repeat(5, minmax(120px, 1fr)); }
.split-section { display: grid; grid-template-columns: minmax(180px, 0.7fr) minmax(0, 2fr); gap: 30px; }
label { display: grid; gap: 6px; color: #53615b; font-size: 12px; }
input, select { width: 100%; height: 38px; padding: 7px 9px; border: 1px solid #b8c2bd; border-radius: 4px; color: #17201d; background: #fff; }
.light-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.light-control { margin: 0; padding: 16px; border: 1px solid #cfd8d4; border-radius: 6px; }
.light-control legend { padding: 0 6px; font-size: 13px; font-weight: 600; }
.manual-fields, .automatic-fields { margin-top: 12px; display: grid; grid-template-columns: repeat(5, minmax(100px, 1fr)); gap: 10px; }
.manual-fields { grid-template-columns: minmax(120px, 200px); }
.form-actions { position: sticky; bottom: 0; min-height: 66px; display: flex; justify-content: flex-end; align-items: center; gap: 16px; padding: 12px 0; background: #f4f6f5; border-top: 1px solid #d1d9d5; }
#config-feedback { color: #52605a; font-size: 13px; }
#config-feedback.error { color: #a43f2b; }

dialog { width: min(420px, calc(100% - 32px)); padding: 0; border: 1px solid #aebbb5; border-radius: 6px; box-shadow: 0 16px 50px #111a; }
dialog::backdrop { background: #101714aa; }
.login-form { padding: 24px; }
.login-form h2 { margin: 0 0 22px; font-size: 19px; }
.login-form button { width: 100%; margin-top: 10px; }
.error { min-height: 18px; color: #a43f2b; font-size: 12px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; color: #fff; background: #26332e; border-radius: 5px; box-shadow: 0 6px 20px #0004; }

@media (max-width: 1000px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.five, .form-grid.four { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .light-grid, .split-section { grid-template-columns: 1fr; }
  .automatic-fields { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
}

@media (max-width: 700px) {
  .topbar { height: auto; min-height: 64px; padding: 10px 14px; align-items: flex-start; }
  .subtitle, #logout-button { display: none; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .workspace { grid-template-columns: 1fr; }
  .device-pane { border-right: 0; border-bottom: 1px solid #d8dfdc; }
  .device-list { display: flex; gap: 6px; overflow-x: auto; }
  .device-row { min-width: 190px; }
  .main-pane { padding: 16px 12px 36px; }
  .device-header { align-items: flex-start; gap: 10px; }
  .tabs { overflow-x: auto; }
  .tab { min-width: 78px; padding-inline: 8px; }
  .metrics, .detail-grid, .form-grid.five, .form-grid.four { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 430px) {
  .connection { display: none; }
  .metrics, .detail-grid, .form-grid.five, .form-grid.four, .automatic-fields { grid-template-columns: 1fr; }
  .state-label { max-width: 130px; text-align: center; }
}
