:root {
    --sidebar-width: 250px;
    --header-height: 70px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Fallback variables in case PHP doesn't inject them */
    --primary-color: #ff4d8d;
    --primary-glow: rgba(255, 77, 141, 0.25);
    --primary-bg-soft: rgba(255, 77, 141, 0.08);
    --bg-dark: #0b0e14;
    --card-dark: #151b23;
    --sidebar-bg: #0d1117;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --text-primary: var(--text-main);
    --text-secondary: var(--text-muted);
    --border-color: rgba(255, 255, 255, 0.08);
    --card-bg: var(--card-dark);
    
    /* Status Colors */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Plus Jakarta Sans', 'Inter', 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow-x: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    /* Support for iOS safe area */
    padding-bottom: env(safe-area-inset-bottom);
}

.filter-card {
    background: var(--card-bg);
    padding: 0.5rem 0.75rem; /* Lebih kecil lagi */
    border-radius: 10px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); /* Min-width lebih kecil */
    gap: 0.5rem;
    align-items: flex-end;
}

.filter-grid label {
    font-size: 0.65rem !important; /* Font label mikro */
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1px !important;
    text-transform: uppercase;
}

.filter-grid .form-control {
    padding: 0.3rem 0.5rem; /* Input sangat ramping */
    font-size: 0.8rem !important;
    height: 30px; /* Tinggi sangat pendek */
    border-radius: 6px;
}

.filter-grid .btn-search {
    height: 30px !important;
    padding: 0 0.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Base Styles */

@media (max-width: 768px) {
    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }
    .filter-grid .btn-search {
        grid-column: span 2;
    }
}

/* Sidebar Styles */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--text-main);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1001;
    transition: var(--transition-smooth);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    /* Safe Area Support */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header h3 {
    color: var(--primary-color);
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar-menu {
    padding: 1.5rem 0;
    list-style: none;
}

.sidebar-menu li {
    margin: 0.4rem 1rem;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 14px;
    transition: var(--transition-smooth);
    font-weight: 600;
    font-size: 0.95rem;
}

.sidebar-menu li a i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
    transition: var(--transition-smooth);
}

.sidebar-menu li a:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
    transform: translateX(4px);
}

.sidebar-menu li a.active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-glow));
    color: #ffffff;
    box-shadow: 0 8px 20px var(--primary-glow);
}

.sidebar-menu li a.active i {
    color: #ffffff;
}

/* Main Content Styles */
.main-content {
    margin-left: var(--sidebar-width);
    padding: calc(var(--header-height) + 30px) 30px 30px 30px;
    transition: var(--transition-smooth);
    min-height: 100vh;
    /* Safe Area Support for Horizontal View */
    padding-left: calc(30px + env(safe-area-inset-left));
    padding-right: calc(30px + env(safe-area-inset-right));
    padding-top: calc(var(--header-height) + env(safe-area-inset-top) + 30px);
}

/* Navbar Styles */
.navbar {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: var(--header-height);
    background: rgba(21, 27, 35, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 1000;
    transition: var(--transition-smooth);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    /* Safe Area Padding */
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-height) + env(safe-area-inset-top));
    padding-left: calc(2rem + env(safe-area-inset-left));
    padding-right: calc(2rem + env(safe-area-inset-right));
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-info .username {
    font-weight: 600;
    color: var(--text-primary);
}

.user-info .role-badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background-color: var(--primary-bg-soft);
    color: var(--primary-color);
    text-transform: uppercase;
    font-weight: 700;
}

/* User Management Grid */
.user-management-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 2rem;
}

@media (max-width: 992px) {
    .user-management-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* Global Container & Responsive Fixes */
.container-fluid {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
    overflow-x: hidden; /* Prevent horizontal scroll on body */
}

/* Ensure cards and tables don't overflow */
.card {
    background: var(--card-dark);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition-smooth);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    word-wrap: break-word;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.01);
}

.card-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.3px;
}

.card-body {
    padding: 1.5rem;
}

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    position: relative;
}

.table-responsive table {
    width: 100%;
    min-width: 600px; /* Base minimum width for smaller tables */
}

.table-responsive table.table-wide {
    min-width: 900px; /* Wider for tables with many columns */
}

@media (max-width: 768px) {
    .table-responsive table.table-wide {
        min-width: 1100px; /* Ensure wide tables are scrollable and readable on mobile */
    }
}

