/* Copyright (c) 2025-2026 Ioannis Belesiotis. All rights reserved.
   This source code is proprietary and confidential. */
/* ── AI Copilot — right-side chat drawer ──────────────────────────────────── */

/* Drawer container — covers the whole viewport */
.ai-drawer {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  justify-content: flex-end;
}

.ai-drawer.hidden {
  display: none;
}

/* Dimmed backdrop — light tint so the calendar stays visible behind the drawer */
.ai-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 34, 60, 0.08);
  -webkit-backdrop-filter: none; backdrop-filter: none;
}

/* Slide-in panel */
.ai-panel {
  position: relative;
  z-index: 1;
  width: 540px;
  min-width: 360px;
  max-width: 90vw;
  height: 100%;
  background: var(--color-surface);
  border-top: 3px solid var(--color-accent);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

/* Auto-widen (kept for future use; tables now stack vertically so rarely needed) */
.ai-panel.ai-panel-wide:not(.ai-panel-resized) {
  width: 780px;
}

/* ── Resize handle (left edge) ───────────────────────────────────────────── */

.ai-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 100%;
  cursor: ew-resize;
  z-index: 2;
  background: transparent;
  transition: background 0.15s;
}

.ai-resize-handle:hover,
.ai-resize-handle.dragging {
  background: var(--color-accent);
}

/* Kill width transition during drag for smooth resize */
.ai-panel.ai-resizing {
  transition: none;
  -webkit-user-select: none; user-select: none;
}

.ai-drawer:not(.hidden) .ai-panel {
  transform: translateX(0);
}

/* ── Drawer mode (Cmd+K overlay) ──────────────────────────────────────── */

.ai-drawer-panel {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.ai-drawer-panel .ai-panel {
  width: 540px;
  min-width: 360px;
  max-width: 90vw;
  height: 100%;
  transform: translateX(0);
  box-shadow: var(--shadow-lg);
  border-top: 3px solid var(--color-accent);
}

/* ── Tab mode (promoted from drawer to navigation tab) ────────────────── */

.ai-tab-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

.ai-tab-panel .ai-panel {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  height: 100%;
  transform: none;
  transition: none;
  box-shadow: none;
  border-top: none;
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.ai-header {
  position: relative;
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.ai-ant-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
[data-theme="dark"] .ai-ant-icon {
  filter: brightness(0) invert(1);
}

.ai-header h3 {
  margin: 0;
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--color-text);
}

/* ── Credit badge ──────────────────────────────────────────────────────── */
.ai-credit-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-credit-badge.warning {
  background: color-mix(in srgb, var(--color-warning) 15%, transparent);
  color: var(--color-warning);
}
.ai-credit-badge.exhausted {
  background: color-mix(in srgb, var(--color-danger) 15%, transparent);
  color: var(--color-danger);
}

/* ── Credits exhausted blocker ──────────────────────────────────────────── */
.ai-credits-blocked {
  text-align: center;
  padding: 12px 20px;
  font-size: var(--font-sm);
  color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 6%, transparent);
  border-top: 1px solid color-mix(in srgb, var(--color-danger) 20%, transparent);
}

#aiNewChat {
  font-size: var(--font-xs);
  padding: 4px 10px;
}

.ai-header .modal-close {
  position: static;
  flex-shrink: 0;
}

/* ── Messages area (scrollable) ───────────────────────────────────────────── */

.ai-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-surface-alt);
}

/* ── Welcome state ────────────────────────────────────────────────────────── */

.ai-welcome {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  justify-content: center;
  padding: 24px 20px;
}

.ai-welcome-greeting {
  margin: 0;
  font-size: var(--font-lg);
  font-weight: 500;
  color: var(--color-text);
}

/* Welcome capability sections */
.ai-welcome-sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-welcome-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-accent);
  margin-bottom: 2px;
}

