:root {
    --bg-body: #f5f7fa;
    --bg-sidebar: #2c3e50;
    --bg-header: white;
    --bg-card: white;
    --text-primary: #333;
    --text-secondary: #7f8c8d;
    --text-sidebar: white;
    --color-primary: #3498db;
    --color-success: #2ecc71;
    --border-color: rgba(0, 0, 0, 0.125);
    --color-danger: #e74c3c;
    --color-warning: #f1c40f;
    --color-primary-contrast: #fff;
    --erp-sidebar-width: 220px;
    --erp-sidebar-collapsed-width: 56px;
    --erp-header-height: 56px;
    --erp-content-padding: 16px;
    --erp-panel-padding: 16px;
}

html[data-theme="dark"] {
    --bg-body: #1a252f;
    --bg-sidebar: #0e1621;
    --bg-header: #2c3e50;
    --bg-card: #2c3e50;
    --text-primary: #ecf0f1;
    --text-secondary: #bdc3c7;
    --text-sidebar: #bdc3c7;
    --color-primary: #3498db;
    --color-success: #27ae60;
    --border-color: rgba(255, 255, 255, 0.1);
    --color-danger: #ff6b6b;
    --color-warning: #feca57;
    --color-primary-contrast: #fff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
}

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

/* Layout */
.erp-container {
    display: flex;
    height: 100vh;
    min-height: 0;
    max-height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--erp-sidebar-width);
    flex: 0 0 var(--erp-sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    transition: width 0.24s ease, flex-basis 0.24s ease;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar.collapsed {
    width: var(--erp-sidebar-collapsed-width);
    flex-basis: var(--erp-sidebar-collapsed-width);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #34495e;
    border-radius: 3px;
}

/* Toggle Button */
.toggle-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: #34495e;
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 10;
}

.toggle-btn:hover {
    background: #1abc9c;
    transform: translateY(-1px);
}

/* Logo Area */
.sidebar-header {
    min-height: var(--erp-header-height);
    height: var(--erp-header-height);
    padding: 0 52px 0 18px;
    border-bottom: 1px solid #34495e;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 19px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.3s;
}

.sidebar.collapsed .sidebar-header {
    padding: 0;
    justify-content: center;
}

.sidebar.collapsed .sidebar-header h2 {
    opacity: 0;
    width: 0;
}

/* Menu */
.menu {
    padding: 6px 0;
}

.menu-item {
    position: relative;
}

.item-label {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 16px;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease;
    color: #ecf0f1;
    text-decoration: none;
}

.item-label:hover {
    background: #34495e;
}

.item-label.active {
    background: #1abc9c;
    box-shadow: inset 3px 0 #16a085;
}

.item-label i {
    min-width: 24px;
    width: 24px;
    text-align: center;
    font-size: 17px;
}

.item-label span {
    margin-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.3s;
    font-size: 15px;
}

.sidebar.collapsed .item-label {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .item-label i {
    min-width: 0;
    width: auto;
}

.sidebar.collapsed .item-label span {
    opacity: 0;
    width: 0;
}

.arrow {
    margin-left: auto;
    transition: transform 0.3s;
    font-size: 12px;
}

.arrow.expanded {
    transform: rotate(90deg);
}

.sidebar.collapsed .arrow {
    display: none;
}

/* Submenu */
.submenu {
    background: #1a252f;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.submenu .item-label {
    padding-left: 42px;
    font-size: 14px;
}

.submenu .submenu .item-label {
    padding-left: 58px;
    font-size: 13px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    margin-left: 0;
    transition: margin-left 0.3s ease;
    overflow: hidden;
}

/* Header */
.top-header {
    background: var(--bg-header);
    min-height: var(--erp-header-height);
    height: var(--erp-header-height);
    flex: 0 0 var(--erp-header-height);
    padding: 0 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.15;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.notification-icon {
    position: relative;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
}

.notification-badge {
    position: absolute;
    top: -7px;
    right: -7px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 17px;
    height: 17px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #3498db;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    position: relative;
    padding: 0.25rem 0.35rem;
    border-radius: 8px;
    transition: background-color 0.2s;
    color: var(--text-primary);
}

.user-profile:hover {
    background-color: var(--border-color);
}

.profile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    background: var(--bg-header);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 0.5rem 0;
    z-index: 1000;
    margin-top: 0.5rem;
    border: 1px solid var(--border-color);
    animation: fadeIn 0.2s ease-out;
}

.dropdown-item {
    display: flex !important;
    align-items: center !important;
    padding: 0.75rem 1rem !important;
    color: var(--text-primary) !important;
    text-decoration: none !important;
    transition: background-color 0.2s !important;
}

.dropdown-item.text-danger {
    color: var(--color-danger) !important;
}

.dropdown-item:hover {
    background-color: var(--bg-body);
    color: var(--color-primary);
}

.dropdown-item i {
    width: 20px;
    margin-right: 10px;
    text-align: center;
}

.dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}

