:root {
  /* Biz Tecno palette — deep navy + teal, matching the dashboards */
  --navy: #16456e;
  --navy-deep: #0e3355;
  --teal: #4da5a4;
  --teal-soft: #e4f1f1;
  --bg: #eef2f7;
  --panel: #ffffff;
  --text: #1c2b3a;
  --muted: #64778c;
  --border: #dde5ee;
  --accent: #16456e;
  --accent-hover: #0e3355;
  --user-bubble: linear-gradient(135deg, #1b4f82, #16456e);
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --error-bg: #fdecec;
  --error-text: #b3261e;
  --chip-bg: #e4f1f1;
  --chip-text: #2e6f6e;
  --code-bg: #eef2f6;
  --shadow: 0 1px 3px rgba(22, 69, 110, .08), 0 4px 14px rgba(22, 69, 110, .06);
  --shadow-lg: 0 2px 6px rgba(22, 69, 110, .10), 0 10px 28px rgba(22, 69, 110, .10);
  --radius: 14px;
}

body.dark {
  --bg: #0f1722;
  --panel: #182432;
  --text: #e7edf4;
  --muted: #8fa1b5;
  --border: #263547;
  --accent: #4da5a4;
  --accent-hover: #63bdbc;
  --user-bubble: linear-gradient(135deg, #1b4f82, #133c63);
  --user-text: #ffffff;
  --bot-bubble: #1d2b3b;
  --error-bg: #3a2022;
  --error-text: #ff9d94;
  --chip-bg: #14303c;
  --chip-text: #6fc7c6;
  --code-bg: #101a26;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  background: var(--bg);
  color: var(--text);
}

body { display: flex; flex-direction: column; }

/* ---------- Header ---------- */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--navy-deep), var(--navy) 60%, #1b5a8e);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(14, 51, 85, .25);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .22);
  display: flex; align-items: center; justify-content: center;
  color: #7fd4d3;
  flex-shrink: 0;
}
.brand-text h1 {
  font-size: 14.5px;
  margin: 0;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}
.brand-text h1 span { font-weight: 400; opacity: .85; }
#context-line { display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #9aa8b5;
  flex-shrink: 0;
  transition: background .3s;
}
.status-dot.ok { background: #4ade80; box-shadow: 0 0 6px rgba(74, 222, 128, .7); }
.status-dot.err { background: #f87171; box-shadow: 0 0 6px rgba(248, 113, 113, .7); }
.chip {
  font-size: 10.5px;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .13);
  color: rgba(255, 255, 255, .92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}
.chip-muted { background: transparent; border: 1px solid rgba(255, 255, 255, .25); color: rgba(255, 255, 255, .75); }

.header-actions { display: flex; gap: 6px; flex-shrink: 0; }
.header-actions button {
  border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .08);
  color: rgba(255, 255, 255, .9);
  border-radius: 9px;
  width: 32px; height: 32px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.header-actions button:hover { background: rgba(255, 255, 255, .2); }

/* ---------- Layout: left dashboard rail + main column ---------- */
#layout { flex: 1; display: flex; min-height: 0; }
#main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#dash-rail {
  width: 50px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 8px 9px 10px;
  position: relative;
  z-index: 20;
  overflow: visible;            /* tooltips overlay the chat */
  transition: width .22s ease;
}
#dash-rail.expanded { width: 236px; }

#rail-toggle {
  width: 32px; height: 26px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  align-self: center;
}
#dash-rail.expanded #rail-toggle { align-self: flex-end; }
#rail-toggle:hover { color: var(--teal); background: var(--bg); }
#rail-toggle svg { transition: transform .22s ease; }
#dash-rail.expanded #rail-toggle svg { transform: rotate(180deg); }

#dash-icons {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: center;
  align-self: stretch;
}
.rail-sep { width: 22px; height: 1px; background: var(--border); flex-shrink: 0; }
#dash-rail.expanded .rail-sep { width: 100%; }

.rail-item {
  position: relative;
  width: 32px; height: 32px;
  flex-shrink: 0;
  transition: width .22s ease, height .22s ease;
}
#dash-rail.expanded .rail-item { width: 100%; height: 42px; }

