/* ============================================================
   PERFORMANCE HUB — Layout หลัก: Sidebar + Topbar + Page container
   ============================================================ */
html, body { height: 100%; }
body {
    font-family: 'Inter', 'Sarabun', sans-serif;
    background: var(--bg-warm);
    color: var(--text-main);
    margin: 0;
}

/* ---------- App Shell ---------- */
#appShell { display: flex; height: 100vh; overflow: hidden; }
.main-area { flex-grow: 1; display: flex; flex-direction: column; min-width: 0; }
#pageContainer { flex-grow: 1; overflow-y: auto; padding: 18px 22px 40px; }
.page-view { animation: pageIn .25s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Sidebar ---------- */
#sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: linear-gradient(180deg, var(--green-900) 0%, var(--green-800) 55%, var(--green-700) 100%);
    color: #fff; display: flex; flex-direction: column;
    position: relative; z-index: 1040;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo {
    width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
    background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.18);
    display: flex; align-items: center; justify-content: center; font-size: 1.15rem; color: #BBF7D0;
}
.brand-name { font-weight: 800; font-size: .98rem; letter-spacing: .3px; line-height: 1.2; }
.brand-sub { font-size: .62rem; color: rgba(255,255,255,.55); letter-spacing: .5px; }

.sidebar-nav { flex-grow: 1; overflow-y: auto; padding: 10px 0 14px; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

.nav-section-title {
    font-size: .62rem; letter-spacing: 1.6px; text-transform: uppercase;
    color: rgba(255,255,255,.38); margin: 14px 22px 5px; font-weight: 700;
}
.side-nav-item {
    display: flex; align-items: center; gap: 12px;
    width: calc(100% - 20px); margin: 3px 10px; padding: 10px 14px;
    border: none; background: transparent; color: rgba(255,255,255,.78);
    border-radius: 10px; font-weight: 500; font-size: .88rem;
    cursor: pointer; transition: all .22s ease; text-align: left; font-family: inherit;
}
.side-nav-item i { width: 20px; text-align: center; font-size: .98rem; }
.side-nav-item:hover { background: rgba(255,255,255,.09); color: #fff; }
.side-nav-item.active {
    background: #fff; color: var(--primary-hover);
    font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.22);
}

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1);
    border-radius: 12px; padding: 10px 12px;
}
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
    background: var(--accent-green); color: #06301B;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 1rem; text-transform: uppercase;
}
.user-chip-info { min-width: 0; flex-grow: 1; }
.user-chip-name { font-size: .82rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-role { font-size: .64rem; color: #BBF7D0; }
.user-chip-logout { color: rgba(255,255,255,.6); font-size: .95rem; text-decoration: none; padding: 6px; border-radius: 8px; transition: all .2s; }
.user-chip-logout:hover { color: #FECACA; background: rgba(239,68,68,.15); }

/* ---------- Topbar ---------- */
.topbar {
    flex-shrink: 0; background: var(--white);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 62px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.hamburger {
    display: none; border: 1px solid var(--border-color); background: #fff;
    width: 38px; height: 38px; border-radius: 10px; color: var(--text-muted); font-size: 1rem;
}
.page-title { font-size: 1.02rem; font-weight: 800; margin: 0; color: var(--text-main); line-height: 1.25; }
.page-subtitle { font-size: .68rem; color: var(--text-muted); margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-clock { text-align: right; line-height: 1.25; }
.clock-date { font-size: .68rem; color: var(--text-muted); }
.clock-time { font-size: 1.05rem; font-weight: 800; color: var(--primary-green); font-variant-numeric: tabular-nums; }
.conn-pill {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-warm); border: 1px solid var(--border-color);
    border-radius: 20px; padding: 5px 12px; font-size: .68rem; color: var(--text-muted); font-weight: 600;
    white-space: nowrap;
}
.topbar-logout { color: var(--text-muted); font-size: 1rem; padding: 8px; border-radius: 8px; }
.topbar-logout:hover { color: var(--danger); background: #FEF2F2; }

.sidebar-backdrop { display: none; }

/* ---------- Responsive: mobile sidebar off-canvas ---------- */
@media (max-width: 991.98px) {
    .hamburger { display: inline-flex; align-items: center; justify-content: center; }
    #sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-105%); transition: transform .28s ease; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
    #appShell.sidebar-open #sidebar { transform: translateX(0); }
    #appShell.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
    #pageContainer { padding: 14px 12px 40px; }
    .topbar { padding: 10px 12px; }
}

/* ---------- Login ---------- */
#loginSection {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #F4F6F5 0%, #DCF1E4 100%); overflow: auto;
}
.login-card {
    background: rgba(255,255,255,.95); backdrop-filter: blur(10px);
    border-radius: 20px; padding: 40px; width: 90%; max-width: 400px;
    box-shadow: 0 20px 40px rgba(22,163,74,.15); border: 1px solid rgba(255,255,255,.5);
}

/* ---------- Print: พิมพ์เฉพาะหน้ารายงาน ---------- */
@media print {
    #sidebar, .topbar, .sidebar-backdrop, .no-print, .hamburger { display: none !important; }
    #appShell { display: block !important; height: auto !important; overflow: visible !important; }
    .main-area, #pageContainer { height: auto !important; overflow: visible !important; padding: 0 !important; display: block !important; }
    .page-view { display: none !important; }
    #page-report { display: block !important; }
    body { background: #fff !important; }
    .glass-card { box-shadow: none !important; border: 1px solid #D1D5DB !important; break-inside: avoid; }
}
