:root {
    --primary-purple: #6f42c1;
    --primary-blue: #0d6efd;
    --light-blue: #e7f1ff;
    --bg-light: #f4f7fe;
    --white: #ffffff;
    --text-main: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --transition: all 0.3s ease;

    /* Typography Scale */
    --fs-xs: 0.75rem;     /* 12px */
    --fs-sm: 0.875rem;    /* 14px */
    --fs-base: 1rem;      /* 16px */
    --fs-md: 1.125rem;    /* 18px */
    --fs-lg: 1.25rem;     /* 20px */
    --fs-xl: 1.5rem;      /* 24px */
    --fs-2xl: 1.875rem;   /* 30px */
    --fs-3xl: 2.25rem;    /* 36px */
}

html {
    font-size: 16px;
}

body {
    background-color: var(--bg-light);
    color: var(--text-main);
    font-family: 'Sarabun', sans-serif;
    font-size: var(--fs-base);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Fluid Typography for Headings */
h1 { font-size: clamp(var(--fs-2xl), 5vw, var(--fs-3xl)); font-weight: 700; }
h2 { font-size: clamp(var(--fs-xl), 4vw, var(--fs-2xl)); font-weight: 700; }
h3 { font-size: clamp(var(--fs-lg), 3vw, var(--fs-xl)); font-weight: 700; }
h4 { font-size: clamp(var(--fs-md), 2.5vw, var(--fs-lg)); font-weight: 600; }
h5 { font-size: var(--fs-md); font-weight: 600; }
h6 { font-size: var(--fs-sm); font-weight: 600; }

/* Layout Structure */
#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
}

/* Sidebar Styling */
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-purple) 0%, #5a32a3 100%);
    color: var(--white);
    transition: var(--transition);
    min-height: 100vh;
    box-shadow: 4px 0 10px rgba(0,0,0,0.05);
    z-index: 1000;
}

#sidebar .sidebar-header {
    padding: 1.5rem;
    background: rgba(0,0,0,0.1);
    text-align: center;
}

#sidebar ul.components {
    padding: 1.25rem 0;
}

#sidebar ul p {
    padding: 0.625rem 1.5rem;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 0.3125rem;
}

#sidebar ul li a {
    padding: 0.75rem 1.5rem;
    font-size: var(--fs-base);
    display: block;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: var(--transition);
}

#sidebar ul li a:hover, #sidebar ul li.active > a {
    color: var(--white);
    background: rgba(255,255,255,0.1);
    border-left: 4px solid var(--white);
}

#sidebar ul li a i {
    margin-right: 0.625rem;
    width: 1.25rem;
}

/* Main Content Area */
#content {
    width: 100%;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.container-fluid {
    width: 100%;
    padding: 0 1.5rem 1.5rem 1.5rem;
    flex: 1;
}

.top-navbar {
    background: var(--white);
    padding: 0.9375rem 1.875rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    margin-bottom: 1.875rem;
}

/* UI Components */
.card {
    border: none;
    border-radius: 1rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-5px);
}

.card-header h5 {
    font-size: var(--fs-md);
    margin-bottom: 0;
}

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 0.625rem;
    font-weight: 500;
    font-size: var(--fs-base);
    transition: var(--transition);
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: var(--fs-sm);
}

.btn-primary {
    background-color: var(--primary-blue);
    border: none;
}

