:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #0f1535;
  --muted: #68708d;
  --line: #e5e8f2;
  --indigo: #4f37d6;
  --violet: #7657ff;
  --blue: #2563eb;
  --soft-violet: #eeeaff;
  --shadow-soft: 0 10px 24px rgba(22, 29, 78, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea, input { font: inherit; }

.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ---- Top bar ---- */
.topbar {
  height: 70px;
  flex: 0 0 70px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background:
    radial-gradient(circle at 10% 10%, rgba(109, 91, 255, 0.8), transparent 28%),
    linear-gradient(110deg, #17205f 0%, #33208f 48%, #4f2fd4 100%);
  box-shadow: 0 12px 34px rgba(43, 30, 128, 0.22);
  z-index: 5;
}
.brand-wrap, .top-actions { display: flex; align-items: center; gap: 14px; }
.icon-button {
  border: 0; width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 14px; color: white;
  background: rgba(255, 255, 255, 0.10); cursor: pointer; font-size: 18px;
}
.icon-button:hover { background: rgba(255,255,255,.2); }
.brand-divider { width: 1px; height: 34px; background: rgba(255,255,255,.22); margin: 0 4px; }
.brand-logo { height: 30px; display: flex; align-items: end; gap: 4px; }
.logo-bar { width: 6px; border-radius: 8px 8px 2px 2px; display: block; }
.logo-bar.one { height: 18px; background: #60a5fa; }
.logo-bar.two { height: 25px; background: #22c55e; }
.logo-bar.three { height: 13px; background: #fb923c; }
.brand-line { display: flex; align-items: baseline; gap: 10px; }
.brand-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.brand-subtitle { font-size: 14px; font-weight: 600; color: rgba(255,255,255,.82); }
.new-chat {
  height: 42px; padding: 0 18px;
  border: 1px solid rgba(255,255,255,.22); border-radius: 999px;
  color: white; background: rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 9px; font-weight: 700; cursor: pointer;
}
.new-chat:hover { background: rgba(255,255,255,.18); }
.avatar { width: 42px; height: 42px; border: 0; border-radius: 50%; background: white; color: #20176d; font-weight: 800; cursor: pointer; }
.logout { color: #fff; text-decoration: none; font-weight: 700; font-size: 14px; padding: 9px 14px; border: 1px solid rgba(255,255,255,.22); border-radius: 999px; background: rgba(255,255,255,.06); }
.logout:hover { background: rgba(255,255,255,.18); }

/* ---- 3-column shell ---- */
.shell {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 440px;
  min-height: 0;
}
.shell.nav-collapsed { grid-template-columns: minmax(0, 1fr) 440px; }
.shell.nav-collapsed .sidebar { display: none; }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 24px 12px;
  display: flex; flex-direction: column;
  min-height: 0; overflow-y: auto;
}
.sidebar-title {
  text-transform: uppercase; font-size: 13px; font-weight: 850;
  letter-spacing: .06em; color: #10194e; margin: 0 12px 26px;
}
.nav-list { display: grid; gap: 10px; }
.nav-item {
  min-height: 54px; border: 0; border-radius: 14px; padding: 12px 14px;
  color: #28315c; background: transparent;
  display: flex; align-items: center; gap: 13px;
  text-align: left; cursor: pointer; transition: .2s ease;
  font-size: 14px; font-weight: 600;
}
.nav-item:hover { background: #f3f4ff; }
.nav-item.active {
  color: white;
  background: linear-gradient(135deg, var(--indigo), var(--violet));
  box-shadow: 0 14px 28px rgba(79,55,214,.28);
}
.nav-icon { width: 22px; height: 22px; display: grid; place-items: center; flex: 0 0 auto; font-size: 18px; }
.collapse { margin-top: auto; border: 0; background: transparent; color: #36406d; display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.collapse:hover { color: var(--indigo); }

/* ---- Middle: the Power BI report ---- */
.report-main { padding: 16px; min-height: 0; min-width: 0; }
.report-frame {
  width: 100%; height: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.report-frame iframe { border: 0; width: 100%; height: 100%; display: block; }
.report-frame .error { padding: 22px; color: #b00020; font-size: 14px; }

/* ---- Chat panel ---- */
.chat-panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 22px 22px 18px;
  display: flex; flex-direction: column;
  min-height: 0;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; }
.chat-head div { display: flex; align-items: center; gap: 12px; color: #4f37d6; }
.chat-head .spark { font-size: 18px; }
.chat-head h2 { margin: 0; color: #151a39; font-size: 18px; letter-spacing: -0.02em; }

.messages { flex: 1 1 auto; overflow-y: auto; padding: 8px 2px; margin-top: 8px; }

/* user message bubble */
.user-bubble {
  width: 90%; margin: 18px 0 18px auto;
  padding: 16px 18px 12px; border-radius: 14px;
  color: white; background: linear-gradient(135deg, #3625bd, #7657ff);
  box-shadow: 0 18px 38px rgba(79,55,214,.28);
}
.user-bubble p { margin: 0 0 10px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.user-bubble .time { display: block; text-align: right; font-size: 12px; color: rgba(255,255,255,.78); }

/* assistant answer card */
.answer-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; box-shadow: var(--shadow-soft);
  padding: 18px 20px; margin: 0 0 18px;
}
.answer-intro { display: flex; align-items: center; gap: 10px; color: #68708d; margin-bottom: 12px; font-size: 14px; }
.answer-intro .spark { color: var(--indigo); }
.answer-card.thinking { color: var(--muted); }

/* markdown inside the answer */
.md { font-size: 15px; line-height: 1.55; color: var(--text); }
.md:not(:last-child) { margin-bottom: 8px; }
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 10px; padding-left: 22px; display: grid; gap: 10px; }
.md li { margin: 0; }
.md strong { color: var(--indigo); }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 8px 0 6px; letter-spacing: -0.01em; }
.md code { background: #eef0f7; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.md pre { background: #14163a; color: #e6edf3; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.md pre code { background: none; padding: 0; color: inherit; }

/* live "what I'm doing" steps */
.steps { display: flex; flex-direction: column; gap: 6px; }
.step { font-size: 14px; line-height: 1.35; padding-left: 22px; position: relative; color: var(--muted); }
.step::before { position: absolute; left: 0; top: 1px; }
.step.active { color: var(--text); font-weight: 600; }
.step.active::before {
  content: ""; width: 11px; height: 11px; margin-top: 3px;
  border: 2px solid var(--violet); border-top-color: transparent; border-radius: 50%;
  animation: step-spin .7s linear infinite;
}
.step.done { color: var(--indigo); }
.step.done::before { content: "✓"; color: var(--violet); font-weight: 800; }
@keyframes step-spin { to { transform: rotate(360deg); } }

/* charts inside an answer */
.chart-wrap { background: #fbfcff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 10px 12px; margin: 12px 0; }
.chart-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 8px; text-align: center; }
.chart-box { position: relative; width: 100%; height: 220px; }
.chart-error { font-size: 13px; color: #b00020; margin: 8px 0; }

/* ---- Composer ---- */
.composer {
  flex: 0 0 auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow-soft);
  padding: 14px 16px; margin-top: 8px;
}
.composer textarea {
  width: 100%; min-height: 70px; max-height: 200px;
  border: 0; resize: none; outline: 0; color: var(--text);
  font-size: 15px; line-height: 1.5; background: transparent;
}
.composer textarea::placeholder { color: #98a0ba; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #506080; margin-top: 6px; }
.composer-actions .hint { font-size: 12px; color: #98a0ba; }
.composer-actions button {
  border: 0; border-radius: 999px; color: white;
  background: linear-gradient(135deg, #4f37d6, #7657ff);
  padding: 11px 20px; display: flex; gap: 8px; align-items: center;
  font-weight: 800; box-shadow: 0 14px 26px rgba(79,55,214,.26); cursor: pointer;
}
.composer-actions button:disabled { opacity: .55; cursor: not-allowed; }
.disclaimer { margin: 12px 0 0; color: #8a91a9; text-align: center; font-size: 12px; flex: 0 0 auto; }

@media (max-width: 1320px) {
  .shell { grid-template-columns: 220px minmax(0, 1fr) 380px; }
  .shell.nav-collapsed { grid-template-columns: minmax(0, 1fr) 380px; }
}
@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-panel { border-left: 0; }
}
