/* --- Global Reset & Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Poppins:wght@400;600;700;800&display=swap');

:root {
    --primary: #4e73df;
    --primary-dark: #224abe;
    --secondary: #858796;
    --success: #1cc88a;
    --info: #36b9cc;
    --warning: #f6c23e;
    --danger: #e74a3b;
    --light: #f8f9fc;
    --dark: #5a5c69;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --border: #e3e6f0;
    --text: #444;
    --sidebar-width: 250px;
    --header-height: 70px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg);
    margin: 0;
    padding: 0;
    color: var(--text);
    font-size: 1rem;
    line-height: 1.5;
}

/* --- Text Logo Style --- */
.text-logo {
    font-family: 'Poppins', sans-serif;
    font-weight: 800;
    font-size: 2rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1.5rem;
    display: inline-block;
}

/* --- Layout Structure (Admin Dashboard) --- */
.admin-wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--primary);
    background: linear-gradient(180deg, var(--primary) 10%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 0 1rem;
}

.sidebar-brand img {
    max-height: 40px;
    max-width: 100%;
    object-fit: contain;
}

.nav-links {
    padding: 1rem 0;
    list-style: none;
    margin: 0;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
    color: white;
    background: rgba(255,255,255,0.1);
    border-left: 4px solid white;
}

.nav-link i { margin-right: 10px; width: 20px; text-align: center; }

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: var(--header-height);
    background: white;
    box-shadow: 0 .15rem 1.75rem 0 rgba(58,59,69,.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark);
    margin: 0;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-logout-sm {
    font-size: 0.85rem;
    color: var(--danger);
    text-decoration: none;
    font-weight: 700;
    border: 1px solid var(--danger);
    padding: 5px 12px;
    border-radius: 20px;
    transition: all 0.2s;
}
.btn-logout-sm:hover { background: var(--danger); color: white; }

/* Page Content */
.page-content {
    padding: 2rem;
    flex: 1;
}

/* --- Footer --- */
.footer {
    background: white;
    padding: 1.5rem;
    text-align: center;
    color: var(--secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

/* --- Components --- */

/* Cards */
.card {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 0.15rem 1.75rem 0 rgba(58,59,69,.1);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    background: #f8f9fc;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 1.5rem;
}

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-left: 4px solid var(--primary);
    border-radius: 0.35rem;
    padding: 1.5rem;
    box-shadow: 0 .15rem 1.75rem 0 rgba(58,59,69,.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.info { border-left-color: var(--info); }

.stat-text { display: flex; flex-direction: column; }
.stat-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--primary); margin-bottom: 0.25rem; }
.stat-card.success .stat-label { color: var(--success); }
.stat-card.warning .stat-label { color: var(--warning); }
.stat-card.info .stat-label { color: var(--info); }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--dark); }

/* Grid Layouts */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -0.75rem;
}
.col-lg-8 { flex: 0 0 66.66667%; max-width: 66.66667%; padding: 0 0.75rem; }
.col-lg-6 { flex: 0 0 50%; max-width: 50%; padding: 0 0.75rem; }
.col-lg-4 { flex: 0 0 33.33333%; max-width: 33.33333%; padding: 0 0.75rem; }
.col-12 { flex: 0 0 100%; max-width: 100%; padding: 0 0.75rem; }

/* Forms */
.form-group { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--dark); }
.form-control {
    display: block;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #6e707e;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #d1d3e2;
    border-radius: 0.35rem;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.form-control:focus { color: #6e707e; background-color: #fff; border-color: #bac8f3; outline: 0; box-shadow: 0 0 0 0.2rem rgba(78,115,223,.25); }
textarea.form-control { min-height: 120px; font-family: monospace; font-size: 0.9rem; }

/* Buttons */
.btn {
    display: inline-block;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    user-select: none;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.35rem;
    transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
}
.btn-primary { color: #fff; background-color: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { color: #fff; background-color: var(--success); border-color: var(--success); }
.btn-danger { color: #fff; background-color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.875rem; }
.btn-block { display: block; width: 100%; }

/* Tables */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table { width: 100%; margin-bottom: 1rem; color: #858796; border-collapse: collapse; }
.table th, .table td { padding: 0.75rem; vertical-align: top; border-top: 1px solid #e3e6f0; }
.table thead th { vertical-align: bottom; border-bottom: 2px solid #e3e6f0; background: #f8f9fc; color: var(--primary); font-weight: 700; text-transform: uppercase; font-size: 0.8rem; }
.table tbody tr:hover { background-color: rgba(0,0,0,.05); }

/* Alerts */
.alert {
    position: relative;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.35rem;
}
.alert-success { color: #0f6848; background-color: #d4edda; border-color: #c3e6cb; }
.alert-danger { color: #721c24; background-color: #f8d7da; border-color: #f5c6cb; }

/* --- Redirect Page (Index) --- */
body.redirect-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #eef2f7;
    padding: 20px;
}

.redirect-container {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.redirect-logo { max-height: 70px; margin-bottom: 1.5rem; object-fit: contain; max-width: 100%; }

/* Counter */
.counter-circle {
    width: 120px;
    height: 120px;
    background: #007bff;
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 64px;
    font-weight: bold;
    margin: 20px 0;
    box-shadow: 0 4px 15px rgba(0,123,255,0.3);
    animation: pulse 1s infinite;
}

.referrer-badge {
    background: #e4e6eb;
    color: #65676b;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

#status-text {
    font-size: 18px;
    color: #555;
    margin: 10px 0;
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin-top: 15px;
}

/* --- Ad Container --- */
.ad-container {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px dashed #ddd;
    width: 100%;
    text-align: center;
    min-height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Make Ads Responsive */
.ad-container img, 
.ad-container iframe, 
.ad-container video,
.ad-container object,
.ad-container embed {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* --- Login Page --- */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
}
.login-card {
    background: white;
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1rem 3rem rgba(0,0,0,0.175);
}
.login-title { text-align: center; margin-bottom: 2rem; color: var(--dark); font-weight: 800; font-size: 1.5rem; }

/* --- Responsive Media Queries --- */
@media (max-width: 992px) {
    .col-lg-8, .col-lg-6, .col-lg-4 { flex: 0 0 100%; max-width: 100%; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 250px;
    }
    .sidebar.show { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { padding: 0 1rem; }
    .menu-toggle { display: block !important; cursor: pointer; font-size: 1.5rem; margin-right: 15px; color: var(--primary); }
}
.menu-toggle { display: none; }

@media (max-width: 600px) {
    .redirect-container {
        padding: 20px;
    }
    .counter-circle {
        width: 100px;
        height: 100px;
        font-size: 48px;
    }
    .text-logo {
        font-size: 1.5rem;
    }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(78, 115, 223, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(78, 115, 223, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(78, 115, 223, 0); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
