@import url('https://fonts.googleapis.com/css2?family=Darker+Grotesque:wght@400;600&family=Inter:wght@400;600&display=swap');

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  /* Colours taken from the Figma design (file 17Rrqz4QK82fI4Y534PDdy). */
  --navy: #12224b;
  --navy-selected: #232c52;
  --green: #73ef96;
  --panel: #f6f7fa;
  --success-bg: #d6fadf;
  --success-text: #315e43;
  --font-display: "Darker Grotesque", "Inter", system-ui, sans-serif;
  --bg: #fbf9ff;
  --surface: #ffffff;
  --border: #e8eaf1;
  --border-strong: #cbd0de;
  --text: #12224b;
  --text-muted: #596582;
  --text-faint: #596582;
  /* The accent is a fill (buttons, highlights); the ink is what text and icons use
     so a pale accent never makes text unreadable. Both follow a client's own accent. */
  --accent: #73ef96;
  --on-accent: #12224b;
  --accent-ink: #12224b;
  --accent-hover: color-mix(in srgb, var(--accent) 88%, white);
  --accent-soft: var(--panel);
  --accent-soft-border: color-mix(in srgb, var(--accent) 25%, white);
  --danger: #d64545;
  --danger-soft: #fdeded;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 22, 30, 0.05);
  --shadow-md: 0 4px 16px rgba(20, 22, 30, 0.08);
}

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

button {
  font-family: inherit;
}

/* ---------- Header ---------- */

#app-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.65rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 5;
}

#brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

#brand svg {
  color: var(--accent-ink);
}

#report-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

#report-picker {
  appearance: none;
  padding: 0.45rem 2rem 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

#report-picker:hover {
  border-color: var(--accent);
}

#report-picker:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#report-select-caret {
  position: absolute;
  right: 0.75rem;
  pointer-events: none;
  color: var(--text-faint);
}

#header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#chat-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s ease, transform 0.1s ease;
}

#chat-toggle:hover {
  background: var(--accent-hover);
}

#chat-toggle:active {
  transform: scale(0.97);
}

#admin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-faint);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

#admin-link:hover {
  background: var(--bg);
  color: var(--accent-ink);
}

#fullscreen-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

#fullscreen-toggle:hover {
  background: var(--bg);
  color: var(--accent-ink);
}

/* Fullscreening #app-shell should fill the screen the same way it fills
   the viewport normally -- the UA fullscreen default is usually fine, but
   this pins the background so there's no flash of white at the edges on
   browsers that don't fully stretch a flex container by default. */
#app-shell:fullscreen,
#app-shell:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: var(--bg);
}

#brand-icon img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

/* ---------- Sidebar ---------- */
/*
  Deliberately its own dark palette, independent of --accent (which stays
  admin-configurable for the rest of the UI) -- this matches the reference
  product's own dark-navy/coral chrome rather than inheriting whatever
  brand colour an admin picks for the content area.
*/
:root {
  --sidebar-bg: #12224b;
  --sidebar-bg-active: #232c52;
  --sidebar-border: #232c52;
  --sidebar-text: #b9becd;
  --sidebar-text-active: #ffffff;
  --sidebar-accent: #73ef96;
  --sidebar-accent-hover: #8af3a9;
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 60px;
}

#app-shell {
  display: flex;
  height: 100vh;
}

#app-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 auto;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.15s ease;
}

#app-sidebar.collapsed {
  width: var(--sidebar-width-collapsed);
}

#page-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  /* Stretched to #app-shell's full 100vh by flexbox, not an explicit
     height -- an explicit 100vh here would stack on top of the shell's
     own 100vh and overflow the viewport. */
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 0.5rem;
}

.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--sidebar-text-active);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand-icon {
  flex: 0 0 auto;
  color: var(--sidebar-accent);
  display: flex;
}

#app-sidebar.collapsed .sidebar-brand-name,
#app-sidebar.collapsed .sidebar-label,
#app-sidebar.collapsed .sidebar-group-label {
  display: none;
}

