/* ====== DESIGN SYSTEM - DARK THEME ====== */
/* Reference: stitch-refrence/my_design_system/DESIGN.md */
/* Font: Vazirmatn | Theme: Dark | Primary: #aac7ff */

:root {
    --bg: #10131a;
    --surface: #10131a;
    --surface-low: #181c22;
    --surface-container: #1c2026;
    --surface-high: #272a31;
    --surface-highest: #32353c;
    --surface-lowest: #0b0e15;
    --on-surface: #e0e2ec;
    --on-surface-variant: #c1c6d5;
    --primary: #aac7ff;
    --primary-container: #4090fe;
    --secondary: #afc7f7;
    --secondary-container: #2e4770;
    --tertiary: #ffb68c;
    --tertiary-container: #e3711f;
    --outline: #8b919f;
    --outline-variant: #414753;
    --error: #ffb4ab;

    /* Legacy compat */
    --primary-color: #aac7ff;
    --secondary-color: #afc7f7;
    --dark-bg: #10131a;
    --dark-card: #1c2026;
    --dark-border: #414753;
    --text-primary: #e0e2ec;
    --text-secondary: #c1c6d5;
    --accent-purple: #aac7ff;
    --accent-pink: #ffb68c;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    background-color: var(--bg) !important;
    color: var(--on-surface) !important;
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif !important;
    direction: rtl;
    max-width: 100%;
    overflow-x: hidden;
}

img, video, iframe, canvas, svg {
    max-width: 100%;
}

table {
    display: block;
    width: 100%;
    overflow-x: auto;
}

/* ====== BOOTSTRAP OVERRIDES - Force dark theme ====== */
.bg-white { background-color: var(--surface-container) !important; color: var(--on-surface) !important; }
.bg-light { background-color: var(--surface-high) !important; color: var(--on-surface) !important; }
.bg-light\! { background-color: var(--surface-high) !important; }

.card {
    background-color: var(--surface-container) !important;
    border-color: var(--outline-variant) !important;
    color: var(--on-surface) !important;
}
.card-body { background-color: transparent !important; }

.table {
    color: var(--on-surface) !important;
    background-color: transparent !important;
}
.table-light, .table thead {
    background-color: var(--surface-high) !important;
    color: var(--on-surface) !important;
    --bs-table-bg: var(--surface-high) !important;
    --bs-table-color: var(--on-surface) !important;
}
.table tbody tr { background-color: transparent !important; }
.table tbody tr:hover { background-color: var(--surface-high) !important; }

.alert {
    background-color: var(--surface-container) !important;
    border-color: var(--outline-variant) !important;
    color: var(--on-surface) !important;
}
.alert-info { background-color: rgba(170, 199, 255, 0.1) !important; border-color: var(--primary) !important; }

.form-control, .form-select, .form-check-input {
    background-color: var(--surface-low) !important;
    border-color: var(--outline-variant) !important;
    color: var(--on-surface) !important;
}
.form-control:focus, .form-select:focus {
    background-color: var(--surface-container) !important;
    border-color: var(--primary) !important;
    color: var(--on-surface) !important;
    box-shadow: 0 0 0 3px rgba(170, 199, 255, 0.15) !important;
}
.form-control::placeholder { color: var(--outline) !important; }

.modal-content {
    background-color: var(--surface-container) !important;
    border-color: var(--outline-variant) !important;
    color: var(--on-surface) !important;
}
.modal-header, .modal-footer {
    border-color: var(--outline-variant) !important;
}

.nav-tabs {
    border-bottom: 2px solid var(--outline-variant) !important;
}
.nav-tabs .nav-link {
    color: var(--on-surface-variant) !important;
    border: none !important;
    border-bottom: 3px solid transparent !important;
    font-weight: 600 !important;
    background: transparent !important;
}
.nav-tabs .nav-link:hover {
    color: var(--primary) !important;
    border-bottom-color: var(--primary) !important;
}
.nav-tabs .nav-link.active {
    color: var(--primary) !important;
    background-color: transparent !important;
    border-bottom-color: var(--primary) !important;
}
.tab-content { color: var(--on-surface) !important; }

