:root {
    --rp-bg: #f4f7fb;
    --rp-surface: rgba(255, 255, 255, 0.92);
    --rp-border: rgba(15, 23, 42, 0.08);
    --rp-text: #0f172a;
    --rp-muted: #64748b;
    --rp-primary: #2563eb;
    --rp-primary-dark: #1d4ed8;
    --rp-emerald: #059669;
    --rp-sky: #0ea5e9;
    --rp-gradient: linear-gradient(135deg, #0f172a 0%, #1d4ed8 55%, #059669 100%);
    --rp-accent-gradient: linear-gradient(135deg, #2563eb 0%, #059669 100%);
    --rp-sidebar-width: 264px;
    --rp-radius: 16px;
    --rp-shadow: 0 4px 16px -4px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.04);
    --rp-shadow-md: 0 20px 40px -15px rgba(37, 99, 235, 0.14), 0 4px 12px rgba(15, 23, 42, 0.05);
}

/* Dark Mode Theme */
[data-theme="dark"] {
    --rp-bg: #0b1120;
    --rp-surface: rgba(15, 23, 42, 0.9);
    --rp-border: rgba(148, 163, 184, 0.14);
    --rp-text: #f1f5f9;
    --rp-muted: #94a3b8;
    --rp-shadow: 0 6px 20px -4px rgba(0, 0, 0, 0.45);
    --rp-shadow-md: 0 20px 40px -12px rgba(0, 0, 0, 0.65);
}

[data-theme="dark"] body {
    background-color: var(--rp-bg);
    background-image:
        radial-gradient(ellipse 65% 45% at 15% 0%, rgba(37, 99, 235, 0.16) 0%, transparent 55%),
        radial-gradient(ellipse 55% 45% at 95% 15%, rgba(16, 185, 129, 0.12) 0%, transparent 55%);
    color: var(--rp-text);
}

[data-theme="dark"] .rp-sidebar,
[data-theme="dark"] .rp-topbar {
    background: rgba(15, 23, 42, 0.88);
    border-color: var(--rp-border);
}

[data-theme="dark"] .rp-nav-link {
    color: #cbd5e1;
}

[data-theme="dark"] .rp-nav-link:hover {
    background: rgba(37, 99, 235, 0.16);
    color: #93c5fd;
}

[data-theme="dark"] .rp-nav-link.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.22) 0%, rgba(5, 150, 105, 0.2) 100%);
    color: #e2e8f0;
}

[data-theme="dark"] .table {
    --bs-table-color: #e2e8f0;
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(148, 163, 184, 0.08);
    border-color: var(--rp-border);
}

[data-theme="dark"] .table > thead th {
    background-color: rgba(30, 41, 59, 0.85);
    color: #94a3b8;
    border-bottom-color: var(--rp-border);
}

[data-theme="dark"] .table > tbody td {
    border-bottom-color: rgba(148, 163, 184, 0.08);
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .modal-content,
[data-theme="dark"] .dropdown-menu {
    background-color: #1e293b;
    border-color: rgba(148, 163, 184, 0.2);
    color: #f1f5f9;
}

[data-theme="dark"] .dropdown-item {
    color: #e2e8f0;
}

[data-theme="dark"] .dropdown-item:hover {
    background-color: rgba(37, 99, 235, 0.2);
}

[data-theme="dark"] .bg-light,
[data-theme="dark"] .bg-light-subtle {
    background-color: rgba(30, 41, 59, 0.72) !important;
    color: #e2e8f0 !important;
}

[data-theme="dark"] .text-dark {
    color: #f1f5f9 !important;
}

[data-theme="dark"] .text-muted {
    color: #94a3b8 !important;
}

[data-theme="dark"] .btn-light {
    background-color: #1e293b;
    border-color: rgba(148, 163, 184, 0.22);
    color: #e2e8f0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--rp-bg);
    background-image:
        radial-gradient(ellipse 65% 45% at 15% 0%, rgba(37, 99, 235, 0.06) 0%, transparent 55%),
        radial-gradient(ellipse 55% 45% at 95% 15%, rgba(16, 185, 129, 0.06) 0%, transparent 55%);
    background-attachment: fixed;
    color: var(--rp-text);
    -webkit-font-smoothing: antialiased;
}

.rp-gradient-text {
    background: var(--rp-accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-primary {
    position: relative;
    overflow: hidden;
    background: var(--rp-gradient);
    background-size: 170% 170%;
    border: none;
    box-shadow: 0 8px 20px -6px rgba(37, 99, 235, 0.42);
    transition: transform 0.18s ease, box-shadow 0.2s ease, background-position 0.35s ease;
}

.btn-primary:hover,
.btn-primary:focus {
    background-position: 100% 50%;
    transform: translateY(-1px);
    box-shadow: 0 12px 26px -6px rgba(5, 150, 105, 0.38), 0 6px 14px rgba(37, 99, 235, 0.28);
}

.btn-outline-primary {
    border-color: var(--rp-primary);
    color: var(--rp-primary);
}

.btn-outline-primary:hover {
    background: var(--rp-primary);
    border-color: var(--rp-primary);
}

/* App Shell Layout */
.rp-shell {
    display: flex;
    min-height: 100vh;
}

.rp-sidebar {
    width: var(--rp-sidebar-width);
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--rp-border);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

.rp-brand {
    padding: 1.15rem 1.3rem;
    border-bottom: 1px solid var(--rp-border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--rp-text);
}

.rp-brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--rp-accent-gradient);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
    transition: transform 0.2s ease;
}

.rp-brand:hover .rp-brand-icon {
    transform: scale(1.06) rotate(-3deg);
}

.rp-nav {
    padding: 0.9rem 0.85rem;
    overflow-y: auto;
    flex: 1;
}

.rp-nav-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rp-muted);
    padding: 0.7rem 0.75rem 0.3rem;
}

