/* TradingMax SaaS — Modern Dark Trading UI */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d28;
    --bg-card: #1e2233;
    --bg-input: #252a3a;
    --border: #2d3348;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b0;
    --accent: #4f8cff;
    --accent-hover: #6ba0ff;
    --green: #00c853;
    --red: #ff3d57;
    --yellow: #ffc107;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── Layout ──────────────────────────────────────── */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ─── Navbar ──────────────────────────────────────── */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    border-radius: 0 0 var(--radius) var(--radius);
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.navbar-brand span {
    color: var(--text-primary);
}

.navbar-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.navbar-links a {
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.2s;
}

.navbar-links a:hover, .navbar-links a.active {
    color: var(--accent);
}

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

/* ─── Cards ──────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.stat-grid-6 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

/* ─── Stat Boxes ─────────────────────────────────── */
.stat-box {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.neutral { color: var(--accent); }

/* ─── Forms ──────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input, select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ─── Buttons ────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

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

.btn-success {
    background: var(--green);
    color: #fff;
}
.btn-success:hover { opacity: 0.85; }

.btn-danger {
    background: var(--red);
    color: #fff;
}
.btn-danger:hover { opacity: 0.85; }

.btn-sandbox {
    background: linear-gradient(135deg, #ff9800, #ff5722);
    color: #fff;
    font-weight: 600;
}
.btn-sandbox:hover { opacity: 0.85; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}
.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-block { width: 100%; }

.btn-group {
    display: flex;
    gap: 12px;
}

/* ─── Tables ─────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

td {
    font-size: 0.95rem;
}

tr:hover { background: rgba(79, 140, 255, 0.05); }

/* ─── Login Page ─────────────────────────────────── */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 2rem;
    color: var(--accent);
}

.login-logo p {
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ─── Price Flash Animations (Flatex Style) ───────── */
.flash-up {
    animation: flashUp 600ms ease-out;
}
.flash-down {
    animation: flashDown 600ms ease-out;
}

@keyframes flashUp {
    0% { background-color: rgba(0, 200, 83, 0.35); }
    100% { background-color: transparent; }
}

@keyframes flashDown {
    0% { background-color: rgba(255, 61, 87, 0.35); }
    100% { background-color: transparent; }
}

.stat-box.flash-up { animation: statFlashUp 600ms ease-out; }
.stat-box.flash-down { animation: statFlashDown 600ms ease-out; }

@keyframes statFlashUp {
    0% { box-shadow: inset 0 0 20px rgba(0, 200, 83, 0.3); }
    100% { box-shadow: none; }
}
@keyframes statFlashDown {
    0% { box-shadow: inset 0 0 20px rgba(255, 61, 87, 0.3); }
    100% { box-shadow: none; }
}

/* ─── Positions List ─────────────────────────────── */
.position-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 24px;
    padding: 16px 20px;
    background: var(--bg-input);
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 3px solid var(--border);
    transition: border-color 0.2s;
}

.position-card.side-long-border { border-left-color: var(--green); }
.position-card.side-short-border { border-left-color: var(--red); }

