* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #0f1419;
  color: #e7ecf1;
}
.hidden { display: none !important; }
.page { min-height: 100vh; }
.muted { color: #8b98a5; }
.error { color: #f4212e; min-height: 20px; }
.hint { margin: 0 0 12px; font-size: 13px; }

.login-card {
  max-width: 380px;
  margin: 12vh auto;
  padding: 32px;
}
.card {
  background: #16202a;
  border: 1px solid #2f3b47;
  border-radius: 16px;
}
input, select, button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid #2f3b47;
  padding: 10px 12px;
  background: #0f1419;
  color: #e7ecf1;
}
input, select { width: 100%; margin-top: 10px; }
button {
  cursor: pointer;
  margin-top: 12px;
}
button.primary { background: #6750a4; border-color: #6750a4; color: #fff; }
button.ghost { background: transparent; margin-top: 0; }
button.warn { background: #ed6c02; border-color: #ed6c02; color: #fff; margin-top: 0; }
button.danger { background: #d32f2f; border-color: #d32f2f; color: #fff; margin-top: 0; }

/* App shell: sidebar + main */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #121a22;
  border-right: 1px solid #2f3b47;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid #2f3b47;
  font-weight: 600;
  font-size: 17px;
}
.brand-icon { font-size: 22px; }
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 4px;
}
.nav-item {
  width: 100%;
  text-align: left;
  margin-top: 0;
  padding: 12px 14px;
  border: 1px solid transparent;
  background: transparent;
  color: #b8c5d0;
  border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover {
  background: #1c2430;
  color: #e7ecf1;
}
.nav-item.active {
  background: #2a3544;
  border-color: #6750a4;
  color: #fff;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid #2f3b47;
  background: #16202a;
  flex-shrink: 0;
}
.topbar h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-name {
  color: #8b98a5;
  font-size: 14px;
  margin-right: 4px;
}

.content {
  flex: 1;
  padding: 20px 24px;
  overflow: auto;
}
.view-panel { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: #16202a;
  border: 1px solid #2f3b47;
  border-radius: 16px;
  padding: 16px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Devices layout */
.devices-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}
.devices-list-panel { min-height: 400px; }
.devices-detail-panel.empty-detail {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
}
.device-list { display: flex; flex-direction: column; gap: 8px; }
.device-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.device-item .btn-del-device {
  padding: 4px 10px;
  font-size: 12px;
  flex-shrink: 0;
}
.device-item {
  padding: 12px;
  border: 1px solid #2f3b47;
  border-radius: 12px;
  cursor: pointer;
}
.device-item.active { border-color: #6750a4; background: #1c2430; }
.device-item .meta { color: #8b98a5; font-size: 13px; margin-top: 4px; }

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.badge.online { background: #1b5e20; }
.badge.offline { background: #424242; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 120px auto;
  gap: 8px;
  margin-bottom: 16px;
}
.form-row input, .form-row select, .form-row button { margin-top: 0; width: auto; }
.form-row button.primary { width: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  border-bottom: 1px solid #2f3b47;
  padding: 10px 8px;
  text-align: left;
  font-size: 14px;
}

.cmd-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.cmd-bar button, .cmd-bar input { margin-top: 0; width: auto; }

.workflow-run-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #2d3748;
  border-radius: 8px;
  background: #151b24;
}
.workflow-run-bar-editor { margin-top: 8px; margin-bottom: 16px; }
.workflow-run-label { font-size: 13px; color: #a0aec0; margin: 0; }
.workflow-run-status { font-size: 12px; margin-left: 4px; }
.workflow-run-status.running { color: #90caf9; }
.workflow-run-status.done { color: #81c784; }
.workflow-run-status.failed { color: #ef9a9a; }
.workflow-run-status.cancelled { color: #ffb74d; }

.screenshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.screenshot-grid img {
  width: 100%;
  max-width: 360px;
  border-radius: 10px;
  border: 1px solid #2f3b47;
  background: #000;
}

/* Workflow */
.workflow-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  align-items: start;
}
.workflow-list-panel { min-height: 420px; }
.workflow-list { display: flex; flex-direction: column; gap: 8px; }
.workflow-item {
  padding: 12px;
  border: 1px solid #2f3b47;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.workflow-item:hover { border-color: #4a5568; }
.workflow-item.active { border-color: #6750a4; background: #1c2430; }
.workflow-item .wf-item-name { font-weight: 600; font-size: 14px; }
.workflow-item .wf-item-meta { font-size: 12px; color: #8b98a5; margin-top: 4px; }
.workflow-item .wf-item-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 6px;
}
.workflow-item .wf-item-badge.on { background: #1b5e20; }
.workflow-item .wf-item-badge.off { background: #424242; }

.workflow-editor-panel { min-height: 420px; }
.center-msg { text-align: center; padding: 80px 20px; }
.wf-form label {
  display: block;
  font-size: 13px;
  color: #8b98a5;
  margin: 12px 0 4px;
}
.wf-form label:first-child { margin-top: 0; }
.settings-form label {
  display: block;
  font-size: 13px;
  color: #8b98a5;
  margin: 12px 0 4px;
}
.settings-panel { max-width: 560px; }
textarea {
  font: inherit;
  border-radius: 10px;
  border: 1px solid #2f3b47;
  padding: 10px 12px;
  background: #0f1419;
  color: #e7ecf1;
  width: 100%;
  resize: vertical;
}
.steps-head { margin-top: 20px; }
.steps-head h4 { margin: 0; font-size: 15px; }
.btn-sm {
  margin-top: 0 !important;
  padding: 6px 12px !important;
  font-size: 13px !important;
}
.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #b8c5d0;
  margin-top: 0;
}
.toggle-label input { width: auto; margin: 0; }

.workflow-steps { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.workflow-step {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid #2f3b47;
  border-radius: 12px;
  background: #1a232e;
}
.step-order {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #6750a4;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.step-body { min-width: 0; }
.step-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.step-meta { font-size: 12px; color: #8b98a5; line-height: 1.5; }
.step-condition {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #2a3544;
  color: #9ab0c4;
  margin-top: 6px;
}
.step-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.step-actions button { padding: 4px 8px !important; font-size: 12px !important; }

.step-payload-fields { margin: 8px 0; }
.step-payload-fields label { font-size: 13px; color: #8b98a5; margin: 8px 0 4px; display: block; }
.modal-card-wide { width: min(480px, 94vw); }

/* Password modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal-card {
  position: relative;
  width: min(400px, 92vw);
  padding: 20px;
  z-index: 1;
}
.modal-card .panel-head { margin-bottom: 8px; }
.modal-card button.primary { width: 100%; margin-top: 8px; }
.login-card button.primary { width: 100%; }

.vision-log-table td { vertical-align: middle; font-size: 13px; }

.ai-log-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.ai-log-tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1a222c;
  color: #8b98a5;
  cursor: pointer;
  font-size: 13px;
}
.ai-log-tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.ai-log-tab:hover:not(.active) {
  border-color: #475569;
  color: #e7ecf1;
}

.vision-log-thumb {
  width: 48px;
  height: 86px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #2f3b47;
  background: #0f1419;
  display: block;
  cursor: pointer;
}
.vision-log-thumb-placeholder {
  width: 48px;
  height: 86px;
  border-radius: 4px;
  border: 1px dashed #2f3b47;
  background: #0f1419;
  color: #6b7c8f;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
}
.vision-log-image-wrap { margin-bottom: 12px; }
.vision-log-image {
  display: block;
  max-width: 100%;
  max-height: 420px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid #2f3b47;
  background: #0f1419;
}
.vision-log-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}
.vision-log-modal-card { width: min(720px, 96vw); max-height: 90vh; overflow: auto; }
.vision-log-meta { margin-bottom: 12px; font-size: 13px; line-height: 1.6; }
.vision-log-pre {
  background: #0f1419;
  border: 1px solid #2f3b47;
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  margin: 4px 0 12px;
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #2f3b47;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .devices-layout { grid-template-columns: 1fr; }
  .workflow-layout { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .workflow-step { grid-template-columns: 1fr; }
  .step-order { width: 28px; height: 28px; }
}

.toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.toast {
  background: rgba(22, 32, 42, 0.94);
  color: #e7ecf1;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.2s ease;
}
.toast.error {
  background: rgba(180, 40, 40, 0.94);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Embedded device console (wormhole) — scoped, do not load console.css globally */
#view-devices.view-panel {
  padding: 0;
  overflow: hidden;
}
#view-devices .device-console-layout.layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 320px;
  gap: 16px;
  min-height: calc(100vh - 120px);
  padding: 12px 16px 16px;
}
#view-devices .phone-panel {
  display: flex;
  flex-direction: column;
  background: #141b24;
  border: 1px solid #243041;
  border-radius: 12px;
  padding: 12px;
  min-width: 0;
}
#view-devices .phone-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
#view-devices .phone-toolbar button {
  width: 36px;
  height: 36px;
  margin-top: 0;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1c2430;
  color: #fff;
  cursor: pointer;
  padding: 0;
}
#view-devices .phone-toolbar button:hover {
  background: #263040;
}
#view-devices .phone-toolbar .meta {
  font-size: 12px;
  color: #8b98a5;
  margin-left: auto;
  white-space: nowrap;
}
#view-devices .tap-calib-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #151b24;
  font-size: 12px;
  color: #cbd5e1;
}
#view-devices .tap-calib-panel.hidden {
  display: none;
}
#view-devices .tap-calib-panel label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
#view-devices .tap-calib-panel input[type="range"] {
  width: 110px;
}
#view-devices .tap-calib-title {
  font-weight: 600;
  color: #94a3b8;
}
#view-devices .phone-frame {
  position: relative;
  background: #000;
  border-radius: 16px;
  flex: 1 1 auto;
  height: min(58vh, 640px);
  min-height: 360px;
  max-height: 640px;
  overflow: hidden;
  border: 2px solid #2a3441;
}
#view-devices #screen-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 14px;
  text-align: center;
  padding: 20px;
  pointer-events: none;
}
#view-devices .screen-idle-overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(0, 0, 0, 0.88);
  color: #e2e8f0;
  font-size: 15px;
  text-align: center;
  padding: 24px;
}
#view-devices .screen-idle-overlay.hidden {
  display: none;
}
#view-devices .screen-idle-overlay p {
  margin: 0;
  line-height: 1.5;
}
#view-devices .phone-screen-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
#view-devices .phone-screen-wrap.hidden {
  display: none;
}
#view-devices #screen-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  cursor: crosshair;
  user-select: none;
}
#view-devices #screen-tap-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#view-devices .phone-log-panel {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 auto;
}
#view-devices .phone-log-title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: #8b98a5;
}
#view-devices .console-log {
  margin: 0;
  flex: 1;
  min-height: 140px;
  max-height: calc(100vh - 52vh - 220px);
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  color: #b0bec5;
  background: #0a0e13;
  padding: 10px;
  border-radius: 8px;
  scrollbar-gutter: stable;
  white-space: pre-wrap;
  word-break: break-all;
}
#view-devices .side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
  max-width: 360px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}
