:root {
    /* Core Colors */
    --bg-color: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;

    /* Brand Colors */
    --primary-color: #8223d2;
    --primary-hover: #9c4be6;
    --secondary-color: #38bdf8;

    /* Functional Colors */
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --success-color: #22c55e;

    /* Glassmorphism Variables */
    --glass-bg: rgba(30, 41, 59, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glass-blur: 16px;

    --input-bg: rgba(15, 23, 42, 0.6);
    --radius: 16px;

    --font-family: 'Inter', sans-serif;

    /* Animation Speeds */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    padding: 2rem 1rem;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* --- Ambient Background Orbs --- */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    opacity: 0.6;
    animation: floatOrb 10s infinite alternate cubic-bezier(0.45, 0.05, 0.55, 0.95);
}

body::before {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, var(--primary-color), transparent 70%);
}

body::after {
    bottom: -10%;
    right: -10%;
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, var(--secondary-color), transparent 70%);
    animation-delay: -5s;
}

@keyframes floatOrb {
    0% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -50px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }

    100% {
        transform: translate(0, 0) scale(1);
    }
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

/* --- Header --- */
header {
    text-align: center;
    margin-bottom: 2.5rem;
    animation: fadeInDown 0.6s ease-out;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
    background: linear-gradient(135deg, #a855f7, #38bdf8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
    text-shadow: 0 4px 12px rgba(130, 35, 210, 0.3);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.9;
}

/* --- Glass Cards --- */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: fadeInUp 0.5s ease-out backwards;
}

/* Stagger animations for cards */
#add-expense {
    animation-delay: 0.1s;
}

#dashboard {
    animation-delay: 0.2s;
}

#history {
    animation-delay: 0.3s;
}

#danger-zone {
    animation-delay: 0.4s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.15);
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
}

.card-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.card-body {
    padding: 1.5rem;
}

/* --- Forms & Inputs --- */
.input-group,
.form-row {
    display: flex;
    gap: 1rem;
}

.form-group {
    margin-bottom: 1.25rem;
    flex: 1;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
select {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background-color: var(--input-bg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: all var(--transition-fast);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 3px rgba(130, 35, 210, 0.25);
}

/* Custom Checkbox/Radio Polish */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.checkbox-label,
.radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.checkbox-label:hover,
.radio-label:hover {
    color: var(--text-primary);
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary-color);
    width: 1.1em;
    height: 1.1em;
    cursor: pointer;
}

/* --- Buttons --- */
.btn {
    padding: 0.85rem 1.5rem;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.01em;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    box-shadow: 0 4px 12px rgba(130, 35, 210, 0.4);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(130, 35, 210, 0.6);
    filter: brightness(1.1);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-text {
    background: none;
    padding: 0.5rem;
    color: var(--secondary-color);
}

.btn-text:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
}

.full-width {
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 8px;
}

.btn-discord {
    background: #5865F2;
    color: white;
    text-decoration: none;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.4);
    transition: all var(--transition-fast);
}

.btn-discord:hover {
    background: #4752c4;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(88, 101, 242, 0.6);
}

.btn-discord svg {
    flex-shrink: 0;
}

/* --- Lists & Items --- */
.list-group {
    list-style: none;
    margin-top: 0.5rem;
}

.list-group li {
    padding: 1rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
    background: rgba(255, 255, 255, 0.02);
}

.list-group li:first-child {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.list-group li:last-child {
    border-bottom: none;
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.list-group li:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* User Avatars */
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: white;
    margin-right: 14px;
    flex-shrink: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Settlement Items */
.settlement-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.settlement-item {
    padding: 1rem;
    background: rgba(130, 35, 210, 0.15);
    border: 1px solid rgba(130, 35, 210, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.money {
    font-weight: 700;
    color: #a855f7;
    /* Lighter purple for text */
    text-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
}

/* --- Modals (Glass Style) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    /* Fixed: Cover Mobile Nav */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: rgba(30, 41, 59, 0.85);
    /* Darker/Opaque for readability */
    border: 1px solid rgba(255, 255, 255, 0.15);
    margin: 5% auto;
    width: 90%;
    max-width: 550px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    background: linear-gradient(to right, rgba(255, 255, 255, 0.05), transparent);
    padding: 1.25rem 1.5rem;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.close-modal {
    color: var(--text-secondary);
    font-size: 1.8rem;
    font-weight: 300;
    line-height: 1;
    transition: color 0.2s;
    /* Alignment fix */
    float: right;
    margin-left: 10px;
}

.close-modal:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

/* Breakdown & Payments */
.breakdown-section {
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.history-item-payment {
    border-left: 3px solid var(--success-color);
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.1), transparent);
}

/* --- Mobile Navigation (Glass Dock) --- */
.bottom-nav {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;

    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);

    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;

    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    z-index: 1000;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    padding: 6px 12px;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: visible;
}

.nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
    transition: stroke 0.3s;
}

.nav-item.active {
    color: white;
    transform: translateY(-5px);
}

.nav-item.active svg {
    stroke: var(--primary-color);
    filter: drop-shadow(0 0 8px var(--primary-color));
}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--primary-color);
}

/* --- Animations --- */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(50px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- Media Queries --- */

/* Mobile Enhancements */
@media (max-width: 1023px) {
    body {
        padding-bottom: 110px;
        /* Space for floating dock */
    }

    main section {
        display: none;
        animation: fadeIn 0.4s ease-out;
    }

    main section.active-section {
        display: block;
    }
}

/* Desktop Enhancements */
@media (min-width: 1024px) {
    .app-container {
        max-width: 1200px;
    }

    .bottom-nav {
        display: none;
    }

    main {
        display: grid;
        grid-template-columns: 360px 1fr;
        gap: 2rem;
        align-items: start;
    }

    /* Reset individual section displays */
    main section {
        display: block !important;
        height: auto;
        margin-bottom: 0;
        /* Handled by gap/flex */
    }

    /* Sidebar */
    #add-expense {
        position: sticky;
        top: 2rem;
        grid-column: 1 / 2;
    }

    /* Right Column Container */
    .right-column {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        grid-column: 2 / 3;
    }

    /* Enhance Desktop Scrollbar */
    ::-webkit-scrollbar {
        width: 8px;
    }

    ::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1);
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
        border-radius: 4px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.3);
    }
}

/* Utilities */
.text-danger {
    color: #f87171;
}

.text-warning {
    color: #fbbf24;
}

.empty-state {
    opacity: 0.6;
    font-style: italic;
    text-align: center;
    margin-top: 1rem;
}

/* Auth visibility toggle (class-based to avoid inline style conflicts with mobile CSS) */
.auth-hidden {
    display: none !important;
}

.delete-btn:hover,
.delete-expense-btn:hover {
    color: var(--danger-color);
    transform: scale(1.1);
}

/* Specific Button Overrides */
#reset-data {
    background: linear-gradient(135deg, var(--danger-color), #b91c1c) !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* Modal Buttons: Cancel favored */
#confirm-cancel-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover)) !important;
    box-shadow: 0 4px 12px rgba(130, 35, 210, 0.3);
    color: white;
    border: none;
    font-weight: 700;
}

#confirm-yes-btn {
    background: transparent !important;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
}

#confirm-yes-btn:hover {
    background: rgba(239, 68, 68, 0.1) !important;
}