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

:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --accent-primary: #6366f1;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --border-color: #333333;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 20px;
}

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

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-settings {
    background: var(--accent-primary);
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-settings:hover {
    background: #4f46e5;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.badge.stopped {
    background: var(--accent-danger);
    color: white;
}

.badge.running {
    background: var(--accent-success);
    color: white;
}


.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

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

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

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

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
    overflow: hidden;
    transition: transform 0.3s ease;
}

/* Remove hover effect for specific metric cards: BTC Price, Gross PnL, Volume, Grid Entry, Distance */
.dashboard .card:hover {
    transform: none;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 0;
}

.icon {
    width: 20px;
    height: 20px;
    stroke: var(--text-primary);
    fill: none;
    flex-shrink: 0;
}

.card-body {
    padding: 20px;
}

.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 10px;
}

.metric-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

/* Statistics card body with 2 columns */
.stats-grid .card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: row;
    gap: 0;
    column-gap: 30px;
    row-gap: 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

/* Force items into correct rows and columns:
   Coluna 1 (esquerda): Total Orders, Trades Opened, Trades Closed, Take Profit
   Coluna 2 (direita): Margin Added, TP Updated, Total Grids, Occupied Grids
*/
/* Coluna 1 - Primeira coluna (esquerda) */
.stat-item:nth-child(1) { /* Total Orders */
    grid-column: 1;
    grid-row: 1;
}
.stat-item:nth-child(3) { /* Trades Opened */
    grid-column: 1;
    grid-row: 2;
}
.stat-item:nth-child(5) { /* Trades Closed */
    grid-column: 1;
    grid-row: 3;
}
.stat-item:nth-child(7) { /* Take Profit */
    grid-column: 1;
    grid-row: 4;
    border-bottom: none; /* Last item in col 1 */
}

/* Coluna 2 - Segunda coluna (direita) */
.stat-item:nth-child(2) { /* Margin Added */
    grid-column: 2;
    grid-row: 1;
}
.stat-item:nth-child(4) { /* TP Updated */
    grid-column: 2;
    grid-row: 2;
}
.stat-item:nth-child(6) { /* Total Grids */
    grid-column: 2;
    grid-row: 3;
}
.stat-item:nth-child(8) { /* Occupied Grids */
    grid-column: 2;
    grid-row: 4;
    border-bottom: none; /* Last item in col 2 */
}

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

.stat-value {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1rem;
}

.config-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

.form-input {
    padding: 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.trades-list {
    max-height: 400px;
    overflow-y: auto;
}

.trade-item {
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 10px;
    border-left: 4px solid var(--accent-primary);
}

.trade-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.trade-index {
    font-weight: 700;
    color: var(--accent-primary);
}

.trade-pnl {
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
}

.trade-pnl.positive {
    background: var(--accent-success);
    color: white;
}

.trade-pnl.negative {
    background: var(--accent-danger);
    color: white;
}

.trade-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.trade-detail-item {
    display: flex;
    flex-direction: column;
}

.trade-detail-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.trade-detail-value {
    color: var(--text-primary);
    font-weight: 600;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-style: italic;
}

.trade-history-card {
    margin-top: 30px;
}

.trades-table-container {
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

.trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 600px;
}

.trades-table thead {
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
}

.trades-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background 0.2s ease;
}

.trades-table th:hover {
    background: var(--bg-secondary);
}

.trades-table th.sortable {
    padding-right: 24px;
}

.trades-table th .sort-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    opacity: 0.5;
    font-size: 10px;
}

.trades-table th.sort-asc .sort-icon,
.trades-table th.sort-desc .sort-icon {
    opacity: 1;
}

.trades-table th.sort-asc .sort-icon::before {
    content: '▲';
}

.trades-table th.sort-desc .sort-icon::before {
    content: '▼';
}

.trades-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.trades-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.trades-table td {
    padding: 12px;
    color: var(--text-primary);
}

.trades-table .trade-index-cell {
    font-weight: 700;
    color: var(--accent-primary);
}

.trades-table .trade-pnl-cell {
    font-weight: 600;
}

.trades-table .trade-pnl-cell.positive {
    color: var(--accent-success);
}

.trades-table .trade-pnl-cell.negative {
    color: var(--accent-danger);
}

.trades-table .trade-value {
    font-weight: 600;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.modal-content {
    background: var(--bg-secondary);
    margin: auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    display: flex;
    flex-direction: column;
}

.modal-large {
    max-width: 800px;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: 12px 12px 0 0;
    gap: 10px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    border-radius: 0 0 12px 12px;
}

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

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.form-help {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 5px;
    font-style: italic;
}

/* Presets Section - Clean Profile Design */
.presets-section {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.presets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.presets-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.presets-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.preset-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.preset-profile:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.preset-profile:active {
    transform: translateY(0);
}

.preset-profile-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--accent-primary);
    border-radius: 50%;
    color: white;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.preset-profile:hover .preset-profile-icon {
    background: var(--accent-primary);
    transform: scale(1.1);
}

.preset-profile-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.preset-profile-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preset-profile-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preset-profile-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.preset-profile:hover .preset-profile-delete {
    opacity: 1;
}

.preset-profile-delete:hover {
    background: var(--accent-danger);
    color: white;
    transform: scale(1.1);
}

.preset-profile-delete:active {
    transform: scale(0.95);
}

/* Empty state for presets */
.presets-list .empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-style: italic;
}

.config-form h3 {
    margin-top: 20px;
    margin-bottom: 15px;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard {
        grid-template-columns: 1fr;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    /* On mobile, statistics back to single column */
    .stats-grid .card-body {
        grid-template-columns: 1fr;
        column-gap: 0;
    }
    
    /* Restore border for last item on mobile */
    .stats-grid .card-body .stat-item:last-child {
        border-bottom: none;
    }
    
    /* Presets grid - single column on mobile */
    .presets-list {
        grid-template-columns: 1fr;
    }
    
    /* Show delete button on mobile */
    .preset-profile-delete {
        opacity: 1;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
    }
    
    .header-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-settings {
        width: 100%;
    }
    
    .controls {
        flex-wrap: wrap;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
}

