@import url("blueprint.css");

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.58;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--color-text);
  background-color: var(--color-bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4375rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(16, 42, 67, 0.92);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 30;
}

.builder-header .logo {
  font-size: 0.875rem;
  gap: 0.375rem;
}

.builder-header .logo-mark {
  font-size: 0.75rem;
}

.builder-url-bar {
  --url-bar-control-height: 2rem;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(var(--grid-line-fine) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line-fine) 1px, transparent 1px),
    rgba(16, 42, 67, 0.88);
  background-size: 12px 12px, 12px 12px, auto;
  flex-shrink: 0;
  z-index: 25;
}

.url-bar-project,
.url-bar-nav-btn,
.url-bar-input {
  box-sizing: border-box;
  height: var(--url-bar-control-height);
  min-height: var(--url-bar-control-height);
}

.url-bar-project {
  flex-shrink: 0;
  padding-block: 0;
  line-height: 1;
}

.url-bar-project[aria-expanded="true"] {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.url-bar-nav {
  display: flex;
  align-items: stretch;
  gap: 0.125rem;
  flex-shrink: 0;
}

.url-bar-nav-btn {
  min-width: var(--url-bar-control-height);
  padding-block: 0;
  padding-inline: 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1;
}

.url-bar-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.url-bar-nav-btn:disabled:hover {
  border-color: var(--border);
  color: var(--color-text);
}

.url-bar-field {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0;
}

.url-bar-input {
  width: 100%;
  padding-block: 0;
  padding-inline: 0.625rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: rgba(8, 28, 48, 0.55);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1;
  outline: none;
  cursor: default;
  user-select: all;
}

.url-bar-input:focus {
  border-color: rgba(56, 189, 248, 0.35);
}

.profile-menu {
  position: relative;
}

.profile-avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--color-surface-muted);
  cursor: pointer;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}

.profile-avatar-btn:hover,
.profile-avatar-btn[aria-expanded="true"] {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.profile-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  overflow: hidden;
  font-family: var(--font-meta);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--color-heading);
  background: rgba(56, 189, 248, 0.15);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  left: auto;
  z-index: 40;
  min-width: 220px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(16, 42, 67, 0.98);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(8, 28, 48, 0.45);
}

.profile-details {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding-bottom: 0.625rem;
  margin-bottom: 0.625rem;
  border-bottom: 1px solid var(--border);
}

.profile-name {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-title);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-email {
  font-family: var(--font-meta);
  font-size: 0.6875rem;
  color: var(--color-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-sign-out {
  width: 100%;
  justify-content: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.builder-main {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.preview-canvas {
  position: absolute;
  inset: 0;
}

#preview-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: rgba(8, 28, 48, 0.6);
}

.project-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 15;
  width: 260px;
  padding: 1rem;
  border-right: 1px solid var(--border);
  overflow: auto;
  background:
    linear-gradient(var(--grid-line-fine) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line-fine) 1px, transparent 1px),
    rgba(16, 42, 67, 0.97);
  background-size: 12px 12px, 12px 12px, auto;
  backdrop-filter: blur(12px);
  box-shadow: 4px 0 24px rgba(8, 28, 48, 0.35);
}

.project-panel[hidden] {
  display: none;
}

.project-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.project-panel-header h2 {
  margin-bottom: 0;
}

.project-close {
  flex-shrink: 0;
  min-width: 2rem;
  padding-inline: 0.5rem;
  line-height: 1;
  font-size: 1.125rem;
}

.project-panel h2 {
  font-family: var(--font-meta);
  font-size: 0.62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-accent);
}

.project-status {
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
  color: var(--color-accent);
}

.project-actions {
  margin-bottom: 0.75rem;
}

.project-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.project-list-item {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  color: var(--color-text);
}

.project-list-item.is-active,
.project-list-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.project-details {
  margin-bottom: 0.75rem;
  font-size: 0.75rem;
}

.project-meta {
  color: var(--color-muted);
}

.file-tree {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--color-muted);
  line-height: 1.8;
}

.builder-chat-bar {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(960px, calc(100% - 2rem));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(16, 42, 67, 0.96);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(8, 28, 48, 0.5);
  transition: box-shadow 250ms ease-out;
}

.builder-chat-bar.expanded {
  box-shadow:
    0 8px 32px rgba(8, 28, 48, 0.5),
    0 -2px 16px rgba(56, 189, 248, 0.08);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding: 0 1rem;
}