.dash-ico, #refresh-all {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  text-align: left;
  font-family: inherit;
  z-index: 5;
}
#dash-rail.expanded .dash-ico:hover,
#dash-rail.expanded #refresh-all:hover:not(:disabled) { background: var(--bg); }
.dash-ico:disabled { cursor: default; }
#refresh-all:disabled { opacity: .5; cursor: default; }

.ico-glyph {
  width: 32px; height: 32px;
  flex-shrink: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .3px;
  color: #fff;
  position: relative;
  box-shadow: var(--shadow);
}
.dash-ico:hover .ico-glyph { box-shadow: var(--shadow-lg); }
#refresh-all .ico-glyph {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--muted);
  box-shadow: none;
}
#refresh-all:hover:not(:disabled) .ico-glyph { color: var(--teal); border-color: var(--teal); }

.ico-text {
  display: none;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
#dash-rail.expanded .ico-text { display: flex; }
.ico-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}
.ico-sub {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ico-refresh {
  display: none;
  margin-left: auto;
  margin-right: 9px;
  color: var(--teal);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
#dash-rail.expanded .rail-item:hover .ico-refresh { display: block; animation: ctaPulse 1.6s ease-in-out infinite; }
#dash-rail.expanded .rail-tip { display: none; }   /* timestamps are visible inline when expanded */

.dash-ico.syncing .ico-glyph { color: transparent; }
.dash-ico.syncing .ico-glyph::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .95);
  border-top-color: transparent;
  animation: dashspin .8s linear infinite;
}
@keyframes dashspin { to { transform: rotate(360deg); } }

/* custom flyout tooltip: freshness + refresh call-to-action */
.rail-tip {
  position: absolute;
  top: 37px;
  left: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  padding: 8px 12px;
  white-space: nowrap;
  z-index: 7;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-3px);
  transition: opacity .15s, transform .15s, visibility 0s .15s;
  pointer-events: none;
}
.rail-item:hover .rail-tip,
.rail-item:focus-within .rail-tip {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: .3s;
}
.tip-updated { font-size: 11px; color: var(--muted); }
.tip-cta {
  margin-top: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--teal);
  animation: ctaPulse 1.6s ease-in-out infinite;
}
.tip-cta.off { color: var(--muted); font-weight: 500; animation: none; }
@keyframes ctaPulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) {
  .tip-cta { animation: none; }
  .dash-ico, #refresh-all { transition: none; }
}

/* ---------- Messages ---------- */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Welcome / starters ---------- */
#welcome {
  margin: auto 0;
  max-width: 560px;
  width: 100%;
  align-self: center;
  animation: fadeUp .4s ease both;
}
.hero { text-align: center; margin-bottom: 20px; }
.hero-mark {
  width: 58px; height: 58px;
  margin: 0 auto 12px;
  border-radius: 17px;
  background: linear-gradient(135deg, var(--navy-deep), var(--navy));
  color: #7fd4d3;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}
.hero h2 { font-size: 18px; margin: 0 0 6px; font-weight: 700; }
.hero p { color: var(--muted); margin: 0 auto; max-width: 420px; line-height: 1.5; }

.starter-group { margin-top: 18px; }
.starter-group-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  padding-left: 2px;
}
.starter {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.starter:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
  border-color: var(--teal);
}
.starter:active { transform: translateY(0); }
.starter-icon { font-size: 17px; flex-shrink: 0; }

.starter-row { display: flex; gap: 8px; }
.starter-meta { flex: 1; padding: 11px 13px; }
.starter-text { font-size: 12.5px; font-weight: 600; }

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.starter-card { padding: 11px 13px; align-items: flex-start; }
.starter-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.starter-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--chip-text);
  letter-spacing: .3px;
}
.starter-q { font-size: 12px; color: var(--muted); line-height: 1.35; }

@media (max-width: 430px) {
  .starter-grid { grid-template-columns: 1fr; }
  .starter-row { flex-direction: column; }
}

