/* VCX Legal Assistant — ChatGPT-style full-page chat */

body[data-vcx-page="legal-assistant"] {
  background: var(--vcx-bg-canvas, #F6F2EA);
  color: var(--vcx-ink-body, #2E4F46);
}

/* Hide footer on legal-assistant page for immersive chat */
body[data-vcx-page="legal-assistant"] .footer {
  display: none;
}

/* ── Full-page layout ──────────────────────────────────────────────── */

.la-chat-main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
  min-height: 400px;
}

.la-chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.la-chat-messages {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px 16px;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  justify-content: flex-end;
}

/* ── Messages ──────────────────────────────────────────────────────── */

.la-message {
  margin-bottom: 16px;
  padding: 14px 18px;
  border-radius: 3px;
  max-width: 85%;
  white-space: pre-wrap;
  font-size: .9rem;
  line-height: 1.65;
  animation: laFadeIn .2s ease;
}

@keyframes laFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.la-message-user {
  margin-left: auto;
  background: rgba(46, 79, 70, .07);
  border: 1px solid rgba(46, 79, 70, .1);
}

.la-message-assistant {
  background: transparent;
  border: none;
  padding-left: 0;
  padding-right: 0;
  max-width: 100%;
}

.la-message-meta {
  display: block;
  margin-bottom: 6px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--vcx-ink-muted, #5E6C7B);
}

/* ── Input area (sticky bottom) ────────────────────────────────────── */

.la-chat-input-area {
  border-top: 1px solid rgba(26, 47, 42, .08);
  padding: 16px 20px;
  background: var(--vcx-bg-canvas, #F6F2EA);
}

.la-chat-form {
  max-width: 720px;
  margin: 0 auto;
}

.la-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1px solid rgba(26, 47, 42, .15);
  border-radius: 3px;
  background: var(--vcx-bg-surface, #FBF8F3);
  padding: 8px 12px;
  transition: border-color .2s, box-shadow .2s;
}

.la-chat-input-wrap:focus-within {
  border-color: #2D8A82;
  box-shadow: 0 0 0 2px rgba(45, 138, 130, .1);
}

.la-chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--vcx-ink-body, #2E4F46);
  font-size: .9rem;
  font-family: inherit;
  line-height: 1.5;
  padding: 4px 0;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}

.la-chat-textarea::placeholder {
  color: var(--vcx-ink-muted, #5E6C7B);
  opacity: .6;
}

.la-chat-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: flex-end;
}

.la-icon-btn,
.la-send-btn {
  appearance: none;
  border: none !important;
  background: transparent;
  color: var(--vcx-ink-muted, #5E6C7B);
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  min-height: 28px !important;
  max-width: 28px !important;
  max-height: 28px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 3px !important;
  transition: background .15s, color .15s;
  flex-shrink: 0;
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1;
  box-sizing: border-box !important;
  overflow: hidden;
}

.la-icon-btn:hover {
  background: rgba(46, 79, 70, .06) !important;
  color: var(--vcx-ink-body, #2E4F46);
}

.la-send-btn {
  background: #2D8A82 !important;
  color: #fff !important;
  font-weight: 800;
  font-size: 13px;
  font-family: inherit;
  letter-spacing: -.02em;
}

.la-send-btn:hover {
  background: #3D9E94 !important;
}

.la-chat-disclaimer {
  margin: 10px 0 0;
  font-size: .72rem;
  color: var(--vcx-ink-muted, #5E6C7B);
  text-align: center;
}

.la-chat-disclaimer a {
  color: #2D8A82;
  text-decoration: none;
}

.la-chat-disclaimer a:hover {
  text-decoration: underline;
}

/* ── Suggestion chips ──────────────────────────────────────────────── */

.la-message-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.suggestion-chip {
  appearance: none;
  border: 1px solid rgba(26, 47, 42, .12);
  background: var(--vcx-bg-surface, #FBF8F3);
  color: var(--vcx-ink-body, #2E4F46);
  border-radius: 3px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: .8rem;
  font-family: inherit;
  transition: border-color .15s, background .15s;
}

.suggestion-chip:hover {
  border-color: #2D8A82;
  background: rgba(45, 138, 130, .04);
}

/* ── Boundary / escalation ─────────────────────────────────────────── */

.la-message-boundary {
  background: rgba(139, 67, 72, .04);
  border: 1px solid rgba(139, 67, 72, .12);
  padding: 14px 18px;
}

.la-escalation-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.la-escalation-link {
  display: block;
  padding: 8px 12px;
  border-radius: 3px;
  border: 1px solid rgba(46, 79, 70, .12);
  background: rgba(46, 79, 70, .03);
  text-decoration: none;
  transition: border-color .15s, background .15s;
}

.la-escalation-link:hover {
  border-color: #2D8A82;
  background: rgba(46, 79, 70, .06);
}

.la-escalation-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: #2D8A82;
}

.la-escalation-desc {
  display: block;
  font-size: .72rem;
  color: var(--vcx-ink-muted, #5E6C7B);
  margin-top: 2px;
}

/* ── Mode badges ───────────────────────────────────────────────────── */

.la-mode-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 6px;
}

.la-mode-legal {
  background: rgba(46, 79, 70, .1);
  color: var(--vcx-brand-primary, #2E4F46);
}

.la-mode-routing {
  background: rgba(45, 138, 130, .1);
  color: #2D8A82;
}

.la-mode-escalate {
  background: rgba(139, 67, 72, .1);
  color: #8B4348;
}

/* Mode tints on assistant messages */
.la-message-assistant.la-mode-legal-information {
  border-left: 3px solid var(--vcx-brand-primary, #2E4F46);
  padding-left: 16px;
}

.la-message-assistant.la-mode-vcx-routing {
  border-left: 3px solid rgba(45, 138, 130, .5);
  padding-left: 16px;
}

.la-message-assistant.la-mode-high-risk {
  border-left: 3px solid #8B4348;
  padding-left: 16px;
}

/* ── Streaming cursor ──────────────────────────────────────────────── */

.la-stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #2D8A82;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: la-blink .6s step-end infinite;
}

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

.la-message-streaming .la-message-body {
  min-height: 1.5em;
}

/* ── Typing indicator ──────────────────────────────────────────────── */

.la-typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.la-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(26, 47, 42, .22);
  animation: laTypingBounce 1.2s ease-in-out infinite;
}

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

@keyframes laTypingBounce {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Upload status ─────────────────────────────────────────────────── */

.la-upload-status {
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 3px;
  font-size: .78rem;
  line-height: 1.4;
}

.la-upload-ok {
  background: rgba(47, 107, 87, .07);
  color: #2F6B57;
  border: 1px solid rgba(47, 107, 87, .12);
}

.la-upload-error {
  background: rgba(139, 67, 72, .07);
  color: #8B4348;
  border: 1px solid rgba(139, 67, 72, .12);
}

/* ── Intake CTA ────────────────────────────────────────────────────── */

body[data-vcx-page="legal-assistant"] .la-intake-cta {
  margin-top: 14px;
  padding: 14px 18px;
  background: rgba(45, 138, 130, .04);
  border: 1px solid rgba(45, 138, 130, .12);
  border-radius: 3px;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-text {
  font-size: .84rem;
  color: var(--vcx-ink-body, #2E4F46);
  margin: 0 0 8px;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-btn {
  appearance: none;
  display: inline-block;
  padding: 9px 18px;
  border: none;
  background: #2D8A82;
  color: #fff;
  border-radius: 3px;
  font-size: .84rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-btn:hover {
  background: #3D9E94;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-detected {
  display: block;
  margin-bottom: 8px;
  font-size: .76rem;
  font-weight: 600;
  color: #2D8A82;
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-steps {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: .74rem;
  color: var(--vcx-ink-muted, #5E6C7B);
}

body[data-vcx-page="legal-assistant"] .la-intake-cta-steps span {
  white-space: nowrap;
}

/* ── Message sources ───────────────────────────────────────────────── */

.la-message-sources {
  margin-top: 8px;
  font-size: .72rem;
  color: var(--vcx-ink-muted, #5E6C7B);
}

/* ── Markdown in messages ──────────────────────────────────────────── */

.la-message-body h2,
.la-message-body h3,
.la-message-body h4 {
  font-size: .95rem;
  font-weight: 700;
  color: #1A2F2A;
  margin: 12px 0 6px;
}

.la-message-body h2 { font-size: 1.05rem; }

.la-message-body p {
  margin: 0 0 4px;
  line-height: 1.6;
}

.la-message-body .la-list-item {
  padding-left: 16px;
  position: relative;
  margin: 2px 0;
  line-height: 1.6;
}

.la-message-body .la-list-item::before {
  content: '\2022';
  position: absolute;
  left: 4px;
  color: #2D8A82;
}

.la-message-body strong { font-weight: 700; }
.la-message-body em { font-style: italic; }

.la-message-body .la-inline-code {
  background: rgba(45, 138, 130, .07);
  padding: 1px 5px;
  border-radius: 2px;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: .85em;
}

.la-message-body pre.la-code {
  background: rgba(26, 47, 42, .05);
  border: 1px solid rgba(26, 47, 42, .08);
  border-radius: 3px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
}

.la-message-body pre.la-code code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: .82rem;
  line-height: 1.5;
}

.la-message-body a {
  color: #2D8A82;
  text-decoration: underline;
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .la-chat-main {
    height: calc(100dvh - 100px);
    height: calc(100vh - 100px);
  }

  .la-chat-messages {
    padding: 20px 14px 12px;
  }

  .la-message {
    max-width: 92%;
    font-size: .88rem;
  }

  .la-chat-input-area {
    padding: 12px 14px;
  }

  .la-chat-textarea {
    font-size: 16px; /* prevent iOS zoom */
  }

  .suggestion-chip {
    min-height: 44px;
    padding: 10px 14px;
  }

  .la-escalation-link {
    min-height: 44px;
    padding: 10px 12px;
  }

  body[data-vcx-page="legal-assistant"] .la-intake-cta-btn {
    min-height: 44px;
    padding: 12px 18px;
  }

  .la-icon-btn,
  .la-send-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
  }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 640px) {
    .la-chat-input-area {
      padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }
  }
}
