:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: rgba(37, 99, 235, 0.1);
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #0f172a;
    --dark-lighter: #1e293b;
    --light: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --sidebar-width: 280px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--light);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
    /* Prevent horizontal scroll from sidebar */
}

/* Global Responsive Resets */
img,
video,
iframe {
    max-width: 100%;
    height: auto;
}

/* Text Wrapping */
p,
h1,
h2,
h3,
h4,
h5,
h6,
span {
    overflow-wrap: break-word;
}


/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: var(--white);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: var(--transition);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    padding: 32px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.3);
}

.sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    padding: 0 16px 32px;
}

.nav-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-light);
    margin: 24px 12px 12px;
    font-weight: 600;
    opacity: 0.5;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 4px;
}

.nav-link i {
    font-size: 18px;
    width: 24px;
    text-align: center;
    transition: var(--transition);
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--white);
}

.nav-link.active {
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-link.active i {
    transform: scale(1.1);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 0;
    transition: var(--transition);
    min-width: 0;
    /* Critical for flexbox children to shrink */
    width: 100%;
}

/* Topbar */
.topbar {
    height: 80px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    position: sticky;
    top: 0;
    z-index: 900;
}

.topbar-left h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--dark);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-radius: var(--radius-lg);
    background: var(--light);
    cursor: pointer;
    transition: var(--transition);
}

.user-profile:hover {
    background: var(--border);
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
    line-height: 1.2;
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.btn-logout {
    color: var(--danger);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Page Content */
.content-wrapper {
    padding: 40px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 32px;
    margin-bottom: 32px;
    transition: var(--transition);
}

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--dark);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: var(--transition);
}

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

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

.stat-icon.blue {
    background: #eff6ff;
    color: #2563eb;
}

.stat-icon.green {
    background: #ecfdf5;
    color: #10b981;
}

.stat-icon.purple {
    background: #f5f3ff;
    color: #8b5cf6;
}

.stat-icon.orange {
    background: #fff7ed;
    color: #f59e0b;
}

.stat-data h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-data .value {
    font-size: 28px;
    font-weight: 800;
    color: var(--dark);
}

/* Forms */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-main);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
    background: var(--light);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #dc2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    width: 100%;
    margin-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    background: var(--light);
    padding: 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-main);
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover {
    background: rgba(248, 250, 252, 0.5);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #15803d;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-info {
    background: #e0f2fe;
    color: #0369a1;
}

/* Messages */
.alert {
    padding: 16px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

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

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

    .sidebar.active {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block !important;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 0 16px;
        height: 60px;
    }

    .content-wrapper {
        padding: 16px;
    }

    .form-row {
        grid-template-columns: 1fr !important;
    }

    .user-info {
        display: none;
        /* Hide user name on small mobile to save space */
    }

    /* Mobile Table Styles for better readability */
    .table th,
    .table td {
        padding: 12px 10px;
        font-size: 13px;
    }

    /* Stats grid on mobile */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Card adjustments */
    .card {
        padding: 20px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .card-tools {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Make flex containers stack on mobile */
    .d-flex-mobile-stack {
        flex-direction: column !important;
        align-items: stretch !important;
    }
}

/* Sidebar Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: var(--dark);
    margin-right: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: var(--transition);
    backdrop-filter: blur(2px);
}

/* Dashboard Styles */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 32px;
}

.dashboard-actions {
    margin-top: 24px;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.quick-actions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-actions-list .nav-link {
    color: var(--text-main);
    background: var(--light);
    padding: 12px;
}

/* Mobile specific overrides */
@media (max-width: 991px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .dashboard-actions {
        flex-direction: column;
        width: 100%;
    }

    .dashboard-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Settings Layout */
.settings-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 32px;
}

.settings-nav .card {
    position: sticky;
    top: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

/* Mobile Settings Overrides */
@media (max-width: 991px) {
    .settings-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .settings-nav {
        margin-bottom: 20px;
    }

    .settings-nav .card {
        position: static !important;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .settings-nav .btn {
        width: calc(50% - 4px) !important;
        margin-bottom: 0 !important;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .color-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 576px) {
    .settings-nav .btn {
        width: 100% !important;
    }
}

.add-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 16px;
    align-items: flex-end;
}

@media (max-width: 768px) {
    .add-form-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    /* Mobile Table Cards - The "Card View" */
    @media (max-width: 768px) {
        .table-responsive .table {
            display: block;
        }

        .table-responsive .table thead {
            display: none;
        }

        .table-responsive .table tbody {
            display: block;
        }

        .table-responsive .table tr {
            display: block;
            background: var(--white);
            margin-bottom: 16px;
            border: 1px solid var(--border);
            border-radius: var(--radius-md);
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        }

        .table-responsive .table td {
            display: flex;
            /* Changed from block to flex for alignment */
            flex-direction: column;
            align-items: flex-start;
            justify-content: center;
            text-align: left;
            padding: 12px 16px;
            border-bottom: 1px solid var(--border);
            position: relative;
            min-height: 40px;
        }

        .table-responsive .table td:last-child {
            border-bottom: none;
        }

        /* Add label */
        .table-responsive .table td::before {
            content: attr(data-label);
            font-weight: 600;
            font-size: 11px;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 6px;
            display: block;
        }

        /* Make Action buttons fit */
        .table-responsive .table td[data-label="Actions"]>div {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .table-responsive .table td[data-label="Actions"] form {
            flex: 1;
            min-width: 140px;
            /* Force wrap if too small */
        }

        .table-responsive .table td[data-label="Actions"] select {
            width: 100% !important;
            /* Override inline styles */
            margin-bottom: 4px;
        }
    }
}