/* ---------- Chat bubbles ---------- */
.msg-row {
  display: flex;
  gap: 9px;
  max-width: 94%;
  animation: fadeUp .25s ease both;
}
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.bot { align-self: flex-start; }

.avatar {
  width: 28px; height: 28px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.avatar.bot-avatar {
  background: linear-gradient(135deg, var(--navy-deep), var(--navy));
  color: #7fd4d3;
  box-shadow: var(--shadow);
}

.msg { line-height: 1.55; min-width: 0; }
.msg.user {
  background: var(--user-bubble);
  color: var(--user-text);
  padding: 9px 14px;
  border-radius: 15px 15px 4px 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}
.msg.bot {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  padding: 11px 15px;
  border-radius: 4px 15px 15px 15px;
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.msg.bot > :first-child { margin-top: 0; }
.msg.bot > :last-child { margin-bottom: 0; }
.msg.bot p { margin: 6px 0; }
.msg.bot h1, .msg.bot h2, .msg.bot h3 { font-size: 14px; margin: 10px 0 4px; }
.msg.bot ul, .msg.bot ol { margin: 6px 0; padding-left: 20px; }
.msg.bot a { color: var(--accent); font-weight: 600; text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.msg.bot a:hover { border-bottom-color: var(--accent); }
.msg.bot code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: Consolas, monospace;
  font-size: 12px;
}
.msg.bot pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  overflow-x: auto;
  margin: 9px 0;
}
.msg.bot pre code {
  background: none;
  padding: 0;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

/* ---------- Mermaid diagrams ---------- */
.mermaid-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 560px;
  box-shadow: var(--shadow);
}
.mermaid-block svg {
  display: block;
  margin: 0 auto;
}
.mermaid-loading {
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
  padding: 6px 2px;
}
.mermaid-error {
  color: var(--error-text);
  background: var(--error-bg);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12.5px;
  margin-bottom: 8px;
}
.msg.bot table {
  border-collapse: separate;
  border-spacing: 0;
  margin: 9px 0;
  font-size: 12.5px;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.msg.bot th, .msg.bot td {
  padding: 6px 11px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.msg.bot tr:last-child td { border-bottom: none; }
.msg.bot th {
  background: var(--chip-bg);
  color: var(--chip-text);
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .3px;
}
.msg.bot tr:nth-child(even) td { background: color-mix(in srgb, var(--border) 22%, transparent); }

.msg.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 12px;
  padding: 9px 13px;
}

/* typing indicator */
.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 2px 0;
}
.typing-label { color: var(--muted); font-size: 12.5px; margin-right: 5px; }
.typing .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--teal);
  flex-shrink: 0;
  animation: blink 1.2s infinite both;
}
.typing .dot:nth-child(3) { animation-delay: .2s; }
.typing .dot:nth-child(4) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Composer ---------- */
#composer {
  flex-shrink: 0;
  padding: 12px 16px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#error-banner {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 10px;
  padding: 8px 11px;
  margin-bottom: 9px;
  font-size: 12px;
}
.input-row {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 15px;
  padding: 6px 6px 6px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input-row:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 18%, transparent);
}
#input {
  flex: 1;
  resize: none;
  border: none;
  padding: 7px 0;
  font: inherit;
  background: transparent;
  color: var(--text);
  max-height: 110px;
  outline: none;
}
#input::placeholder { color: var(--muted); }
#send {
  background: linear-gradient(135deg, var(--navy), #1b5a8e);
  color: #fff;
  border: none;
  border-radius: 11px;
  width: 38px; height: 38px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s, transform .12s;
  box-shadow: var(--shadow);
}
body.dark #send { background: linear-gradient(135deg, #2e7d7c, var(--teal)); }
#send:hover:not(:disabled) { transform: scale(1.05); }
#send:disabled { opacity: .35; cursor: default; }
.composer-hint {
  text-align: center;
  color: var(--muted);
  font-size: 10.5px;
  margin-top: 7px;
  letter-spacing: .2px;
}

/* Embed mode (inside the Power BI custom visual): keep the admin gear visible
   so operators can manage from within the report. The admin page is still
   gated by the admin key, and secrets are masked, so viewers see nothing. */
