/* Import Google Font Sarabun with extended weights */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@200;300;400;500;600;700;800&display=swap');

/* Enhanced root variables for modern professional design */
:root {
    /* Primary color palette - inspired by Thai government branding */
    --primary-color: #1a365d; /* Deep navy blue - professional and trustworthy */
    --primary-light: #2d4a6b;
    --primary-dark: #0f2537;

    /* Secondary colors */
    --secondary-color: #2b6cb8; /* Bright professional blue */
    --secondary-light: #4a8dd4;
    --secondary-dark: #1e4d85;

    /* Accent colors */
    --accent-gold: #d4af37; /* Thai gold accent */
    --accent-gold-light: #e6c555;
    --accent-gold-dark: #b8941f;

    /* Background colors */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e2e8f0;
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);

    /* Text colors */
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-light: #a0aec0;

    /* Border and shadow */
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Border radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Transitions */
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);

    /* Animation duration from JS */
    --animation-duration: 0.5s;
}

/* Base styles */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.65;
    font-weight: 400;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography enhancements */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: -0.025em;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

h1 { font-size: 2.25rem; font-weight: 700; }
h2 { font-size: 1.875rem; font-weight: 600; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; font-weight: 500; }

/* Enhanced Navbar */
.navbar {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    padding: 1rem 0;
    transition: var(--transition-normal);
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary-color) !important;
    letter-spacing: -0.02em;
    transition: var(--transition-fast);
}

.navbar-brand:hover {
    color: var(--secondary-color) !important;
    transform: translateY(-1px);
}

.nav-link {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-secondary) !important;
    padding: 0.75rem 1rem !important;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    position: relative;
    margin: 0 0.25rem;
}

.nav-link:hover {
    color: var(--primary-color) !important;
    background-color: rgba(43, 108, 184, 0.1);
    transform: translateY(-1px);
}

.nav-link.active {
    color: var(--secondary-color) !important;
    background-color: rgba(43, 108, 184, 0.15);
    font-weight: 600;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background-color: var(--secondary-color);
    border-radius: 50%;
}

.dropdown-menu {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: 0.75rem 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    margin-top: 0.5rem;
}

.dropdown-item {
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: var(--transition-fast);
    border-radius: 0;
}

.dropdown-item:hover {
    background-color: var(--bg-primary);
    color: var(--primary-color);
    transform: translateX(4px);
}

.dropdown-item:active {
    background-color: var(--secondary-color);
    color: white !important;
}

/* Enhanced Card System */
.card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    transition: var(--transition-normal);
    background: var(--bg-secondary);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: white;
    border: none;
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: -0.01em;
    position: relative;
}

.card-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-gold) 0%, var(--accent-gold-light) 100%);
}

.card-header-custom {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-light) 100%);
}

.card-header h4,
.card-header .h4,
.card-header-custom h4,
.card-header-custom .h4 {
    color: white;
    margin-bottom: 0;
    font-weight: 600;
}

.card-body {
    padding: 1.5rem;
}

.dashboard-card .card-body {
    padding: 2rem 1.5rem;
}

.dashboard-card .card-title {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

/* --- Custom Dashboard Card Icons --- */
.dashboard-card .card-icon {
    transition: var(--transition-normal);
}

.dashboard-card:hover .card-icon {
    transform: scale(1.1);
    filter: brightness(1.05);
}

.icon-primary { color: var(--primary-color); }
.icon-secondary { color: var(--secondary-color); }
.icon-success { color: #10b981; } /* Matching the button gradient */
.icon-gold { color: var(--accent-gold); }
.icon-info { color: #0ea5e9; } /* A bright, friendly blue */
.icon-dark { color: var(--text-secondary); }

/* Enhanced Table Styling */
.table {
    margin-bottom: 0;
    font-size: 0.95rem;
}

.table th {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--primary-color);
    padding: 1rem 0.75rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.table td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition-fast);
}

.table-hover tbody tr {
    transition: var(--transition-fast);
}

.table-hover tbody tr:hover {
    background: linear-gradient(135deg, rgba(43, 108, 184, 0.03) 0%, rgba(43, 108, 184, 0.06) 100%);
    transform: scale(1.001);
}

.table-bordered {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.table-sm th,
.table-sm td {
    padding: 0.75rem 0.5rem;
}

/* Enhanced Form Controls */
.form-control,
.form-select {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 400;
    background-color: var(--bg-secondary);
    transition: var(--transition-normal);
    box-shadow: none;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px rgba(43, 108, 184, 0.1);
    background-color: white;
    outline: none;
    transform: translateY(-1px);
}

.form-label {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-floating > label {
    font-weight: 500;
    color: var(--text-muted);
}

/* Enhanced Button System */
.btn {
    border-radius: var(--radius-md);
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    letter-spacing: -0.01em;
    transition: var(--transition-normal);
    border: none;
    box-shadow: var(--shadow-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: var(--transition-normal);
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
    color: white;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
}

.btn-info {
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--secondary-light) 100%);
    color: white;
}

.btn-info:hover {
    background: linear-gradient(135deg, var(--secondary-dark) 0%, var(--secondary-color) 100%);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-gold-light) 100%);
    color: var(--primary-color);
    font-weight: 700;
}

.btn-warning:hover {
    background: linear-gradient(135deg, var(--accent-gold-light) 0%, var(--accent-gold) 100%);
    color: var(--primary-dark);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: white;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 700;
}

/* Enhanced Alert System */
.alert {
    border: none;
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    border-left: 4px solid;
}