.sidebar-collapse {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
}

.sidebar-collapse:hover {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
}

#app-sidebar.collapsed .sidebar-collapse svg {
  transform: rotate(180deg);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.6rem 1rem;
}

.sidebar-group-label {
  color: var(--sidebar-text);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.9rem 0.6rem 0.3rem;
  opacity: 0.7;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.6rem;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-item:hover {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
}

.sidebar-item.active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
}

.sidebar-item.featured {
  background: var(--sidebar-accent);
  color: var(--navy);
  margin: 2px 0;
}

.sidebar-item.featured:hover,
.sidebar-item.featured.active {
  background: var(--sidebar-accent-hover);
}

.sidebar-icon {
  flex: 0 0 auto;
  display: flex;
}

.sidebar-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.stub-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  padding: 2rem;
  color: var(--text-muted);
}

.stub-view-icon {
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

.stub-view h2 {
  margin: 0 0 0.4rem;
  color: var(--text);
}

.stub-view p {
  margin: 0;
  max-width: 30ch;
}

/* ---------- Layout ---------- */

#app-main {
  display: flex;
  height: calc(100vh - 55px);
  position: relative;
}

#report-container {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--surface);
}

#stub-view-container {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  overflow-y: auto;
}

#report-container iframe {
  border: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  padding: 2rem;
}

.empty-state svg {
  color: var(--text-faint);
}

.empty-state p {
  margin: 0;
  font-size: 0.9rem;
  max-width: 320px;
  line-height: 1.5;
}

.empty-state.error {
  color: var(--danger);
}

.empty-state.error svg {
  color: var(--danger);
}

/* ---------- Chat resize handle ---------- */

#chat-resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: transparent;
  position: relative;
}

#chat-resize-handle::after {
  content: "";
  position: absolute;
  inset: 0 1px;
  background: var(--border);
  transition: background 0.15s ease;
}

#chat-resize-handle:hover::after,
#chat-resize-handle.dragging::after {
  background: var(--accent);
}

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

#chat-panel {
  width: 380px;
  min-width: 280px;
  max-width: 640px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
}

#chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

#chat-panel-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}

#chat-panel-title svg {
  color: var(--accent-ink);
}

#chat-new,
#chat-history-btn {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.15rem;
  transition: background 0.15s ease, color 0.15s ease;
}

/* The first button in the header pushes the group to the right. */
#chat-history-btn {
  margin-left: auto;
}

#chat-new:hover,
#chat-history-btn:hover {
  background: var(--bg);
  color: var(--text);
}

#chat-history-panel {
  max-height: 45%;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-history-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
}

.chat-history-row.current {
  background: var(--accent-soft);
}

.chat-history-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 8px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  color: inherit;
}

.chat-history-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.chat-history-when {
  font-size: 11px;
  color: var(--text-faint);
}

.chat-history-delete {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text-faint);
  padding: 4px 8px;
  border-radius: 4px;
}

.chat-history-delete:hover {
  color: var(--text);
}

.chat-history-delete.armed {
  color: var(--danger);
}

.chat-history-empty {
  margin: 0;
  padding: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.chat-unsaved {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-faint);
}

#chat-close {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

#chat-close:hover {
  background: var(--bg);
  color: var(--text);
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  /* --text-muted, not --border-strong: the thumb needs 3:1 against the page (WCAG 1.4.11). */
  scrollbar-color: var(--text-muted) transparent;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  position: relative;
}

#chat-empty-state {
  position: static;
  height: 100%;
  padding: 1rem;
}

#chat-empty-state svg {
  color: var(--accent-ink);
  opacity: 0.5;
}

.chat-row {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}

.chat-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-row.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-bubble {
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font-size: 0.86rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-row.user .chat-bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-bottom-right-radius: 4px;
}

.chat-row.assistant .chat-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-row.assistant .chat-bubble.error {
  background: var(--danger-soft);
  border-color: #f4c6c6;
  color: var(--danger);
}

