/* assets/css/style.css */

/* --- 1. CORE VARIABLES & SETUP --- */
:root {
    --brand-primary: #C41230; 
    --brand-dark: #8E0D23;
    --brand-light: #FFF0F2;
    --brand-gradient: linear-gradient(135deg, #C41230 0%, #9e0e26 100%);
    
    --text-main: #1f2937;
    --text-muted: #6b7280;
    
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    
    /* Modern Shadows (Soft & Diffused) */
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-brand: 0 4px 14px 0 rgba(196, 18, 48, 0.3);
    
    --sidebar-width: 280px;
    --header-height: 72px;
    --font-main: 'Kanit', sans-serif;
    
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-main);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Typography */
h1, h2, h3, h4, h5, h6, .font-header { 
    font-family: var(--font-main); 
    font-weight: 600; 
    letter-spacing: -0.01em; 
    color: #111827;
}
.fs-7 { font-size: 0.875rem; }
.fs-8 { font-size: 0.75rem; }

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

/* --- 2. COMPONENTS & THEME --- */

/* Buttons - Modern & Tactile */
.btn {
    font-weight: 500;
    border-radius: var(--radius-full);
    padding: 0.65rem 1.5rem;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
    position: relative;
    border: 1px solid transparent;
}

.btn:active {
    transform: scale(0.96); /* Tactile feedback */
}

/* Brand Button */
.btn-brand, .btn-brand-gradient {
    background: var(--brand-gradient);
    color: white;
    border: none;
    box-shadow: var(--shadow-brand);
}

.btn-brand:hover, .btn-brand-gradient:hover {
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -4px rgba(196, 18, 48, 0.5);
    filter: brightness(1.05);
}

.btn-brand:active, .btn-brand-gradient:active {
    transform: translateY(0) scale(0.98);
    box-shadow: none;
}

/* Secondary Button */
.btn-outline-secondary {
    background: white;
    border-color: #e2e8f0;
    color: #475569;
}
.btn-outline-secondary:hover, .btn-outline-secondary.active {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #1e293b;
    box-shadow: var(--shadow-sm);
}

/* Form Inputs - Clean & Spacious */
.form-control, .form-select {
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem; /* Larger touch target */
    border: 1px solid #e2e8f0;
    background-color: #fff;
    font-size: 0.95rem;
    transition: var(--transition-fast);
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.form-control:focus, .form-select:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 4px rgba(196, 18, 48, 0.1);
    outline: none;
}

.form-label {
    font-weight: 500;
    color: #64748b;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

/* Cards - Floating & Clean */
.card {
    border: none;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-smooth);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.hover-shadow:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg) !important;
}

/* --- 3. LAYOUT --- */

/* Sidebar - Modern Gradient */
#sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--brand-gradient);
    color: #fff;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: fixed;
    top: 0; left: 0; height: 100vh;
    z-index: 1040;
    overflow-y: auto;
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    /* Make sidebar a flex container to push footer down */
    display: flex;
    flex-direction: column;
}

#sidebar .sidebar-header {
    padding: 1.75rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#sidebar ul.components { padding: 1rem 0; flex: 1; }

#sidebar ul li a {
    padding: 0.9rem 1.5rem;
    margin: 0.25rem 1rem;
    font-size: 0.95rem;
    display: flex; align-items: center;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    border-left: none; /* Removed border */
}

#sidebar ul li a:hover { 
    background: rgba(255, 255, 255, 0.15); 
    color: #fff;
    transform: translateX(4px);
}

#sidebar ul li a.active {
    background: #fff;
    color: var(--brand-primary);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

#sidebar ul li a i {
    width: 24px;
    text-align: center;
    margin-right: 12px;
    font-size: 1.15rem;
}

/* Sidebar Footer (Logout Section) Fix */
#sidebar .mt-auto {
    margin-top: auto;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.15);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
}

/* Content Area */
#content {
    width: 100%;
    min-height: 100vh;
    display: flex; flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Navbar - Glassmorphism */
.navbar-custom {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    box-shadow: 0 1px 0 0 #e2e8f0;
    height: var(--header-height);
    padding: 0 1.5rem;
    z-index: 1030;
    position: sticky; top: 0;
}

/* Notifications - Fixed Display Issue */
.notification-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: 320px;
    background: white;
    border: none;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-radius: var(--radius-lg);
    margin-top: 12px;
    overflow: hidden;
    padding: 0;
    display: none; /* Hidden by default */
    z-index: 1050;
}

