/**
 * IAL Conversation Design System (CDS)
 * Presentation layer for AI chat responses.
 */

:root {
  --cds-brand: #1b6da9;
  --cds-brand-dark: #155a8a;
  --cds-ink: #1f2937;
  --cds-muted: #6b7280;
  --cds-line: #e5e7eb;
  --cds-soft: #f3f6f9;
  --cds-success: #0b6b36;
  --cds-success-bg: #ecfdf3;
  --cds-success-bd: #25d366;
  --cds-warn: #92400e;
  --cds-warn-bg: #fffbeb;
  --cds-warn-bd: #f59e0b;
  --cds-danger: #991b1b;
  --cds-danger-bg: #fef2f2;
  --cds-danger-bd: #ef4444;
  --cds-info: #1e40af;
  --cds-info-bg: #eff6ff;
  --cds-info-bd: #3b82f6;
  --cds-radius: 12px;
  --cds-gap: 8px;
}

/* ── Bubble host ── */
.chat-bubble.cds-host {
  white-space: normal;
  max-width: 300px;
  width: max-content;
  min-width: 200px;
  padding: 11px 13px;
  word-break: normal;
  overflow-wrap: break-word;
}

.cds-root {
  display: flex;
  flex-direction: column;
  gap: var(--cds-gap);
  color: var(--cds-ink);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 500;
}

.cds-root > *:first-child { margin-top: 0; }
.cds-root > *:last-child { margin-bottom: 0; }

/* ── Typography ── */
.cds-h1, .cds-h2, .cds-h3 {
  margin: 0;
  color: var(--cds-brand);
  font-weight: 700;
  line-height: 1.3;
}
.cds-h1 { font-size: 15px; }
.cds-h2 { font-size: 14px; }
.cds-h3 { font-size: 13px; }

.cds-p {
  margin: 0;
  color: var(--cds-ink);
  font-weight: 500;
}

.cds-strong { font-weight: 700; }
.cds-em { font-style: italic; }
.cds-strike { text-decoration: line-through; opacity: 0.75; }

.cds-muted { color: var(--cds-muted); font-size: 12px; }

/* ── Lists ── */
.cds-ul, .cds-ol {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cds-ul { list-style: disc; }
.cds-ol { list-style: decimal; }
.cds-li { padding-left: 2px; }
.cds-li::marker { color: var(--cds-brand); font-weight: 700; }

.cds-task {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.cds-task-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.cds-task-box {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  border: 1.5px solid #94a3b8;
  border-radius: 3px;
  flex-shrink: 0;
  background: #fff;
}
.cds-task-box.is-done {
  background: var(--cds-brand);
  border-color: var(--cds-brand);
  position: relative;
}
.cds-task-box.is-done::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ── Divider / Quote ── */
.cds-hr {
  border: 0;
  border-top: 1px solid var(--cds-line);
  margin: 4px 0;
}

.cds-quote {
  margin: 0;
  padding: 6px 10px;
  border-left: 3px solid var(--cds-brand);
  background: var(--cds-soft);
  border-radius: 0 8px 8px 0;
  color: #374151;
  font-style: italic;
}

/* ── Code ── */
.cds-code-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: #eef2f7;
  color: #0f172a;
  padding: 1px 5px;
  border-radius: 5px;
}

.cds-code {
  position: relative;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
}
.cds-code pre { margin: 0; white-space: pre; }
.cds-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 0;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.cds-code-copy:hover { background: rgba(255,255,255,0.22); }

/* ── Table ── */
.cds-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--cds-line);
  border-radius: 10px;
}
.cds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.cds-table th, .cds-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--cds-line);
  text-align: left;
  vertical-align: top;
}
.cds-table th {
  background: var(--cds-soft);
  color: var(--cds-brand);
  font-weight: 700;
}
.cds-table tr:last-child td { border-bottom: 0; }

/* ── Alerts / Callouts ── */
.cds-alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid;
  font-size: 12.5px;
  line-height: 1.4;
}
.cds-alert-icon { flex-shrink: 0; font-weight: 700; line-height: 1.2; }
.cds-alert-info { background: var(--cds-info-bg); border-color: var(--cds-info-bd); color: var(--cds-info); }
.cds-alert-success { background: var(--cds-success-bg); border-color: var(--cds-success-bd); color: var(--cds-success); }
.cds-alert-warning { background: var(--cds-warn-bg); border-color: var(--cds-warn-bd); color: var(--cds-warn); }
.cds-alert-danger { background: var(--cds-danger-bg); border-color: var(--cds-danger-bd); color: var(--cds-danger); }

/* ── Badges / Tags ── */
.cds-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.cds-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e8f1f8;
  color: var(--cds-brand);
}

