:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #1e293b;
    --dark-2: #334155;
    --dark-3: #475569;
    --light: #f8fafc;
    --light-2: #f1f5f9;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 15px 20px 120px 20px;
    line-height: 1.6;
    overflow-x: hidden;
}

.container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    overflow-x: hidden;
}

/* Header */
header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    animation: fadeInDown 0.6s ease;
}

h1 {
    font-size: 3em;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 4px 6px rgba(0,0,0,0.2);
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.2em;
    font-weight: 300;
    opacity: 0.95;
    letter-spacing: 0.02em;
}

/* Main Layout */
.main-layout {
    display: flex;
    gap: 20px;
    animation: fadeInUp 0.6s ease;
    flex-wrap: nowrap;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.main-layout > aside {
    flex: 0 0 420px;
    max-width: 420px;
    min-width: 420px;
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
}

.main-layout > main {
    display: flex;
    gap: 20px;
    flex: 1;
    min-width: 0;
    max-width: calc(100vw - 320px - 60px);
    align-items: stretch;
    overflow: hidden;
}

@media (max-width: 1800px) {
    .main-layout {
        flex-wrap: nowrap;
    }

    .main-layout > main {
        flex-wrap: nowrap;
    }
}

@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .main-layout > aside {
        flex: 1;
        width: 100%;
    }

    /* Stacked layout: the sidebar sits above the chart, so the viewport
       cap would just create a nested scroll trap -- let it flow naturally. */
    .sidebar-sticky {
        max-height: none;
        overflow-y: visible;
    }
}

/* Card Styles */
.card {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-height: calc(100vh - 200px);
    overflow-x: hidden;
    overflow-y: hidden;
    word-wrap: break-word;
}

.card:hover {
    transform: translateY(-2px);
}

/* Ensure card content doesn't overflow */
.card > * {
    min-width: 0;
}

/* Make card content scrollable */
.card-header {
    flex-shrink: 0;
}

.tabs {
    flex-shrink: 0;
}

.main-tab-content {
    overflow-y: auto;
    flex: 0 1 auto;
    min-height: 0;
    max-height: calc(100vh - 420px);
    display: flex;
    flex-direction: column;
}

/* Button group at bottom of configuration */
.btn-group {
    margin-top: auto;
    padding-top: 20px;
}

/* Plots card specific styling - removed to allow horizontal layout with positions panel */

/* Tip section at bottom of plots */
#plots_card .tip-section {
    margin-top: auto;
    flex-shrink: 0;
}


.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--light-2);
}

.card-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
}

.card-title {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--dark);
    letter-spacing: -0.01em;
}

/* Form Elements */
.form-section {
    margin-bottom: 30px;
}

.section-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group {
    margin-bottom: 20px;
    max-width: 100%;
    overflow-x: hidden;
}

label {
    display: block;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--dark-2);
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

select, input[type="text"], input[type="number"] {
    width: 100%;
    max-width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 0.95em;
    font-family: inherit;
    transition: all 0.3s ease;
    background: var(--light);
    color: var(--dark);
    box-sizing: border-box;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

select:hover, input[type="text"]:hover, input[type="number"]:hover {
    border-color: var(--dark-3);
}

/* Disabled form controls must LOOK disabled. The custom background/border
   above otherwise masks the browser's native disabled dimming, so frozen
   fields (e.g. the live-strategy lock in applyStrategyLockUI) read as
   editable. Applies app-wide to every intentionally disabled control. */
select:disabled, input:disabled, textarea:disabled {
    background: var(--border);
    color: var(--dark-3);
    border-color: var(--border);
    cursor: not-allowed;
    opacity: 0.7;
}

select:disabled:hover, input:disabled:hover, textarea:disabled:hover {
    border-color: var(--border);
}

/* Non-.btn buttons (inline-styled toggles like the Static/Dynamic correlation
   pair) keep their inline colors when disabled -- dim them so frozen state is
   visible. .btn has its own :disabled rule below. */
button:disabled:not(.btn) {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Collapsible Sections */
.collapsible-section {
    background: var(--light);
    border-radius: 16px;
    margin-bottom: 20px;
    overflow: hidden;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
}

.collapsible-section:hover {
    border-color: var(--primary);
}

.collapsible-header {
    padding: 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    user-select: none;
}

.collapsible-header:hover {
    background: var(--light);
}

.collapsible-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.collapsible-icon {
    font-size: 1.2em;
    transition: transform 0.3s ease;
}

.collapsible-icon.open {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.collapsible-content.open {
    max-height: 1500px;
    overflow-y: auto;
}

.collapsible-inner {
    padding: 20px;
    max-height: 100%;
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.config-item {
    background: white;
    padding: 16px;
    border-radius: 12px;
    border: 2px solid var(--border);
    transition: all 0.2s ease;
}

.config-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.config-item label {
    margin-bottom: 10px;
}

.helper-text {
    font-size: 0.8em;
    color: var(--dark-3);
    margin-top: 6px;
    line-height: 1.4;
}

/* Inline Help Tooltip (see static/js/hint_tooltip.js for the markup contract) */
.hint-tip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--primary);
    cursor: help;
    border-bottom: 1px dashed var(--primary);
    line-height: 1.3;
    transition: color 0.15s ease;
}

.hint-tip:hover,
.hint-tip.is-open,
.hint-tip:focus-visible {
    color: var(--primary-dark);
    border-bottom-color: var(--primary-dark);
}

.hint-tip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
    border-radius: 3px;
}

.hint-tip > template {
    display: none;
}

.hint-tip__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    font-style: normal;
    line-height: 1;
    font-family: Georgia, 'Times New Roman', serif;
}

