/* ============================================
   KMM-TH - Modern UI Stylesheet v2
   โทนสี: ขาว + ฟ้า (#2563EB, #3B82F6, #DBEAFE)
   Layout: Full-height, no body scroll
   ============================================ */

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

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Sarabun', 'Segoe UI', sans-serif;
    background: #F0F5FF;
    color: #1e293b;
    font-size: 15px;
}

a { text-decoration: none; color: inherit; }

/* ========== Full-height Layout ========== */
.wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100vh;         /* topbar เป็น fixed แล้ว ไม่กิน flow */
}

/* Content scrolls, not the page */
.content-area {
    flex: 1;
    margin-left: 270px;
    padding: 80px 20px 24px;    /* top: เว้น topbar ที่ fixed */
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    transition: margin-left 0.3s cubic-bezier(0.4,0,0.2,1);
}

.content-area.expanded { margin-left: 0; }

/* ========== Topbar - Fixed Pill (only content area, not over sidebar) ========== */
.topbar {
    position: fixed;
    top: 10px;
    left: calc(270px + 12px);   /* เริ่มหลัง sidebar */
    right: 12px;
    height: 58px;
    z-index: 850;               /* ต่ำกว่า sidebar (900) */
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(37,99,235,0.12);
    border: none;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 10px;
    transition: left 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* ปุ่ม Hamburger - pill ลอย */
.topbar .sidebar-toggle {
    background: #fff;
    border: none;
    color: #2563EB;
    font-size: 1rem;
    cursor: pointer;
    padding: 10px 13px;
    border-radius: 14px;
    transition: all 0.2s;
    display: flex; align-items: center;
    box-shadow: 0 2px 8px rgba(37,99,235,0.1);
    flex-shrink: 0;
}
.topbar .sidebar-toggle:hover {
    background: #EFF6FF;
    box-shadow: 0 4px 12px rgba(37,99,235,0.18);
    transform: translateY(-1px);
}

/* ชื่อหน้า - pill ลอย */
.topbar-title {
    background: #fff;
    border-radius: 14px;
    padding: 9px 18px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #1e293b;
 /* box-shadow: 0 2px 8px rgba(37,99,235,0.08); */
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

/* ส่วนขวา */
.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;   /* ดันไปขวาสุด */
}

/* กระดิ่ง - pill ลอย */
.notif-btn {
    position: relative;
    background: #fff;
    color: #2563EB;
    font-size: 1rem;
    padding: 10px 13px;
    border-radius: 14px;
    transition: all 0.2s;
    display: flex; align-items: center;
    box-shadow: 0 2px 8px rgba(37,99,235,0.1);
}
.notif-btn:hover {
    background: #EFF6FF;
    box-shadow: 0 4px 12px rgba(37,99,235,0.18);
    transform: translateY(-1px);
}
.notif-btn .badge {
    position: absolute; top: 4px; right: 4px;
    background: #ef4444; color: #fff;
    border-radius: 50%; font-size: 0.6rem;
    width: 15px; height: 15px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    border: 2px solid #F0F5FF;
}

/* User Chip - pill ลอย */
.user-chip {
    display: flex; align-items: center; gap: 8px;
    background: #fff;
    border-radius: 99px;
    padding: 5px 16px 5px 5px;
    cursor: default;
    box-shadow: 0 2px 8px rgba(37,99,235,0.1);
    transition: box-shadow 0.2s;
}
.user-chip:hover { box-shadow: 0 4px 12px rgba(37,99,235,0.16); }

.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563EB, #60a5fa);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}
.user-name { font-size: 0.82rem; font-weight: 600; color: #1e293b; }

/* ปุ่ม Logout - pill ลอย */
.btn-logout {
    background: #fff;
    color: #ef4444;
    border-radius: 14px;
    padding: 10px 13px;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex; align-items: center; gap: 6px;
    box-shadow: 0 2px 8px rgba(239,68,68,0.1);
}
.btn-logout:hover {
    background: #FEF2F2;
    box-shadow: 0 4px 12px rgba(239,68,68,0.2);
    transform: translateY(-1px);
}

/* ========== Sidebar - Modern Like-KM Style ========== */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;   /* sidebar เต็มความสูง */
    width: 270px;
    background: #fff;
    border-right: 1px solid #e8f0fe;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 900;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
    box-shadow: 2px 0 16px rgba(37,99,235,0.06);
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #DBEAFE; border-radius: 99px; }

.sidebar.collapsed { transform: translateX(-270px); }

/* Logo */
.sidebar-logo {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #f1f5f9;
}
.logo-icon-wrap {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #2563EB, #60a5fa);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(37,99,235,0.3);
    flex-shrink: 0;
}
.logo-text-wrap .logo-title { font-size: 1.15rem; font-weight: 800; color: #1e293b; }
.logo-text-wrap .logo-sub   { font-size: 0.7rem; color: #94a3b8; font-weight: 500; }

/* User card in sidebar */
.sidebar-user-card {
    margin: 12px 14px;
    background: linear-gradient(135deg, #EFF6FF, #DBEAFE);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex; align-items: center; gap: 10px;
    border: 1px solid #BFDBFE;
}
.sidebar-user-avatar {
    width: 38px; height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563EB, #3B82F6);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-info .sidebar-username { font-size: 0.88rem; font-weight: 700; color: #1e293b; }
.sidebar-user-info .sidebar-role {
    font-size: 0.72rem; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
    background: #2563EB; color: #fff;
    padding: 1px 8px; border-radius: 99px;
    margin-top: 2px;
}

/* Menu */
.sidebar-nav { flex: 1; padding: 6px 14px 14px; }

.nav-section { margin-bottom: 6px; }
.nav-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 10px 8px 4px;
}

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    color: #475569;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 2px;
}
.nav-item:hover {
    background: #F0F5FF;
    color: #2563EB;
}
.nav-item.active {
    background: linear-gradient(135deg, #2563EB, #3B82F6);
    color: #fff;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.nav-item.active .nav-icon { color: #fff; }
.nav-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: #F0F5FF;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem;
    color: #2563EB;
    flex-shrink: 0;
    transition: all 0.2s;
}
.nav-item:hover .nav-icon { background: #DBEAFE; }
.nav-item.active .nav-icon {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* Disabled menu item */
.nav-item-disabled {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    color: #cbd5e1;
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 2px;
    cursor: not-allowed;
    opacity: 0.7;
    user-select: none;
}

/* ========== Cards ========== */
.card {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 1px 4px rgba(37,99,235,0.06), 0 4px 16px rgba(37,99,235,0.04);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #f1f5f9;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}
.card-title { font-size: 0.95rem; font-weight: 700; color: #1e293b; display: flex; align-items: center; gap: 8px; }

/* ========== KPI Cards ========== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.kpi-card {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(37,99,235,0.06), 0 4px 16px rgba(37,99,235,0.04);
    border: 1px solid #f1f5f9;
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.5s ease both;
}
.kpi-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 3px;
}
.kpi-card:nth-child(1)::before { background: linear-gradient(90deg,#2563EB,#60a5fa); }
.kpi-card:nth-child(2)::before { background: linear-gradient(90deg,#7c3aed,#a78bfa); }
.kpi-card:nth-child(3)::before { background: linear-gradient(90deg,#0891b2,#22d3ee); }
.kpi-card:nth-child(4)::before { background: linear-gradient(90deg,#059669,#34d399); }

.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.kpi-label { font-size: 0.78rem; font-weight: 600; color: #64748b; }
.kpi-icon-box {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
}
.kpi-card:nth-child(1) .kpi-icon-box { background:#EFF6FF; color:#2563EB; }
.kpi-card:nth-child(2) .kpi-icon-box { background:#F5F3FF; color:#7c3aed; }
.kpi-card:nth-child(3) .kpi-icon-box { background:#ECFEFF; color:#0891b2; }
.kpi-card:nth-child(4) .kpi-icon-box { background:#ECFDF5; color:#059669; }
.kpi-value { font-size: 1.8rem; font-weight: 800; color: #0f172a; line-height: 1; }

/* kpi-icon แบบเก่า (reports/monthly, staff/dashboard) */
.kpi-icon {
    margin-top: 10px;
    font-size: 1.3rem;
    color: #BFDBFE;
    display: block;
}

/* ========== Charts ========== */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-card { animation: fadeIn 0.8s ease; }

/* ========== Progress Bars ========== */
.progress-bar-wrap { margin-bottom: 16px; }
.progress-label {
    display: flex; justify-content: space-between;
    font-size: 0.82rem; margin-bottom: 6px; font-weight: 600; color: #475569;
}
.progress-track {
    background: #F0F5FF; border-radius: 99px;
    height: 8px; overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 99px;
    background: linear-gradient(90deg, #2563EB, #60a5fa);
    transition: width 1.2s cubic-bezier(0.4,0,0.2,1);
    width: 0;
}
.progress-fill.danger  { background: linear-gradient(90deg,#ef4444,#f87171); }
.progress-fill.warning { background: linear-gradient(90deg,#f59e0b,#fbbf24); }
.progress-fill.success { background: linear-gradient(90deg,#10b981,#34d399); }

/* ========== Tables ========== */
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
    background: #F8FAFF; color: #64748b;
    padding: 10px 14px; text-align: left;
    font-weight: 700; white-space: nowrap;
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 2px solid #F0F5FF;
}
tbody td {
    padding: 11px 14px; border-bottom: 1px solid #F8FAFF;
    vertical-align: middle;
}
tbody tr:hover td { background: #FAFCFF; }
tbody tr:last-child td { border-bottom: none; }

/* ========== Badges ========== */
.badge-role { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; }
.badge-admin   { background: #EFF6FF; color: #2563EB; }
.badge-staff   { background: #F0FDF4; color: #16a34a; }
.badge-active  { background: #F0FDF4; color: #16a34a; }
.badge-inactive{ background: #FEF2F2; color: #dc2626; }
.badge-income  { background: #F0FDF4; color: #16a34a; }
.badge-expense { background: #FEF2F2; color: #dc2626; }

/* ========== Buttons ========== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 10px;
    font-size: 0.85rem; font-weight: 600; cursor: pointer;
    border: none; transition: all 0.2s;
    font-family: inherit;
}
.btn-primary   { background: linear-gradient(135deg,#2563EB,#3B82F6); color:#fff; box-shadow:0 4px 12px rgba(37,99,235,0.25); }
.btn-primary:hover { background: linear-gradient(135deg,#1d4ed8,#2563EB); box-shadow:0 6px 16px rgba(37,99,235,0.35); transform:translateY(-1px); }
.btn-success   { background: linear-gradient(135deg,#10b981,#34d399); color:#fff; box-shadow:0 4px 12px rgba(16,185,129,0.25); }
.btn-success:hover { filter:brightness(1.05); transform:translateY(-1px); }
.btn-danger    { background: linear-gradient(135deg,#ef4444,#f87171); color:#fff; box-shadow:0 4px 12px rgba(239,68,68,0.2); }
.btn-danger:hover  { filter:brightness(1.05); transform:translateY(-1px); }
.btn-warning   { background: linear-gradient(135deg,#f59e0b,#fbbf24); color:#fff; }
.btn-warning:hover { filter:brightness(1.05); }
.btn-secondary { background: #F0F5FF; color: #475569; border:1px solid #e2e8f0; }
.btn-secondary:hover { background: #E8F0FE; color: #2563EB; }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; border-radius: 8px; }

/* ========== Forms ========== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 0.82rem; font-weight: 700; color: #374151; margin-bottom: 7px; }
.form-control {
    width: 100%; padding: 10px 14px;
    border: 1.5px solid #e2e8f0; border-radius: 10px;
    font-size: 0.88rem; color: #1e293b;
    transition: all 0.2s;
    background: #fff;
    font-family: inherit;
}
.form-control:focus {
    outline: none; border-color: #3B82F6;
    box-shadow: 0 0 0 4px rgba(59,130,246,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ========== Alerts ========== */
.alert {
    padding: 12px 16px; border-radius: 12px;
    margin-bottom: 16px; font-size: 0.85rem; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
}
.alert-success { background: #F0FDF4; color: #15803d; border: 1px solid #BBF7D0; }
.alert-danger  { background: #FEF2F2; color: #b91c1c; border: 1px solid #FEE2E2; }
.alert-warning { background: #FFFBEB; color: #92400e; border: 1px solid #FDE68A; }
.alert-info    { background: #EFF6FF; color: #1d4ed8; border: 1px solid #BFDBFE; }

/* ========== Leaderboard ========== */
.leaderboard-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    transition: background 0.2s;
    margin-bottom: 4px;
}
.leaderboard-item:hover { background: #F8FAFF; }
.leaderboard-rank {
    width: 28px; height: 28px; border-radius: 8px;
    background: #F0F5FF; color: #2563EB;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.8rem; flex-shrink: 0;
}
.leaderboard-rank.gold   { background: linear-gradient(135deg,#fbbf24,#f59e0b); color:#fff; }
.leaderboard-rank.silver { background: linear-gradient(135deg,#94a3b8,#64748b); color:#fff; }
.leaderboard-rank.bronze { background: linear-gradient(135deg,#d97706,#92400e); color:#fff; }
.leaderboard-name { flex:1; font-size:0.88rem; font-weight:600; color:#1e293b; }
.leaderboard-score { font-size:0.8rem; color:#64748b; display:flex; gap:10px; }

/* ========== Login Page ========== */
.login-page {
    height: 100vh; overflow: hidden;
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 50%, #BFDBFE 100%);
    display: flex; align-items: center; justify-content: center;
}
.login-wrap { display: flex; width: 860px; max-width: 95vw; border-radius: 24px; overflow: hidden; box-shadow: 0 24px 80px rgba(37,99,235,0.18); }
.login-banner {
    flex: 1; background: linear-gradient(145deg,#1d4ed8,#2563EB,#3B82F6);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 30px; color: #fff;
}
.login-banner .banner-icon { font-size: 5rem; margin-bottom: 20px; animation: pulse 2.5s infinite; }
.login-banner h2 { font-size: 2rem; font-weight: 800; }
.login-banner p  { opacity: 0.8; margin-top: 8px; font-size: 0.95rem; text-align: center; }
.login-form-area {
    width: 380px; flex-shrink: 0;
    background: #fff;
    padding: 44px 36px;
    display: flex; flex-direction: column; justify-content: center;
}
.login-form-area h3 { font-size: 1.4rem; font-weight: 800; color: #0f172a; margin-bottom: 6px; }
.login-form-area p  { font-size: 0.85rem; color: #64748b; margin-bottom: 28px; }

/* ========== Page Header ========== */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 1.25rem; font-weight: 800; color: #0f172a; display: flex; align-items: center; gap: 8px; }
.page-header .breadcrumb { font-size: 0.75rem; color: #94a3b8; margin-top: 2px; }

/* ========== Filter Bar ========== */
.filter-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 0; }

/* ========== Animations ========== */
@keyframes fadeInUp {
    from { opacity:0; transform:translateY(16px); }
    to   { opacity:1; transform:translateY(0); }
}
@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }
@keyframes fadeInDown {
    from { opacity:0; transform:translateY(-20px); }
    to   { opacity:1; transform:translateY(0); }
}
@keyframes pulse {
    0%,100%{transform:scale(1);} 50%{transform:scale(1.06);}
}

/* ========== Responsive ========== */
@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2,1fr); }
    .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    html, body { overflow: hidden; }
    .sidebar { transform: translateX(-270px); }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.12); }
    .topbar { left: 12px !important; }   /* topbar เต็มความกว้างบนมือถือ */
    .content-area { margin-left: 0 !important; padding: 76px 12px 16px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .user-name { display: none; }
    .login-banner { display: none; }
    .login-wrap { width: 100%; max-width: 400px; border-radius: 20px; }
    .login-form-area { width: 100%; padding: 32px 24px; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .content-area { padding: 10px; }
}

/* ========== Sidebar Overlay (mobile) ========== */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.35); z-index: 850;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ========== Scrollbar inside content ========== */
.content-area::-webkit-scrollbar { width: 5px; }
.content-area::-webkit-scrollbar-track { background: transparent; }
.content-area::-webkit-scrollbar-thumb { background: #DBEAFE; border-radius: 99px; }

/* ========== Finance ========== */
.finance-kpi { grid-template-columns: repeat(3,1fr) !important; }