.chat-bubble p {
  margin: 0 0 0.5em;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble ul, .chat-bubble ol {
  margin: 0.3em 0 0.5em;
  padding-left: 1.2em;
}

.chat-bubble strong {
  font-weight: 700;
}

.chat-bubble code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
  font-family: ui-monospace, monospace;
}

/* thinking indicator */

.typing-dots {
  display: inline-flex;
  gap: 3px;
  padding: 0.2rem 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* DAX disclosure */

.dax-disclosure {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-strong);
  padding-top: 0.4rem;
}

.dax-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.1rem 0;
}

.dax-toggle:hover {
  color: var(--text);
}

.dax-toggle svg {
  transition: transform 0.15s ease;
}

.dax-toggle.open svg {
  transform: rotate(90deg);
}

.dax-body {
  display: none;
  margin-top: 0.4rem;
  position: relative;
}

.dax-body.open {
  display: block;
}

.dax-body pre {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  padding-right: 2rem;
}

.dax-copy {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 5px;
  padding: 0.2rem 0.3rem;
  cursor: pointer;
  color: var(--text-faint);
  display: flex;
}

.dax-copy:hover {
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* ---------- charts (D3) ---------- */

.chat-row.has-chart {
  width: 100%;
  max-width: 100%;
}

.chat-row.has-chart .chat-bubble {
  width: 100%;
}

.chat-chart {
  position: relative;
  margin: 0.6rem 0 0;
}

.chat-chart svg {
  max-width: 100%;
  display: block;
  overflow: visible;
}

.chart-enlarge {
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.chart-enlarge:hover {
  color: var(--accent-ink);
  border-color: var(--accent);
}

.chart-tools {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.chat-chart:hover .chart-tools,
.chart-tools:focus-within { opacity: 1; }
.chart-tool, .chart-type {
  font-size: 10px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.chart-tool:hover, .chart-type:hover { color: var(--text); }

/* IBCS chart typography. No gridline styles here by design — the standard
   removes gridlines rather than styling them, and the renderers draw a single
   baseline instead of an axis. */

.chat-chart text,
#chart-modal-body text {
  font-family: inherit;
  fill: #1a1a1a;
}

/* Category labels sit quieter than the data they describe. */
.ibcs-cat {
  font-size: 11px;
  fill: var(--text-muted);
}

/* Direct data labels replace the value axis. */
.ibcs-value {
  font-size: 10.5px;
  font-weight: 600;
  fill: #1a1a1a;
}

.ibcs-series-label {
  font-size: 10.5px;
  font-weight: 600;
}

.ibcs-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.35rem;
}

.ibcs-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

.ibcs-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.ibcs-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.ibcs-swatch {
  width: 10px;
  height: 10px;
  display: inline-block;
}

/* card (single-value KPI) */

.chart-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  text-align: center;
}

.chart-card-value {
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.chart-card-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- enlarge modal ---------- */

#chart-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

#chart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 22, 30, 0.45);
}

#chart-modal-panel {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
  animation: modal-in 0.14s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

#chart-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

#chart-modal-title {
  font-weight: 600;
  font-size: 0.9rem;
}

#chart-modal-close {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
}

#chart-modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

#chart-modal-body {
  padding: 1.25rem;
}

.error-text {
  word-break: break-word;
}

.error-hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.error-details {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.error-details pre {
  white-space: pre-wrap;
  margin: 4px 0 0;
}

.error-dax {
  margin-top: 6px;
  font-size: 11px;
  white-space: pre-wrap;
}

.retry-btn {
  margin-top: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid #f4c6c6;
  background: #fff;
  color: var(--danger);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.retry-btn:hover {
  background: var(--danger-soft);
}

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

#chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

/* The AI disclosure under the input: always visible, never in the way. */
#chat-disclosure {
  margin: -0.35rem 0 0;
  padding: 0 0.85rem 0.6rem;
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--text-faint);
}

#chat-input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-size: 0.85rem;
  background: var(--bg);
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

