/* ============================================================
 * QUANTUM 4.0 PREMIUM DESIGN SYSTEM
 * Hybrid Pro: Dark theme + Glassmorphism + Indigo/Violet accent
 * ============================================================ */

/* ── CSS Custom Properties ─────────────────────────────────── */

:root {
    /* Backgrounds */
    --bg-body: #0f172a;
    --bg-body-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --bg-sidebar: #111827;
    --bg-card: rgba(255,255,255,0.04);
    --bg-card-header: rgba(255,255,255,0.02);
    --bg-input: rgba(255,255,255,0.05);
    --bg-hover: rgba(255,255,255,0.06);
    --bg-secondary: rgba(255,255,255,0.03);

    /* Glassmorphism */
    --glass-blur: blur(12px);
    --glass-border: 1px solid rgba(255,255,255,0.08);
    --glass-border-hover: 1px solid rgba(255,255,255,0.12);

    /* Accent — Indigo → Violet */
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-light: #818cf8;
    --accent-glow: 0 0 20px rgba(99,102,241,0.3);
    --accent-bg: rgba(99,102,241,0.1);
    --accent-bg-hover: rgba(99,102,241,0.15);
    --accent-border: rgba(99,102,241,0.3);

    /* Semantic colors */
    --color-positive: #34d399;
    --color-positive-bg: rgba(52,211,153,0.1);
    --color-negative: #f87171;
    --color-negative-bg: rgba(248,113,113,0.1);

    /* Text */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-label: #94a3b8;
    --text-title: #e2e8f0;

    /* Borders */
    --border-primary: #1e293b;
    --border-subtle: rgba(255,255,255,0.06);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-glow: var(--accent-glow);

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-pill: 99px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 24px;
    --space-3xl: 32px;

    /* Typography */
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --text-xs: 10px;
    --text-sm: 11px;
    --text-base: 13px;
    --text-lg: 14px;
    --text-xl: 18px;
    --text-2xl: 20px;
    --text-3xl: 28px;
    --text-hero: 32px;

    /* Sidebar */
    --sidebar-width: 220px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;

    /* Progress */
    --bg-progress: rgba(255,255,255,0.08);
    --bg-progress-fill: var(--accent-gradient);

    /* Compatibility aliases (для существующего JS) */
    --bg-button: #6366f1;
    --bg-button-hover: #4f46e5;
    --bg-button-disabled: #334155;
    --text-positive: #34d399;
    --text-negative: #f87171;
    --bg-primary: #0f172a;
    --bg-card-solid: #111827;

    /* Нативные формы (select, scrollbars): тёмная отрисовка выпадающих списков */
    color-scheme: dark;
}

/* Light theme */
[data-theme="light"] {
    --bg-body: #f8fafc;
    --bg-body-gradient: #f8fafc;
    --bg-sidebar: #ffffff;
    --bg-card: rgba(255,255,255,0.8);
    --bg-card-header: rgba(0,0,0,0.02);
    --bg-input: #ffffff;
    --bg-hover: rgba(0,0,0,0.04);
    --bg-secondary: rgba(0,0,0,0.02);

    --glass-border: 1px solid rgba(0,0,0,0.08);
    --glass-border-hover: 1px solid rgba(0,0,0,0.15);

    --color-positive: #059669;
    --color-positive-bg: rgba(5,150,105,0.08);
    --color-negative: #dc2626;
    --color-negative-bg: rgba(220,38,38,0.08);

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-label: #64748b;
    --text-title: #1e293b;

    --border-primary: #e2e8f0;
    --border-subtle: rgba(0,0,0,0.06);

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.1);

    --bg-progress: rgba(0,0,0,0.06);
    --bg-card-solid: #ffffff;
    --bg-button: #6366f1;
    --bg-button-hover: #4f46e5;
    --bg-button-disabled: #cbd5e1;
    --text-positive: #059669;
    --text-negative: #dc2626;
    --bg-primary: #f8fafc;

    color-scheme: light;
}

