/* ==========================================================================
   Backtester workspace skin
   --------------------------------------------------------------------------
   Restyles the existing strategy panel (#backtester in templates/home.html)
   to match the landing cover's product window: a dark glass window with a
   prompt pane on the left and a tabbed results pane on the right.

   Presentation only. Every id, class, handler and data attribute that
   static/js/scripts.js relies on is unchanged; rules are scoped under
   #backtester so they win over glassmorphism.css without touching it.
   Validation (aria-invalid) and locked (readonly) states keep their
   original rules.
   ========================================================================== */

@font-face { font-family: 'Statis Avenir'; font-weight: 400; font-style: normal; font-display: swap;
    src: url('../fonts/AvenirNextCyr-Regular.woff2') format('woff2'), url('../fonts/AvenirNextCyr-Regular.woff') format('woff'); }
@font-face { font-family: 'Statis Avenir'; font-weight: 500; font-style: normal; font-display: swap;
    src: url('../fonts/AvenirNextCyr-Medium.woff2') format('woff2'), url('../fonts/AvenirNextCyr-Medium.woff') format('woff'); }
@font-face { font-family: 'Statis Avenir'; font-weight: 600; font-style: normal; font-display: swap;
    src: url('../fonts/AvenirNextCyr-Demi.woff2') format('woff2'), url('../fonts/AvenirNextCyr-Demi.woff') format('woff'); }

#backtester {
    --bt-ink: #f6f4ff;
    --bt-muted: rgba(232, 227, 255, .72);
    --bt-faint: rgba(232, 227, 255, .48);
    --bt-line: rgba(255, 255, 255, .09);
    --bt-line-strong: rgba(255, 255, 255, .16);
    --bt-field: rgba(255, 255, 255, .045);
    --bt-violet: #a78bfa;
    --bt-lilac: #d8ccff;
    --bt-cyan: #7dd3fc;
    --bt-mint: #6ee7b7;
    --bt-label: 'Statis Avenir', 'AvenirNextLight', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --bt-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
    --bt-ease: cubic-bezier(.2, .8, .2, 1);
}

/* --- Window ------------------------------------------------------------------ */
#backtester.strategy-panel {
    padding: 0;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .14);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .02)),
        rgba(20, 15, 52, .58);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .09) inset,
        0 40px 100px -30px rgba(8, 5, 30, .75),
        0 24px 60px -32px rgba(76, 29, 149, .55);
    text-align: left;
    color: var(--bt-ink);
}
#backtester .bt-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding: 0;
    margin: 0;
}
#backtester .bt-left { min-width: 0; padding: 24px; }
#backtester .bt-right {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 18px 24px 24px;
    border-top: 1px solid var(--bt-line);
}
@media (min-width: 1024px) {
    #backtester .bt-body { grid-template-columns: minmax(340px, 380px) minmax(0, 1fr); }
    #backtester .bt-left { border-right: 1px solid var(--bt-line); }
    #backtester .bt-right { border-top: 0; }
}

/* Small uppercase labels, like the cover's "DEFINE STRATEGY". */
#backtester .bt-left > h3,
#backtester .date-input-container .range-label,
#backtester .strategy-output > h2,
#backtester .strategy-graph-output > h2,
#backtester .diagram-heading h3 {
    margin: 0;
    font-family: var(--bt-label);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--bt-faint);
}

/* --- Prompt pane ------------------------------------------------------------- */
#backtester .strategy-input { margin-top: 12px; }
#backtester .strategy-input textarea {
    margin: 0;
    min-height: 112px;
    padding: 14px 16px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.6;
    color: rgba(246, 244, 255, .94);
    transition: border-color .25s ease, box-shadow .25s ease, background-color .25s ease;
}
#backtester .strategy-input textarea:not([aria-invalid="true"]) {
    border: 1px solid rgba(255, 255, 255, .12);
    background: var(--bt-field);
    box-shadow: none;
}
#backtester .strategy-input textarea:not([aria-invalid="true"]):enabled:not([readonly]):hover {
    border-color: rgba(255, 255, 255, .22);
    background: rgba(255, 255, 255, .06);
}
#backtester .strategy-input textarea:not([aria-invalid="true"]):enabled:not([readonly]):focus {
    outline: none;
    border-color: rgba(167, 139, 250, .6);
    background: rgba(255, 255, 255, .06);
    box-shadow: 0 0 0 4px rgba(167, 139, 250, .14);
}
#backtester #strategyConditions[readonly] { background: rgba(255, 255, 255, .02); }
#backtester .strategy-input-limit { margin: 6px 2px 0; font-size: 11.5px; color: var(--bt-faint); }

