/* --- Root Variables & Reset --- */
:root {
    --bg-primary: #0b0f19;
    --bg-surface: rgba(22, 30, 49, 0.65);
    --bg-card: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-blue: #3b82f6;
    --accent-teal: #14b8a6;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-orange: #f97316;
    --accent-warn: #eab308;
    --accent-purple: #a855f7;
    
    --font-main: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    --shadow-premium: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

body.light-mode {
    --bg-primary: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.85);
    --bg-card: rgba(241, 245, 249, 0.9);
    --border-color: rgba(0, 0, 0, 0.1);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --shadow-premium: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
}

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow-x: hidden;
    min-height: 100vh;
}

/* Glass Background Layer */
.glass-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.05) 0%, transparent 40%),
                radial-gradient(circle at 90% 80%, rgba(20, 184, 166, 0.05) 0%, transparent 40%);
    z-index: -1;
    pointer-events: none;
}

/* App Wrapper */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* --- Header Style --- */
.app-header {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    box-shadow: var(--shadow-premium);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    font-size: 28px;
    color: var(--accent-teal);
    animation: rotate 6s linear infinite;
}

@keyframes rotate {
    100% { transform: rotate(360deg); }
}

.brand-text h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sub-brand {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}

/* Badges */
.badge {
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.3);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Switch Styles */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
}

input:checked + .slider {
    background-color: var(--accent-green);
}

input:checked + .slider-warn {
    background-color: var(--accent-warn);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

.status-indicator {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.status-indicator.active {
    background: rgba(234, 179, 8, 0.15);
    color: var(--accent-warn);
}

.status-indicator.live {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}

.status-indicator.inactive {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

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

.stat-card {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-premium);
    transition: transform 0.2s;
}

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

.stat-icon {
    width: 54px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
}

.icon-blue { background: rgba(59, 130, 246, 0.1); color: var(--accent-blue); }
.icon-orange { background: rgba(249, 115, 22, 0.1); color: var(--accent-orange); }
.icon-teal { background: rgba(20, 184, 166, 0.1); color: var(--accent-teal); }
.icon-green { background: rgba(16, 185, 129, 0.1); color: var(--accent-green); }
.icon-red { background: rgba(239, 68, 68, 0.1); color: var(--accent-red); }
.icon-purple { background: rgba(168, 85, 247, 0.1); color: var(--accent-purple); }

.stat-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.stat-info h3 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.stat-desc {
    font-size: 11px;
    color: var(--text-muted);
}

/* --- Layout --- */
.main-layout {
    display: grid;
    grid-template-columns: 1.8fr 1.2fr;
    gap: 24px;
}

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

.left-section, .right-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Panels */
.panel {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-premium);
    overflow: hidden;
}

.panel-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.panel-badge {
    font-size: 11px;
    font-weight: 600;
    background: rgba(20, 184, 166, 0.12);
    color: var(--accent-teal);
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(20, 184, 166, 0.2);
}

/* --- Tables --- */
.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 13px;
}

th {
    padding: 14px 24px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

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

.empty-row {
    text-align: center;
}

.empty-row td {
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

/* Contract Address link style */
.ca-cell {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 140px;
}

.ca-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.copy-btn {
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s;
}

.copy-btn:hover {
    color: var(--accent-teal);
}

/* Badges PnL */
.pnl-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-family: var(--font-mono);
    display: inline-block;
}

.pnl-green {
    background: rgba(16, 185, 129, 0.12);
    color: var(--accent-green);
}

.pnl-red {
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-red);
}

/* Buttons */
.btn {
    font-size: 11px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
}

.icon-btn:hover {
    color: var(--text-primary);
}

/* --- Logs Panel --- */
.logs-panel {
    display: flex;
    flex-direction: column;
    max-height: 580px;
}

.logs-container {
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(0, 0, 0, 0.1);
}

.log-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    border-left: 3px solid var(--text-muted);
}

.log-item.entered { border-left-color: var(--accent-green); }
.log-item.rejected { border-left-color: var(--accent-orange); }
.log-item.rejected_error { border-left-color: var(--accent-red); }
.log-item.processing { border-left-color: var(--accent-blue); }

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.log-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.log-title.entered { color: var(--accent-green); }
.log-title.rejected { color: var(--accent-orange); }
.log-title.rejected_error { color: var(--accent-red); }
.log-title.processing { color: var(--accent-blue); }

.log-time {
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.log-ca {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.log-reason {
    font-size: 11px;
    color: var(--text-muted);
}

.empty-logs {
    text-align: center;
    padding: 60px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
}

/* Toast System */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--accent-teal);
    color: var(--bg-primary);
    font-weight: 600;
    font-size: 13px;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10000;
    transition: transform 0.3s, opacity 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Warning Banner Styling */
.warning-banner {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-premium);
    animation: slideDown 0.3s ease-out;
}