#chat-send {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

#chat-send:hover {
  background: var(--accent-hover);
}

#chat-send:active {
  transform: scale(0.95);
}

/* While a request is in flight the send arrow becomes a stop square, so the
   one button in reach is always the one that does what is next. */
#chat-send.sending svg {
  display: none;
}

#chat-send.sending::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
}

#chat-send:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}

/* ============ Auth (login/setup) page ============ */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.15rem;
  margin: 0 0 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auth-card h1 svg {
  color: var(--accent-ink);
}

.auth-card p.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 1.5rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-size: 0.88rem;
  font-family: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.field .hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.3rem;
}

/* Small "i" icon with a hover/focus tooltip, used for example values. */
.label-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.label-row label {
  margin-bottom: 0;
}

.info-tip {
  position: relative;
  display: inline-block;
}

.info-icon {
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  line-height: 1;
  cursor: help;
}

.info-icon:hover,
.info-icon:focus-visible {
  color: var(--accent-ink);
  border-color: var(--accent);
  outline: none;
}

.info-tip-body {
  display: none;
  position: absolute;
  left: 50%;
  top: calc(100% + 0.4rem);
  transform: translateX(-50%);
  z-index: 20;
  width: max-content;
  max-width: 17rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.45;
  white-space: normal;
}

.info-tip:hover .info-tip-body,
.info-tip:focus-within .info-tip-body {
  display: block;
}

.info-tip-body code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.74rem;
}

.btn-primary {
  width: 100%;
  padding: 0.65rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}

.btn-secondary {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-danger {
  padding: 0.4rem 0.7rem;
  border: 1px solid #f4c6c6;
  border-radius: 6px;
  background: var(--surface);
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-danger:hover {
  background: var(--danger-soft);
}

.form-message {
  font-size: 0.82rem;
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 1rem;
}

.form-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-message.success {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

/* ============ Admin dashboard ============ */

#admin-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

#admin-header h1 {
  font-size: 1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#admin-header h1 svg {
  color: var(--accent-ink);
}

#admin-header a.back-link {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
}

#admin-header a.back-link:hover {
  color: var(--accent-ink);
}

#admin-main {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  /* #page-content (the sidebar shell's content pane) is fixed to the
     viewport height with its own overflow hidden -- flex:1 + min-height:0
     lets this pane actually shrink to fit it instead of forcing it to its
     content's full height, which is what makes overflow-y:auto here the
     thing that scrolls when the admin content (an open report editor, a
     long table) runs taller than the window. */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.admin-section h2 {
  font-size: 0.95rem;
  margin: 0 0 0.2rem;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  font-size: 0.85rem;
  cursor: pointer;
}

.checkbox-list .checkbox-empty {
  color: var(--text-faint);
  font-size: 0.82rem;
}

.admin-section .section-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 1.2rem;
}

.admin-section .section-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 560px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.logo-preview-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.logo-preview {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
}

.secret-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.secret-status.set::before {
  content: "●";
  color: var(--success-text);
}

.secret-status.unset::before {
  content: "●";
  color: var(--text-faint);
}

#test-powerbi-result {
  margin-top: 0.75rem;
  font-size: 0.82rem;
}

#test-powerbi-result.ok {
  color: var(--success-text);
}

#test-powerbi-result.fail {
  color: var(--danger);
}

.reports-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.reports-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  padding: 0 0.5rem 0.5rem 0;
}

.reports-table td {
  padding: 0.6rem 0.5rem 0.6rem 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.reports-table tr:last-child td {
  border-bottom: none;
}

.report-row-name {
  font-weight: 600;
}

.report-row-id {
  color: var(--text-faint);
  font-size: 0.75rem;
}

#report-editor {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

#report-editor h3 {
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.report-editor-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

/* visual-context answers */

.thinking-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.visual-context {
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-strong);
  font-size: 0.72rem;
  color: var(--text-faint);
  line-height: 1.4;
}

/* suggested prompts */

#chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-top: 0.85rem;
}

