/* Dashboard Assistant — floating chat widget.
 * Reuses the dashboard's CSS custom properties so colour, type and shadow
 * match the rest of the chrome. Z-index 800 sits above the page but below
 * any modal we'd add later.
 */

.srg-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 800;
  font-family: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--srg-dark);
}

/* ---------- bubble ------------------------------------------------------ */

.srg-chat__bubble {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--srg-red);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  transition: background 0.15s ease, transform 0.15s ease;
}
.srg-chat__bubble:hover  { background: var(--srg-red-dark); transform: translateY(-1px); }
.srg-chat__bubble:focus  { outline: 2px solid var(--srg-red); outline-offset: 3px; }

/* When the panel is open we hide the bubble — the panel has its own close
   button and we don't want both visible. */
.srg-chat[data-srg-chat-open] .srg-chat__bubble { display: none; }

/* ---------- panel ------------------------------------------------------- */

.srg-chat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border: 1px solid var(--srg-border);
  border-left: 3px solid var(--srg-red);   /* matches KPI cards */
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
}
.srg-chat__panel[hidden] { display: none; }

.srg-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--srg-border);
  background: var(--surface-2);
}
.srg-chat__title {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--srg-dark);
}
.srg-chat__close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--srg-grey);
  cursor: pointer;
  padding: 0 4px;
}
.srg-chat__close:hover { color: var(--srg-red); }

/* ---------- log + welcome ----------------------------------------------- */

.srg-chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.45;
}

.srg-chat__welcome {
  color: var(--srg-grey);
  font-size: 13px;
}
.srg-chat__welcome p { margin: 0 0 10px; }

.srg-chat__chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.srg-chat__chip {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--srg-border);
  background: var(--surface);
  font-family: inherit;
  font-size: 12.5px;
  color: var(--srg-dark);
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s, border-color 0.12s;
}
.srg-chat__chip:hover {
  background: var(--srg-red-soft);
  border-color: var(--srg-red);
}

/* ---------- messages ---------------------------------------------------- */

.srg-chat__msg {
  display: flex;
}
.srg-chat__msg--user      { justify-content: flex-end; }
.srg-chat__msg--assistant { justify-content: flex-start; }

.srg-chat__bubble-text {
  max-width: 86%;
  padding: 8px 11px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.srg-chat__msg--user .srg-chat__bubble-text {
  background: var(--srg-red-soft);
  color: var(--srg-dark);
}
.srg-chat__msg--assistant .srg-chat__bubble-text {
  background: var(--surface-2);
  border: 1px solid var(--srg-border);
  color: var(--srg-dark);
}
.srg-chat__bubble-text.is-streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--srg-grey-2);
  animation: srg-chat-blink 1s infinite;
}
.srg-chat__bubble-text.is-error {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

/* ---------- rendered-markdown elements --------------------------------- */
/* Bubble defaults to `white-space: pre-wrap` so streaming text shows
   newlines as the model emits them. Once renderMarkdown takes over after
   the stream ends, paragraphs / tables / lists need normal flow. */
.srg-chat__bubble-text p,
.srg-chat__bubble-text ul,
.srg-chat__bubble-text ol,
.srg-chat__bubble-text table { white-space: normal; }
.srg-chat__bubble-text p { margin: 0; }
.srg-chat__bubble-text p + p,
.srg-chat__bubble-text p + ul,
.srg-chat__bubble-text p + ol,
.srg-chat__bubble-text p + table,
.srg-chat__bubble-text table + p,
.srg-chat__bubble-text ul + p,
.srg-chat__bubble-text ol + p { margin-top: 8px; }

.srg-chat__list {
  margin: 4px 0;
  padding-left: 20px;
}
.srg-chat__list li { margin: 2px 0; }

.srg-chat__table-wrap {
  margin: 6px 0;
  overflow-x: auto;
  /* Lets the inner table grow past the bubble's max-width if it needs to,
     while the wrapper scrolls. */
  max-width: 100%;
}
.srg-chat__table {
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}
.srg-chat__table th,
.srg-chat__table td {
  border: 1px solid var(--srg-border);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
  line-height: 1.35;
}
.srg-chat__table th {
  background: var(--surface-2);
  font-weight: 700;
  white-space: nowrap;
}
.srg-chat__bubble-text strong { font-weight: 700; }

@keyframes srg-chat-blink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---------- form -------------------------------------------------------- */

.srg-chat__form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--srg-border);
  background: var(--surface-2);
}

.srg-chat__input {
  flex: 1;
  resize: none;
  border: 1px solid var(--srg-border);
  background: var(--surface);
  font: inherit;
  font-size: 13.5px;
  color: var(--srg-dark);
  padding: 8px 10px;
  border-radius: 2px;
  max-height: 120px;
  line-height: 1.4;
}
.srg-chat__input:focus {
  outline: none;
  border-color: var(--srg-red);
  box-shadow: 0 0 0 2px var(--srg-red-soft);
}

.srg-chat__send {
  border: 1px solid var(--srg-red);
  background: var(--srg-red);
  color: white;
  padding: 0 10px;
  cursor: pointer;
  border-radius: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.srg-chat__send:hover { background: var(--srg-red-dark); border-color: var(--srg-red-dark); }
.srg-chat__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- print + small screens --------------------------------------- */

@media print {
  .srg-chat { display: none !important; }
}

@media (max-width: 480px) {
  .srg-chat {
    right: 12px;
    bottom: 12px;
  }
  .srg-chat__bubble {
    width: 48px;
    height: 48px;
  }
  .srg-chat__panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 80px);
    right: 0;
    bottom: 0;
  }
}
