:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-border: #d8dee4;
  --text: #182026;
  --muted: #63707a;
  --line: #e5e9ed;
  --primary: #176b87;
  --primary-strong: #0f5268;
  --accent: #2f7d50;
  --warn: #b86b00;
  --danger: #b13b3b;
  --control: #eef3f5;
  --shadow: 0 10px 28px rgba(24, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
}

.eyebrow,
.subtle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  margin-top: 2px;
  font-size: 24px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
  font-weight: 700;
}

.status-strip,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 18px 28px 28px;
}

.side-stack {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.devices-panel {
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #fafbfc;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.action-column {
  width: 190px;
  text-align: right;
}

td.action-cell {
  text-align: right;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.editing-row td {
  background: #f8fbfc;
}

.inline-input {
  min-height: 34px;
  padding: 7px 8px;
}

.connection-edit-fields {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 92px;
  gap: 8px;
  align-items: center;
}

.port-input {
  max-width: 100px;
}

.empty-cell {
  height: 136px;
  color: var(--muted);
  text-align: center;
}

.device-name {
  display: grid;
  gap: 3px;
}

.serial {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 10px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.pill.connected {
  color: #155c38;
  border-color: #b9dec9;
  background: #e8f5ee;
}

.pill.offline,
.pill.error {
  color: #7c2424;
  border-color: #f0c4c4;
  background: #fff0f0;
}

.pill.warning {
  color: #7a4a00;
  border-color: #eac98f;
  background: #fff6df;
}

.pill.muted {
  color: var(--muted);
  border-color: var(--line);
  background: var(--control);
}

.form-grid {
  display: grid;
  gap: 13px;
  margin-top: 14px;
}

.split-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd4db;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.16);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    opacity 120ms ease;
}

.button.primary {
  color: #ffffff;
  background: var(--primary);
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.secondary {
  color: var(--text);
  border-color: #cbd4db;
  background: var(--control);
}

.button.secondary:hover {
  border-color: #aebac3;
  background: #e3ebee;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  display: none;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: var(--text);
}

.toast.visible {
  display: block;
}

.toast.error {
  border-color: #efb7b7;
  color: #762525;
}

.toast.success {
  border-color: #abd6bd;
  color: #155c38;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .side-stack .panel:first-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .workspace {
    padding: 14px;
  }

  .side-stack,
  .split-fields {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 15px;
  }

  .panel-header {
    flex-direction: column;
  }

  .status-strip,
  .button-row {
    width: 100%;
  }

  .button-row .button,
  .status-strip .button {
    flex: 1;
  }
}