.alert-primary {
    background: linear-gradient(135deg, rgba(43, 108, 184, 0.1) 0%, rgba(43, 108, 184, 0.05) 100%);
    color: var(--primary-color);
    border-left-color: var(--secondary-color);
}

.alert-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.05) 100%);
    color: #065f46;
    border-left-color: #10b981;
}

.alert-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0.05) 100%);
    color: #991b1b;
    border-left-color: #ef4444;
}

.alert-warning {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.1) 0%, rgba(212, 175, 55, 0.05) 100%);
    color: var(--primary-color);
    border-left-color: var(--accent-gold);
}

.alert-info {
    background: linear-gradient(135deg, rgba(43, 108, 184, 0.1) 0%, rgba(43, 108, 184, 0.05) 100%);
    color: var(--secondary-dark);
    border-left-color: var(--secondary-color);
}

/* Login Form Enhancement */
.form-signin {
    max-width: 440px;
    margin: auto;
    padding: 3rem 2.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
    position: relative;
}

.form-signin::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 50%, var(--accent-gold) 100%);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.form-signin .form-floating:focus-within {
    z-index: 2;
}

.form-signin input[type="text"],
.form-signin input[type="email"],
.form-signin input[type="password"] {
    margin-bottom: 1rem;
    border-radius: var(--radius-md) !important;
}

/* Footer Enhancement */
.footer {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-top: 1px solid var(--border-light);
    padding: 2rem 0;
    margin-top: 3rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Utility Classes */
.text-primary { color: var(--primary-color) !important; }
.text-secondary { color: var(--secondary-color) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-accent { color: var(--accent-gold) !important; }

.bg-primary { background: var(--primary-color) !important; }
.bg-secondary { background: var(--secondary-color) !important; }
.bg-gradient-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%) !important;
}

/* Loading and Animation Utilities */
.fade-in {
    animation: fadeIn var(--animation-duration) ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.slide-up {
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Modal Styling */
.modal-content {
    border: none;
    border-radius: var(--bs-border-radius-lg, 0.5rem);
    overflow: hidden;
}

.modal-header.bg-gradient-primary {
    background: linear-gradient(135deg, var(--bs-primary, #0d6efd) 0%, #0056b3 100%) !important;
}

.btn-close-white {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Mobile-optimized footer */
.footer {
    padding: 0.75rem 0;
}

.footer-copyright,
.footer-org {
    font-size: 0.875rem;
}

/* Back to Top Button - Mobile Optimized */
#btn-back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1050;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8) translateY(20px);
}

#btn-back-to-top.show {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

#btn-back-to-top:hover,
#btn-back-to-top.touched {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

#btn-back-to-top i {
    line-height: 1;
}


/* Enhanced Responsive Design */
@media (max-width: 768px) {
    body { font-size: 15px; }

    h1 { font-size: 1.875rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }

    .navbar { padding: 0.75rem 0; }
    .navbar-brand { font-size: 1.25rem; }

    .card { margin-bottom: 1.5rem; }
    .card-body { padding: 1.25rem; }
    .dashboard-card .card-body { padding: 1.5rem 1.25rem; }

    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.85rem;
    }

    .form-signin {
        margin: 1rem;
        padding: 2rem 1.5rem;
        max-width: none;
    }

    .table-responsive {
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
    }
}

@media (max-width: 576px) {
    .container { padding-left: 1rem; padding-right: 1rem; }

    .card-header { padding: 1rem 1.25rem; }
    .card-body { padding: 1rem; }

    .btn-sm {
        padding: 0.375rem 0.75rem;
        font-size: 0.75rem;
    }

    .table th, .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* Mobile-specific modal adjustments */
@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 1rem 0.5rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1;
        min-height: 44px;
    }

    .input-group {
        margin-bottom: 0.5rem;
    }

    .form-label {
        margin-bottom: 0.25rem;
        font-size: 0.9rem;
    }

    .form-control {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }

    .btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .footer {
        padding: 1rem 0;
    }

    .footer-copyright,
    .footer-org {
        font-size: 0.8rem;
    }

    /* Larger touch targets for mobile */
    .toggle-password {
        min-width: 44px;
        padding: 0.75rem 0.5rem;
    }

    /* Better spacing for mobile forms */
    .mb-3 {
        margin-bottom: 1rem !important;
    }
}

/* High DPI screens adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .modal-content {
        border-width: 0.5px;
    }

    #btn-back-to-top {
        border-width: 0.5px;
    }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    #btn-back-to-top,
    .modal-content,
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* Focus indicators for keyboard navigation */
.btn:focus-visible,
.form-control:focus {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

/* Custom Tooltip Style - Aligned with your theme */
.tooltip .tooltip-inner {
    background-color: var(--primary-color); /* ใช้สีน้ำเงินเข้มตามธีมหลัก */
    color: white;
    padding: 8px 12px;
    border-radius: var(--radius-md, 0.5rem); /* ใช้รัศมีความโค้งของขอบตามธีม */
    box-shadow: var(--shadow-md);            /* เพิ่มเงาให้เข้ากับส่วนอื่นๆ */
    font-weight: 500;                        /* ปรับความหนาตัวอักษรเล็กน้อย */
}

/* ทำให้สีของลูกศรถูกต้องในทุกทิศทาง (บน, ล่าง, ซ้าย, ขวา) */
.bs-tooltip-top .tooltip-arrow::before {
    border-top-color: var(--primary-color);
}
.bs-tooltip-end .tooltip-arrow::before {
    border-right-color: var(--primary-color);
}
.bs-tooltip-bottom .tooltip-arrow::before {
    border-bottom-color: var(--primary-color);
}
.bs-tooltip-start .tooltip-arrow::before {
    border-left-color: var(--primary-color);
}