.builder-chat-bar.expanded .messages {
  max-height: 220px;
  opacity: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem 0;
}

.msg {
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  line-height: 1.5;
  max-width: 90%;
  border: 1px solid var(--border);
}

.msg.user {
  background: var(--color-surface-muted);
  align-self: flex-end;
  color: var(--color-text);
}

.msg.assistant {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--color-heading);
  align-self: flex-start;
}

.msg.assistant.error {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.typing-indicator {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.625rem 0.875rem;
}

.msg.streaming-message {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 2rem;
}

.msg.streaming-message:empty::after {
  content: "▍";
  display: inline-block;
  color: var(--color-accent);
  animation: stream-cursor-blink 1s step-end infinite;
}

@keyframes stream-cursor-blink {
  50% {
    opacity: 0;
  }
}

.typing-dots {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
}

.typing-dots span {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--color-accent);
  opacity: 0.35;
  animation: typing-dot-pulse 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-dot-pulse {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.builder-chat-bar.is-agent-loading {
  border-color: rgba(56, 189, 248, 0.45);
  animation: chat-bar-glow 1.6s ease-in-out infinite;
}

@keyframes chat-bar-glow {
  0%,
  100% {
    box-shadow:
      0 8px 32px rgba(8, 28, 48, 0.5),
      0 0 0 rgba(56, 189, 248, 0);
  }

  50% {
    box-shadow:
      0 8px 32px rgba(8, 28, 48, 0.5),
      0 0 18px rgba(56, 189, 248, 0.12);
  }
}

.input-area {
  display: flex;
  gap: 0.625rem;
  align-items: center;
  padding: 0.625rem 0.75rem;
}

.prompt-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.chat-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding-inline: 0.5rem;
  line-height: 1;
}

.chat-toggle[hidden] {
  display: none;
}

.chat-toggle[aria-expanded="true"] {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.chat-toggle-chevron {
  display: inline-block;
  font-size: 0.75rem;
  line-height: 1;
  transition: transform 250ms ease-out;
}

.chat-toggle[aria-expanded="true"] .chat-toggle-chevron {
  transform: rotate(180deg);
}

#prompt {
  width: 100%;
  padding: 0.75rem 2.75rem 0.75rem 0.875rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--color-surface-muted);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 150ms ease-out;
}

.prompt-send {
  position: absolute;
  top: 50%;
  right: 0.375rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: calc(var(--radius) - 2px);
  background: rgba(56, 189, 248, 0.1);
  color: rgba(186, 230, 253, 0.8);
  font-size: 1rem;
  line-height: 1;
  transition:
    background 150ms ease-out,
    border-color 150ms ease-out,
    color 150ms ease-out,
    opacity 150ms ease-out;
}

.prompt-send:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--color-accent);
}

.prompt-send:disabled {
  opacity: 0.45;
  cursor: wait;
}

.prompt-send[aria-busy="true"] {
  border-color: rgba(56, 189, 248, 0.35);
  animation: send-btn-pulse 1.4s ease-in-out infinite;
}

.prompt-send[aria-busy="true"] .prompt-send-icon {
  animation: send-icon-breathe 0.9s ease-in-out infinite;
}

@keyframes send-btn-pulse {
  0%,
  100% {
    background: rgba(56, 189, 248, 0.1);
  }

  50% {
    background: rgba(56, 189, 248, 0.18);
  }
}

@keyframes send-icon-breathe {
  0%,
  100% {
    opacity: 0.55;
  }

  50% {
    opacity: 1;
  }
}

.prompt-send-icon {
  display: inline-block;
  line-height: 1;
}

#prompt:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

#prompt::placeholder {
  color: var(--color-muted);
}

#prompt:focus {
  border-color: var(--color-accent);
}

@media (max-width: 900px) {
  .builder-chat-bar {
    width: calc(100% - 1.5rem);
    bottom: 0.75rem;
  }

  .builder-url-bar {
    padding: 0.3125rem 0.5rem;
    gap: 0.375rem;
  }

  .url-bar-input {
    font-size: 0.625rem;
  }

  .builder-chat-bar.expanded .messages {
    max-height: 160px;
  }

  .input-area {
    flex-wrap: wrap;
  }

  .prompt-wrap {
    flex: 1 1 100%;
    order: 2;
  }

  .project-panel {
    width: min(260px, 85vw);
  }
}
