:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --dark: #0f172a;
    --light: #f8fafc;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 64px;
}

body {
    background-color: #f8fafc;
    color: #1e293b;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.925rem;
    line-height: 1.5;
    margin: 0;
    padding: 0;
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.app-main {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-header {
    height: var(--header-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
}

.app-content {
    flex-grow: 1;
    padding: 1.5rem;
}

/* Sidebar Nav */
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
}

.sidebar-menu {
    list-style: none;
    padding: 0.75rem 0.5rem;
    margin: 0;
}

.sidebar-heading {
    padding: 0.75rem 1rem 0.35rem 1rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.sidebar-link i {
    font-size: 1.1rem;
    width: 20px;
}

.sidebar-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.07);
}

.sidebar-link.active {
    color: #ffffff;
    background: var(--primary);
}

/* Sidebar Nav Groups & Submenus */
.sidebar-nav-group {
    padding: 0 0.5rem;
    margin-bottom: 3px;
}

.sidebar-group-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.6rem 0.85rem;
    color: #94a3b8;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    text-align: left;
    transition: all 0.15s ease;
    cursor: pointer;
    user-select: none;
}

.sidebar-group-btn i:first-child {
    font-size: 1.05rem;
    width: 20px;
}

.sidebar-group-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.07);
}

.sidebar-group-btn:not(.collapsed) {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
}

.sidebar-group-btn .group-chevron {
    font-size: 0.72rem;
    transition: transform 0.2s ease;
    color: #64748b;
}

.sidebar-group-btn:hover .group-chevron {
    color: #ffffff;
}

.sidebar-group-btn:not(.collapsed) .group-chevron {
    transform: rotate(90deg);
    color: #38bdf8;
}

.sidebar-submenu {
    list-style: none;
    padding: 0.25rem 0 0.4rem 0.65rem;
    margin: 0.2rem 0 0.4rem 1.1rem;
    border-left: 2px solid rgba(255, 255, 255, 0.08);
}

.sidebar-submenu .sidebar-link {
    font-size: 0.84rem;
    padding: 0.42rem 0.75rem;
    color: #94a3b8;
    border-radius: 6px;
    gap: 0.65rem;
    margin-bottom: 2px;
}

.sidebar-submenu .sidebar-link i {
    font-size: 0.95rem;
    width: 18px;
}

.sidebar-submenu .sidebar-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.07);
}

.sidebar-submenu .sidebar-link.active {
    color: #ffffff;
    background: var(--primary);
    font-weight: 600;
}

/* Custom Scrollbar for Sidebar */
.app-sidebar::-webkit-scrollbar {
    width: 5px;
}

.app-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Impersonation Banner */
.impersonation-banner {
    background: linear-gradient(90deg, #f59e0b, #d97706);
    color: #ffffff;
    padding: 0.6rem 1.5rem;
    font-size: 0.88rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 1050;
}

/* Stat Cards */
.stat-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.1rem 1.15rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    height: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-value {
    font-size: clamp(1.1rem, 1.3vw + 0.4rem, 1.45rem);
    font-weight: 700;
    color: #0f172a;
    line-height: 1.25;
    margin: 0.35rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    letter-spacing: -0.01em;
}

.stat-value.full-mode {
    font-size: clamp(0.92rem, 1.1vw + 0.35rem, 1.25rem);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tables */
.table-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.table-custom {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table-custom thead th {
    background: #f8fafc;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.table-custom tbody td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}

/* Badges */
.badge-soft-success { background: #dcfce7; color: #166534; }
.badge-soft-danger { background: #fee2e2; color: #991b1b; }
.badge-soft-warning { background: #fef3c7; color: #92400e; }
.badge-soft-primary { background: #dbeafe; color: #1e40af; }
.badge-soft-secondary { background: #f1f5f9; color: #475569; }

/* Global Search Modal */
.search-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1060;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10vh;
}

.search-modal-backdrop.show {
    display: flex;
}

.search-modal-dialog {
    width: 100%;
    max-width: 620px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    overflow: hidden;
}

.search-input-group {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.search-input-group input {
    border: none;
    outline: none;
    font-size: 1.1rem;
    width: 100%;
    margin-left: 0.75rem;
}

.search-results-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}

.search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background 0.1s ease;
}

.search-item:hover {
    background: #f1f5f9;
}

/* Responsive adjustments */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
}