.ai-welcome-section-text {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* Collapsible sections (<details>/<summary>) inside assistant bubbles */
.ai-message.assistant details {
  border: none;
  border-radius: 0;
  margin: 6px 0;
  background: none;
}

.ai-message.assistant summary {
  padding: 2px 0;
  font-size: 12px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text);
  font-weight: 500;
  transition: color 0.15s;
}

.ai-message.assistant summary::-webkit-details-marker {
  display: none;
}

/* Chevron */
.ai-message.assistant summary::before {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid var(--color-text-muted);
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.ai-message.assistant details[open] > summary::before {
  transform: rotate(90deg);
}

.ai-message.assistant summary:hover {
  color: var(--color-accent);
}

/* Content inside expanded details — strip card styles from tables/lists */
.ai-message.assistant details > ul,
.ai-message.assistant details > ol {
  margin: 2px 0 6px;
  padding-left: 20px;
}

.ai-message.assistant details > p {
  margin: 4px 0 6px;
}

.ai-message.assistant details table,
.ai-message.assistant details tr,
.ai-message.assistant details td,
.ai-message.assistant details th {
  border: none;
  background: none;
  border-radius: 0;
  padding: 2px 0;
  margin: 0;
}

.ai-message.assistant details td:first-child {
  color: var(--color-accent);
}

.ai-welcome-hint {
  margin: 10px 0 0;
  font-size: var(--font-xs);
  color: var(--color-text-muted);
  text-align: center;
}

/* ── Message bubbles ──────────────────────────────────────────────────────── */

.ai-message {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.ai-message.user {
  align-self: flex-end;
  background: var(--color-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

/* Stretch assistant bubble to full width when it contains a chart or excel card */
.ai-message.assistant:has(.ai-chart-wrap),
.ai-message.assistant:has(.ai-excel-card) {
  max-width: 100%;
}

.ai-message.assistant {
  align-self: flex-start;
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}

/* ── Rich content inside assistant bubbles ────────────────────────────────── */

.ai-message.assistant p {
  margin: 0 0 8px;
}

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

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

.ai-message.assistant h1,
.ai-message.assistant h2,
.ai-message.assistant h3,
.ai-message.assistant h4 {
  margin: 14px 0 6px;
  font-weight: 600;
  color: var(--color-accent);
  line-height: 1.3;
}

.ai-message.assistant h1:first-child,
.ai-message.assistant h2:first-child,
.ai-message.assistant h3:first-child,
.ai-message.assistant h4:first-child {
  margin-top: 0;
}

.ai-message.assistant h1 { font-size: 15px; }
.ai-message.assistant h2 { font-size: 14px; }
.ai-message.assistant h3 { font-size: 13px; }
.ai-message.assistant h4 { font-size: 12px; font-weight: 700; }

.ai-message.assistant strong {
  font-weight: 600;
  color: var(--color-text);
  margin: 0 1px;  /* breathing room when spaces are missing around bold markers */
}

.ai-message.assistant em {
  font-style: italic;
}

/* Tables — linearised as stacked blocks (the AI generates tables despite instructions) */
.ai-message.assistant .table-wrap {
  margin: 6px 0;
}

.ai-message.assistant table,
.ai-message.assistant thead,
.ai-message.assistant tbody,
.ai-message.assistant tr,
.ai-message.assistant th,
.ai-message.assistant td {
  display: block;
  width: 100%;
}

.ai-message.assistant table {
  font-size: 12px;
  border: none;
}

/* Hide the header row — cell content speaks for itself in stacked layout */
.ai-message.assistant thead {
  display: none;
}

/* Each row becomes a card */
.ai-message.assistant tr {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.ai-message.assistant tr:last-child {
  margin-bottom: 0;
}

/* First cell in each row acts as a label */
.ai-message.assistant td:first-child {
  font-weight: 600;
  color: var(--color-accent);
  padding: 0 0 2px;
  font-size: 12px;
}

/* Remaining cells are the content */
.ai-message.assistant td {
  padding: 1px 0;
  line-height: 1.5;
}

.ai-message.assistant td:empty {
  display: none;
}

/* Lists */
.ai-message.assistant ul,
.ai-message.assistant ol {
  margin: 6px 0;
  padding-left: 16px;
}

.ai-message.assistant li {
  margin-bottom: 6px;
  font-size: 12px;
  line-height: 1.55;
  /* Reset global li card styling from catalyst.css */
  height: auto;
  background: none;
  border: none;
  display: list-item;
  transition: none;
}

.ai-message.assistant li:last-child {
  margin-bottom: 0;
}

/* Bold label inside list items — acts as a mini-heading */
.ai-message.assistant li > strong:first-child {
  color: var(--color-accent);
  font-weight: 600;
}

/* List items with bold labels get extra spacing (mini-sections) */
.ai-message.assistant li + li:has(> strong:first-child) {
  margin-top: 10px;
}

/* Nested lists */
.ai-message.assistant li ul,
.ai-message.assistant li ol {
  margin: 4px 0;
}

.ai-message.assistant li li {
  font-size: 11px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

/* Inline code */
.ai-message.assistant code {
  font-family: 'SF Mono', 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  background: var(--color-surface);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

/* Fenced code blocks */
.ai-message.assistant pre {
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.ai-message.assistant pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 11px;
  line-height: 1.45;
}

/* Blockquotes — neutralised to plain text (no card styling) */
.ai-message.assistant blockquote {
  margin: 4px 0;
  padding: 0;
  border-left: none;
  background: none;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

.ai-message.assistant blockquote blockquote {
  margin: 2px 0 0;
  padding: 0;
  border-left: none;
  background: none;
  border-radius: 0;
}

.ai-message.assistant blockquote p {
  margin: 0;
}

/* Horizontal rules */
.ai-message.assistant hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 8px 0;
}

/* Links */
.ai-message.assistant a {
  color: var(--color-accent);
  text-decoration: none;
}

.ai-message.assistant a:hover {
  text-decoration: underline;
}

/* ── Thinking indicator ───────────────────────────────────────────────────── */

.ai-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
}

.ai-thinking-ant {
  display: inline-block;
  width: 16px;
  height: 16px;
  animation: ai-ant-march 2.4s linear infinite;
}
[data-theme="dark"] .ai-thinking-ant {
  filter: brightness(0) invert(1);
}

.ai-thinking-dots {
  display: flex;
  gap: 3px;
}

.ai-thinking-dots span {
  width: 4px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-text-muted);
  animation: ai-dot-fade 1.4s ease-in-out infinite;
}

.ai-thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-ant-march {
  0%   { transform: translateX(0)    scaleY(1); }
  5%   { transform: translateX(1px)  scaleY(0.92); }
  10%  { transform: translateX(2px)  scaleY(1); }
  15%  { transform: translateX(3px)  scaleY(0.92); }
  20%  { transform: translateX(5px)  scaleY(1); }
  25%  { transform: translateX(6px)  scaleY(0.92); }
  30%  { transform: translateX(8px)  scaleY(1); }
  35%  { transform: translateX(9px)  scaleY(0.92); }
  40%  { transform: translateX(10px) scaleY(1); }
  45%  { transform: translateX(11px) scaleY(0.92); }
  50%  { transform: translateX(12px) scaleY(1); }
  55%  { transform: translateX(11px) scaleY(0.92); }
  60%  { transform: translateX(10px) scaleY(1); }
  65%  { transform: translateX(9px)  scaleY(0.92); }
  70%  { transform: translateX(8px)  scaleY(1); }
  75%  { transform: translateX(6px)  scaleY(0.92); }
  80%  { transform: translateX(5px)  scaleY(1); }
  85%  { transform: translateX(3px)  scaleY(0.92); }
  90%  { transform: translateX(2px)  scaleY(1); }
  95%  { transform: translateX(1px)  scaleY(0.92); }
  100% { transform: translateX(0)    scaleY(1); }
}

@keyframes ai-dot-fade {
  0%, 100% { opacity: 0.2; }
  50%      { opacity: 0.8; }
}

/* ── Tool activity ────────────────────────────────────────────────────────── */

.ai-tool-activity {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: var(--font-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--color-accent);
}

.ai-tool-activity.ai-tool-error {
  border-left-color: var(--color-warning);
  color: var(--color-warning);
}

.ai-tool-activity .ai-tool-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: ai-spin 0.6s linear infinite;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

/* ── Proposed action card ─────────────────────────────────────────────────── */

.ai-action-card {
  align-self: flex-start;
  width: 92%;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-action-desc {
  font-size: var(--font-sm);
  color: var(--color-text);
  font-weight: 500;
}

.ai-action-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.ai-action-buttons .btn {
  font-size: var(--font-xs);
  padding: 4px 12px;
}

/* Confirmed state */
.ai-action-card.confirmed {
  border-left-color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 6%, transparent);
}

.ai-action-card.confirmed .ai-action-buttons {
  display: none;
}

.ai-action-card.confirmed .ai-action-status {
  font-size: var(--font-xs);
  color: var(--color-success);
  font-weight: 600;
}

/* Dismissed state */
.ai-action-card.dismissed {
  opacity: 0.5;
  border-left-color: var(--color-border);
}

.ai-action-card.dismissed .ai-action-buttons {
  display: none;
}

.ai-action-card.dismissed .ai-action-status {
  font-size: var(--font-xs);
  color: var(--color-text-muted);
}

/* Error state */
.ai-action-card.errored {
  border-left-color: var(--color-danger);
  background: color-mix(in srgb, var(--color-danger) 6%, transparent);
}

.ai-action-card.errored .ai-action-buttons {
  display: none;
}

.ai-action-card.errored .ai-action-status {
  font-size: var(--font-xs);
  color: var(--color-danger);
}

/* ── Skill proposal cards (ADR-035) ───────────────────────────────────── */

.ai-proposal {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  padding: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-proposal.confirmed { border-left-color: var(--color-success); background: color-mix(in srgb, var(--color-success) 6%, transparent); }
.ai-proposal.errored   { border-left-color: var(--color-danger); }

.ai-proposal-summary { font-size: var(--font-sm); font-weight: 600; color: var(--color-text); }

.ai-proposal-metrics {
  display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 11px; color: var(--color-text-muted);
}
.ai-proposal-metrics span {
  background: var(--color-surface-alt); padding: 2px 8px; border-radius: var(--radius-full);
}

/* Action rows */
.ai-proposal-row {
  display: grid;
  grid-template-columns: auto 70px 1fr 120px 50px 1fr;
  gap: 6px; align-items: center;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--color-border);
}
.ai-proposal-row:last-child { border-bottom: none; }
.ai-proposal-tier1 .ai-proposal-row { grid-template-columns: 70px 1fr 120px 50px 1fr; }
.ai-proposal-key { font-weight: 600; color: var(--color-accent); white-space: nowrap; }
.ai-proposal-move { color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-proposal-dates { color: var(--color-text-muted); white-space: nowrap; font-size: 11px; }
.ai-proposal-effort { color: var(--color-text-muted); text-align: right; font-size: 11px; }
.ai-proposal-reason { color: var(--color-text-muted); font-style: italic; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-proposal-chk-label { display: flex; align-items: center; }

/* Expandable detail (tier 2) */
.ai-proposal-expand {
  background: none; border: none; color: var(--color-accent); cursor: pointer;
  font-size: 12px; font-weight: 500; padding: 0; text-align: left;
}
.ai-proposal-expand:hover { text-decoration: underline; }

/* Grouped actions (tier 3) */
.ai-proposal-groups { max-height: 300px; overflow-y: auto; }
.ai-proposal-group { border-top: 1px solid var(--color-border); }
.ai-proposal-group:first-child { border-top: none; }
.ai-proposal-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; cursor: pointer; -webkit-user-select: none; user-select: none;
  font-size: 12px;
}
.ai-proposal-group-header:hover { color: var(--color-accent); }
.ai-proposal-group-count {
  font-size: 10px; color: var(--color-accent);
  background: var(--color-accent-subtle); padding: 1px 6px; border-radius: 10px;
}
.ai-proposal-chevron {
  font-size: 10px; transition: transform 0.15s; display: inline-block;
}
.ai-proposal-chevron.collapsed { transform: rotate(-90deg); }

/* Timeline bars (tier 3) */
.ai-proposal-timeline { display: flex; flex-direction: column; gap: 4px; padding: 8px 0; }
.ai-proposal-timeline-row { display: grid; grid-template-columns: 100px 1fr 50px; gap: 8px; align-items: center; font-size: 11px; }
.ai-proposal-timeline-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-proposal-timeline-bar { height: 8px; background: var(--color-surface-alt); border-radius: 4px; overflow: hidden; }
.ai-proposal-bar-fill { height: 100%; background: var(--color-accent); border-radius: 4px; transition: width 0.3s; }
.ai-proposal-timeline-hours { text-align: right; color: var(--color-text-muted); }

/* Unplaced / couldn't place */
.ai-proposal-unplaced { font-size: 11px; color: var(--color-text-muted); padding-top: 6px; border-top: 1px dashed var(--color-border); }
.ai-proposal-unplaced-label { font-weight: 600; display: block; margin-bottom: 4px; }
.ai-proposal-unplaced-item { padding: 2px 0; }

/* Proposal footer (ID + expiry) */
.ai-proposal-footer { display: flex; align-items: center; gap: 6px; padding-top: 8px; font-size: 11px; color: var(--color-text-muted); }
.ai-proposal-id { font-family: monospace; font-weight: 600; }
.ai-proposal-expiry { opacity: 0.8; }
.ai-proposal-hint { margin-left: auto; font-style: italic; opacity: 0.6; }

/* Buttons */
.ai-proposal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.ai-proposal-applied-badge {
  display: inline-block;
  padding: 4px 12px;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-success);
  background: color-mix(in srgb, var(--color-success) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-success) 25%, transparent);
  border-radius: var(--radius-md);
}

/* Error */
.ai-proposal-error { font-size: 11px; color: var(--color-danger); padding-top: 4px; }

/* ── Copilot glossary ─────────────────────────────────────────────────── */

.ai-glossary-link {
  background: none; border: none; color: var(--color-accent);
  font-size: 12px; cursor: pointer; padding: 0; margin-top: 4px;
}
.ai-glossary-link:hover { text-decoration: underline; }

.ai-glossary {
  width: 100%; max-width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}

.ai-glossary-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: var(--font-sm);
}
.ai-glossary-close {
  background: none; border: none; font-size: 18px;
  color: var(--color-text-muted); cursor: pointer; line-height: 1;
}
.ai-glossary-close:hover { color: var(--color-text); }

.ai-glossary-section { display: flex; flex-direction: column; gap: 4px; }
.ai-glossary-category {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--color-accent);
  margin-top: 4px;
}

.ai-glossary-prompt {
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); padding: 6px 10px;
  font-size: 12px; color: var(--color-text); cursor: pointer;
  text-align: left; transition: border-color 0.15s, background 0.15s;
}
.ai-glossary-prompt:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

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

.ai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-surface);
}

