:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;

    /* Light Mode (Default) */
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --card-border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --sidebar-bg: #fdfaf6;
    --sidebar-hover: #f5f0e5;
    --sidebar-text: #5c5346;
    --sidebar-active-bg: #4f46e5;
    --sidebar-active-text: #ffffff;
    --border-color: #e2e8f0;
    --header-bg: rgba(255, 255, 255, 0.8);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --input-bg: #f8fafc;
    --input-border: #e2e8f0;
    --th-bg: #f8fafc;
    --badge-ghost-bg: #f1f5f9;
    --btn-ghost-hover: #f1f5f9;

    --header-height: 55px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
}

[data-theme='dark'] {
    --bg-color: #020617;
    --card-bg: #0f172a;
    --card-border: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active-bg: rgba(79, 70, 229, 0.2);
    --sidebar-active-text: #818cf8;
    --border-color: #1e293b;
    --header-bg: rgba(15, 23, 42, 0.8);
    --input-bg: #1e293b;
    --input-border: #1e293b;
    --th-bg: rgba(255, 255, 255, 0.05);
    --badge-ghost-bg: #1e293b;
    --btn-ghost-hover: #1e293b;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
}

/* Page Loader */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loader-content {
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: loaderSpin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.loader-logo {
    width: 60px;
    height: 60px;
    border-radius: 15px;
    object-fit: cover;
    z-index: 2;
    box-shadow: var(--shadow-md);
    animation: loaderPulse 2s infinite ease-in-out;
}

@keyframes loaderSpin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes loaderPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(0.92);
        opacity: 0.8;
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Layout */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 1.5rem 0;
}

.sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.sidebar.collapsed .menu-label {
    display: none;
}

.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 0.875rem 0;
}

.sidebar.collapsed .menu-item span,
.sidebar.collapsed .menu-item .fa-chevron-right {
    display: none;
}

.sidebar.collapsed .menu-item i {
    margin: 0;
    font-size: 1.25rem;
}

/* Tooltip for collapsed sidebar items */
.sidebar.collapsed .menu-item {
    position: relative;
}

.sidebar.collapsed .menu-item:hover::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    z-index: 1002;
    margin-left: 10px;
    box-shadow: var(--shadow-md);
}

.sidebar.collapsed .sidebar-submenu {
    position: absolute;
    /* Submenus behave differently when collapsed, handled with JS or CSS */
    left: 100%;
    top: 0;
    min-width: 200px;
    margin: 0;
    border-radius: 0 8px 8px 0;
    box-shadow: var(--shadow-md);
    background: var(--sidebar-bg);
    z-index: 1001;
}

/* Force specific submenu icon handling */
.sidebar.collapsed .sidebar-submenu .menu-item {
    justify-content: flex-start;
    padding: 0.75rem 1.25rem;
}

.sidebar.collapsed .sidebar-submenu .menu-item span {
    display: inline;
}

.sidebar.collapsed .sidebar-submenu .menu-item i {
    margin-right: 0.75rem;
    font-size: 1rem;
}

.sidebar.collapsed .sidebar-footer .menu-item {
    justify-content: center;
}

.sidebar.collapsed .sidebar-footer .menu-item span {
    display: none;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
}

/* Global minimalist scrollbar */
::-webkit-scrollbar {
    width: 3px !important;
    height: 3px !important;
}

::-webkit-scrollbar-track {
    background: transparent !important;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1) !important;
    border-radius: 10px !important;
    transition: all 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color) !important;
}

[data-theme='dark'] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1) !important;
}

.sidebar-menu {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto !important;
    scrollbar-width: thin;
    /* Firefox */
    scrollbar-color: rgba(0, 0, 0, 0.1) transparent;
}

/* Minimalist Scrollbar FORCED for Sidebar */
.sidebar-menu::-webkit-scrollbar {
    width: 3px !important;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent !important;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1) !important;
    border-radius: 10px !important;
}

[data-theme='dark'] .sidebar-menu {
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

[data-theme='dark'] .sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1) !important;
}

.menu-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-left: 0.5rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
}

.menu-item:hover {
    background: var(--sidebar-hover);
    color: var(--text-main);
    transform: translateX(4px);
}

.menu-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.menu-item i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed~.main-content {
    margin-left: var(--sidebar-collapsed-width);
}

header.top-bar {
    height: var(--header-height);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 900;
    border-bottom: 1px solid var(--border-color);
}

.content-body {
    padding: 2rem;
    width: 100%;
}

/* Cards & Stats */
.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
}

.stat-info .value {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.stat-info .label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    border: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: #fee2e2;
    color: var(--danger-color);
}

.btn-danger:hover {
    background: var(--danger-color);
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--btn-ghost-hover);
    color: var(--text-main);
}

/* Modal Premium */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1.5rem;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 24px;
    width: 100%;
    max-width: 600px;
    padding: 1.5rem 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    border: 1px solid var(--border-color);
}

.modal-header {
    margin-bottom: 1.5rem;
    text-align: left;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.025em;
}

.modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

/* Form Elements SaaS Style */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.form-group.full {
    grid-column: span 2;
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: 12px;
    color: var(--text-main);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    background: var(--card-bg);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
    outline: none;
}

.form-control::placeholder {
    color: #94a3b8;
}

/* Modal Buttons Container */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content,
    .sidebar.collapsed~.main-content {
        margin-left: 0 !important;
    }

    .mobile-toggle {
        display: block !important;
    }
}

.mobile-toggle {
    display: block;
    /* Always display for desktop collapse as well */
    font-size: 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-main);
}

.mobile-toggle:hover {
    color: var(--primary-color);
}

/* Tables Improvements */
.table-card {
    background: var(--card-bg);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--card-border);
}

.table-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: var(--th-bg);
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

tr:last-child td {
    border-bottom: none;
}

/* Badges */
.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.badge-ghost {
    background: var(--badge-ghost-bg);
    color: var(--text-muted);
}

.decision-dropdown-content {
    animation: fadeInDown 0.2s ease-out;
    background: var(--card-bg) !important;
    border: 1px solid var(--border-color);
}

.decision-dropdown-content button {
    color: var(--text-main);
}

.decision-dropdown-content button:hover {
    background: var(--bg-color) !important;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}