/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Figtree:ital,wght@0,300..900;1,300..900&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

:root {
    /* M3-ish Color Tokens */
    --primary: #2c3e50;
    --on-primary: #ffffff;
    --primary-container: #d3e3fd;
    --on-primary-container: #041e49;

    --secondary: #3498db;
    --on-secondary: #ffffff;

    --background: #f5f7fa;
    --on-background: #1f1f1f;

    --surface: #ffffff;
    --on-surface: #1f1f1f;
    --surface-variant: #e1e8ed;
    --on-surface-variant: #444746;

    --outline: #747775;
    --outline-variant: #c4c7c5;

    --success: #2ecc71;
    --warning: #f1c40f;
    --danger: #e74c3c;
    --text-main: #333333;
    --text-light: #7f8c8d;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Shape */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Header Height */
    --header-height: 72px;
    /* Approx height based on padding */
}

body {
    font-family: 'Figtree', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background);
    color: var(--on-background);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
}

/* Layout */
.main-content {
    flex: 1;
    width: 100%;
    margin: 0 auto;
    margin-top: var(--header-height);
    padding: 0;
    /* Padding moved to dashboard wrapper */
    box-sizing: border-box;
    overflow: hidden;
    /* Prevent body scroll if using inner scrolling */
}

/* Header & Nav */
header {
    background: var(--surface);
    padding: var(--spacing-md) var(--spacing-lg);
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    z-index: 1;
    height: var(--header-height);
    box-sizing: border-box;
}

.brand {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo {
    width: 40px;
    height: 40px;
}

.skeleton {
    animation: skeleton-loading 1s linear infinite;
    border: 0px solid var(--surface-variant);
}

@keyframes skeleton-loading {
    0% {
        background-color: var(--surface-variant);
    }

    100% {
        background-color: var(--surface);
    }
}

/* Material 3 Expressive Button Group for Navigation */
.nav-group {
    display: flex;
    background-color: var(--surface-variant);
    border-radius: var(--radius-full);
    padding: 2px;
}

.nav-item {
    padding: 0 24px;
    height: 40px;
    border-radius: var(--radius-full) !important;
    text-decoration: none;
    color: var(--on-surface-variant);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border: none;
    background: none;
    cursor: pointer;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--on-surface);
}

.nav-item.active {
    background-color: var(--primary-container);
    color: var(--on-primary-container);
}

.desktop-icon {
    display: inline-block;
    margin-right: 8px;
}

.mobile-icon {
    display: none;
}

a {
    color: var(--primary);
}

/* Mobile Nav */
@media (max-width: 768px) {
    header {
        flex-direction: row;
        padding: 0;
        height: var(--header-height);
        position: fixed;
        bottom: 0;
        top: auto;
        border-top: 1px solid var(--surface-variant);
        border-bottom: none;
        z-index: 1000;
        background: var(--surface);
    }

    .brand {
        display: none; /* Only show bottom tab icons on mobile */
    }

    .nav-group {
        width: 100%;
        overflow-x: hidden;
        justify-content: space-around;
        border-radius: 0;
        background-color: transparent;
        padding: 8px 0;
    }

    .nav-item {
        flex-shrink: 1;
        padding: 4px 8px;
        flex-direction: column;
        height: auto;
    }
    
    .nav-text {
        font-size: 0.70rem;
        margin-top: 2px;
        display: block;
    }

    .desktop-icon {
        display: none;
    }

    .mobile-icon {
        display: block;
        font-size: 24px;
    }

    .main-content {
        margin-top: 0;
        margin-bottom: 0;
        height: auto;
        overflow: visible;
    }

    footer {
        margin-bottom: 60px;
    }

    .desktop-only {
        display: none !important;
    }
}

/* Footer */
footer {
    background: var(--surface);
    padding: 30px 40px;
    text-align: left;
    font-size: 0.7rem;
    line-height: 1.5;
    color: var(--text-light);
    border-top: 1px solid var(--surface-variant);
    margin-top: auto;
}

/* Shared Components */
.container {
    max-width: 800px !important;
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 0 !important;
}

.index-container {
    max-width: 1000px !important;
}

.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    border: 1px solid var(--surface-variant);
}

/* Button Styles */
.btn {
    padding: 0 20px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 24px;
    height: 48px;
    border-radius: var(--radius-full);
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-decoration: none;
    background: transparent;
    border: 1px solid var(--outline);
    color: var(--primary);
    box-sizing: border-box;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--on-primary);
    border: none;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--outline);
    color: var(--primary);
}


.btn-micro {
    padding: 0 16px;
    height: 36px;
    font-size: 0.8rem;
}

/* Tables */
table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--surface-variant);
}

