:root {
  color-scheme: light;
  --bg: #d9d9d9;
  --panel: #f2f2f2;
  --white: #ffffff;
  --text: #111111;
  --muted: #555555;
  --line: #a7a7a7;
  --line-dark: #777777;
  --select: #dce8f8;
  --button: #eeeeee;
  --button-hover: #e0e0e0;
  --danger: #8b0000;
  --ok: #0b5f16;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 12px;
}

button,
input,
select {
  font: inherit;
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: 28px 26px 34px 1fr 24px;
  border: 1px solid var(--line-dark);
  background: var(--panel);
}

.window-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-weight: 600;
  background: #f7f7f7;
  border-bottom: 1px solid var(--line);
}

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

.brand img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.menu-bar,
.toolbar,
.status-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px;
  border-bottom: 1px solid var(--line);
  background: #eeeeee;
}

.menu {
  position: relative;
  height: 24px;
}

.menu-bar button {
  height: 22px;
  min-width: 42px;
  padding: 0 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.menu-bar button:hover {
  border-color: var(--line);
  background: var(--button-hover);
}

.menu-trigger::after {
  content: "";
}

.menu-panel {
  position: absolute;
  top: 24px;
  left: 0;
  z-index: 20;
  display: none;
  min-width: 178px;
  padding: 3px;
  border: 1px solid var(--line-dark);
  background: var(--white);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.12);
}

.menu.open .menu-panel,
.menu:focus-within .menu-panel {
  display: grid;
}

.menu-panel button {
  width: 100%;
  height: 24px;
  border: 1px solid transparent;
  background: var(--white);
}

.menu-panel button:hover {
  border-color: #9eb9df;
  background: var(--select);
}

.toolbar {
  gap: 5px;
}

.toolbar button,
.actions button {
  height: 25px;
  min-width: 76px;
  padding: 0 10px;
  border: 1px solid var(--line-dark);
  background: var(--button);
  color: var(--text);
  cursor: pointer;
}

.toolbar button:hover:not(:disabled),
.actions button:hover:not(:disabled) {
  background: var(--button-hover);
}

button:disabled,
input:disabled,
select:disabled {
  color: #777;
  cursor: not-allowed;
}

button:disabled {
  opacity: 0.7;
}

.separator {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--line);
}

.badge {
  min-width: 86px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: var(--white);
  text-align: center;
  font-weight: 600;
}

.badge.running {
  color: var(--ok);
}

.badge.error {
  color: var(--danger);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 6px;
  padding: 6px;
}

.sidebar,
.content,
.data-pane {
  min-height: 0;
  border: 1px solid var(--line-dark);
  background: var(--white);
}

.sidebar {
  display: flex;
  flex-direction: column;
}

.pane-title,
.pane-header {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: #e8e8e8;
  font-weight: 600;
}

.tree {
  padding: 5px;
  border-bottom: 1px solid var(--line);
}

.tree-row {
  height: 23px;
  display: flex;
  align-items: center;
  padding: 0 6px;
}

.tree-row.selected {
  background: var(--select);
  border: 1px solid #9eb9df;
}

.counter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 24px;
  padding: 0 8px;
  border-bottom: 1px solid #e3e3e3;
}

.counter-row span {
  color: var(--muted);
}

.counter-row strong {
  font-size: 12px;
}

.content {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
  padding: 6px;
  background: #f8f8f8;
}

.form-layout {
  display: grid;
  gap: 6px;
}

fieldset {
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--white);
}

legend {
  padding: 0 5px;
  font-weight: 600;
}

.form-grid {
  display: grid;
  gap: 7px;
  align-items: end;
}

.connection-grid {
  grid-template-columns: 1.35fr 0.7fr 1.2fr 0.55fr 0.65fr 0.75fr;
}

.serial-grid {
  grid-template-columns: 1.4fr 0.8fr 0.8fr 0.8fr 0.8fr 0.8fr;
}

.read-grid {
  grid-template-columns: 1.3fr 0.75fr 1fr 0.6fr 0.85fr;
}

label {
  display: grid;
  gap: 3px;
}

label span {
  color: var(--muted);
}

input,
select {
  width: 100%;
  height: 24px;
  padding: 0 5px;
  border: 1px solid var(--line-dark);
  border-radius: 0;
  background: var(--white);
  color: var(--text);
}

.field-button {
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line-dark);
  background: var(--button);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 1px solid #2f6db3;
  outline-offset: 0;
}

.data-pane {
  display: grid;
  grid-template-rows: 24px 1fr;
}

.pane-header span:last-child {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
}

.pane-header span.ok {
  color: var(--ok);
}

.pane-header span.error {
  color: var(--danger);
}

.table-wrap {
  min-height: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
}

th,
td {
  height: 24px;
  padding: 0 7px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid #e2e2e2;
  text-align: left;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #ededed;
  border-bottom-color: var(--line-dark);
  font-weight: 600;
}

td:last-child,
th:last-child {
  border-right: 0;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.status-bar {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  color: var(--muted);
}

.app-dialog {
  width: min(520px, calc(100vw - 30px));
  padding: 0;
  border: 1px solid var(--line-dark);
  background: var(--white);
  color: var(--text);
}

.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.2);
}

.dialog-title {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 9px;
  border-bottom: 1px solid var(--line);
  background: #e8e8e8;
  font-weight: 600;
}

.dialog-title button {
  width: 24px;
  height: 22px;
  border: 1px solid var(--line-dark);
  background: var(--button);
}

.dialog-body {
  padding: 12px;
  line-height: 1.45;
}

.dialog-body h3 {
  margin: 0 0 7px;
  font-size: 14px;
}

.dialog-body p {
  margin: 0 0 8px;
}

.dialog-body ul {
  margin: 7px 0 0 18px;
  padding: 0;
}

.dialog-body li {
  margin: 3px 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: #f4f4f4;
}

.dialog-actions button {
  min-width: 72px;
  height: 25px;
  border: 1px solid var(--line-dark);
  background: var(--button);
}

.app-dialog.error-dialog {
  border-color: #9f1d1d;
}

.error-dialog .dialog-title {
  color: #ffffff;
  border-bottom-color: #7f1717;
  background: #b42318;
}

.error-dialog .dialog-title button {
  color: #ffffff;
  border-color: #7f1717;
  background: #8f1d14;
}

.error-dialog .dialog-body {
  border-left: 4px solid #b42318;
  background: #fff5f4;
}

.error-dialog .dialog-body h3 {
  color: #8f1d14;
}

.error-dialog .dialog-actions {
  border-top-color: #efb5b0;
  background: #fff5f4;
}

.error-dialog .dialog-actions button {
  color: #ffffff;
  border-color: #7f1717;
  background: #b42318;
}

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

  .sidebar {
    display: none;
  }

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

@media (max-width: 600px) {
  .app {
    grid-template-rows: 28px auto auto 1fr 24px;
  }

  .menu-bar,
  .toolbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 30px;
    padding: 4px;
  }

  .connection-grid,
  .serial-grid,
  .read-grid {
    grid-template-columns: 1fr;
  }
}