.pos-header {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.position-symbol {
    font-weight: 700;
    font-size: 1.1rem;
}

.pos-side-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.pos-side-badge.long {
    background: rgba(0, 200, 83, 0.15);
    color: var(--green);
}
.pos-side-badge.short {
    background: rgba(255, 61, 87, 0.15);
    color: var(--red);
}

.ai-status-indicator {
    padding: 8px 0;
    min-width: 140px;
    display: flex;
    align-items: center;
}

.pos-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pos-field-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pos-field-value {
    font-size: 0.95rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    padding: 2px 4px;
    border-radius: 4px;
}

.pos-field-value.price-cell {
    font-weight: 600;
}

.pos-pnl-positive { color: var(--green); }
.pos-pnl-negative { color: var(--red); }

.pos-stop-type {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 4px;
    font-weight: 600;
}

.stop-normal { background: rgba(154, 160, 176, 0.15); color: var(--text-secondary); }
.stop-breakeven { background: rgba(255, 193, 7, 0.15); color: var(--yellow); }
.stop-trailing { background: rgba(79, 140, 255, 0.15); color: var(--accent); }

.side-long { color: var(--green); }
.side-short { color: var(--red); }

/* ─── Last Update / Activity ────────────────────── */
.last-update {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

.last-update .loop-counter {
    margin-left: 12px;
    color: var(--accent);
}

.last-update .loop-countdown {
    margin-left: 10px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
    opacity: 0.85;
}

/* ─── Status Indicator ───────────────────────────── */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
}

.status-running { background: var(--green); animation: pulse 2s infinite; }
.status-stopped { background: var(--red); }

.sandbox-badge {
    display: inline-block;
    background: linear-gradient(135deg, #ff9800, #ff5722);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 4px;
    letter-spacing: 1px;
    vertical-align: middle;
    margin-left: 8px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ─── Toast / Alerts ─────────────────────────────── */
.toast {
    position: fixed;
    bottom: 80px;
    right: 24px;
    padding: 16px 24px;
    border-radius: var(--radius);
    color: #fff;
    font-weight: 500;
    z-index: 10001;
    animation: slideIn 0.3s ease;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--accent); }

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

/* ─── Tabs ───────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 4px;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--accent);
    color: #fff;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── Config Sections ────────────────────────────── */
.config-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 20px 0 12px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.config-section-title:first-of-type {
    margin-top: 0;
}

/* ─── Toggle Grid ────────────────────────────────── */
.toggle-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.toggle-label:has(input:checked) {
    border-color: var(--green);
    background: rgba(0, 200, 83, 0.08);
}

.toggle-label input {
    width: auto;
    accent-color: var(--green);
}

/* ─── Template Description ───────────────────────── */
.template-desc {
    padding: 12px 16px;
    background: var(--bg-input);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.template-desc-short {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.template-desc-detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: pre-line;
    line-height: 1.6;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* ─── Metric Grid (Analytics) ────────────────────── */
.metric-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 0.95rem;
}

.metric-row .positive { color: var(--green); font-weight: 600; }
.metric-row .negative { color: var(--red); font-weight: 600; }

/* ─── 2FA QR Code ───────────────────────────────── */
#twofa-qr svg {
    max-width: 200px;
    height: auto;
    background: white;
    padding: 8px;
    border-radius: 8px;
}

/* ─── Tooltip (? Help Icons) ─────────────────────── */
.help-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 700;
    cursor: help;
    margin-left: 6px;
    position: relative;
    vertical-align: middle;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.help-tip:hover {
    background: var(--accent);
    color: #fff;
}

.help-tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1a1d28;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 999;
    text-transform: none;
    letter-spacing: normal;
}

.help-tip:hover::after {
    opacity: 1;
}

.help-tip::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--border);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 1000;
}

.help-tip:hover::before {
    opacity: 1;
}

/* Align tooltip to the right when at the left edge */
.help-tip.tip-right::after {
    left: 0;
    transform: none;
}
.help-tip.tip-right::before {
    left: 8px;
    transform: none;
}

/* ─── Asset Selection ────────────────────────────── */
.asset-search-container {
    position: relative;
}

.asset-search-input {
    padding-left: 40px !important;
}

.asset-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
    pointer-events: none;
}

.asset-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.asset-search-results.open {
    display: block;
}

.asset-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border);
}

.asset-result-item:last-child {
    border-bottom: none;
}

.asset-result-item:hover {
    background: rgba(79, 140, 255, 0.1);
}

.asset-result-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.asset-result-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.asset-result-add {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 600;
}

/* Asset Group Cards */
.asset-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.asset-group-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    text-align: center;
}

.asset-group-card:hover {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.05);
}

.asset-group-card.selected {
    border-color: var(--green);
    background: rgba(0, 200, 83, 0.06);
}

.asset-group-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.asset-group-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.asset-group-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Asset Detail List */
.asset-detail-list {
    margin-top: 16px;
}

.asset-detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: 6px;
    margin-bottom: 6px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}

.asset-detail-item:hover {
    border-color: var(--border);
}

.asset-detail-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.asset-detail-symbol {
    font-weight: 700;
    font-size: 0.95rem;
    min-width: 80px;
}

.asset-detail-name {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.asset-detail-isin {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-family: monospace;
}

.asset-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
}

.asset-toggle input[type="checkbox"] {
    width: auto;
    accent-color: var(--green);
}

/* Watchlist Tags */
.watchlist-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.watchlist-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(79, 140, 255, 0.12);
    border: 1px solid var(--accent);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent);
}

.watchlist-tag .remove-tag {
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.6;
    transition: opacity 0.15s;
    line-height: 1;
}

.watchlist-tag .remove-tag:hover {
    opacity: 1;
    color: var(--red);
}

/* ─── Help Tab ──────────────────────────────────── */
.help-section {
    margin-bottom: 24px;
}

.help-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.help-section p, .help-section li {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
}

.help-section ul {
    padding-left: 20px;
    margin-top: 8px;
}

.help-section li {
    margin-bottom: 6px;
}

.help-section strong {
    color: var(--text-primary);
}

.help-faq {
    margin-top: 12px;
}

.help-faq details {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    overflow: hidden;
}

.help-faq summary {
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: background 0.15s;
    list-style: none;
}

.help-faq summary::-webkit-details-marker { display: none; }
.help-faq summary::before {
    content: '+ ';
    color: var(--accent);
    font-weight: 700;
}

.help-faq details[open] summary::before {
    content: '- ';
}

.help-faq summary:hover {
    background: rgba(79, 140, 255, 0.05);
}