/* Example prompts: one swipeable row of chips. */
#backtester .prompt-suggestions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    margin: 12px 0 0;
    padding: 0 24px 4px 0;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
#backtester .prompt-suggestions::-webkit-scrollbar { display: none; }
#backtester .prompt-suggestions-label { margin: 0 2px 0 0; font-size: 11.5px; color: var(--bt-faint); }
#backtester .prompt-chip {
    flex: 0 0 auto;
    margin: 0;
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid var(--bt-line);
    background: rgba(255, 255, 255, .03);
    font-family: var(--bt-label);
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--bt-muted);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}
#backtester .prompt-chip:hover {
    color: #fff;
    transform: none;
    border-color: rgba(255, 255, 255, .26);
    background: rgba(255, 255, 255, .08);
}

/* Backtest period + mode options, grouped like the cover's meta chips. */
#backtester .date-input-container {
    box-sizing: border-box;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 18px 0 0;
    padding: 14px;
    border-radius: 14px;
    border: 1px solid var(--bt-line);
    background: rgba(255, 255, 255, .02);
    align-items: end;
}
#backtester .date-input-container .range-label { grid-column: 1 / -1; }
#backtester .strategy-date-field { gap: 5px; }
#backtester .strategy-date-field label { font-size: 12px; color: var(--bt-muted); }
#backtester .strategy-date-field input[type="date"] {
    height: 40px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .12);
    background-color: var(--bt-field);
    box-shadow: none;
    font-size: 14px;
}
#backtester .date-input-container .date-preset-inline {
    grid-column: 1 / -1;
    justify-content: flex-start;
    min-height: 0;
    gap: 6px;
}
#backtester .date-preset-inline .prompt-chip { flex: 1 1 0; min-height: 30px; text-align: center; }
#backtester .strategy-options {
    grid-column: 1 / -1;
    gap: 4px 18px;
    padding-top: 2px;
}
#backtester .strategy-options > div { min-height: 36px; }
#backtester .strategy-options label,
#backtester .strategy-options .tooltip label { font-size: 13px; color: var(--bt-muted); }

/* AI model */
#backtester .glass-form {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: 100%;
    margin: 14px 0 0;
}
#backtester .glass-form > label {
    margin: 0;
    font-family: var(--bt-label);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--bt-faint);
    white-space: nowrap;
}
#backtester .glass-dropdown { width: 100%; }
#backtester .glass-form .glass-dropdown-toggle {
    height: 42px;
    padding: 8px 40px 8px 14px;
    border-radius: 12px;
    border-color: rgba(255, 255, 255, .12);
    background-color: var(--bt-field);
    font-size: 14px;
}
#backtester .bt-left > p.bt-note,
#backtester .bt-left > p.upgrade-message {
    margin: 10px 0 0;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
    color: var(--bt-faint);
}

/* Test Idea: the cover's full-width glass pill. The loader/label logic is untouched. */
#backtester #testIdeaBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-width: 0;
    height: 48px;
    min-height: 48px;
    margin: 16px 0 0;
    padding: 0 20px;
    border-radius: 999px;
    border: 1px solid rgba(225, 220, 255, .32);
    background: linear-gradient(135deg, rgba(202, 192, 255, .30), rgba(255, 255, 255, .08));
    box-shadow: 0 1px 0 rgba(255, 255, 255, .14) inset, 0 12px 30px -12px rgba(139, 92, 246, .7);
    font-family: var(--bt-label);
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: .12em;
    color: #fff;
}
#backtester #testIdeaBtn:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(225, 220, 255, .5);
    background: linear-gradient(135deg, rgba(202, 192, 255, .38), rgba(255, 255, 255, .12));
    box-shadow: 0 1px 0 rgba(255, 255, 255, .16) inset, 0 16px 36px -12px rgba(139, 92, 246, .85);
}
#backtester #testIdeaBtn:disabled { box-shadow: none; }
#backtester .ideas-container { margin: 10px 0 0; gap: 4px; }
#backtester .ideas-container p { margin: 0; font-size: 12.5px; color: var(--bt-faint); }
#backtester .ideas-container .lightbulb { font-size: 13px; margin-right: 2px; }

