:root {
    --shared-nav-height: 70px;
    --shared-content-width: 1280px;
}

body {
    padding-top: var(--shared-nav-height) !important;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", Tahoma, sans-serif !important;
    font-size: 16.5px !important;
    line-height: 1.55;
}

/* Legacy sidebars cleanup */
body > .sidebar, .app > .sidebar, .layout > .sidebar { display: none !important; }
body > .main, .app > .main, .layout > .main { margin-left: 0 !important; width: 100% !important; }

.app > .main.dashboard-main,
.layout > .main.realtime-main,
.app > .main.graph-main,
.app > .main.history-main,
.app > .main.report-main,
.app > .main.notifications-main {
    width: min(calc(100% - 2rem), var(--shared-content-width)) !important;
    max-width: var(--shared-content-width);
    margin: 0 auto !important;
    padding: 1.5rem 0 2.5rem;
}

.app, .layout { display: block !important; }

/* Give legacy page shells the same centered content width after hiding sidebars. */
body > main.main, .app > main.main, .layout > main.main {
    width: min(calc(100% - 2rem), var(--shared-content-width)) !important;
    max-width: var(--shared-content-width) !important;
    margin: 0 auto !important;
    box-sizing: border-box;
}

body > .wrap, body > main.wrap, .app > .wrap, .layout > .wrap,
.page-content, .page-shell {
    width: min(100% - 2rem, var(--shared-content-width)) !important;
    max-width: var(--shared-content-width) !important;
    margin: 0 auto !important;
    padding: 1.5rem 0 2.5rem;
}

body > .container, body > .container-fluid, .app > .container {
    width: min(calc(100% - 2rem), var(--shared-content-width)) !important;
    max-width: var(--shared-content-width) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-top: 1.5rem;
    padding-bottom: 2.5rem;
    box-sizing: border-box;
}

/* ==========================================================================
   SMART OVEN - PREMIUM NAVBAR SYSTEM
   ========================================================================== */

.shared-navbar, .shared-navbar * { box-sizing: border-box; }

.shared-navbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 10000;
    height: var(--shared-nav-height);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    color: #ffffff;
    background: linear-gradient(135deg, rgba(26, 16, 11, 0.96) 0%, rgba(40, 24, 15, 0.94) 50%, rgba(28, 17, 12, 0.97) 100%);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 2px solid rgba(181, 119, 58, 0.62);
    box-shadow: none;
}

/* Brand */
.shared-navbar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ffffff;
    text-decoration: none;
    font-size: 18px;
    font-weight: 800;
    white-space: nowrap;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.shared-navbar__brand:hover {
    color: #ffffff;
    transform: translateY(-1px);
    opacity: 0.95;
}

.shared-navbar__brand-mark {
    position: relative;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #1c110b;
    font-size: 20px;
    font-weight: 900;
    box-shadow: none;
    overflow: hidden;
}

.shared-navbar__brand-icon {
    position: relative;
    z-index: 1;
}

.shared-navbar__brand-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.shared-navbar__brand-text {
    letter-spacing: 0.5px;
}

.shared-navbar__brand-badge {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.35);
    text-transform: uppercase;
}

/* Navigation Links Container */
.shared-navbar__links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    height: 100%;
}

.shared-navbar__group {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* The Expressive Pill Buttons (ทำให้ปุ่มสื่อความหมายและสวยงาม) */
.shared-navbar__link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 14px;
    border-radius: 9999px;
    font-size: 14.5px;
    font-weight: 600;
    white-space: nowrap;
    color: #eedfd6;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.11);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

/* Keep every dropdown arrow comfortably inside its pill button. */
.shared-navbar__group-toggle {
    position: relative;
    padding-right: 38px;
}

.shared-navbar__link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
    box-shadow: none;
}

/* Group Button Open / Pressed */
.shared-navbar__group.is-open .shared-navbar__group-toggle {
    background: rgba(245, 158, 11, 0.16);
    border-color: #f59e0b;
    color: #ffffff;
    box-shadow: none;
}

.shared-navbar__group.is-open .shared-navbar__chevron {
    transform: translateY(-50%) rotate(180deg);
}

/* Active state */
.shared-navbar__link.is-active,
.shared-navbar__group.is-active-group .shared-navbar__group-toggle {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #1a0e07 !important;
    font-weight: 700;
    border: 1px solid rgba(254, 240, 138, 0.7);
    box-shadow: none;
}

.shared-navbar__link.is-active:hover,
.shared-navbar__group.is-active-group .shared-navbar__group-toggle:hover {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: #1a0e07 !important;
    transform: translateY(-1px);
    box-shadow: none;
}

