:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #64706b;
  --line: #d9dfd7;
  --primary: #12665d;
  --primary-ink: #ffffff;
  --accent: #b98324;
  --danger: #b64232;
  --danger-bg: #fff2ef;
  --console: #111815;
  --console-ink: #d9f2e7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-kicker,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 6px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

h2 {
  margin-top: 4px;
  font-size: 21px;
  line-height: 1.2;
}

.top-actions,
.button-row,
.maintenance-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.build-badge,
.state-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.25fr);
  gap: 18px;
  padding: 18px clamp(18px, 4vw, 48px) 36px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.firmware-row,
.status-grid {
  display: grid;
  gap: 10px;
}

.firmware-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.firmware-row > div,
.status-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.label {
  display: block;
  margin-bottom: 6px;
}

strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.3;
}

.button,
.icon-button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 650;
}

.button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.text-button:hover:not(:disabled) {
  border-color: #aab5af;
  background: #f7faf8;
}

.button:active:not(:disabled),
.icon-button:active:not(:disabled),
.text-button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.primary:hover:not(:disabled) {
  border-color: #0d574f;
  background: #0d574f;
}

.danger {
  border-color: #e5b9b0;
  background: var(--danger-bg);
  color: var(--danger);
}

.install-button {
  width: 100%;
  margin-bottom: 16px;
}

.browser-warning {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid #e8cf89;
  border-radius: 8px;
  background: #fff9e8;
  color: #694b05;
}

.serial-help {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: #fff9e8;
  color: #694b05;
  font-size: 13px;
  line-height: 1.5;
}

.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.status-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 18px 0;
}

.wifi-form {
  display: grid;
  gap: 12px;
}

.agent-mode-field {
  margin: 0;
  border: 0;
  padding: 0;
}

.agent-mode-field legend {
  margin-bottom: 7px;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment {
  min-height: 40px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 0 14px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}

.segment:last-child {
  border-right: 0;
}

.segment.is-selected {
  background: var(--primary);
  color: var(--primary-ink);
}

.mode-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.wifi-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.wifi-form input,
.wifi-form select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover {
  background: #eef3ef;
  color: var(--ink);
}

.password-toggle svg {
  width: 18px;
  height: 18px;
}

.wifi-form input:focus,
.wifi-form select:focus {
  border-color: var(--primary);
  outline: 2px solid rgba(18, 102, 93, 0.18);
}

.advanced-panel,
.console-wrap {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.advanced-panel summary,
.console-wrap summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  background: #f7faf8;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.advanced-panel[open] summary,
.console-wrap[open] summary {
  border-bottom: 1px solid var(--line);
}

.advanced-body {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.maintenance-row {
  align-items: stretch;
}

.console-tools {
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px;
  background: #f7faf8;
  border-bottom: 1px solid var(--line);
}

.text-button {
  min-height: 28px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 13px;
}

pre {
  margin: 0;
  min-height: 180px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  background: var(--console);
  color: var(--console-ink);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.line-tx {
  color: #9dd6ff;
}

.line-rx {
  color: #aae6bd;
}

.line-error {
  color: #ffb2a4;
}

@media (max-width: 880px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace,
  .firmware-row,
  .status-grid {
    grid-template-columns: 1fr;
  }
}
