/* === LifeTiming Advisor Assistant — Design System === */
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-LightItalic.ttf') format('truetype');
    font-weight: 300;
    font-style: italic;
}
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-Italic.ttf') format('truetype');
    font-weight: 400;
    font-style: italic;
}
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
}
@font-face {
    font-family: 'Aeonik-Lifetiming';
    src: url('../fonts/AeonikLifetiming-MediumItalic.ttf') format('truetype');
    font-weight: 500;
    font-style: italic;
}

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

html {
    height: 100dvh;
    overflow: hidden;
}

:root {
    --accent: #FB7B34;
    --accent-hover: #FF9F53;
    --accent-light: #FF9C5E;
    --accent-subtle: rgba(251, 123, 52, 0.08);
    --accent-muted: rgba(251, 123, 52, 0.15);
    --secondary: #6467C3;
    --secondary-hover: #7b7ed4;

    --text-primary: #0F0F0F;
    --text-secondary: #7E716D;
    --text-tertiary: #8B8A8A;
    --bg-page: #F1E8E4;
    --bg-surface: #FFFFFF;
    --bg-surface-alt: #FBF9F9;
    --bg-surface-raised: #F6F4F3;
    --bg-input: transparent;
    --border-color: #E6E6E6;
    --border-hover: #FF9C5E;
    --divider: #F2EEED;

    --success: #139E19;
    --success-bg: #e8f5e9;
    --error: #DC180C;
    --error-bg: #ffeaea;
    --warning: #E59A00;
    --warning-bg: rgba(255, 171, 0, 0.12);

    --radius-pill: 24px;
    --radius-container: 10px;
    --radius-sm: 6px;
    --radius-xs: 4px;

    --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-modal: 0 10px 25px rgba(0, 0, 0, 0.1);

    --font: 'Aeonik-Lifetiming', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 500;
    --font-weight-bold: 500;

    --bg-header: #0F0F0F;
}

/* === Dark Theme === */
body.dark-theme {
    color-scheme: dark;
    --bg-header: #1B1918;
    --bg-page: #251F1D;
    --bg-surface: #2D2624;
    --bg-surface-alt: #393332;
    --bg-surface-raised: #2D2624;
    --bg-input: #1B1918;
    --text-primary: #FFFFFF;
    --text-secondary: #F2EEED;
    --text-tertiary: #8B8A8A;
    --border-color: #3D3533;
    --divider: #3D3533;
    --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-modal: 0 10px 25px rgba(0, 0, 0, 0.5);
    --success-bg: rgba(19, 158, 25, 0.10);
    --error-bg: rgba(220, 24, 12, 0.10);
    --warning-bg: rgba(229, 154, 0, 0.10);
}

body {
    font-family: var(--font);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    background: var(--bg-page);
    line-height: 1.5;
    height: 100%;
    min-height: 500px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-page);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

.loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-overlay-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.loading-logo {
    width: 180px;
}


.loading-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--divider);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-status {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: var(--font-weight-medium);
}

/* === Header === */
/* === Section Header with How-to-use === */
.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--divider);
}

.section-header-row h2 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.btn-how-to-use {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: transparent;
    color: var(--text-tertiary);
    border: none;
    padding: 0.3rem 0.1rem;
    margin-left: 0.5rem;
    vertical-align: middle;
    font-size: 0.78rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: color 0.2s;
    white-space: nowrap;
}

.btn-how-to-use:hover,
.btn-how-to-use.active {
    color: var(--accent);
}

/* === How-to-use fold-out panel === */
.how-to-use-panel {
    display: none;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.2s ease;
}

.how-to-use-panel.open {
    display: block;
}

.how-to-use-panel h3 {
    font-size: 0.88rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0 0 0.75rem;
    text-transform: none;
    letter-spacing: normal;
}

.how-to-use-panel p {
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.how-to-use-panel p:last-of-type {
    margin-bottom: 0.75rem;
}

.btn-how-to-use-close {
    display: inline-block;
    background: transparent;
    color: var(--text-tertiary);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.85rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    margin-top: 0.25rem;
}

.btn-how-to-use-close:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* === Two-Column App Layout === */
.app-layout {
    display: flex;
    justify-content: center;
    flex: 1;
    height: 0;
    min-height: 500px;
    overflow: hidden;
    max-width: 1500px;
    width: 100%;
    margin: 0 auto;
}

.app-layout.form-visible {
    justify-content: flex-start;
}

.app-layout .app-main {
    margin: 0;
}

/* === Main Content === */
.app-main {
    flex: 1;
    max-width: 640px;
    margin: 0 auto;
    padding: 1.25rem clamp(0.5rem, 2vw, 1.5rem) 2rem clamp(0.5rem, 2vw, 1.5rem);
    min-width: 500px;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.app-layout .app-main.report-active {
    max-width: 900px;
}

#advisory-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.form-tab-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.form-tab-content::-webkit-scrollbar {
    width: 5px;
}

.form-tab-content::-webkit-scrollbar-track {
    background: transparent;
}

.form-tab-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.form-tab-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* === Chat Pane === */
.chat-pane-wrapper {
    flex: 1;
    width: 100%;
    min-width: 500px;
    max-width: 640px;
    margin: 0;
    padding: 1.25rem clamp(0.25rem, 2vw, 1.5rem) 2rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}


.chat-pane {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-pane-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #FCFCFC;
    font-size: 1rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.02em;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header-info h3 {
    font-size: 0.95rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin: 0;
    line-height: 1.2;
}

.chat-header-info .chat-subtitle {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    font-weight: var(--font-weight-medium);
    margin-top: 0.1rem;
}

.chat-header-status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--success);
    font-weight: var(--font-weight-medium);
    flex-shrink: 0;
}

