/* =========================================================
   AI-GENCY DEVELOPER LAB — INTERACTIVE WORKSPACES
   Developer Lab AI + Application Playground
========================================================= */

.workbench-grid {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.workbench-card {
  min-height: 100%;
}

.workbench-card .workbench-card-action {
  margin-top: auto;
  cursor: pointer;
}

body.lab-modal-open {
  overflow: hidden;
}

.lab-modal-backdrop {
  position: fixed;
  z-index: 9997;
  inset: 0;
  background: rgba(0, 4, 14, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.lab-modal-backdrop[hidden],
.lab-modal[hidden],
.playground-code-input[hidden] {
  display: none !important;
}

.lab-modal {
  position: fixed;
  z-index: 9998;
  top: 50%;
  left: 50%;
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(76, 195, 255, 0.36);
  border-radius: 18px;
  color: var(--text);
  background:
    linear-gradient(165deg, rgba(5, 17, 43, 0.995), rgba(2, 8, 24, 0.995));
  box-shadow:
    0 32px 95px rgba(0, 0, 0, 0.7),
    0 0 38px rgba(76, 195, 255, 0.08);
  transform: translate(-50%, -50%);
}

.lab-chat-modal {
  width: min(760px, calc(100vw - 34px));
  height: min(760px, calc(100vh - 34px));
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.lab-playground-modal {
  width: min(1420px, calc(100vw - 28px));
  height: min(860px, calc(100vh - 28px));
  grid-template-rows: auto auto minmax(0, 1fr);
}

.lab-modal-header {
  min-height: 72px;
  padding: 13px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(76, 195, 255, 0.15);
  background: rgba(3, 11, 30, 0.72);
}

.lab-modal-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.lab-modal-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid rgba(76, 195, 255, 0.28);
  border-radius: 12px;
  background: rgba(76, 195, 255, 0.08);
}

.lab-modal-icon.chat {
  border-color: rgba(208, 35, 232, 0.3);
  color: var(--pink);
  background: rgba(208, 35, 232, 0.08);
}

.lab-modal-icon.playground {
  color: var(--cyan);
}

.lab-modal-icon svg {
  width: 21px;
  height: 21px;
}

.lab-modal-heading strong,
.lab-modal-heading small {
  display: block;
}

.lab-modal-heading strong {
  font-size: 0.82rem;
  font-weight: 850;
}

.lab-modal-heading small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.59rem;
}

.modal-status-dot {
  width: 6px;
  height: 6px;
  margin-right: 6px;
  display: inline-block;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px rgba(70, 230, 168, 0.68);
  vertical-align: 1px;
}

.modal-status-dot.error {
  background: #ff7592;
  box-shadow: 0 0 10px rgba(255, 117, 146, 0.58);
}

.lab-modal-close {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(122, 151, 196, 0.2);
  border-radius: 10px;
  color: #9dabc0;
  background: rgba(4, 12, 29, 0.64);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.lab-modal-close:hover {
  border-color: rgba(76, 195, 255, 0.4);
  color: #fff;
}

.lab-chat-messages {
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(76, 195, 255, 0.46) rgba(4, 13, 30, 0.82);
}

.lab-chat-message {
  width: fit-content;
  max-width: min(88%, 620px);
  margin-top: 12px;
  padding: 13px 15px;
  border: 1px solid rgba(76, 195, 255, 0.15);
  border-radius: 15px 15px 15px 5px;
  color: #d0daea;
  background: rgba(10, 29, 59, 0.82);
  font-size: 0.77rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.lab-chat-message:first-child {
  margin-top: 0;
}

.lab-chat-message.user {
  margin-left: auto;
  border-color: rgba(208, 35, 232, 0.23);
  border-radius: 15px 15px 5px 15px;
  color: #f3e9fa;
  background: rgba(105, 35, 143, 0.25);
}

.lab-chat-message.error {
  border-color: rgba(255, 117, 146, 0.27);
  color: #ffd0da;
  background: rgba(129, 29, 55, 0.18);
}

.lab-chat-message.loading {
  color: #95a6bc;
  animation: lab-chat-pulse 1.3s ease-in-out infinite;
}

.lab-chat-suggestions {
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  border-top: 1px solid rgba(76, 195, 255, 0.11);
}

.lab-chat-suggestions button {
  padding: 7px 10px;
  border: 1px solid rgba(208, 35, 232, 0.18);
  border-radius: 999px;
  color: #cdb7dc;
  background: rgba(83, 37, 111, 0.14);
  font-size: 0.56rem;
  cursor: pointer;
}

.lab-chat-suggestions button:hover {
  border-color: rgba(208, 35, 232, 0.42);
  color: #f1e0fb;
}

.lab-chat-composer {
  padding: 13px 16px 16px;
  border-top: 1px solid rgba(76, 195, 255, 0.13);
  background: rgba(3, 10, 26, 0.88);
}

.lab-chat-composer textarea {
  width: 100%;
  min-height: 90px;
  max-height: 210px;
  padding: 12px 13px;
  resize: vertical;
  border: 1px solid rgba(76, 195, 255, 0.23);
  border-radius: 12px;
  outline: 0;
  color: #f2f6fd;
  background: rgba(1, 7, 20, 0.76);
  font-size: 0.74rem;
  line-height: 1.55;
}

.lab-chat-composer textarea:focus {
  border-color: rgba(76, 195, 255, 0.52);
  box-shadow: 0 0 0 3px rgba(76, 195, 255, 0.07);
}

.lab-chat-composer-footer {
  margin-top: 9px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.lab-chat-clear,
.lab-chat-send {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 0.62rem;
  font-weight: 800;
  cursor: pointer;
}

.lab-chat-clear {
  border: 1px solid rgba(120, 148, 190, 0.18);
  color: #8998ad;
  background: transparent;
}

.lab-chat-clear:disabled,
.lab-chat-suggestions button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.lab-chat-send {
  min-width: 82px;
  border: 1px solid rgba(208, 35, 232, 0.38);
  color: #fff;
  background: linear-gradient(120deg, #b82bd0, #526be8);
}

.lab-chat-send:disabled {
  opacity: 0.58;
  cursor: wait;
}

.lab-chat-count {
  justify-self: end;
  color: #68778f;
  font-size: 0.55rem;
}

.lab-chat-spinner {
  width: 13px;
  height: 13px;
  display: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lab-spin 0.8s linear infinite;
}

.lab-chat-send.loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.lab-chat-send.loading .lab-chat-spinner {
  display: inline-block;
}

.playground-toolbar {
  min-height: 58px;
  padding: 9px 14px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(76, 195, 255, 0.13);
  background: rgba(3, 11, 28, 0.58);
}

.playground-toolbar > div {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.playground-toolbar > div:last-child {
  justify-content: flex-end;
}

.playground-action {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(76, 195, 255, 0.2);
  border-radius: 9px;
  color: #cdd8e8;
  background: rgba(9, 24, 49, 0.74);
  font-size: 0.59rem;
  font-weight: 800;
  cursor: pointer;
}

.playground-action.primary {
  border-color: rgba(76, 195, 255, 0.5);
  color: #03101e;
  background: linear-gradient(135deg, var(--cyan), #72e0ff);
}

.playground-action.subtle {
  color: #8998ad;
  background: transparent;
}

.playground-status {
  color: #74839a;
  font-size: 0.56rem;
  text-align: center;
}

.playground-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
}

.playground-editor,
.playground-preview-panel {
  min-width: 0;
  min-height: 0;
}

.playground-editor {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid rgba(76, 195, 255, 0.15);
  background: rgba(2, 8, 22, 0.94);
}

.playground-tabs {
  min-height: 46px;
  padding: 7px 9px 0;
  display: flex;
  align-items: end;
  gap: 5px;
  border-bottom: 1px solid rgba(76, 195, 255, 0.13);
}

.playground-tabs button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
  color: #73829a;
  background: transparent;
  font-size: 0.59rem;
  font-weight: 800;
  cursor: pointer;
}

.playground-tabs button[aria-selected="true"] {
  border-color: rgba(76, 195, 255, 0.22);
  color: var(--cyan-bright);
  background: rgba(10, 31, 60, 0.72);
}

.playground-code-input {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 18px;
  resize: none;
  border: 0;
  outline: 0;
  color: #d7e7f7;
  background:
    linear-gradient(180deg, rgba(4, 14, 31, 0.98), rgba(2, 8, 20, 0.98));
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.65;
  tab-size: 2;
}

.playground-code-input:focus {
  box-shadow: inset 0 0 0 2px rgba(76, 195, 255, 0.12);
}

.playground-preview-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #071020;
}

.playground-preview-heading {
  min-height: 46px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid rgba(76, 195, 255, 0.13);
}

.playground-preview-heading strong {
  font-size: 0.65rem;
}

.playground-preview-heading span {
  padding: 4px 7px;
  border: 1px solid rgba(70, 230, 168, 0.2);
  border-radius: 999px;
  color: #a8edd3;
  background: rgba(70, 230, 168, 0.06);
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.playground-preview-panel iframe {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

@keyframes lab-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes lab-chat-pulse {
  0%,
  100% {
    opacity: 0.58;
  }

  50% {
    opacity: 1;
  }
}

@media (max-width: 820px) {
  .playground-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .playground-toolbar > div:last-child {
    justify-content: flex-end;
  }

  .playground-status {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .playground-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(290px, 0.9fr) minmax(300px, 1.1fr);
  }

  .playground-editor {
    border-right: 0;
    border-bottom: 1px solid rgba(76, 195, 255, 0.15);
  }
}

@media (max-width: 620px) {
  .workbench-grid {
    grid-template-columns: 1fr;
  }

  .lab-modal {
    width: calc(100vw - 18px);
    height: calc(100vh - 18px);
    border-radius: 14px;
  }

  .lab-modal-header {
    min-height: 66px;
    padding: 10px 12px;
  }

  .lab-chat-messages {
    padding: 14px;
  }

  .lab-chat-message {
    max-width: 94%;
  }

  .lab-chat-suggestions {
    padding: 9px 11px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .lab-chat-suggestions button {
    flex: 0 0 auto;
  }

  .lab-chat-composer {
    padding: 11px;
  }

  .playground-toolbar {
    padding: 8px;
    grid-template-columns: 1fr;
  }

  .playground-toolbar > div,
  .playground-toolbar > div:last-child {
    justify-content: stretch;
  }

  .playground-action {
    flex: 1;
  }

  .playground-status {
    grid-column: 1;
    grid-row: auto;
  }

  .playground-workspace {
    grid-template-rows: minmax(250px, 0.9fr) minmax(270px, 1.1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lab-chat-message.loading,
  .lab-chat-spinner {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