.notification-menu.show { 
    display: block; 
    animation: slideDown 0.2s ease-out; 
}

.notif-item {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
}
.notif-item:hover { background-color: #f8fafc; }
.timeline-item .badge{
	background-color:var(--brand-primary);
}
.badge-notify {
    position: absolute; top: 6px; right: 6px;
    transform: translate(25%, -25%);
    font-size: 0.65rem; padding: 0.3em 0.5em;
    min-width: 1.6em; text-align: center;
    border-radius: 99rem !important; border: 2px solid #fff;
    z-index: 1; line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

/* Sidebar Collapse Button Fix */
#sidebarCollapse {
    width: 40px;
    height: 40px;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    flex-shrink: 0;
}

/* --- 4. MODULES --- */

/* Kanban Board - Improved Spacing */
.kanban-container {
    display: flex;
    overflow-x: auto;
    height: calc(100vh - 200px); 
    padding-bottom: 1.5rem;
    gap: 1.25rem;
    padding-right: 1.5rem;
    scroll-snap-type: x mandatory;
}

.kanban-col {
    min-width: 310px; max-width: 310px;
    background-color: #f1f5f9;
    border-radius: var(--radius-lg);
    display: flex; flex-direction: column;
    height: 100%;
    border: none;
    scroll-snap-align: start;
}

.kanban-header {
    padding: 1.25rem;
    font-weight: 600;
    background-color: transparent;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    position: sticky; top: 0;
    display: flex; justify-content: space-between; align-items: center;
    color: #475569;
}

.kanban-body { flex: 1; padding: 1rem; overflow-y: auto; }

.kanban-card {
    background: #fff;
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    cursor: pointer;
    border-left: 4px solid transparent;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.kanban-card:hover { 
    transform: translateY(-4px); 
    box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1); 
}

.kanban-card.tier-1 { border-left-color: #ef4444; }
.kanban-card.tier-2 { border-left-color: #f59e0b; }
.kanban-card.tier-3 { border-left-color: #94a3b8; }

/* Calendar */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: #cbd5e1;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.calendar-day {
    background-color: white;
    min-height: 130px;
    padding: 0.75rem;
    transition: background 0.2s;
}
.calendar-day:hover { background-color: #f8fafc; }
.calendar-day.today { background-color: #fff1f2; }

.calendar-event {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    transition: transform 0.1s;
}
.calendar-event:hover { transform: scale(1.02); z-index: 2; }

/* --- 5. RESPONSIVE (MOBILE OPTIMIZED) --- */

@media (min-width: 992px) {
    #content { margin-left: var(--sidebar-width); width: calc(100% - var(--sidebar-width)); }
    #sidebar.active { margin-left: calc(var(--sidebar-width) * -1); }
    #content.active { margin-left: 0; width: 100%; }
    .overlay { display: none !important; }
}

@media (max-width: 991.98px) {
    /* Layout */
    #sidebar { margin-left: calc(var(--sidebar-width) * -1); box-shadow: none; }
    #sidebar.active { margin-left: 0; box-shadow: 10px 0 30px rgba(0,0,0,0.2); }
    #content { margin-left: 0; width: 100%; }
    
    .overlay {
        display: none; position: fixed;
        width: 100vw; height: 100vh;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1035; top: 0; left: 0;
        opacity: 0; transition: opacity 0.3s;
        backdrop-filter: blur(4px);
    }
    .overlay.active { display: block; opacity: 1; }
    
    /* Mobile Components */
    .btn:not(#sidebarCollapse):not(.rounded-circle) {
        width: 100%; /* Full width buttons for easy tapping */
        margin-bottom: 0.5rem;
        padding: 0.8rem;
    }
    
    /* Ensure sidebar toggle stays square/round on mobile */
    #sidebarCollapse {
        margin-bottom: 0;
    }
    
    .d-flex.gap-2.align-items-center { /* Calendar Controls */
        width: 100%; justify-content: space-between; margin-bottom: 1rem;
    }
    
    .navbar-custom { padding: 0 1rem; height: auto; min-height: var(--header-height); }
    
    .kanban-container {
        padding-right: 1rem;
        height: auto;
        min-height: 500px;
    }
    .kanban-col {
        min-width: 85vw; /* Almost full screen width */
    }
    
    .card-body { padding: 1.25rem; }
    
    /* Text Sizing */
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.35rem; }
    h4, .h4 { font-size: 1.2rem; }
    .fs-7 { font-size: 0.9rem; }
    
    /* Spacing */
    .p-4 { padding: 1.25rem !important; }
    .mb-4 { margin-bottom: 1.25rem !important; }
}

/* Animations */
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}
.animate-shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }

/* Login Page Styles (Preserved) */
.login-container {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1.5rem; position: relative;
    background-color: #111827;
}
.login-bg-image {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: url('https://images.unsplash.com/photo-1600596542815-2495db98dada?ixlib=rb-4.0.3&auto=format&fit=crop&w=2000&q=80') no-repeat center center;
    background-size: cover; z-index: 0;
}
.login-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, rgba(196, 18, 48, 0.85) 0%, rgba(17, 24, 39, 0.95) 100%);
    z-index: 1; backdrop-filter: blur(4px);
}
.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.5);
    z-index: 2;
    border-radius: 24px;
}
.brand-logo {
    width: 80px; height: 80px;
    background: var(--brand-gradient);
    border-radius: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    transform: rotate(-5deg); transition: transform 0.3s;
    box-shadow: 0 15px 30px -10px rgba(196, 18, 48, 0.4);
}
.brand-logo:hover { transform: rotate(0deg) scale(1.05); }

