/* =========================================================
   TRAFOSPHERE CHAT WIDGET
========================================================= */

:root {
  --chat-brand: #0015c8;
  --chat-brand-soft: #eaf1ff;
  --chat-border: #dbe3ef;
  --chat-muted: #475569;
  --chat-bg: #f8fafc;
}

/* Floating button */
#chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9998;
  border: none;
  border-radius: 999px;
  background: var(--chat-brand);
  color: #fff;
  padding: 14px 18px;
  font-weight: 700;
  box-shadow: 0 14px 30px rgba(0, 21, 200, 0.25);
  cursor: pointer;
  font-family: inherit;
}

/* Main container */
#chat-container {
  position: fixed;
  right: 24px;
  bottom: 84px;
  width: 380px;
  height: 620px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: inherit;
}

/* Header */
.chat-header {
  padding: 16px 18px;
  background: var(--chat-brand);
  color: #fff;
}

.chat-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.chat-subtitle {
  margin: 6px 0 0 0;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0.95;
}

#chat-close {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-family: inherit;
}

/* Quick actions */
.quick-actions {
  padding: 12px 16px;
  background: var(--chat-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-action {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.quick-action:hover {
  background: #f1f5f9;
}

/* Chat box */
#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Messages */
.chat-message {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.chat-message.bot {
  align-self: flex-start;
  background: var(--chat-brand-soft);
  color: #1f2937;
  border-bottom-left-radius: 6px;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--chat-brand);
  color: #fff;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}

.chat-message.system {
  align-self: center;
  background: #eef2f7;
  color: var(--chat-muted);
  font-size: 12px;
  text-align: center;
  max-width: 92%;
  white-space: normal;
}

/* Form */
#chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}

#message-input {
  flex: 1;
  min-height: 48px;
  max-height: 120px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

#message-input:focus {
  border-color: var(--chat-brand);
}

#chat-form button {
  border: none;
  border-radius: 12px;
  background: var(--chat-brand);
  color: #fff;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

#chat-form button:hover {
  opacity: 0.95;
}

/* =========================================================
   MARKDOWN RENDERING
========================================================= */

.chat-message.markdown {
  white-space: normal;
}

.chat-message.markdown p {
  margin: 0 0 0.65rem 0;
}

.chat-message.markdown p:last-child {
  margin-bottom: 0;
}

.chat-message.markdown strong {
  font-weight: 800;
  color: var(--chat-brand);
}

.chat-message.markdown em {
  font-style: italic;
}

.chat-message.markdown h1,
.chat-message.markdown h2,
.chat-message.markdown h3,
.chat-message.markdown h4 {
  color: var(--chat-brand);
  font-weight: 800;
  line-height: 1.25;
  margin: 0.75rem 0 0.4rem;
}

.chat-message.markdown h1 {
  font-size: 1.2rem;
}

.chat-message.markdown h2 {
  font-size: 1.1rem;
}

.chat-message.markdown h3,
.chat-message.markdown h4 {
  font-size: 1rem;
}

.chat-message.markdown ul,
.chat-message.markdown ol {
  margin: 0.5rem 0 0.75rem 0;
  padding-left: 1.25rem;
}

.chat-message.markdown li {
  margin: 0.3rem 0;
}

.chat-message.markdown a {
  color: var(--chat-brand);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chat-message.markdown code {
  background: rgba(0, 21, 200, 0.08);
  color: #00115c;
  padding: 0.12rem 0.3rem;
  border-radius: 0.35rem;
  font-size: 0.88em;
}

.chat-message.markdown pre {
  background: #0f172a;
  color: #f8fafc;
  padding: 0.85rem;
  border-radius: 0.75rem;
  overflow-x: auto;
  margin: 0.75rem 0;
}

.chat-message.markdown pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
}

.chat-message.markdown blockquote {
  margin: 0.75rem 0;
  padding: 0.6rem 0.8rem;
  border-left: 4px solid var(--chat-brand);
  background: rgba(0, 21, 200, 0.06);
  border-radius: 0.5rem;
  color: #334155;
}

.chat-message.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.9em;
}

.chat-message.markdown th,
.chat-message.markdown td {
  border: 1px solid var(--chat-border);
  padding: 0.45rem 0.55rem;
  text-align: left;
}

.chat-message.markdown th {
  background: #eef2ff;
  color: var(--chat-brand);
  font-weight: 800;
}

/* =========================================================
   BOT UI CARDS
========================================================= */

.chat-card-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
  max-width: 86%;
  align-self: flex-start;
}

.chat-card {
  background: #ffffff;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
}

.chat-card-title {
  font-weight: 700;
  color: var(--chat-brand);
  margin-bottom: 10px;
  font-size: 14px;
}

.chat-card-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-card-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  font-size: 13px;
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 6px;
}

.chat-card-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.chat-card-label {
  font-weight: 600;
  color: #334155;
  min-width: 95px;
}

.chat-card-value {
  color: var(--chat-muted);
  text-align: right;
}

.chat-card-cta {
  display: inline-block;
  margin-top: 12px;
  background: var(--chat-brand);
  color: white;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* Mobile */
@media (max-width: 640px) {
  #chat-container {
    right: 12px;
    left: 12px;
    bottom: 76px;
    width: auto;
    height: 70vh;
  }

  #chat-toggle {
    right: 12px;
    bottom: 12px;
  }

  .chat-message,
  .chat-card-group {
    max-width: 92%;
  }

  #chat-form {
    gap: 8px;
    padding: 12px;
  }

  #chat-form button {
    padding: 0 14px;
  }
}