/* TradingBox AI panel (app/ai-panel.js). Uses the page's colour tokens from index.html. */

.ai-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ai-panel[hidden] { display: none; }

.ai-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px 10px;
    font-size: 13px;
}

.ai-mark, .ai-hero-mark { display: grid; color: #a78bfa; }
.ai-mark svg { width: 18px; height: 18px; }

.ai-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 14px 12px;
}

/* Empty state, as on the LuxAlgo-style landing */
.ai-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 48px 8px 16px;
    text-align: center;
}

.ai-hero-mark svg { width: 34px; height: 34px; }
.ai-hero h2 { margin: 6px 0 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.ai-hero p { margin: 0; color: var(--text-muted); font-size: 13px; line-height: 1.45; }
.ai-panel.has-thread .ai-hero { display: none; }

.ai-notice {
    margin: 8px 0;
    padding: 12px;
    border-radius: 12px;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.5;
}

.ai-notice[hidden] { display: none; }

.ai-notice--locked {
    display: grid;
    justify-items: center;
    gap: 10px;
    text-align: center;
    border-style: solid;
    border-color: rgba(123, 77, 255, 0.35);
    background: rgba(123, 77, 255, 0.08);
    color: var(--text);
}

.ai-unlock {
    padding: 8px 16px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 13px;
    color: #fff;
    background: linear-gradient(90deg, #7b4dff, #5a2cff);
}

/* Conversation */
.ai-thread {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 4px 0 0;
    list-style: none;
}

.ai-msg--user { align-self: flex-end; max-width: 88%; }

.ai-bubble {
    padding: 9px 12px;
    border-radius: 14px 14px 4px 14px;
    background: var(--accent-soft);
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-text {
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg--error .ai-text { color: var(--down); }

.ai-typing { display: flex; gap: 4px; padding: 6px 2px; }

.ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: ai-dot 1.1s ease-in-out infinite;
}

.ai-typing span:nth-child(2) { animation-delay: .15s; }
.ai-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes ai-dot {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* Result card: what was built, in words (no code) */
.ai-card {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.ai-card-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ai-card-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }

.ai-badge {
    flex: none;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(90deg, #8b5cf6, #6d28d9);
}

.ai-badge--strategy { background: var(--accent); }

.ai-card-summary {
    margin: 8px 0 0;
    color: var(--text-muted);
    font-size: 12.5px;
    line-height: 1.5;
}

.ai-card-actions { display: flex; gap: 8px; margin-top: 10px; }

.ai-card-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
}

.ai-card-btn:hover { border-color: var(--accent); color: var(--accent); }
.ai-card-btn.is-on:hover { border-color: var(--down); color: var(--down); }

/* Composer */
.ai-composer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 14px;
    border-top: 1px solid var(--border);
}

.ai-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.ai-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.ai-input-wrap textarea {
    flex: 1;
    min-height: 40px;
    max-height: 140px;
    padding: 4px 0;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    color: var(--text);
    font: 13px/1.45 "Inter", sans-serif;
}

.ai-input-wrap textarea::placeholder { color: var(--text-muted); }

.ai-send {
    display: grid;
    place-items: center;
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text);
    color: var(--bg);
    transition: opacity .15s ease, transform .15s ease;
}

.ai-send svg { width: 18px; height: 18px; }
.ai-send:hover:not(:disabled) { transform: translateX(1px); }
.ai-send:disabled { opacity: .35; cursor: default; }

.ai-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.ai-modes {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.ai-mode {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
}

.ai-mode svg { width: 14px; height: 14px; }
.ai-mode:hover { color: var(--text); }
.ai-mode[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }

.ai-try {
    overflow: hidden;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ai-try:hover { border-color: var(--text-muted); color: var(--text); }
.ai-try-label { opacity: .7; }
.ai-try-text { color: var(--text); font-weight: 600; }

/* Conversation extras: new chat, follow-up chips, backtest card */
.ai-head { justify-content: flex-start; }
.ai-new {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.ai-new svg { width: 13px; height: 13px; }
@media (hover: hover) { .ai-new:hover { color: var(--text); border-color: var(--accent); } }

.ai-badge--edit { color: #f59e0b; background: rgba(245, 158, 11, .14); }

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.ai-chip {
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 12.5px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    text-align: left;
}
@media (hover: hover) { .ai-chip:hover { border-color: #7b4dff; } }

.ai-bt {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12.5px;
}
.ai-bt--loading { color: var(--text-muted); }
.ai-bt-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ai-bt-head span { color: var(--text-muted); }
.ai-bt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.ai-bt-kpi { display: grid; gap: 3px; }
.ai-bt-kpi span { color: var(--text-muted); font-size: 11.5px; }
.ai-bt-kpi strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.ai-bt-kpi.up strong { color: var(--up); }
.ai-bt-kpi.down strong { color: var(--down); }
.ai-bt-note { margin: 10px 0 0; color: var(--text-muted); font-size: 11px; }

/* Daily allowance and cooldown */
.ai-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ai-usage { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.ai-usage.is-low { color: #f59e0b; }
.ai-send { position: relative; }
.ai-send-wait:empty { display: none; }
.ai-send.is-waiting svg { visibility: hidden; }
.ai-send-wait {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Optimizer result */
.ai-opt {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(123, 77, 255, .35);
    background: rgba(123, 77, 255, .08);
    font-size: 12.5px;
    color: var(--text-muted);
}
.ai-opt .ai-bt-head strong { color: var(--text); }
.ai-opt-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px 10px; margin-top: 4px; }
.ai-opt-label { color: var(--text-muted); font-size: 11.5px; }
.ai-opt-val { color: var(--text); font-variant-numeric: tabular-nums; font-size: 12px; }
.ai-opt-changes { margin: 10px 0 0; padding-left: 18px; color: var(--text); }
.ai-opt-changes li { margin: 2px 0; }

/* Live activity (Quant-style steps) */
.ai-msg--activity { list-style: none; }
.ai-activity {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 12.5px;
    overflow: hidden;
}
.ai-activity-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    color: var(--text-muted);
    text-align: left;
    font-size: 12.5px;
}
.ai-activity-head:disabled { cursor: default; }
.ai-activity:not(.is-running) .ai-activity-head::after { content: "▸"; margin-left: auto; font-size: 11px; }
.ai-activity.is-open .ai-activity-head::after { content: "▾"; }
.ai-activity-spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); border-top-color: #a78bfa; animation: ai-spin .8s linear infinite; }
.ai-activity:not(.is-running) .ai-activity-spin { animation: none; border-color: var(--up); background: var(--up); transform: scale(.6); }
@keyframes ai-spin { to { transform: rotate(360deg); } }
.ai-activity-steps { margin: 0; padding: 0 12px 10px; list-style: none; display: grid; gap: 6px; }
.ai-activity:not(.is-running):not(.is-open) .ai-activity-steps { display: none; }
.ai-step { display: flex; align-items: flex-start; gap: 8px; color: var(--text); line-height: 1.35; }
.ai-step-dot { flex: none; width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: var(--text-muted); }
.ai-step.is-running .ai-step-dot { background: #a78bfa; animation: ai-pulse 1s ease-in-out infinite; }
.ai-step.is-running .ai-step-text { color: var(--text-muted); }
.ai-step.is-done .ai-step-dot { background: var(--up); }
.ai-step.is-failed .ai-step-dot { background: #f59e0b; }
.ai-step.is-failed .ai-step-text { color: var(--text-muted); }
@keyframes ai-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .ai-activity-spin, .ai-step.is-running .ai-step-dot { animation: none; } }

/* Quant-style answer details */
.ai-step-time { margin-left: auto; padding-left: 8px; color: var(--text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ai-plan { margin: 0 0 8px; color: var(--text-muted); font-style: italic; font-size: 12.5px; line-height: 1.45; }
.ai-text p { margin: 0 0 8px; }
.ai-text p:last-child { margin-bottom: 0; }
.ai-text ul { margin: 6px 0 8px; padding-left: 18px; }
.ai-text li { margin: 4px 0; }
.ai-text strong { color: var(--text); font-weight: 650; }
.ai-tools { display: flex; gap: 4px; margin-top: 8px; }
.ai-tool { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: var(--text-muted); }
.ai-tool svg { width: 14px; height: 14px; }
@media (hover: hover) { .ai-tool:hover { color: var(--text); background: var(--surface-2); } }
.ai-tool.is-done { color: var(--up); }

/* Live clock in the working header */
.ai-activity-clock { margin-left: auto; color: var(--text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ai-activity:not(.is-running) .ai-activity-clock { display: none; }

/* Plan: shimmering status while thinking, then the AI's thoughts appear one by one */
.ai-think { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }
.ai-think-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 12.5px; }
.ai-think-items { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; counter-reset: plan; }
.ai-think-item { position: relative; padding-left: 20px; font-size: 12.5px; line-height: 1.35; counter-increment: plan; animation: ai-rise .3s ease-out; }
.ai-think-item::before { content: counter(plan); position: absolute; left: 0; top: 1px; width: 14px; height: 14px; border-radius: 50%;
    background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); font-size: 9.5px; font-weight: 700;
    display: grid; place-items: center; }
.ai-think-item.is-failed { color: var(--text-muted); }
.ai-think-item.is-failed::before { content: "!"; background: color-mix(in srgb, #f59e0b 18%, transparent); color: #f59e0b; }
.ai-think-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.ai-think-secs { margin-left: auto; color: var(--text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ai-shimmer { color: transparent; background: linear-gradient(90deg, var(--text-muted) 0%, var(--text-muted) 35%, var(--text) 50%, var(--text-muted) 65%, var(--text-muted) 100%);
    background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; animation: ai-shimmer 1.6s linear infinite; }
@keyframes ai-shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
@keyframes ai-rise { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* Script: the recipe written out line by line */
.ai-script { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ai-script-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 11.5px; color: var(--text-muted);
    border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--text) 4%, transparent); }
.ai-script-path { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-script-count { margin-left: auto; white-space: nowrap; }
.ai-script:not(.is-done) .ai-script-count { animation: ai-pulse 1s ease-in-out infinite; }
.ai-script-code { margin: 0; padding: 6px 0; max-height: 180px; overflow: auto;
    font: 11.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.ai-script-line { display: flex; gap: 10px; padding: 0 10px; white-space: pre-wrap; word-break: break-word; }
.ai-script-line.is-comment .ai-script-txt { color: var(--text-muted); }
.ai-script-no { flex: none; width: 16px; text-align: right; color: var(--text-muted); opacity: .6; user-select: none; }
.ai-script:not(.is-done) .ai-script-line:last-child .ai-script-txt::after { content: ""; display: inline-block; width: 6px; height: 12px;
    margin-left: 1px; vertical-align: -2px; background: #a78bfa; animation: ai-pulse .8s steps(2) infinite; }
@media (prefers-reduced-motion: reduce) { .ai-shimmer, .ai-think-item, .ai-script-count, .ai-script-txt::after { animation: none !important; } .ai-shimmer { color: var(--text-muted); } }
