:root {
    /* Color Palette - Premium Dark Financial Theme */
    --bg-app: #0f1115;
    --bg-sidebar: #161920;
    --bg-card: #1c2029;
    --bg-input: #232833;
    --bg-hover: #2a303d;

    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #6366f1;

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --info: #3b82f6;

    --border: #2d3342;
    --border-light: #374151;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-heading: 'Outfit', sans-serif;

    /* Spacing & Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --header-height: 70px;
    --sidebar-width: 260px;
    --bg-body: #0f1115;
    /* Fallback for views using it */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    /* Allow scrolling on mobile if layout breaks, but keep app-feel on desktop */
}

@media (min-width: 769px) {
    body {
        overflow: hidden;
    }
}

/* Layout */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

@media (max-width: 768px) {
    #app {
        height: auto;
        min-height: 100vh;
        width: 100%;
        flex-direction: column;
    }
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: transform 0.3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
    color: var(--primary);
    text-decoration: none;
}

.brand-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.brand h1 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: var(--primary);
    color: white;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.user-info {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
}

.user-info .name {
    font-weight: 600;
}

.user-info .status {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.social-footer {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.social-icon {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    transition: all 0.2s;
    cursor: pointer;
}

.social-icon:hover {
    color: var(--primary);
    transform: translateY(-2px);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-app);
    overflow: hidden;
    position: relative;
    width: 0;
    /* Allow flex to control width */
}

.top-bar {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    background-color: rgba(15, 17, 21, 0.8);
    backdrop-filter: blur(10px);
}

.top-bar h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
}

.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* UI Elements */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
}

.btn-icon:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 1.5rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-heading);
}

.stat-value.positive {
    color: var(--success);
}

.stat-value.negative {
    color: var(--danger);
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.three-col {
    grid-template-columns: repeat(3, 1fr);
}

.four-col {
    grid-template-columns: repeat(4, 1fr);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input,
select,
textarea {
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.7rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 40;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-card);
    width: 1000px;
    max-width: 95vw;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    z-index: 50;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal.hidden,
.modal-backdrop.hidden {
    display: none;
}

/* Radio Group (Buy/Sell) */
.radio-group {
    display: flex;
    background-color: var(--bg-input);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.radio-label {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.radio-label input {
    position: absolute;
    opacity: 0;
}

.radio-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.radio-label input:checked+.radio-btn.buy {
    background-color: var(--success);
    color: white;
}

.radio-label input:checked+.radio-btn.sell {
    background-color: var(--danger);
    color: white;
}

/* File Upload */
.file-upload-area {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-md);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.file-upload-area:hover {
    border-color: var(--primary);
    background-color: var(--bg-hover);
}

.image-preview-list {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.img-preview {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* Table */
.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.trade-detail-row.hidden {
    display: none;
}

.trade-detail-content {
    background-color: var(--bg-sidebar);
    padding: 0;
    border-left: 4px solid var(--primary);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.detail-block {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.detail-block:last-child {
    border-bottom: none;
}

.detail-block h5 {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    font-weight: 600;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1.5rem;
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.metric-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.text-content {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius-sm);
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    font-size: 0.95rem;
}

th {
    text-align: left;
    padding: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

tr:hover td {
    background-color: var(--bg-hover);
}

.badge {
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge.win {
    background-color: var(--success-bg);
    color: var(--success);
}

.badge.loss {
    background-color: var(--danger-bg);
    color: var(--danger);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        width: 100%;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 0.75rem 1rem;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        z-index: 100;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .brand {
        margin-bottom: 0;
    }

    .brand h1 {
        font-size: 1.25rem;
    }

    .nav-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background-color: var(--bg-sidebar);
        flex-direction: row;
        justify-content: space-around;
        padding: 0.5rem;
        border-top: 1px solid var(--border);
        z-index: 100;
        border-right: none;
    }

    .nav-link {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem;
        font-size: 0.7rem;
    }

    .nav-link i {
        width: 20px;
        height: 20px;
    }

    .nav-link span {
        display: block;
        /* Show labels but smaller */
    }

    .user-profile,
    .social-footer {
        display: none;
    }

    .main-content {
        width: 100%;
        flex: none;
        padding-bottom: 70px;
        overflow: visible;
    }

    .top-bar {
        padding: 0 1rem;
        height: 60px;
    }

    .top-bar h2 {
        font-size: 1.2rem;
    }

    .view-container {
        padding: 1rem;
    }

    .grid-2,
    .grid-3,
    .form-grid,
    .three-col {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .modal {
        width: 95vw;
        max-height: 85vh;
    }

    /* Fix for tables on mobile */
    .table-container {
        margin: 0 -1rem;
        width: calc(100% + 2rem);
        padding: 0 1rem;
    }

    /* Small font for tables on mobile */
    td,
    th {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Calendar Mobile Fix */
    .calendar-grid {
        gap: 0.25rem !important;
        grid-template-columns: repeat(7, 1fr) !important;
    }

    .calendar-day {
        min-height: 60px !important;
        padding: 0.25rem !important;
    }

    .calendar-day .day-num {
        font-size: 0.7rem !important;
    }

    .calendar-day .day-pnl {
        font-size: 0.65rem !important;
        margin-top: 0.25rem !important;
    }

    /* Hide day labels in full if screen too small, or use single letters */
    .calendar-day-label {
        font-size: 0.7rem !important;
    }

    /* Analytics Chart Container Fix */
    .card canvas {
        max-width: 100% !important;
    }

    .metrics-grid {
        gap: 0.75rem !important;
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .detail-block {
        padding: 1rem !important;
    }

    .text-content {
        font-size: 0.85rem !important;
        padding: 0.75rem !important;
    }

    /* Hide less important columns on mobile tables */
    th:nth-child(3),
    td:nth-child(3),
    th:nth-child(5),
    td:nth-child(5) {
        display: none !important;
    }
}

.view-toggle-btn {
    color: var(--text-muted);
}

.view-toggle-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.view-toggle-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

.analytics-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
    align-items: flex-start;
}

@media (max-width: 1100px) {
    .analytics-layout {
        grid-template-columns: 1fr;
    }
}

.analytics-card {
    display: flex;
    flex-direction: column;
}

.analytics-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.analytics-card h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.chart-wrapper {
    height: 250px;
    position: relative;
}

.chart-wrapper.large {
    height: 350px;
}

.filter-input {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 6px;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.filter-input:focus {
    border-color: var(--primary);
}

.btn-secondary {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

/* Tooltip Styles (Native title uses browser tooltip, but we can enhance it if needed) */
[title] {
    cursor: help;
}