/* CSS Variables */
:root {
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-light: #e0e7ff;
    --color-secondary: #64748b;
    --color-secondary-hover: #475569;

    --color-success: #10b981;
    --color-success-light: #d1fae5;
    --color-warning: #f59e0b;
    --color-warning-light: #fef3c7;
    --color-danger: #ef4444;
    --color-danger-light: #fee2e2;

    --color-bg: #f8fafc;
    --color-bg-card: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

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

.nav-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--color-primary), #818cf8);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 18px;
}

.nav-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--color-bg);
    border-radius: 20px;
    font-size: 14px;
    color: var(--color-text-secondary);
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-warning);
    animation: pulse 2s infinite;
}

.status-indicator.active {
    background: var(--color-success);
}

.status-indicator.inactive {
    background: var(--color-danger);
    animation: none;
}

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

/* Main Content */
.main-content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Dashboard */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
}

.header-content h1 {
    margin: 0 0 4px 0;
    font-size: 28px;
    font-weight: 700;
}

.subtitle {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: 14px;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary.active {
    background: var(--color-danger);
}

.btn-primary.active:hover {
    background: #dc2626;
}

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
}

.btn-icon::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background: currentColor;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpolygon points='5 3 19 12 5 21 5 3'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
}

.btn.active .btn-icon::before {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='6' y='4' width='4' height='16'/%3E%3Crect x='14' y='4' width='4' height='16'/%3E%3C/svg%3E");
}

.refresh-icon::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    background: currentColor;
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M23 4v6h-6'/%3E%3Cpath d='M1 20v-6h6'/%3E%3Cpath d='M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
}

.btn-secondary:active .refresh-icon::before {
    animation: spin 0.5s ease;
}

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

/* Cards */
.card {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-bg);
}

.card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.card-actions {
    display: flex;
    gap: 8px;
}

/* Cards Row */
.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
}

/* Status Card */
.status-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-row .label {
    color: var(--color-text-secondary);
    font-size: 14px;
}

.status-row .value {
    font-weight: 500;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: var(--color-success-light);
    color: var(--color-success);
}

.badge-warning {
    background: var(--color-warning-light);
    color: #b45309;
}

.badge-danger {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.date-badge {
    font-size: 13px;
    color: var(--color-text-muted);
}

.count-badge {
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--color-primary);
}

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

/* Progress Bar */
.progress-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.progress-bar {
    height: 8px;
    background: var(--color-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #818cf8);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: right;
}

/* Wallets */
.wallets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.wallet-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wallet-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--color-text-secondary);
}

.wallet-icon {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.wallet-icon.target {
    background: var(--color-warning);
}

.wallet-icon.your {
    background: var(--color-success);
}

.wallet-address {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-bg);
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.wallet-address code {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-copy {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.btn-copy:hover {
    opacity: 1;
}

.copy-icon::before {
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    background: var(--color-text-secondary);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
}

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

.config-item {
    text-align: center;
}

.config-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
}

.config-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tooltip Styles */
.config-card {
    overflow: visible;  /* Allow tooltips to overflow */
}

.config-card .card-body {
    overflow: visible;
}

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

.config-item.has-tooltip {
    cursor: help;
    position: relative;
    padding: 12px 8px;
    border-radius: var(--radius);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.config-item.has-tooltip:hover {
    background-color: var(--color-primary-light);
    transform: translateY(-2px);
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: var(--color-text-muted);
    color: white;
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    margin-left: 4px;
    vertical-align: middle;
}

.config-item.has-tooltip:hover .help-icon {
    background: var(--color-primary);
}

/* Custom tooltip styling */
.config-item.has-tooltip[data-tooltip] {
    position: relative;
}

.config-item.has-tooltip[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-text);
    color: white;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    line-height: 1.5;
    white-space: normal;
    width: 260px;
    max-width: 90vw;
    text-align: left;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease;
}

.config-item.has-tooltip[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--color-text);
    z-index: 1001;
    animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    background: var(--color-bg);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tbody tr:hover {
    background: var(--color-bg);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.empty-row td {
    padding: 40px 16px;
}

.empty-row:hover {
    background: transparent !important;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--color-text-muted);
}

.empty-icon::before {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    background: var(--color-border);
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.5'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E");
    mask-size: contain;
    mask-repeat: no-repeat;
    opacity: 0.5;
}

/* Trade Status Badges */
.trade-status {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
}

.trade-status.executed {
    background: var(--color-success-light);
    color: var(--color-success);
}

.trade-status.pending {
    background: var(--color-warning-light);
    color: #b45309;
}

.trade-status.failed {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

.trade-status.filtered {
    background: var(--color-bg);
    color: var(--color-text-muted);
}

/* Side Badge */
.side-badge {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.side-badge.yes {
    background: var(--color-success-light);
    color: var(--color-success);
}

.side-badge.no {
    background: var(--color-danger-light);
    color: var(--color-danger);
}

/* Select */
.select-small {
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
}

.select-small:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Footer */
.footer {
    padding: 20px;
    text-align: center;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-card);
}

.footer p {
    margin: 0;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.toast {
    background: var(--color-text);
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast.success {
    background: var(--color-success);
}

.toast.error {
    background: var(--color-danger);
}

.toast.warning {
    background: var(--color-warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Slippage styling */
.slippage-value {
    font-size: 12px;
}

.slippage-value.positive {
    color: var(--color-danger);
}

.slippage-value.negative {
    color: var(--color-success);
}

/* Stop-Loss / Take-Profit styling */
.sl-value {
    color: var(--color-danger);
}

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

.sl-price {
    color: var(--color-danger);
    font-weight: 500;
    font-size: 13px;
}

.tp-price {
    color: var(--color-success);
    font-weight: 500;
    font-size: 13px;
}

.sl-tp-disabled {
    color: var(--color-text-muted);
    font-style: italic;
    font-size: 12px;
}

/* P&L styling */
.pnl-positive {
    color: var(--color-success);
    font-weight: 500;
}

.pnl-negative {
    color: var(--color-danger);
    font-weight: 500;
}

/* Header badges container */
.header-badges {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 0 16px;
    }

    .nav-title {
        display: none;
    }

    .main-content {
        padding: 16px;
    }

    .dashboard-header {
        flex-direction: column;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .cards-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .config-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .data-table th,
    .data-table td {
        padding: 10px 12px;
        font-size: 13px;
    }
}

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

    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
        padding: 8px 0;
        border-bottom: 1px solid var(--color-border);
    }

    .stat-item:last-child {
        border-bottom: none;
    }

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

    .config-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }
}
