:root {
    /* Apple-like Dark Theme Colors */
    --bg-app: #1e1e1e;
    /* Main background */
    --bg-sidebar: #252526;
    /* Sidebar background (slightly lighter/darker depending on preference, sticking to VSCode/Apple dark convention) */
    --bg-card: #333333;
    /* Card background */
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --accent-color: #007aff;
    /* Apple Blue */
    --border-color: #444444;
    --hover-bg: rgba(255, 255, 255, 0.1);

    /* Spacing & Radius */
    --sidebar-width: 250px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --padding-md: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle in content */
    display: flex;
    user-select: none;
    /* App-like feel */
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: var(--padding-md);
}

.brand {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 30px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-item:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--accent-color);
    color: white;
}

/* Main Content */
#content {
    flex: 1;
    overflow-y: auto;
    /* Scrollable content */
    padding: var(--padding-md);
    background-color: var(--bg-app);
}

header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

.trade-filters {
    width: 100%;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 10px;
}

/* Utilities / Components */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 15px;
    border: 1px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
}

.card.owned {
    border-color: #4cd964;
    background: rgba(76, 217, 100, 0.05);
}

.owned-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #4cd964;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.search-bar {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    width: 300px;
    outline: none;
}

.search-bar:focus {
    border-color: var(--accent-color);
}

/* Views visibility */
.view {
    display: none;
}

.view.active {
    display: block;
}

/* Auth Styles */
.auth-container {
    max-width: 400px;
    margin: 50px auto;
    background-color: var(--bg-card);
    padding: 30px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.auth-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
}

.auth-tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.auth-form {
    display: none;
    flex-direction: column;
    gap: 15px;
}

.auth-form.active {
    display: flex;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    text-align: left;
}

.form-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-group input {
    padding: 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent-color);
}

.btn-primary {
    padding: 12px;
    border-radius: var(--radius-sm);
    background-color: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
    transition: opacity 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.error-message {
    color: #ff4d4d;
    font-size: 0.9rem;
    margin-top: 10px;
    display: none;
}

/* Toast Notification - Small Overlay */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

.toast {
    background: rgba(40, 40, 40, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
    color: #f0f0f0;
    font-size: 0.8rem;
    backdrop-filter: blur(8px);
    animation: slideIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    pointer-events: auto;
    font-weight: 500;
}

.toast.fade-out {
    animation: fadeOut 0.2s ease forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: scale(0.95);
    }
}

/* Quantity Input Styles */
.quantity-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    padding: 2px;
    margin-right: 8px;
}

.quantity-input {
    width: 24px;
    background: transparent;
    border: none;
    color: white;
    text-align: center;
    font-size: 0.8rem;
    padding: 0;
    -moz-appearance: textfield;
}

.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-qty {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    transition: all 0.2s;
}


.btn-delete {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(255, 59, 48, 0.3);
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: 5px;
}


.btn-wishlist {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-right: 5px;
}

.btn-wishlist:hover {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
}

.btn-wishlist.active {
    color: #ff3b30;
}

.btn-wishlist svg {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    transition: fill 0.2s;
}


/* Market Controls */
.market-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    display: inline-block;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #444;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.price-input-group {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    flex: 1;
    min-width: 0;
    /* Flexbox fix */
}

.price-symbol {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-right: 4px;
}

.price-input {
    background: transparent;
    border: none;
    color: white;
    width: 100%;
    padding: 6px 0;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
}


/* Trade Center */
.trade-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    border: 1px solid var(--border-color);
}

.trade-card.match {
    border: 1px solid #4cd964;
    background: rgba(76, 217, 100, 0.05);
}

.trade-info {
    flex: 1;
}

.seller-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.match-badge {
    background: #4cd964;
    color: black;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 5px;
}

.trade-price {
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
}


