/* Insights AI task pane — dark teal theme matching the MCP Access modal,
   laid out as a full-height chat app. */
:root {
  --surface: #081c20;
  --panel: #0f2d32;
  --panel-deep: #06171a;
  --border: #2e5058;
  --border-soft: #223437;
  --green: #54c22d;
  --green-hover: #46a924;
  --error: #ff7875;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.6);
  --muted-soft: rgba(255, 255, 255, 0.45);
}

* {
  box-sizing: border-box;
}

/* The [hidden] attribute must beat the flex/display rules on .connect/.chat,
   so toggling element.hidden actually shows/hides the view. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--surface);
  font-size: 14px;
}

/* App fills the task pane height so the chat composer sits at the bottom. */
.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Brand header ---- */
.brand {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

.brand-logo {
  height: 26px;
  width: auto;
  object-fit: contain;
}

.brand-text {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 3px;
  color: var(--text);
}

/* Build stamp — makes a cached vs fresh build obvious at a glance. */
.build-stamp {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--muted-soft);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* Detected Office app badge (Word / Excel / PowerPoint) */
.brand-host {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  background: rgba(84, 194, 45, 0.12);
  border: 1px solid rgba(84, 194, 45, 0.4);
  border-radius: 999px;
  padding: 2px 10px;
}

/* Connected company/tenant code badge. margin-left:auto anchors the right-hand
   group; the host badge (also right-aligned) then sits next to it. */
.brand-tenant {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 2px 10px;
}

/* ---- Connection view ---- */
.connect {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px;
}

.connect-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.connect-card h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.connect-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

label {
  display: block;
  margin: 0 0 6px;
  font-weight: 600;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

.token-input,
.chat-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--panel-deep);
  color: var(--text);
  resize: none;
}

.token-input::placeholder,
.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.token-input:focus,
.chat-input:focus {
  outline: none;
  border-color: var(--green);
}

button.primary {
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  cursor: pointer;
}

button.primary:hover {
  background: var(--green-hover);
}

button.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.block {
  display: block;
  width: 100%;
  margin-top: 12px;
}

/* "Token configured" status pill (shown instead of the token, once saved). */
.token-configured {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-deep);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.token-configured-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

/* Full-width secondary button (e.g. Reset Token) under the primary action. */
button.ghost.block {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 9px 16px;
  font-size: 13px;
}

.status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  word-break: break-word;
}

.status.error {
  color: var(--error);
}

/* ---- Chat view ---- */
.chat {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0; /* allow the messages area to scroll */
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}

.msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-ai {
  align-self: flex-start;
  align-items: flex-start;
  position: relative;
}

/* Copy button on AI answers — hidden until the bubble is hovered/focused. */
.copy-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-deep);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.msg-ai:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

.copy-btn:hover {
  color: var(--green);
  border-color: var(--green);
}

.copy-btn.copied {
  opacity: 1;
  color: var(--green);
  border-color: var(--green);
}

.copy-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

.bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-user .bubble {
  background: var(--green);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-ai .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble-error {
  border-color: var(--error) !important;
  color: var(--error);
}

/* Markdown-rendered AI answers */
.bubble-md {
  white-space: normal;
}
.bubble-md > *:first-child {
  margin-top: 0;
}
.bubble-md > *:last-child {
  margin-bottom: 0;
}
.bubble-md p {
  margin: 0 0 8px;
}
.bubble-md h1,
.bubble-md h2,
.bubble-md h3 {
  margin: 10px 0 6px;
  line-height: 1.3;
  font-weight: 700;
}
.bubble-md h1 {
  font-size: 16px;
}
.bubble-md h2 {
  font-size: 15px;
}
.bubble-md h3 {
  font-size: 14px;
}
.bubble-md ul,
.bubble-md ol {
  margin: 0 0 8px;
  padding-left: 20px;
}
.bubble-md li {
  margin: 2px 0;
}
.bubble-md strong {
  font-weight: 700;
  color: var(--text);
}
.bubble-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--panel-deep);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble-md a {
  color: var(--green);
  text-decoration: underline;
}

.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
}

button.ghost:hover {
  border-color: var(--green);
  color: var(--green);
}

/* Live progress status tag (streamed states + animated dots). */
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.status-text {
  font-size: 13px;
  color: var(--muted);
}

.status-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.status-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 1.2s infinite both;
}

.status-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.status-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* typing indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite both;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
}

/* ---- Composer (chat input pinned at bottom) ---- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
}

.composer .chat-input {
  flex: 1 1 auto;
  font-family: inherit;
  max-height: 120px;
  overflow-y: auto;
}

.composer .send {
  flex: 0 0 auto;
  padding: 10px 16px;
}

/* ---- Toast (in-pane success/info banner) ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%) translateY(12px);
  background: var(--green);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
