:root {
    --primary: #667eea;
    --secondary: #764ba2;
    --bg-page: #f0f2f5;
    --text-dark: #333;
    --card-shadow: 0 10px 30px rgba(0,0,0,0.08);
    --hover-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

body {
    font-family: 'Kanit', sans-serif;
    background: var(--bg-page);
    background-image: radial-gradient(#d4dce6 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--text-dark);
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 20px;
}

/* ===== Page Header ===== */
.page-header {
    background: linear-gradient(135deg, white 0%, #f8f9fa 100%);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 40px;
    box-shadow: var(--card-shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.5);
}

.page-header::before {
    content: ''; 
    position: absolute; 
    right: -50px; 
    top: -50px;
    width: 200px; 
    height: 200px; 
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    opacity: 0.1; 
    border-radius: 50%;
}

.header-content h1 {
    color: var(--text-dark);
    font-size: 32px;
    font-weight: 600;
    margin-bottom: 8px;
}

.header-content p {
    color: #666;
    font-size: 16px;
}

/* ===== Room Closed Alert ===== */
.room-closed-alert {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border: 2px solid #ef4444;
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.2);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.alert-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

.alert-icon {
    width: 60px;
    height: 60px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); 
    }
    50% { 
        transform: scale(1.05); 
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); 
    }
}

.alert-content h3 {
    color: #dc2626;
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 5px 0;
}

.alert-content p {
    color: #991b1b;
    margin: 0;
    font-size: 15px;
}

.alert-details {
    background: rgba(255, 255, 255, 0.7);
    padding: 15px;
    border-radius: 10px;
    margin-top: 15px;
    border-left: 4px solid #ef4444;
}

.alert-details strong {
    color: #dc2626;
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
}

.alert-details p {
    color: #7f1d1d;
    margin: 5px 0;
    line-height: 1.6;
    font-size: 14px;
}

.alert-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px dashed #f87171;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.alert-footer .btn {
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: 0.3s;
}

.btn-back {
    background: white;
    color: #dc2626;
    border: 2px solid #dc2626;
}

.btn-back:hover {
    background: #dc2626;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 38, 38, 0.3);
}

.btn-view-others {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
}

.btn-view-others:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(59, 130, 246, 0.4);
}

/* ===== Rooms Grid ===== */
.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 30px;
    padding-bottom: 50px;
}

.room-card {
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    opacity: 0;
    animation: slideUpFade 0.6s forwards;
    border: 1px solid white;
}

.room-card:hover {
    transform: translateY(-10px);
    box-shadow: var(--hover-shadow);
}

