:root {
    /* Modern Palette - Premium & Clean */
    --primary: #4f46e5;
    /* Indigo 600 */
    --primary-hover: #4338ca;
    /* Indigo 700 */
    --primary-light: #e0e7ff;
    /* Indigo 100 */
    --primary-bg: #eef2ff;
    /* Indigo 50 */

    --secondary: #0ea5e9;
    /* Sky 500 */
    --accent: #8b5cf6;
    /* Violet 500 */

    --bg-body: #f8fafc;
    /* Slate 50 */
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.85);

    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
    --text-light: #94a3b8;
    /* Slate 400 */

    --border: #e2e8f0;
    /* Slate 200 */
    --border-hover: #cbd5e1;
    /* Slate 300 */

    --success: #10b981;
    /* Emerald 500 */
    --success-bg: #ecfdf5;
    /* Emerald 50 */
    --danger: #ef4444;
    /* Red 500 */
    --danger-bg: #fef2f2;
    /* Red 50 */
    --warning: #f59e0b;
    /* Amber 500 */
    --warning-bg: #fffbeb;
    /* Amber 50 */
    --info: #3b82f6;
    /* Blue 500 */
    --info-bg: #eff6ff;
    /* Blue 50 */

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);

    --radius: 12px;
    --radius-lg: 16px;
    --radius-sm: 6px;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

/* Typography & Global */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin-top: 0;
    color: var(--text-main);
    font-weight: 700;
}

h1 {
    font-size: 1.8rem;
    letter-spacing: -0.025em;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: 1.5rem;
    letter-spacing: -0.025em;
    margin-bottom: 1rem;
}

h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-hover);
}

/* Layout Structure */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    overflow: hidden;
    /* Prevent body scroll if sidebar is open */
}

/* Sidebar */
.sidebar {
    width: 200px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.03);
}

.brand {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 2rem;
    display: block;
    text-align: center;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

/* Sidebar DateTime Widget */
.sidebar-datetime {
    margin-bottom: 1.5rem;
    padding: 14px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(139, 92, 246, 0.08));
    border-radius: var(--radius);
    border: 1px solid rgba(79, 70, 229, 0.15);
}

.datetime-display {
    text-align: center;
}

.date-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.time-text {
    font-size: 1.3rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 3px;
    font-variant-numeric: tabular-nums;
}

.timezone-text {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

/* Group Label */
.nav-group-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 16px 12px 8px 12px;
    margin-top: 8px;
}

/* Navigation */
.nav-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    color: var(--text-main);
    border-radius: var(--radius);
    margin-bottom: 2px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
    transform: scaleY(0);
    transition: transform 0.2s ease;
}

.nav-link:hover {
    background: var(--primary-bg);
    color: var(--primary);
    transform: translateX(2px);
}

.nav-link.active {
    background: linear-gradient(90deg, var(--primary-bg) 0%, rgba(79, 70, 229, 0.05) 100%);
    color: var(--primary);
    font-weight: 600;
}

.nav-link.active::before {
    transform: scaleY(1);
}

.nav-link i {
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
}

/* Modern Text Colors */
.text-success {
    color: #10b981 !important;
}

/* Emerald 500 */
.text-danger {
    color: #ef4444 !important;
}

/* Red 500 */
.text-warning {
    color: #f59e0b !important;
}

/* Amber 500 */
.text-info {
    color: #3b82f6 !important;
}

/* Blue 500 */
.text-primary {
    color: var(--primary) !important;
}

.text-secondary {
    color: var(--secondary) !important;
}

.text-muted {
    color: #94a3b8 !important;
}

/* Slate 400 */
.text-dark {
    color: #1e293b !important;
}

/* Slate 800 */

.fw-bold {
    font-weight: 600 !important;
}

.fw-extra-bold {
    font-weight: 800 !important;
}

.text-nowrap {
    white-space: nowrap !important;
}

.text-uppercase {
    text-transform: uppercase !important;
}

.text-xs {
    font-size: 0.75rem !important;
}

.text-sm {
    font-size: 0.875rem !important;
}

/* Status Badges (Subtle) */
.status-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.status-lunas {
    background: #dcfce7;
    color: #166534;
}

/* Green */
.status-lebih {
    background: #dbeafe;
    color: #1e40af;
}

/* Blue */
.status-minus {
    background: #fee2e2;
    color: #991b1b;
}

/* Red */
.status-belum {
    background: #fef3c7;
    color: #92400e;
}

/* Amber */

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 200px;
    padding: 20px 15px 20px 15px;
    /* Added left padding for spacing from sidebar */
    width: calc(100% - 200px);
    background: var(--bg-body);
    min-height: 100vh;
    overflow-y: visible;
    /* Create scroll context for sticky */
}

/* Mobile Navigation Bar */
.mobile-navbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    /* Above dashboard sticky (100) and overlay (140) */
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    border-radius: var(--radius);
    transition: var(--transition);
}

.mobile-menu-btn:hover {
    background: var(--bg-body);
}

.mobile-brand {
    font-size: 1.1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 140;
    /* Below sidebar (150), above content */
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}