/* ── Reset & Base ──────────────────────────────────────────── */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    background: var(--bg-body-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background var(--transition-slow), color var(--transition-slow);
    overflow-x: hidden;
}

/* Fixed background gradient that doesn't scroll */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-body-gradient);
    z-index: -1;
}

/* ── App Layout ────────────────────────────────────────────── */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width var(--transition-slow);
}

.sidebar-logo {
    padding: var(--space-xl);
    border-bottom: 1px solid var(--border-primary);
}

.logo-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md) 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xl);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: 500;
    transition: all var(--transition-base);
    border-left: 2px solid transparent;
    cursor: pointer;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--accent-light);
    background: var(--accent-bg);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
}

.sidebar-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-primary);
}

.sidebar-debug-tools {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-primary);
}

.sidebar-debug-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: var(--space-sm);
    line-height: 1.3;
}

.sidebar-debug-label input {
    flex-shrink: 0;
}

.sidebar-debug-download {
    display: block;
    width: 100%;
    margin-top: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-sm);
    font-family: var(--font-ui);
    color: var(--text-secondary);
    background: var(--bg-input);
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--transition-base), border-color var(--transition-base);
}

.sidebar-debug-download:hover {
    color: var(--text-primary);
    border-color: var(--accent-border);
}

.sidebar-footer .theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-xs);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: var(--text-base);
    font-family: var(--font-ui);
    cursor: pointer;
    transition: color var(--transition-base);
    width: 100%;
}

.sidebar-footer .theme-toggle:hover {
    color: var(--text-primary);
}

/* ── Main Content ──────────────────────────────────────────── */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: var(--space-2xl) var(--space-3xl);
    min-height: 100vh;
    max-width: calc(100vw - var(--sidebar-width));
}

/* ── Tab Content ───────────────────────────────────────────── */

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ── Glassmorphism Cards ───────────────────────────────────── */

.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    overflow: hidden;
    transition: border var(--transition-base);
}

.card:hover {
    border: var(--glass-border-hover);
}

.card-title {
    padding: var(--space-lg) var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: var(--bg-card-header);
    transition: background var(--transition-base);
    user-select: none;
}

.card-title:hover {
    background: var(--bg-hover);
}

/* Мини-прогресс загрузки свечей под заголовком карточки "Основные настройки" */
.download-mini-progress {
    display: none;
    height: 3px;
    width: calc(100% - (var(--space-xl) * 2));
    margin: 0 var(--space-xl);
    background: var(--bg-progress);
    border-radius: 2px;
    overflow: hidden;
}

.download-mini-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    transition: width var(--transition-base);
}

.card-title-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.card-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: var(--accent-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.card-name {
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: 600;
}

.card-subtitle {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin-top: 1px;
    display: block;
}

.card-content {
    padding: var(--space-lg) var(--space-xl);
    display: block;
}

.card-content.collapsed {
    display: none;
}

.collapse-icon {
    color: var(--text-muted);
    font-size: var(--text-sm);
    transition: transform var(--transition-base);
}

.collapse-icon.collapsed {
    transform: rotate(-90deg);
}

/* ── Forms ──────────────────────────────────────────────────── */

.form-group {
    margin-bottom: var(--space-lg);
    position: relative;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-label);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-family: var(--font-ui);
    color: var(--text-primary);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
    outline: none;
}

[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="number"],
[data-theme="light"] input[type="date"],
[data-theme="light"] select {
    border-color: var(--border-primary);
}

input[type="number"],
.mono {
    font-family: var(--font-mono);
}

input:focus,
select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

input:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Checkbox styling */
input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 16px;
    height: 16px;
    margin-right: var(--space-sm);
    vertical-align: middle;
}