.help-faq .help-answer {
    padding: 0 16px 14px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.6;
}

/* ─── Sandbox Reset Button ──────────────────────── */
.btn-reset {
    background: transparent;
    border: 1px solid var(--yellow);
    color: var(--yellow);
    font-weight: 600;
    font-size: 0.85rem;
}
.btn-reset:hover {
    background: rgba(255, 193, 7, 0.1);
}

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
    .navbar { flex-direction: column; gap: 12px; }
    .card-grid { grid-template-columns: 1fr; }
    .stat-grid-6 { grid-template-columns: repeat(2, 1fr); }
    .btn-group { flex-direction: column; }
    .toggle-grid { flex-direction: column; }
    .position-card { grid-template-columns: 1fr; }
    table { font-size: 0.85rem; }
    th, td { padding: 8px 6px; }
    .chat-panel.open { width: calc(100vw - 16px); right: 8px; bottom: 8px; height: 70vh; }
}

/* ─── AI Chat Widget ────────────────────────────── */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Inter', sans-serif;
}

.chat-bubble {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 140, 255, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}
.chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(79, 140, 255, 0.55);
}
.chat-bubble.hidden { display: none; }

.chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: var(--red);
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

/* Chat Panel */
.chat-panel {
    display: none;
    flex-direction: column;
    width: 400px;
    height: 560px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.45);
    overflow: hidden;
    position: absolute;
    bottom: 0;
    right: 0;
}
.chat-panel.open {
    display: flex;
    animation: chatSlideUp 0.25s ease-out;
}
@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
    color: #fff;
    flex-shrink: 0;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}
.chat-ai-dot {
    width: 8px;
    height: 8px;
    background: #00e676;
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}
.chat-close:hover { opacity: 1; }

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.chat-msg {
    max-width: 88%;
    animation: msgFade 0.2s ease-out;
}
@keyframes msgFade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg-user {
    align-self: flex-end;
}
.chat-msg-ai {
    align-self: flex-start;
}
.chat-msg-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}
.chat-msg-user .chat-msg-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg-ai .chat-msg-content {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

/* Typing Indicator */
.chat-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex-shrink: 0;
}
.typing-dots {
    display: flex;
    gap: 3px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Chat Input */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}
.chat-input:focus {
    border-color: var(--accent);
}
.chat-input::placeholder { color: var(--text-secondary); }
.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent);
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
.chat-send:hover { background: var(--accent-hover); }

/* Chat Action Cards */
.chat-actions {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-action-card {
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 10px 12px;
    transition: opacity 0.3s, border-color 0.3s;
}
.chat-action-card.action-executed {
    border-color: var(--green);
    opacity: 0.7;
}
.chat-action-card.action-dismissed {
    border-color: var(--text-secondary);
    opacity: 0.5;
}
.chat-action-desc {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.85rem;
    margin-bottom: 8px;
}
.chat-action-type {
    font-weight: 600;
    color: var(--accent);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.chat-action-buttons {
    display: flex;
    gap: 8px;
}
.btn-action-confirm {
    padding: 5px 14px;
    border-radius: 6px;
    border: none;
    background: var(--green);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-action-confirm:hover { background: #00b848; }
.btn-action-dismiss {
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: color 0.15s;
}
.btn-action-dismiss:hover { color: var(--text-primary); }
.chat-action-pending { color: var(--yellow); font-size: 0.85rem; }
.chat-action-done { color: var(--green); font-size: 0.85rem; font-weight: 500; }
.chat-action-error { color: var(--red); font-size: 0.85rem; }
.chat-action-dismissed { color: var(--text-secondary); font-size: 0.85rem; font-style: italic; }
.chat-download-link {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 12px;
    background: var(--accent);
    color: #fff !important;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}
.chat-download-link:hover { background: var(--accent-hover, #4a90d9); }
/* ─── Pre-Trade Simulation Card ─────────────────── */
.sim-card {
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    border-left: 3px solid var(--green);
    font-size: 0.82rem;
}
.sim-card.sim-medium {
    border-left-color: var(--yellow);
}
.sim-card.sim-high {
    border-left-color: var(--red);
}
.sim-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 6px;
}
.sim-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.sim-metric-value {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.sim-metric-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: center;
}
.sim-regime {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding-top: 4px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.sim-warning {
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(255, 193, 7, 0.12);
    border-radius: 4px;
    color: var(--yellow);
    font-size: 0.78rem;
    font-weight: 500;
}
.sim-high .sim-warning {
    background: rgba(255, 61, 87, 0.12);
    color: var(--red);
}

.chat-provider-hint {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
    opacity: 0.7;
}

/* ─── Language Toggle ──────────────────────────────── */
.lang-toggle {
    background: var(--bg-input);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}
.lang-toggle:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