#aiInput {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: var(--font-sm);
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  line-height: 1.4;
  max-height: 96px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s;
}

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

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

.ai-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.ai-send-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Error message in chat ────────────────────────────────────────────────── */

.ai-error-msg {
  align-self: flex-start;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--color-danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-danger) 20%, transparent);
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  color: var(--color-danger);
}

/* ── Inline charts (ECharts) ─────────────────────────────────────────────── */

/* Hide raw JSON during streaming; replaced by chart div after stream completes */
.ai-message.assistant pre:has(> code.language-chart) {
  display: none;
}

/* Chart wrapper (replaces the <pre> after initCharts runs) */
.ai-chart-wrap {
  margin: 8px 0;
  padding: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-width: 100%;
  overflow: visible;
}

/* Render error inside the bubble */
.ai-chart-error {
  margin: 8px 0;
  padding: 8px 10px;
  font-size: var(--font-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
}

/* ── Excel export cards ────────────────────────────────────────────────── */

/* Hide raw JSON during streaming; replaced by download card after stream completes */
.ai-message.assistant pre:has(> code.language-excel) {
  display: none;
}

/* Download card (replaces the <pre> after initExcelBlocks runs) */
.ai-excel-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s;
}

.ai-excel-card:hover {
  border-color: var(--color-accent);
}