/* Select dark arrow fix */
select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Фон и текст пунктов выпадающего списка (совпадает со скином карточек/сайдбара) */
select option,
select optgroup {
    background-color: var(--bg-card-solid);
    color: var(--text-primary);
}

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: var(--space-md) var(--space-2xl);
    border-radius: var(--radius-sm);
    font-size: var(--text-lg);
    font-weight: 600;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.btn:hover:not(:disabled) {
    box-shadow: var(--accent-glow);
    transform: translateY(-1px);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    background: var(--bg-button-disabled);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    opacity: 0.6;
}

.btn-primary {
    background: var(--accent-gradient);
}

.btn-ghost {
    background: transparent;
    color: var(--accent-light);
    border: 1px solid var(--accent-border);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--accent-bg);
    box-shadow: none;
    transform: none;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

/* ── Progress Bars ─────────────────────────────────────────── */

.progress-container {
    margin: var(--space-xl) 0;
    display: none;
}

.progress-bar {
    width: 100%;
    height: 24px;
    background: var(--bg-progress);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-bottom: var(--space-sm);
}

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-pill);
    transition: width var(--transition-slow);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    min-width: 36px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    text-align: center;
    font-size: var(--text-base);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

/* ── Results ───────────────────────────────────────────────── */

.results {
    display: none;
    margin-top: var(--space-xl);
}

.results.active {
    display: block;
}

/* Hero Results Block */
.results-hero {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
    overflow: hidden;
}

.hero-metrics {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-lg);
    position: relative;
    z-index: 1;
}

.hero-primary {
    flex: 1;
}

.hero-label {
    color: var(--text-muted);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hero-value {
    font-size: var(--text-hero);
    font-weight: 700;
    font-family: var(--font-mono);
    margin-top: var(--space-xs);
    line-height: 1.2;
}

.hero-value.positive {
    color: var(--color-positive);
}

.hero-value.negative {
    color: var(--color-negative);
}

.hero-subtitle {
    color: var(--color-positive);
    font-size: var(--text-sm);
    margin-top: var(--space-xs);
}

.hero-secondary {
    display: flex;
    gap: var(--space-2xl);
    text-align: right;
}

.hero-stat-label {
    color: var(--text-muted);
    font-size: var(--text-xs);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.hero-stat-value {
    color: var(--text-primary);
    font-size: var(--text-2xl);
    font-weight: 700;
    font-family: var(--font-mono);
    margin-top: 2px;
}

.hero-stat-value.negative {
    color: var(--color-negative);
}

.hero-stat-value.accent {
    color: var(--accent-light);
}

.hero-chart {
    height: 250px;
    margin: 0 calc(var(--space-xl) * -1);
    margin-bottom: calc(var(--space-xl) * -1);
}

/* Secondary Metrics Row */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.metric-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    text-align: center;
    transition: border-color var(--transition-base);
}

.metric-card:hover {
    border-color: rgba(255,255,255,0.12);
}

.metric-label {
    color: var(--text-muted);
    font-size: 9px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.metric-value {
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-weight: 600;
    font-family: var(--font-mono);
    margin-top: 2px;
}

.metric-value.positive {
    color: var(--color-positive);
}

.metric-value.negative {
    color: var(--color-negative);
}

/* ── Stats Grid (legacy support) ───────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin: var(--space-xl) 0;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--accent-primary);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-xs);
}

.stat-value {
    font-size: var(--text-2xl);
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.stat-value.positive {
    color: var(--color-positive);
}

.stat-value.negative {
    color: var(--color-negative);
}

/* ── Tables ────────────────────────────────────────────────── */

table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--space-xl) 0;
    font-size: var(--text-base);
}

th, td {
    padding: var(--space-md) var(--space-lg);
    text-align: left;
    border-bottom: 1px solid var(--border-primary);
}