/* Utilities */
.text-danger {
    color: var(--color-danger) !important;
}

.text-success {
    color: var(--color-success) !important;
}

.text-warning {
    color: var(--color-warning) !important;
}

.text-primary {
    color: var(--color-primary) !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Content Area */
.content-area {
    flex: 1;
    min-height: 0;
    min-width: 0;
    padding: var(--erp-content-padding);
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-body);
}

.page-content {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 0;
}

.dashboard-panel {
    display: grid;
    gap: 0.45rem;
}

/* Animations */
.submenu-enter-active,
.submenu-leave-active {
    transition: all 0.3s ease;
}

.submenu-enter-from {
    max-height: 0;
    opacity: 0;
}

.submenu-enter-to {
    max-height: 500px;
    opacity: 1;
}

.submenu-leave-from {
    max-height: 500px;
    opacity: 1;
}

.submenu-leave-to {
    max-height: 0;
    opacity: 0;
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-size: 20px;
    color: #7f8c8d;
}


/* Menu loading state */
.menu-loading {
    padding: 12px;
    text-align: center;
    color: #ecf0f1;
    font-size: 14px;
}

.menu-loading i {
    margin-right: 8px;
}

/* Loading Bar */
.loading-bar-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--loading-bar-height, 3px);
    z-index: 9999;
    pointer-events: none;
}

.loading-bar {
    height: 100%;
    background: var(--loading-bar-color, linear-gradient(90deg, #3498db, #2ecc71));
    width: 100%;
    animation: loading-animation 2s infinite;
    transform-origin: 0% 50%;
}

@keyframes loading-animation {
    0% {
        transform: translateX(0) scaleX(0);
    }

    40% {
        transform: translateX(0) scaleX(0.4);
    }

    100% {
        transform: translateX(100%) scaleX(0.5);
    }
}

/* Global Dialog */
.erp-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: color-mix(in srgb, var(--bg-sidebar) 68%, transparent);
    backdrop-filter: blur(2px);
}

.erp-dialog-panel {
    width: min(460px, calc(100vw - 24px));
    max-height: calc(100dvh - 32px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
    animation: dialog-in 0.18s ease-out;
}

.erp-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 18px 10px;
}

.erp-dialog-title {
    margin: 0;
    color: var(--text-primary);
    font-size: 20px;
    line-height: 1.2;
    font-weight: 700;
}

.erp-dialog-close {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.erp-dialog-close:hover,
.erp-dialog-close:focus-visible {
    border-color: var(--color-primary);
    color: var(--color-primary);
    outline: none;
}

.erp-dialog-body {
    overflow-y: auto;
    padding: 8px 18px 18px;
}

.erp-dialog-message {
    margin: 0;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.55;
}

.erp-dialog-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border-color);
    padding: 14px 18px 18px;
    background: color-mix(in srgb, var(--bg-body) 55%, var(--bg-card));
}

.erp-dialog-btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 0 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.erp-dialog-btn:hover,
.erp-dialog-btn:focus-visible {
    transform: translateY(-1px);
    outline: none;
}

.erp-dialog-btn-primary {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
}

.erp-dialog-btn-primary:hover,
.erp-dialog-btn-primary:focus-visible {
    border-color: color-mix(in srgb, var(--color-primary) 70%, var(--text-primary));
}

.erp-dialog-btn-danger {
    border-color: color-mix(in srgb, var(--color-danger) 38%, var(--border-color));
    background: color-mix(in srgb, var(--color-danger) 12%, var(--bg-card));
    color: var(--color-danger);
}

.erp-dialog-btn-danger:hover,
.erp-dialog-btn-danger:focus-visible {
    background: color-mix(in srgb, var(--color-danger) 18%, var(--bg-card));
}

.erp-dialog-btn-secondary,
.erp-dialog-btn-light {
    border-color: var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
}

.erp-dialog-btn-secondary:hover,
.erp-dialog-btn-secondary:focus-visible,
.erp-dialog-btn-light:hover,
.erp-dialog-btn-light:focus-visible {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

@keyframes dialog-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal and Transitions */
.fade-enter-active,
.fade-leave-active {
    transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
}

@media (max-width: 900px) {
    :root {
        --erp-content-padding: 12px;
    }

    .sidebar {
        width: var(--erp-sidebar-collapsed-width);
        flex-basis: var(--erp-sidebar-collapsed-width);
    }

    .sidebar-header {
        padding: 0;
        justify-content: center;
    }

    .sidebar-header h2,
    .item-label span,
    .arrow {
        opacity: 0;
        width: 0;
        display: none;
    }

    .item-label {
        justify-content: center;
        padding: 0;
    }

    .item-label i {
        min-width: 0;
        width: auto;
    }

    .top-header {
        padding: 0 12px;
    }

    .header-left h1 {
        font-size: 18px;
    }

    .erp-dialog-footer {
        justify-content: stretch;
    }

    .erp-dialog-btn {
        flex: 1 1 100%;
    }
}