.chat-header-status .status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
}


.chat-messages {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    min-height: 150px;
    flex: 1 1 auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.chat-bubble {
    max-width: 90%;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-container);
    font-size: 0.85rem;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-line;
}

.chat-bubble.bot {
    align-self: flex-start;
    background: var(--bg-surface-alt);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--accent);
    color: #FCFCFC;
}

.chat-bubble .chat-bubble-time {
    font-size: 0.65rem;
    margin-top: 0.3rem;
    opacity: 0.6;
}

.chat-client-results {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.3rem 0.8rem;
    margin-bottom: 0.4rem;
}

.chat-client-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font);
}

.chat-client-card:hover:not(:disabled) {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.chat-client-card.selected {
    background: var(--accent-subtle);
    border-color: var(--accent);
    font-weight: var(--font-weight-semibold);
}

.chat-client-card:disabled {
    opacity: 0.6;
    cursor: default;
}

.chat-client-card.client-has-onboarding {
    background: var(--success-bg);
    border-left: 3px solid var(--success);
}
.chat-client-card.client-has-onboarding:hover:not(:disabled) {
    background: #c8e6c9;
}
.chat-client-card.client-no-onboarding {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}
.chat-client-card.client-no-onboarding:hover:not(:disabled) {
    background: #ffe0b2;
}

.chat-client-card .client-name {
    font-size: 0.82rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.chat-client-card .client-id {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* Tool call indicators in chat */
.chat-tool-indicator {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 1.25rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.chat-tool-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    border: 2.5px solid rgba(0, 0, 0, 0.12);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: tool-spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes tool-spin {
    to { transform: rotate(360deg); }
}

.chat-tool-check {
    display: inline-block;
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    position: relative;
    flex-shrink: 0;
}

.chat-tool-check::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid var(--accent);
    border-width: 0 2.5px 2.5px 0;
    transform: rotate(45deg);
}

.chat-tool-indicator.done {
    color: var(--text-secondary);
}

.chat-tool-indicator.done .chat-tool-label {
    opacity: 0.7;
}

.chat-input-area {
    padding: 0.75rem 1.25rem;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input-row textarea {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    resize: none;
    color: var(--text-primary);
    background: var(--bg-surface-alt);
    min-height: 38px;
    max-height: 100px;
    line-height: 1.4;
}

.chat-input-row textarea:focus {
    outline: none;
    border-color: var(--accent-light);
}

.chat-send-btn {
    background: var(--accent);
    color: #FCFCFC;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

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

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

.chat-typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 0.5rem 0.85rem;
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin: 0 1.25rem;
}

.chat-typing-indicator.visible {
    display: block;
}

/* --- Chat-driven intent animations --- */

/* New intent box: bold accent border glow that holds then fades */
.chat-intent-new {
    animation: chatIntentAppear 3s ease-out;
}

@keyframes chatIntentAppear {
    0%   { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-muted), 0 0 12px var(--accent-muted); }
    60%  { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-muted), 0 0 12px var(--accent-muted); }
    100% { border-color: var(--border-color); box-shadow: none; }
}

/* Individual field glow when value is auto-populated */
.chat-field-flash {
    animation: chatFieldGlow 3s ease-out;
}

@keyframes chatFieldGlow {
    0%   { box-shadow: 0 0 0 3px var(--accent), 0 0 8px var(--accent-muted); background: var(--accent-subtle); }
    60%  { box-shadow: 0 0 0 3px var(--accent), 0 0 8px var(--accent-muted); background: var(--accent-subtle); }
    100% { box-shadow: none; background: var(--bg-input); }
}

textarea.chat-field-flash,
select.chat-field-flash {
    animation: chatFieldGlow 3s ease-out;
}

/* === Step Content === */
.step-content {
    display: none;
}

.step-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Form Tabs === */
.form-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0;
    flex-shrink: 0;
    background: var(--bg-page);
}

.form-tab {
    padding: 0.6rem 1.25rem;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.form-tab:hover {
    color: var(--text-primary);
}

.form-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: var(--font-weight-semibold);
}

/* === Form Styles === */
.form-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.form-section h2 {
    font-size: 1rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--divider);
    letter-spacing: -0.01em;
}

.form-section h3 {
    font-size: 0.85rem;
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    margin: 1.25rem 0 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    padding-left: 0.85rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-family: var(--font);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    background: var(--bg-input);
    transition: border-color 0.2s;
    line-height: 1.4;
}

.form-group textarea {
    border-radius: var(--radius-container);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-light);
}

.form-group input[readonly] {
    background: var(--bg-surface-raised);
    color: var(--text-primary);
    cursor: default;
}

.form-group textarea[readonly] {
    background: var(--bg-surface-raised);
    color: var(--text-primary);
    cursor: default;
}

.form-row {
    display: flex;
    gap: 0.85rem;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
}

/* === Buttons === */
.btn-primary {
    background: var(--accent);
    color: #FCFCFC;
    border: none;
    padding: 0.6rem 1.75rem;
    border-radius: var(--radius-pill);
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s;
    line-height: 1.2;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--text-primary);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: border-color 0.2s;
}

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

.btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-save {
    background: var(--secondary);
    color: #FCFCFC;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.2s;
}

.btn-save:hover {
    background: var(--secondary-hover);
}

.btn-save:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-undo {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--text-secondary);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

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

.btn-undo:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-remove-directive {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-family: var(--font);
    cursor: pointer;
    margin-top: 0.5rem;
    transition: all 0.2s;
}

.btn-remove-directive:hover {
    background: var(--error);
    color: #FCFCFC;
}

.btn-remove-small {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0 0.5rem;
    line-height: 1;
    align-self: center;
    transition: color 0.2s;
}

.btn-remove-small:hover {
    color: var(--error);
}

.form-actions {
    text-align: center;
    margin-top: 1.5rem;
}

.form-actions .btn-primary {
    padding: 0.75rem 3.5rem;
    font-size: 1rem;
}

/* Generate button below chat pane */
.chat-actions {
    text-align: center;
    margin-top: 1rem;
    flex-shrink: 0;
}

.chat-actions .btn-primary {
    padding: 0.75rem 3.5rem;
    font-size: 1rem;
    width: 100%;
}

/* Chat pane content wrapper */
.chat-pane-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Form toolbar spacer (matches chat-toolbar height for alignment) */
.form-toolbar-spacer {
    min-height: 2.45rem;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

/* Toolbars */
.form-toolbar,
.chat-toolbar {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
    min-height: 2.45rem;
    padding-bottom: 0;
    flex-shrink: 0;
}

/* Form toggle button */
.btn-form-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: none;
    border: none;
    padding: 0.4rem;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-speed);
}

.btn-form-toggle:hover {
    color: var(--accent);
}

/* Pane toggle arrow (form show/hide) */
.pane-toggle-icon {
    transition: transform 0.2s;
    color: var(--text-tertiary);
}

.btn-pane-arrow:hover .pane-toggle-icon {
    color: var(--accent);
}

/* Chat toolbar: arrow points left (show form) when form is hidden */
.chat-toolbar .pane-toggle-icon {
    transform: rotate(180deg);
}

/* When form is visible, chat arrow points right (hide form) */
.app-layout.form-visible .chat-toolbar .pane-toggle-icon {
    transform: rotate(0deg);
}

/* === Directives & Allocations === */
.directive-item,
.allocation-item,
.session-item,
.intention-item {
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    padding: 1rem;
    margin-bottom: 0.6rem;
}

/* === Portfolio ID Picker === */
.field-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
}

.client-id-picker,
.portfolio-id-picker {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin-bottom: 1.25rem;
}

.client-id-option,
.portfolio-id-option {
    flex: 1;
    transition: opacity 0.2s;
}

.client-id-option label,
.portfolio-id-option label {
    display: block;
    font-size: 0.8rem;
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    padding-left: 0.85rem;
}

.client-id-option input[type="text"],
.portfolio-id-option input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-family: var(--font);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    background: var(--bg-input);
    transition: border-color 0.2s;
    line-height: 1.4;
}

.client-id-option input:focus,
.portfolio-id-option input:focus {
    outline: none;
    border-color: var(--accent-light);
}

.portfolio-id-fetch {
    align-self: flex-start;
    margin-top: 1.15rem;
    margin-left: 1rem;
    white-space: nowrap;
}

/* === Portfolio Load Status === */
.portfolio-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.portfolio-load-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.portfolio-load-status.portfolio-load-error {
    color: #c0392b;
}

.spinner-inline {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--divider);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* === Client Search Autocomplete === */
.client-search-wrapper {
    position: relative;
}

/* === Portfolio Search Autocomplete === */
.portfolio-search-wrapper {
    position: relative;
}

.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 var(--radius-container) var(--radius-container);
    box-shadow: var(--shadow-elevated);
    z-index: 100;
}

.search-dropdown.open {
    display: block;
}

.search-dropdown-item {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--divider);
}

.search-dropdown-item:last-child {
    border-bottom: none;
}

.search-dropdown-item:hover {
    background: var(--accent-subtle);
}

.search-dropdown-item .sdi-name {
    font-weight: var(--font-weight-semibold);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.search-dropdown-item .sdi-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.1rem;
}

.search-dropdown-item .sdi-status,
.chat-portfolio-card .sdi-status {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.1rem 0.5rem;
    border-radius: var(--radius-pill);
    margin-left: 0.4rem;
    vertical-align: middle;
}