th {
    background: var(--bg-card-header);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover {
    background: var(--bg-hover);
}

td.positive,
.positive {
    color: var(--color-positive);
    font-weight: 500;
}

td.negative,
.negative {
    color: var(--color-negative);
    font-weight: 500;
}

/* ── Chart Container ───────────────────────────────────────── */

.chart-container {
    margin: var(--space-xl) 0;
    height: 400px;
}

/* ── Comparison Panel ──────────────────────────────────────── */

.comparison-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
    margin: var(--space-xl) 0;
}

.comparison-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    border-top: 3px solid var(--accent-primary);
}

.comparison-card.best {
    border-top-color: var(--color-positive);
}

.comparison-card h3 {
    margin: 0 0 var(--space-md);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.comparison-ts {
    font-weight: 400;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.comparison-stats {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.cmp-row {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-base);
    padding: 3px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.cmp-row:last-child {
    border-bottom: none;
}

.cmp-row span:first-child {
    color: var(--text-secondary);
}

.cmp-row span:last-child {
    font-weight: 500;
    font-family: var(--font-mono);
}

.comparison-hint {
    color: var(--text-secondary);
    font-size: var(--text-base);
    margin: var(--space-md) 0;
    font-style: italic;
}

/* ── Trades Stats ──────────────────────────────────────────── */

.trades-stats {
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

/* ── Details / Accordion ───────────────────────────────────── */

details.param-group {
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
}

details.param-group summary {
    cursor: pointer;
    font-weight: 600;
    font-size: var(--text-lg);
    padding: var(--space-xs) 0;
    user-select: none;
    color: var(--text-primary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

details.param-group summary::-webkit-details-marker {
    display: none;
}

details.param-group summary::before {
    content: "\25B6";
    font-size: var(--text-xs);
    transition: transform var(--transition-base);
    display: inline-block;
    color: var(--text-muted);
}

details.param-group[open] summary::before {
    transform: rotate(90deg);
}

details.param-group summary:hover {
    opacity: 0.8;
}

details.param-group[open] summary {
    margin-bottom: var(--space-sm);
}

details.param-group .details-body {
    padding-top: var(--space-xs);
}

/* ── Optimizer Param Group Headers ─────────────────────────── */

.opt-param-group-header {
    background: var(--accent-gradient);
}

.param-group-title {
    font-weight: 600;
    font-size: var(--text-base);
    color: #fff;
    padding: var(--space-sm) var(--space-md);
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

/* ── Tooltips ──────────────────────────────────────────────── */

.input-wrapper {
    position: relative;
    width: 100%;
}

.input-wrapper .tooltip-text,
label .tooltip-text {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 0;
    background: var(--bg-card-solid);
    color: var(--text-primary);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-primary);
    font-size: var(--text-base);
    line-height: 1.6;
    z-index: 10000;
    visibility: hidden;
    opacity: 0;
    transition: opacity var(--transition-base), visibility var(--transition-base), transform var(--transition-base);
    pointer-events: none;
    white-space: normal;
    width: 350px;
    max-width: calc(100vw - 40px);
    transform: translateY(-5px);
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

.input-wrapper .tooltip-text::before,
label .tooltip-text::before {
    content: "";
    position: absolute;
    top: 100%;
    left: 20px;
    border: 8px solid transparent;
    border-top-color: var(--bg-card-solid);
}

.input-wrapper:hover .tooltip-text,
label:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* ── Utility Classes ───────────────────────────────────────── */

.text-positive { color: var(--color-positive); }
.text-negative { color: var(--color-negative); }
.text-accent { color: var(--accent-light); }
.text-muted { color: var(--text-muted); }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 600; }

/* ── Direction Badges ──────────────────────────────────────── */

.badge-long {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--color-positive-bg);
    color: var(--color-positive);
    font-size: var(--text-sm);
    font-weight: 600;
}

.badge-short {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--color-negative-bg);
    color: var(--color-negative);
    font-size: var(--text-sm);
    font-weight: 600;
}

/* Strategy dot indicator */
.strategy-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: var(--space-xs);
    vertical-align: middle;
}

/* ── Responsive ────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        z-index: 1000;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
    }

    .sidebar-logo {
        padding: var(--space-md);
        border-bottom: none;
        border-right: 1px solid var(--border-primary);
    }

    .sidebar-nav {
        flex-direction: row;
        padding: 0;
        gap: 0;
        overflow-x: auto;
    }

    .nav-item {
        padding: var(--space-md);
        border-left: none;
        border-bottom: 2px solid transparent;
        white-space: nowrap;
    }

    .nav-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--accent-primary);
    }

    .nav-label {
        display: none;
    }

    .sidebar-footer {
        padding: var(--space-md);
        border-top: none;
        border-left: 1px solid var(--border-primary);
    }

    .sidebar-footer .theme-toggle .nav-label {
        display: none;
    }

    .main-content {
        margin-left: 0;
        margin-top: 52px;
        padding: var(--space-lg);
        max-width: 100vw;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .hero-metrics {
        flex-direction: column;
        gap: var(--space-lg);
    }

    .hero-secondary {
        text-align: left;
        gap: var(--space-lg);
    }

    .comparison-panel {
        grid-template-columns: 1fr;
    }

    .metrics-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .input-wrapper .tooltip-text,
    label .tooltip-text {
        width: 280px;
        font-size: var(--text-sm);
    }
}

@media (max-width: 480px) {
    .metrics-row {
        grid-template-columns: 1fr;
    }
}

/* ── Scrollbar ─────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.25);
}

/* Подсветка обновлённых полей после оптимизации. */
.param-updated {
    border-color: var(--accent-green, #22c55e) !important;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
    transition: border-color 0.3s, box-shadow 0.3s;
}

/* ═══════════════════════════════════════ */
/* Toast-уведомления                       */
/* ═══════════════════════════════════════ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 420px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    color: #fff;
    pointer-events: auto;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.3s, transform 0.3s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    word-break: break-word;
}

.toast-visible {
    opacity: 1;
    transform: translateX(0);
}

.toast-hiding {
    opacity: 0;
    transform: translateX(40px);
}

.toast-error   { background: #dc2626; }
.toast-warning { background: #d97706; }
.toast-success { background: #16a34a; }
.toast-info    { background: #2563eb; }

.toast-icon {
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1.3;
}

.toast-msg {
    flex: 1;
}

.toast-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 18px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}

.toast-close:hover {
    color: #fff;
}

/* Таблица топа оптимизации по метрикам: клик по строке */
.optimizer-top-by-return-table .optimizer-result-row,
.optimizer-top-by-metrics-table .optimizer-result-row {
    cursor: pointer;
}
.optimizer-top-by-return-table .optimizer-result-row:hover,
.optimizer-top-by-metrics-table .optimizer-result-row:hover {
    background: var(--bg-hover);
}

/* Подпись таблицы: топ-10 и быстрый выбор кнопками */
.optimizer-top10-caption {
    caption-side: top;
    text-align: left;
    padding-bottom: 12px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
}
.optimizer-top10-picker-desc {
    margin: 0 0 10px;
    max-width: 72em;
}
.optimizer-top10-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: stretch;
}
.optimizer-top-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 8px 12px;
    font-size: 12px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    color: var(--text-primary);
    background: var(--bg-secondary, rgba(255, 255, 255, 0.06));
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.optimizer-top-chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent-color, rgba(100, 180, 255, 0.45));
}
.optimizer-top-chip-rank {
    font-weight: 700;
    color: var(--accent-color, #6eb3ff);
    flex-shrink: 0;
}
.optimizer-top-chip-text {
    white-space: normal;
    line-height: 1.35;
}

/* SVG иконки в заголовках таблицы сделок */
table th svg {
    vertical-align: middle;
    flex-shrink: 0;
}
table th span[title] {
    cursor: help;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
table td svg {
    vertical-align: middle;
}
