:root {
  color-scheme: light;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --danger: #b91c1c;
  --warning: #b45309;
  --border: #d6dce5;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  background: linear-gradient(90deg, #0f766e, #115e59);
  color: #fff;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 1.1rem;
  font-weight: 700;
}

.container {
  max-width: 1500px;
  margin: 1.5rem auto;
  padding: 0 1rem 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

.card h1,
.card h2,
.card h3 {
  margin-top: 0;
}

.narrow {
  max-width: 460px;
  margin: 4rem auto 0;
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

label {
  display: block;
  margin-top: 0.8rem;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.9rem;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

.button.ghost {
  margin-top: 0;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.7);
}

.button.warning {
  background: var(--warning);
}

.messages {
  margin-bottom: 1rem;
}

.message {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.5rem;
  background: #fff;
}

.message.error {
  border-color: #fecaca;
  background: #fee2e2;
}

.message.success {
  border-color: #bbf7d0;
  background: #dcfce7;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.badge {
  display: inline-flex;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge.online {
  background: #dcfce7;
  color: #14532d;
}

.badge.offline {
  background: #fee2e2;
  color: #7f1d1d;
}

.list {
  display: grid;
  gap: 0.55rem;
}

.list-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem;
  background: #fff;
}

.inline-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.qr {
  width: 220px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 0.35rem;
}

.code,
code,
pre {
  font-family: Consolas, "Courier New", monospace;
}

.code {
  display: block;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  margin-bottom: 0.6rem;
}

pre {
  margin: 0.3rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.meta-row {
  margin: 0.35rem 0;
}

.hint {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.quick-command-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.quick-command-grid form,
.quick-form,
.manual-command-form {
  margin: 0;
}

.quick-form {
  margin-top: 0.55rem;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.form-row select {
  width: auto;
  min-width: 130px;
  flex: 1 1 0;
}

.form-row .button {
  margin-top: 0;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.55rem;
}

.telemetry-grid.compact {
  margin-top: 0.55rem;
}

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: #fbfdff;
}

.metric-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
}

.metric-value {
  font-weight: 700;
}

.telemetry-item summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: flex-start;
}

.summary-line {
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.extra-fields {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.25rem;
  font-size: 0.92rem;
}

.raw-json {
  margin-top: 0.55rem;
}

.controller-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.controller-header-top .link-button {
  margin-top: 0;
}

.controller-summary-grid {
  margin-top: 0.6rem;
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-tile {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem;
  background: #fbfdff;
}

.summary-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.summary-value {
  margin-top: 0.15rem;
  font-weight: 700;
  word-break: break-word;
}

.controller-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  align-items: start;
}

.stack {
  display: grid;
  gap: 1rem;
}

.section-subtitle {
  margin: 0.9rem 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.command-history .list-item {
  padding: 0.65rem;
}

.quick-command-grid .button {
  margin-top: 0;
  width: 100%;
}

.command-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.18rem 0.48rem;
  border: 1px solid var(--border);
  background: #f8fafc;
  text-transform: uppercase;
}

.status-pill.acked {
  background: #dcfce7;
  border-color: #86efac;
  color: #14532d;
}

.status-pill.failed {
  background: #fee2e2;
  border-color: #fecaca;
  color: #7f1d1d;
}

.status-pill.pending,
.status-pill.sent {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.command-time {
  color: var(--muted);
  font-size: 0.82rem;
}

.result-label {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.command-history code {
  display: block;
  margin-top: 0.15rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.command-result {
  margin-top: 0.25rem;
  max-height: 210px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 0.45rem 0.5rem;
}

@media (max-width: 1160px) {
  .controller-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .telemetry-item summary {
    display: block;
  }

  .summary-line {
    display: block;
    margin-top: 0.2rem;
    text-align: left;
  }

  .form-row select {
    width: 100%;
    min-width: 0;
  }
}