/* Icons inside the group toggle button */
.shared-navbar__btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.shared-navbar__btn-icon svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.shared-navbar__link:hover .shared-navbar__btn-icon svg {
    transform: scale(1.1);
}

.shared-navbar__chevron {
    position: absolute;
    top: 50%;
    right: 21px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    opacity: 0.75;
    transform: translateY(-50%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
}

.shared-navbar__chevron svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.shared-navbar__link.is-active .shared-navbar__chevron {
    opacity: 0.95;
}

/* Dropdown Floating Glass Card */
.shared-navbar__dropdown {
    display: none;
    position: absolute;
    z-index: 10001;
    top: calc(100% + 10px);
    left: 0;
    min-width: 300px;
    padding: 8px;
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 16px;
    background: rgba(28, 17, 11, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(255, 255, 255, 0.06);
    flex-direction: column;
    gap: 4px;
}

@keyframes navDropdownFade {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.shared-navbar__group.is-open .shared-navbar__dropdown {
    display: flex;
    animation: navDropdownFade 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.shared-navbar__dropdown-header {
    padding: 6px 12px 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.shared-navbar__dropdown-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(245, 158, 11, 0.9);
}

/* Dropdown Links with Visual Identity */
.shared-navbar__dropdown-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 12px;
    color: #e5d7cc;
    text-decoration: none;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.shared-navbar__dropdown-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transform: translateX(4px);
}

.shared-navbar__dropdown-link.is-active {
    background: rgba(245, 158, 11, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Icon Box inside Dropdown */
.shared-navbar__item-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    flex-shrink: 0;
    transition: transform 0.18s ease;
}

.shared-navbar__dropdown-link:hover .shared-navbar__item-icon {
    transform: scale(1.08);
}

.shared-navbar__item-icon svg {
    width: 19px;
    height: 19px;
    stroke: currentColor;
}

/* Color Accent Themes for Icons */
.accent-amber {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.25);
}
.accent-blue {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.25);
}
.accent-emerald {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
}
.accent-rose {
    background: rgba(244, 63, 94, 0.15);
    color: #fb7185;
    border: 1px solid rgba(244, 63, 94, 0.25);
}
.accent-violet {
    background: rgba(139, 92, 246, 0.15);
    color: #c084fc;
    border: 1px solid rgba(139, 92, 246, 0.25);
}

/* Dropdown Content Stack */
.shared-navbar__item-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.shared-navbar__item-title {
    font-size: 14.5px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.25;
}

.shared-navbar__dropdown-link.is-active .shared-navbar__item-title {
    color: #fde68a;
    font-weight: 700;
}

.shared-navbar__item-desc {
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.52);
    line-height: 1.35;
    margin-top: 2px;
}

.shared-navbar__item-active-dot {
    color: #f59e0b;
    font-size: 10px;
    margin-left: auto;
    filter: drop-shadow(0 0 6px #f59e0b);
}

/* Live Clock Badge */
.shared-navbar__clock {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 5px 14px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    line-height: 1.15;
    user-select: none;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.shared-navbar__clock-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.shared-navbar__clock-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulseClock 2s infinite ease-in-out;
}

@keyframes pulseClock {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.shared-navbar__clock-date {
    font-size: 11px;
    color: #fbd38d;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.shared-navbar__clock-time {
    font-size: 15.5px;
    font-weight: 800;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: #ffffff;
    letter-spacing: 0.8px;
    text-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

/* Activity Bell */
.activity-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    align-self: center;
    flex-shrink: 0;
    margin: 0;
}

.shared-navbar__bell-btn,
.shared-navbar .activity-bell button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    padding: 0;
    margin: 0;
    line-height: 1;
    vertical-align: middle;
    align-self: center;
    box-sizing: border-box;
}

.shared-navbar__bell-btn:hover,
.shared-navbar .activity-bell button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(245, 158, 11, 0.4);
    transform: translateY(-1px);
}

.shared-navbar__bell-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    line-height: 0;
}

.shared-navbar__bell-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    display: block;
}

.shared-navbar__bell-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 10px;
    background: #ef4444;
    color: #ffffff;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.shared-navbar__activity-panel {
    position: absolute;
    right: 0;
    top: 54px;
    width: min(390px, calc(100vw - 24px));
    max-height: 70vh;
    overflow-y: auto;
    padding: 16px;
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 16px;
    background: rgba(28, 17, 11, 0.98);
    backdrop-filter: blur(24px);
    box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.75);
    color: #f5efe8;
    z-index: 10002;
}

.shared-navbar__activity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 10px;
    margin-bottom: 12px;
}