.sdi-status-10 { background: #f3e5f5; color: #7b1fa2; }
.sdi-status-20 { background: #e3f2fd; color: #1565c0; }
.sdi-status-30 { background: var(--warning-bg); color: #975a16; }
.sdi-status-40 { background: #fff3e0; color: #e65100; }
.sdi-status-50 { background: var(--success-bg); color: #276749; }
.sdi-status-60 { background: #efebe9; color: #5d4037; }
.sdi-status-70 { background: #e0e0e0; color: #616161; }
.sdi-status-90 { background: var(--error-bg); color: var(--error); }

/* Client onboarding status in dropdown */
.search-dropdown-item.client-has-onboarding {
    background: var(--success-bg);
    border-left: 3px solid var(--success);
}
.search-dropdown-item.client-has-onboarding:hover {
    background: #c8e6c9;
}
.search-dropdown-item.client-no-onboarding {
    background: var(--warning-bg);
    border-left: 3px solid var(--warning);
}
.search-dropdown-item.client-no-onboarding:hover {
    background: #ffe0b2;
}

.search-dropdown-empty {
    padding: 0.85rem 1rem;
    text-align: center;
    color: #975a16;
    background: var(--warning-bg);
    font-size: 0.82rem;
    line-height: 1.6;
    border-left: 3px solid var(--warning);
}

/* === Client ID Display === */
.client-id-display {
    padding: 0.3rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.client-id-label {
    font-weight: 500;
}

.client-id-value {
    margin-left: 0.4rem;
}

/* === Radio Group (Portfolio Status) === */
.radio-group {
    display: flex;
    gap: 1.2rem;
    padding: 0.4rem 0;
    font-size: 0.9rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    color: var(--text-primary);
}

/* Custom radio button appearance (all themes) */
input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    width: 1em;
    height: 1em;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-surface-alt);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    top: 0.05em;
    transition: border-color 0.15s;
}
input[type="radio"]:checked {
    border-color: var(--accent);
    background-image: radial-gradient(var(--accent) 45%, transparent 50%);
    background-color: var(--bg-surface-alt);
}
input[type="radio"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Dark mode: inputs and selects not covered by --bg-surface-alt via their own rules */
body.dark-theme input[type="text"],
body.dark-theme input[type="password"],
body.dark-theme input[type="number"],
body.dark-theme textarea,
body.dark-theme select {
    background: #393332;
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* === Withdrawal Amount Feedback === */
.intention-amount-feedback {
    margin-top: 0.4rem;
    margin-bottom: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
}

.feedback-warning {
    background: #fff3e0;
    border: 1px solid #e65100;
    color: #bf360c;
}

.feedback-success {
    background: #e8f5e9;
    border: 1px solid #2e7d32;
    color: #1b5e20;
}

/* === Intention Top Fields === */
.field-row { display: flex; gap: 0.75rem; }
.field-row .form-group { flex: 1; }

/* === Risk-Return Params === */
.riskreturn-params { display: flex; gap: 0.75rem; }
.rr-field { flex: 1; }
.rr-field label { font-size: 0.8rem; margin-bottom: 0.25rem; display: block; }
.rr-field input:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Collapsible Sections === */
.collapsible h2 {
    cursor: pointer;
    user-select: none;
}

.collapsible h2:hover {
    color: var(--accent);
}

.toggle-icon {
    float: right;
    transition: transform 0.2s;
    color: var(--text-tertiary);
    vertical-align: middle;
    margin-top: 0.2rem;
}

.collapsible.open .toggle-icon {
    transform: rotate(90deg);
}

/* === Fetch Status === */
#fetch-status,
#bff-fetch-status {
    font-size: 0.8rem;
    font-weight: var(--font-weight-medium);
    padding: 0.35rem 0;
    margin-top: 0.25rem;
}

/* === Processing View === */
.processing-container {
    text-align: center;
    padding: 5rem 2rem;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--divider);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.processing-container h2 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: var(--font-weight-semibold);
    margin-bottom: 0.5rem;
}

.processing-status {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.processing-detail {
    color: var(--text-tertiary);
    font-size: 0.85rem;
    margin-top: 1rem;
}

/* === Report Display === */
.report-actions-top,
.edit-actions-top {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.version-indicator {
    font-size: 0.75rem;
    color: #999;
    font-family: monospace;
}

.report-sticky-header {
    z-index: 10;
    background: var(--bg-page);
    padding-top: 0.75rem;
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.report-scroll-area {
    flex: 1;
    min-height: 500px;
    overflow-y: auto;
    padding-right: 0;
    padding-bottom: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.report-scroll-area::-webkit-scrollbar {
    width: 5px;
}

.report-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}

.report-scroll-area::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.report-scroll-area::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.report-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
}

.report-header {
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 2rem 2.5rem;
    border-bottom: 3px solid var(--accent);
    position: sticky;
    top: 0;
    z-index: 10;
}

.report-header h2 {
    font-size: 1.6rem;
    font-weight: var(--font-weight-bold);
    margin-bottom: 0.35rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.report-header .report-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.report-body {
    padding: 2rem;
}

/* === Welcome Section (Swedish Report) === */
.report-welcome {
    margin-bottom: 1.5rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.report-welcome p {
    margin-bottom: 0.75rem;
}

.greeting-signature {
    margin-top: 0.5rem;
}

.report-part-heading {
    font-size: 1.25rem;
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin: 0 0 1.5rem;
    letter-spacing: -0.01em;
}

.report-divider {
    border: none;
    border-top: 2px solid var(--divider);
    margin: 1.5rem 0 2rem;
}

/* === Report Subsections (Swedish Report) === */
.report-subsection {
    margin-bottom: 2rem;
}

.report-subsection h3 {
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: var(--font-weight-semibold);
    margin-bottom: 0.75rem;
}

.required-asterisk {
    color: var(--danger, #e53e3e);
    font-weight: var(--font-weight-bold);
}

.subsection-content {
    white-space: pre-line;
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 0.95rem;
}

.subsection-content.readonly {
    color: var(--text-secondary);
    font-style: italic;
}

.report-readonly-field {
    opacity: 1;
}

/* === Report Group Headings === */
.report-group-heading {
    font-size: 1.1rem;
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0;
    color: var(--text-primary);
    margin: 2rem 0 0.75rem 0;
    padding-bottom: 0.5rem;
}

/* === Report Select Fields === */
.report-select-field select,
.report-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s;
}

.report-select:hover,
.report-select:focus {
    border-color: var(--border-hover);
    outline: none;
}

/* === Report Number Input === */
.report-number-input input,
.report-number {
    width: 200px;
    padding: 0.5rem 0.75rem;
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-surface-alt);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

.report-number:hover,
.report-number:focus {
    border-color: var(--border-hover);
    outline: none;
}

/* === Checkbox Sections === */
.checkbox-question {
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.checkbox-row {
    display: flex;
    gap: 2rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-surface-raised);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: var(--font-weight-medium);
    cursor: default;
}

.checkbox-box {
    font-size: 1.3rem;
    line-height: 1;
    color: var(--text-tertiary);
}

.checkbox-box.checked {
    color: var(--accent);
    font-weight: var(--font-weight-bold);
}

/* === Report Radio Groups === */
.report-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin-bottom: 0.75rem;
}

.report-radio-group.vertical {
    flex-direction: column;
    gap: 0.4rem;
}

.radio-option {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.radio-option input[type="radio"] {
    accent-color: var(--accent);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.radio-option span {
    color: var(--text-primary);
    line-height: 1.4;
}

/* === Report Textarea === */
.text-input-wrapper {
    position: relative;
}

.report-textarea {
    width: 100%;
    min-height: 8.5rem;
    padding: 0.6rem 0.75rem;
    padding-bottom: 1.5rem;
    font-family: var(--font);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    resize: vertical;
    overflow-y: hidden;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.report-textarea:focus {
    border-color: var(--accent-light);
    outline: none;
}

.char-count {
    position: absolute;
    bottom: 0.4rem;
    right: 0.6rem;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    pointer-events: none;
    user-select: none;
}

.char-count.near-limit { color: var(--warning, #e67e22); }
.char-count.at-limit   { color: var(--error, #e74c3c); }

/* === Transaction Tables in Report === */
.report-transactions {
    margin-top: 2rem;
}

.report-transactions h3 {
    font-size: 1.1rem;
    font-weight: var(--font-weight-bold);
}

.transaction-report-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

.transaction-report-table th {
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    font-size: 0.75rem;
    border-bottom: 1px solid var(--divider);
    padding: 0.5rem 0.75rem;
    text-transform: none;
    letter-spacing: 0;
}

.transaction-report-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--divider);
}

.transaction-report-table tfoot td {
    border-bottom: none;
    border-top: 1px solid var(--divider);
    padding-top: 0.75rem;
}

/* === Fee Summary Table === */
.fee-summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

.fee-summary-table th {
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    font-size: 0.75rem;
    border-bottom: 1px solid var(--divider);
    padding: 0.5rem 0.75rem;
    text-transform: none;
    letter-spacing: 0;
}

.fee-summary-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--divider);
}

.fee-summary-table tfoot td {
    border-bottom: none;
    border-top: 1px solid var(--divider);
    padding-top: 0.75rem;
}

/* === BFF Form Tables === */
.bff-form-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid var(--text-primary);
}

.bff-form-table th.bff-group-header {
    text-align: left;
    font-weight: var(--font-weight-semibold);
    font-size: 0.95rem;
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--text-primary);
    text-transform: none;
    letter-spacing: normal;
}

.bff-form-table td {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--text-primary);
    vertical-align: top;
}

.bff-form-table .bff-field-label {
    font-weight: var(--font-weight-normal);
    color: var(--text-primary);
    width: 40%;
}

/* === Legacy Report Styles === */
.report-executive-summary {
    background: var(--accent-subtle);
    border-left: 3px solid var(--accent);
    padding: 1.25rem;
    border-radius: 0 var(--radius-container) var(--radius-container) 0;
    margin-bottom: 2rem;
}

.report-executive-summary h3 {
    color: var(--accent);
    font-size: 0.95rem;
    font-weight: var(--font-weight-semibold);
    margin-bottom: 0.5rem;
}

.report-section {
    margin-bottom: 1.75rem;
}

.report-section h3 {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: var(--font-weight-semibold);
    margin-bottom: 0.6rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--divider);
}

.report-section .content {
    margin-bottom: 0.75rem;
    white-space: pre-line;
    color: var(--text-primary);
    line-height: 1.65;
}

.report-section .recommendations {
    list-style: none;
    padding: 0;
}

.report-section .recommendations li {
    padding: 0.35rem 0 0.35rem 1.5rem;
    position: relative;
    font-size: 0.9rem;
}

.report-section .recommendations li::before {
    content: "\2192";
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: 500;
}

.report-risk-assessment {
    background: var(--warning-bg);
    border: 1px solid rgba(229, 154, 0, 0.25);
    border-radius: var(--radius-container);
    padding: 1.25rem;
    margin-bottom: 1.75rem;
}

.report-risk-assessment h3 {
    color: var(--warning);
    font-weight: var(--font-weight-semibold);
    margin-bottom: 0.5rem;
    border: none;
    padding: 0;
}

.report-action-items {
    margin-bottom: 1.75rem;
}

.report-action-items h3 {
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 0.6rem;
}

.action-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-surface-raised);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
}

.action-priority {
    font-size: 0.65rem;
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    letter-spacing: 0.03em;
}

.action-priority.HIGH { background: var(--error-bg); color: var(--error); }
.action-priority.MEDIUM { background: var(--warning-bg); color: #975a16; }
.action-priority.LOW { background: var(--success-bg); color: #276749; }

.action-details { flex: 1; }
.action-details .action-text { font-weight: var(--font-weight-medium); font-size: 0.9rem; }
.action-details .action-timeline { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.15rem; }

.report-disclaimer {
    background: var(--bg-surface-raised);
    border-top: 1px solid var(--divider);
    padding: 1.25rem 2rem;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* === Unified Report View: Inline Editing + Refinement === */
.report-guide-panel {
    display: none;
    background: var(--accent-subtle);
    border: 1px solid var(--accent-muted);
    border-radius: var(--radius-sm);
    padding: 0.6rem 1rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    animation: fadeIn 0.2s ease;
}

.report-guide-panel.open {
    display: block;
}

.report-guide-panel p {
    margin: 0;
    line-height: 1.5;
}

#report-display img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin: 0.75rem 0;
}

#report-display.drag-over {
    box-shadow: 0 0 0 3px var(--accent);
    background: var(--accent-subtle);
}

#report-display .subsection-content[contenteditable="true"] {
    outline: none;
    min-height: 1.5em;
    cursor: text;
    border-radius: var(--radius-xs);
    transition: background 0.15s;
}

#report-display .subsection-content[contenteditable="true"]:focus {
    background: var(--accent-subtle);
}

#report-display [data-section-id] h3[contenteditable="false"] {
    user-select: none;
}

/* Selectable sections — header click for refinement */
#report-display [data-section-id] {
    border-radius: var(--radius-xs);
    position: relative;
    transition: outline 0.15s, box-shadow 0.15s;
}

#report-display [data-section-id]:not(.non-refinable) h3 {
    cursor: pointer;
    transition: color 0.15s;
}

#report-display [data-section-id]:not(.non-refinable) h3:hover {
    color: var(--accent);
}

#report-display [data-section-id]:not(.non-refinable) h3::after {
    content: "AI";
    font-size: 0.6rem;
    font-weight: var(--font-weight-semibold);
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--accent-muted);
    color: var(--accent);
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.15s;
    vertical-align: middle;
}

