/* ===== Copilot centered hero ===== */
.copilot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px 32px;
  min-height: calc(100vh - 56px);
}

.copilot__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 760px;
  gap: 24px;
}

/* ===== Chat state overrides ===== */
.copilot.is-chat {
  justify-content: flex-start;
  padding: 24px 24px 28px;
}

.copilot.is-chat .copilot__inner {
  align-items: stretch;
  gap: 16px;
  flex: 1;
  height: 100%;
}

.copilot.is-chat .copilot__greeting {
  display: none;
}

.chat__messages {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.copilot.is-chat .chat__messages {
  display: flex;
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 16px;
  scroll-behavior: smooth;
}

.copilot.is-chat .copilot__input {
  margin-top: auto;
  flex-shrink: 0;
}

.copilot.is-chat .copilot__hint {
  flex-shrink: 0;
}

/* ===== Chat message bubbles ===== */
.chat__msg {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: chat-in 0.25s ease-out;
}

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

.chat__msg--user {
  justify-content: flex-end;
}

/* Divider between conversation turns — appears before each new user message except the first */
.chat__msg--user:not(:first-child) {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 4px;
}

.chat__bubble {
  max-width: 75%;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat__bubble--user {
  background: #E5E7EB;
  color: var(--text-1);
  border-radius: 18px;
}

.chat__msg--assistant {
  justify-content: flex-start;
  align-items: flex-start;
}

.chat__mini-mascot {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg);
}

.chat__mini-mascot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat__loading {
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  color: var(--text-3);
  padding: 8px 0;
}

.chat__loading-dots {
  display: inline-block;
  margin-left: 2px;
  animation: dots-pulse 1.4s ease-in-out infinite;
}

@keyframes dots-pulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

/* Assistant column: stacks an optional thinking block above the answer bubble */
.chat__assistant-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  max-width: 85%;
}

/* Assistant message bubble */
.chat__bubble--assistant {
  background: transparent;
  color: var(--text-1);
  max-width: 85%;
  padding: 6px 0;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
}

.chat__assistant-body .chat__bubble--assistant {
  max-width: 100%;
}

/* Once markdown is rendered, normalize spacing (no pre-wrap on HTML structure) */
.chat__bubble--assistant:not(.is-streaming) {
  white-space: normal;
}

.chat__bubble--error {
  color: var(--primary-red);
}

/* ===== Thinking block (claude.ai-style collapsible reasoning) ===== */
.chat__thinking {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}

.chat__thinking-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-2);
  user-select: none;
  list-style: none;
}

.chat__thinking-toggle::-webkit-details-marker { display: none; }

.chat__thinking-chevron {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

.chat__thinking[open] .chat__thinking-chevron {
  transform: rotate(90deg);
}

.chat__thinking-label {
  font-weight: 500;
}

/* Shimmer the label while reasoning is still streaming */
.chat__thinking.is-thinking .chat__thinking-label {
  background: linear-gradient(90deg, var(--text-3), var(--text-1), var(--text-3));
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: think-shimmer 1.6s linear infinite;
}

@keyframes think-shimmer {
  to { background-position: -200% 0; }
}

.chat__thinking-content {
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-3);
  white-space: pre-wrap;
}

/* ===== Markdown elements ===== */
.chat__bubble--assistant p {
  margin: 0 0 8px;
}

.chat__bubble--assistant p:last-child {
  margin-bottom: 0;
}

.chat__bubble--assistant h1,
.chat__bubble--assistant h2,
.chat__bubble--assistant h3,
.chat__bubble--assistant h4 {
  font-weight: 700;
  margin: 14px 0 6px;
  line-height: 1.3;
}

.chat__bubble--assistant h1 { font-size: 18px; }
.chat__bubble--assistant h2 { font-size: 16px; }
.chat__bubble--assistant h3 { font-size: 15px; }
.chat__bubble--assistant h4 { font-size: 14px; }

.chat__bubble--assistant > *:first-child {
  margin-top: 0;
}

.chat__bubble--assistant strong {
  font-weight: 700;
}

.chat__bubble--assistant em {
  font-style: italic;
}

.chat__bubble--assistant ul,
.chat__bubble--assistant ol {
  margin: 0 0 8px;
  padding-left: 22px;
}

.chat__bubble--assistant li {
  margin: 3px 0;
}

.chat__bubble--assistant a {
  color: #04BE8C;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat__bubble--assistant a:hover {
  color: #03A77B;
}

.chat__bubble--assistant blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid #04BE8C;
  color: var(--text-2);
  background: rgba(4, 190, 140, 0.05);
  border-radius: 0 6px 6px 0;
}