@media (max-width: 768px) {
    .container-fluid {
        padding: 1rem 0.75rem;
    }
    
    .main-content {
        padding: calc(var(--header-height) + 20px) 10px 20px 10px;
    }
}

/* Form Styles */
.form-group { margin-bottom: 1.5rem; }
.form-group label { 
    display: block; 
    margin-bottom: 0.6rem; 
    font-weight: 600; 
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.8rem 1.2rem;
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    transition: var(--transition-smooth);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

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

/* Buttons & Badges */
.btn {
    padding: 0.8rem 1.5rem;
    border-radius: 14px;
    font-weight: 700;
    transition: var(--transition-smooth);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary-color);
    color: #ffffff !important;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
    filter: brightness(1.1);
}

.badge {
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-lunas { 
    background-color: rgba(16, 185, 129, 0.15); 
    color: #10b981; 
}
.badge-dp { 
    background-color: rgba(245, 158, 11, 0.15); 
    color: #f59e0b; 
}
.badge-belum { 
    background-color: rgba(239, 68, 68, 0.15); 
    color: #ef4444; 
}

/* Table Styles */
.table-responsive .table thead tr {
    background: var(--primary-color) !important; /* Memaksa warna tema pada seluruh baris judul */
}

.table-responsive .table thead th {
    text-align: left;
    padding: 18px 15px;
    color: #ffffff !important; /* Teks putih bersih agar kontras tinggi di atas warna tema */
    font-weight: 800;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    border: none !important; /* Hilangkan border bawah agar tampilan lebih modern dan menyatu */
}

.table-responsive .table thead th i {
    color: #ffffff !important; /* Ikon juga menjadi putih */
    margin-right: 5px;
}

.table td {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    font-size: 0.95rem;
}

.table tr:hover td {
    background: rgba(255, 255, 255, 0.01);
}
.stats-grid-mobile {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
}

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

.stats-grid-row-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.stats-grid-row-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.micro-card {
    background: var(--card-dark);
    padding: 12px 5px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.micro-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex; 
    align-items: center;
    justify-content: center;
    margin: 0 auto 6px;
    font-size: 0.85rem;
    background: var(--primary-bg-soft);
    color: var(--primary-color);
}

.micro-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.micro-value {
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-main);
}