#report-display [data-section-id]:not(.non-refinable):hover h3::after {
    opacity: 1;
}

#report-display [data-section-id].selected-section {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    box-shadow: 0 0 0 8px var(--accent-subtle);
}

.refine-bottom-panel {
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-container);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.refine-close-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.refine-close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-surface-raised);
}

.refine-selection-indicator {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-page);
    margin-top: 1.5rem;
    padding: 0.5rem 0.85rem;
    background: var(--bg-surface-raised);
    border-radius: var(--radius-pill);
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--text-tertiary);
}

.refine-selection-indicator.has-selection {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--accent-subtle);
}

body.dark-theme .refine-selection-indicator:not(.has-selection) {
    background: #1B1918;
}

body.dark-theme .chat-tool-spinner {
    border-color: rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
}

/* Dark theme: transparent status/feedback elements */
body.dark-theme .feedback-warning {
    background: rgba(220, 24, 12, 0.10);
    border-color: rgba(220, 24, 12, 0.3);
    color: var(--error);
}
body.dark-theme .feedback-success {
    background: rgba(19, 158, 25, 0.10);
    border-color: rgba(19, 158, 25, 0.3);
    color: var(--success);
}
body.dark-theme .search-dropdown-empty {
    color: var(--warning);
}
body.dark-theme .search-dropdown-item.client-has-onboarding {
    background: rgba(19, 158, 25, 0.10);
}
body.dark-theme .search-dropdown-item.client-has-onboarding:hover {
    background: rgba(19, 158, 25, 0.18);
}
body.dark-theme .search-dropdown-item.client-no-onboarding {
    background: rgba(229, 154, 0, 0.10);
}
body.dark-theme .search-dropdown-item.client-no-onboarding:hover {
    background: rgba(229, 154, 0, 0.18);
}
body.dark-theme .report-risk-assessment {
    border-color: rgba(229, 154, 0, 0.3);
}
body.dark-theme .action-priority.HIGH { color: var(--error); }
body.dark-theme .action-priority.MEDIUM { color: var(--warning); }
body.dark-theme .action-priority.LOW { color: var(--success); }
body.dark-theme .sdi-status-10 { background: rgba(123, 31, 162, 0.12); color: #ce93d8; }
body.dark-theme .sdi-status-20 { background: rgba(21, 101, 192, 0.12); color: #90caf9; }
body.dark-theme .sdi-status-30 { background: rgba(229, 154, 0, 0.10); color: var(--warning); }
body.dark-theme .sdi-status-40 { background: rgba(230, 81, 0, 0.10); color: #ffb74d; }
body.dark-theme .sdi-status-50 { background: rgba(19, 158, 25, 0.10); color: var(--success); }
body.dark-theme .sdi-status-60 { background: rgba(93, 64, 55, 0.15); color: #bcaaa4; }
body.dark-theme .sdi-status-70 { background: rgba(97, 97, 97, 0.15); color: #bdbdbd; }
body.dark-theme .sdi-status-90 { background: rgba(220, 24, 12, 0.10); color: var(--error); }
body.dark-theme .chat-message.system { color: var(--success); }
body.dark-theme .chat-message.error { color: var(--error); }
body.dark-theme .chat-client-card {
    background: var(--bg-surface-alt);
    border-color: var(--border-color);
}
body.dark-theme .chat-client-card.client-has-onboarding {
    background: rgba(19, 158, 25, 0.10);
}
body.dark-theme .chat-client-card.client-has-onboarding:hover:not(:disabled) {
    background: rgba(19, 158, 25, 0.18);
}
body.dark-theme .chat-client-card.client-no-onboarding {
    background: rgba(229, 154, 0, 0.10);
}
body.dark-theme .chat-client-card.client-no-onboarding:hover:not(:disabled) {
    background: rgba(229, 154, 0, 0.18);
}
body.dark-theme .chat-messages {
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
body.dark-theme .chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}
body.dark-theme .chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}
body.dark-theme .btn-remove-directive {
    background: rgba(220, 24, 12, 0.10);
    border-color: rgba(220, 24, 12, 0.35);
}
body.dark-theme .btn-remove-directive:hover {
    background: rgba(220, 24, 12, 0.25);
}
body.dark-theme .login-error {
    background: rgba(220, 24, 12, 0.10);
    border-color: rgba(220, 24, 12, 0.3);
}


/* Diff highlighting */
.highlight-primary {
    background: var(--success-bg);
    border-radius: 2px;
    padding: 0 2px;
}

.highlight-secondary {
    background: var(--warning-bg);
    border-radius: 2px;
    padding: 0 2px;
}

.highlight-legend {
    display: flex;
    gap: 1.25rem;
    font-size: 0.8rem;
    color: var(--text-tertiary);
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
}

.highlight-legend span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.legend-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: var(--radius-xs);
}

.legend-swatch.primary { background: var(--success-bg); }
.legend-swatch.secondary { background: var(--warning-bg); }

.refinement-chat {
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    padding: 0.75rem;
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 0.75rem;
    display: none;
}

.refinement-chat.has-messages {
    display: block;
}

.chat-message {
    margin-bottom: 0.6rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.chat-message.user {
    background: var(--accent-subtle);
    border-left: 3px solid var(--accent);
}

.chat-message.system {
    background: var(--success-bg);
    border-left: 3px solid var(--success);
}

.chat-message.error {
    background: var(--error-bg);
    border-left: 3px solid var(--error);
}

.chat-message .chat-label {
    font-size: 0.7rem;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    color: var(--text-tertiary);
    margin-bottom: 0.2rem;
    letter-spacing: 0.04em;
}

.refinement-input-area textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    resize: vertical;
    color: var(--text-primary);
}

.refinement-input-area textarea:focus {
    outline: none;
    border-color: var(--accent-light);
}

.refinement-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

/* === Tables === */
table {
    font-size: 0.85rem;
}

table th {
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.7rem;
    border-bottom: 1px solid var(--divider);
}

table td {
    border-bottom: 1px solid var(--divider);
}

/* === Footer === */
.app-footer {
    text-align: center;
    padding: 1rem;
    margin-top: 0.75rem;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    border-top: 1px solid var(--divider);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.report-page .app-main {
    overflow-y: hidden;
    max-width: 900px;
}

.report-page .refine-bottom-panel {
    border-radius: var(--radius-container) var(--radius-container) 0 0;
}


/* === Responsive === */
@media (max-width: 640px) {
    .form-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .field-row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .riskreturn-params {
        flex-direction: column;
        gap: 0.5rem;
    }

    .step-line {
        width: 16px;
    }

    .step-label {
        font-size: 0.55rem;
    }

    .report-header {
        padding: 1.25rem;
    }

    .report-body {
        padding: 1.25rem;
    }

    .checkbox-row {
        flex-direction: column;
        gap: 0.5rem;
    }
}


/* === Login Page === */
.login-theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-secondary) !important;
}
.login-theme-toggle:hover {
    border-color: var(--text-secondary) !important;
    color: var(--text-primary) !important;
}
body.dark-theme .login-theme-toggle {
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.55);
}
body.dark-theme .login-theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.8);
}
.login-page {
    background: var(--bg-page);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    padding: 1rem;
}
.login-container {
    width: 100%;
    max-width: 400px;
}
.login-card {
    background: var(--bg-surface);
    border-radius: var(--radius-container);
    box-shadow: var(--shadow-elevated);
    padding: 2.5rem 2rem;
    text-align: center;
}
.login-logo {
    height: 32px;
    margin-bottom: 1rem;
}
.login-card h1 {
    font-size: 1.4rem;
    margin: 0 0 0.25rem;
    color: var(--text-primary);
}
.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 1.5rem;
}
.login-field {
    text-align: left;
    margin-bottom: 1rem;
}
.login-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}
.login-field input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    box-sizing: border-box;
}
.login-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(251, 123, 52, 0.15);
}
.login-error {
    background: #fef2f2;
    color: var(--error);
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: left;
}
.login-btn {
    width: 100%;
    padding: 0.7rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}