@keyframes slideUpFade {
    from { 
        opacity: 0; 
        transform: translateY(40px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* ===== Inactive Room Style ===== */
.room-card.inactive {
    opacity: 0.6;
    position: relative;
}

.room-card.inactive::before {
    content: '🔒 ปิดใช้งาน';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(239, 68, 68, 0.95);
    color: white;
    padding: 15px 30px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    z-index: 10;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

.room-card.inactive .btn-primary.disabled {
    background: #9ca3af;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===== Room Image ===== */
.room-image {
    width: 100%;
    height: 220px;
    background: #e0e6ed;
    position: relative;
    overflow: hidden;
}

.room-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.room-card:hover .room-image img {
    transform: scale(1.1);
}

.room-image-placeholder,
.modal-image-placeholder {
    width: 100%; 
    height: 100%;
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center;
    font-size: 60px; 
    color: #cbd5e0;
    background: linear-gradient(135deg, #f5f7fa, #e4e7eb);
}

.modal-image-placeholder p {
    font-size: 16px;
    margin-top: 10px;
}

.capacity-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    color: white;
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 5px;
    z-index: 2;
}

/* ===== Room Content ===== */
.room-content {
    padding: 25px;
}

.room-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.room-floor {
    font-size: 13px;
    color: #888;
    background: #f0f0f0;
    padding: 3px 8px;
    border-radius: 6px;
}

.room-desc {
    color: #666;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Card Actions ===== */
.card-actions {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.3s;
    font-family: 'Kanit', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
}

.btn-outline {
    background: white;
    border: 2px solid #e2e8f0;
    color: #64748b;
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f8fafc;
}

.btn-info {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-info:hover {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px; /* ✅ เพิ่ม padding รอบ modal */
    overflow-y: auto; /* ✅ เพิ่ม scroll สำหรับ overlay */
    overflow-x: hidden;
}

/* ✅ ใช้ class 'active' แทน 'show' */
.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: white;
    width: 80%; /* ✅ เปลี่ยนจาก 90% เป็น 80% */
    max-width: 800px; /* ✅ เปลี่ยนจาก 900px เป็น 800px */
    border-radius: 20px; /* ✅ เปลี่ยนจาก 24px เป็น 20px */
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 80vh; /* ✅ เปลี่ยนจาก 85vh เป็น 80vh */
    display: flex;
    flex-direction: column;
    margin: auto; /* ✅ เพิ่ม margin auto เพื่อจัดกลาง */
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-header {
    padding: 18px 25px; /* ✅ เปลี่ยนจาก 20px 30px เป็น 18px 25px */
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 { 
    font-size: 22px; /* ✅ เปลี่ยนจาก 24px เป็น 22px */
    color: var(--text-dark); 
}

.close-modal { 
    font-size: 24px; /* ✅ เปลี่ยนจาก 28px เป็น 24px */
    cursor: pointer; 
    color: #999; 
    transition: 0.2s; 
    background: none; 
    border: none;
    width: 32px; /* ✅ เพิ่มขนาดพื้นที่คลิก */
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.close-modal:hover { 
    color: var(--secondary); 
    background: rgba(102, 126, 234, 0.1); /* ✅ เพิ่มพื้นหลังตอน hover */
    transform: rotate(90deg); 
}

.modal-body {
    padding: 25px; /* ✅ เปลี่ยนจาก 30px เป็น 25px */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 25px; /* ✅ เปลี่ยนจาก 30px เป็น 25px */
}

@media (min-width: 768px) {
    .modal-body {
        flex-direction: row;
        align-items: flex-start;
    }
    .modal-img-col { flex: 0.8; } /* ✅ เปลี่ยนจาก 1 เป็น 0.8 (รูปเล็กลง 20%) */
    .modal-info-col { flex: 1.3; }
}

.modal-image {
    width: 100%;
    border-radius: 12px; /* ✅ เปลี่ยนจาก 16px เป็น 12px (มุมโค้งน้อยลง = ดูเล็กลง) */
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    aspect-ratio: 16/10;
}

.modal-image img { 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
}

.info-row {
    display: flex;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px dashed #eee;
}

.info-label { 
    width: 100px; 
    font-weight: 500; 
    color: #888; 
    flex-shrink: 0;
}

.info-value { 
    flex: 1; 
    color: #333; 
    font-weight: 500; 
}

.modal-desc-box {
    background: #f9fafb;
    padding: 20px;
    border-radius: 12px;
    margin-top: 10px;
    line-height: 1.8;
    color: #444;
    font-size: 15px;
    min-height: auto;
}

.modal-desc-box strong {
    display: block;
    margin-bottom: 12px;
    font-size: 16px;
    color: #333;
}

.inactive-notice {
    background: #fee2e2;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #ef4444;
    margin-bottom: 15px;
}

.inactive-notice i {
    color: #dc2626;
    margin-right: 5px;
}

.inactive-notice strong {
    color: #dc2626;
    display: inline;
    margin: 0;
}

.modal-actions {
    padding: 18px 25px; /* ✅ เปลี่ยนจาก 20px 30px เป็น 18px 25px */
    background: #f8f9fa;
    display: flex;
    gap: 12px; /* ✅ เปลี่ยนจาก 15px เป็น 12px */
    justify-content: flex-end;
}

/* ===== Ripple Effect ===== */
.ripple {
    position: absolute;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: scale(0);
    animation: rippleAnim 0.6s linear;
    pointer-events: none;
}

@keyframes rippleAnim { 
    to { 
        transform: scale(4); 
        opacity: 0; 
    } 
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .rooms-grid {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        padding: 20px;
    }
    
    .header-content h1 {
        font-size: 24px;
    }
    
    .modal-overlay {
        padding: 10px; /* ✅ ลด padding บนมือถือ */
    }
    
    .modal-card {
        width: 95%;
        max-height: 90vh; /* ✅ ใช้พื้นที่เต็มบนมือถือ */
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-actions .btn {
        width: 100%;
    }
}