/* Design system shared with the coaching app (structure-corpus): Geist + Newsreader,
   quiet neutrals, one petrol-blue accent. Every page links this file. */

/* ── Reset & tokens ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #14181F;
  --ink-2: #3D4552;
  --muted: #5B6472;
  --faint: #8A929E;
  --bg: #FBFBFC;
  --surface: #FFFFFF;
  --sidebar: #F3F4F6;
  --line: #E6E8EC;
  --line-strong: #DDE1E6;
  --hover: #E9ECF0;
  --accent: #2E5E7E;
  --accent-hover: #24506D;
  --accent-soft: #E3EEF4;
  --user-bubble: #EEF2F6;
  --danger: #B3261E;
  --danger-soft: #FCE8E6;
  --success: #1E7A4C;
  --font: 'Geist', system-ui, -apple-system, sans-serif;
  --font-display: 'Newsreader', Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-h: 56px;
}
html, body { height: 100%; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }  /* also for inline SVG */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Navigation ───────────────────────────────────────────────── */
#main-nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 4px;
  height: var(--nav-h); padding: 0 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
#nav-burger {
  display: none; width: 40px; height: 40px; border-radius: 10px;
  background: none; border: none; color: var(--ink-2); cursor: pointer;
  align-items: center; justify-content: center;
}
#nav-burger:hover { background: var(--hover); color: var(--ink); }
#nav-logo { display: flex; align-items: center; margin-right: auto; }
#nav-logo img { height: 34px; width: auto; }
.nav-item {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 999px;
  font-size: 14px; font-weight: 500; color: var(--ink-2); text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item.nav-active { background: #E4E8ED; color: var(--ink); font-weight: 600; }
.nav-icon { padding: 0 11px; }

/* ── Buttons & forms ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  border: 1px solid transparent; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: #F6F7F9; border-color: #C9D3DD; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #F2C6C2; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; height: 46px; font-size: 15px; font-weight: 600; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.input-field {
  width: 100%; height: 42px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px;
  font-size: 15px; color: var(--ink); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-field::placeholder { color: var(--faint); }
.input-field:focus { border-color: #B9C7D3; box-shadow: 0 0 0 3px rgba(46,94,126,0.10); }
.input-field:disabled { background: #F6F7F9; color: var(--muted); }
select.input-field { padding-right: 32px; cursor: pointer; }
.form-msg { display: none; font-size: 13px; margin-top: 10px; }
.form-msg.success { display: block; color: var(--success); }
.form-msg.error { display: block; color: var(--danger); }

/* ── Content pages (profile, admin, energy flows) ─────────────── */
.page {
  width: 100%; max-width: 760px; margin: 0 auto;
  padding: 40px 24px 64px;
  display: flex; flex-direction: column; gap: 20px;
}
.page-wide { max-width: 1200px; }
.page-title {
  font-family: var(--font-display); font-style: italic; font-weight: 400;
  font-size: 36px; line-height: 1.15; letter-spacing: -0.02em; color: var(--ink);
}
.page-subtitle { color: var(--muted); font-size: 15px; margin-top: -8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.card-row .card-text-title { font-size: 14px; font-weight: 600; }
.card-row .card-text-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--muted); }
.info-value { font-weight: 500; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent);
}
.badge-admin { background: #EFE9F7; color: #6A4C93; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left; padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--muted);
  background: #F7F8FA; border-bottom: 1px solid var(--line);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.table-card { padding: 0; overflow: hidden; }
.table-card .table-header { display: flex; align-items: baseline; justify-content: space-between; padding: 20px 24px 14px; }
.table-card .card-title { margin: 0; }
.table-scroll { overflow-x: auto; }
.empty-state { text-align: center; padding: 36px 24px; color: var(--muted); font-size: 14px; }
.muted { color: var(--muted); }

/* ── Auth pages (login, invite) ───────────────────────────────── */
.auth-body { background: var(--surface); }
.auth-page {
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 360px; min-height: 100vh; min-height: 100dvh;
  margin: 0 auto; padding: 0 24px;
}
.auth-top {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding-top: 20vh; padding-bottom: 36px; text-align: center;
}
.auth-logo { height: 64px; width: auto; }
.auth-title {
  font-family: var(--font-display); font-style: italic; font-weight: 400;
  font-size: 30px; line-height: 1.2; letter-spacing: -0.01em;
}
.auth-subtitle { font-size: 14px; color: var(--muted); margin-top: -8px; }
.auth-form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.auth-form .form-group { margin-bottom: 0; }
.auth-form .input-field { height: 48px; }
.auth-form .btn-block { margin-top: 8px; }
.auth-error {
  display: none; background: #FEF2F2; color: var(--danger);
  font-size: 13px; padding: 9px 14px; border-radius: 8px; text-align: center;
}
.auth-error.show { display: block; }
.auth-success {
  display: none; background: #ECF7F1; color: var(--success);
  font-size: 13px; padding: 9px 14px; border-radius: 8px; text-align: center;
}
.auth-success.show { display: block; }
.auth-bottom { margin-top: auto; padding: 32px 0; font-size: 12px; color: var(--faint); }

/* ── Chat page ────────────────────────────────────────────────── */
.app-body { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
#chat-page { display: flex; flex: 1; min-height: 0; overflow: hidden; }

#conversation-sidebar {
  width: 272px; min-width: 272px;
  background: var(--sidebar); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
#sidebar-new-btn {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 12px 10px; height: 40px; padding: 0 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 10px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  box-shadow: 0 1px 2px rgba(20,24,31,0.04);
  transition: background 0.15s, border-color 0.15s;
}
#sidebar-new-btn:hover { background: #F8F9FA; border-color: #C9D3DD; }
#sidebar-list {
  flex: 1; overflow-y: auto; padding: 0 12px 16px;
  scrollbar-width: thin; scrollbar-color: #D5D9DF transparent;
}
.sidebar-group { font-size: 12px; font-weight: 500; color: var(--muted); padding: 14px 12px 4px; }
.sidebar-group:first-child { padding-top: 4px; }
.sidebar-item {
  display: flex; align-items: center; gap: 4px;
  height: 36px; padding: 0 4px 0 12px; margin-bottom: 1px;
  border-radius: 8px; cursor: pointer;
  color: var(--ink-2); font-size: 14px; transition: background 0.12s;
}
.sidebar-item:hover { background: var(--hover); }
.sidebar-item.active, .sidebar-item.active:hover {
  background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20,24,31,0.06);
}
.sidebar-item-preview { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item.is-new .sidebar-item-preview { font-style: italic; color: var(--muted); }
.sidebar-delete {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted); cursor: pointer;
  opacity: 0; transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.sidebar-item:hover .sidebar-delete, .sidebar-item.active .sidebar-delete, .sidebar-delete:focus-visible { opacity: 1; }
.sidebar-delete:hover { color: var(--danger); background: var(--danger-soft); }
.sidebar-empty { padding: 20px 14px; text-align: center; font-size: 13px; color: var(--muted); }
#sidebar-overlay { display: none; }

#chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
#chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 40px 24px 24px;
  display: flex; flex-direction: column; gap: 32px;
}
#chat-messages > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }

/* Empty state: greeting, composer and suggestions centered */
.chat-welcome, .welcome-suggestions { display: none; }
#chat-page.is-empty #chat-main { justify-content: center; overflow-y: auto; padding: 32px 0; }
#chat-page.is-empty #chat-messages { display: none; }
#chat-page.is-empty .chat-welcome { display: flex; }
#chat-page.is-empty .welcome-suggestions { display: grid; }
.chat-welcome {
  flex-direction: column; align-items: center; gap: 12px;
  text-align: center; padding: 0 24px 28px;
}
.welcome-title {
  font-family: var(--font-display); font-style: italic; font-weight: 400;
  font-size: 44px; line-height: 1.12; letter-spacing: -0.02em; max-width: 760px;
}
.welcome-subtitle { font-size: 15px; color: var(--muted); max-width: 560px; }
.welcome-suggestions {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;
  width: 100%; max-width: 848px; margin: 0 auto; padding: 16px 24px 0;
}
.suggestion-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  font-size: 14px; font-weight: 500; line-height: 1.4; color: var(--ink);
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
}
.suggestion-btn:hover { border-color: #C9D3DD; box-shadow: 0 4px 16px rgba(20,24,31,0.06); }
.suggestion-icon {
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.suggestion-kind { font-size: 12px; font-weight: 500; color: var(--muted); margin-top: auto; }

/* Messages */
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-user .msg-bubble {
  background: var(--user-bubble); border-radius: 20px 20px 6px 20px;
  padding: 10px 18px; max-width: 78%; white-space: pre-wrap; overflow-wrap: anywhere;
}
.chat-msg-assistant { align-items: flex-start; gap: 14px; }
.msg-avatar {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.msg-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.msg-content { font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4 {
  margin: 18px 0 6px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em;
}
.msg-content > :first-child { margin-top: 0; }
.msg-content p { margin: 0 0 12px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 6px 0 12px; padding-left: 24px; }
.msg-content li { margin-bottom: 6px; }
.msg-content strong { font-weight: 600; }
.msg-content a { color: var(--accent); text-underline-offset: 2px; }
.msg-content table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.msg-content th, .msg-content td { border: 1px solid #D8DDE4; padding: 6px 10px; text-align: left; vertical-align: top; }
.msg-content th { background: #F3F5F8; font-weight: 600; }
.msg-content code { font-family: var(--mono); font-size: 13px; background: #F1F3F5; padding: 1px 5px; border-radius: 4px; }
.msg-content blockquote { border-left: 3px solid var(--line-strong); padding-left: 12px; color: var(--ink-2); }
.msg-subtask { font-size: 15px; font-weight: 600; margin-top: 4px; }
.msg-note { color: var(--muted); font-style: italic; }
.msg-error { color: var(--danger); }

.msg-actions { display: flex; gap: 2px; margin-left: -8px; }
.msg-action {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.msg-action svg { width: 16px; height: 16px; }
.msg-action:hover { background: #EEF1F4; color: var(--ink); }
.msg-action.up.active { color: var(--accent); background: var(--accent-soft); }
.msg-action.down.active { color: var(--danger); background: var(--danger-soft); }
.msg-action.copied { color: var(--accent); }

/* Typing / status indicator */
.typing { display: flex; align-items: center; gap: 10px; min-height: 30px; }
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: typing-pulse 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
.typing-status { font-size: 14px; color: var(--muted); }
@keyframes typing-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

/* Composer */
#chat-input-area { width: 100%; max-width: 808px; margin: 0 auto; padding: 0 24px 20px; flex-shrink: 0; }
.composer {
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 22px; padding: 14px 12px 10px 20px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: 0 6px 24px rgba(20,24,31,0.06), 0 1px 2px rgba(20,24,31,0.04);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: #B9C7D3;
  box-shadow: 0 8px 28px rgba(20,24,31,0.08), 0 0 0 3px rgba(46,94,126,0.08);
}
#question {
  width: 100%; border: 0; outline: none; resize: none; background: transparent;
  padding: 2px 0; font-size: 15px; line-height: 1.55; color: var(--ink);
  min-height: 26px; max-height: 200px;
}
#question::placeholder { color: var(--faint); }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-hint { font-size: 12px; color: var(--faint); }
#send-button {
  width: 38px; height: 38px; border-radius: 50%; border: none; margin-left: auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; cursor: pointer; transition: background 0.15s;
}
#send-button:hover:not(:disabled) { background: var(--accent-hover); }
#send-button:disabled { background: #C9D3DD; cursor: not-allowed; }
#send-button.stop-mode { background: var(--ink); }

/* ── Visualizations (renderVisualization.js) ──────────────────── */
.viz-block { width: 100%; }
.nice-card {
  width: 100%; margin: 0; padding: 20px 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.nice-title { margin: 0 0 14px; font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.nice-list { columns: 2; column-gap: 20px; list-style: none; font-size: 14px; }
.nice-list-item {
  padding: 8px 12px; margin: 5px 0; border-radius: 8px;
  background: #F7F8FA; border-left: 2px solid var(--accent); color: var(--ink-2); list-style: none;
}
.nice-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.nice-table th {
  background: #F7F8FA; color: var(--muted); padding: 9px 14px; text-align: left;
  font-size: 12px; font-weight: 600; border-bottom: 1px solid var(--line);
}
.nice-table td { padding: 9px 14px; border-bottom: 1px solid #F0F1F3; color: var(--ink); }
.nice-table tbody tr:last-child td { border-bottom: none; }
.nice-table tbody tr:hover { background: #FAFBFC; }
.nice-table-card { overflow-x: auto; }
.warnings-banner { border-radius: 8px !important; }

.sql-toggle-btn {
  width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--line-strong); color: var(--faint);
  font-size: 14px; line-height: 1; cursor: pointer; transition: all 0.15s;
}
.sql-toggle-btn:hover { background: #F6F7F9; color: var(--ink-2); border-color: #C9D3DD; }
.sql-details { margin-top: 12px; padding: 14px; background: #F7F8FA; border-radius: 10px; border: 1px solid var(--line); }
.sql-section { margin-bottom: 16px; }
.sql-section:last-child { margin-bottom: 0; }
.sql-label { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.sql-translation { font-size: 13px; color: var(--ink-2); margin-bottom: 8px; line-height: 1.45; }
.sql-query {
  margin: 0; padding: 10px 12px; border-radius: 8px;
  background: #1B1F27; color: #E6E8EC; font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
}

/* ── Energy flows page ────────────────────────────────────────── */
.controls { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.controls .form-group { margin-bottom: 0; min-width: 220px; }
#sankey-chart { width: 100%; min-height: 600px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 400px; color: var(--muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chart-note { font-size: 13px; color: var(--muted); }

/* ── Dialog (replaces native confirm/alert) ───────────────────── */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(20,24,31,0.35);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog-box {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px;
  padding: 22px 22px 18px; box-shadow: 0 16px 48px rgba(20,24,31,0.18);
}
.dialog-message { font-size: 15px; line-height: 1.5; margin-bottom: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #main-nav { padding: 0 8px; }
  #nav-burger { display: flex; }
  .nav-label { display: none; }
  .nav-item { padding: 0 11px; }

  #conversation-sidebar {
    display: none; position: fixed; left: 0; top: var(--nav-h); bottom: 0;
    z-index: 100; width: 288px; box-shadow: 8px 0 32px rgba(20,24,31,0.12);
  }
  #conversation-sidebar.open { display: flex; }
  #sidebar-overlay.open {
    display: block; position: fixed; inset: var(--nav-h) 0 0 0;
    background: rgba(20,24,31,0.3); z-index: 99;
  }
  .sidebar-delete { opacity: 1; }

  #chat-messages { padding: 24px 16px 16px; gap: 24px; }
  #chat-input-area { padding: 0 12px 14px; }
  .composer { flex-direction: row; align-items: flex-end; gap: 4px; padding: 6px 6px 6px 16px; border-radius: 28px; }
  .composer-hint { display: none; }
  #question { font-size: 16px; padding: 10px 0; } /* 16px: no iOS auto-zoom */
  #send-button { width: 44px; height: 44px; }
  .chat-msg-assistant { gap: 10px; }
  .msg-avatar { width: 26px; height: 26px; border-radius: 8px; }
  .chat-msg-user .msg-bubble { max-width: 88%; }
  .welcome-title { font-size: 32px; }
  .welcome-suggestions { padding: 12px 12px 0; }
  .suggestion-btn { flex-direction: row; align-items: center; padding: 12px 14px; }
  .suggestion-kind { display: none; }
  .nice-list { columns: 1; }

  .page { padding: 28px 16px 48px; }
  .page-title { font-size: 30px; }
  .card-row { flex-direction: column; align-items: flex-start; }
}

.verified-badge {
  display: inline-block; font-size: 10px; font-weight: 600; color: #1F6B45;
  background: #E6F2EA; border: 1px solid #BFDCCB; border-radius: 999px; padding: 1px 7px; margin-right: 6px;
}

.report-btn {
  margin-left: auto; font: inherit; font-size: 13px; font-weight: 500; color: var(--accent);
  background: var(--accent-soft); border: 1px solid transparent; border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.report-btn:hover { border-color: var(--accent); }
#chat-page.is-empty .report-btn { display: none; }

/* ── Chart cards (renderVisualization.js, ECharts) ────────────── */
.chart-card {
  width: 100%; margin: 0; padding: 18px 20px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.chart-head-text { min-width: 0; }
.chart-title { font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; line-height: 1.35; }
.chart-sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.chart-tools { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.chart-tabs { display: inline-flex; padding: 2px; border-radius: 8px; background: #F1F3F5; margin-right: 4px; }
.chart-tab {
  font: inherit; font-size: 12px; font-weight: 500; color: var(--muted);
  background: none; border: none; border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.chart-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20,24,31,0.08); }
.chart-icon-btn {
  font: inherit; font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted);
  background: none; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; cursor: pointer;
}
.chart-icon-btn:hover, .chart-tab:hover { color: var(--ink); }
.chart-icon-btn:hover { border-color: var(--line-strong); background: #F7F8FA; }
.chart-body { width: 100%; }
.chart-table-view .chart-table-wrap { max-height: 420px; overflow: auto; }
.chart-empty { padding: 20px 0; font-size: 14px; color: var(--muted); }
.chart-warn {
  margin-bottom: 12px; padding: 8px 12px; border-radius: 8px;
  background: #FBF6EA; border: 1px solid #EEDFB8; color: #74591C; font-size: 13px;
}
.chart-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid #F0F1F3;
}
.chart-foot-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chart-source { font-size: 11.5px; color: var(--faint); }
.chart-link {
  font: inherit; font-size: 12px; color: var(--muted); background: none; border: none;
  padding: 2px 0; cursor: pointer; white-space: nowrap;
}
.chart-link:hover { color: var(--accent); text-decoration: underline; }

.chart-card-kpi { max-width: 420px; }
.kpi { padding: 2px 0 4px; }
.kpi-value {
  font-size: 40px; font-weight: 600; color: var(--ink); letter-spacing: -0.03em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-unit { margin-left: 8px; font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi-context { margin-top: 6px; font-size: 13px; color: var(--muted); }

.chart-table-wrap { overflow-x: auto; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.chart-table th {
  position: sticky; top: 0; background: var(--surface);
  padding: 8px 12px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.chart-table td { padding: 8px 12px; border-bottom: 1px solid #F2F3F5; color: var(--ink); }
.chart-table .num { text-align: right; }
.chart-table tbody tr:last-child td { border-bottom: none; }
.chart-table tbody tr:hover { background: #FAFBFC; }

@media (max-width: 640px) {
  .chart-card { padding: 14px 14px 10px; border-radius: 14px; }
  .chart-head { flex-direction: column; gap: 10px; }
  .kpi-value { font-size: 32px; }
}

/* Energy flows: node history under the Sankey */
.flow-detail { margin-top: 20px; }
.flow-detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.flow-detail-title { font-size: 18px; font-weight: 600; margin: 0; }
.flow-detail-sub { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.flow-detail-chart { width: 100%; height: 300px; }
.flow-detail-total { height: 240px; margin-bottom: 12px; }
.flow-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.flow-detail-h { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.flow-detail-h span { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
@media (max-width: 800px) { .flow-detail-grid { grid-template-columns: 1fr; } }

/* Energy flows: decarbonation view */
.view-toggle { min-width: 0 !important; }
.view-toggle .chart-tabs { height: 40px; align-items: center; }
.view-toggle .chart-tab { height: 34px; padding: 0 14px; }
.decarb-summary { margin-top: 20px; }
.decarb-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px 24px; margin-bottom: 16px; }
.decarb-kpi { display: flex; gap: 10px; align-items: flex-start; }
.decarb-swatch { width: 10px; height: 36px; border-radius: 3px; flex: none; margin-top: 2px; }
.decarb-kpi-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.decarb-kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.decarb-kpi-label { font-size: 13px; color: var(--ink); }
.decarb-kpi-sub { font-size: 12px; color: var(--muted); }
.decarb-lede { font-size: 15px; line-height: 1.6; margin: 0 0 12px; }
.decarb-hyp summary { cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 500; }
.decarb-src { font-size: 12px; color: var(--muted); margin: 8px 0; }
.decarb-hyp .chart-table td:last-child { color: var(--muted); font-size: 12px; }
.decarb-scope { font-size: 14px; margin: 0 0 14px; }
.decarb-scope span { color: var(--muted); font-size: 12px; }
.decarb-why { margin: 4px 0 14px; }
.decarb-why-sources { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 10px; font-size: 14px; }
.decarb-why-src span { color: var(--muted); font-size: 13px; }
.decarb-swatch-s { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.decarb-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; }
.decarb-why .chart-table td:last-child { color: var(--muted); font-size: 12px; min-width: 260px; }
.decarb-why .chart-table-wrap { max-height: 420px; overflow: auto; }