.toolbar-username {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
}
.btn-theme-toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.55);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
}
.btn-theme-toggle:hover {
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.8);
}

/* === Debug Pane === */
.debug-pane-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.debug-pane {
    background: #1a1a2e;
    color: #ccc;
    border: 1px solid #2a2a4a;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    border-radius: var(--radius-container);
    overflow: hidden;
}
.debug-pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    background: #16162a;
    border-bottom: 1px solid #2a2a4a;
    flex-shrink: 0;
}
.debug-pane-header h3 {
    margin: 0;
    font-size: 0.8rem;
    color: #aaa;
    font-weight: 500;
}
.debug-tabs {
    display: flex;
    gap: 0;
}
.debug-tab {
    background: none;
    border: 1px solid #3a3a5a;
    color: #888;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.15s;
}
.debug-tab:first-child {
    border-radius: 4px 0 0 4px;
}
.debug-tab:last-child {
    border-radius: 0 4px 4px 0;
    border-left: none;
}
.debug-tab.active {
    background: #2a2a5a;
    color: #ddd;
    border-color: #5a5aaa;
}
.debug-tab:hover:not(.active) {
    color: #bbb;
    border-color: #5a5a8a;
}
.debug-header-actions {
    display: flex;
    gap: 0.4rem;
}
.btn-debug-refresh,
.btn-debug-close {
    background: none;
    border: 1px solid #3a3a5a;
    color: #999;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    font-family: inherit;
}
.btn-debug-refresh:hover,
.btn-debug-close:hover {
    border-color: #5a5a8a;
    color: #ddd;
}
.debug-pane-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}
.debug-empty,
.debug-loading {
    color: #666;
    text-align: center;
    padding: 2rem 0;
    font-style: italic;
}
.debug-entry {
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    background: #12122a;
}
.debug-entry-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid #2a2a4a;
    font-size: 0.7rem;
}
.debug-tag {
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.65rem;
    text-transform: uppercase;
}
.debug-tag-chat {
    background: #1a3a5a;
    color: #6ab0f3;
}
.debug-tag-report {
    background: #3a2a1a;
    color: #f3a96a;
}

