/* style.css - Final Fixed for Desktop & Mobile */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary-color: #4361ee;
    --primary-hover: #3a0ca3;
    --secondary-bg: #f8f9fa;
    --sidebar-width: 260px;
    --card-radius: 12px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
    font-family: 'Prompt', sans-serif;
    background-color: var(--secondary-bg);
    margin: 0; padding: 0;
    color: #333;
    overflow-x: hidden; /* ป้องกันหน้าจอล้นแนวนอน */
}

/* --- Layout Structure (Desktop Default) --- */
.page-wrapper { display: flex; min-height: 100vh; width: 100%; }
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    background: var(--secondary-bg);
    width: calc(100% - var(--sidebar-width)); /* fix width calculation */
    box-sizing: border-box;
}
.container, .container-fluid { width: 100%; max-width: 1200px; margin: 0 auto; }

/* --- Sidebar (Desktop) --- */
.sidebar {
    width: var(--sidebar-width);
    background: #fff;
    height: 100vh;
    position: fixed;
    top: 0; left: 0;
    border-right: 1px solid #eee;
    display: flex; flex-direction: column;
    z-index: 1000;
}
.sidebar-header { 
    padding: 20px; 
    border-bottom: 1px solid #f0f0f0; 
    display: flex; 
    align-items: center; 
    justify-content: center; /* จัดกึ่งกลางสำหรับ Desktop */
    gap: 10px; 
}
.logo-img { width: 100%; max-width: 150px; height: auto; object-fit: contain; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 15px; }
.sidebar-nav ul { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li a {
    display: flex; align-items: center; padding: 12px 15px;
    color: #64748b; text-decoration: none; border-radius: 8px;
    margin-bottom: 5px; transition: 0.2s; font-size: 15px;
}
.sidebar-nav li a:hover { background: #f1f5f9; color: var(--primary-color); }
.sidebar-nav li.nav-active a { background: #eff6ff; color: var(--primary-color); font-weight: 600; }
.sidebar-nav li a i { width: 25px; font-size: 18px; }
.nav-header { font-size: 12px; color: #94a3b8; font-weight: 600; padding: 15px 15px 5px; text-transform: uppercase; }

/* ปุ่ม Hamburger (ซ่อนใน Desktop) */
#sidebarToggle { display: none; }

/* --- Buttons & Forms --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 5px;
    padding: 8px 20px; border-radius: 6px; text-decoration: none; border: none;
    cursor: pointer; font-size: 14px; transition: 0.2s;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-pay { background: #10b981; color: #fff; }

.form-control {
    width: 100%; padding: 10px 15px; border: 1px solid #e2e8f0;
    border-radius: 8px; font-size: 14px; background: #fff; box-sizing: border-box;
}

/* --- Cards & General --- */
.form-wrapper, .table-container, .card-box {
    background: #fff; padding: 25px; border-radius: var(--card-radius);
    box-shadow: var(--shadow-sm); margin-bottom: 30px; border: 1px solid #f1f5f9;
}

/* --- Dashboard Stats --- */
.dashboard-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 30px;
}
.stat-card {
    background: #fff; border-radius: 16px; padding: 20px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-sm); border: 1px solid #f1f5f9;
}
.stat-icon {
    width: 50px; height: 50px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.stat-blue .stat-icon { background: #eff6ff; color: #3b82f6; }
.stat-green .stat-icon { background: #ecfdf5; color: #10b981; }
.stat-orange .stat-icon { background: #fff7ed; color: #f97316; }
.stat-red .stat-icon { background: #fef2f2; color: #ef4444; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 15px; background: #f8fafc; color: #475569; font-weight: 600; }
td { padding: 15px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }

/* --- Chat System --- */
.chat-inbox-container, .chat-room-wrapper {
    background: #fff; border-radius: 16px; box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9; overflow: hidden; max-width: 800px; margin: 0 auto;
}
.chat-item {
    display: flex; align-items: center; padding: 15px 20px;
    border-bottom: 1px solid #f8fafc; text-decoration: none; position: relative;
}
.chat-item:hover { background-color: #f8fafc; }
.chat-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; margin-right: 15px; }
.msg-bubble { padding: 10px 16px; border-radius: 18px; max-width: 70%; word-wrap: break-word; }
.msg-left .msg-bubble { background: #fff; color: #1e293b; }
.msg-right .msg-bubble { background: linear-gradient(135deg, #4361ee, #3a0ca3); color: #fff; }

/* --- Auth Pages --- */
.auth-wrapper { min-height: 85vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
    background: #fff; width: 100%; max-width: 480px; padding: 40px 35px;
    border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    position: relative; overflow: hidden; border: 1px solid #f1f5f9; box-sizing: border-box;
}
.auth-card::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 6px;
    background: linear-gradient(to right, #4361ee, #7209b7);
}
.auth-input {
    width: 100%; height: 48px; padding: 0 15px 0 45px; border: 1px solid #cbd5e1;
    border-radius: 12px; font-size: 15px; box-sizing: border-box;
}
.btn-auth {
    width: 100%; padding: 14px; background: #4361ee; color: #fff;
    border: none; border-radius: 12px; font-weight: 600; cursor: pointer; margin-top: 10px;
}

/* ============================================================
   MOBILE RESPONSIVE FIXES (ทำงานเฉพาะหน้าจอมือถือ/แท็บเล็ต) 
   ============================================================ */
@media screen and (max-width: 991px) {
    /* 1. เปลี่ยนโครงสร้างหลักเป็น บน-ล่าง */
    .page-wrapper { display: block; }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: relative; /* ไม่ Fixed */
        border-right: none;
        border-bottom: 1px solid #ddd;
        z-index: 2000;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 15px; /* ลด Padding ให้ไม่กินที่ */
    }

    /* 2. จัดการ Header ของ Sidebar ในมือถือ */
    .sidebar-header {
        justify-content: space-between; /* โลโก้ซ้าย ปุ่มขวา */
        padding: 10px 20px;
    }
    
    /* ปรับขนาดโลโก้ในมือถือ */
    .logo-img { max-height: 40px; width: auto; }

    /* โชว์ปุ่มเมนู */
    #sidebarToggle {
        display: block !important;
        background: none; border: none; font-size: 24px; color: #333; cursor: pointer;
    }

    /* 3. ซ่อนเมนูไว้ก่อน (กดแล้วค่อยโชว์ด้วย JS) */
    .sidebar-nav { display: none; background: #fff; border-top: 1px solid #f1f5f9; }

    /* 4. ปรับ Grid ต่างๆ ให้เป็น 1 แถว */
    .dashboard-grid, .condo-grid-layout, .form-row-dual {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }
    
    /* 5. ปรับตารางให้เลื่อนแนวนอนได้ */
    .table-container { overflow-x: auto; }
    
    /* 6. ปรับ Chat ให้เต็มจอ */
    .chat-room-wrapper { height: calc(100vh - 80px); }
    
    /* 7. ปรับ Font Input กัน iPhone Zoom */
    input, select, textarea { font-size: 16px !important; }
}