.shared-navbar__activity-header h2 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    color: #fbbf24;
}

.shared-navbar__activity-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

/* User Profile & Logout */
.shared-navbar__user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.shared-navbar__user-info {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 3px 10px 3px 4px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.shared-navbar__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #b45309);
    color: #1a0e07;
    font-weight: 800;
    font-size: 14px;
    display: grid;
    place-items: center;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.shared-navbar__user-details {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.shared-navbar__username {
    font-size: 13.5px;
    font-weight: 700;
    color: #ffffff;
}

.shared-navbar__role {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.shared-navbar__role--admin {
    color: #fbbf24;
}

.shared-navbar__role--user {
    color: #60a5fa;
}

.shared-navbar__logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fca5a5;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.shared-navbar__logout:hover {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.45);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.shared-navbar__guest-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    border-radius: 9999px;
    background: linear-gradient(135deg, #d97706, #b45309);
    border: 1px solid rgba(251, 191, 36, 0.4);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}

.shared-navbar__guest-login-btn:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
    color: #ffffff;
}

.shared-navbar__guest-login-btn svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
}

.shared-navbar__logout-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* Mobile Toggle */
.shared-navbar__mobile-logout { display: none; }
.shared-navbar__toggle {
    display: none;
    margin-left: auto;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.shared-navbar__toggle:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(245, 158, 11, 0.4);
}

/* Responsive Overrides */
@media (max-width: 1024px) {
    .shared-navbar { padding: 0 16px; gap: 12px; }
    .shared-navbar__link { padding: 0 11px; font-size: 13.5px; }
    .shared-navbar__brand-text { font-size: 16px; }
    .shared-navbar__dropdown { min-width: 270px; }
}

@media (max-width: 980px) {
    .shared-navbar__toggle { display: grid; place-items: center; }
    .shared-navbar__clock { padding: 4px 10px; margin-left: auto; }
    .shared-navbar__clock-date { display: none; }
    .shared-navbar__clock-time { font-size: 13.5px; }
    .shared-navbar__user { display: none; }
    
    .shared-navbar__links {
        display: none;
        position: absolute;
        top: var(--shared-nav-height);
        left: 0;
        right: 0;
        height: auto;
        max-height: calc(100vh - var(--shared-nav-height));
        overflow-y: auto;
        padding: 16px;
        background: rgba(24, 15, 10, 0.98);
        backdrop-filter: blur(24px);
        border-bottom: 2px solid rgba(181, 119, 58, 0.62);
        box-shadow: 0 16px 36px rgba(0, 0, 0, 0.7);
        flex-direction: column;
        gap: 10px;
    }
    
    .shared-navbar__links.is-open {
        display: flex;
    }
    
    .shared-navbar__group {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
    }
    
    .shared-navbar__link {
        width: 100%;
        justify-content: space-between;
        height: 46px;
        padding: 0 16px;
        font-size: 15px;
    }
    
    .shared-navbar__dropdown {
        position: static;
        width: 100%;
        min-width: 0;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.04);
        margin-top: 6px;
        border: 1px solid rgba(255, 255, 255, 0.08);
    }
    
    .shared-navbar__mobile-logout {
        display: flex;
        align-items: center;
        gap: 10px;
        color: #fca5a5;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        margin-top: 8px;
        padding-top: 14px;
        width: 100%;
    }
}

@media (max-width: 520px) {
    .shared-navbar__clock { display: none; }
    .shared-navbar__brand-badge { display: none; }
}

@media print {
    @page { margin: 12mm; }
    html, body { padding-top: 0 !important; background: #fff !important; }
    .shared-navbar, .live-devices, #activityPanel { display: none !important; }
    .app > .main.report-main { width: 100% !important; max-width: none; margin: 0 !important; padding: 0 !important; }
}

/* Visitor Counter Pill in Navbar */
.visitor-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.28);
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 12px;
    color: #a7f3d0;
    margin-right: 6px;
    transition: all 0.2s ease;
    user-select: none;
    white-space: nowrap;
}
.visitor-stat-pill:hover {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(16, 185, 129, 0.5);
    transform: translateY(-1px);
}
.visitor-icon { font-size: 13px; }
.visitor-label { color: #d1fae5; font-size: 11px; }
.visitor-total { color: #34d399; font-weight: 700; font-family: monospace; }
.visitor-today-label { color: #fde68a; font-size: 11px; }
.visitor-today { color: #fbbf24; font-weight: 700; font-family: monospace; }
.visitor-sep { color: rgba(255, 255, 255, 0.2); margin: 0 1px; }

@media (max-width: 860px) {
    .visitor-stat-pill { display: none; }
}