.suggestion {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.suggestion:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent-soft);
}

/* follow-ups — where to go next, under every answer */

.followups {
  margin-top: 0.75rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.followups-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.followup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.followup-chips .suggestion {
  text-align: left;
}

/* clarifying question — a prompt back to the user, not a finding */

.chat-row.assistant .chat-bubble.clarify {
  background: var(--accent-soft);
  border-color: var(--accent-soft-border);
}

.chat-bubble.clarify::before {
  content: "Needs clarification";
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--accent-ink);
  margin-bottom: 0.3rem;
}

/* authored DAX — code the user will paste into Power BI */

.authored-dax {
  margin-top: 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
}

.authored-dax-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.authored-dax pre {
  margin: 0;
  padding: 0.55rem;
  font-family: ui-monospace, monospace;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--text);
  white-space: pre-wrap;
  background: var(--surface);
}

.dax-validation {
  padding: 0.4rem 0.55rem;
  font-size: 0.72rem;
  border-top: 1px solid var(--border);
}

.dax-validation.ok {
  color: var(--success-text);
  background: var(--success-bg);
}

.dax-validation.fail {
  color: var(--danger);
  background: var(--danger-soft);
}


/* table — when the values themselves are the point */

.chart-table-wrap {
  margin-top: 0.1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chart-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.chart-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  background: var(--bg);
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.chart-table td {
  padding: 0.35rem 0.55rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.chart-table tbody tr:last-child td {
  border-bottom: none;
}

.chart-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* clarifying questions with selectable answers */

.clarify-questions {
  margin-top: 0.7rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--accent-soft-border);
}

.clarify-q + .clarify-q {
  margin-top: 0.6rem;
}

.clarify-ask {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text);
}

