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

:root {
    --font-primary: 'Inter', 'Sarabun', sans-serif;
    --sidebar-width: 260px;
    --header-height: 70px;
    
    /* Sleek Color Palette */
    --bg-main: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.85);
    --border-card: rgba(226, 232, 240, 0.8);
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    
    /* Accent Gradients */
    --gradient-primary: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-danger: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
    --gradient-purple: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    --gradient-dark: linear-gradient(135deg, #475569 0%, #1e293b 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 15px rgba(14, 165, 233, 0.4);
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* App Wrapper Layout */
#app-container {
    display: flex;
    min-height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #f8fafc;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 25px rgba(0, 0, 0, 0.15);
}

#sidebar .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 .brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.5px;
}

#sidebar .brand-logo i {
    font-size: 1.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

#sidebar .sidebar-menu {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    color: #94a3b8;
    border-radius: 10px;
    font-weight: 500;
    margin-bottom: 0.5rem;
    transition: all 0.2s ease;
}

#sidebar .nav-link i {
    font-size: 1.15rem;
    width: 20px;
    text-align: center;
    transition: transform 0.2s ease;
}

#sidebar .nav-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
}

#sidebar .nav-link:hover i {
    transform: translateX(3px);
}

#sidebar .nav-link.active {
    color: #fff;
    background: var(--gradient-primary);
    box-shadow: var(--shadow-glow);
}

#sidebar .nav-link.active i {
    color: #fff;
}

#sidebar .sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.8rem;
    color: #64748b;
}

/* Main Content Wrapper */
#main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Header Styling */
#header {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-card);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: var(--shadow-sm);
}

#header .toggle-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    transition: background 0.2s;
    display: none; /* Hidden on desktop */
}

#header .toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Content Body */
#content-body {
    padding: 2rem;
    flex: 1;
    animation: fadeIn 0.4s ease-out;
}

/* Footer Styling */
#footer {
    background: #fff;
    border-top: 1px solid var(--border-card);
    padding: 1.5rem 2rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

/* Modern Card (Glassmorphism) */
.custom-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.custom-card:hover {
    box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.08);
}

.card-title-badge {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.card-header-gradient {
    background: var(--gradient-dark);
    color: #fff;
    border-radius: 16px 16px 0 0 !important;
    border-bottom: none;
    padding: 1.25rem 1.5rem;
}

/* Stat Cards */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0) 70%);
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 1rem;
}

.stat-icon.primary { background: var(--gradient-primary); }
.stat-icon.success { background: var(--gradient-success); }
.stat-icon.warning { background: var(--gradient-warning); }
.stat-icon.danger { background: var(--gradient-danger); }
.stat-icon.purple { background: var(--gradient-purple); }

.stat-number {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    letter-spacing: -0.5px;
}

/* Custom Buttons */
.btn-grad-primary {
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    box-shadow: 0 4px 10px rgba(14, 165, 233, 0.3);
    transition: all 0.25s ease;
}

.btn-grad-primary:hover, .btn-grad-primary:focus {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(14, 165, 233, 0.4);
}

.btn-grad-success {
    background: var(--gradient-success);
    color: #fff;
    border: none;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
    transition: all 0.25s ease;
}

.btn-grad-success:hover, .btn-grad-success:focus {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(16, 185, 129, 0.4);
}

.btn-grad-danger {
    background: var(--gradient-danger);
    color: #fff;
    border: none;
    box-shadow: 0 4px 10px rgba(244, 63, 94, 0.3);
    transition: all 0.25s ease;
}

.btn-grad-danger:hover, .btn-grad-danger:focus {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(244, 63, 94, 0.4);
}

.btn-grad-secondary {
    background: var(--gradient-dark);
    color: #fff;
    border: none;
    box-shadow: 0 4px 10px rgba(71, 85, 105, 0.3);
    transition: all 0.25s ease;
}

.btn-grad-secondary:hover {
    color: #fff;
    transform: translateY(-2px);
}

/* Custom Table Styles */
.custom-table {
    border-collapse: separate;
    border-spacing: 0 8px;
}

.custom-table thead th {
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    padding: 12px 16px;
}

.custom-table tbody tr {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.custom-table tbody tr:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.custom-table tbody td {
    border: none;
    padding: 16px;
    vertical-align: middle;
}

.custom-table tbody tr td:first-child {
    border-radius: 10px 0 0 10px;
}

.custom-table tbody tr td:last-child {
    border-radius: 0 10px 10px 0;
}

/* Badges */
.badge-custom {
    padding: 0.45em 0.85em;
    font-weight: 500;
    border-radius: 6px;
}

.badge-pickup {
    background-color: rgba(14, 165, 233, 0.15);
    color: #0284c7;
}

.badge-six {
    background-color: rgba(168, 85, 247, 0.15);
    color: #7c3aed;
}

.badge-ten {
    background-color: rgba(245, 158, 11, 0.15);
    color: #d97706;
}

/* Keyframe Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Responsiveness */
@media (max-width: 991.98px) {
    #sidebar {
        left: calc(var(--sidebar-width) * -1);
    }
    #sidebar.show {
        left: 0;
    }
    #main-wrapper {
        margin-left: 0;
    }
    #header .toggle-btn {
        display: block;
    }
}

/* Form Styles */
.form-control, .form-select {
    padding: 0.75rem 1rem;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-family: var(--font-primary);
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15);
}

.input-group-text {
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0.75rem 1rem;
}

/* Summary results block */
.summary-result-box {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #fff;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.summary-result-box::after {
    content: '';
    position: absolute;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(14,165,233,0.15) 0%, rgba(14,165,233,0) 70%);
    bottom: -100px;
    right: -100px;
    pointer-events: none;
}

.summary-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: #38bdf8;
    letter-spacing: -1px;
}

/* Print View Styles */
@media print {
    /* สไตล์สำหรับการสั่งพิมพ์ผ่านการกดปุ่ม "พิมพ์ใบเสนอราคา" ในหน้า Modal */
    body.printing-active {
        background: #fff !important;
        color: #000 !important;
    }
    body.printing-active #app-container,
    body.printing-active .modal,
    body.printing-active .modal-backdrop {
        display: none !important;
        height: 0 !important;
        overflow: hidden !important;
    }
    body.printing-active #print-container {
        display: block !important;
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 30px !important;
        background: #fff !important;
        color: #000 !important;
    }
    body.printing-active #print-container * {
        visibility: visible !important;
    }

    /* สไตล์สำรองสำหรับในกรณีที่ผู้ใช้กดสั่งพิมพ์ด้วยปุ่มลัดเบราว์เซอร์ (Ctrl + P) ในขณะที่ Modal เปิดอยู่ */
    body.modal-open {
        background: #fff !important;
        color: #000 !important;
    }
    body.modal-open #app-container,
    body.modal-open .modal-backdrop {
        display: none !important;
    }
    body.modal-open .modal {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        background: #fff !important;
    }
    body.modal-open .modal-dialog {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 20px !important;
    }
    body.modal-open .modal-content {
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }
    body.modal-open .modal-header,
    body.modal-open .modal-footer,
    body.modal-open .btn-close {
        display: none !important;
    }
    body.modal-open .modal-body {
        padding: 0 !important;
    }
    body.modal-open * {
        visibility: visible !important;
    }
}
