:root {
  color-scheme: light;
  --page: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #62706a;
  --line: #d9e3df;
  --brand: #0f684f;
  --brand-strong: #0a513d;
  --brand-soft: #e4f2ed;
  --warn: #9d650f;
  --warn-soft: #fff1d6;
  --danger: #a33a2c;
  --danger-soft: #fde8e3;
  --good: #126146;
  --good-soft: #e2f2eb;
  --neutral: #66736d;
  --neutral-soft: #edf2ef;
  --shadow: 0 14px 36px rgba(20, 35, 28, 0.08);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans SC",
    sans-serif;
  line-height: 1.5;
  font-weight: 400;
  color: var(--ink);
  background: linear-gradient(180deg, #f7f9f8 0%, #eef3f1 100%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
}

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

button {
  appearance: none;
}

a {
  color: inherit;
}

#app {
  min-height: 100vh;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

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

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 1.12rem;
  letter-spacing: 0;
}

.brand p {
  color: var(--muted);
  font-size: 0.86rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--brand);
  color: white;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-link {
  position: relative;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.94rem;
  transition: 140ms ease;
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--ink);
  background: var(--brand-soft);
}

.nav-link.is-active::before {
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 3px;
  border-radius: 999px;
  background: var(--brand);
  content: "";
}

.app-content {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px 14px;
  border-bottom: 1px solid rgba(217, 227, 223, 0.72);
  background: rgba(245, 247, 246, 0.74);
  backdrop-filter: blur(10px);
}

.topbar h2,
.topbar p {
  margin: 0;
}

.topbar h2 {
  font-size: 1.35rem;
  line-height: 1.25;
}

.page-body {
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 24px 32px 40px;
}

.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
}

.page-grid {
  display: grid;
  gap: 20px;
}

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

.nested-panel {
  padding: 18px;
  background: var(--surface-muted);
  box-shadow: none;
}

.panel.nested-panel {
  border-color: rgba(217, 227, 223, 0.86);
}

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

.panel-heading.compact {
  align-items: center;
  margin-bottom: 14px;
}

.panel-heading h3,
.panel-heading h4 {
  margin: 4px 0 0;
}

.panel-heading h3 {
  font-size: 1.24rem;
  line-height: 1.25;
}

.panel-heading h4 {
  font-size: 1rem;
  line-height: 1.3;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: 140ms ease;
  font-size: 0.92rem;
  font-weight: 600;
}

.primary-button,
.ghost-button,
.danger-button {
  padding: 9px 14px;
}

.primary-button {
  background: var(--brand);
  color: white;
}

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

.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.ghost-button:hover {
  border-color: #bfd0c9;
  background: var(--surface-muted);
}

.compact-button {
  min-height: 34px;
  padding: 7px 11px;
  white-space: nowrap;
}

.danger-button {
  background: var(--danger);
  color: white;
}

.danger-button:hover {
  background: #8c2e21;
}

.inline-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.inline-link.danger-link {
  color: var(--danger);
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled,
.inline-link:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.primary-button:focus-visible,
.ghost-button:focus-visible,
.danger-button:focus-visible,
.inline-link:focus-visible,
.nav-link:focus-visible {
  outline: 3px solid rgba(15, 104, 79, 0.18);
  outline-offset: 2px;
}

.stats-grid,
.split-grid,
.toolbar-grid,
.form-grid {
  display: grid;
  gap: 16px;
}

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

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

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

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

.form-grid.three-columns {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-section + .form-section,
.danger-zone {
  margin-top: 18px;
}

.form-section {
  padding: 18px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid rgba(217, 227, 223, 0.9);
}

.form-section h4,
.danger-zone h4 {
  margin-top: 0;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(217, 227, 223, 0.9);
  font-size: 1rem;
}

.form-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(217, 227, 223, 0.9);
}

.form-section-header h4 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: 1.05rem;
}

.form-section-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 0.92rem;
  flex-shrink: 0;
}

.form-section-icon.serial {
  background: var(--brand-soft);
  color: var(--brand);
}

.form-section-icon.power {
  background: var(--warn-soft);
  color: var(--warn);
}

.form-section-icon.boot {
  background: #ebe9fb;
  color: #4f43a0;
}

.form-section-icon.info {
  background: var(--brand-soft);
  color: var(--brand);
}

.field,
.checkbox-field {
  display: grid;
  gap: 8px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid rgba(217, 227, 223, 0.95);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.92rem;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

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

.inline-form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.action-field {
  align-self: end;
}

.table-form-stack {
  display: grid;
  gap: 10px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 28, 0.42);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.modal-card {
  width: min(720px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(20, 35, 28, 0.18);
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.dtb-config-grid {
  align-items: stretch;
}

.dtb-selection-panel,
.dtb-action-panel {
  display: grid;
  gap: 14px;
}

.dtb-selection-panel {
  background: var(--surface);
}

.dtb-action-panel {
  align-content: space-between;
  background: var(--brand-soft);
}

.selection-caption {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-muted);
  word-break: break-word;
}

.field span {
  color: var(--muted);
  font-size: 0.92rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #cdd9d4;
  background: var(--surface);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(15, 104, 79, 0.55);
  box-shadow: 0 0 0 3px rgba(15, 104, 79, 0.1);
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid rgba(217, 227, 223, 0.95);
  cursor: pointer;
  transition: background 140ms ease;
}

.toggle-field:hover {
  background: #fbfcfc;
}

.toggle-switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--neutral-soft);
  pointer-events: none;
  transition: background 200ms ease;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--brand);
}