.ai-excel-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  border-radius: var(--radius-sm);
  color: var(--color-success);
}

.ai-excel-icon svg {
  width: 18px;
  height: 18px;
}

.ai-excel-info {
  flex: 1;
  min-width: 0;
}

.ai-excel-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-excel-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.ai-excel-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  font-size: var(--font-xs);
  font-weight: 500;
  color: #fff;
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.ai-excel-btn:hover {
  background: var(--color-accent-hover, #4558d4);
}

.ai-excel-btn svg {
  width: 13px;
  height: 13px;
}

.ai-excel-btn.downloaded {
  background: var(--color-success);
  cursor: default;
}

/* Error state */
.ai-excel-error {
  margin: 8px 0;
  padding: 8px 10px;
  font-size: var(--font-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
}

/* ── Proposal preview CTA button ───────────────────────────────────────── */

.ai-proposal-preview-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 4px;
  padding: 8px 16px;
  font-size: var(--font-sm);
  font-weight: 600;
}

.ai-proposal-preview-btn svg {
  flex-shrink: 0;
}

/* ── Timeline (critical path visualisation) ────────────────────────────── */

.ai-timeline {
  margin: 8px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  overflow: hidden;
}

.ai-timeline-header {
  padding: 10px 12px 6px;
}

.ai-timeline-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text);
}

