:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-main: #f8fafc;
    --sidebar-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --card-bg: rgba(255, 255, 255, 0.8);
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    padding: 0 24px;
    margin-bottom: 40px;
    gap: 12px;
}

.logo-icon {
    color: var(--primary);
    width: 28px;
    height: 28px;
}

.logo span {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.025em;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 12px;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-link:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

.nav-link.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3);
}

.nav-link i {
    width: 20px;
    height: 20px;
}

.sidebar-footer {
    padding: 0 12px;
    margin-top: auto;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--danger);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius);
}

.logout-btn:hover {
    background: #fef2f2;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-bar {
    height: 72px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border);
    z-index: 5;
}

.page-title h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

/* Page Content */
#content-area {
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.content-animate {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.stat-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.blue {
    background: #eff6ff;
    color: #3b82f6;
}

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

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

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
}

/* Charts & Lists */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

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

/* Tables */
.table-container {
    overflow-x: auto;
}

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

th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    padding: 32px;
}

.hidden {
    display: none !important;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin: 40px auto;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Login Page */
.login-body {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 24px;
    box-shadow:
        0 20px 25px -5px rgba(0, 0, 0, 0.1),
        0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.5);
    transition: transform 0.2s;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo-large {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.3);
}

.logo-icon-large {
    color: white;
    width: 32px;
    height: 32px;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.input-wrapper input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
    background: #f8fafc;
}

.input-wrapper input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    margin-top: 12px;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.error-message {
    background: #fef2f2;
    color: var(--danger);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #fee2e2;
}

.error-message i {
    width: 18px;
    height: 18px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Animations */
.shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* Responsive Styles */
/* Mobile Sidebar Overlay & Close */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 90;
    /* Below sidebar (100) but above everything else */
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-toggle {
    display: none !important;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
    /* Improvements for touch */
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    z-index: 200;
    /* Extremely high to ensure clickability */
    position: relative;
}

.mobile-toggle:hover {
    background: #f1f5f9;
}

@media (max-width: 1024px) {
    .mobile-toggle {
        display: flex !important;
    }

    .sidebar-close-btn {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.1);
        z-index: 100;
    }

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

    .main-content {
        width: 100%;
    }

    .top-bar {
        padding: 0 16px;
    }

    #content-area {
        padding: 16px;
    }

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

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

    .modal-content {
        margin: 16px;
        padding: 24px;
    }
}

@media (max-width: 640px) {
    .user-info span {
        display: none;
    }

    .page-title h1 {
        font-size: 1.1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    td,
    th {
        padding: 12px 8px;
        font-size: 0.8rem;
    }
}

/* Settings Styles */
.settings-tabs {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.tab-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 8px;
    transition: all 0.2s;
}

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

.settings-section {
    display: none;
}

.settings-section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e1;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--primary);
}

input:checked+.slider:before {
    -webkit-transform: translateX(24px);
    -ms-transform: translateX(24px);
    transform: translateX(24px);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-info h4 {
    margin-bottom: 4px;
}

.setting-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-control-area {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.9rem;
    resize: vertical;
    background: #f8fafc;
}

.form-control-area:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}