:root {
    --sidebar-w: 284px;
    --sc-nav-bg: #ffffff;
    --sc-nav-border: #e2e8f0;
    --sc-nav-border-strong: #cbd5e1;
    --sc-nav-text: #0f172a;
    --sc-nav-muted: #64748b;
    --sc-nav-primary: #2563eb;
    --sc-nav-primary-soft: #eff6ff;
    --sc-nav-danger: #dc2626;
    --sc-nav-shadow: 0 18px 42px rgba(15, 23, 42, .14);
    --bg: #f4f6f9;
    --panel: #ffffff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-soft: #64748b;
    --primary: #2563eb;
    --danger: #dc2626;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans Thai', 'Sarabun', sans-serif;
    -webkit-font-smoothing: antialiased;
}
body.sc-has-sidebar { padding-left: var(--sidebar-w); }
a { text-decoration: none; }

.main-content {
    min-height: calc(100vh - 76px);
    padding: 2rem 2.5rem;
}

.sc-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sc-nav-bg);
    color: var(--sc-nav-text);
    border-right: 1px solid var(--sc-nav-border);
    box-shadow: 2px 0 16px rgba(15, 23, 42, .035);
    z-index: 1040;
    transition: transform .22s ease;
}
.sc-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
.sc-brand {
    min-height: 84px;
    padding: 18px 18px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--sc-nav-border);
    color: var(--sc-nav-text);
}
.sc-brand:hover { color: var(--sc-nav-text); }
.sc-brand-icon,
.sc-mobile-brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #fff;
    box-shadow: 0 7px 18px rgba(37, 99, 235, .20);
}
.sc-brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 1.12rem;
}
.sc-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.sc-brand-title {
    color: var(--sc-nav-text);
    font-size: 1.05rem;
    line-height: 1.25;
    font-weight: 800;
    letter-spacing: .01em;
}
.sc-brand-sub {
    color: var(--sc-nav-muted);
    font-size: .72rem;
    line-height: 1.3;
    margin-top: 3px;
}

.sc-menu-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    padding: 16px 12px 22px;
}
.sc-menu-scroll::-webkit-scrollbar { width: 5px; }
.sc-menu-scroll::-webkit-scrollbar-track { background: transparent; }
.sc-menu-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
.sc-menu-section { margin: 0 0 18px; }
.sc-menu-section:last-child { margin-bottom: 0; }
.sc-menu-label {
    padding: 0 10px 7px;
    color: #94a3b8;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .055em;
    text-transform: uppercase;
}
.sc-menu-section.is-current .sc-menu-label { color: #64748b; }
.sc-menu-list { display: grid; gap: 3px; }
.sc-menu-link {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 11px;
    color: #475569;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 600;
    line-height: 1.35;
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
    position: relative;
}
.sc-menu-link:hover {
    color: var(--sc-nav-primary);
    background: #f8fafc;
    border-color: #eef2f7;
    transform: translateX(1px);
}
.sc-menu-link.is-active {
    color: #1d4ed8;
    background: var(--sc-nav-primary-soft);
    border-color: #dbeafe;
    font-weight: 700;
}
.sc-menu-link.is-active::before {
    content: '';
    position: absolute;
    width: 3px;
    left: -12px;
    top: 8px;
    bottom: 8px;
    border-radius: 0 4px 4px 0;
    background: var(--sc-nav-primary);
}
.sc-menu-icon {
    width: 22px;
    flex: 0 0 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: .98rem;
}
.sc-menu-link:hover .sc-menu-icon,
.sc-menu-link.is-active .sc-menu-icon { color: var(--sc-nav-primary); }
.sc-menu-title { min-width: 0; }

.sc-sidebar-footer {
    flex: 0 0 auto;
    padding: 14px;
    border-top: 1px solid var(--sc-nav-border);
    background: #fbfcfe;
}
.sc-user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin-bottom: 12px;
}
.sc-user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 42px;
    background: linear-gradient(135deg, #334155, #0f172a);
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    box-shadow: 0 3px 9px rgba(15, 23, 42, .12);
}
.sc-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}
.sc-user-info .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--sc-nav-text);
    font-size: .86rem;
    font-weight: 750;
}
.sc-user-info .role {
    margin-top: 3px;
    color: #475569;
    font-size: .7rem;
    font-weight: 700;
}
.sc-user-info .scope {
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #94a3b8;
    font-size: .67rem;
}
.sc-user-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
}
.sc-action-btn {
    width: 100%;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 1px solid var(--sc-nav-border);
    border-radius: 9px;
    background: #fff;
    color: #64748b;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}
button.sc-action-btn { cursor: pointer; font: inherit; }
.sc-action-btn:hover {
    color: var(--sc-nav-primary);
    border-color: #bfdbfe;
    background: #f8fbff;
    transform: translateY(-1px);
}
.sc-action-btn.logout:hover {
    color: var(--sc-nav-danger);
    border-color: #fecaca;
    background: #fff7f7;
}
.sc-notif-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: .59rem;
    font-weight: 800;
    line-height: 1;
}