/* Provider bar in debug pane */
.debug-provider-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    background: #1a1a32;
    border-bottom: 1px solid #2a2a4a;
    font-size: 0.72rem;
    flex-shrink: 0;
}
.debug-provider-label {
    color: #777;
    font-weight: 500;
}
.debug-provider-value {
    color: #ddd;
    font-weight: 500;
}
.debug-provider-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #888;
}
.debug-provider-dot-primary {
    background: #3b82f6;
}
.debug-provider-dot-secondary {
    background: #8b5cf6;
}
.debug-failover-tag {
    margin-left: auto;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    background: #4c1d95;
    color: #c4b5fd;
    font-size: 0.62rem;
    font-weight: 500;
    text-transform: uppercase;
}

/* Provider tags on debug entries */
.debug-provider-tag {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
}
.debug-provider-tag-primary {
    background: #1e3a5f;
    color: #60a5fa;
}
.debug-provider-tag-secondary {
    background: #2e1065;
    color: #a78bfa;
}
.debug-entry-error {
    border-color: #5a1a1a;
    background: #1a0a0a;
}
.debug-ts {
    color: #666;
}
.debug-dur {
    color: #888;
    margin-left: auto;
}
.debug-entry details {
    border-top: 1px solid #2a2a4a;
}
.debug-entry details summary {
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    color: #888;
    font-size: 0.7rem;
    user-select: none;
}
.debug-entry details summary:hover {
    color: #bbb;
}
.debug-json {
    margin: 0;
    padding: 0.5rem;
    font-size: 0.65rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    color: #a0d0a0;
    background: #0e0e20;
    max-height: 400px;
    overflow-y: auto;
}
.debug-tag-bff {
    background: #1a3a2a;
    color: #6af3a0;
}
.debug-url {
    padding: 0.2rem 0.6rem;
    font-size: 0.65rem;
    color: #7a7aaa;
    word-break: break-all;
    border-bottom: 1px solid #2a2a4a;
}
.debug-status {
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 500;
}
.debug-status-ok {
    background: #1a3a1a;
    color: #6af36a;
}
.debug-status-err {
    background: #3a1a1a;
    color: #f36a6a;
}

