:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --text: #18222d;
  --muted: #607080;
  --line: #d8e1ea;
  --brand: #0f8b8d;
  --brand-dark: #0a686b;
  --accent: #b7791f;
  --danger: #b83232;
  --success: #277a48;
  --shadow: 0 16px 36px rgba(31, 45, 61, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: #16232f;
  color: #f8fbfd;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--brand);
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.section-head h3,
.command-form h4 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin-top: 2px;
  color: #9fb2c3;
  font-size: 13px;
}

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

.version-panel div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.version-panel span,
.version-panel strong {
  display: block;
}

.version-panel span {
  color: #9fb2c3;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.version-panel strong {
  margin-top: 4px;
  overflow: hidden;
  color: #ffffff;
  font-size: 14px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.connection,
.device-panel {
  color: var(--text);
  box-shadow: none;
}

.connection {
  display: grid;
  gap: 8px;
  padding: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

.field-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 8px;
}

.mini-button {
  min-height: 40px;
  padding: 0 10px;
  color: var(--brand-dark);
  border: 1px solid rgba(15, 139, 141, 0.28);
  border-radius: 6px;
  background: rgba(15, 139, 141, 0.08);
  font-size: 12px;
  font-weight: 850;
}

.mini-button:hover {
  background: rgba(15, 139, 141, 0.14);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 750;
  white-space: nowrap;
}

.icon-button {
  width: 40px;
  padding: 0;
  color: var(--text);
  border-color: var(--line);
  background: #ffffff;
}

.icon-button:hover,
.secondary-button:hover {
  background: var(--surface-2);
}

.primary-button {
  padding: 0 14px;
  color: #ffffff;
  background: var(--brand);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  padding: 0 14px;
  color: var(--text);
  border-color: var(--line);
  background: #ffffff;
}

.danger-button {
  padding: 0 14px;
  color: #ffffff;
  background: var(--danger);
}

.danger-button:hover {
  background: #942626;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.device-panel {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 14px;
}

.panel-heading,
.section-head,
.topbar,
.topbar-actions,
.button-row {
  display: flex;
  align-items: center;
}

.panel-heading,
.section-head,
.topbar {
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar .eyebrow {
  color: #657789;
}

#deviceCount {
  font-size: 28px;
  line-height: 1;
}

.search {
  margin: 14px 0 10px;
}

.device-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 120px;
  overflow: auto;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.device-item[aria-selected="true"] {
  color: #ffffff;
  border-color: var(--brand);
  background: var(--brand);
}

.device-item small {
  color: inherit;
  opacity: 0.72;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  margin-bottom: 18px;
}

.topbar h2 {
  font-size: 26px;
  line-height: 1.15;
}

.topbar-actions,
.button-row {
  flex-wrap: wrap;
  gap: 8px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
  line-height: 1.15;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.surface {
  min-width: 0;
  padding: 18px;
}

.span-2 {
  grid-column: span 2;
}

.section-head {
  margin-bottom: 16px;
}

.section-head h3 {
  font-size: 18px;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.command-form,
.stack-form {
  display: grid;
  gap: 12px;
}

.command-form {
  align-content: start;
  min-height: 194px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.command-form h4 {
  font-size: 15px;
}

.command-form p {
  min-height: 38px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.two-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-pill {
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.ok {
  color: var(--success);
  border-color: rgba(39, 122, 72, 0.24);
  background: rgba(39, 122, 72, 0.08);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(184, 50, 50, 0.24);
  background: rgba(184, 50, 50, 0.08);
}

.error-banner {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin: -4px 0 18px;
  padding: 14px;
  color: #701c1c;
  border: 2px solid rgba(184, 50, 50, 0.42);
  border-radius: 8px;
  background: #fff1f1;
}

.error-banner[hidden] {
  display: none;
}

.error-banner-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: #ffffff;
  border-radius: 8px;
  background: var(--danger);
}

.error-banner strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
}

.error-banner p {
  margin: 5px 0 0;
  color: #842727;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.log {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  padding-right: 4px;
}

.log-entry {
  display: grid;
  grid-template-columns: 90px 90px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  font-size: 13px;
}

.log-entry strong {
  color: var(--text);
}

.log-entry span,
.log-entry code {
  color: var(--muted);
}

.log-entry code {
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
  }

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

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

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .device-panel {
    max-height: 360px;
  }

  .workspace {
    padding: 18px;
  }

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

  .content-grid,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .two-cols {
    grid-template-columns: 1fr;
  }

  .field-action {
    grid-template-columns: minmax(0, 1fr) 54px;
  }

  .log-entry {
    grid-template-columns: 1fr;
  }
}
