/* Arcana Lab — Unified Projects, Smart Router, Specialized Agents, Repurpose & Workflows */
#labWorkspace {
  position: fixed;
  inset: 0;
  height: 100dvh;
  z-index: 4100;
  display: flex;
  flex-direction: column;
  background: #090a0f;
  color: #f3f4f6;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
  box-sizing: border-box;
}
#labWorkspace *,
#labWorkspace *::before,
#labWorkspace *::after {
  box-sizing: border-box;
}
#labWorkspace.lab-hidden {
  display: none !important;
}
body.arcana-lab-active > .main,
body.arcana-lab-active > .sidebar {
  display: none !important;
}

.lab-topbar {
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 58px 0 12px;
  background: #11131a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.lab-top-left,
.lab-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.lab-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.25), rgba(0, 212, 255, 0.2));
  border: 1px solid rgba(124, 92, 255, 0.45);
  color: #ddd6fe;
  white-space: nowrap;
}
.lab-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: #f3f4f6;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.lab-btn:hover { background: rgba(255, 255, 255, 0.11); }
.lab-btn.primary {
  border: none;
  background: linear-gradient(135deg, #7c5cff, #4f46e5);
  color: #fff;
}
.lab-btn.cyan {
  border-color: rgba(0, 212, 255, 0.45);
  background: rgba(0, 212, 255, 0.14);
  color: #67e8f9;
}
.lab-btn.danger {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.12);
  color: #fca5a5;
}
.lab-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.lab-select,
.lab-input,
.lab-textarea {
  background: #0b0d14;
  color: #f3f4f6;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 14px;
  line-height: 1.45;
  font-family: inherit;
  outline: none;
  max-width: 100%;
}
.lab-select:focus,
.lab-input:focus,
.lab-textarea:focus {
  border-color: #00d4ff;
}

.lab-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: #0e1017;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  overflow-x: auto;
  flex-shrink: 0;
}
.lab-tab {
  padding: 8px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #9ca3af;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.lab-tab.active {
  background: rgba(124, 92, 255, 0.18);
  border-color: rgba(124, 92, 255, 0.45);
  color: #ffffff;
}
.lab-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
}

.lab-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.lab-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
}
.lab-card {
  background: #131620;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lab-card-title {
  font-size: 15px;
  font-weight: 700;
  color: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.lab-sub {
  font-size: 13.5px;
  color: #b4bcc8;
  line-height: 1.5;
  overflow-wrap: break-word;
}
.lab-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
  line-height: 1.45;
  min-width: 0;
}
.lab-form-row-mem {
  display: grid;
  grid-template-columns: 1fr 1.6fr auto;
  gap: 8px;
  align-items: center;
}
.lab-form-row-rep {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
}
.lab-form-row-wf {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.lab-wf-run-row {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.lab-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.lab-pre {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #080a10;
  border: 1px solid rgba(255, 255, 255, 0.09);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: #edf0f5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow-y: auto;
  line-height: 1.6;
}
.lab-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 5000;
  background: #1f2433;
  color: #fff;
  border: 1px solid rgba(0, 212, 255, 0.45);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  display: none;
  max-width: calc(100vw - 24px);
  text-align: center;
}
.lab-toast.show { display: block; }

@media (max-width: 768px) {
  .lab-topbar {
    height: auto;
    flex-wrap: wrap;
    align-items: center;
    padding: 8px;
    gap: 6px;
  }
  .lab-top-left {
    width: 100%;
    padding-right: 46px; /* preserves clean room for fixed #arcane-avatar-btn */
    gap: 6px;
  }
  .lab-top-right {
    width: 100%;
    gap: 6px;
  }
  .lab-top-left #labProjectSelect,
  .lab-top-right #labRouterPref {
    flex: 1 1 0;
    min-width: 0;
    max-width: none !important;
    min-height: 38px;
  }
  .lab-topbar .lab-btn {
    min-height: 38px;
    padding: 0 10px;
    font-size: 12.5px;
    flex-shrink: 0;
  }
  .lab-pill { display: none; }
  .lab-tabs { padding: 6px 8px; gap: 6px; }
  .lab-main { padding: 12px 10px calc(20px + env(safe-area-inset-bottom, 0px)); overflow-x: hidden; }
  .lab-grid-2 { grid-template-columns: 1fr; }
  .lab-form-row-mem,
  .lab-form-row-rep,
  .lab-form-row-wf {
    grid-template-columns: 1fr;
  }
  .lab-wf-run-row {
    flex-direction: column;
  }
  .lab-form-row-mem .lab-btn,
  .lab-form-row-rep .lab-btn,
  .lab-form-row-wf .lab-btn,
  .lab-wf-run-row .lab-btn,
  .lab-action-row .lab-btn,
  .lab-tab {
    min-height: 44px;
  }
  .lab-form-row-mem .lab-input,
  .lab-form-row-rep .lab-select,
  .lab-form-row-wf .lab-input,
  .lab-form-row-wf .lab-select,
  .lab-wf-run-row .lab-input {
    width: 100%;
    min-height: 44px;
  }
  .lab-item-row {
    flex-wrap: wrap;
  }
}
