@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
    --bg-dark: #090d16;
    --bg-card: rgba(17, 25, 40, 0.65);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.15);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-glow: rgba(245, 158, 11, 0.15);
    --danger: #ef4444;
    --danger-glow: rgba(239, 68, 68, 0.15);
    --accent: #06b6d4;
    --sidebar-width: 260px;
    --radius-lg: 16px;
    --radius-md: 10px;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2.5rem;
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.95rem;
}

.sidebar-item a:hover, .sidebar-item.active a {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 0 0 1px var(--border-color);
}

.sidebar-item.active a {
    background: var(--primary-glow);
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
}

.sidebar-user {
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.15rem;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 0.6rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.3s ease;
    width: 100%;
}

.btn-logout:hover {
    background: var(--danger);
    color: var(--text-primary);
}

/* Main Content Area */
.main-content {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    padding: 2.5rem;
    min-width: 0; /* Prevents flex children from stretching */
}

/* Heading Typography */
h1, h2, h3, h4, h5 {
    font-family: var(--font-heading);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.page-title {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 0.35rem;
}

/* Glassmorphism Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px -5px rgba(99, 102, 241, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

/* Dashboard Grid & Key Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.metric-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
}

.metric-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
}

.metric-value {
    font-size: 1.85rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-primary);
}

.metric-trend {
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.trend-up { color: var(--success); }
.trend-down { color: var(--danger); }

/* Layout Grids */
.layout-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

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

/* Beautiful Custom Tables */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.custom-table th {
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
}

.custom-table td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    vertical-align: middle;
}

.custom-table tbody tr {
    transition: background-color 0.2s ease;
}

.custom-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.custom-table tbody tr:last-child td {
    border-bottom: none;
}

/* Glowing Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-success {
    background: var(--success-glow);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-danger {
    background: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-warning {
    background: var(--warning-glow);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-primary {
    background: var(--primary-glow);
    color: var(--primary);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

/* Custom Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.btn-danger {
    background: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

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

/* Sleek Forms styling */
.form-group {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-control {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: all 0.3s ease;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background: rgba(255, 255, 255, 0.05);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
}

.form-select option {
    background-color: var(--bg-dark);
    color: var(--text-primary);
}

/* Dues alerts */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-success {
    background: var(--success-glow);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert-danger {
    background: var(--danger-glow);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Savings Matrix Specific styling */
.matrix-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.matrix-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.matrix-table th, .matrix-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    text-align: center;
    min-width: 120px;
}

.matrix-table th {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
}

.matrix-table td.member-name-cell {
    position: sticky;
    left: 0;
    background: #0d1527;
    text-align: left;
    min-width: 180px;
    z-index: 5;
    font-weight: 600;
    border-right: 2px solid var(--border-color);
}

.matrix-cell-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.matrix-cell-clickable:hover {
    background: rgba(255, 255, 255, 0.05);
}

.matrix-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}

.matrix-status-dot.paid { background-color: var(--success); }
.matrix-status-dot.unpaid { background-color: var(--danger); }

/* Login Page Layout */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: var(--bg-dark);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
}

.login-logo {
    text-align: center;
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2rem;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 99;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.25rem;
    align-items: center;
    justify-content: space-between;
    z-index: 98;
}

.mobile-toggle-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background-color 0.2s;
}

.mobile-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.mobile-brand {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

@media (max-width: 768px) {
    /* Show mobile header */
    .mobile-header {
        display: flex !important;
    }

    /* Off-canvas sidebar */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 100;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Shift main content below mobile header */
    .main-content {
        margin-left: 0 !important;
        margin-top: 60px !important;
        padding: 1.5rem 1rem !important;
    }

    /* Stack page headers vertically */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .page-title {
        font-size: 1.65rem;
    }

    /* Stack form rows/groups */
    .form-row {
        flex-direction: column;
        gap: 1rem;
    }

    /* General Layout Adjustments */
    .layout-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Scroll hints for wide elements */
    .table-wrapper::after,
    .matrix-container::after {
        content: '← Swipe horizontally to scroll table →';
        display: block;
        text-align: center;
        font-size: 0.7rem;
        color: var(--text-secondary);
        margin-top: 0.55rem;
        font-style: italic;
    }
}