.ai-timeline-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.ai-timeline-track {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 12px 12px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.ai-timeline-track::-webkit-scrollbar {
  height: 4px;
}
.ai-timeline-track::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: 2px;
}

.ai-timeline-card {
  flex-shrink: 0;
  width: 140px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  position: relative;
}

/* Float-based border colouring */
.ai-timeline-card.critical {
  border-left: 3px solid var(--color-danger);
}
.ai-timeline-card.near-critical {
  border-left: 3px solid var(--color-warning);
}
.ai-timeline-card.has-buffer {
  border-left: 3px solid var(--color-success);
}

/* Cross-project tint */
.ai-timeline-card.cross-project {
  background: color-mix(in srgb, var(--color-accent) 6%, var(--color-surface-alt));
  border-style: dashed;
  border-left-style: solid;
}

.ai-timeline-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.ai-timeline-id {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-accent);
  white-space: nowrap;
}

.ai-timeline-float-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.ai-timeline-float-badge.float-critical {
  background: color-mix(in srgb, var(--color-danger) 15%, transparent);
  color: var(--color-danger);
}
.ai-timeline-float-badge.float-near-critical {
  background: color-mix(in srgb, var(--color-warning) 15%, transparent);
  color: var(--color-warning);
}
.ai-timeline-float-badge.float-has-buffer {
  background: color-mix(in srgb, var(--color-success) 15%, transparent);
  color: var(--color-success);
}

.ai-timeline-card-title {
  font-size: 11px;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.ai-timeline-card-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--color-text-muted);
}

.ai-timeline-cross {
  font-weight: 600;
  color: var(--color-accent);
}

.ai-timeline-progress {
  height: 3px;
  background: var(--color-border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.ai-timeline-progress-fill {
  height: 100%;
  background: var(--color-success);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Arrow connector between cards */
.ai-timeline-arrow {
  flex-shrink: 0;
  width: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1;
}

.ai-timeline-footer {
  padding: 4px 12px 8px;
  font-size: 10px;
  color: var(--color-text-muted);
}

/* Full-width in bubbles (same as charts/excel) */
.ai-message.assistant:has(.ai-timeline) {
  max-width: 100%;
}