/* Chat System */
.chat-layout {
    display: flex;
    height: calc(100vh - 140px);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.chat-sidebar {
    width: 250px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
}

.chat-conversation {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.chat-conversation:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-conversation.active {
    background: var(--accent-color);
}

.chat-conversation h4 {
    margin: 0;
    font-size: 0.95rem;
}

.chat-conversation p {
    margin: 5px 0 0 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Back button - hidden on desktop */
.btn-back-chat {
    display: none;
    background: transparent;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
}

.btn-back-chat:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.message.sent {
    align-self: flex-end;
    background: var(--accent-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: #3a3a3c;
    color: white;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.chat-input-area input {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    color: white;
    outline: none;
}


.notification-dot {
    position: absolute;
    top: 10px;
    right: 15px;
    background-color: #ff3b30;
    border-radius: 10px;
    box-shadow: 0 0 5px #ff3b30;
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    min-width: 18px;
    text-align: center;
    font-weight: bold;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-card);
    margin: 10% auto;
    padding: 25px;
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    position: relative;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-btn {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover,
.close-btn:focus {
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
}

.star-rating {
    display: flex;
    gap: 5px;
    font-size: 1.5rem;
    color: #444;
    cursor: pointer;
    margin-bottom: 10px;
}

.star-rating span.filled {
    color: #ffd700;
}

/* Stats Modal Styles */
.stat-bar-container {
    width: 100%;
}

.progress-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease-out;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        background-image: url('icons/logo.png');
        background-repeat: no-repeat;
        background-position: center 40%;
        background-size: 70%;
        background-attachment: fixed;
    }

    /* Make content semi-transparent so logo shows through */
    #content {
        background-color: rgba(30, 30, 30, 0.85);
    }

    .view {
        background-color: transparent;
    }

    .card {
        background-color: rgba(51, 51, 51, 0.9);
    }

    /* Semi-transparent accordions for parts categories */
    details {
        background-color: rgba(30, 30, 30, 0.8) !important;
    }

    details summary {
        background-color: rgba(51, 51, 51, 0.85) !important;
    }

    details>div {
        background-color: rgba(0, 0, 0, 0.3) !important;
    }

    /* Stack trade filters vertically on mobile */
    .trade-filters {
        grid-template-columns: 1fr;
    }

    #sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 70px;
        /* Fixed height for bottom bar */
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border-color);
        padding: 5px;
        z-index: 1000;
        justify-content: space-around;
        background-color: rgba(30, 30, 30, 0.98);
        backdrop-filter: blur(10px);
    }

    .brand {
        display: none;
        /* Hide brand name in bottom bar to save space */
    }

    .nav-links {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        gap: 0;
    }

    .nav-item {
        flex-direction: column;
        padding: 5px;
        font-size: 0.7rem;
        /* Smaller text */
        gap: 2px;
        text-align: center;
        border-radius: 8px;
        flex: 1;
        justify-content: center;
    }

    /* Main Content bottom padding */
    #content {
        padding-bottom: 90px;
    }

    /* Card Grid - 2 columns on mobile */
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* Card adjustments */
    .card {
        padding: 10px;
    }

    .card h3 {
        font-size: 0.9rem;
    }

    /* Sidebar User Profile Text */
    #sidebar-user {
        display: none;
    }

    /* Deck Builder Layout */
    .deck-layout {
        grid-template-columns: 1fr !important;
        height: auto !important;
        /* Allow scroll */
        overflow-y: visible !important;
    }

    /* Deck Builder Header - Stack controls on mobile */
    #deck-builder header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    #deck-builder header>div {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    #deck-builder header h1 {
        margin-bottom: 5px;
    }

    #deck-builder #deck-select {
        width: 100% !important;
        max-width: none;
    }

    /* Deck Builder #deck-name */
    #deck-builder #deck-name {
        flex: 1;
        min-width: 120px;
    }

    /* Chat Mobile Layout - Strict Layering */
    .chat-layout {
        position: relative;
        /* Container for absolute children */
        height: calc(100vh - 140px);
        overflow: hidden;
        display: block;
        /* Ensure block layout for positioning */
    }

    /* Sidebar is ALWAYS visible as the base layer */
    .chat-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        z-index: 10;
        /* Base layer */
        background: var(--card-bg) !important;
        display: flex !important;
        flex-direction: column;
        border-right: none;
    }

    /* Chat window is hidden by default, sits ON TOP when active */
    .chat-window {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        z-index: 20;
        /* Upper layer */
        background: var(--bg-app) !important;
        display: none !important;
        /* Hidden by default */
        flex-direction: column;
        transform: translateX(100%);
        /* Slide out to right initially as fail-safe */
        transition: transform 0.3s ease-in-out;
    }

    /* When active, slide in and show */
    .chat-window.mobile-active {
        display: flex !important;
        transform: translateX(0);
        /* Slide in */
    }

    .btn-back-chat {
        display: flex !important;
        margin-right: 15px;
    }

    /* Stats Modal fit screen */
    .modal-content {
        width: 95%;
        margin: 10px auto;
        padding: 15px;
        max-height: 90vh;
        overflow-y: auto;
    }
}