/* MAESTRO Research — Themed Professional Styles */

/* Login page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-card {
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.8em;
  margin-bottom: 0.25rem;
}

.login-card input {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border, #ccc);
  border-radius: 6px;
  font-size: 0.95em;
}

.login-card button {
  width: 100%;
  padding: 0.65rem;
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95em;
  font-weight: 600;
}

.login-card button:hover {
  opacity: 0.9;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --border: #e5e7eb;
  --card-header-bg: #f8fafc;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Buttons inherit font from body by default browsers render them in
   a system UI font that looks out of place next to every other
   piece of text in the app. Force consistency. */
button, input, select, textarea {
  font-family: inherit;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-primary);
  background: var(--bg-secondary);
  /* MoneyBot 1.3: full-viewport flex column so #grid-container can
     claim a BOUNDED remainder below the header/what-if rows. Use
     height (not min-height) so children can't push the body past the
     viewport. The dashboard pane scrolls internally. */
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  padding: 0.75rem 1rem 2.5rem;
  overflow: hidden;
}

/* App header bar */
.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.app-header > div {
  flex-shrink: 0;
}

.header-spacer { flex: 1; }
#mode-toggle-container { flex: 0; }
#palette-selector-container { flex: 0; }
#profile-selector-container { flex: 0; }
#goal-context-container { flex: 0; }

/* Scenario selector bar */
#scenario-selector-container:empty { display: none; }

.scenario-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
}

.scenario-label {
  font-size: 0.8em;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.scenario-cards {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  flex: 1;
}

.scenario-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  min-width: 0;
  flex-shrink: 0;
}

.scenario-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.scenario-card.scenario-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.3);
}

.scenario-card.scenario-active .scenario-desc {
  color: rgba(255, 255, 255, 0.8);
}

.scenario-name {
  font-size: 0.82em;
  font-weight: 600;
  line-height: 1.2;
}

.scenario-desc {
  font-size: 0.7em;
  color: var(--text-secondary);
  line-height: 1.2;
  max-width: 180px;
  white-space: normal;
}

/* What-if centre bar */
#what-if-bar-container:empty { display: none; }

.what-if-bar {
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.85em;
}

/* Envelope integrity violations banner — shown when the server's invariants
   enforcer attaches _violations to a response. Red so it cannot be ignored. */
.envelope-violations-banner {
  background: #b91c1c;
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: 6px;
  margin: 0.5rem 0 0.8rem 0;
  font-size: 0.88em;
  box-shadow: 0 2px 8px rgba(185, 28, 28, 0.35);
}
.envelope-violations-banner .evb-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.envelope-violations-banner .evb-badge {
  background: #fff;
  color: #b91c1c;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-weight: 700;
  font-size: 0.75em;
  letter-spacing: 0.5px;
}
.envelope-violations-banner .evb-sub {
  font-weight: 400;
  opacity: 0.92;
  flex: 1;
}
.envelope-violations-banner .evb-dismiss {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  cursor: pointer;
  font-size: 1em;
  line-height: 1;
}
.envelope-violations-banner .evb-list {
  margin: 0.45rem 0 0 1.1rem;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
}
.envelope-violations-banner .evb-list li {
  margin: 0.1rem 0;
}

.what-if-bar .what-if-changes {
  flex: 1;
}

.what-if-bar button {
  padding: 0.35rem 0.75rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 600;
}

.what-if-bar .wif-update-btn {
  background: #fff;
  color: var(--accent);
}

