:root {
    --bg-color: #0c0f14;
    --card-bg: rgba(23, 28, 36, 0.7);
    --border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, hsla(217, 76%, 15%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(217, 76%, 10%, 1) 0, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Modern Header & Navigation */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;

    background: rgba(23, 28, 36, 0.95);
    /* Slightly less transparent for readability */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    padding: 1rem 1.2rem;
    border-radius: 0 0 16px 16px;
    /* Rounded bottom corners only */
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    text-decoration: none;
    color: inherit;
}

.logo:hover {
    opacity: 0.9;
}

.logo-icon {
    /* Container for SVG */
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--success);
    filter: drop-shadow(0 0 12px rgba(16, 185, 129, 0.5));
}

.logo-icon svg {
    width: 28px;
    height: 28px;
    stroke-width: 2.5;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

header h1 small {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

/* Nav Container - Segmented Control Look */
nav {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1.2rem;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}

.nav-link svg {
    width: 18px;
    height: 18px;
    stroke-width: 2;
}

.status-badge {
    padding: 0.4rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.header-status-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 0.5rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
}

.user-badge {
    background: rgba(59, 130, 246, 0.15); /* matching --accent */
    color: var(--accent);
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.logout-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.logout-icon-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Hide on mobile if needed */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.2rem;
    }

    .nav-link span {
        display: none;
    }

    /* Hide text, show icon only */
    .nav-link {
        padding: 0.5rem;
    }
}

.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    /* backdrop-filter removed for performance stability */
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1.5rem;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    border-color: rgba(59, 130, 246, 0.3);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.8rem;
    font-weight: 500;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.stat-card .delta {
    font-size: 0.95rem;
    font-weight: 600;
}

.stat-card {
    position: relative;
    /* For absolute positioning of badge */
}

/* Fancy Market Badge */
.fancy-badge {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    /* Pill shape */
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.fancy-badge.open {
    background: rgba(16, 185, 129, 0.15);
    /* Emerald tint */
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
}

.fancy-badge.closed {
    background: rgba(239, 68, 68, 0.15);
    /* Red tint */
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: currentColor;
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 5px currentColor;
}

.fancy-badge.open .pulse-dot::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid currentColor;
    animation: pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulse-ring {
    0% {
        width: 100%;
        height: 100%;
        opacity: 0.8;
    }

    100% {
        width: 300%;
        height: 300%;
        opacity: 0;
    }
}

.delta.up {
    color: var(--success);
}

.delta.down {
    color: var(--danger);
}


.charts-row {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 1100px) {
    .charts-row {
        grid-template-columns: 1fr;
    }
}

.holdings-section {
    width: 100%;
}

.chart-container {
    min-height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent grid blowout */
}

/* Make Performance Chart fill the height */
.chart-container .canvas-wrapper {
    flex: 1;
    height: 100%;
    /* Fill flex parent */
    width: 100%;
    min-height: 300px;
    position: relative;
    /* Crucial for Chart.js */
    overflow: hidden;
    /* Prevent spillover */
}

.canvas-wrapper {
    height: 300px;
    position: relative;
}

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 0.8rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    transition: color 0.2s;
    /* Sticky Header */
    position: sticky;
    top: 0;
    z-index: 20;
    /* Keep above date-headers and markers */
    background: #171c24;
    /* Match var(--card-bg) without transparency for scrolling */
}

th.sortable {
    cursor: pointer;
    white-space: nowrap;
}

th.sortable:hover {
    color: var(--text-primary);
}

th.sort-asc::after {
    content: ' ▲';
    font-size: 0.8em;
    color: var(--accent);
}

th.sort-desc::after {
    content: ' ▼';
    font-size: 0.8em;
    color: var(--accent);
}

td {
    padding: 1rem 0.8rem;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

.up {
    color: var(--success);
}

.down {
    color: var(--danger);
}

button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.chart-legend-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.chart-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* Reset Zoom Button specific override for visibility */
#reset-zoom-btn {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #e2e8f0;
    width: 32px;
    height: 32px;
    padding: 6px;
    z-index: 100;
}

#reset-zoom-btn:hover {
    background: rgba(30, 41, 59, 0.9);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.4);
}

/* Ensure overlay doesn't block chart interactions */
.chart-controls-overlay {
    pointer-events: none;
}

.chart-controls-overlay button {
    pointer-events: auto;
}

button.active {
    background: var(--accent);
    color: white;
}

/* Removed duplicate header/nav styles */

/* Backtest Grid */
.backtest-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 2rem;
}

.form-group {
    margin-bottom: 1.2rem;
}

label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

