:root {
  color-scheme: dark;
  --bg: #08090b;
  --panel: #111419;
  --panel-2: #171b21;
  --line: #2a3038;
  --text: #f5f7f9;
  --muted: #9aa5b1;
  --green: #6df134;
  --cyan: #54c7ec;
  --amber: #ffbd4a;
  --red: #ff5d6c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

input[type="checkbox"] {
  accent-color: var(--green);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: #0b0d10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  background: transparent;
}

.brand-logo {
  display: block;
  width: 132px;
  height: 48px;
  object-fit: contain;
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 0 0 auto;
}

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

h1 {
  font-size: 22px;
  line-height: 1.15;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
}

.subtle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.workspace {
  min-height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(520px, 1fr);
  grid-template-areas: "models devices";
  gap: 12px;
  padding: 12px;
  align-items: stretch;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.device-panel,
.model-panel {
  min-height: 0;
  height: 100%;
}

.model-panel {
  grid-area: models;
  display: flex;
  flex-direction: column;
}

.device-panel {
  grid-area: devices;
  display: flex;
  flex-direction: column;
}

.content-view {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.content-view[hidden] {
  display: none;
}

.panel-title {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.pill {
  min-width: 30px;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.control {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0e12;
  color: var(--text);
  padding: 9px 10px;
}

.state-line,
.form-message {
  min-height: 22px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.device-table-wrap {
  flex: 1 1 260px;
  min-height: 260px;
  overflow: auto;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0e12;
}

.device-table {
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
  color: var(--text);
  font-size: 13px;
}

.device-table th,
.device-table td {
  height: 36px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.device-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #171b21;
  color: #c9d2dc;
  font-size: 12px;
  font-weight: 700;
}

.device-table th.check-cell,
.device-table td.check-cell {
  width: 46px;
  text-align: center;
}

.device-table th:nth-child(1),
.device-table td:nth-child(1) {
  text-align: center;
}

.device-table th:nth-child(2),
.device-table td:nth-child(2) {
  width: 64px;
  text-align: center;
}

.device-table th:nth-child(3),
.device-table td:nth-child(3) {
  width: 190px;
}

.device-table th:nth-child(5),
.device-table td:nth-child(5) {
  width: 132px;
}

.device-table tbody tr {
  cursor: pointer;
}

.device-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, .025);
}

.device-table tbody tr:hover,
.device-table tbody tr.active {
  background: rgba(109, 241, 52, .1);
}

.device-table tbody tr.active td:first-child {
  box-shadow: inset 3px 0 0 var(--green);
}

.device-table .empty-row {
  cursor: default;
}

.device-table .empty-row td {
  height: 156px;
  color: var(--muted);
  text-align: center;
}

.status-badge {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #10151b;
  font-size: 12px;
}

.status-badge.recovery,
.status-badge.device {
  border-color: rgba(109, 241, 52, .45);
  color: var(--green);
}

.status-badge.warning {
  border-color: rgba(255, 189, 74, .5);
  color: var(--amber);
}

.model-list {
  flex: 1 1 auto;
  align-content: start;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.model-card {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.model-card.active {
  border-color: var(--green);
  box-shadow: inset 3px 0 0 var(--green);
}

.model-name {
  font-weight: 700;
}

.model-code {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.model-count {
  color: var(--cyan);
  font-size: 12px;
}

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

.device-install-form {
  margin-top: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.option-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.option-grid label {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0e12;
}

.primary-button,
.ghost-button,
.load-device-button,
.help-button,
.guide-button,
.policy-button,
.nav-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.primary-button {
  grid-column: 1 / -1;
  background: var(--green);
  color: #071006;
  font-weight: 800;
}

.primary-button:disabled,
.ghost-button:disabled,
.load-device-button:disabled {
  opacity: .55;
  cursor: wait;
}

.ghost-button {
  min-width: 96px;
  padding: 0 14px;
  color: var(--text);
  background: #10151b;
  border-color: var(--line);
}

.load-device-button {
  min-width: 132px;
  min-height: 32px;
  padding: 0 12px;
  color: var(--text);
  background: #10151b;
  border-color: var(--line);
  font-size: 13px;
  font-weight: 700;
}

.help-button {
  min-width: 78px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: var(--text);
  background: #10151b;
  border-color: var(--line);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.guide-button {
  min-width: 150px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--text);
  background: #10151b;
  border-color: var(--line);
  font-size: 13px;
  font-weight: 700;
}

.policy-button {
  min-width: 260px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--text);
  background: #10151b;
  border-color: var(--line);
  font-size: 13px;
  font-weight: 700;
}

.policy-button.active,
.guide-button.active {
  border-color: var(--green);
  color: var(--green);
}

.form-message {
  grid-column: 1 / -1;
}

.form-message.error {
  color: var(--red);
}

.form-message.ok {
  color: var(--green);
}

.policy-content,
.guide-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.policy-text {
  margin: 0;
  padding-right: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: #d9e0e7;
  font: 13px/1.65 Consolas, "Segoe UI", Arial, sans-serif;
}

.guide-content {
  display: grid;
  gap: 18px;
  padding-right: 4px;
}

.guide-section {
  display: grid;
  gap: 12px;
}

.guide-copy {
  color: #d9e0e7;
  font-size: 14px;
  line-height: 1.55;
}

.guide-copy h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.guide-copy ol {
  margin: 0 0 12px;
  padding-left: 22px;
}

.guide-copy li + li {
  margin-top: 4px;
}

.guide-note {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid rgba(255, 189, 74, .38);
  border-radius: 6px;
  color: #f3d7a6;
  background: rgba(255, 189, 74, .08);
}

.guide-note p {
  margin: 6px 0 0;
}

.guide-copy a {
  color: var(--cyan);
}

.guide-image-flow {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(8px, 1vw, 14px);
  overflow: auto;
  padding-bottom: 8px;
}

.guide-image-flow-short {
  max-width: 520px;
}

.guide-shot {
  flex: 1 1 0;
  min-width: 116px;
  max-width: 220px;
  margin: 0;
}

.guide-shot img {
  display: block;
  width: 100%;
  aspect-ratio: 1440 / 2960;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050607;
}

.guide-arrow {
  flex: 0 0 auto;
  color: var(--green);
  font-size: clamp(24px, 2vw, 34px);
  line-height: 1;
  font-weight: 800;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "models"
      "devices";
  }

  .option-grid,
  .install-form {
    grid-template-columns: 1fr;
  }

  .guide-shot {
    min-width: 132px;
  }
}

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

  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .brand-logo {
    width: 112px;
    height: 42px;
  }

  h1 {
    font-size: 19px;
  }

  .ghost-button {
    width: 100%;
  }

  .policy-button {
    width: 100%;
  }

  .guide-button {
    width: 100%;
  }

  .help-button {
    width: 88px;
  }
}