.clarify-hint {
  margin-left: 0.4rem;
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.clarify-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* A tickable answer. The native control is kept — it carries the keyboard
   behaviour and the checkbox/radio distinction that tells the user whether a
   second tick adds to the first or replaces it. */

.clarify-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.32rem 0.7rem 0.32rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.clarify-option:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.clarify-option input {
  margin: 0;
  width: 0.82rem;
  height: 0.82rem;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

.clarify-option.chosen {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 500;
}

.clarify-options .suggestion.chosen {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.clarify-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.clarify-actions .btn-primary {
  padding: 0.35rem 0.8rem;
  font-size: 0.78rem;
}

.clarify-note {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.clarify-skip {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.clarify-skip:hover { color: var(--text); }

/* IBCS table: no vertical rules, hairline horizontals, figures right-aligned
   with tabular numerals so columns of numbers line up for scanning. */

.ibcs-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.78rem;
}

.ibcs-table th {
  background: none;
  border-bottom: 1px solid #1a1a1a;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  padding: 0.3rem 0.5rem;
  white-space: nowrap;
}

.ibcs-table th.num,
.ibcs-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ibcs-table td {
  border-bottom: 1px solid #eceef1;
  padding: 0.32rem 0.5rem;
  color: #1a1a1a;
}

.ibcs-table tbody tr:last-child td {
  border-bottom: none;
}

/* Colour appears only on variance, so red always means the same thing. */
.ibcs-table td.var-good { color: #1f7a4d; }
.ibcs-table td.var-bad  { color: #c0362c; }

.chart-table-wrap {
  border: none;
  border-radius: 0;
}

.chart-card-value {
  color: #1a1a1a !important;
}

/* sync-from-model reconciliation report */

.model-sync { display: flex; align-items: center; gap: 10px; }
.model-report {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.model-report pre { white-space: pre-wrap; margin: 6px 0 0; font-size: 11px; }
.model-report-warn { color: var(--text); font-weight: 600; margin-top: 6px; }
.model-report-ok { color: var(--text); font-weight: 600; margin-top: 6px; }

/* ---------- Mobile ---------- */
/*
  Everything above was designed at desktop widths -- the sidebar is a fixed
  240px column, the chat panel sits beside the report at 380px+, and chart
  tools only ever appear on :hover, none of which survives a phone-width
  screen or a touch input. This section adapts the same markup rather than
  branching it.
*/

@media (max-width: 768px) {
  /* Sidebar: the icon-only rail the desktop collapse toggle already
     produces (--sidebar-width-collapsed) becomes the only state on mobile,
     rather than building a second off-canvas-drawer version of the same
     nav. Cheap, and a 240px column would otherwise eat most of the screen. */
  #app-sidebar,
  #app-sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
  }
  #app-sidebar .sidebar-brand-name,
  #app-sidebar .sidebar-label,
  #app-sidebar .sidebar-group-label,
  #app-sidebar .sidebar-collapse {
    display: none;
  }
  .sidebar-brand {
    padding: 0.85rem 0.4rem 0.6rem;
    justify-content: center;
  }
  .sidebar-item {
    justify-content: center;
    padding: 0.65rem;
  }

  /* Header: the brand wordmark and the signed-in user's email are the
     first things to give way -- the report picker and the primary actions
     (chat, admin, logout) are what someone on a phone actually came for.
     flex-wrap is a safety net, not the primary fix, for whatever still
     doesn't fit at very narrow widths. */
  /* Vertical padding is left alone -- #app-main and #chat-panel both size
     themselves off the header's ~55px desktop height (see the "calc(100vh
     - 55px)" comment above), so shrinking it here would leave a gap or a
     sliver of clipped content below the header on mobile. */
  #app-header {
    gap: 0.5rem;
    padding: 0.65rem 0.65rem;
    flex-wrap: wrap;
  }
  #brand-name {
    display: none;
  }
  #report-select-wrap {
    flex: 1;
    min-width: 0;
  }
  #report-picker {
    width: 100%;
    max-width: 100%;
  }
  #chat-toggle span {
    display: none;
  }
  #chat-toggle {
    margin-left: 0;
    padding: 0.5rem;
  }
  #viewer-user-email {
    display: none;
  }

  /* Report + chat: a 380px+ chat column beside the report would leave next
     to nothing for either on a phone-width screen, so chat becomes a
     full-screen overlay instead of a side panel. The resize handle exists
     to drag that side-by-side split with a mouse, which doesn't apply once
     there's no split to drag -- hidden outright, `!important` because
     JS toggles its own `hidden` attribute independently of this layout. */
  #chat-resize-handle {
    display: none !important;
  }
  /* `!important` because app.js restores a saved desktop width as an
     inline style on load, which would otherwise outrank this rule. */
  #chat-panel {
    position: fixed;
    inset: 0;
    top: 55px; /* below #app-header, matching #app-main's own offset below */
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
    z-index: 20;
    border-left: none;
  }

  /* Chart tools (enlarge, switch type) were opacity:0 until :hover --
     a state a touchscreen never enters, which made them unreachable on
     mobile. Always visible here instead of chasing a tap-to-reveal
     equivalent for a control this small. */
  .chart-tools {
    opacity: 1;
  }

  #chart-modal {
    padding: 0.75rem;
  }

  /* Below 16px, iOS Safari zooms the whole page in on focus rather than
     just the field -- every text input in the app is sized well under that
     today (chat input is 0.85rem ≈ 11.9px at this file's 14px root). */
  #chat-input,
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
  }

  /* Admin: wide data tables (reports, users, groups) don't reflow at
     phone width -- scope them to their own horizontal scroll rather than
     letting them force the whole page wider. (.chart-table already scrolls
     via its own .chart-table-wrap ancestor, so it's not included here.) */
  .reports-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  #admin-header {
    padding: 0.65rem 1rem;
    gap: 0.6rem;
  }

  #admin-main {
    padding: 1rem 1rem 3rem;
  }
}

/* Headings use the design's display face. */
.auth-card h1,
#admin-header h1,
.admin-section h2,
.stub-view h2,
.sidebar-brand-name,
#brand-name {
  font-family: var(--font-display);
}