.sc-dropdown-shell { position: relative; min-width: 0; }
.sc-panel-dropdown {
    position: absolute;
    left: calc(100% + 16px);
    bottom: 0;
    width: min(380px, calc(100vw - 32px));
    overflow: hidden;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-8px) scale(.985);
    transform-origin: bottom left;
    background: #fff;
    border: 1px solid var(--sc-nav-border);
    border-radius: 14px;
    box-shadow: var(--sc-nav-shadow);
    transition: opacity .16s ease, transform .16s ease, visibility .16s ease;
    z-index: 1060;
}
.sc-dropdown-shell.open .sc-panel-dropdown {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0) scale(1);
}
.dd-header {
    min-height: 52px;
    padding: 11px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: #f8fafc;
    border-bottom: 1px solid var(--sc-nav-border);
}
.dd-header h6 {
    margin: 0;
    color: var(--sc-nav-text);
    font-size: .88rem;
    font-weight: 800;
}
.dd-action {
    padding: 5px 7px;
    border: 0;
    background: transparent;
    color: var(--sc-nav-primary);
    font-family: inherit;
    font-size: .72rem;
    font-weight: 700;
    cursor: pointer;
}
.notif-list { max-height: 340px; overflow-y: auto; }
.notif-item {
    padding: 11px 13px;
    display: flex;
    gap: 9px;
    color: var(--sc-nav-text);
    border-bottom: 1px solid #f1f5f9;
    transition: background .14s ease;
}
.notif-item:hover { background: #f8fafc; color: var(--sc-nav-text); }
.notif-item.unread { background: #f5f9ff; }
.notif-state {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    margin-top: 6px;
    border-radius: 50%;
    background: transparent;
}
.notif-item.unread .notif-state { background: var(--sc-nav-primary); }
.notif-content { min-width: 0; display: flex; flex-direction: column; }
.notif-message { color: #334155; font-size: .81rem; line-height: 1.48; }
.notif-time { margin-top: 5px; color: #94a3b8; font-size: .67rem; }
.notif-empty {
    min-height: 128px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #94a3b8;
    font-size: .8rem;
}
.notif-empty i { font-size: 1.4rem; }
.dd-footer-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sc-nav-primary);
    border-top: 1px solid var(--sc-nav-border);
    background: #fff;
    font-size: .75rem;
    font-weight: 700;
}
.dd-footer-link:hover { background: #f8fafc; color: #1d4ed8; }

.sc-mobile-header,
.sc-mobile-overlay { display: none; }

@media (max-width: 991.98px) {
    :root { --sidebar-w: 284px; }
    body.sc-has-sidebar { padding-left: 0; padding-top: 62px; }
    .main-content { padding: 1.25rem 1rem; }
    .sc-mobile-header {
        position: fixed;
        inset: 0 0 auto 0;
        height: 62px;
        padding: 0 14px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        background: rgba(255, 255, 255, .97);
        border-bottom: 1px solid var(--sc-nav-border);
        box-shadow: 0 2px 10px rgba(15, 23, 42, .04);
        backdrop-filter: blur(12px);
        z-index: 1030;
    }
    .sc-mobile-brand {
        display: inline-flex;
        align-items: center;
        gap: 9px;
        color: var(--sc-nav-text);
        font-weight: 800;
        font-size: .94rem;
    }
    .sc-mobile-brand-icon { width: 31px; height: 31px; border-radius: 9px; font-size: .78rem; }
    .sc-hamburger {
        width: 42px;
        height: 42px;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        border: 1px solid var(--sc-nav-border);
        border-radius: 10px;
        background: #fff;
        cursor: pointer;
    }
    .sc-hamburger span {
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: #475569;
        transition: transform .18s ease, opacity .18s ease;
    }
    .sc-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .sc-hamburger.open span:nth-child(2) { opacity: 0; }
    .sc-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
    .sc-sidebar { transform: translateX(-100%); }
    .sc-sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(15, 23, 42, .16); }
    .sc-mobile-overlay {
        position: fixed;
        inset: 0;
        display: block;
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        background: rgba(15, 23, 42, .42);
        transition: opacity .18s ease, visibility .18s ease;
        z-index: 1035;
    }
    .sc-mobile-overlay.show { visibility: visible; opacity: 1; pointer-events: auto; }
    .sc-panel-dropdown {
        position: fixed;
        left: 50%;
        bottom: auto;
        top: 50%;
        width: min(390px, calc(100vw - 28px));
        transform: translate(-50%, -48%) scale(.985);
        transform-origin: center;
    }
    .sc-dropdown-shell.open .sc-panel-dropdown { transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 575.98px) {
    .sc-sidebar { width: min(88vw, 304px); }
    .sc-brand { min-height: 78px; }
}

@media (prefers-reduced-motion: reduce) {
    .sc-sidebar,
    .sc-menu-link,
    .sc-action-btn,
    .sc-panel-dropdown,
    .sc-mobile-overlay,
    .sc-hamburger span { transition: none !important; }
}
