.chat-wrapper {
  padding: 32px 0;
}

// ── Setup Required Gate ───────────────────────────────────────────────────────
.setup-gate {
  max-width: 560px;
  margin: 80px auto 0;
  padding: 48px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
}

.setup-gate__icon {
  font-size: 3rem;
}

.setup-gate__title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.setup-gate__desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 420px;

  code {
    font-family: monospace;
    color: var(--accent-gold);
    font-size: 0.82rem;
  }
}

.setup-gate__row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.setup-gate__input {
  flex: 1;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: monospace;
  font-size: 0.82rem;
  transition: border-color 0.2s ease;

  &:focus {
    outline: none;
    border-color: var(--accent-gold);
  }
}

.setup-gate__save {
  flex-shrink: 0;
  padding: 12px 24px;
}

.setup-gate__status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
}

.setup-gate__status-label {
  color: var(--text-secondary);
  &.state-online  { color: #00a651; }
  &.state-warn    { color: #ffc107; }
  &.state-offline { color: #dc3545; }
}

.setup-gate__hint {
  font-size: 0.62rem;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.6;
}

.chat-layout {
  display: flex;
  height: calc(100vh - 140px);
  min-height: 500px;

  @media (max-width: 768px) {
    height: auto;
    min-height: unset;
  }
}

// ── Chat panel ─────────────────────────────────────────────────────────────────
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px;
  min-width: 0;

  @media (max-width: 768px) {
    height: calc(100vh - 200px);
    min-height: 400px;
  }
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.chat-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-lego {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.chat-clear-btn {
  font-size: 0.75rem;
  padding: 5px 12px;
}

// ── Messages ──────────────────────────────────────────────────────────────────
.message-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.message {
  display: flex;

  &--user {
    justify-content: flex-end;

    .message-bubble {
      background: rgba(0, 166, 81, 0.15);
      border: 1px solid rgba(0, 166, 81, 0.3);
      border-radius: 16px 16px 4px 16px;
      max-width: 72%;
    }
  }

  &--bot {
    justify-content: flex-start;

    .message-bubble {
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      border-radius: 16px 16px 16px 4px;
      max-width: 85%;
    }
  }

  &--error {
    justify-content: flex-start;

    .message-bubble {
      background: rgba(220, 53, 69, 0.1);
      border: 1px solid rgba(220, 53, 69, 0.3);
      border-radius: 16px 16px 16px 4px;
      max-width: 85%;

      .message-text { color: var(--danger); }
    }
  }
}

.message-bubble {
  padding: 12px 16px;
}

.message-text {
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.message-time {
  font-size: 0.62rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.message-latency {
  font-size: 0.62rem;
  color: var(--accent-gold);
  font-family: monospace;
}

// Thinking animation
.thinking-dots {
  display: flex;
  gap: 5px;
  margin-bottom: 4px;

  span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: blink 1.2s infinite;

    &:nth-child(2) { animation-delay: 0.2s; }
    &:nth-child(3) { animation-delay: 0.4s; }
  }
}

.thinking-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-style: italic;
}

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

// ── Input row ─────────────────────────────────────────────────────────────────
.chat-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.chat-input {
  flex: 1;
  resize: none;
  padding: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.88rem;
  line-height: 1.5;
  transition: border-color 0.2s ease;

  &:focus {
    outline: none;
    border-color: var(--accent-gold);
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.send-btn {
  padding: 12px 22px;
  flex-shrink: 0;
  align-self: flex-end;

  &:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
  }
}

.chat-hint {
  margin-top: 8px;
  font-size: 0.62rem;
  color: var(--text-secondary);
  text-align: center;
  opacity: 0.7;
}

// ── Lego 06: Webhook URL config panel ────────────────────────────────────────
.webhook-config {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--input-bg);
  border: 1px solid var(--accent-gold);
  border-radius: 10px;
  animation: slideUp 0.15s ease-out;
}

.webhook-config__label-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}

.webhook-config__label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.webhook-config__status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;

  &.dot-green  { background: #00a651; box-shadow: 0 0 5px rgba(0,166,81,0.7); }
  &.dot-yellow { background: #ffc107; box-shadow: 0 0 5px rgba(255,193,7,0.6); }
  &.dot-red    { background: #dc3545; box-shadow: 0 0 5px rgba(220,53,69,0.6); }
}

.webhook-config__verify {
  padding: 9px 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.webhook-config__row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.webhook-config__input {
  flex: 1;
  padding: 9px 12px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  color: var(--text-primary);
  font-family: monospace;
  font-size: 0.8rem;
  transition: border-color 0.2s ease;

  &:focus {
    outline: none;
    border-color: var(--accent-gold);
  }
}

.webhook-config__save {
  padding: 9px 16px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.webhook-config__cancel {
  padding: 9px 12px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.webhook-config__hint {
  margin-top: 6px;
  font-size: 0.6rem;
  color: var(--text-secondary);
}

// ── n8n status indicator (sidebar) ────────────────────────────────────────────
.n8n-status-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  background: var(--input-bg);
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.n8n-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;

  &.dot-green  { background: #00a651; box-shadow: 0 0 5px rgba(0,166,81,0.7); }
  &.dot-yellow { background: #ffc107; box-shadow: 0 0 5px rgba(255,193,7,0.6); }
  &.dot-red    { background: #dc3545; box-shadow: 0 0 5px rgba(220,53,69,0.6); }
}

.n8n-status-label {
  font-size: 0.72rem;
  color: var(--text-secondary);

  &.state-online  { color: #00a651; }
  &.state-warn    { color: #ffc107; }
  &.state-offline { color: #dc3545; }
}

// ── n8n offline warning banner (chat panel) ───────────────────────────────────
.n8n-offline-banner {
  padding: 9px 14px;
  background: rgba(220, 53, 69, 0.1);
  border: 1px solid rgba(220, 53, 69, 0.35);
  border-radius: 8px;
  color: #f8a8ae;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 10px;
}