#backtester .status-messages { margin-top: 10px; font-size: 12.5px; line-height: 1.55; text-align: left; }
#backtester .timer { text-align: left; }
/* Empty status/timer boxes shouldn't leave a gap under the button. */
#backtester .status-messages:empty,
#backtester .timer:empty { display: none; }
#backtester .backtest-progress { max-width: none; margin: 10px 0 0; }
#backtester .backtest-progress-track { height: 6px; border-color: var(--bt-line); background: rgba(255, 255, 255, .06); }
#backtester .backtest-progress-fill { background: linear-gradient(90deg, var(--bt-violet), var(--bt-cyan)); }
#backtester .backtest-progress-label { font-size: 11.5px; color: var(--bt-muted); }

/* --- Results pane ------------------------------------------------------------- */
#backtester .bt-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 260px;
    padding: 24px;
    border-radius: 14px;
    border: 1px dashed rgba(255, 255, 255, .12);
    background: radial-gradient(ellipse at 50% 35%, rgba(139, 92, 246, .10), transparent 70%);
    text-align: center;
}
#backtester .bt-empty-art { width: min(240px, 70%); height: auto; margin-bottom: 8px; color: rgba(167, 139, 250, .55); }
#backtester .bt-empty-title { margin: 0; font-family: var(--bt-label); font-size: 15px; font-weight: 500; color: var(--bt-muted); }
#backtester .bt-empty-sub { margin: 0; max-width: 380px; font-size: 13px; line-height: 1.6; color: var(--bt-faint); }
/* The empty state steps aside as soon as code streams in or results arrive. */
#backtester .bt-right:has(> #streamContainer[style*="block"]) > .bt-empty,
#backtester .bt-right:has(> .content-group:not(.hidden)) > .bt-empty { display: none; }

/* Live code stream */
#backtester #streamContainer { margin: 0 0 18px; }
#backtester .stream-header { gap: 10px; padding: 2px 2px 10px; }
#backtester .stream-header h2 {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    font-family: var(--bt-label);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
}
#backtester .stream-header h2::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--bt-violet);
    box-shadow: 0 0 10px var(--bt-violet);
    animation: bt-pulse 1.4s ease-in-out infinite;
}
@keyframes bt-pulse { 50% { opacity: .35; } }

/* Code windows (stream + Generated Code tab) */
#backtester #streamContainer pre,
#backtester #streamContainer pre[class*="language-"],
#backtester .tab-panel pre,
#backtester .tab-panel pre[class*="language-"] {
    margin: 0;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid var(--bt-line);
    background: rgba(8, 6, 26, .38);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    font-size: 12.5px;
    line-height: 1.7;
}
#backtester #streamContainer pre { max-height: 460px; overflow: auto; }
#backtester .tab-panel code[class*="language-"],
#backtester #streamContainer code { font-family: var(--bt-mono); font-size: 12.5px; }

#backtester .content-group { margin: 0; }
#backtester .tabbed-container { margin: 0; }

/* Text tabs with the cover's gradient underline. */
#backtester .tab-buttons {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    gap: 4px;
    margin: 0 0 18px;
    border-bottom: 1px solid var(--bt-line);
    overflow-x: auto;
    scrollbar-width: none;
}
#backtester .tab-buttons::-webkit-scrollbar { display: none; }
#backtester .tab-button.glass-button {
    position: relative;
    flex: 0 0 auto;
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 8px 12px 12px;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    opacity: 1;
    transform: none;
    font-family: var(--bt-label);
    font-size: 13.5px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--bt-faint);
    transition: color .25s ease;
}
#backtester .tab-button.glass-button::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--bt-violet), var(--bt-cyan));
    transform: scaleX(0);
    transition: transform .35s var(--bt-ease);
}
#backtester .tab-button.glass-button:hover { color: var(--bt-muted); background: none; transform: none; box-shadow: none; }
#backtester .tab-button.glass-button.active { color: #fff; background: none; border: 0; }
#backtester .tab-button.glass-button.active::after { transform: scaleX(1); }

/* Performance tab: chart, same-period comparison, then original trade statistics. */
#backtester .strategy-graph-output,
#backtester .strategy-output { margin: 0; }
#backtester .strategy-graph-output > h2 { margin-bottom: 10px; }
#backtester .strategy-output { margin-top: 18px; }
#backtester .strategy-output > h2 { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 10px; }
#backtester .strategy-output > h2 .analytics-period { margin: 0; font-weight: 400; letter-spacing: normal; text-transform: none; }
#backtester .strategy-output > p {
    margin: 12px 0 0;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--bt-faint);
}