.chat__bubble--assistant code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12.5px;
  color: var(--text-1);
}

.chat__bubble--assistant pre {
  background: #F4F4F4;
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid var(--border);
}

.chat__bubble--assistant pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.chat__bubble--assistant hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* Tables */
.chat__bubble--assistant .table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.chat__bubble--assistant table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.chat__bubble--assistant thead {
  background: #04BE8C;
}

.chat__bubble--assistant th,
.chat__bubble--assistant td {
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
  text-align: left;
  vertical-align: top;
}

.chat__bubble--assistant th {
  font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap;
  border-bottom-color: #04BE8C;
}

.chat__bubble--assistant tbody tr:last-child td {
  border-bottom: 0;
}

.chat__bubble--assistant tbody tr:hover {
  background: rgba(4, 190, 140, 0.04);
}

/* Standalone tables (when marked emits <table> without wrapper) */
.chat__bubble--assistant > table {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

/* Streaming cursor (blinking caret at end of in-progress text) */
.chat__bubble.is-streaming::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 14px;
  margin-left: 3px;
  vertical-align: -2px;
  background: #04BE8C;
  border-radius: 1px;
  animation: caret-blink 0.9s steps(2) infinite;
}

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

/* Pending state: disable send button + dim input */
.copilot__input.is-pending .copilot__send {
  opacity: 0.55;
  pointer-events: none;
}

.copilot__field:disabled {
  background: transparent;
  color: var(--text-3);
  cursor: not-allowed;
}

.copilot__greeting {
  display: flex;
  align-items: center;
  gap: 24px;
}

.copilot__mascot {
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.copilot__mascot img,
.copilot__mascot svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.copilot__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  /* Reserve a stable width so the mascot + title don't shift between tabs
     when the per-use-case subtitle length changes */
  min-width: 320px;
}

.copilot__title {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.1;
}

.copilot__sub {
  font-size: 15px;
  color: var(--text-2);
}

/* ===== Input bar (column: attachment chips + input row) ===== */
.copilot__input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

/* Soften corners to a rounded rectangle when chips show or the box grows multi-line */
.copilot__input:has(.copilot__attachments:not([hidden])),
.copilot__input.is-multiline {
  border-radius: 20px;
}

.copilot__input:focus-within {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(123, 201, 184, 0.15), var(--shadow-card);
}

.copilot__input.is-dragover {
  border-color: var(--mint);
  background: rgba(123, 201, 184, 0.06);
}

.copilot__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
}

/* Multi-line: text takes the top row; + (left) and send (right) drop below it */
.copilot__input.is-multiline .copilot__row {
  justify-content: space-between;
}

.copilot__input.is-multiline .copilot__field {
  order: -1;
  flex: 0 0 100%;
  width: 100%;
}

/* ===== Attachment preview chips ===== */
.copilot__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 6px 0;
}

.copilot__attachments[hidden] {
  display: none;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--text-1);
}

.attach-chip__thumb {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
}

.attach-chip__icon {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
  color: var(--text-2);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.attach-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 130px;
}

.attach-chip__remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.attach-chip__remove:hover {
  background: var(--primary-red-soft);
  color: var(--primary-red);
}

.copilot__attach {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-2);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.copilot__attach:hover {
  background: var(--bg);
  color: var(--text-1);
}

.copilot__attach svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.copilot__field {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  padding: 8px 4px;
  min-width: 0;
  resize: none;
  max-height: 121px; /* ~5 lines, then scrolls */
  overflow-y: auto;
}

.copilot__field::placeholder {
  color: var(--text-3);
}

.copilot__send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mint);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

.copilot__send:hover {
  background: var(--mint-hover);
}

.copilot__send:active {
  transform: scale(0.94);
}

.copilot__send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.copilot__hint {
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
  margin-top: 4px;
}

/* ===== Mobile chat tweaks ===== */
@media (max-width: 768px) {
  /* Shorten the centered area so the input bar clears the bottom nav */
  .copilot {
    padding: 24px 16px;
    min-height: calc(100vh - 56px - var(--bottom-nav-h));
  }

  .copilot.is-chat {
    padding: 16px 12px 20px;
  }

  /* Mascot + greeting stack vertically and shrink */
  .copilot__greeting {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .copilot__mascot {
    width: 88px;
    height: 88px;
  }

  .copilot__text {
    align-items: center;
    min-width: 0;
  }

  .copilot__title {
    font-size: 24px;
  }

  /* Wider user bubbles read better on a narrow screen */
  .chat__bubble--user {
    max-width: 88%;
  }

  .chat__assistant-body {
    max-width: 92%;
  }
}
