/* MoneyBot Chat — Vanilla CSS */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f6fa;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#app {
    display: flex;
    flex-direction: row;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    background: #fff;
    box-shadow: 0 0 20px rgba(0,0,0,0.08);
}

/* Profile sidebar */
#profile-sidebar {
    width: 420px;
    min-width: 420px;
    height: 100vh;
    overflow-y: auto;
    background: #fafbfc;
    border-right: 1px solid #e0e0e0;
    padding: 20px 16px;
}

#profile-sidebar:empty {
    display: none;
}

.sidebar-name {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 2px;
}

.sidebar-archetype {
    font-size: 13px;
    color: #6c63ff;
    font-weight: 500;
    margin-bottom: 16px;
}

.sidebar-section {
    margin-bottom: 14px;
}

.sidebar-section-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    font-weight: 600;
    margin-bottom: 4px;
}

.sidebar-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 12px;
    font-size: 12px;
    color: #444;
}

.sidebar-grid .label {
    color: #888;
}

.sidebar-grid .value {
    font-weight: 500;
    text-align: right;
}

.sidebar-notes {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    font-size: 11px;
    color: #666;
    line-height: 1.5;
    font-style: italic;
}

/* Sidebar transaction history (collapsible) */
.sidebar-transactions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.sidebar-transactions summary {
    cursor: pointer;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    font-weight: 600;
    padding: 4px 0;
    user-select: none;
}

.sidebar-transactions summary:hover {
    color: #555;
}

.txn-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin-top: 6px;
}

.txn-table th {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    font-weight: 600;
    text-align: left;
    padding: 4px 4px;
    border-bottom: 1px solid #e0e0e0;
}

.txn-table th:last-child {
    text-align: right;
}

.txn-table td {
    padding: 3px 4px;
    color: #444;
    border-bottom: 1px solid #f0f0f0;
}

.txn-table td:last-child {
    text-align: right;
    font-weight: 500;
}

.txn-table tr:nth-child(even) {
    background: #f8f9fa;
}

.txn-table tr.txn-rebalance {
    background: #fff8e1;
    font-style: italic;
}

.txn-table tr.txn-rebalance td {
    color: #8d6e00;
    font-size: 10px;
}

.txn-month-header td {
    font-weight: 600;
    color: #1a1a2e;
    padding-top: 8px;
    border-bottom: 1px solid #ddd;
    font-size: 11px;
}

/* Chat column */
#chat-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
}

/* Header */
header {
    background: #1a1a2e;
    color: #fff;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
}

#session-status {
    font-size: 12px;
    color: #888;
}

#session-status.connected {
    color: #4caf50;
}

/* Chat container */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Messages */
.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user {
    align-self: flex-end;
    background: #1a1a2e;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #f0f0f5;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: #fff8e1;
    color: #666;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
}

/* Visualization containers inside messages */
.viz-container {
    margin: 12px 0 4px 0;
    padding: 12px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.viz-container canvas {
    max-width: 100%;
    max-height: 250px;
}

/* Metric card */
.metric-card {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin: 4px;
    min-width: 120px;
}

.metric-card .metric-value {
    font-size: 24px;
    font-weight: 700;
    color: #1a1a2e;
}

.metric-card .metric-label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    margin-top: 4px;
}

.metric-card .metric-delta {
    font-size: 12px;
    margin-top: 2px;
}

.metric-card .metric-delta.positive { color: #4caf50; }
.metric-card .metric-delta.negative { color: #f44336; }

/* Probability gauge (SVG) */
.gauge-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
}

.gauge-container svg {
    max-width: 160px;
}

.gauge-label {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
}

/* Typing indicator */
#typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    color: #888;
    font-size: 13px;
}

#typing-indicator.hidden {
    display: none;
}

.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #888;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Tool call progress */
.tool-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #e8f5e9;
    color: #2e7d32;
    border-radius: 6px;
    font-size: 12px;
    align-self: flex-start;
}

.tool-progress .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #81c784;
    border-top-color: #2e7d32;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Input bar */
#input-bar {
    display: flex;
    padding: 12px;
    gap: 8px;
    border-top: 1px solid #e0e0e0;
    background: #fff;
}

#message-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#message-input:focus {
    border-color: #1a1a2e;
}

#send-btn {
    padding: 10px 20px;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

#send-btn:hover {
    background: #2d2d4e;
}

#send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Hidden utility */
.hidden { display: none !important; }

/* Profile Selector */
#profile-selector {
    max-width: 1000px;
    margin: 40px auto;
    padding: 20px;
    text-align: center;
}

#profile-selector h2 {
    font-size: 24px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 4px;
}

.selector-subtitle {
    color: #888;
    margin-bottom: 20px;
    font-size: 14px;
}

/* Mode Toggle */
#mode-toggle {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.mode-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 14px;
    color: #555;
}

.mode-option:has(input:checked) {
    border-color: #1a1a2e;
    background: #f0f0f5;
    color: #1a1a2e;
    font-weight: 600;
}

.mode-option input[type="radio"] {
    accent-color: #1a1a2e;
}

#profile-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    text-align: left;
}

