/* ============================================
   AFFILIATE TRACKER - PREMIUM STYLESHEET
   ============================================ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 60px;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #eef2ff;
    --primary-rgb: 99, 102, 241;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.1);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode */
[data-bs-theme="dark"] {
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --border-color: #334155;
    --primary-light: #1e1b4b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
}

[data-bs-theme="dark"] body { background-color: var(--bg-body); }
[data-bs-theme="dark"] .sidebar { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .topbar { background: #1e293b !important; border-color: #334155 !important; }
[data-bs-theme="dark"] .stat-card { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .stat-card .stat-value { color: #f1f5f9; }
[data-bs-theme="dark"] .card { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .card-header { border-color: #334155; }
[data-bs-theme="dark"] .table { color: #e2e8f0; }
[data-bs-theme="dark"] .table th { color: #94a3b8; border-color: #334155; }
[data-bs-theme="dark"] .table td { border-color: #334155; }
[data-bs-theme="dark"] .filter-bar { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .tracking-link { background: #0f172a; border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .auth-card { background: #1e293b; }
[data-bs-theme="dark"] .auth-card h2 { color: #f1f5f9; }
[data-bs-theme="dark"] .sidebar-link { color: #94a3b8; }
[data-bs-theme="dark"] .sidebar-link:hover { color: #c7d2fe; background: rgba(99,102,241,0.1); }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { background: #0f172a; border-color: #334155; color: #e2e8f0; }
[data-bs-theme="dark"] .dropdown-menu { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .dropdown-item { color: #e2e8f0; }
[data-bs-theme="dark"] .dropdown-item:hover { background: #334155; }
[data-bs-theme="dark"] .modal-content { background: #1e293b; border-color: #334155; }
[data-bs-theme="dark"] .nav-tabs .nav-link { color: #94a3b8; }
[data-bs-theme="dark"] .nav-tabs .nav-link.active { color: #c7d2fe; background: transparent; border-color: #334155 #334155 #1e293b; }

/* ---- Global ---- */
* { box-sizing: border-box; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }

::selection { background: rgba(var(--primary-rgb), 0.15); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---- Auth Pages ---- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    position: relative;
    overflow: hidden;
}

.auth-wrapper::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 50%, rgba(255,255,255,0.08) 0%, transparent 50%),
                radial-gradient(circle at 70% 80%, rgba(255,255,255,0.05) 0%, transparent 40%);
    animation: authBgFloat 20s ease-in-out infinite;
}

@keyframes authBgFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-2%, 2%) rotate(1deg); }
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    box-shadow: var(--shadow-xl);
    position: relative;
    z-index: 1;
    animation: authSlideUp 0.5s ease-out;
    backdrop-filter: blur(20px);
}

@keyframes authSlideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-card h2 {
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.auth-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    margin: 0 auto 1rem;
    box-shadow: 0 8px 16px rgba(var(--primary-rgb), 0.3);
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    z-index: 1040;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 1.25rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-header h5 {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 2px;
    transition: var(--transition);
    position: relative;
}

.sidebar-link:hover {
    background: var(--primary-light);
    color: var(--primary);
    transform: translateX(2px);
}

.sidebar-link.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
}

.sidebar-link.active:hover { transform: none; }

.sidebar-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-section {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 1rem 14px 0.4rem;
    font-weight: 700;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* ---- Main Content ---- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: var(--transition);
}

.content-area {
    padding: 1.5rem;
    max-width: 1400px;
}

/* ---- Topbar ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--bg-card) !important;
    border-bottom: 1px solid var(--border-color) !important;
    backdrop-filter: blur(12px);
    height: var(--topbar-height);
}

.topbar h5 {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.3px;
}

/* ---- Stat Cards ---- */
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    opacity: 0;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.stat-card:hover::before { opacity: 1; }

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    font-weight: 600;
    margin-bottom: 4px;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
}

.stat-card .stat-change.up { color: var(--success); }
.stat-card .stat-change.down { color: var(--danger); }

/* ---- Cards ---- */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    background: var(--bg-card);
    transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-header h6 {
    font-weight: 700;
    letter-spacing: -0.2px;
}

/* ---- Tables ---- */
.table { margin-bottom: 0; }

.table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 700;
    border-bottom-width: 1px;
    padding: 0.75rem 1rem;
    white-space: nowrap;
    background: rgba(248, 250, 252, 0.5);
}

[data-bs-theme="dark"] .table th { background: rgba(15, 23, 42, 0.3); }

.table td {
    vertical-align: middle;
    font-size: 0.85rem;
    padding: 0.7rem 1rem;
    color: var(--text-secondary);
}

.table-hover tbody tr {
    transition: var(--transition);
}

.table-hover tbody tr:hover {
    background-color: rgba(var(--primary-rgb), 0.04) !important;
}

.table a { font-weight: 600; }

/* ---- Badges ---- */
.badge {
    font-weight: 600;
    padding: 0.4em 0.75em;
    font-size: 0.7rem;
    border-radius: 6px;
    letter-spacing: 0.3px;
}

/* ---- Buttons ---- */
.btn { font-weight: 600; font-size: 0.875rem; border-radius: var(--radius-sm); transition: var(--transition); }
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), #4338ca);
    box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.35);
    transform: translateY(-1px);
}

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

.btn-group-sm .btn { border-radius: 6px; }

/* ---- Forms ---- */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border-color);
    font-size: 0.875rem;
    padding: 0.6rem 0.85rem;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.form-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.input-group-text {
    border-color: var(--border-color);
    background: #f8fafc;
    font-size: 0.875rem;
}

[data-bs-theme="dark"] .input-group-text { background: #0f172a; border-color: #334155; color: #94a3b8; }

/* ---- Charts ---- */
.chart-container {
    position: relative;
    height: 320px;
    padding: 0.5rem;
}

/* ---- Pagination ---- */
.pagination .page-link {
    border-radius: var(--radius-sm);
    margin: 0 2px;
    font-size: 0.85rem;
    font-weight: 600;
    border-color: var(--border-color);
    color: var(--text-secondary);
    transition: var(--transition);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* ---- Copy button ---- */
.copy-btn {
    cursor: pointer;
    opacity: 0.6;
    transition: var(--transition);
    border-radius: 6px;
}

.copy-btn:hover { opacity: 1; transform: scale(1.05); }

/* ---- Tracking link ---- */
.tracking-link {
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
    word-break: break-all;
    line-height: 1.4;
}

/* ---- Filter bar ---- */
.filter-bar {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state p { font-size: 0.95rem; }

/* ---- Alerts ---- */
.alert {
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    animation: alertSlide 0.3s ease-out;
}

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

/* ---- Nav Tabs ---- */
.nav-tabs {
    border-bottom: 2px solid var(--border-color);
}

.nav-tabs .nav-link {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    border: none;
    padding: 0.75rem 1.25rem;
    position: relative;
    transition: var(--transition);
}

.nav-tabs .nav-link:hover { color: var(--primary); border: none; }

.nav-tabs .nav-link.active {
    color: var(--primary);
    background: transparent;
    border: none;
}

.nav-tabs .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
}

/* ---- Modal ---- */
.modal-content {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
}

.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-footer { border-top: 1px solid var(--border-color); }

/* ---- Tooltips ---- */
.tooltip-inner { border-radius: 6px; font-size: 0.75rem; }

/* ---- Loading spinner ---- */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

/* ---- Theme Toggle ---- */
.theme-toggle {
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
}

.theme-toggle:hover { background: var(--primary-light); color: var(--primary); }

/* ---- Quick Stats Row ---- */
.quick-stats {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 0;
}

.quick-stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.quick-stat-item strong { color: var(--text-primary); }

/* ---- Offer Cards ---- */
.offer-card {
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.offer-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(var(--primary-rgb), 0.3);
}

/* ---- Page transitions ---- */
.content-area {
    animation: pageIn 0.3s ease-out;
}

@keyframes pageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

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

    .sidebar.show {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }

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

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1035;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.show {
        display: block;
        animation: fadeIn 0.2s ease;
    }

    .content-area { padding: 1rem; }

    .stat-card { padding: 1rem; }
    .stat-card .stat-value { font-size: 1.25rem; }
}

@media (max-width: 575.98px) {
    .auth-card { margin: 1rem; padding: 1.5rem; }
    .topbar h5 { font-size: 0.95rem; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Utility animations ---- */
.animate-fade-in { animation: fadeIn 0.3s ease; }
.animate-slide-up { animation: authSlideUp 0.4s ease-out; }

/* ---- Print styles ---- */
@media print {
    .sidebar, .topbar, .sidebar-overlay, .btn, .filter-bar { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .stat-card { break-inside: avoid; }
}
