/* ==========================================================================
   Design System & Variables
   ========================================================================== */
   :root {
    /* Colors - Light Theme */
    --bg-main: #f3f4f6;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    
    /* Brand/Accent Colors */
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    
    /* Status Colors */
    --success: #10b981;
    --success-bg: #d1fae5;
    --success-text: #065f46;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --warning: #f59e0b;
    
    /* Layout */
    --sidebar-width: 250px;
    --border-radius: 12px;
    --transition-speed: 0.3s;
}

/* Dark Theme Variables */
:root.dark {
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;

    --success-bg: rgba(16, 185, 129, 0.15);
    --success-text: #34d399;
    --danger-bg: rgba(239, 68, 68, 0.15);
    --danger-text: #f87171;
}

/* ==========================================================================
   Reset & Global Styles
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ==========================================================================
   Layout Structure
   ========================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-icon {
    font-size: 1.8rem;
    color: var(--primary);
}

.sidebar-nav {
    padding: 24px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item i {
    font-size: 1.4rem;
}

.nav-item:hover, .nav-item.active {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
}

.theme-btn {
    padding: 10px;
    border-radius: 50%;
    color: var(--text-muted);
    transition: all 0.2s;
    font-size: 1.5rem;
}
.theme-btn:hover { background-color: var(--border-color); color: var(--text-main); }

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    max-width: 1200px;
    width: 100%;
}

.mobile-header {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 90;
}

.mobile-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--primary);
}

.icon-btn { font-size: 1.5rem; color: var(--text-main); }

/* ==========================================================================
   Views & Typography
   ========================================================================== */
.view-section {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.view-section.active { display: block; }

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

.view-header {
    margin-bottom: 32px;
}

.view-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle { color: var(--text-muted); font-size: 0.95rem; }

/* ==========================================================================
   Dashboard Stats
   ========================================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background-color: var(--bg-card);
    padding: 24px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}
.stat-icon.profit { background-color: rgba(16, 185, 129, 0.15); color: #10b981; }
.stat-icon.winrate { background-color: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.stat-icon.trades { background-color: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.stat-icon.rr { background-color: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.stat-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.5rem; font-weight: 700; margin-top: 4px; }

/* Charts */
.charts-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}
.chart-card {
    background-color: var(--bg-card);
    padding: 24px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}
.chart-card h3 { margin-bottom: 16px; font-size: 1.1rem; }
.chart-wrapper { position: relative; height: 300px; width: 100%; }

/* PNL Calendar */
.pnl-calendar-card { margin-bottom: 24px; }
.pnl-calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.pnl-calendar-header h3 { margin-bottom: 0; }
.pnl-calendar-controls { display: flex; gap: 10px; flex-wrap: wrap; }

.pnl-calendar-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}
.pnl-calendar-nav button {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: 0.2s;
}
.pnl-calendar-nav button:hover { background-color: var(--border-color); }
.pnl-calendar-nav span { font-weight: 700; font-size: 1rem; min-width: 140px; text-align: center; }