.profile-card {
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.profile-card:hover {
    border-color: #1a1a2e;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.profile-name {
    font-size: 17px;
    font-weight: 700;
    color: #1a1a2e;
}

.profile-archetype {
    font-size: 13px;
    color: #6c63ff;
    margin: 2px 0 12px 0;
    font-weight: 500;
}

.profile-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    font-size: 12px;
    color: #555;
}

.profile-notes {
    margin-top: 12px;
    font-size: 11px;
    color: #888;
    line-height: 1.4;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

/* Back button */
#back-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 12px;
}

#back-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Dashboard panels in sidebar */
.sidebar-dashboard {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.dash-section {
    margin-bottom: 16px;
}

.dash-gauge {
    display: flex;
    justify-content: center;
    margin: 6px 0 4px 0;
}

.dash-gauge svg {
    max-width: 110px;
}

.dash-gauge-label {
    text-align: center;
    font-size: 10px;
    color: #888;
    margin-top: 2px;
}

.dash-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px 8px;
    font-size: 11px;
    color: #444;
    margin-top: 6px;
}

.dash-stats .label { color: #888; }
.dash-stats .value { font-weight: 500; text-align: right; }

.dash-no-target {
    text-align: center;
    font-size: 11px;
    color: #999;
    font-style: italic;
    padding: 8px 0;
}

.dash-donut-wrap {
    display: flex;
    justify-content: center;
}

.dash-donut-wrap canvas {
    max-height: 160px;
}

.dash-account-row {
    display: flex;
    gap: 4px;
    justify-content: space-between;
}

.dash-account {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.dash-account-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #888;
    font-weight: 600;
    margin-bottom: 2px;
}

.dash-account canvas {
    max-height: 80px;
}

.dash-hill-wrap {
    margin-top: 4px;
}

.dash-hill-wrap canvas {
    max-height: 160px;
    width: 100%;
}

.dash-hill-legend {
    display: flex;
    justify-content: center;
    gap: 10px;
    font-size: 9px;
    margin-top: 4px;
    color: #888;
}

.dash-hill-legend span {
    display: flex;
    align-items: center;
    gap: 3px;
}

.dash-hill-legend .swatch {
    display: inline-block;
    width: 12px;
    height: 3px;
    border-radius: 1px;
}

/* Changeable Factors */
.cf-section {
    margin-bottom: 14px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.cf-row {
    margin-bottom: 8px;
}

.cf-row-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.cf-label {
    font-size: 11px;
    color: #888;
    font-weight: 500;
}

.cf-value {
    font-size: 11px;
    font-weight: 600;
    color: #1a1a2e;
}

.cf-slider {
    width: 100%;
    margin: 2px 0;
    -webkit-appearance: none;
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    outline: none;
}

.cf-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #1a1a2e;
    cursor: pointer;
}

.cf-input {
    width: 90px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 11px;
    text-align: right;
}

.cf-input:focus {
    border-color: #1a1a2e;
    outline: none;
}

.cf-risk-detail {
    font-size: 10px;
    color: #888;
    text-align: center;
    margin-top: 2px;
    padding: 2px 6px;
    background: #f8f9fa;
    border-radius: 3px;
}

.cf-risk-return {
    color: #28a745;
    font-weight: 700;
    font-size: 1.1em;
}

.cf-risk-loss {
    color: #dc3545;
    font-weight: 700;
    font-size: 1.1em;
}

.cf-risk-info-icon {
    cursor: pointer;
    position: relative;
    font-size: 0.85em;
    opacity: 0.7;
}
.cf-risk-info-icon:hover {
    opacity: 1;
}
.cf-risk-info-icon:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    width: 220px;
    line-height: 1.4;
    white-space: normal;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.cf-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 10px 0 6px;
}

.cf-nav button {
    padding: 4px 12px;
    font-size: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    color: #555;
}

.cf-nav button:hover:not(:disabled) {
    border-color: #1a1a2e;
    color: #1a1a2e;
}

.cf-nav button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.rebalance-btn {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 6px;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.2s;
}

.rebalance-btn:hover {
    background: #2d2d4e;
}

.rebalance-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.cf-updating {
    text-align: center;
    font-size: 10px;
    color: #6c63ff;
    padding: 4px 0;
    font-style: italic;
}

.cf-pension-equiv {
    font-size: 0.85em;
    color: #666;
    text-align: center;
    margin-top: 1px;
}

.cf-savings-split {
    font-size: 0.85em;
    color: #666;
    margin-top: 3px;
    line-height: 1.4;
}

.cf-isa-first-label {
    font-size: 10px;
    color: #888;
    font-weight: 400;
    cursor: pointer;
    margin-left: 6px;
}

.cf-isa-first-label input {
    vertical-align: middle;
    margin-right: 2px;
}

/* Question suggestion buttons — above input bar */
#question-bar {
    padding: 0 12px;
}

.question-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0 4px;
    max-height: 108px;
    overflow: hidden;
}

.question-btn {
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.question-btn:hover {
    background: #f5f5f5;
    border-color: #999;
    color: #222;
}

.question-btn:active {
    transform: scale(0.97);
}

/* Responsive */
@media (max-width: 900px) {
    #profile-sidebar {
        display: none;
    }

    #app {
        max-width: 100%;
    }

    .message {
        max-width: 92%;
    }
}
