:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --border-color: #334155;
    --hover-bg: #334155;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 3rem;
}

.sidebar nav ul {
    list-style: none;
}

.sidebar nav li {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar nav li:hover, .sidebar nav li.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}

.sidebar nav li i {
    width: 20px;
}

.status-indicator {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background-color: rgba(16, 185, 129, 0.1);
    border-radius: 8px;
    color: var(--success-color);
    font-size: 0.9rem;
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success-color);
    box-shadow: 0 0 10px var(--success-color);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.last-update {
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    transition: color 0.3s;
}

.btn-icon:hover {
    color: var(--text-primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    background-color: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.balance { background: rgba(59, 130, 246, 0.1); color: var(--accent-color); }
.stat-icon.pnl { background: rgba(16, 185, 129, 0.1); color: var(--success-color); }
.stat-icon.positions { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); }
.stat-icon.winrate { background: rgba(239, 68, 68, 0.1); color: var(--danger-color); }

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-change.positive { color: var(--success-color); }
.stat-change.negative { color: var(--danger-color); }

.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.card-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Filter Group */
.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.filter-group select {
    padding: 0.4rem 0.8rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 150px;
}

.filter-group select option {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 0.5rem;
}

.filter-group select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.filter-group select:hover {
    border-color: var(--accent-color);
}

.btn-text {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-weight: 500;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.table td {
    font-size: 0.95rem;
}

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-buy { background: rgba(16, 185, 129, 0.1); color: var(--success-color); }
.badge-sell { background: rgba(239, 68, 68, 0.1); color: var(--danger-color); }
.badge-neutral { background: rgba(148, 163, 184, 0.1); color: var(--text-secondary); }
.badge-warning { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }

/* Navigation badge (issues count) */
.nav-badge {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.sidebar nav li {
    position: relative;
}

.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }

/* Real-time price update flash animation */
@keyframes flash-green {
    0% { background-color: rgba(16, 185, 129, 0.4); }
    100% { background-color: transparent; }
}

@keyframes flash-red {
    0% { background-color: rgba(239, 68, 68, 0.4); }
    100% { background-color: transparent; }
}

.flash-update {
    animation: flash-green 0.3s ease-out;
}

.current-pnl.text-danger.flash-update {
    animation: flash-red 0.3s ease-out;
}

.current-price {
    font-family: 'Roboto Mono', monospace;
    font-weight: 500;
}

.current-pnl {
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
}

/* Views */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.btn-action {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: opacity 0.3s;
}

.btn-action:hover {
    opacity: 0.9;
}

.btn-action.warning {
    background-color: var(--warning-color);
    color: #fff;
}

.btn-action.success {
    background-color: var(--success-color);
    color: #fff;
}

.form-input {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.indicator.paused {
    background-color: var(--warning-color);
    box-shadow: 0 0 10px var(--warning-color);
}

/* Charts Page Styles */
#tradingview-chart {
    background-color: #1a1a2e;
    border-radius: 8px;
}

.charts-controls .card-header {
    padding: 1rem 1.5rem;
    margin-bottom: 0;
}

#streaming-indicator.connected {
    background: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

#streaming-indicator.disconnected {
    background: var(--danger-color);
    box-shadow: 0 0 8px var(--danger-color);
}

/* Chart info cards specific styling */
#view-charts .stat-card {
    text-align: center;
}

#view-charts .stat-info {
    width: 100%;
}

#view-charts .stat-value {
    font-family: 'Inter', monospace;
    letter-spacing: -0.5px;
}

/* Responsive adjustments for charts page */
@media (max-width: 1200px) {
    #view-charts .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    #view-charts .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    #tradingview-chart {
        height: 350px !important;
    }
}

/* Price change animation */
@keyframes priceUp {
    0% { background-color: rgba(34, 197, 94, 0.3); }
    100% { background-color: transparent; }
}

@keyframes priceDown {
    0% { background-color: rgba(239, 68, 68, 0.3); }
    100% { background-color: transparent; }
}

.price-up {
    animation: priceUp 0.5s ease;
}

.price-down {
    animation: priceDown 0.5s ease;
}

/* ==========================================
   MOBILE RESPONSIVE STYLES
   ========================================== */

/* Header left container */
.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Mobile menu toggle button - hidden by default */
.btn-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.3s;
}

.btn-menu-toggle:hover {
    background-color: var(--hover-bg);
}

/* Mobile overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* Tablet breakpoint (1024px) */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

    #view-charts .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .main-content {
        padding: 1.5rem;
    }
}