.text-muted { color: var(--on-surface-variant) !important; }
.text-primary { color: var(--primary) !important; }
.text-success { color: #7dd3a8 !important; }
.text-warning { color: var(--tertiary) !important; }
.text-danger { color: var(--error) !important; }

.btn-primary {
    background: linear-gradient(135deg, #4248d4 0%, var(--primary) 100%) !important;
    border-color: transparent !important;
    color: #002f64 !important;
    font-weight: 700 !important;
    transition: all 0.3s ease !important;
}
.btn-primary:hover {
    opacity: 0.9 !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 20px rgba(170, 199, 255, 0.2) !important;
}
.btn-outline-secondary {
    border-color: var(--outline-variant) !important;
    color: var(--on-surface-variant) !important;
}
.btn-outline-secondary:hover {
    background-color: var(--surface-high) !important;
    color: var(--on-surface) !important;
}

.badge {
    padding: 0.4rem 0.8rem !important;
    border-radius: 0.5rem !important;
    font-weight: 600 !important;
}
.badge.bg-primary { background-color: rgba(170, 199, 255, 0.2) !important; color: var(--primary) !important; }
.badge.bg-info { background-color: rgba(175, 199, 247, 0.2) !important; color: var(--secondary) !important; }
.badge.bg-danger { background-color: rgba(255, 180, 171, 0.2) !important; color: var(--error) !important; }
.badge.bg-success { background-color: rgba(125, 211, 168, 0.2) !important; color: #7dd3a8 !important; }

.progress { background-color: var(--surface-highest) !important; border-radius: 0.5rem !important; }
.progress-bar { background: linear-gradient(90deg, #4248d4, var(--primary)) !important; }

.rounded-4 { border-radius: 1rem !important; }
.shadow-sm { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important; }

/* ====== APP LAYOUT ====== */
.app-layout {
    display: flex;
    height: 100vh;
    background-color: var(--bg);
}

/* ====== SIDEBAR ====== */
.sidebar {
    width: 260px;
    background: var(--surface-low);
    border-left: 1px solid var(--outline-variant);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
    position: fixed;
    height: 100vh;
    right: 0;
    z-index: 1000;
    transition: transform 0.34s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.34s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.24s ease;
    will-change: transform;
}

/* Collapsed state — sidebar slides off-screen (RTL: to the right) */
.app-layout.sidebar-collapsed .sidebar {
    transform: translateX(100%);
    opacity: 0.4;
    pointer-events: none;
}
.app-layout.sidebar-collapsed .main-layout {
    margin-right: 0;
}

.sidebar-header {
    margin-bottom: 2rem;
    text-align: center;
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.logo-subtitle {
    font-size: 0.8rem;
    color: var(--on-surface-variant);
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    color: var(--on-surface-variant);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-item:hover {
    background-color: var(--surface-container);
    color: var(--primary);
    text-decoration: none;
}

.nav-item.active {
    background-color: var(--surface-high);
    color: var(--primary);
    font-weight: 700;
}

.nav-icon { font-size: 1.3rem; }
.nav-label { font-weight: inherit; }

/* Today's Challenge Button */
.btn-today-challenge {
    width: calc(100% - 1.7rem);
    align-self: center;
    background: linear-gradient(135deg, #4248d4 0%, #9197ff 100%);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem auto 0;
    text-decoration: none;
    font-family: 'Vazirmatn', sans-serif;
    box-shadow: 0 4px 15px rgba(66, 72, 212, 0.3);
}
.btn-today-challenge:hover {
    opacity: 0.9;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(66, 72, 212, 0.4);
    color: white;
    text-decoration: none;
}

.sidebar-footer {
    border-top: 1px solid var(--outline-variant);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.75rem;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}
.user-profile:hover {
    background-color: var(--surface-container);
    text-decoration: none;
    color: inherit;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
}

.user-info { flex: 1; }
.user-name { font-size: 0.9rem; font-weight: 600; margin: 0; color: var(--on-surface); }
.user-role { font-size: 0.75rem; color: var(--on-surface-variant); margin: 0; }

.btn-logout {
    width: 100%;
    padding: 0.5rem;
    background-color: rgba(255, 180, 171, 0.1);
    color: var(--error);
    border: 1px solid rgba(255, 180, 171, 0.3);
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.875rem;
}
.btn-logout:hover {
    background-color: rgba(255, 180, 171, 0.2);
    border-color: rgba(255, 180, 171, 0.5);
}

/* ====== MAIN LAYOUT ====== */
.main-layout {
    flex: 1;
    margin-right: 260px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    transition: margin-right 0.34s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====== TOP HEADER ====== */
.top-header {
    background-color: var(--surface-low);
    border-bottom: 1px solid var(--outline-variant);
    padding: 0.875rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.btn-menu {
    background: rgba(170, 199, 255, 0.06);
    border: 1px solid rgba(170, 199, 255, 0.18);
    color: var(--on-surface);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.4rem 0.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.65rem;
    transition: all 0.2s ease;
}
.btn-menu:hover {
    background: rgba(170, 199, 255, 0.14);
    border-color: rgba(170, 199, 255, 0.35);
    transform: translateY(-1px);
}
.btn-menu:active { transform: translateY(0); }

.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--surface-container);
    border: 1px solid var(--outline-variant);
    border-radius: 0.625rem;
    padding: 0.5rem 1rem;
}
.search-box input {
    background: none;
    border: none;
    color: var(--on-surface);
    outline: none;
    width: 200px;
    font-size: 0.875rem;
    font-family: 'Vazirmatn', sans-serif;
}
.search-box input::placeholder { color: var(--outline); }
.search-icon { color: var(--on-surface-variant); }
.search-submit-btn {
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-notification, .btn-settings {
    background: none;
    border: none;
    color: var(--on-surface-variant);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    position: relative;
}
.btn-notification:hover, .btn-settings:hover {
    background-color: var(--surface-container);
    color: var(--on-surface);
}
.btn-notification.has-unread {
    color: #f1c0e3;
}
.btn-notification.has-unread .notification-icon {
    animation: bellPulse 1.8s ease-in-out infinite;
}

.btn-upload {
    background: linear-gradient(135deg, #4248d4, #9197ff);
    border: none;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    transition: all 0.2s ease;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-weight: 600;
    font-size: 0.85rem;
    box-shadow: 0 2px 10px rgba(66, 72, 212, 0.3);
    font-family: 'Vazirmatn', sans-serif;
}
.btn-upload:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(66, 72, 212, 0.4);
    color: white;
    text-decoration: none;
}
.upload-icon { font-size: 1.1rem; }

.notification-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    background-color: var(--error);
    color: #1a0000;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    min-width: 16px;
    padding: 0 2px;
}

@keyframes bellPulse {
    0%, 100% { transform: rotate(0deg); }
    15% { transform: rotate(-10deg); }
    30% { transform: rotate(10deg); }
    45% { transform: rotate(-6deg); }
    60% { transform: rotate(6deg); }
}

/* Header profile avatar link */
.header-profile-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}
.header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
    cursor: pointer;
    transition: all 0.2s ease;
}
.header-avatar:hover {
    border-color: var(--secondary);
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(170, 199, 255, 0.2);
}

/* ====== MAIN CONTENT ====== */
.main-content {
    position: relative;
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 14% 8%, rgba(170, 199, 255, 0.07), transparent 24%),
        radial-gradient(circle at 86% 12%, rgba(125, 211, 168, 0.05), transparent 22%),
        linear-gradient(120deg, rgba(66, 72, 212, 0.035), rgba(227, 113, 31, 0.024), rgba(175, 199, 247, 0.03));
    background-size: 150% 150%, 150% 150%, 240% 240%;
    animation: pageBackdropEnter 0.45s ease-out both, pageBackdropDrift 34s ease-in-out infinite alternate;
}

.main-content > * {
    animation: pageRise 0.52s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

/* ====== SCROLLBAR ====== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--outline-variant); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--outline); }

/* ====== ANIMATIONS ====== */
@keyframes slideInRight { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideInLeft { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pageRise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pageBackdropEnter { from { opacity: 0.4; } to { opacity: 1; } }
@keyframes pageBackdropDrift {
    0% { background-position: 0% 0%, 100% 0%, 0% 0%; }
    100% { background-position: 10% 12%, 90% 8%, 100% 100%; }
}
@keyframes chartReveal {
    from { opacity: 0; transform: scaleX(0); }
    to { opacity: 1; transform: scaleX(1); }
}
@keyframes ringReveal {
    from { opacity: 0; transform: scale(0.94); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(170, 199, 255, 0.3); }
    50% { box-shadow: 0 0 0 10px rgba(170, 199, 255, 0); }
}

.animate-page {
    animation: pageRise 0.52s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    animation-delay: var(--delay, 0s);
}

.animate-page.delay-1 { --delay: 0.08s; }
.animate-page.delay-2 { --delay: 0.16s; }
.animate-page.delay-3 { --delay: 0.24s; }
.animate-page.delay-4 { --delay: 0.32s; }
.animate-page.delay-5 { --delay: 0.4s; }

.progress-fill,
.progress-bar {
    transform-origin: right center;
    animation: chartReveal 0.85s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    animation-delay: var(--delay, 0s);
}

.growth-ring {
    animation: ringReveal 0.85s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    animation-delay: var(--delay, 0s);
}

.sidebar { animation: slideInRight 0.4s ease-out; }
.main-layout { animation: slideInLeft 0.4s ease-out; }

@media (prefers-reduced-motion: reduce) {
    .main-content,
    .main-content > *,
    .animate-page,
    .progress-fill,
    .progress-bar,
    .growth-ring,
    .sidebar,
    .main-layout {
        animation: none !important;
        transition: none !important;
    }
}

.animate-slide-up { animation: slideUp 0.5s ease-out; }
.animate-scale-in { animation: scaleIn 0.5s ease-out; }
.animate-fade-in { animation: fadeIn 0.5s ease-out; }

.hover-lift { transition: all 0.25s ease; }
.hover-lift:hover { transform: translateY(-4px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }

/* ====== RESPONSIVE ====== */
@media (max-width: 1024px) {
    .sidebar { width: 220px; }
    .main-layout { margin-right: 220px; }
    .search-box input { width: 150px; }
}

/* Mobile sidebar overlay backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.active { display: block; }

@media (max-width: 768px) {
    .btn-menu { display: flex !important; align-items: center; justify-content: center; }

    /* Sidebar becomes a fixed drawer from the right */
    .sidebar {
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 280px !important;
        height: 100vh;
        position: fixed !important;
        top: 0;
        right: 0;
        z-index: 1000;
        box-shadow: -8px 0 32px rgba(0,0,0,0.4);
    }
    .sidebar.open {
        transform: translateX(0);
    }

    .main-layout {
        margin-right: 0 !important;
        width: 100%;
    }

    .top-header {
        gap: 0.75rem;
        flex-wrap: wrap;
    }
    .header-left, .header-right {
        width: 100%;
        justify-content: space-between;
    }
    .search-box {
        flex: 1;
        min-width: 0;
    }
    .search-box input { width: 100%; }
    .main-content { padding: 1rem; }
}

@media (max-width: 480px) {
    .top-header { padding: 0.75rem 1rem; }
    .main-content { padding: 0.75rem; }
    .btn-upload span:last-child { display: none; }
    .btn-upload {
        padding: 0.5rem 0.75rem;
    }
}