/* Calendar Events Types */
.calendar-event {
    /* ... (Style เดิม) ... */
    font-size: 0.75rem;
    padding: 3px 6px; /* ปรับ Padding นิดหน่อย */
}

/* สีสำหรับลูกค้าใหม่ (Date Received) */
.calendar-event.type-new {
    background-color: #198754; /* สีเขียว */
    color: white;
}

/* [เพิ่มใหม่] สีสำหรับนัดหมาย (Appointment) */
.calendar-event.type-appt {
    background-color: #fd7e14; /* สีส้ม */
    color: white;
}
.calendar-event.type-appt:hover {
    background-color: #e36802;
}

#calendar-grid .badge.text-white{
	background-color: var(--brand-primary);
}

/* เมื่อ Modal แสดงแบบเต็มจอ (Fullscreen) */
.modal-fullscreen-xl-down .modal-content {
    border-radius: 0; /* ลบมุมโค้งเพื่อให้ดูเต็มจอจริง */
}

/* ปรับปรุงการแสดงผลบนหน้าจอขนาด Tablet/iPad (น้อยกว่า 1200px) */
@media (max-width: 1199.98px) {
    .modal-fullscreen-xl-down .modal-body {
        padding: 1.5rem !important; /* เพิ่มพื้นที่หายใจ */
    }
    
    /* ขยายความสูงของ Input ใน Modal ให้กดง่ายขึ้นบนจอสัมผัส */
    .modal-body .form-control, 
    .modal-body .form-select {
        padding: 0.8rem 1rem;
    }

    /* ปรับปุ่มกดให้ใหญ่ขึ้นเล็กน้อย */
    .modal-footer .btn {
        padding: 0.8rem 2rem;
        width: 100%; /* ปุ่มเต็มความกว้างในแนวตั้งบนมือถือบางรุ่น */
        margin-bottom: 0.5rem;
    }
    
    .modal-footer {
        flex-direction: column-reverse; /* ปุ่มบันทึกอยู่บน ปุ่มยกเลิกอยู่ล่าง */
        gap: 0.5rem;
    }
    
    /* ถ้าเป็น iPad แนวนอน (กว้างหน่อย) ให้ปุ่มเรียงแนวนอนเหมือนเดิม */
    @media (min-width: 576px) {
        .modal-footer .btn { width: auto; margin-bottom: 0; }
        .modal-footer { flex-direction: row; }
    }
}

/* --- 6. RESPONSIVE MODAL FOR TABLET/IPAD --- */
/* ใช้ Media Query สำหรับหน้าจอที่เล็กกว่า XL (1200px) */
@media (max-width: 1199.98px) {
    .modal-fullscreen-xl-down .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .modal-fullscreen-xl-down .modal-dialog {
        width: 100%;
        max-width: none;
        height: 100%;
        margin: 0;
        padding: 0;
    }
    
    .modal-fullscreen-xl-down .modal-body {
        overflow-y: auto;
    }
    
    .modal-fullscreen-xl-down .modal-footer {
        position: sticky;
        bottom: 0;
        background: white;
        z-index: 10;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }
}

/* Welcome Page */
.welcome-banner {
    background: var(--brand-gradient);
    min-height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.cursor-pointer {
    cursor: pointer;
}

.icon-box {
    transition: transform 0.2s;
}

.hover-shadow:hover .icon-box {
    transform: scale(1.1);
}