.hint-tip-popup {
    display: none;
    position: fixed;
    z-index: 10000;
    max-width: 340px;
    padding: 14px 16px;
    background: white;
    color: var(--dark-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    line-height: 1.55;
    text-align: left;
    white-space: normal;
}

.hint-tip-popup.is-visible {
    display: block;
}

.hint-tip-popup strong {
    color: var(--dark);
    font-weight: 700;
}

.hint-tip-popup p {
    margin: 0 0 10px 0;
}

.hint-tip-popup p:last-child {
    margin-bottom: 0;
}

.hint-tip-popup ul {
    margin: 0 0 10px 0;
    padding-left: 18px;
}

.hint-tip-popup ul:last-child {
    margin-bottom: 0;
}

.hint-tip-popup li {
    margin-bottom: 6px;
}

.hint-tip-popup li:last-child {
    margin-bottom: 0;
}

/* Checkbox Styles */
.checkbox-group {
    display: flex;
    align-items: center;
    padding: 16px;
    background: white;
    border-radius: 12px;
    border: 2px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
}

.checkbox-group:hover {
    border-color: var(--primary);
    background: var(--light);
}

.checkbox-group input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 12px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-group label {
    margin: 0;
    cursor: pointer;
    flex: 1;
    font-weight: 500;
}

/* Buttons */
.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--success);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-secondary:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 30px;
}

.btn-group .btn {
    font-size: 0.85em;
    padding: 12px 16px;
}

.btn-group .btn span:first-child {
    font-size: 1em;
}

/* Alert Messages */
.alert {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: none;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    animation: slideInDown 0.3s ease;
}

.alert.show {
    display: flex;
}

.alert.success {
    background: #d1fae5;
    color: #065f46;
    border: 2px solid #10b981;
}

.alert.error {
    background: #fee2e2;
    color: #991b1b;
    border: 2px solid #ef4444;
}

/* Results Section */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.result-card {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    padding: 24px;
    border-radius: 16px;
    border-left: 4px solid var(--primary);
    transition: all 0.3s ease;
}

.result-card:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow);
}

.result-card h3 {
    color: var(--primary);
    margin-bottom: 12px;
    font-size: 1.3em;
    font-weight: 700;
}

.result-info {
    margin-bottom: 8px;
    color: var(--dark-2);
    font-size: 0.95em;
}

.result-info strong {
    color: var(--dark);
    font-weight: 600;
}

.status-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.status-completed {
    background: #d1fae5;
    color: #065f46;
}

.status-running {
    background: #fef3c7;
    color: #92400e;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--dark-3);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--light-2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.inline-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--light-2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--dark-3);
}

.empty-icon {
    font-size: 5em;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-text {
    font-size: 1.1em;
    font-weight: 500;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: var(--light-2);
}

::-webkit-scrollbar-thumb {
    background: var(--dark-3);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--dark-2);
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
}

.tab {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 600;
    color: var(--dark-3);
    transition: all 0.3s ease;
    font-size: 0.95em;
}

.tab:hover {
    color: var(--dark);
    background: var(--light);
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeInUp 0.4s ease;
}

/* Responsive Design */
@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .btn-group {
        grid-template-columns: 1fr;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    main > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* Sidebar Sticky */
.sidebar-sticky {
    position: sticky;
    top: 20px;
    /* Cap the sidebar at viewport height with internal scroll. Without the
       cap, a tall tab (e.g. Parameters > Execution) stretches the whole
       .main-layout row (align-items: stretch), so every tab switch resized
       the Plots/Key Metrics cards and re-rendered the chart. With it, row
       height is driven by the plots column, which doesn't change per tab. */
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* Expanded Chart: pins the plots card to fill the viewport. Intentionally does
   not override anything inside the card (heights, visibility, canvas sizing) —
   the card's own flex layout handles filling, so whatever is currently rendered
   simply gets more room. */
.chart-expanded {
    position: fixed !important;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    margin: 0 !important;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    animation: expandChart 0.25s ease-out;
}

@keyframes expandChart {
    from {
        transform: scale(0.96);
        opacity: 0.4;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Expanded Configuration panel reuses .chart-expanded pinning. While expanded,
   all three main tab sections are shown at once: side-by-side columns that
   scroll independently on wide screens, stacked (card scrolls) below 1400px.
   The main tab bar is hidden and replaced by per-column titles; collapsing the
   card removes the class and restores normal tab behavior untouched. */
#config_card.chart-expanded {
    overflow-y: auto;
}

/* switchMainTab() shows/hides sections via inline styles, so !important is
   needed to reveal all three while expanded. */
#config_card.chart-expanded .main-tab-content {
    display: block !important;
    /* Lift the sidebar-mode height cap (max-height: calc(100vh - 420px) above)
       so the sections can use the full expanded card height. */
    max-height: none;
}

/* Hide only the top-level tab bar (direct child) — the Parameters section has
   its own inner .tabs bar that must keep working. !important because the bar
   carries an inline display: flex in the template. */
#config_card.chart-expanded > .tabs {
    display: none !important;
}

/* Column titles replace the hidden tab bar. */
#config_card.chart-expanded .main-tab-content::before {
    display: block;
    font-size: 1.1em;
    font-weight: 700;
    color: var(--dark);
    padding-bottom: 10px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--border);
}