#backtester #strategySummary {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    white-space: normal;
    font-family: inherit;
    overflow: visible;
}
#backtester #strategySummary .analytics-table {
    display: table;
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    border: 1px solid var(--bt-line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .025);
    overflow: hidden;
    font-family: var(--bt-label);
    font-size: 13px;
    line-height: 1.4;
}
#backtester .analytics-table caption { text-align: left; padding: 0 0 10px; color: var(--bt-ink); font-weight: 600; }
#backtester .analytics-table thead { display: table-header-group; }
#backtester .analytics-table tbody { display: table-row-group; }
#backtester .analytics-table tr { display: table-row; }
#backtester .analytics-table th,
#backtester .analytics-table td {
    display: table-cell;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--bt-line);
    border-radius: 0;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: inherit;
    font-weight: 500;
    color: var(--bt-ink);
    font-variant-numeric: tabular-nums;
    background: none;
}
#backtester .analytics-table th:first-child { width: 44%; text-align: left; color: var(--bt-muted); font-weight: 400; }
#backtester .analytics-table thead th { background: rgba(255, 255, 255, .055); }
#backtester .analytics-comparison td:nth-child(2) { background: rgba(183, 162, 255, .07); }
#backtester .analytics-table tr:last-child > * { border-bottom: 0; }
#backtester .analytics-table tbody tr:hover { background: rgba(255, 255, 255, .035); }
#backtester .analytics-table td::before { content: none; }
#backtester .analytics-subtitle { display: block; font-size: 11px; font-weight: 400; color: var(--bt-muted); }
#backtester .analytics-period,
#backtester .analytics-note { margin: 8px 0 12px; color: var(--bt-muted); font-size: 12px; line-height: 1.5; }
#backtester .analytics-trade-heading { margin: 18px 0 10px; font-size: 13px; font-weight: 500; }
#backtester .analytics-trades { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
#backtester .analytics-trades > div { padding: 10px; border: 1px solid var(--bt-line); border-radius: 10px; background: rgba(255,255,255,.025); }
#backtester .analytics-trades dt { font-size: 11px; color: var(--bt-muted); }
#backtester .analytics-trades dd { margin: 5px 0 0; font-size: 13px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#backtester .analytics-details { margin-top: 10px; font-size: 12px; line-height: 1.6; color: var(--bt-muted); }
#backtester .analytics-details summary { cursor: pointer; padding: 4px 0; }
#backtester .analytics-details summary:focus-visible { outline: 2px solid var(--bt-lilac); outline-offset: 3px; }
#backtester .analytics-details .analytics-table { margin-top: 10px; }

/* Flow diagram tab */
#backtester .diagram-container {
    margin: 0;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1px solid var(--bt-line);
    background: rgba(8, 6, 26, .3);
    box-shadow: none;
}
#backtester .diagram-heading { margin-bottom: 10px; }

/* Share / Save */
#backtester .bt-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
#backtester .bt-actions .glass-button {
    width: auto;
    height: 38px;
    margin: 0;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--bt-line-strong);
    background: rgba(255, 255, 255, .05);
    font-family: var(--bt-label);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .08em;
}
#backtester .bt-actions .glass-button:hover:not(:disabled) { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .3); }
#backtester #shareLinkContainer { margin: 12px 0 0; padding: 0; font-size: 13px; text-align: left; }

/* --- Smaller screens ------------------------------------------------------------ */
@media (max-width: 680px) {
    #backtester.strategy-panel { border-radius: 18px; }
    #backtester .bt-left { padding: 18px 16px 20px; }
    #backtester .bt-right { padding: 14px 16px 18px; }
    #backtester .bt-empty { display: none; }
    #backtester .bt-right:not(:has(> #streamContainer[style*="block"])):has(> .content-group.hidden) { display: none; }
    #backtester .tab-button.glass-button { padding: 8px 10px 12px; font-size: 13px; }
    #backtester .bt-actions .glass-button { flex: 1 1 0; }
    #backtester .analytics-trades { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #backtester .analytics-table th,
    #backtester .analytics-table td { padding: 9px 7px; }
}
@media (max-width: 480px) {
    /* Native iPhone date controls need the full row. */
    #backtester .date-input-container { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    #backtester .stream-header h2::before { animation: none; }
    #backtester .tab-button.glass-button::after { transition: none; }
}