.stats-card-mini {
    padding: 12px 10px;
    border-radius: 16px;
    color: white;
    text-align: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.stats-label-mini {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-bottom: 5px;
    font-weight: 600;
}

.stats-value-mini {
    font-size: 0.95rem;
    font-weight: 800;
}

.stats-card-mini.cash { background: linear-gradient(135deg, #10b981, #059669); }
.stats-card-mini.bank { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stats-card-mini.luar { background: linear-gradient(135deg, #64748b, #475569); }

.stats-card.total-combined { 
    background: linear-gradient(135deg, var(--primary-color), var(--primary-glow));
    box-shadow: 0 10px 30px var(--primary-glow);
}
.stats-card.total-all { background: linear-gradient(135deg, #1e293b, #0f172a); }

.keuangan-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 1.5rem;
}

.tab-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    background: var(--card-dark);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    color: var(--text-muted);
    text-decoration: none;
    transition: var(--transition-smooth);
    gap: 6px;
}

.tab-link i {
    font-size: 1.2rem;
}

.tab-link span {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-link.active {
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
    box-shadow: 0 8px 20px var(--primary-glow);
}

.tab-link.active.cash { background: linear-gradient(135deg, #10b981, #059669); border-color: #10b981; box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3); }
.tab-link.active.bank { background: linear-gradient(135deg, #3b82f6, #2563eb); border-color: #3b82f6; box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3); }
.tab-link.active.luar { background: linear-gradient(135deg, #64748b, #475569); border-color: #64748b; box-shadow: 0 8px 20px rgba(100, 116, 139, 0.3); }

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stats-card {
    padding: 1.5rem;
    border-radius: 20px;
    color: white;
    position: relative;
    overflow: hidden;
    transition: var(--transition-smooth);
    border: none;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.stats-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}

.stats-card.cash { background: linear-gradient(135deg, #10b981, #059669); }
.stats-card.bank { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stats-card.luar { background: linear-gradient(135deg, #64748b, #475569); }
.stats-card.total { 
    background: linear-gradient(135deg, var(--primary-color), var(--primary-glow));
    box-shadow: 0 10px 25px var(--primary-glow);
}

.stats-icon {
    font-size: 2.5rem;
    opacity: 0.2;
    position: absolute;
    right: 20px;
    bottom: 20px;
}

.stats-label { font-size: 0.95rem; font-weight: 600; opacity: 0.9; }
.stats-value { font-size: 2rem; font-weight: 800; margin-top: 0.5rem; letter-spacing: -0.5px; }

/* Table Styles */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
}

/* Custom Scrollbar for Desktop, hidden for Mobile if desired */
.table-responsive::-webkit-scrollbar {
    height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}
.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

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

.table th {
    text-align: left;
    padding: 12px 15px;
    background-color: var(--card-bg);
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

.table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-lunas { background-color: #d4edda; color: #155724; }
.badge-dp { background-color: #fff3e0; color: #ef6c00; }
.badge-belum { background-color: #f8d7da; color: #721c24; }

/* Form Styles */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: var(--text-secondary); }
.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--card-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

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

/* Mobile & iOS Optimizations */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }
    
    body {
        font-size: 14px;
        overflow-x: hidden; /* Extra precaution */
    }

    /* Prevent horizontal scroll from elements */
    * {
        max-width: 100vw;
    }

    .sidebar {
        left: -280px;
        width: 280px;
        background: var(--sidebar-bg);
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-left: 0;
        padding: calc(var(--header-height) + 20px) 10px 20px 10px;
        padding-top: calc(var(--header-height) + env(safe-area-inset-top) + 20px);
        width: 100%;
        overflow-x: hidden;
    }

    .navbar {
        left: 0 !important;
        padding: 0 1rem;
        width: 100% !important;
    }

    /* Responsive Card Header */
    .responsive-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
        padding: 1.2rem !important;
    }
    
    .header-subtitle {
        margin-left: 0 !important;
        margin-top: 8px !important;
    }

    .btn-responsive {
        width: 100%;
        justify-content: center;
    }

    /* Responsive Table Footer */
    .table-footer-responsive {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1.2rem !important;
    }

    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .stats-grid-row-4, .stats-grid-row-3 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    .stats-grid-row-2 {
        grid-template-columns: 1fr !important;
    }
    .keuangan-tabs {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .form-control {
        font-size: 16px !important; /* Prevent auto-zoom on iOS */
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .table th, .table td {
        padding: 10px 8px !important;
        font-size: 0.75rem !important;
    }
    
    .card-body, .card-header {
        padding: 1rem !important;
    }
    
    .stats-value {
        font-size: 1.6rem !important;
    }

    /* Welcome Card Responsive */
    .welcome-card-body {
        padding: 1.5rem !important;
    }
    .welcome-title {
        font-size: 1.4rem !important;
    }
    .welcome-subtitle {
        font-size: 0.9rem !important;
    }
    .welcome-stats {
        margin-top: 1.5rem !important;
        flex-direction: column;
    }
    .welcome-stat-item {
        padding: 1rem !important;
    }
    .welcome-stat-item span {
        font-size: 1.4rem !important;
    }
    .welcome-bg-icon {
        font-size: 8rem !important;
    }

    /* Keuangan Main Stats Responsive */
    .stats-card-main {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }
    .stats-label-main {
        font-size: 0.8rem !important;
        letter-spacing: 1px !important;
    }
    .stats-value-main {
        font-size: 1.8rem !important;
        margin-top: 0.5rem !important;
    }

    /* Fix table padding for specific layouts */
    .table-responsive .table {
        padding: 0 !important;
    }
}

.btn-danger { background-color: #ef4444; color: #ffffff !important; }
.btn-success { background-color: #10b981; color: #ffffff !important; }
.btn-warning { background-color: #f59e0b; color: #ffffff !important; }

/* Calendar Ultra Compact for iPhone */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    overflow: hidden;
    background: var(--card-dark);
}

.calendar-day-head {
    padding: 12px;
    text-align: center;
    background: rgba(255, 255, 255, 0.02);
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.calendar-day {
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 100px;
    transition: var(--transition-smooth);
}

.calendar-day:hover {
    background: rgba(255, 255, 255, 0.02);
}

.calendar-day.today {
    background: var(--primary-bg-soft);
}

.day-number {
    text-align: right;
    font-weight: 800;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.event-item {
    display: block;
    text-decoration: none;
    font-size: 0.7rem;
    padding: 4px 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    font-weight: 700;
}

.event-item.lunas { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.event-item.dp { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.event-item.belum { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