#config_card.chart-expanded #config-section::before { content: "Configuration"; }
#config_card.chart-expanded #signal-section::before { content: "Signal & Strategy"; }
#config_card.chart-expanded #params-section::before { content: "Parameters"; }

/* While expanded, the Signal Strategy collapsible is forced open so the column
   shows its content like the other two — no need to click it open. The header
   is made inert so clicking can't desync the collapse state that the normal
   sidebar view returns to on close. */
#config_card.chart-expanded #signal-section .collapsible-content {
    max-height: none;
    overflow: visible;
}

#config_card.chart-expanded #signal-section .collapsible-header {
    pointer-events: none;
}

#config_card.chart-expanded #signal-section .collapsible-icon {
    display: none;
}

@media (min-width: 1400px) {
    #config_card.chart-expanded {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: auto minmax(0, 1fr);
        column-gap: 24px;
        overflow: hidden;
        /* Explicit height (viewport minus the 20px pinning insets) so the 1fr
           row resolves against a definite size and the columns stretch to the
           card bottom instead of shrinking to their content. */
        height: calc(100vh - 40px) !important;
    }

    #config_card.chart-expanded > .card-header {
        grid-column: 1 / -1;
    }

    /* Each column scrolls on its own so the short sections stay in view while
       browsing the long ones. */
    #config_card.chart-expanded .main-tab-content {
        min-height: 0;
        overflow-y: auto;
        padding-right: 6px;
    }
}

/* Overlay when chart is expanded */
.chart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Performance Stats Cards */
.stat-card {
    background: var(--light);
    padding: 15px;
    border-radius: 12px;
    border: 2px solid var(--border);
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.stat-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--dark-3);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.4em;
    font-weight: 700;
    color: var(--dark);
}

.stat-value.positive {
    color: var(--success);
}

.stat-value.negative {
    color: var(--danger);
}

/* Spinner Animation */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(139, 92, 246, 0.3);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Disabled/Blurred state for buttons */
.btn-disabled {
    opacity: 0.5;
    filter: blur(1px);
    pointer-events: none;
    cursor: not-allowed !important;
}

/* Tooltip styles for regression statistics */
.stat-tooltip {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted #9ca3af;
    transition: all 0.2s ease;
}

.stat-tooltip:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.stat-tooltip::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: #1f2937;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75em;
    white-space: normal;
    width: 250px;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
    line-height: 1.4;
}

.stat-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1f2937;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.stat-tooltip:hover::after,
.stat-tooltip:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* ---- Download wait overlay ----
   Page-level blocking notice shown while a download is being prepared.
   Lives above every other layer (max in-app z-index is 9999) so it cannot be
   hidden behind a panel or scrolled out of view the way the inline #message
   alert can be. */
.download-wait-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 10050;
}

.download-wait-overlay.show {
    display: flex;
}

.download-wait-card {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 32px 40px;
    max-width: 420px;
    text-align: center;
    animation: slideInDown 0.25s ease;
}

.download-wait-spinner {
    width: 42px;
    height: 42px;
    margin: 0 auto 18px auto;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: downloadWaitSpin 0.9s linear infinite;
}

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

.download-wait-title {
    font-size: 1.05em;
    font-weight: 700;
    color: var(--dark);
    margin-bottom: 8px;
}

.download-wait-detail {
    font-size: 0.88em;
    color: var(--dark-3);
    line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
    .download-wait-spinner { animation-duration: 2.5s; }
    .download-wait-card { animation: none; }
}

/* Wait state: spinner visible, no dismiss button (the request owns the lifetime).
   Error state: spinner hidden, dismiss button shown so the user can recover. */
.download-wait-dismiss {
    display: none;
    margin-top: 18px;
    padding: 9px 22px;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.download-wait-dismiss:hover {
    background: var(--primary-dark);
}

.download-wait-overlay.is-error .download-wait-spinner {
    display: none;
}

.download-wait-overlay.is-error .download-wait-dismiss {
    display: inline-block;
}

.download-wait-overlay.is-error .download-wait-title {
    color: var(--danger);
}