/* === Signing Button & Modal === */
.signing-actions {
    margin-top: 1.25rem;
    text-align: center;
}
.btn-signing {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.btn-signing:hover {
    background: var(--accent-hover);
}
.btn-signing:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-trace {
    background: #555;
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-trace:hover {
    background: #777;
}
.signing-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.signing-modal {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-container);
    width: 80vw;
    max-width: 1000px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-modal);
}
.signing-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-surface-alt);
    border-bottom: 1px solid var(--divider);
    border-radius: var(--radius-container) var(--radius-container) 0 0;
}
.signing-modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: var(--font-weight-semibold);
}
.signing-modal-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 0.3rem;
    line-height: 1;
    font-family: var(--font);
}
.signing-modal-close:hover {
    color: var(--text-primary);
}
.signing-modal-meta {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--divider);
    background: var(--bg-surface);
}
.signing-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
}
.signing-modal-json {
    margin: 0;
    padding: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-primary);
    background: var(--bg-surface-raised);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    max-height: none;
}
.signing-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--divider);
    background: var(--bg-surface-alt);
    border-radius: 0 0 var(--radius-container) var(--radius-container);
}

/* === iFrame embed mode === */
body.iframe-mode .btn-toolbar-hidden-iframe,
body.iframe-mode .toolbar-username,
body.iframe-mode #fetched-portfolio-section,
body.iframe-mode #transactions-section,
body.iframe-mode #onboarding-data-section,
body.iframe-mode #report-settings-section,
body.iframe-mode #report-settings-section-report,
body.iframe-mode #show-prompt-actions,
body.iframe-mode #prompt-preview-section,
body.iframe-mode .btn-trace,
body.iframe-mode .version-indicator {
    display: none !important;
}
