:root {
    --bg-body: #ffffff;
    --bg-card: #f8f9fa;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --brand-primary: #2563eb;
    --brand-hover: #1d4ed8;
    --border-color: #e5e7eb;
    --market-up: #10b981;
    --market-down: #ef4444;
}

[data-theme="dark"] {
    --bg-body: #0d1117;
    --bg-card: #161b22;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --brand-primary: #58a6ff;
    --brand-hover: #1f6feb;
    --border-color: #30363d;
    --market-up: #3fb950;
    --market-down: #f85149;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

header {
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

/* Header & Nav */
header .container {
    max-width: 1400px;
    /* Wider for dashboard feel */
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    /* Allow wrapping */
}

/* Logo - Order 1 */
.logo {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.4rem;
    text-decoration: none;
    color: var(--text-primary);
    letter-spacing: -1px;
    white-space: nowrap;
    order: 1;
}

/* Nav - Order 3 (Desktop) */
.main-nav {
    order: 3;
}

/* Search Bar - Order 2 (Desktop) */
.search-bar {
    position: relative;
    max-width: 500px;
    width: 100%;
    order: 2;
    flex: 1;
    margin: 0 40px;
}



.search-bar input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    /* Bigger padding */
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    font-size: 0.95rem;
    /* Larger font */
    height: 44px;
    /* Explicit height */
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
    width: 20px;
    height: 20px;
}


/* Navigation */
.nav-links {
    display: flex;
    align-items: center;
    gap: 20px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--text-primary);
}

/* User Menu */
.balance-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
    margin-right: 10px;
}

.balance-display .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
    letter-spacing: 0.05em;
}

.balance-display .amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.user-menu-container {
    position: relative;
}

.user-dropdown {
    position: absolute;
    top: 120%;
    right: 0;
    width: 260px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
}

.user-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--brand-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.user-info .username {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 6px 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s;
}

.dropdown-item:hover {
    background: rgba(var(--brand-primary-rgb), 0.1);
    /* Needs RGB var or fallback */
    background: rgba(125, 125, 125, 0.1);
    color: var(--text-primary);
}

.dropdown-item svg {
    color: inherit;
    opacity: 0.7;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .header-content {
        flex-wrap: wrap;
    }

    .header-left {
        width: 100%;
        order: 1;
        justify-content: space-between;
        gap: 15px;
    }

    .search-bar {
        width: 100%;
        max-width: none;
        order: 3;
        margin-top: 10px;
    }

    .nav-links {
        gap: 10px;
    }

    .desktop-only {
        display: none;
    }
}

/* Button Polish */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 8px;
    /* Softer corners */
    text-decoration: none;
    font-weight: 600;
    /* Bolder text */
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.95rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* Subtle depth */
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-primary {
    background: var(--brand-primary);
    color: white !important;
    border-color: var(--brand-primary);
}

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

/* Theme Toggle Icon Button */
.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--text-primary);
}

/* Mobile Visibility */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex !important;
    }

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

/* Theme Toggle inside Toggle */
#theme-toggle-menu .icon-sun-wrapper,
#theme-toggle-menu .icon-moon-wrapper {
    display: none;
}

/* Theme Toggle Visibility Logic */
html[data-theme='light'] .icon-sun-wrapper {
    display: none !important;
}

html[data-theme='light'] .icon-moon-wrapper {
    display: flex !important;
}

html[data-theme='dark'] .icon-sun-wrapper {
    display: flex !important;
}

html[data-theme='dark'] .icon-moon-wrapper {
    display: none !important;
}

/* Standard Header Toggle */
.icon-sun,
.icon-moon {
    pointer-events: none;
}

html[data-theme='light'] .icon-moon {
    display: block;
}

html[data-theme='light'] .icon-sun {
    display: none;
}

html[data-theme='dark'] .icon-sun {
    display: block;
}

html[data-theme='dark'] .icon-moon {
    display: none;
}

.card {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.text-mono {
    font-family: 'JetBrains Mono', monospace;
}

.text-green {
    color: var(--market-up);
}

.text-red {
    color: var(--market-down);
}

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

th {
    text-align: left;
    padding: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 16px 12px;
    border-bottom: 1px solid var(--border-color);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

input,
select {
    font-family: inherit;
    font-size: 0.95rem;
    padding: 12px 16px;
    /* Increased padding */
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    width: 100%;
    /* Ensure full width */
    transition: all 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

/* Modern Auth Modal */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    /* Darker dim */
    backdrop-filter: blur(8px);
    /* The "Modern" blur effect */
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-modal {
    background: var(--bg-card);
    width: 100%;
    max-width: 440px;
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    position: relative;
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }

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

.close-modal {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
    line-height: 0;
}

.close-modal:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* Form Polish */
.auth-modal h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
    text-align: center;
}

.auth-subtext {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.checkbox-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
}

.checkbox-wrapper input[type="checkbox"] {
    margin-top: 3px;
    accent-color: var(--brand-primary);
    width: 16px;
    height: 16px;
}

.checkbox-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.checkbox-text a {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 500;
}

.checkbox-text a:hover {
    text-decoration: underline;
}

/* Hide Scrollbar for clean modal look */
body.modal-open {
    overflow: hidden;
}

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

    .header-content {
        gap: 10px;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }

    .logo {
        height: auto;
        font-size: 1.5rem;
        /* Further increased to be obvious */
        order: 1;
        flex: 0 1 auto;
        margin-right: auto;
    }

    .main-nav {
        order: 2;
        flex: 0 1 auto;
        margin-left: 10px;
    }

    .nav-links {
        gap: 30px;
        /* Further increased gap */
    }

    .search-bar {
        order: 3;
        margin: 15px 0 5px 0;
        /* Add top margin for spacing */
        max-width: 100%;
        width: 100%;
        flex: 0 0 100%;
        /* ABSOLUTELY FORCE NEW LINE */
    }

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

    .mobile-only {
        display: flex !important;
    }
}