th {
    background-color: var(--background);
    font-weight: 600;
    color: var(--text-light);
}

tr:hover {
    background-color: var(--background);
}

/* --- Dashboard Refactor --- */

.dashboard-wrapper {
    width: 100%;
    height: 100%;
    padding: var(--spacing-md);
    box-sizing: border-box;
    overflow: hidden;
}

.dashboard-grid {
    display: grid;
    /* Left (Accounts), Middle (Main), Right (Analyzer) */
    grid-template-columns: 280px 1fr 320px;
    gap: var(--spacing-lg);
    align-items: start;
    height: 100%;
}

/* 1. Left Sidebar */
.sidebar {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
    /* Hide scrollbar for cleaner look */
    scrollbar-width: thin;
}

.sidebar-tab {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0 16px;
    height: 40px;
    margin-bottom: 4px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-full);
    color: var(--on-surface-variant);
    font-weight: 500;
    box-sizing: border-box;
}

.sidebar-tab:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.sidebar-tab.active {
    background-color: var(--secondary);
    color: white;
}

.sidebar-icon {
    margin-right: 10px;
    width: 20px;
}

.sidebar-separator {
    margin: 15px 0;
    border-bottom: 1px solid var(--surface-variant);
}

.sidebar-header-text {
    color: var(--text-light);
    font-size: 0.8rem;
    margin-bottom: 10px;
    padding-left: 15px;
}

.sidebar-action-icon {
    color: var(--danger);
    opacity: 0.6;
    padding: 5px;
}

/* 2. Middle Content */
.content {
    height: 100%;
    overflow-y: auto;
    padding-right: 5px;
    /* Spacing for scrollbar */
    scrollbar-width: thin;
}

/* 3. Right Sidebar */
.analyzer-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
    scrollbar-width: thin;
}

.analyzer-header {
    border-bottom: 1px solid var(--surface-variant);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.analyzer-stat {
    margin-bottom: 15px;
}

.buying-power-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary);
}

.buying-power-subtitle {
    font-size: 0.8rem;
    color: var(--text-light);
}


/* Connect Page Styles */
.connect-step {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #e1e1e1;
}