#view-devices .panel-block {
  background: #141b24;
  border: 1px solid #243041;
  border-radius: 12px;
  padding: 14px;
}
#view-devices .bridge-panel {
  flex-shrink: 0;
}
#view-devices .panel-block h2 {
  margin: 0 0 10px;
  font-size: 15px;
}
#view-devices .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#view-devices .panel-head h2 {
  margin: 0;
}
#view-devices .icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 30px;
  text-align: center;
  font-size: 16px;
}
#view-devices .icon-btn.spinning {
  animation: spin 0.8s linear infinite;
  pointer-events: none;
  opacity: 0.6;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
#view-devices .bridge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
  max-height: 320px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}
#view-devices .bridge-item {
  position: relative;
  padding: 10px 30px 10px 28px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1c2430;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
#view-devices .bridge-item:hover {
  border-color: #4a5568;
  background: #222b38;
}
#view-devices .bridge-item.active {
  border-color: #6750a4;
  background: #252038;
  box-shadow: inset 3px 0 0 #6750a4;
}
#view-devices .bridge-item .title {
  font-weight: 600;
  font-size: 14px;
  word-break: break-all;
}
#view-devices .bridge-item .sub {
  font-size: 12px;
  color: #8b98a5;
  margin-top: 4px;
}
#view-devices .bridge-item .status-dot {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
}
#view-devices .bridge-item.has-viewer .status-dot {
  background: #29b6f6;
}
#view-devices .bridge-item .bridge-edit-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  border: none;
  background: transparent;
  color: #8b98a5;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}