.warning-banner.hidden {
    display: none !important;
}

.warning-icon {
    color: var(--accent-red);
    font-size: 16px;
    animation: warningPulse 1.5s infinite;
}

@keyframes warningPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

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

/* Console Panel Styling */
.console-panel {
    margin-top: 24px;
    background: rgba(10, 15, 30, 0.85);
    border: 1px solid var(--border-color);
}

.console-body {
    background: #040811;
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
    height: 280px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    color: #a7f3d0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.log-line {
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
}

/* Scrollbar styling for console */
.console-body::-webkit-scrollbar {
    width: 8px;
}
.console-body::-webkit-scrollbar-track {
    background: #040811;
}
.console-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
.console-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Tab Header & Buttons */
.tab-header {
    display: flex;
    gap: 8px;
}

.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
}

/* Helper Utilities */
.hidden {
    display: none !important;
}

/* Action Badges in Real Wallet Activity */
.action-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
    letter-spacing: 0.5px;
}

.action-buy {
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.action-sell {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.action-receive {
    background: rgba(59, 130, 246, 0.12);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.action-send {
    background: rgba(249, 115, 22, 0.12);
    color: #fdba74;
    border: 1px solid rgba(249, 115, 22, 0.2);
}

.action-other {
    background: rgba(156, 163, 175, 0.12);
    color: #d1d5db;
    border: 1px solid rgba(156, 163, 175, 0.2);
}

.sig-link {
    color: var(--accent-blue);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}

.sig-link:hover {
    text-decoration: underline;
}

.desc-cell {
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-color);
}

/* History & Activity Scrollable Container */
.history-panel .table-container {
    max-height: 420px;
    overflow-y: auto;
    border-radius: 8px;
}

/* Coin Cell Styling */
.coin-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0;
}

.coin-logo {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #101726;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

.coin-logo-fallback {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    text-transform: uppercase;
}

.coin-name-wrap {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.coin-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-color);
}

.coin-symbol {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Time Cell Styling */
.time-cell {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.time-relative {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-color);
}

.time-absolute {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .app-container {
        padding: 12px;
        gap: 16px;
        overflow-x: hidden;
    }
    
    .app-header {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 12px;
    }
    
    .header-controls {
        justify-content: space-between;
        gap: 12px;
        width: 100%;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .stat-card {
        padding: 14px;
        gap: 14px;
    }
    
    .stat-icon {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
    
    .stat-info h3 {
        font-size: 18px;
    }
    
    .main-layout {
        gap: 16px;
    }
    
    .left-section, .right-section {
        gap: 16px;
        min-width: 0;
        width: 100%;
    }
    
    .panel {
        border-radius: 12px;
        min-width: 0;
        width: 100%;
    }
    
    .panel-header {
        padding: 14px 16px;
    }
    
    .table-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table th, table td {
        padding: 10px 12px;
        font-size: 12px;
    }
    
    /* Hide non-essential columns on mobile */
    #positions-table th:nth-child(2),
    #positions-table td:nth-child(2),
    #positions-table th:nth-child(5),
    #positions-table td:nth-child(5) {
        display: none;
    }

    #history-table th:nth-child(2),
    #history-table td:nth-child(2),
    #history-table th:nth-child(5),
    #history-table td:nth-child(5) {
        display: none;
    }

    #real-activity-table th:nth-child(4),
    #real-activity-table td:nth-child(4),
    #real-activity-table th:nth-child(5),
    #real-activity-table td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 480px) {
    .brand {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }
    
    .logo-icon {
        font-size: 24px;
    }
    
    .brand-text h1 {
        font-size: 18px;
    }
    
    .header-controls {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
    }
    
    #circuit-breaker-badge {
        width: 100%;
        justify-content: center;
        padding: 8px;
    }

    .toggle-container {
        flex: 1 1 45%;
        justify-content: space-between;
        padding: 6px 10px;
        background: rgba(0,0,0,0.1);
        border-radius: 8px;
    }
    
    body.light-mode .toggle-container {
        background: rgba(0,0,0,0.03);
    }
    
    .header-controls .switch {
        display: none;
    }
    
    #theme-toggle-btn {
        flex: 0 0 auto !important;
        justify-content: center;
        padding: 8px 14px !important;
    }
}

/* --- Light Mode Overrides for Console --- */
body.light-mode .console-panel {
    background: #ffffff;
    border: 1px solid var(--border-color);
}

body.light-mode .console-body {
    background: #f8fafc;
    border-top: 1px solid var(--border-color);
}

body.light-mode .console-body::-webkit-scrollbar-track {
    background: #f8fafc;
}

body.light-mode .console-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}

body.light-mode .console-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body.light-mode .log-line {
    color: #334155 !important;
}