input,
select {
    width: 100%;
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

#start-btn,
.btn-danger,
.btn-primary {
    width: 100%;
    margin-top: 1rem;
    padding: 0.8rem;
    font-weight: 600;
    color: white;
    border-radius: 8px;
    font-size: 0.95rem;
    /* Ensure matching font size */
}

#start-btn,
.btn-primary {
    background: var(--accent);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border);
    width: 100%;
    margin-top: 1rem;
    padding: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 0.95rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: var(--danger);
    border: none;
}

#start-btn:disabled,
.btn-danger:disabled,
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    gap: 0.5rem;
}

.button-group button {
    flex: 1;
    /* Equal width */
}

/* Progress */
.progress-container {
    background: #1e293b;
    border-radius: 100px;
    height: 10px;
    margin: 1.5rem 0;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    background: linear-gradient(90deg, var(--accent), #60a5fa);
    height: 100%;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

.canvas-wrapper {
    height: 400px;
    margin-top: 0;
}

.buy {
    color: var(--success);
    font-weight: 600;
}

.sell {
    color: var(--danger);
    font-weight: 600;
}

.table-container {
    max-height: 500px;
    overflow-y: auto;
}

@media (max-width: 900px) {
    .backtest-grid {
        grid-template-columns: 1fr;
    }
}

/* Config Page Specifics */
.config-section {
    max-width: 900px;
    margin: 0 auto;
}

.form-group-section {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.form-group-section:last-child {
    border-bottom: none;
}

.form-group-section h3 {
    margin-bottom: 1.5rem;
    color: var(--accent);
    font-weight: 600;
}

.form-group-section h4 {
    margin: 1.5rem 0 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.strategy-block {
    background: rgba(255, 255, 255, 0.02);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

/* Strategy Tags */
.strategy-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.strategy-tag {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8em;
    color: var(--text-secondary);
}

.strategy-tag strong {
    color: var(--text-primary);
    font-weight: 600;
}

.strategy-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    margin-top: 1rem;
    font-weight: 600;
}

/* Strategy Grid for Filters */
.strategy-grid {
    display: grid;
    /* Reduce min width so items fit in rows more easily */
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 0.5rem;
    /* Smaller gap */
    margin-top: 0.5rem;
}

.strategy-grid-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    padding: 0.4rem 0.5rem;
    /* Compact padding */
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.strategy-grid-item .label {
    font-size: 0.65rem;
    /* Smaller label */
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0.1rem;
    white-space: nowrap;
    /* Prevent wrap */
    overflow: hidden;
    text-overflow: ellipsis;
}

.strategy-grid-item .val {
    font-size: 0.85rem;
    /* Smaller value */
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Outfit', sans-serif;
}

/* Enhanced Tag Styling */
.strategy-tag {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.2);
}

/* Scroll container for strategy info to prevent expanding row */
.strategy-scroll-container {
    max-height: 140px;
    /* Limit height roughly to match other summary cards */
    overflow-y: auto;
    padding-right: 4px;
    /* Space for scrollbar */
}

/* Custom scrollbar for webkit */
.strategy-scroll-container::-webkit-scrollbar {
    width: 4px;
}

.strategy-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* Strategy Content Horizontal Layout */
.strategy-content-row {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.strategy-section-group {
    flex: 1;
    min-width: 200px;
    /* Ensure they don't get too squashed */
}

/* Adjust grid within the groups to use available space */
.strategy-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

/* --- Config UI Improvements --- */
.config-sub-section {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.2rem;
    margin-bottom: 1.5rem;
}

.group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    color: var(--accent);
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-helper-text {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    font-style: italic;
}

/* Toggle Switch Styled Checkbox */
.toggle-switch-label {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
    font-weight: 500;
}

/* Floating Save Bar */
.floating-save-bar {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    /* Move to right */
    left: auto;
    transform: none;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--accent);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    gap: 1rem;
    align-items: center;
}

.floating-save-bar button {
    margin: 0;
    /* Override default margins */
    width: auto;
    min-width: 150px;
}

/* Success Header Notification */
.success-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--success);
    color: #fff;
    text-align: center;
    padding: 1rem;
    font-weight: 600;
    font-size: 1.1rem;
    transform: translateY(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Add padding to bottom of page so content isn't hidden */
body {
    padding-bottom: 8rem;
}

/* Custom Chart Legend */
.chart-legend-html {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    /* Reduced gap */
    justify-content: center;
    padding: 0.8rem;
    /* Reduced padding */
    margin-top: -0.5rem;
    /* Pull up closer to chart */
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    /* Slightly smaller text */
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.25rem 0.6rem;
    /* Compact padding */
    border-radius: 8px;
    border: 1px solid transparent;
    position: relative;
    /* Anchor for tooltip */
}

/* Tooltip container (HTML) */
.tooltip-content {
    position: absolute;
    bottom: 125%;
    /* Start slightly above */
    left: 50%;
    transform: translateX(-50%);

    background: #1e293b;
    color: #e2e8f0;
    padding: 0.8rem;
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.4;
    text-align: left;
    white-space: nowrap;

    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    min-width: 180px;
}

/* Tooltip Arrow */
.chart-legend-item::before {
    content: '';
    position: absolute;
    bottom: 115%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #1e293b;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

/* Chart Overlay Controls */
.chart-icon-btn {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    margin: 0;
    /* Override default button margins */
}

.chart-icon-btn:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.05);
}

/* Hover State */
.chart-legend-item:hover .tooltip-content {
    opacity: 1;
    bottom: 135%;
    /* Move up slightly on show */
}

.chart-legend-item:hover::before {
    opacity: 1;
    bottom: 125%;
}

.chart-legend-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border);
    color: var(--text-primary);
}