/* ── Buttons / Actions ── */
.cds-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.cds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.2;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
  max-width: 100%;
  text-align: center;
}
.cds-btn:hover { transform: translateY(-1px); }
.cds-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.cds-btn-primary {
  background: var(--cds-brand);
  border-color: var(--cds-brand);
  color: #fff;
}
.cds-btn-primary:hover { background: var(--cds-brand-dark); }

.cds-btn-secondary {
  background: #fff;
  border-color: var(--cds-brand);
  color: var(--cds-brand);
}
.cds-btn-secondary:hover { background: #eef5fb; }

.cds-btn-wa {
  background: var(--cds-success-bg);
  border-color: var(--cds-success-bd);
  color: var(--cds-success);
}
.cds-btn-wa:hover { background: #d1fae5; }
.cds-btn-wa svg { fill: var(--cds-success-bd); }

.cds-btn-link {
  background: transparent;
  border: 0;
  color: var(--cds-brand);
  text-decoration: underline;
  padding: 4px 0;
  justify-content: flex-start;
}
.cds-btn-link svg path { stroke: var(--cds-brand); }

/* Legacy aliases kept for compatibility */
.chat-wa-btn { /* mapped via CDS */ }
.chat-link-btn { /* mapped via CDS */ }

/* ── Cards ── */
.cds-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--cds-line);
  border-radius: var(--cds-radius);
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.cds-card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--cds-brand);
}
.cds-card-desc {
  margin: 0;
  font-size: 12px;
  color: #4b5563;
  line-height: 1.4;
}
.cds-card-meta {
  font-size: 11px;
  color: var(--cds-muted);
}

.cds-link-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #cfe0ee;
  border-radius: 10px;
  background: #f7fbfe;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
  width: 100%;
  box-sizing: border-box;
  max-width: 100%;
}
.cds-link-card:hover {
  background: #eef6fc;
  border-color: var(--cds-brand);
}
.cds-link-card-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #e8f1f8;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--cds-brand);
}
.cds-link-card-icon svg { width: 14px; height: 14px; }
.cds-link-card-body {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}
.cds-link-card-label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cds-brand);
  text-decoration: underline;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: normal;
  overflow-wrap: normal;
  line-height: 1.3;
}
.cds-link-card-url {
  display: block;
  font-size: 10.5px;
  color: var(--cds-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  word-break: normal;
  line-height: 1.3;
  margin-top: 2px;
}

/* ── Steps / Timeline ── */
.cds-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cds-step {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: start;
}
.cds-step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--cds-brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cds-step-body { font-size: 12.5px; }

.cds-timeline {
  margin: 0;
  padding: 0 0 0 10px;
  list-style: none;
  border-left: 2px solid #cfe0ee;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cds-timeline-item {
  position: relative;
  padding-left: 12px;
  font-size: 12.5px;
}
.cds-timeline-item::before {
  content: "";
  position: absolute;
  left: -15px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cds-brand);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #cfe0ee;
}

/* ── FAQ / Accordion ── */
.cds-faq {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cds-faq details {
  border: 1px solid var(--cds-line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}
.cds-faq summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--cds-brand);
  font-size: 12.5px;
  list-style: none;
}
.cds-faq summary::-webkit-details-marker { display: none; }
.cds-faq summary::after {
  content: "+";
  float: right;
  color: var(--cds-muted);
}
.cds-faq details[open] summary::after { content: "–"; }
.cds-faq-body {
  margin-top: 6px;
  font-size: 12.5px;
  color: #374151;
}

/* ── Metrics ── */
.cds-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.cds-metric {
  background: var(--cds-soft);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}
.cds-metric-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--cds-brand);
}
.cds-metric-label {
  font-size: 10.5px;
  color: var(--cds-muted);
}

/* ── Progress ── */
.cds-progress {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cds-progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.cds-progress-fill {
  height: 100%;
  background: var(--cds-brand);
  border-radius: 999px;
}
.cds-progress-label {
  font-size: 11px;
  color: var(--cds-muted);
}

/* ── Sources / References ── */
.cds-sources {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 2px;
  border-top: 1px dashed var(--cds-line);
}
.cds-sources-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--cds-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Highlight ── */
.cds-highlight {
  background: linear-gradient(180deg, transparent 60%, #dbeafe 60%);
  font-weight: 700;
}

/* ── Image ── */
.cds-img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--cds-line);
}

/* ── Suggestion chips (quick replies) ── */
.cds-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.cds-chip {
  border: 1px solid #cfe0ee;
  background: #fff;
  color: var(--cds-brand);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.cds-chip:hover { background: #eef6fc; }

/* ── Empty / Loading helpers ── */
.cds-empty {
  color: var(--cds-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 8px;
}

/* User bubble: keep plain; CDS only on robot */
.chat-msg.user .chat-bubble {
  white-space: pre-wrap;
}