.what-if-bar .wif-reset-btn {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

header {
  margin-bottom: 2rem;
  padding: 1rem 1.5rem;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

/* Grid cards */
.grid-card {
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-header {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--card-header-bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.85em;
  position: sticky;
  top: 0;
  z-index: 10;
}

.card-title {
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.what-if-indicator {
  display: none; /* moved to global what-if bar */
}

.minimize-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  font-size: 1.1em;
  padding: 0 0.25rem;
  line-height: 1;
}

.minimize-btn:hover { color: #374151; }

.card-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

/* Global: black text on data, no decorative colours */
.card-body table { color: var(--text-primary); }
.card-body td, .card-body th { color: inherit; }

/* Chat: maximise height */
[data-card-id="chat-panel"] { display: flex; flex-direction: column; max-height: 700px; }
[data-card-id="chat-panel"] .card-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-panel { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
.chat-panel-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}
/* Shared "utility button" — used by chat Clear, Logout, and any other
   secondary-priority action. Keeps those buttons visually consistent
   with each other AND in the same family as the prominent CTAs
   (Transact / Send / What-if Update) — same shape, same border
   radius, same font-family, just lower-weight colour so they don't
   compete for attention. */
.btn-utility,
.chat-panel-toolbar button {
  font-size: 0.78em;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
}
.btn-utility:hover,
.chat-panel-toolbar button:hover {
  background: var(--bg-secondary);
  border-color: var(--accent);
}
.chat-panel-body { display: flex; flex: 1; gap: 0.75rem; overflow: hidden; min-height: 0; }
.chat-main { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; min-height: 150px; }

/* Right-side suggestions sidebar — narrower and smaller per design pass.
   Questions should feel lightweight, not compete with the conversation. */
.chat-sidebar {
  width: 165px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  padding: 0.45rem 0.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.chat-sidebar-header {
  font-size: 0.64em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}
.chat-sidebar-list { display: flex; flex-direction: column; gap: 0.25rem; }
.chat-sidebar-suggestion {
  width: 100%;
  text-align: left;
  white-space: normal;
  font-size: 0.72em;
  padding: 0.3rem 0.45rem;
  line-height: 1.25;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
}
.chat-sidebar-suggestion:hover {
  background: var(--accent-light, var(--bg-secondary));
  border-color: var(--accent);
  color: var(--accent);
}
.chat-sidebar-empty { color: var(--text-secondary); font-size: 0.7em; font-style: italic; }

/* Processing spinner — shown immediately on send, before the server typing
 * indicator. Uses a small circular CSS animation. */
.chat-processing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  color: var(--accent);
  font-size: 0.78em;
  font-weight: 500;
}
.chat-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: chat-spin 0.7s linear infinite;
}
@keyframes chat-spin {
  to { transform: rotate(360deg); }
}
.chat-typing {
  padding: 0.3rem;
  color: var(--text-secondary);
  font-size: 0.75em;
}

/* Minimized bar */
#minimized-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.minimized-tab {
  padding: 0.3rem 0.75rem;
  background: #e5e7eb;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8em;
  color: #374151;
}

.minimized-tab:hover { background: #d1d5db; }

header label {
  display: block;
  font-size: 0.85em;
  font-weight: 600;
  color: #666;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

header select {
  width: 100%;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
}

/* Mode toggle */
/* Mode toggle + palette (in header) */
#mode-toggle-container {}

.palette-select {
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-secondary);
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
}

.mode-btn {
  padding: 0.4rem 1rem;
  border: none;
  background: #fff;
  cursor: pointer;
  font-size: 0.85em;
  color: #666;
  transition: background 0.15s, color 0.15s;
}

.mode-btn.active {
  background: #2563eb;
  color: #fff;
}

.mode-btn:hover:not(.active) {
  background: #f0f0f0;
}

/* Goal context (in header) */
#goal-context-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#goal-context-container label {
  font-size: 0.8em;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
}

#goal-context-container select {
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

#profile-summary-container {
  margin-bottom: 1.5rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card, #fff);
  border-radius: 8px;
  border: 1px solid var(--border, #e0e0e0);
}

main {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.5rem;
}

main section {
  background: #fff;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  padding: 1.5rem;
}

/* Slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #ddd;
  border-radius: 3px;
  outline: none;
  margin-top: 0.75rem;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #2563eb;
  border-radius: 50%;
  cursor: pointer;
}

/* Factor rows */
.factor-row {
  margin-bottom: 1.25rem;
}

.factor-row label {
  display: block;
  font-size: 0.9em;
  margin-bottom: 0.25rem;
}

/* Loading state */
.loading-text {
  color: #888;
  font-size: 0.85em;
}

/* Chat panel */
#chat-panel-container {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 1.5rem;
}

.chat-messages {
  height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg-inset, var(--bg-secondary));
}

.chat-msg {
  margin-bottom: 0.75rem;
  max-width: 80%;
}