.chart-legend-dot {
    display: inline-block;
    /* Ensure span respects dimensions */
    width: 10px;
    /* Smaller square */
    height: 10px;
    border-radius: 2px;
    /* Distinct square */
    flex-shrink: 0;
}

.chart-legend-item.hidden {
    opacity: 0.4;
    text-decoration: line-through;
    background: transparent;
}

/* Timeline Styles */
.timeline-table {
    border-collapse: separate;
    border-spacing: 0;
}

.date-header {
    position: sticky;
    top: 38px;
    /* Offset to keep column headers (th) visible */
    z-index: 15;
}

.date-header td {
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.75rem 1rem !important;
    font-weight: 700 !important;
    color: var(--success) !important;
    font-size: 0.8rem !important;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border) !important;
    border-top: 1px solid var(--border) !important;
}

/* Vertical line for timeline */
.timeline-table td:first-child {
    position: relative;
    padding-left: 2.5rem !important;
    width: 140px;
}

.timeline-table td:first-child::before {
    content: '';
    position: absolute;
    left: 1.25rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

/* Markers */
.timeline-table td:first-child::after {
    content: '';
    position: absolute;
    left: calc(1.25rem - 4px);
    top: 1.2rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #475569;
    border: 2px solid var(--bg-color);
    z-index: 2;
    transition: all 0.2s;
}

/* Marker color based on status classes added to TR */
.timeline-table tr.log-ERROR td:first-child::after {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

.timeline-table tr.log-JOB_START td:first-child::after {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.timeline-table tr.log-JOB_END td:first-child::after {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.timeline-table tr.log-MARKET_CHECK td:first-child::after {
    background: #64748b;
}

.timeline-table tr.log-BUY td:first-child::after {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.timeline-table tr.log-SELL td:first-child::after {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}


.timeline-table td {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03) !important;
    vertical-align: top;
}

.timeline-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.timeline-table td.log-time {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.timeline-table .log-message {
    line-height: 1.5;
    color: #e2e8f0;
}

/* Action Badges in Timeline */
.action-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
    background: rgba(255, 255, 255, 0.05);
}

.text-danger {
    color: #f87171 !important;
}

.text-info {
    color: #60a5fa !important;
}

.text-success {
    color: #34d399 !important;
}

.text-secondary {
    color: #94a3b8 !important;
}

/* --- Mobile Responsiveness --- */

@media (max-width: 768px) {
    body {
        padding: 1rem;
        padding-bottom: 5rem; /* Space for floating action buttons if any */
    }

    .container {
        padding: 0; 
        max-width: 100%;
    }

    /* Header Adjustments */
    header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }

    .logo {
        justify-content: center;
    }

    nav {
        overflow-x: auto;
        justify-content: flex-start; /* Allow scroll if needed */
        padding: 4px;
        -webkit-overflow-scrolling: touch;
    }
    
    .nav-link {
        flex-shrink: 0;
        padding: 0.6rem 0.8rem; /* slightly larger touch target */
        justify-content: center;
    }
    
    .header-status-group {
         justify-content: center;
         margin-top: 0.5rem;
    }

    /* Summary Cards */
    .summary {
        grid-template-columns: 1fr; /* Stack cards vertically */
        gap: 1rem;
    }

    .stat-card .value {
        font-size: 1.8rem; /* Slightly smaller for mobile */
    }

    /* Charts */
    .charts-row {
        grid-template-columns: 1fr;
    }
    
    .chart-container, .canvas-wrapper {
        min-height: 250px; /* Reduced height for mobile */
        height: auto;
    }

    /* Ensure canvas doesn't overflow */
    canvas {
        max-width: 100%;
    }
    
    .chart-controls {
        overflow-x: auto;
        display: flex;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Hide scrollbar for cleaner look */
    }
    
    .chart-controls::-webkit-scrollbar {
        display: none;
    }
    
    .chart-controls button {
        flex-shrink: 0;
    }

    /* Tables */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        border: 1px solid var(--border);
        margin-bottom: 1rem;
    }
    
    table {
        min-width: 600px; /* Force scroll */
    }

    /* Backtest Grid */
    .backtest-grid {
         grid-template-columns: 1fr;
    }
    
    /* Config Page Structure */
    .config-section {
        padding: 0;
    }

    /* Form Elements */
    input, select, button {
        font-size: 16px; /* Prevent iOS zoom */
        min-height: 44px; /* Touch target size */
    }

    .form-row {
        grid-template-columns: 1fr; /* Stack form rows */
    }
    
    /* Config Page Specifics */
    .form-group-grid {
        grid-template-columns: 1fr;
    }
    
    .filters-grid {
        grid-template-columns: 1fr 1fr; /* 2 columns on mobile likely fits */
    }
    
    .strategy-content-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    /* Floating Bar */
    .floating-save-bar {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        width: auto;
        transform: none;
        border-radius: 12px;
    }
    
    /* Fancy Badge Position Override for Mobile */
    .fancy-badge {
         position: static;
         margin-top: 1rem;
         display: inline-flex;
         width: fit-content;
    }
    
    .stat-card {
        display: flex;
        flex-direction: column;
    }

    /* Logs Table */
    .timeline-table th:nth-child(1) {
        width: auto; /* Auto width for time */
    }
    
    /* Hide some table columns on very small screens if needed, 
       but scrolling is usually better for data density */
}

@media (max-width: 480px) {
    /* Very small devices */
    header h1 {
        font-size: 1.1rem;
    }
    
    .nav-link span {
         display: none; /* Hide text on very small screens if icons are clear */
    }
    
    .nav-link svg {
        margin: 0;
    }
    
    .filters-grid {
        grid-template-columns: 1fr; /* Stack filters */
    }
}

/* --- Custom Modal System --- */
.custom-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; opacity: 0; transition: opacity 0.2s ease;
    pointer-events: none;
}
.custom-modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.custom-modal {
    background: #1e293b; border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px; padding: 2rem; max-width: 500px; width: 90%;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5); transform: translateY(20px);
    transition: transform 0.2s ease;
}
.custom-modal.show { transform: translateY(0); }
.custom-modal h3 { margin-top: 0; color: #f8fafc; margin-bottom: 1rem; }
.custom-modal p { color: #94a3b8; line-height: 1.5; margin-bottom: 1.5rem; white-space: pre-wrap; }
.custom-modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; }
.custom-modal-btn {
    padding: 0.5rem 1.25rem; border-radius: 6px; font-weight: 600;
    cursor: pointer; border: none; transition: all 0.2s;
}
.btn-cancel { background: rgba(255,255,255,0.05); color: #cbd5e1; }
.btn-cancel:hover { background: rgba(255,255,255,0.1); }
.btn-confirm { background: #3b82f6; color: white; }
.btn-confirm:hover { background: #2563eb; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }

/* Strategy Management Extra UI */
.strategy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
    margin-top: 0.8rem;
}
.strategy-grid-item {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}
.strategy-grid-item .label {
    display: block;
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    font-weight: 700;
}
.strategy-grid-item .val {
    font-size: 1.1rem;
    font-weight: 700;
    color: #f8fafc;
}
.strategy-section-title {
    font-size: 0.8rem;
    color: #a5b4fc;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(165, 180, 252, 0.1);
    padding-bottom: 0.25rem;
}

/* --- LOGIN OVERLAY --- */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 8, 14, 0.92);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.login-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 380px;
    backdrop-filter: blur(24px);
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6),
                0 0 40px rgba(59, 130, 246, 0.08);
    animation: loginSlide 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.login-card .login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-card .login-logo .logo-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.login-card .login-logo h2 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.login-card .login-logo h2 span {
    color: var(--accent);
}

.login-card .login-logo p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.login-field {
    margin-bottom: 1.25rem;
}

.login-field label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.login-field input {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: all 0.3s ease;
}

.login-field input:focus {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.04);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}

.login-field input::placeholder {
    color: rgba(255, 255, 255, 0.15);
}

.login-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0.85rem;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
    letter-spacing: 0.3px;
    position: relative;
    overflow: hidden;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.35);
}

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

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.login-error {
    color: var(--danger);
    font-size: 0.8rem;
    text-align: center;
    margin-top: 1rem;
    min-height: 1.2rem;
    font-weight: 500;
    transition: opacity 0.3s;
}

@keyframes loginShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

.login-card.shake {
    animation: loginShake 0.5s ease;
}