/* Forms */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select {
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
    margin: 8px 0 16px;
    border: 1px solid var(--outline-variant);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

/* Login Page Wrapper */
.login-wrapper {
    max-width: 400px;
    margin: 60px auto;
    padding: 40px;
    background: white;
    border-radius: 12px;
    text-align: center;
}

/* Settings Layout Wrapper */
.setting-wrapper {
    max-width: 1000px;
    margin: 0 auto;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.desktop-only {
    display: flex;
}

.text-right {
    text-align: right;
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

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

.flex-center {
    display: flex;
    align-items: center;
}

.flex-end-gap {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.flex-gap-10 {
    display: flex;
    gap: 10px;
}

.m-0 {
    margin: 0;
}

.mt-15 {
    margin-top: 15px;
}

.mt-20 {
    margin-top: 20px;
}

.mb-0 {
    margin-bottom: 0;
}

.mb-10 {
    margin-bottom: 10px;
}

.mb-20 {
    margin-bottom: 20px;
}

.p-20 {
    padding: 20px;
}

.no-decoration {
    text-decoration: none;
}

.cursor-pointer {
    cursor: pointer;
}

.w-full {
    width: 100%;
}

.border-none {
    border: none !important;
}

/* Dashboard Components */
.list-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.list-item {
    background: var(--surface);
    border: 1px solid var(--surface-variant);
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-item:hover {
    border-color: var(--secondary);
}

.list-item-summary {
    display: flex;
    gap: 20px;
    align-items: center;
    width: 100%;
}

.list-col {
    display: flex;
    flex-direction: column;
}

.list-col-label {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 2px;
}

.list-col-value {
    font-weight: 500;
    font-size: 0.95rem;
}

.list-item-details {
    background: #f8f9fa;
    border-top: 1px solid var(--surface-variant);
    padding: 15px;
    margin-top: -5px;
    border-radius: 0 0 8px 8px;
    display: none;
    animation: slideDown 0.2s ease-out;
}

.list-item-details.open {
    display: block;
}

.list-icon-chevron {
    color: var(--text-light);
    font-size: 0.8rem;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.action-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn-performance {
    background: var(--secondary);
    color: white;
    width: 180px;
    justify-content: center;
}

.btn-add-order {
    background: var(--surface);
    color: var(--primary);
    border: 1px solid var(--outline-variant);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--surface-variant);
    padding-bottom: 8px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--primary);
}

.status-tag {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-working {
    background: #e3f2fd;
    color: #1976d2;
}

.status-filled {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-cancelled {
    background: #ffebee;
    color: #c62828;
}

.demo-banner {
    background-color: #fff3cd;
    color: #856404;
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    text-align: center;
    border: 1px solid #ffeeba;
}

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    background: var(--surface);
    border-radius: 8px;
}

.empty-text {
    font-style: italic;
    font-size: 0.9rem;
    color: var(--text-light);
}


/* Badges */
.badge {
    padding: 4px 8px;
    background: var(--surface-variant);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

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

.badge-buy {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-sell {
    background: #ffebee;
    color: #c62828;
}

.link-account-btn {
    margin-top: 20px;
    padding: 0 15px;
    height: 36px;
    background: var(--surface);
    border: 1px solid var(--outline-variant);
    color: var(--primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.disconnected-card {
    background-color: #fce8e6;
    color: #c0392b;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    border: 1px solid #fadbd8;
    text-align: center;
}

.btn-danger-primary {
    background-color: #c0392b;
    border-color: #c0392b;
    color: white;
}

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

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

.stat-value {
    font-size: 1.4rem;
    font-weight: bold;
}

.editable {
    border-bottom: 1px dashed var(--success);
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .sidebar {
        height: auto;
    }
    .analyzer-card {
        height: auto;
    }
}

/* Modal Helper */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content-sm {
    background: white;
    padding: 25px;
    border-radius: 8px;
    width: 300px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 200px 1fr;
        /* Right sidebar moves to bottom or hidden? 
           Request says: "on mobile the sections should all stack together".
           Intermediate state like tablet isn't strictly defined, 
           but 3 cols might be too tight.
           Let's stack right sidebar below or keep it if space allows.
           For now, let's keep 3 cols but shrink sidebars slightly, 
           or go to 2 cols and put analyzer below content.
        */
        /* Let's try to maintain 3 cols but smaller sidebars until mobile checkpoint */
        grid-template-columns: 220px 1fr 240px;
    }
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 200px 1fr 200px;
        gap: var(--spacing-md);
    }
}

/* Mobile Stacked Layout */
@media (max-width: 768px) {
    body { height: auto; overflow-y: auto; }
    .dashboard-grid { display: flex; flex-direction: column; height: auto; gap: var(--spacing-md); }
    .sidebar, .content, .analyzer-card { height: auto; overflow: visible; width: 100%; }
    .sidebar { order: 1; }
    .content { order: 2; }
    .analyzer-card { order: 3; }
}

/* Global Component Styles */
.sidebar-separator { margin: 15px 0; border-bottom: 1px solid var(--surface-variant); }
.sidebar-section-title { color: var(--text-light); font-size: 0.8rem; margin-bottom: 10px; padding-left: 15px; }

/* Notice Banner */
.notice-banner {
    background: #fff8e1;
    border: 1px solid #ffecb3;
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    color: #856404;
    margin-bottom: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
}

/* Performance Page - Global */
.performance-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: var(--spacing-xl) var(--spacing-md);
}

.performance-header { text-align: center; margin-bottom: var(--spacing-xl); }
.performance-tab-group { display: inline-flex; background: var(--surface-variant); border-radius: var(--radius-full); padding: 4px; }
.performance-tab { padding: 8px 24px; text-decoration: none; color: var(--on-surface-variant); font-weight: 500; }
.performance-tab.active { background: var(--surface); border-radius: var(--radius-lg); color: var(--on-surface); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.performance-percentile { font-weight: 500; font-size: 1.1rem; color: var(--on-surface); margin-top: var(--spacing-lg); }
.performance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--spacing-xl); }
@media (max-width: 768px) { .performance-grid { grid-template-columns: 1fr; } }
.performance-stat-label { color: var(--text-light); margin-bottom: var(--spacing-xs); }
.performance-stat-group { display: flex; align-items: baseline; gap: 12px; }
.performance-stat-value { font-size: 2.5rem; margin: 0; font-weight: 700; }
.performance-stat-return { color: var(--success); font-weight: bold; font-size: 1.5rem; }
.performance-chart-card { border: 1px solid var(--outline-variant); border-radius: var(--radius-lg); padding: var(--spacing-lg); background: var(--surface); margin-top: var(--spacing-md); }
.performance-chart-svg { width: 100%; height: auto; aspect-ratio: 2 / 1; max-height: 300px; display: block; }
.performance-forecast-section { display: flex; flex-direction: column; justify-content: center; }
.performance-forecast-item { margin-bottom: var(--spacing-xl); }
.performance-forecast-value { font-size: 2.5rem; color: var(--secondary); margin: 0; }
.performance-summary-text { color: var(--text-light); font-size: 0.95rem; line-height: 1.5; }
.performance-summary-text strong { color: var(--on-surface); }