#view-devices .bridge-item .bridge-edit-btn:hover {
  color: #e2e8f0;
}
#view-devices .device-remark-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#view-devices .device-remark-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #1a2230;
}
#view-devices .device-remark-label {
  flex: 1;
  min-width: 0;
  word-break: break-all;
}
#view-devices .panel-actions {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #243041;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#view-devices .panel-actions .ghost,
#view-devices .panel-actions .primary,
#view-devices .panel-actions .danger {
  margin-top: 0;
  width: auto;
  flex: 0 1 auto;
}
#view-devices .agent-panel textarea,
#view-devices .agent-panel select,
#view-devices .agent-panel input {
  margin-top: 0;
}
#view-devices .ui-tree-panel {
  margin-top: 10px;
  border: 1px solid #243041;
  border-radius: 8px;
  background: #0a0e13;
  overflow: hidden;
}
#view-devices .ui-tree-head {
  padding: 8px 10px;
  font-size: 11px;
  border-bottom: 1px solid #243041;
}
#view-devices .ui-tree-body {
  margin: 0;
  padding: 8px 10px;
  max-height: 180px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.45;
  color: #b0bec5;
  white-space: pre-wrap;
  word-break: break-all;
}
#view-devices .conn-badge {
  margin-left: 8px;
  font-size: 11px;
}
@media (max-width: 900px) {
  #view-devices .device-console-layout.layout {
    grid-template-columns: 1fr;
  }
  #view-devices .side-panel {
    max-width: none;
  }
  #view-devices .phone-frame {
    height: 60vh;
    min-height: 360px;
  }
}
