:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-soft: #111827;
  --line: #334155;
  --line-soft: #243244;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --muted-strong: #64748b;
  --accent: #38bdf8;
  --accent-strong: #3b82f6;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 18px 40px rgba(2, 6, 23, 0.36);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

code {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

#app {
  min-height: 100vh;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card,
.card,
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(380px, 100%);
  border-radius: 12px;
  padding: 32px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 28px;
  color: var(--accent);
}

.auth-brand p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
  font-size: 14px;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin: 24px 0 18px;
}

.tab-btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  transition: 0.2s ease;
}

.tab-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

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

.field-label {
  font-size: 13px;
  color: var(--muted);
}

.field-input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.field-input:focus {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.16);
}

.btn {
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: 0.2s ease;
  padding: 7px 14px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  font-size: 14px;
}

.btn-primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
}

.btn-secondary {
  background: #334155;
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #3f4d63;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.auth-note {
  margin-top: 4px;
  padding: 12px;
  border-radius: 6px;
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.header-title h1 {
  margin: 0;
  font-size: 20px;
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-user {
  color: var(--muted);
  font-size: 13px;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

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

.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-header.with-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.control-code {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 4px;
  background: #334155;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  border: none;
  cursor: pointer;
}

.control-code:hover {
  background: #3f4d63;
}

.control-code-value {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.card-note {
  color: var(--muted-strong);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

.card-body {
  padding: 16px;
}

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

.detail-item {
  padding: 12px;
  border-radius: 6px;
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
}

.detail-label {
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted-strong);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.token-text {
  color: var(--accent);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.token-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  padding: 2px 8px;
  background: #334155;
  color: var(--text);
  font-size: 11px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.boundary-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 16px;
  align-items: stretch;
}

.viewer-placeholder {
  border-radius: 8px;
  border: 1px dashed #3b4b64;
  background: #0b1120;
  padding: 16px;
}

.viewer-shell {
  min-height: 200px;
  height: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #020617 0%, #0f172a 100%);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.viewer-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.viewer-copy strong {
  display: block;
  font-size: 18px;
}

.viewer-copy p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.viewer-footer {
  color: var(--muted-strong);
  font-size: 12px;
}

.control-state {
  display: grid;
  gap: 12px;
}

.table-card-body {
  padding: 0;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

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

.devices-table th,
.devices-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--panel);
  font-size: 13px;
  vertical-align: top;
}

.devices-table th {
  background: var(--bg);
  color: var(--muted-strong);
  font-weight: 600;
}

.devices-table tbody tr:hover {
  background: #253246;
}

.device-name-cell {
  display: grid;
  gap: 4px;
}

.device-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.device-actions .btn {
  min-width: 64px;
}

.cell-muted {
  font-size: 12px;
  color: var(--muted-strong);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.online {
  background: rgba(34, 197, 94, 0.14);
  color: #86efac;
}

.status-pill.offline {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
}

.status-pill.running {
  background: rgba(34, 197, 94, 0.14);
  color: #86efac;
}

.status-pill.paused {
  background: rgba(245, 158, 11, 0.16);
  color: #fcd34d;
}

.status-pill.stopped {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.empty-row {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  line-height: 1.7;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}

.modal {
  width: min(980px, 100%);
  border-radius: 12px;
  overflow: hidden;
}

.modal-header,
.modal-footer {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-subtitle,
.modal-footnote {
  color: var(--muted);
  font-size: 12px;
}

.modal-body {
  padding: 16px;
}

.modal-boundary .viewer-shell {
  min-height: 260px;
}

.preview-modal {
  width: min(1040px, calc(100vw - 32px));
  min-height: 560px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
}

.preview-toolbar {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
}

.preview-toolbar-device {
  min-width: 0;
}

.preview-toolbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.preview-toolbar-name {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.preview-action-btn {
  min-width: 72px;
}

.preview-close-wrap {
  display: flex;
  justify-content: flex-end;
}

.preview-close-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1f2937;
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.preview-close-button:hover {
  background: #334155;
}

.preview-display-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.preview-display-shell {
  flex: 1;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #020617 0%, #0f172a 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.preview-display-frame {
  border: 1px dashed #475569;
  border-radius: 12px;
  background: #111827;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(51, 65, 85, 0.32);
  max-width: 100%;
  max-height: 100%;
  flex: 0 0 auto;
}

.preview-display-frame.landscape {
}

.preview-display-frame.portrait {
}

.preview-display-frame.mobile.landscape {
}

.preview-display-frame.mobile.portrait {
}

.preview-display-surface {
  width: 100%;
  height: 100%;
  position: relative;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.08), transparent 36%),
    linear-gradient(180deg, #111827 0%, #0b1220 100%);
}

.preview-surface {
  cursor: default;
}

.preview-display-canvas,
.preview-frame-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
}

.preview-display-caption {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-display-summary {
  color: var(--text);
  font-weight: 600;
}

.preview-display-separator {
  color: var(--muted);
}

.preview-system-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toast-layer {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  pointer-events: none;
  width: min(460px, calc(100vw - 32px));
}

.toast {
  min-height: 40px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #243244;
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
}

.toast-success {
  color: #bbf7d0;
}

.toast-error {
  color: #fecaca;
}

.toast-info {
  color: #bae6fd;
}

@media (max-width: 1100px) {
  .panel-grid,
  .boundary-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .header {
    padding: 16px;
    flex-direction: column;
    align-items: flex-start;
  }

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

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

  .preview-modal {
    min-height: 0;
  }

  .preview-toolbar {
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .preview-toolbar-device {
    grid-column: 1 / -1;
  }

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

  .preview-display-shell {
    min-height: 300px;
  }

  .preview-system-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .auth-screen,
  .container,
  .modal-overlay {
    padding: 16px;
  }

  .auth-card {
    padding: 24px;
  }

  .card-header.with-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-modal {
    width: min(420px, calc(100vw - 20px));
    max-height: calc(100vh - 20px);
  }

  .preview-toolbar {
    padding: 14px;
  }

  .preview-toolbar-actions {
    gap: 6px;
  }

  .preview-display-section {
    padding: 14px;
  }

  .preview-display-shell {
    min-height: 240px;
    padding: 12px;
  }

  .preview-system-actions {
    gap: 6px;
  }
}

@media (orientation: portrait) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .stat-card {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 12px 8px;
  }

  .stat-card + .stat-card {
    border-left: 1px solid var(--line);
  }

  .stat-value {
    font-size: 28px;
  }

  .devices-table {
    min-width: 620px;
  }

  .devices-table th:nth-child(1),
  .devices-table td:nth-child(1) {
    min-width: 180px;
  }

  .devices-table th:nth-child(2),
  .devices-table td:nth-child(2) {
    min-width: 120px;
  }

  .devices-table th:nth-child(3),
  .devices-table td:nth-child(3) {
    min-width: 170px;
  }

  .devices-table th:nth-child(4),
  .devices-table td:nth-child(4) {
    min-width: 230px;
    white-space: nowrap;
  }
}