/* Chat feedback — smile/frown buttons on assistant messages */
.chat-feedback {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.3rem;
  font-size: 0.9em;
}
.chat-fb-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  font-size: 0.85em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}
.chat-fb-btn:hover { opacity: 1; }
.chat-fb-good.active { background: #dcfce7; border-color: #16a34a; opacity: 1; }
.chat-fb-bad.active  { background: #fee2e2; border-color: #dc2626; opacity: 1; }
.chat-fb-status { font-size: 0.75em; color: var(--text-secondary); margin-left: 0.35rem; }

/* System dividers — mode switches, session events */
.chat-msg-system {
  text-align: center;
  margin: 0.4rem 0;
}
.chat-msg-system .chat-msg-content {
  display: inline-block;
  color: var(--text-secondary);
  font-size: 0.72em;
  font-style: italic;
  padding: 0.15rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.chat-msg-user {
  margin-left: auto;
  text-align: right;
}

.chat-msg-user .chat-msg-content {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 0.4rem 0.65rem;
  border-radius: 12px 12px 2px 12px;
  font-size: 0.78em;
  line-height: 1.4;
}

.chat-msg-assistant .chat-msg-content {
  display: inline-block;
  background: var(--border);
  color: var(--text-primary);
  padding: 0.4rem 0.65rem;
  border-radius: 12px 12px 12px 2px;
  font-size: 0.78em;
  line-height: 1.45;
}

/* Markdown rendering in chat messages */
.chat-msg-assistant .chat-msg-content p { margin: 0.3rem 0; }
.chat-msg-assistant .chat-msg-content p:first-child { margin-top: 0; }
.chat-msg-assistant .chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-assistant .chat-msg-content strong { font-weight: 600; }
.chat-msg-assistant .chat-msg-content ul, .chat-msg-assistant .chat-msg-content ol {
  margin: 0.2rem 0; padding-left: 1.2rem;
}
.chat-msg-assistant .chat-msg-content li { margin: 0.1rem 0; }
.chat-msg-assistant .chat-msg-content code {
  background: rgba(0,0,0,0.1); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.9em;
}

.chat-suggestions {
  margin-top: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chat-suggestion {
  padding: 0.22rem 0.5rem;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--accent);
  font-size: 0.72em;
  cursor: pointer;
}

.chat-suggestion:hover {
  background: var(--accent-light);
}

/* Escalation card */
/* Escalation card — themed for both light and dark mode */
.chat-msg-escalation {
  max-width: 90% !important;
  background: var(--warning-bg, #fffbeb);
  border: 1px solid var(--warning, #f59e0b);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.chat-msg-escalation .chat-msg-content {
  background: transparent;
  color: var(--warning-text, #92400e);
  padding: 0;
}

.escalation-header {
  font-weight: 600;
  color: var(--warning, #d97706);
  margin-bottom: 0.5rem;
  font-size: 0.9em;
}

.advisor-brief-btn {
  margin-top: 0.5rem;
  padding: 0.3rem 0.75rem;
  background: var(--warning, #f59e0b);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8em;
}

.advisor-brief-btn:hover {
  opacity: 0.9;
}

.chat-input-form {
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  /* --input-bg is a dull muted blue in dark mode so typed text
     stands out (was var(--bg-card) = #1e293b, which is identical to
     the chat-messages bg and made cursor + typing almost invisible).
     Navy mode keeps it white. */
  background: var(--input-bg);
  color: var(--text-primary);
}
.chat-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

.chat-input-form button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
}

.chat-input-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Disclaimer banner */
.disclaimer-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #78716c;
  color: #fef3c7;
  text-align: center;
  padding: 0.4rem;
  font-size: 0.8em;
  z-index: 900;
  letter-spacing: 0.03em;
}

/* Audit controls footer */
footer#audit-controls {
  margin-top: 2rem;
  padding: 0.75rem 1.5rem;
  text-align: right;
  font-size: 0.85em;
}

/* Confirmation dialog overlay */
#confirmation-dialog-container {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.confirm-modal {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.confirm-modal h3 { margin-bottom: 1rem; }
.confirm-summary { margin-bottom: 1rem; font-size: 1.05em; }
.confirm-detail { margin-bottom: 1rem; padding-left: 1.5rem; font-size: 0.9em; color: #333; }
.confirm-warnings { margin-bottom: 1rem; }
.confirm-warning {
  background: #fef3c7; border: 1px solid #f59e0b; border-radius: 4px;
  padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; font-size: 0.85em; color: #92400e;
}
.confirm-buttons { display: flex; gap: 0.75rem; justify-content: flex-end; }
.confirm-btn {
  padding: 0.5rem 1.25rem; border-radius: 4px; font-size: 0.9em; cursor: pointer; border: none;
}
.confirm-cancel { background: #e5e7eb; color: #374151; }
.confirm-ok { background: #2563eb; color: #fff; }
.confirm-cancel:hover { background: #d1d5db; }
.confirm-ok:hover { background: #1d4ed8; }

footer#audit-controls button {
  padding: 0.35rem 0.75rem;
  margin-left: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85em;
  color: #666;
}

footer#audit-controls button:hover {
  background: #f0f0f0;
}

footer#audit-controls #audit-status {
  margin-left: 0.75rem;
  color: #888;
}

/* Admin page */
.admin-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.admin-page h1 { margin-bottom: 1.5rem; }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.admin-card {
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 1rem;
}

.admin-card h3 {
  font-size: 0.9em;
  color: var(--text-secondary, #666);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-card table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.admin-card th, .admin-card td { padding: 0.3rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border, #eee); }
.admin-card ul { padding-left: 1.2rem; font-size: 0.9em; }

#admin-back {
  padding: 0.5rem 1.5rem;
  background: var(--accent, #2563eb);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* Transcript */
.transcript-list { max-height: 500px; overflow-y: auto; }
.transcript-user, .transcript-assistant { margin-bottom: 0.75rem; padding: 0.5rem 0.75rem; border-radius: 8px; max-width: 85%; }
.transcript-user { background: #2563eb; color: #fff; margin-left: auto; text-align: right; }
.transcript-assistant { background: #e5e7eb; }
.transcript-time { font-size: 0.7em; color: #999; margin-bottom: 0.2rem; }
.transcript-text { font-size: 0.9em; white-space: pre-wrap; }

/* View toggle button */
.view-toggle-btn {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
.view-toggle-btn:hover {
  background: var(--accent-light, #dbeafe);
  color: var(--accent, #2563eb);
}

/* Client Dashboard */
.client-dashboard {
  padding: 1rem 0;
  max-width: calc(100vw - 4rem);
  box-sizing: border-box;
}

.client-dashboard-title {
  font-size: 1.1em;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.client-dashboard-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9em;
}

.client-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  max-width: 900px;
}

.client-goal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  min-width: 0;
}

.client-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.client-traffic-light {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.client-card-name {
  font-size: 1.05em;
  font-weight: 600;
  color: var(--text-primary);
}

.client-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.3rem 0;
}

.client-card-label {
  font-size: 0.85em;
  color: var(--text-secondary);
}

.client-card-value {
  font-size: 1.05em;
  font-weight: 600;
  color: var(--text-primary);
}

.client-card-status {
  margin-top: 0.75rem;
  font-size: 0.9em;
  font-weight: 600;
}

/* ================================================================
   MoneyBot 1.3 — Two-pane layout.
   Left: dashboard card stack (scrollable). Right: chat, full-height.
   The body is `display: flex; flex-direction: column` (see :body rule
   above) so #grid-container can claim the remaining vertical space.
   ================================================================ */

#grid-container {
  flex: 1;
  min-height: 0;
  /* grid-template-columns is set inline by layout.js (1fr 1fr) */
}

.dashboard-pane {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}

.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-pane-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  /* Reset the legacy #chat-panel-container rule (margin + padding) in
     case anything still matches — the chat panel renders its own
     internal padding. */
  margin: 0;
  padding: 0;
}

.chat-pane-card .chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.chat-pane-card .chat-panel-toolbar {
  padding: 0.4rem 0.6rem 0;
}

/* The chat-panel-body/chat-main wrappers were used by the old
   sidebar layout. MoneyBot 1.3's chat-panel is a flat flex column:
   toolbar, messages, suggestions strip, input. These two rules stay
   for backwards compatibility with any stray references but no
   longer wrap real content. */
.chat-pane-card .chat-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  gap: 0.5rem;
  padding: 0 0.6rem 0.6rem;
}

.chat-pane-card .chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* Suggested-questions strip — four rotating grey tones, flush
   edge-to-edge above the input. Small, simple, not-a-bubble.
   Flex-wrap gives us two tiles per row by default; if a tile would
   have to wrap its text to fit (min-width threshold), it drops to
   one per row automatically. */
.chat-suggestions-strip {
  display: flex;
  flex-wrap: wrap;
  margin: 0 0.6rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.chat-suggestions-strip:empty {
  display: none;
}
.chat-suggestion-tile {
  flex: 1 1 calc(50% - 0.5px);
  min-width: 200px;
  text-align: left;
  font-size: 0.78em;
  line-height: 1.3;
  padding: 0.35rem 0.6rem;
  border: 0;
  border-top: 1px solid rgba(128, 128, 128, 0.15);
  border-left: 1px solid rgba(128, 128, 128, 0.15);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  /* Text wraps inside the tile — no ellipsis. A long question
     either (a) wraps onto a second line within its half-width tile
     or (b) if the chat pane is narrow enough that the tile can't
     hold 200px, the tile drops to its own full-width row via the
     flex min-width rule above. No truncated "..." ever. */
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}
/* Background cycles through four theme-aware tones so alternation
   reads in both navy (light greys) and dark (blue-black variations). */
.chat-suggestion-tile:nth-child(4n+1) { background: var(--tile-1); }
.chat-suggestion-tile:nth-child(4n+2) { background: var(--tile-2); }
.chat-suggestion-tile:nth-child(4n+3) { background: var(--tile-3); }
.chat-suggestion-tile:nth-child(4n)   { background: var(--tile-4); }
.chat-suggestion-tile:nth-child(-n+2) {
  border-top: 0;
}
.chat-suggestion-tile:nth-child(odd) {
  border-left: 0;
}
.chat-suggestion-tile:hover {
  background: var(--tile-hover) !important;
  color: var(--accent);
}

/* Override the earlier `.chat-messages { height: 300px; ... }` rule
   inherited from the single-card chat layout. In the two-pane world
   chat fills whatever vertical space the right pane has. */
.chat-pane-card .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  height: auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  margin-bottom: 0.5rem;
}

/* Pin message content to the bottom of the messages area when it
   doesn't overflow — so the welcome message + any short history
   sits next to the input + suggestions strip rather than floating
   way above them. The ::before pseudo is an invisible flex child
   that takes all remaining space; when real content fills the
   container, it shrinks to zero and the scroll behaviour is
   unchanged. */
.chat-pane-card .chat-messages::before {
  content: "";
  flex: 1 1 auto;
}

/* Dashboard cards sit inside the scrollable left pane — don't let
   flex stretch them; let each size to its content. */
.dashboard-pane .grid-card {
  flex: 0 0 auto;
  transition: background 0.18s, border-color 0.18s;
}

/* What-if tint: when ui.overrides is non-empty, cards whose figures
   reflect those overrides get a subtle warm wash and a warning-
   amber edge so the user can tell at a glance that they're viewing
   a changed dashboard rather than the baseline. Applied by
   layout.js to Projection, Factors, Allocation, Portfolio.
   Theme-aware: cream on navy, warm-dark on dark mode. The border
   is always --warning (amber) which reads as "attention / changed"
   in both themes. */
.dashboard-pane .grid-card.has-overrides {
  background: var(--tint-whatif);
  border-left: 3px solid var(--warning);
}

/* Ask-link: one affordance for "tell me more". The label IS the
   click target — no separate (i) glyph. Muted dotted underline by
   default; accent on hover. */
.ask-link {
  color: inherit;
  text-decoration: underline dotted rgba(0, 0, 0, 0.35);
  text-underline-offset: 2px;
  cursor: help;
  transition: color 0.15s, text-decoration-color 0.15s;
}
.ask-link:hover,
.ask-link:focus {
  color: var(--accent);
  text-decoration-color: var(--accent);
  outline: none;
}

/* Narrow viewport: stack panes vertically. Deferred placeholder so
   the page doesn't break on small screens; a proper mobile pass will
   land later. */
@media (max-width: 900px) {
  #grid-container {
    grid-template-columns: 1fr !important;
    grid-template-rows: 45vh 1fr !important;
  }
  .chat-pane {
    order: -1;
  }
}

/* ================================================================
   Allocation card — donut-left + legend-right layout.
   One panel per account. Wraps to stacked only when the card body
   is narrower than ~260px. Colour-per-class keeps the legend
   consistent between Total, Retirement, and goal views.
   ================================================================ */

.alloc-container {
  /* 2-up grid. Each panel sits in half the card width; if the card
     gets narrow enough that a panel would need to push below
     min-width, they fall back to one-per-row via the flex min-width
     rule on .alloc-panel below. */
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  justify-content: center;
}

.alloc-panel {
  /* flex: grow, shrink, basis 50% minus half the horizontal gap so
     two panels fit per row. min-width catches the narrow fallback. */
  flex: 1 1 calc(50% - 0.5rem);
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.alloc-panel-header {
  text-align: center;
}

.alloc-panel-label {
  font-size: 0.82em;
  font-weight: 700;
  color: var(--text-primary);
}

.alloc-panel-body {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

/* Donut column: chart on top, £ value directly beneath it. Centred
   vertically and horizontally so a single-panel view (Allocation:
   Retirement) doesn't float oddly to one side. */
.alloc-donut-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex: 0 0 auto;
}

.alloc-donut {
  display: block;
  width: 120px;
  height: 120px;
}

.alloc-panel-value {
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.alloc-legend {
  flex: 0 1 160px;
  min-width: 130px;
}

/* Stack when there's no room for side-by-side */
@media (max-width: 500px) {
  .alloc-panel-body {
    flex-direction: column;
  }
  .alloc-legend {
    width: 100%;
    max-width: 200px;
  }
}

/* Portfolio — single table per card. Columns line up vertically:
   Ticker (left), Value (right), % (right), action (right). Holdings
   rows are muted; account summary rows are bolded and separated by
   a subtle top border; the Grand Total sits at the very bottom with
   an extra rule above it. */

.portfolio-card {
  /* The card body already supplies padding */
}
.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8em;
}
.portfolio-table thead th {
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72em;
  padding: 0.25rem 0.3rem;
  border-bottom: 1px solid var(--border);
}
.portfolio-table tbody td {
  padding: 0.2rem 0.3rem;
  border-bottom: 1px solid var(--border);
}

/* Column alignment — pin Value and % to the right so every row's
   number lands in the same place. */
.portfolio-table th.pt-ticker, .portfolio-table td.pt-ticker { text-align: left; font-family: monospace; }
.portfolio-table th.pt-value,  .portfolio-table td.pt-value  { text-align: right; font-variant-numeric: tabular-nums; }
.portfolio-table th.pt-pct,    .portfolio-table td.pt-pct    { text-align: right; font-variant-numeric: tabular-nums; }
.portfolio-table th.pt-action, .portfolio-table td.pt-action { text-align: right; width: 80px; }

.portfolio-holding-row td {
  font-size: 0.95em;
}

/* Account summary row: Pension / £total / 100.0 / [Transact] */
.portfolio-acct-summary td {
  font-weight: 700;
  border-top: 1px solid var(--border);
}

/* Cash row inherits the summary styling but sits beneath all the
   account rows and above the Grand Total. */
.portfolio-cash-row td {
  /* no extra rule — the acct-summary styling is enough. */
}

.portfolio-grand-total td {
  font-weight: 700;
  border-top: 2px solid var(--text-primary);
  padding-top: 0.35rem;
}

/* Spacer row between account blocks — zero content, just vertical
   padding. Keeps Pension's summary visually separated from the ISA
   heading etc without relying on a colour rule. */
.portfolio-spacer td {
  border: 0 !important;
  padding: 0.3rem 0 !important;
  height: 0.3rem;
}

.portfolio-expand-row td {
  border-bottom: 0;
  padding: 0.1rem 0.3rem;
}
.portfolio-expand-row .show-all-link,
.portfolio-expand-row .collapse-link {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85em;
}

/* Per-account Transact button: small, outlined, lives in the
   action cell. Click opens the transact modal pre-selected. */
.portfolio-table .transact-btn {
  font-size: 0.82em;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--accent);
  background: var(--bg-card);
  color: var(--accent);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}
.portfolio-table .transact-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ================================================================
   Transact modal — focus-trapped overlay, no backdrop dismiss.
   ================================================================ */

.tm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.tm-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.tm-header {
  padding: 1rem 1.25rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.tm-header h3 {
  margin: 0 0 0.2rem;
  font-size: 1.05em;
  color: var(--text-primary);
}
.tm-cash {
  font-size: 0.78em;
  color: var(--text-secondary);
}

.tm-body {
  padding: 0.9rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.tm-field label {
  display: block;
  font-size: 0.72em;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.tm-input {
  width: 100%;
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9em;
  background: var(--bg-card);
  color: var(--text-primary);
}
.tm-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.tm-action-tabs {
  display: flex;
  gap: 0.35rem;
}
.tm-tab {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.82em;
  border-radius: 4px;
}
.tm-tab.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.tm-search-results {
  margin-top: 0.35rem;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}
.tm-search-result {
  padding: 0.3rem 0.55rem;
  font-size: 0.82em;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.tm-search-result:last-child { border-bottom: 0; }
.tm-search-result:hover { background: var(--accent-light, #dbeafe); }

.tm-footer {
  padding: 0.7rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.tm-footer-spacer { flex: 1; }

.tm-btn {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 0.85em;
  cursor: pointer;
}
.tm-btn-clear { color: var(--text-secondary); }
.tm-btn-clear:hover { border-color: var(--text-secondary); }
.tm-btn-cancel:hover { border-color: var(--text-primary); }
.tm-btn-submit {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.tm-btn-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