/* Mobile breakpoint (768px) */
@media (max-width: 768px) {
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Show menu toggle button */
    .btn-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar mobile styles */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100%;
        z-index: 999;
        transition: left 0.3s ease;
        padding: 1rem;
    }

    .sidebar.open {
        left: 0;
    }

    /* Main content full width */
    .main-content {
        width: 100%;
        padding: 1rem;
        margin-left: 0;
    }

    /* Header adjustments */
    header {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 1.5rem;
    }

    header h1 {
        font-size: 1.3rem;
    }

    .header-actions {
        gap: 10px;
    }

    .last-update {
        display: none;
    }

    .user-profile span {
        display: none;
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    #view-charts .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Stat cards compact */
    .stat-card {
        gap: 1rem;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .stat-info h3 {
        font-size: 0.8rem;
    }

    /* Charts grid */
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Cards */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 1rem;
    }

    .card-header h2 {
        font-size: 1rem;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select {
        flex: 1;
        min-width: 0;
    }

    /* Tables responsive */
    .table th, .table td {
        padding: 8px 6px;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    /* Buttons */
    .btn-action {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    /* Toast position */
    #toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .toast {
        width: 100%;
    }

    /* TradingView chart height */
    #tradingview-chart {
        height: 300px !important;
    }

    /* Charts page controls */
    .charts-controls .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 1rem;
    }

    .charts-controls .card-header > div {
        flex-wrap: wrap;
        width: 100%;
    }

    .charts-controls select {
        flex: 1;
        min-width: 120px;
    }

    /* AI view adjustments */
    #view-ai .card-header {
        flex-direction: column;
        align-items: stretch;
    }

    #view-ai .card-header > div {
        flex-direction: column;
        gap: 10px;
    }

    #view-ai select {
        width: 100%;
    }

    #btn-trigger-analysis {
        width: 100%;
        justify-content: center;
    }

    /* Settings page */
    #view-settings .form-group > div {
        flex-direction: column;
    }

    #view-settings .btn-action {
        width: 100%;
        justify-content: center;
    }
}

/* Small mobile breakpoint (480px) */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
    }

    header {
        margin-bottom: 1rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    /* Single column stats on small screens */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    #view-charts .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    /* Card compact */
    .card {
        padding: 0.75rem;
        border-radius: 8px;
    }

    .card-header h2 {
        font-size: 0.95rem;
    }

    /* Table - hide less important columns */
    .table th:nth-child(n+5),
    .table td:nth-child(n+5) {
        display: none;
    }

    .table th, .table td {
        padding: 6px 4px;
        font-size: 0.75rem;
    }

    .badge {
        padding: 2px 6px;
        font-size: 0.7rem;
    }

    /* Buttons smaller */
    .btn-sm {
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    /* Logo smaller */
    .logo {
        font-size: 1.2rem;
        margin-bottom: 1.5rem;
    }

    /* Sidebar nav items */
    .sidebar nav li {
        padding: 10px 12px;
        margin-bottom: 4px;
        font-size: 0.9rem;
    }

    /* Status indicator compact */
    .status-indicator {
        padding: 10px;
        font-size: 0.8rem;
    }

    /* TradingView chart */
    #tradingview-chart {
        height: 250px !important;
    }

    /* Form inputs */
    .form-input {
        padding: 6px 10px;
        font-size: 0.9rem;
    }

    /* Mappings form - stack vertically */
    #add-mapping-form {
        flex-direction: column !important;
    }

    #add-mapping-form > div {
        width: 100% !important;
    }

    #add-mapping-form button[type="submit"] {
        width: 100%;
    }
}

/* Landscape mobile adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar {
        width: 240px;
        left: -250px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    #view-charts .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    #tradingview-chart {
        height: 250px !important;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .sidebar nav li {
        padding: 14px 16px;
    }

    .btn-action, .btn-sm, .btn-icon, .btn-text {
        min-height: 44px;
        min-width: 44px;
    }

    .table th, .table td {
        padding: 12px 8px;
    }

    select, input[type="text"], input[type="number"] {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
}

/* ===========================================
   UNIFIED DROPDOWN STYLES
   =========================================== */
.select-dropdown {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 120px;
    transition: border-color 0.2s ease;
}

.select-dropdown:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.select-dropdown:hover {
    border-color: var(--accent-color);
}

.select-dropdown option {
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 6px 12px;
}

/* Global select styles for better readability */
select {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

select option {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

/* ===========================================
   STRATEGIES PAGE
   =========================================== */
.strategies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.strategy-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.strategy-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.15);
}

.strategy-card.active {
    border-color: var(--success-color);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, transparent 100%);
}

.strategy-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.strategy-card-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.strategy-card-title i {
    font-size: 1.5rem;
    color: var(--accent-color);
}

.strategy-card-title h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.strategy-card-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.strategy-card-badge.active {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success-color);
}

.strategy-card-badge.inactive {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-secondary);
}

.strategy-card-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 15px;
}

.strategy-card-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.strategy-stat {
    text-align: center;
}

.strategy-stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.strategy-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.strategy-card-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.strategy-card-actions button {
    flex: 1;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-configure {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-configure:hover {
    background: var(--hover-bg);
    border-color: var(--accent-color);
}

.btn-activate {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    color: white;
}

.btn-activate:hover {
    opacity: 0.9;
}

.btn-deactivate {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: none;
    color: white;
}

.btn-deactivate:hover {
    opacity: 0.9;
}

/* Backtest result stats */
.backtest-stat-card {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.backtest-stat-card.positive {
    border-color: var(--success-color);
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, transparent 100%);
}

.backtest-stat-card.negative {
    border-color: var(--danger-color);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, transparent 100%);
}

.backtest-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.backtest-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