.btn-purple {
    background-color: var(--primary-purple);
    color: white;
    border: none;
}
.btn-purple:hover { color: white; background-color: #5a32a3; }

.btn-blue {
    background-color: var(--primary-blue);
    color: white;
    border: none;
}
.btn-blue:hover { color: white; background-color: #0a58ca; }

/* Dashboard Summary Cards */
.stat-card {
    padding: 1.5rem;
    border-radius: 1rem;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    position: relative;
    height: 100%;
}

.stat-card h6 {
    font-size: var(--fs-sm);
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.stat-card h3 {
    font-size: var(--fs-xl);
    margin-bottom: 0;
}

.stat-card i {
    font-size: 3rem;
    opacity: 0.3;
    position: absolute;
    right: -0.625rem;
    bottom: -0.625rem;
}

.bg-purple { background: linear-gradient(45deg, #6f42c1, #a06ee1); }
.bg-blue { background: linear-gradient(45deg, #0d6efd, #4d94ff); }
.bg-info-custom { background: linear-gradient(45deg, #0dcaf0, #56e2f9); }

/* Helper Classes */
.bg-purple-light { background-color: rgba(111, 66, 193, 0.1); }
.bg-blue-light { background-color: rgba(13, 110, 253, 0.1); }
.bg-success-light { background-color: rgba(25, 135, 84, 0.1); }
.bg-warning-light { background-color: rgba(255, 193, 7, 0.1); }
.bg-danger-light { background-color: rgba(220, 53, 69, 0.1); }

.text-purple { color: var(--primary-purple) !important; }
.text-blue { color: var(--primary-blue) !important; }
.text-orange { color: #fd7e14 !important; }

.bg-orange { background-color: #fd7e14 !important; }
.bg-orange-light { background-color: rgba(253, 126, 20, 0.1) !important; }

.small, small { font-size: var(--fs-sm); }

/* Responsive Adjustments */
@media (max-width: 992px) {
    html { font-size: 15px; }
}

@media (max-width: 768px) {
    html { font-size: 14px; }
    
    #sidebar {
        margin-left: calc(var(--sidebar-width) * -1);
        position: fixed;
        height: 100vh;
        z-index: 1050;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    #sidebar.active {
        margin-left: 0;
        box-shadow: 10px 0 30px rgba(0,0,0,0.2);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.4);
        z-index: 1045;
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active {
        display: block;
    }

    #content {
        padding: 0;
        width: 100%;
    }
    
    .top-navbar {
        padding: 0.625rem 0.9375rem;
        position: sticky;
        top: 0;
        z-index: 1030;
    }

    .container-fluid {
        padding: 0.625rem 0.9375rem 5rem 0.9375rem;
    }

    .card {
        border-radius: 0.75rem !important;
        margin-bottom: 0.9375rem;
    }

    .btn {
        padding: 0.75rem 1.25rem;
        font-weight: 600;
    }

    /* Table Mobile Stack */
    .table-mobile-stack thead {
        display: none;
    }
    .table-mobile-stack tr {
        display: block;
        background: #fff;
        margin-bottom: 0.9375rem;
        border-radius: 0.75rem;
        padding: 1rem;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }
    .table-mobile-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none !important;
        padding: 0.5rem 0 !important;
        text-align: right !important;
        font-size: var(--fs-base);
    }
    .table-mobile-stack td::before {
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
        color: var(--text-muted);
        font-size: var(--fs-sm);
        padding-right: 0.5rem;
    }

    .fab-container {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        z-index: 999;
    }
    .btn-fab {
        width: 3.75rem;
        height: 3.75rem;
        border-radius: 50% !important;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important;
        font-size: 1.5rem;
    }

    /* Better Table Handling on Mobile */
    .table-responsive {
        border: none;
        border-radius: 0.75rem;
    }
    
    .table thead th {
        white-space: nowrap;
    }
}

/* Print Area Responsiveness (On Screen) */
.print-area {
    width: 210mm;
    min-height: 297mm;
    padding: 15mm;
    margin: 1.25rem auto;
    background: white;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    border-radius: 0.5rem;
    overflow-x: auto;
}

@media (max-width: 210mm) {
    .print-area {
        width: 95%;
        padding: 5mm;
        margin: 0.625rem auto;
    }
}

/* Print Utilities */
@media print {
    body { background: white !important; }
    #sidebar, .top-navbar, .no-print, .btn, .fab-container, .breadcrumb { display: none !important; }
    #content { margin-left: 0 !important; width: 100% !important; padding: 0 !important; }
    .container-fluid { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #eee !important; }
    .print-area { width: 100% !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; }
}

@media (max-width: 576px) {
    html { font-size: 13px; }
    .container-fluid { padding-left: 10px; padding-right: 10px; }
}