.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  transition: transform 200ms ease;
}

.toggle-switch input:checked ~ .toggle-knob {
  transform: translateX(18px);
}

.toggle-label {
  font-size: 0.92rem;
}

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

.radio-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.panel:has(> .data-table),
.nested-panel:has(.data-table) {
  overflow-x: auto;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(217, 227, 223, 0.95);
  text-align: left;
  vertical-align: top;
  font-size: 0.9rem;
  word-break: break-word;
}

.data-table th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-muted);
}

.data-table code {
  word-break: break-all;
}

/* Board card grid */
.board-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.board-card {
  position: relative;
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: box-shadow 160ms ease, border-color 160ms ease;
}

.board-card:hover {
  border-color: rgba(15, 104, 79, 0.28);
  box-shadow: 0 10px 28px rgba(20, 35, 28, 0.08);
}

.board-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.board-card-id {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.board-card-id code {
  font-size: 1.05rem;
  font-weight: 600;
  line-break: anywhere;
}

.board-card-type {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

.board-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--brand-soft);
  color: var(--brand);
}

.board-card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 0.88rem;
}

.board-card-meta-item {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.board-card-meta-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.board-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid rgba(217, 227, 223, 0.95);
}

.board-card-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 6px;
}

.board-card-status-dot[data-tone="good"] {
  background: var(--good);
  box-shadow: 0 0 6px rgba(22, 97, 75, 0.35);
}

.board-card-status-dot[data-tone="warn"] {
  background: var(--warn);
  box-shadow: 0 0 6px rgba(185, 115, 22, 0.35);
}

.board-card-status-dot[data-tone="neutral"] {
  background: var(--neutral);
}

.board-card-serial-mini {
  display: grid;
  gap: 2px;
}

.board-card-serial-mini .serial-key-badge {
  width: fit-content;
}

.stat-card {
  min-width: 0;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid rgba(217, 227, 223, 0.95);
}

.stat-card strong {
  display: block;
  font-size: 1.8rem;
  margin-top: 6px;
  line-height: 1.1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.key-value-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.key-value-list div {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid rgba(217, 227, 223, 0.95);
  border-radius: 8px;
  background: var(--surface);
}

.key-value-list dt {
  color: var(--muted);
  font-size: 0.88rem;
}

.key-value-list dd {
  margin: 0;
  line-break: anywhere;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.status-pill[data-tone="good"] {
  color: var(--good);
  background: var(--good-soft);
}

.status-pill[data-tone="warn"] {
  color: var(--warn);
  background: var(--warn-soft);
}

.status-pill[data-tone="danger"] {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-pill[data-tone="neutral"] {
  color: var(--neutral);
  background: var(--neutral-soft);
}

.serial-key-card {
  display: grid;
  gap: 4px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--brand-soft);
  border: 1px solid rgba(15, 104, 79, 0.16);
}

.serial-key-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  font-weight: 700;
}

.serial-key-badge.neutral {
  color: var(--neutral);
  background: var(--neutral-soft);
}

.serial-key-card strong,
.serial-summary strong {
  font-size: 0.98rem;
  line-break: anywhere;
}

.serial-key-secondary {
  color: var(--muted);
  font-size: 0.84rem;
  line-break: anywhere;
}

.serial-key-secondary.unresolved {
  color: var(--warn);
}

.serial-summary {
  display: grid;
  gap: 4px;
}

.serial-baud {
  color: var(--muted);
  font-size: 0.82rem;
}

.notice {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 0.96rem;
}

.notice[data-tone="success"] {
  color: var(--good);
  background: var(--good-soft);
}

.notice[data-tone="error"] {
  color: var(--danger);
  background: var(--danger-soft);
}

.diagnostic-error {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--danger);
  background: rgba(163, 58, 44, 0.08);
  white-space: pre-wrap;
}

.field-hint {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  line-break: anywhere;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-break: anywhere;
}

.empty-state {
  padding: 32px 22px;
  border: 1px dashed #cbd8d3;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.empty-state-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.5;
}

.danger-zone {
  padding: 18px;
  margin-top: 28px;
  border-radius: 8px;
  border: 1px dashed rgba(163, 58, 44, 0.3);
  background: rgba(163, 58, 44, 0.03);
}

code {
  padding: 0.14rem 0.35rem;
  border-radius: 6px;
  background: rgba(23, 32, 28, 0.08);
}

@media (max-width: 1100px) {
  .stats-grid,
  .split-grid,
  .toolbar-grid,
  .form-grid.two-columns,
  .form-grid.three-columns,
  .inline-form-row {
    grid-template-columns: 1fr;
  }

  .board-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    margin-bottom: 12px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .nav-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-link {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .nav-link.is-active::before {
    display: none;
  }

  .page-body,
  .topbar {
    padding-left: 18px;
    padding-right: 18px;
  }

  .page-body {
    padding-top: 18px;
    padding-bottom: 28px;
  }
}

@media (max-width: 640px) {
  .panel,
  .form-section,
  .modal-card {
    padding: 16px;
  }

  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-heading.compact {
    align-items: stretch;
  }

  .toolbar-actions {
    justify-content: flex-start;
  }

  .inline-field-group,
  .radio-group {
    grid-template-columns: 1fr;
  }

  .board-card-meta {
    grid-template-columns: 1fr;
  }
}