/* Mobile Styling */
@media (max-width: 1024px) {
    .mobile-navbar {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        width: 260px;
        /* Wide enough for grouped labels */
        top: 0;
        z-index: 150;
        /* Higher than sticky wrapper (100) */
        padding: 20px 16px;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Keep group labels visible on mobile */
    .nav-group-label {
        font-size: 0.7rem;
        padding: 14px 12px 8px 12px;
        margin-top: 8px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        color: var(--text-muted);
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 64px 10px 16px 10px;
        /* Account for mobile navbar */
    }

    /* Mobile nav-link: horizontal layout with full text */
    .nav-link {
        flex-direction: row;
        gap: 12px;
        padding: 11px 12px;
        font-size: 0.9rem;
        text-align: left;
        justify-content: flex-start;
    }

    .nav-link i {
        font-size: 1.2rem;
        width: 24px;
    }

    /* Cards on mobile */
    .card {
        padding: 14px;
        margin-bottom: 14px;
    }

    /* Stats grid responsive */
    .grid-5-scroll {
        overflow-x: auto;
        gap: 12px;
    }

    /* Brand on mobile sidebar */
    .sidebar .brand {
        font-size: 1.2rem;
        padding-bottom: 0.75rem;
        margin-bottom: 1.5rem;
        word-break: normal;
    }
}

/* Tablet specific (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .main-content {
        padding: 64px 16px 20px 16px;
        /* More padding on tablet */
    }

    .card {
        padding: 16px;
    }
}

/* Glassmorphism & Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

/* Dashboard Sticky Header */
.dashboard-sticky-wrapper {
    position: sticky;
    top: 0;
    z-index: 100;
    /* Higher z-index to stay above content */
    background: var(--bg-body);
    padding: 0 0 10px 0;
    margin: -10px 0 10px -15px;
    /* Less negative margin */
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    /* Shadow when sticky */
}

.card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

/* Colorful Card Variants */
.card-colorful {
    border: none;
    color: white;
}

.card-colorful h3 {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.card-colorful .stat-value {
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.bg-gradient-primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2), 0 2px 4px -1px rgba(79, 70, 229, 0.1);
}

.bg-gradient-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
}

.bg-gradient-danger {
    background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
    box-shadow: 0 4px 6px -1px rgba(225, 29, 72, 0.2);
}

.bg-gradient-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 4px 6px -1px rgba(217, 119, 6, 0.2);
}

.bg-gradient-info {
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
    box-shadow: 0 4px 6px -1px rgba(2, 132, 199, 0.2);
}

.stat-card {
    padding: 20px;
    /* More compact */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 110px;
}

.stat-icon {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 2.5rem;
    opacity: 0.2;
    transform: rotate(-10deg);
}

/* Modern Text Utilities */
.text-modern-heading {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    letter-spacing: -0.03em;
}

/* Compact Table Headers */
th {
    padding: 12px 16px;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    background: #f8fafc;
}

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

/* Dashboard 5-column Horizontal Scroll */
.grid-5-scroll {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    width: 100%;
}



.grid-5-scroll .card {
    min-width: 200px;
    flex: 0 0 auto;
    margin-bottom: 0;
    scroll-snap-align: start;
}

@media (max-width: 768px) {

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* Forms - Modern */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    gap: 8px;
    text-align: center;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--bg-body);
    border-color: var(--border-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
}

/* Tables - Responsive Wrapped */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-card);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    table-layout: fixed;
    /* Fixed layout for consistent column widths */
}

thead {
    background: #f8fafc;
    border-bottom: 3px solid var(--border);
}

th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #475569 !important;
    /* Slate 600 - darker for visibility */
    background: #f8fafc !important;
    border-bottom: 2px solid var(--border);
}

/* Specific column widths for alignment */
th:nth-child(1),
td:nth-child(1) {
    width: 140px;
}

/* PERIOD */
th:nth-child(2),
td:nth-child(2) {
    width: 200px;
}

/* CUSTOMER - Red */
th:nth-child(3),
td:nth-child(3) {
    width: 130px;
}

/* TAGIHAN PAGI - Yellow */
th:nth-child(4),
td:nth-child(4) {
    width: 130px;
}

/* LIMIT SALDO - Green */
th:nth-child(5),
td:nth-child(5) {
    width: 130px;
}

/* BAYAR - Blue */
th:nth-child(6),
td:nth-child(6) {
    width: 100px;
}

/* SISA - Purple */
th:nth-child(7),
td:nth-child(7) {
    width: 100px;
}

/* STATUS - Orange */
th:nth-child(8),
td:nth-child(8) {
    width: 90px;
}

/* ACTION - Black */

td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-main);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg-body);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

.badge-neutral {
    background: var(--bg-body);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Utilities */
.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    width: 600px;
    max-width: 90%;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.modal-backdrop.show .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Overlay for sidebar mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    backdrop-filter: blur(2px);
}

@media (max-width: 1024px) {
    .sidebar.active~.sidebar-overlay {
        display: block;
    }
}

/* Sales Mapping - Prefix Badges */
.prefix-badges-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.prefix-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: linear-gradient(135deg, var(--primary-bg), rgba(79, 70, 229, 0.1));
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.prefix-badge:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

/* --- RESPONSIVE SIDEBAR & LAYOUT --- */
.main-content {
    margin-left: 200px;
    padding: 20px;
    width: calc(100% - 200px);
    transition: all 0.3s ease;
}

.mobile-navbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--primary);
    padding: 10px 15px;
    color: white;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0;
}

.mobile-brand {
    font-weight: 700;
    font-size: 1.1rem;
}

/* Mobile Devices */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 10px;
    }

    .mobile-navbar {
        display: flex;
    }

    .stats-scroll-container {
        display: flex;
        overflow-x: auto;
        padding-bottom: 20px;
        gap: 15px;
    }

    .stat-card {
        min-width: 240px;
    }
}