.rp-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.85rem;
    border-radius: 11px;
    color: #334155;
    font-weight: 500;
    font-size: 0.88rem;
    text-decoration: none;
    margin-bottom: 0.2rem;
    transition: all 0.18s ease;
}

.rp-nav-link i {
    width: 18px;
    text-align: center;
    color: #64748b;
    transition: color 0.18s ease, transform 0.18s ease;
}

.rp-nav-link:hover {
    background: rgba(37, 99, 235, 0.07);
    color: var(--rp-primary);
    transform: translateX(3px);
}

.rp-nav-link:hover i {
    color: var(--rp-primary);
}

.rp-nav-link.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.11) 0%, rgba(5, 150, 105, 0.1) 100%);
    color: var(--rp-primary);
    font-weight: 700;
    box-shadow: inset 3px 0 0 var(--rp-emerald);
}

.rp-nav-link.active i {
    color: var(--rp-emerald);
}

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

.rp-topbar {
    background: rgba(255, 255, 255, 0.84);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--rp-border);
    padding: 0.85rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

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

/* Cards & Tables */
.rp-card {
    background: var(--rp-surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--rp-border);
    border-radius: var(--rp-radius);
    box-shadow: var(--rp-shadow);
    transition: box-shadow 0.22s ease, transform 0.22s ease, border-color 0.22s ease;
}

.rp-card-hover:hover {
    box-shadow: var(--rp-shadow-md);
    border-color: rgba(37, 99, 235, 0.22);
    transform: translateY(-3px);
}

.modal-content {
    background-color: #ffffff;
    color: #0f172a;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.28);
}

.rp-stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: transform 0.2s ease;
}

.rp-card-hover:hover .rp-stat-icon {
    transform: scale(1.08);
}

.rp-stat-blue {
    background: rgba(37, 99, 235, 0.11);
    color: #2563eb;
}

.rp-stat-purple {
    background: rgba(14, 165, 233, 0.12);
    color: #0284c7;
}

.rp-stat-emerald {
    background: rgba(5, 150, 105, 0.12);
    color: #059669;
}

.rp-stat-amber {
    background: rgba(245, 158, 11, 0.13);
    color: #d97706;
}

.rp-stat-rose {
    background: rgba(225, 29, 72, 0.12);
    color: #e11d48;
}

.rp-stat-cyan {
    background: rgba(6, 182, 212, 0.12);
    color: #0891b2;
}

.table>thead th {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--rp-muted);
    background-color: #f8fafc;
    border-bottom: 1px solid var(--rp-border);
    font-weight: 700;
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

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

.table-hover>tbody>tr {
    transition: background-color 0.15s ease;
}

.table-hover>tbody>tr:hover {
    background-color: rgba(37, 99, 235, 0.03);
}

/* Badges */
.rp-pos-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.82rem;
}

.rp-pos-top3 {
    background: #dcfce7;
    color: #047857;
    border: 1px solid #86efac;
}

.rp-pos-top10 {
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
}

.rp-pos-top50 {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #7dd3fc;
}

.rp-pos-deep {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.rp-pos-none {
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    font-weight: 600;
}

.rp-change-up {
    color: #059669;
    background: rgba(5, 150, 105, 0.12);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.78rem;
    white-space: nowrap;
}

.rp-change-down {
    color: #e11d48;
    background: rgba(225, 29, 72, 0.12);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.78rem;
    white-space: nowrap;
}

/* Loading Overlay */
.rp-loading-bar {
    height: 3px;
    background: var(--rp-accent-gradient);
    width: 100%;
    animation: rpPulseProgress 1.2s ease-in-out infinite;
}

@keyframes rpPulseProgress {
    0% {
        opacity: 0.35;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.35;
    }
}

@media (max-width: 991.98px) {
    .rp-sidebar {
        transform: translateX(-100%);
    }

    .rp-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
    }

    .rp-main {
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}