/* =========================================
   1. VARIABLES & THEMES
   ========================================= */
:root {
    /* --- LIGHT MODE (Default) --- */
    --primary: #2563eb;       /* Royal Blue */
    --primary-dark: #1d4ed8;
    --brand: #10b981;         /* Mint Green */
    --brand-dark: #059669;
    
    /* Backgrounds */
    --bg-body: #f1f5f9;       /* Light Slate */
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;    /* Dark Navy */
    
    /* Typography */
    --text-main: #1e293b;     /* Dark Slate */
    --text-muted: #64748b;    /* Gray */
    
    /* Borders & Spacing */
    --border: #e2e8f0;
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius: 8px;
}

/* --- DARK MODE OVERRIDES --- */
[data-theme="dark"] {
    /* Dark Backgrounds */
    --bg-body: #020617;       /* Deepest Navy */
    --bg-card: #1e293b;       /* Lighter Navy */
    --bg-sidebar: #0f172a;    /* Keep Sidebar consistent */
    
    /* Light Text */
    --text-main: #f8fafc;     /* White-ish */
    --text-muted: #94a3b8;    /* Light Gray */
    
    /* Darker Borders */
    --border: #334155;        /* Dark Blue-Gray */
    
    /* Adjust Brand Colors for Contrast */
    --primary: #3b82f6;       /* Brighter Blue */
    --primary-dark: #2563eb;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Inter, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0; padding: 0;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

a { text-decoration: none; color: inherit; transition: 0.2s; }
ul { list-style: none; padding: 0; margin: 0; }
h1, h2, h3, h4 { margin: 0 0 10px 0; font-weight: 700; color: var(--text-main); }

/* =========================================
   2. MAIN APP LAYOUT
   ========================================= */
.app-wrapper { display: flex; min-height: 100vh; width: 100%; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: white;
    position: fixed; top: 0; bottom: 0; left: 0;
    display: flex; flex-direction: column; z-index: 1000;
    border-right: 1px solid rgba(255,255,255,0.05);
}

.brand-area {
    height: var(--header-height); display: flex; align-items: center; padding: 0 25px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.brand-area h3 { margin: 0; color: var(--brand); font-size: 22px; letter-spacing: 0.5px; }
.brand-area small { color: #94a3b8; font-size: 12px; margin-left: 8px; margin-top: 4px; }

.nav-menu { flex-grow: 1; padding-top: 20px; }
.nav-menu li a {
    display: flex; align-items: center; padding: 12px 25px;
    color: #cbd5e1; font-size: 15px; border-left: 4px solid transparent;
}
.nav-menu li a:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-menu li a.active {
    background: rgba(16, 185, 129, 0.1); color: var(--brand); border-left-color: var(--brand);
}
.nav-menu i { width: 25px; text-align: center; margin-right: 10px; }

.user-snippet {
    padding: 20px; border-top: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.2);
}
.user-snippet div { font-weight: bold; color: white; }
.user-snippet small { color: #94a3b8; font-size: 12px; }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 40px;
}

/* =========================================
   3. DASHBOARD COMPONENTS
   ========================================= */

.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}

/* Filter Buttons */
.filter-bar { display: flex; gap: 10px; }
.filter-btn {
    padding: 8px 18px; border-radius: 50px; font-size: 14px; font-weight: 600;
    color: var(--text-muted); background: var(--bg-card); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: 0.2s;
}
.filter-btn:hover { border-color: var(--brand); color: var(--brand); }
.filter-btn.active { background: var(--brand); color: white; border-color: var(--brand); }
.filter-btn span { opacity: 0.8; font-size: 11px; background: rgba(0,0,0,0.1); padding: 1px 6px; border-radius: 10px; }

/* --- ACCORDION --- */
.category-toggle {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 25px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 25px; margin-bottom: 15px;
    cursor: pointer; transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.category-toggle:hover { border-color: var(--primary); transform: translateY(-1px); }
.category-toggle.active { border-left: 5px solid var(--primary); background: var(--bg-body); }

.cat-title { font-size: 18px; font-weight: 700; color: var(--text-main); display: flex; align-items: center; gap: 12px; }
.cat-count { font-size: 12px; color: var(--text-muted); font-weight: 600; background: var(--bg-body); padding: 3px 10px; border-radius: 12px; border: 1px solid var(--border); }

.arrow-icon { font-size: 14px; color: var(--text-muted); transition: transform 0.3s ease; }
.category-toggle.active .arrow-icon { transform: rotate(90deg); color: var(--primary); }

/* Content Visibility */
.category-content { display: none !important; padding: 0 5px 30px 5px; }
.category-content.open { 
    display: grid !important; 
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); 
    gap: 20px; 
    animation: slideDown 0.3s ease-out; 
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* =========================================
   4. CARDS & BADGES
   ========================================= */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 25px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    transition: transform 0.2s;
    display: flex; flex-direction: column; height: 100%;
}
.card:hover { transform: translateY(-4px); box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.1); border-color: var(--border); }

