/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
    background-color: #f9fafb;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    color: #f9fafb;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid #374151;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo h2 {
    font-size: 20px;
    font-weight: 700;
    color: #f9fafb;
}

.logo .version {
    background: #3b82f6;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-menu {
    list-style: none;
}

.nav-item {
    margin-bottom: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: #d1d5db;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: rgba(55, 65, 81, 0.5);
    color: #f9fafb;
}

.nav-link.active {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    border-left-color: #3b82f6;
}

.nav-link i {
    width: 20px;
    height: 20px;
}

/* Sidebar submenu (drawer-style) */
.nav-link-row {
    display: flex;
    align-items: center;
}

.nav-item-submenu .nav-link {
    flex: 1 1 auto;
    min-width: 0;
}

.nav-subtoggle {
    margin-left: auto;
    margin-right: 8px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: #d1d5db;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.nav-subtoggle:hover {
    background: rgba(55, 65, 81, 0.5);
    color: #f9fafb;
}

.nav-subtoggle i {
    width: 18px;
    height: 18px;
}

.nav-submenu {
    display: none;
    list-style: none;
    margin: 4px 0 8px 0;
    padding: 0;
}

.nav-item-submenu.open .nav-submenu {
    display: block;
}

.nav-sublink {
    display: block;
    padding: 10px 20px 10px 52px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s ease;
}

.nav-sublink:hover {
    background: rgba(55, 65, 81, 0.35);
    color: #f9fafb;
}

.nav-sublink.active {
    background: rgba(59, 130, 246, 0.12);
    color: #93c5fd;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #374151;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: #374151;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
    color: #f9fafb;
}

.user-role {
    font-size: 12px;
    color: #9ca3af;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top Bar */
.top-bar {
    height: 60px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-bar-left .page-title {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 24px;
    background: #f9fafb;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-secondary {
    background: #6b7280;
    color: white;
    border-color: #6b7280;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
    border-color: #4b5563;
}

.btn-outline {
    background: white;
    color: #374151;
    border-color: #d1d5db;
}

.btn-outline:hover:not(:disabled) {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-danger {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    border-color: #dc2626;
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
    justify-content: center;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #374151;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    background: white;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-checkbox {
    margin-right: 8px;
}

.form-help {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #6b7280;
}

/* Search Box */
.search-box {
    position: relative;
    width: 300px;
}

.search-box .form-input {
    padding-left: 36px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    width: 16px;
    height: 16px;
}

/* Dropdown */
.filter-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 1000;
    display: none;
    padding: 8px 0;
}

.dropdown-menu.show {
    display: block;
}

/* Portal dropdown mounted to <body> */
.dropdown-menu.portal {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 4000; /* above cards/tables/modals headers */
    /* Aesthetic polish */
    min-width: 200px;
    max-width: 320px;
    width: max-content;
    padding: 8px 0;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
    overflow: visible; /* for arrow */
}

/* Item aesthetics (inherit CPS style) */
.dropdown-menu.portal .dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    font-size: 14px;
    color: #374151;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1.5;
    white-space: nowrap;
}

.dropdown-menu.portal .dropdown-item i[data-feather],
.dropdown-menu.portal .dropdown-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    stroke-width: 2;
}

.dropdown-menu.portal .dropdown-item:hover {
    background: #f3f4f6;
    color: #1e40af;
}

.dropdown-menu.portal .dropdown-item:active {
    background: #e5e7eb;
}

.dropdown-menu.portal .dropdown-item.text-danger {
    color: #dc2626;
}

.dropdown-menu.portal .dropdown-item.text-danger:hover {
    background: #fef2f2;
    color: #b91c1c;
}

.dropdown-menu.portal .dropdown-item:disabled,
.dropdown-menu.portal .dropdown-item[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.dropdown-menu.portal .dropdown-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 8px 0;
}

/* Directional arrow */
.dropdown-menu.portal::after {
    content: "";
    position: absolute;
    width: 10px;
    height: 10px;
    background: #ffffff;
    border-left: 1px solid #d1d5db;
    border-top: 1px solid #d1d5db;
    transform: rotate(45deg);
    box-shadow: -3px -3px 5px rgba(0, 0, 0, 0.03);
}

/* Arrow placement variants */
.dropdown-menu.portal[data-placement="bottom"]::after {
    top: -6px;
    right: 16px;
}
.dropdown-menu.portal[data-placement="top"]::after {
    bottom: -6px;
    right: 16px;
    transform: rotate(225deg);
    border-right: 1px solid #d1d5db;
    border-bottom: 1px solid #d1d5db;
    border-left: none;
    border-top: none;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.dropdown-item:hover {
    background: #f9fafb;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    background: white;
    padding: 24px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.warning {
    border-left: 4px solid #f59e0b;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .search-box {
        width: 200px;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #6b7280; }
.text-success { color: #10b981; }
.text-danger { color: #ef4444; }
.text-warning { color: #f59e0b; }

.d-none { display: none !important; }
.d-block { display: block !important; }
.d-flex { display: flex !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 8px !important; }
.mb-2 { margin-bottom: 16px !important; }
.mb-3 { margin-bottom: 24px !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px !important; }
.mt-2 { margin-top: 16px !important; }
.mt-3 { margin-top: 24px !important; } 