.pnl-calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}
.pnl-calendar-weekdays span {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.pnl-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}
.pnl-day-cell {
    border-radius: 8px;
    padding: 10px 4px;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background-color: var(--bg-main);
}
.pnl-day-cell.empty { visibility: hidden; }
.pnl-day-cell.future { background: transparent; color: var(--text-muted); }
.pnl-day-cell .day-num { font-weight: 700; font-size: 0.85rem; }
.pnl-day-cell .day-val { font-size: 0.75rem; font-weight: 600; }
.pnl-day-cell.zero { background-color: var(--border-color); color: var(--text-muted); }
.pnl-day-cell.zero .day-val { color: var(--text-muted); }
.pnl-day-cell.positive { background-color: rgba(16, 185, 129, 0.18); color: #10b981; }
.pnl-day-cell.positive .day-val { color: #10b981; }
.pnl-day-cell.negative { background-color: rgba(239, 68, 68, 0.18); color: #ef4444; }
.pnl-day-cell.negative .day-val { color: #ef4444; }

.pnl-calendar-grid.weekly .pnl-day-cell { min-height: 90px; }

/* ==========================================================================
   Forms & Inputs
   ========================================================================== */
.form-card {
    background-color: var(--bg-card);
    padding: 32px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 20px;
}

.form-row.three-cols { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px;}
.form-group label { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); }

input[type="text"], input[type="number"], input[type="datetime-local"], select, textarea {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-divider {
    font-size: 0.85rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-muted);
    margin: 24px 0 16px 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

/* Radio Buttons */
.radio-group { display: flex; gap: 16px; }
.radio-btn {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 12px; border: 1px solid var(--border-color); border-radius: 8px;
    cursor: pointer; transition: all 0.2s; background: var(--bg-main);
}
.radio-btn input { display: none; }
.radio-btn.buy-btn:has(input:checked) { border-color: var(--success); background-color: var(--success-bg); color: var(--success-text); font-weight: 600;}
.radio-btn.sell-btn:has(input:checked) { border-color: var(--danger); background-color: var(--danger-bg); color: var(--danger-text); font-weight: 600;}

/* Position Size Unit Toggle */
.label-with-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.unit-toggle { display: inline-flex; border: 1px solid var(--border-color); border-radius: 6px; overflow: hidden; }
.unit-btn {
    background: var(--bg-main); border: none; padding: 4px 10px; font-size: 0.78rem; font-weight: 600;
    color: var(--text-muted); cursor: pointer; transition: all 0.2s;
}
.unit-btn + .unit-btn { border-left: 1px solid var(--border-color); }
.unit-btn.active { background: var(--primary); color: #fff; }

/* Input Suffix (e.g. Leverage "x") */
.input-suffix-wrap { position: relative; display: flex; align-items: center; }
.input-suffix-wrap input { padding-right: 36px; }
.input-suffix {
    position: absolute; right: 14px; font-size: 0.9rem; font-weight: 600; color: var(--text-muted);
    pointer-events: none;
}

/* File Upload */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}
.upload-area:hover { border-color: var(--primary); background-color: rgba(59, 130, 246, 0.05); }
.upload-area i { font-size: 2.5rem; margin-bottom: 8px; color: var(--primary); }
.preview-container { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.preview-img { width: 100px; height: 100px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-color); cursor: pointer;}
.preview-item { position: relative; }
.remove-img { position: absolute; top: -8px; right: -8px; background: var(--danger); color: white; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 12px;}

/* Buttons */
.form-actions { display: flex; justify-content: flex-end; gap: 16px; margin-top: 32px; }
.btn { padding: 12px 24px; border-radius: 8px; font-weight: 600; font-size: 0.95rem; transition: all 0.2s; }
.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); transform: translateY(-1px);}
.btn-secondary { background-color: var(--bg-main); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background-color: var(--border-color); }
.btn-danger { background-color: var(--danger); color: white; }

/* ==========================================================================
   History Table
   ========================================================================== */
.filters-card {
    display: flex; gap: 16px; margin-bottom: 24px;
}
.filters-card .filter-group { flex: 1; max-width: 300px; }

.table-card {
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.table-responsive { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; text-align: left; }
.history-table th, .history-table td { padding: 16px; border-bottom: 1px solid var(--border-color); }
.history-table th { background-color: rgba(0,0,0,0.02); font-weight: 600; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; }
.history-table tr:last-child td { border-bottom: none; }
.history-table tbody tr { transition: background-color 0.2s; }
.history-table tbody tr:hover { background-color: rgba(0,0,0,0.02); cursor: pointer; }

/* Dynamic Colors */
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.badge { padding: 4px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; }
.badge-buy { background-color: var(--success-bg); color: var(--success-text); }
.badge-sell { background-color: var(--danger-bg); color: var(--danger-text); }

.action-btns { display: flex; gap: 8px; }
.action-btn { padding: 6px; border-radius: 4px; color: var(--text-muted); transition: 0.2s; font-size: 1.2rem;}
.action-btn:hover { background-color: var(--border-color); color: var(--text-main); }
.action-btn.delete:hover { background-color: var(--danger-bg); color: var(--danger); }

.empty-state { text-align: center; padding: 64px 24px; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state.hidden { display: none; }

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
    display: none; position: fixed; z-index: 1000; left: 0; top: 0;
    width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.3s ease;
}
.modal.show { display: flex; opacity: 1; }
.modal-content { max-width: 90%; max-height: 90vh; border-radius: 8px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5); object-fit: contain; }
.close-modal { position: absolute; top: 20px; right: 30px; color: white; font-size: 40px; font-weight: bold; cursor: pointer; }

.detail-modal .modal-card {
    background-color: var(--bg-card);
    width: 100%; max-width: 700px; max-height: 90vh;
    border-radius: var(--border-radius);
    overflow-y: auto; display: flex; flex-direction: column;
}
.modal-header { padding: 24px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--bg-card); z-index: 10;}
.close-detail-modal { font-size: 24px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 24px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.detail-item { display: flex; flex-direction: column; gap: 4px; }
.detail-label { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; }
.detail-value { font-weight: 600; font-size: 1.1rem; }
.detail-images { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.detail-images img { max-width: 200px; border-radius: 8px; cursor: pointer; border: 1px solid var(--border-color); transition: transform 0.2s;}
.detail-images img:hover { transform: scale(1.05); }


/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 992px) {
    .charts-container { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 16px; }
    .mobile-header { display: flex; }
    .form-row, .form-row.three-cols { grid-template-columns: 1fr; gap: 16px; }
    .view-header h1 { font-size: 1.5rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .filters-card { flex-direction: column; }
    .filters-card .filter-group { max-width: 100%; }
    .pnl-day-cell { min-height: 48px; padding: 6px 2px; }
    .pnl-day-cell .day-val { font-size: 0.65rem; }
    .pnl-calendar-header { flex-direction: column; align-items: flex-start; }
}