.card h4 { font-size: 16px; margin: 10px 0; color: var(--text-main); line-height: 1.4; }
.card-top { margin-bottom: 15px; }

/* Badges */
.badge-row { display: flex; gap: 6px; margin-bottom: 12px; }
.badge { font-size: 10px; padding: 4px 8px; border-radius: 4px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.diff-Easy { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.diff-Medium { background: #fef9c3; color: #a16207; border: 1px solid #fde047; }
.diff-Hard { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.type-Badge { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* Card Footer */
.card-footer {
    margin-top: auto; padding-top: 18px;
    display: flex; justify-content: space-between; align-items: center;
    border-top: 1px solid var(--bg-body); min-height: 40px;
}
.status-done { color: var(--brand); font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.status-pending { color: var(--text-muted); font-size: 13px; font-weight: 500; }

/* Buttons */
.btn-card {
    padding: 0 20px; height: 36px; border-radius: 6px; font-size: 13px; font-weight: 600;
    text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; box-sizing: border-box;
}
.btn-start { background-color: var(--primary); color: white; border: 1px solid var(--primary); }
.btn-start:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); }

.btn-review { background-color: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
.btn-review:hover { border-color: var(--text-main); color: var(--text-main); transform: translateY(-1px); }

/* =========================================
   5. FORM STYLES
   ========================================= */
.form-layout { display: flex; flex-direction: column; gap: 20px; }
.form-row { display: flex; gap: 25px; }
.form-group { flex: 1; display: flex; flex-direction: column; }

.form-group label {
    font-weight: 600; font-size: 13px; color: var(--text-main); margin-bottom: 8px; display: block;
}
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 14px; background-color: var(--bg-card); color: var(--text-main);
    box-sizing: border-box; font-family: inherit; transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--primary); outline: none; }
.form-group input:disabled { background-color: var(--bg-body); color: var(--text-muted); cursor: not-allowed; }

.form-section-title {
    font-size: 18px; font-weight: 700; color: var(--text-main); margin-top: 10px; margin-bottom: 10px;
    padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.password-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; display: block; }

.btn-primary { background: var(--primary); color: white; border: none; padding: 10px 25px; border-radius: var(--radius); font-weight: 600; cursor: pointer; }
.btn-primary:hover { background: var(--primary-dark); }

/* =========================================
   6. LOGIN & REGISTER (Split Screen)
   ========================================= */
.auth-wrapper { display: flex; min-height: 100vh; width: 100%; background: var(--bg-card); }

.auth-banner {
    flex: 1; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    color: white; padding: 40px; text-align: center; position: relative; overflow: hidden;
}
.auth-banner h1 { color: white; font-size: 3rem; margin-bottom: 10px; }
.auth-banner p { color: #94a3b8; font-size: 1.1rem; max-width: 400px; line-height: 1.6; }

.auth-form-container {
    flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
    padding: 40px; background: var(--bg-card);
}
.auth-box { width: 100%; max-width: 400px; }
.auth-header { margin-bottom: 30px; }
.auth-header h2 { font-size: 28px; color: var(--text-main); margin-bottom: 5px; }
.auth-header p { color: var(--text-muted); font-size: 14px; }

.auth-input {
    width: 100%; padding: 14px; border: 1px solid var(--border); background: var(--bg-body);
    border-radius: 8px; font-size: 15px; margin-bottom: 15px; color: var(--text-main);
    transition: 0.2s; box-sizing: border-box;
}
.auth-input:focus { background: var(--bg-card); border-color: var(--primary); outline: none; }

.btn-auth {
    width: 100%; padding: 14px; background: var(--primary); color: white; border: none;
    border-radius: 8px; font-weight: 600; font-size: 16px; cursor: pointer; transition: 0.2s; margin-top: 10px;
}
.btn-auth:hover { background: var(--primary-dark); transform: translateY(-1px); }

.auth-footer { margin-top: 20px; text-align: center; font-size: 14px; color: var(--text-muted); }
.auth-link { color: var(--primary); font-weight: 600; text-decoration: none; }

/* Loaders */
.btn-loading { opacity: 0.7; cursor: not-allowed !important; pointer-events: none; }
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff;
    animation: spin 0.8s linear infinite; margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   7. CHALLENGE PAGE STYLES
   ========================================= */
.back-link { display: inline-flex; align-items: center; gap: 5px; color: var(--text-muted); font-size: 14px; font-weight: 500; margin-bottom: 20px; }
.back-link:hover { color: var(--primary); }

.challenge-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 30px;
}
.challenge-title { font-size: 28px; margin-bottom: 10px; color: var(--text-main); }

.challenge-layout { display: flex; gap: 40px; align-items: flex-start; }
.challenge-main { flex: 2; min-width: 0; } 
.challenge-sidebar { flex: 1; min-width: 300px; }

.desc-content { font-size: 16px; line-height: 1.7; color: var(--text-main); margin-bottom: 40px; }
.desc-content code { background: var(--bg-body); padding: 2px 6px; border-radius: 4px; color: #c7254e; font-family: monospace; border: 1px solid var(--border); }

/* Hint Box */
.hint-card {
    background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px; padding: 20px;
    margin-top: 30px; display: flex; flex-direction: column; gap: 10px;
}
[data-theme="dark"] .hint-card { background: #451a03; border-color: #78350f; }

.hint-title { color: #b45309; font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: 15px; }
[data-theme="dark"] .hint-title { color: #fbbf24; }

.hint-text { color: #92400e; font-size: 14px; margin: 0; line-height: 1.5; }
[data-theme="dark"] .hint-text { color: #fde68a; }

.btn-unlock {
    background: #f59e0b; color: white; border: none; padding: 8px 16px; border-radius: 6px;
    font-weight: 600; cursor: pointer; font-size: 13px; width: fit-content; transition: 0.2s;
}
.btn-unlock:hover { background: #d97706; }

/* Task Sidebar */
.task-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 25px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); position: sticky; top: 20px;
}
.task-section { margin-bottom: 20px; }
.task-label { font-size: 11px; text-transform: uppercase; font-weight: 700; color: var(--text-muted); margin-bottom: 8px; display: block; }

.target-display { background: var(--bg-body); border: 1px solid var(--border); border-radius: 6px; padding: 12px; }
.target-code {
    font-family: 'Courier New', monospace; font-weight: 600; color: var(--brand); background: var(--bg-card);
    padding: 6px; border: 1px solid var(--border); border-radius: 4px; display: block;
    word-break: break-all; font-size: 13px;
}
.target-link { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--brand); font-weight: 600; }

.submit-input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-family: monospace; font-size: 14px; background: var(--bg-card); color: var(--text-main); }
.btn-submit {
    width: 100%; background: var(--primary); color: white; border: none; padding: 12px;
    border-radius: 6px; font-weight: 600; cursor: pointer; margin-top: 10px;
}
.btn-submit:hover { background: var(--primary-dark); }

/* Reference Solution */
.solution-card {
    background: #1e293b; border-radius: 8px; margin-top: 40px; overflow: hidden; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.solution-header {
    background: #0f172a; padding: 12px 20px; color: #e2e8f0; font-weight: 600;
    display: flex; align-items: center; gap: 10px; font-size: 14px; border-bottom: 1px solid #334155;
}
.solution-code {
    padding: 20px; color: #a5b4fc; font-family: 'Consolas', 'Monaco', monospace;
    font-size: 14px; overflow-x: auto; margin: 0; line-height: 1.5;
}

/* =========================================
   8. RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    .app-wrapper { flex-direction: column; }
    .sidebar { position: relative; width: 100%; height: auto; }
    .nav-menu { display: flex; overflow-x: auto; white-space: nowrap; padding: 10px; }
    .main-content { margin-left: 0; width: 100%; padding: 20px; }
    .form-row { flex-direction: column; gap: 20px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 15px; }
    .filter-bar { overflow-x: auto; width: 100%; padding-bottom: 5px; }
    .challenge-layout { flex-direction: column; }
    .challenge-sidebar { width: 100%; min-width: 0; }
    .user-snippet { display: none; }
    .auth-banner { display: none; }
    .auth-wrapper { justify-content: center; padding: 20px; }
    .auth-form-container { flex: 0 1 450px; padding: 30px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); }
}