/* ==========================================
   BASE CSS & VARIABLES
========================================== */
:root {
    --bma-green: #00963C;
    --bma-green-hover: #007a30;
    --bma-green-dark: #005a24;
    --bma-green-light: #e8f5e9;
    --bma-green-mid: #c8e6c9;
    --text-color: #1a2332;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --bg-page: #f0f4f8;
    --bg-card: #ffffff;
    
    --sidebar-width: 270px;
    --sidebar-collapsed-width: 80px;
    --header-height: 80px; /* 🌟 คงมาตรฐาน กทม. ไว้ที่ 150px */
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.05);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================
   FONTS
========================================== */
@font-face {
    font-family: 'Sao Chingcha';
    src: url("../fonts/saochingcha-light.woff") format('woff');
    font-weight: 300;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sao Chingcha';
    src: url("../fonts/saochingcha-regular.woff") format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Sao Chingcha';
    src: url("../fonts/saochingcha-bold-webfont.woff2") format('woff2'),
         url("../fonts/saochingcha-bold-webfont.woff") format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Sao Chingcha', sans-serif;
    font-weight: 700;
    letter-spacing: 0.5px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { scroll-behavior: smooth; overflow-x: hidden; }

body {
    font-family: 'Kanit', sans-serif;
    background: var(--bg-page);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    -webkit-font-smoothing: antialiased;
}

/* ป้องกัน Google Translate ดันหน้าเว็บ */
.skiptranslate iframe { display: none !important; }
body { top: 0 !important; position: static !important; }
#google_translate_element { display: none; }

a { text-decoration: none; }
ul { list-style: none; }

/* ==========================================
   SIDEBAR NAVIGATION
========================================== */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: #ffffff;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    z-index: 1001;
    transition: width var(--transition), transform var(--transition);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-header-inner {
    display: flex; align-items: center; width: 100%; transition: justify-content 0.2s;
}

.desktop-toggle {
    background: none; border: none;
    font-size: 1.3rem; color: var(--text-color);
    cursor: pointer; width: 40px; height: 40px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
    margin-right: 8px; flex-shrink: 0;
}
.desktop-toggle:hover { background: #f1f5f9; color: var(--bma-green); }

.sidebar-logo {
    display: flex; 
    align-items: center; 
    gap: 12px; 
    text-decoration: none; 
    overflow: hidden; 
    flex: 1;
}

.sidebar-logo img { 
    height: 45px;
    width: auto;
    flex-shrink: 0; 
    transition: var(--transition); 
}

.sidebar-logo .logo-text { 
    font-family: 'Sao Chingcha', sans-serif;
    font-size: 1.05rem; 
    font-weight: 700; 
    color: var(--bma-green); 
    transition: opacity 0.2s; 
    white-space: nowrap; 
    letter-spacing: 0.5px;
    margin: 0;
}

.sidebar-menu {
    flex: 1; overflow-y: auto; padding: 20px 14px;
    display: flex; flex-direction: column; gap: 6px;
}
.sidebar-menu::-webkit-scrollbar { width: 4px; }
.sidebar-menu::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

.nav-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; border-radius: var(--radius-md);
    color: var(--text-muted); font-weight: 500; font-size: 0.95rem;
    transition: all 0.2s; white-space: nowrap; overflow: hidden;
}
.nav-item i { font-size: 1.2rem; width: 24px; text-align: center; flex-shrink: 0; }
.nav-item .link-text { transition: opacity 0.2s; }
.nav-item:hover { background: var(--bma-green-light); color: var(--bma-green); }
.nav-item.active { background: var(--bma-green); color: #fff; box-shadow: 0 4px 12px rgba(0,150,60,0.25); }

.sidebar-footer { padding: 20px 14px; border-top: 1px solid var(--border-color); }
.nav-item.logout { color: #ef4444; }
.nav-item.logout:hover { background: #fef2f2; color: #dc2626; }

/* โหมดพับเมนู */
.sidebar.collapsed { width: var(--sidebar-collapsed-width); }
.sidebar.collapsed .sidebar-header { padding: 0; }
.sidebar.collapsed .sidebar-header-inner { justify-content: center; height: 100%; padding-bottom: 20px; align-items: flex-end; }
.sidebar.collapsed .sidebar-logo { display: none; width: 0; opacity: 0; }
.sidebar.collapsed .desktop-toggle { margin-right: 0; }
.sidebar.collapsed .link-text { opacity: 0; width: 0; display: none; }
.sidebar.collapsed .nav-item { padding: 12px; justify-content: center; }
.sidebar.collapsed .nav-item i { margin: 0; font-size: 1.3rem; }

/* ==========================================
   MAIN CONTENT WRAPPER
========================================== */
.main-wrapper {
    flex: 1; margin-left: var(--sidebar-width);
    display: flex; flex-direction: column; min-height: 100vh;
    transition: margin-left var(--transition), width var(--transition);
    width: calc(100% - var(--sidebar-width));
}

.main-wrapper.collapsed {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

/* ==========================================
   TOP HEADER (แถบสีเขียว กทม.)
========================================== */
.top-header {
    height: var(--header-height); /* ใช้ตัวแปร 80px */
    min-height: var(--header-height);
    max-height: var(--header-height);
    background: var(--bma-green);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-bottom: 2px solid rgba(255,255,255,0.2); 
    display: flex; 
    align-items: center; /* 🌟 จัดกึ่งกลางแนวตั้ง */
    justify-content: space-between;
    padding: 0 24px; /* 🌟 ลบ padding-bottom ออก */
    position: sticky; top: 0; z-index: 999;
}

.header-left { display: flex; align-items: center; gap: 20px; }

.mobile-toggle-btn {
    background: none; border: none; font-size: 1.4rem; 
    color: #ffffff;
    cursor: pointer; width: 40px; height: 40px; border-radius: var(--radius-sm);
    display: none; align-items: center; justify-content: center; transition: background 0.2s;
}
.mobile-toggle-btn:hover { background: rgba(255,255,255,0.15); color: #ffffff; }

.header-right { display: flex; align-items: center; gap: 16px; }

.header-stats-group { display: flex; align-items: center; gap: 8px; }
.stat-pill {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 14px; border-radius: var(--radius-full);
    font-size: 0.85rem; font-weight: 600; white-space: nowrap;
}
.stat-pill.online { background: #ffffff; color: var(--bma-green-dark); border: none; }
.stat-pill.users { background: #f0f9ff; color: #0369a1; border: none; }
.stat-pill.logins { background: #fffbeb; color: #b45309; border: none; }

.pulsating-dot {
    width: 8px; height: 8px; background: #22c55e; border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(34,197,94,0.7); animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
    0%  { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
    70% { box-shadow: 0 0 0 6px rgba(34,197,94,0); }
    100%{ box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

/* ปุ่มสลับภาษา (พื้นหลังสีขาวล้วน) */
.lang-switch-pill {
    display: flex; align-items: center; 
    background: #ffffff; 
    border-radius: 20px; padding: 4px; cursor: pointer;
    border: 1px solid var(--border-color); 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
    transition: all 0.3s; user-select: none;
}
.lang-switch-pill:hover { border-color: var(--bma-green); }
.lang-option {
    padding: 4px 12px; border-radius: 16px; font-size: 0.85rem;
    font-weight: 600; color: var(--text-muted); transition: all 0.3s;
}
.lang-option.active {
    background: var(--bma-green); color: #ffffff; 
    box-shadow: 0 2px 4px rgba(0,150,60,0.2);
}

.notification-wrapper { position: relative; display: flex; align-items: center; }

/* ปุ่มกระดิ่ง (พื้นหลังสีขาวล้วน ไอคอนสีเขียว) */
.btn-bell {
    background: #ffffff; 
    border: none; 
    font-size: 1.2rem; color: var(--bma-green); 
    cursor: pointer; width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; 
    transition: 0.2s; position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.btn-bell:hover { background: var(--bma-green-light); }
.bell-badge {
    position: absolute; top: -2px; right: -2px; background: #ef4444; color: white;
    font-size: 0.65rem; font-weight: bold; width: 18px; height: 18px;
    display: flex; align-items: center; justify-content: center; border-radius: 50%;
    border: 2px solid var(--bma-green); display: none;
}

/* Dropdown แจ้งเตือน */
.noti-dropdown {
    position: absolute; top: 60px; right: 0; /* 🌟 ขยับระยะร่นขึ้นมาให้ติดกับแถบ 80px */
    width: 360px; max-width: 90vw; background: white;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); border: 1px solid var(--border-color);
    display: none; flex-direction: column; z-index: 1000; overflow: hidden;
}
.noti-dropdown.active { display: flex; animation: slideDown 0.2s ease; }
.noti-header { padding: 14px 20px; border-bottom: 1px solid var(--border-color); font-weight: 600; color: var(--text-color); background: #f8fffe; }
.noti-body { max-height: 380px; overflow-y: auto; }
.noti-item { padding: 14px 20px; border-bottom: 1px solid #f1f5f9; display: flex; gap: 14px; transition: background 0.2s; align-items: flex-start; }
.noti-item:hover { background: #f8fafc; }
.noti-icon { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1.1rem; }
.noti-icon.danger { background: #fee2e2; color: #ef4444; }
.noti-icon.warning { background: #fef3c7; color: #f59e0b; }
.noti-icon.info { background: #e0f2fe; color: #3b82f6; }
.noti-content h4 { margin: 0 0 4px 0; font-size: 0.95rem; color: var(--text-color); }
.noti-content p { margin: 0; font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }
.noti-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

/* โปรไฟล์ผู้ใช้งาน */
.profile-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 12px 4px 4px; border-radius: 50px; border: 1px solid transparent; transition: 0.2s; }
.profile-menu:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.3); }
.profile-pic { width: 44px; height: 44px; border-radius: 50%; border: 2px solid #ffffff; object-fit: cover; } 
.profile-name { font-weight: 600; font-size: 0.95rem; color: #ffffff; } 
.profile-role { font-size: 0.8rem; color: #e2e8f0; } 

/* ==========================================
   MAIN CONTENT & FOOTER
========================================== */
main { flex: 1; padding: 24px; }

.main-footer {
    background: #fff; color: var(--text-muted); text-align: center;
    padding: 24px; border-top: 1px solid var(--border-color);
    font-size: 0.88rem; line-height: 1.6;
}

.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: none; opacity: 0; transition: opacity 0.3s;
}
.sidebar-overlay.active { display: block; opacity: 1; }

/* ==========================================
   RESPONSIVE DESIGN 
========================================== */
@media (max-width: 1024px) {
    .stat-pill .stat-label { display: none; }
    .profile-name, .profile-role { display: none; }
    .profile-menu { padding: 4px; }
}

@media (max-width: 768px) {
    :root { --header-height: 100px; } /* ในมือถือลดให้เหลือ 100px กำลังสวย */
    .desktop-toggle { display: none; }
    .mobile-toggle-btn { display: flex; margin-right: 8px; }
    
    .sidebar { transform: translateX(-100%); width: 270px; }
    .sidebar.mobile-active { transform: translateX(0); }
    
    .sidebar-header { justify-content: center; padding: 0; }
    .sidebar-header-inner { justify-content: center; height: 100%; align-items: flex-end; padding-bottom: 15px;}
    
    .main-wrapper { margin-left: 0; width: 100%; }
    .main-wrapper.collapsed { margin-left: 0; width: 100%; }
    
    main { padding: 16px 12px; }
    .header-left { gap: 10px; }
    .stat-pill.users, .stat-pill.logins { display: none; }
    .sidebar-logo img { height: 50px; }
    .noti-dropdown { top: 60px; }
}