:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --secondary: #10B981;
    --danger: #EF4444;
    --bg-color: #0F172A;
    --surface: rgba(30, 41, 59, 0.7);
    --surface-border: rgba(255, 255, 255, 0.1);
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --glass-blur: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(79, 70, 229, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.1), transparent 25%);
    background-attachment: fixed;
    overflow: hidden;
}

/* Typography & Utils */
.hidden { display: none !important; }
.gradient-text {
    background: linear-gradient(135deg, #818CF8, #C084FC);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.error-text { color: var(--danger); font-size: 0.875rem; margin-top: 0.5rem; }

/* Glassmorphism Classes */
.glass-panel {
    background: var(--surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--surface-border);
    border-radius: 16px;
}
.glass-card {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9));
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

/* Buttons & Inputs */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}
.btn-outline:hover {
    background: rgba(79, 70, 229, 0.1);
}
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; padding: 12px; }

.input-group {
    position: relative;
    margin-bottom: 16px;
}
.input-group i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}
.input-group input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border-radius: 8px;
    border: 1px solid var(--surface-border);
    background: rgba(15, 23, 42, 0.5);
    color: white;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}
.input-group input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Auth View */
#auth-view {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    animation: slideUp 0.5s ease-out;
}
.auth-header {
    text-align: center;
    margin-bottom: 30px;
}
.logo-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), #818CF8);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    margin: 0 auto 16px;
    box-shadow: 0 8px 16px rgba(79, 70, 229, 0.2);
}
.logo-icon.small {
    width: 40px;
    height: 40px;
    font-size: 18px;
    margin: 0;
}

/* Layout */
#main-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: 24px 0;
    animation: slideRight 0.4s ease-out;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    margin-bottom: 32px;
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    margin-bottom: 32px;
}
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}
.user-info p { font-weight: 600; font-size: 0.95rem; }
.badge { font-size: 0.7rem; background: rgba(79, 70, 229, 0.2); color: #818CF8; padding: 2px 6px; border-radius: 4px; }

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 12px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}
.nav-item:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}
.nav-item.active {
    color: white;
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.2), transparent);
    border-left: 3px solid var(--primary);
}
.nav-item.danger:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.sidebar-footer { padding: 0 12px; }

/* Content Area */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-left: none;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.household-badge {
    background: rgba(16, 185, 129, 0.1);
    color: var(--secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.scrollable-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
}
.scrollable-content::-webkit-scrollbar { width: 6px; }
.scrollable-content::-webkit-scrollbar-thumb { background: var(--surface-border); border-radius: 4px; }

/* Dashboard Content */
.dashboard-header {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}
.balance-card h1 { font-size: 2.5rem; margin: 12px 0 4px; }
.tasa-info { font-size: 0.85rem; color: var(--text-secondary); }

.unassigned-card {
    border-color: rgba(16, 185, 129, 0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.unassigned-card h2 { color: var(--secondary); margin: 12px 0; font-size: 1.8rem; }

.wallets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}
.wallet-card {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-top: 3px solid var(--primary);
}
.wallet-card h4 { color: var(--text-secondary); font-weight: 500; }
.wallet-balance { font-size: 1.5rem; font-weight: 600; }
.wallet-sub { font-size: 0.85rem; color: var(--text-secondary); }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.view-all { color: var(--primary); text-decoration: none; font-size: 0.9rem; }
.view-all:hover { text-decoration: underline; }

.recent-transactions { padding: 24px; }
.transaction-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--surface-border);
    transition: background 0.2s;
}
.transaction-item:hover { background: rgba(255,255,255,0.02); }
.transaction-item:last-child { border-bottom: none; }
.tx-info { display: flex; align-items: center; gap: 16px; }
.tx-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}
.tx-icon.income { color: var(--secondary); background: rgba(16, 185, 129, 0.1); }
.tx-icon.expense { color: var(--danger); background: rgba(239, 68, 68, 0.1); }
.tx-icon.loan { color: #F59E0B; background: rgba(245, 158, 11, 0.1); }
.tx-details h4 { font-weight: 500; margin-bottom: 4px; }
.tx-details p { font-size: 0.8rem; color: var(--text-secondary); }
.tx-amount { font-weight: 600; text-align: right; }
.tx-amount.positive { color: var(--secondary); }
.tx-amount.negative { color: var(--text-primary); }

/* Animations */
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideRight { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    width: 100%;
    max-width: 500px;
    animation: slideUp 0.3s ease-out;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.close-modal { background: none; border: none; color: var(--text-secondary); font-size: 1.2rem; cursor: pointer; }
.close-modal:hover { color: white; }

/* Forms */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.form-control {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--surface-border);
    background: rgba(15, 23, 42, 0.5);
    color: white;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
}
select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2394A3B8%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 12px auto;
}
select.form-control option {
    background: var(--bg-color);
}

/* Grids and Lists */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.list-container {
    margin-top: 20px;
}
.exchange-cards {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}
.exchange-cards > div {
    flex: 1;
}
.exchange-cards h3 {
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Loader */
.loader-spinner {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Responsive Mobile & PWA Design */
@media (max-width: 768px) {
    #main-layout {
        flex-direction: column;
    }
    
    /* Topbar adjustments to prevent overlapping */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px 20px;
    }
    
    .topbar-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .topbar-right .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* Transform Sidebar into Bottom Navigation */
    .sidebar {
        width: 100%;
        height: 70px;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        padding: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 1000;
        background: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(var(--glass-blur));
        border-top: 1px solid var(--surface-border);
        border-right: none;
        overflow-x: auto; /* Enable horizontal scrolling */
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        animation: none !important;
        transform: none !important;
    }

    /* Hide header and user info and household switcher in sidebar on mobile */
    .sidebar-header, .user-profile, .sidebar > div:not(.sidebar-footer) {
        display: none !important;
    }

    .sidebar-nav {
        display: flex;
        flex-direction: row;
        width: max-content;
        margin: 0;
        padding: 0;
        height: 100%;
    }

    .sidebar-footer {
        display: flex;
        flex-direction: row;
        margin: 0;
        padding: 0;
        height: 100%;
    }

    .nav-item {
        padding: 5px 12px;
        border-radius: 0;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        min-width: 70px;
        height: 100%;
        font-size: 0.7rem; /* Make text smaller for bottom nav */
        gap: 4px;
    }
    
    .nav-item i {
        font-size: 1.2rem;
        margin-right: 0;
    }
    
    .nav-item.active {
        background: transparent;
        color: var(--primary);
        border-left: none;
    }

    .nav-item.active i {
        transform: scale(1.1);
        text-shadow: 0 0 10px rgba(79, 70, 229, 0.5);
    }
    
    /* Main Content adjustments */
    .main-content {
        padding: 20px 15px;
        padding-bottom: 90px; /* Space for bottom nav */
    }

    /* Stack flex containers and grids */
    .exchange-cards {
        flex-direction: column;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .header-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    /* Modals should be full width on mobile */
    .modal-content {
        width: 95%;
        margin: 10px;
        padding: 20px;
    }

    .glass-card {
        padding: 16px;
    }
}