/**
 * RVNS LMS — Core Stylesheet
 * Consolidates: admin.css, student.css, pages.css, dashboard.css, style.css,
 *               animations.css, responsive.css, and all duplicated form/table styles.
 * All colors use CSS custom properties for easy theming & dark mode.
 */

/* ============================================================
   CUSTOM PROPERTIES
   ============================================================ */
:root {
    /* Brand */
    --color-primary:     #2563eb;
    --color-primary-hover:#1d4ed8;
    --color-accent:      #7c3aed;

    /* Backgrounds */
    --bg-root:     #020617;
    --bg-body:     #0f172a;
    --bg-surface:  #111827;
    --bg-raised:   #1e293b;
    --bg-input:    #1e293b;
    --bg-hover:    #263347;

    /* Text */
    --text-primary:  #f8fafc;
    --text-secondary:#cbd5e1;
    --text-muted:    #64748b;
    --text-disabled: #475569;

    /* Borders */
    --border-color:  #1e293b;
    --border-focus:  #2563eb;

    /* Status */
    --success: #22c55e;
    --warning: #f59e0b;
    --danger:  #ef4444;
    --info:    #3b82f6;

    /* Spacing scale */
    --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;  --sp-4: 16px;
    --sp-5: 20px;  --sp-6: 24px;  --sp-8: 32px;  --sp-10: 40px;

    /* Radius */
    --r-sm: 8px;  --r-md: 12px;  --r-lg: 16px;  --r-xl: 22px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
    --shadow-md: 0 8px 24px rgba(0,0,0,.4);
    --shadow-lg: 0 20px 50px rgba(0,0,0,.5);

    /* Transitions */
    --t: 0.2s ease;
}

/* Light mode override (opt-in via .light-mode on <html>) */
html.light-mode {
    --bg-root:    #f1f5f9;
    --bg-body:    #f8fafc;
    --bg-surface: #ffffff;
    --bg-raised:  #f1f5f9;
    --bg-input:   #f1f5f9;
    --bg-hover:   #e2e8f0;
    --text-primary:  #0f172a;
    --text-secondary:#334155;
    --text-muted:    #64748b;
    --border-color:  #e2e8f0;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img, video, audio { max-width: 100%; display: block; }

/* ============================================================
   LAYOUT: ADMIN
   ============================================================ */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: var(--sp-8);
    overflow-x: hidden;
    min-width: 0;
}

.two-col-layout {
    display: flex;
    gap: var(--sp-8);
    align-items: flex-start;
}

.sidebar-panel {
    width: 340px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-radius: var(--r-xl);
    padding: var(--sp-6);
    position: sticky;
    top: var(--sp-5);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.right-panel { flex: 1; min-width: 0; }

/* ============================================================
   LAYOUT: TOPBAR
   ============================================================ */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--sp-10);
    flex-wrap: wrap;
    gap: var(--sp-5);
}

.topbar h1 {
    font-size: clamp(24px, 3vw, 40px);
    font-weight: 800;
    line-height: 1.15;
}

.topbar p { color: var(--text-muted); margin-top: var(--sp-1); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-surface);
    border-radius: var(--r-xl);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: var(--sp-6);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-3);
}

.card-header h2 { font-size: 20px; font-weight: 700; }

.card-body { padding: var(--sp-6); }

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

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-6);
    margin-bottom: var(--sp-10);
}

.stat-card {
    background: var(--bg-surface);
    border-radius: var(--r-xl);
    padding: var(--sp-8);
    transition: transform var(--t);
    border: 1px solid var(--border-color);
}

.stat-card:hover { transform: translateY(-4px); }

.stat-card .stat-value {
    font-size: 42px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: var(--sp-2);
}

.stat-card .stat-label { color: var(--text-muted); font-size: 14px; }

.stat-card.accent-blue  .stat-value { color: var(--info); }
.stat-card.accent-green .stat-value { color: var(--success); }
.stat-card.accent-orange .stat-value { color: var(--warning); }
.stat-card.accent-red   .stat-value { color: var(--danger); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--r-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background var(--t), transform 0.1s;
    white-space: nowrap;
}

.btn:active { transform: scale(.98); }
.btn:hover  { text-decoration: none; }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary { background: var(--bg-raised); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }

.btn-success   { background: var(--success); color: #fff; }
.btn-warning   { background: var(--warning); color: #000; }
.btn-danger    { background: var(--danger);  color: #fff; }
.btn-info      { background: var(--info);    color: #fff; }

.btn-sm  { padding: var(--sp-2) var(--sp-3); font-size: 13px; }
.btn-lg  { padding: var(--sp-4) var(--sp-8); font-size: 16px; }
.btn-full { width: 100%; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: var(--sp-5); }

.form-group label {
    display: block;
    margin-bottom: var(--sp-2);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--r-md);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: border-color var(--t);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--border-focus);
}

.form-group textarea { min-height: 100px; resize: vertical; }

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: var(--sp-1); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-5);
}

.form-row .flex-2 { grid-column: span 2; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--r-md);
    margin-bottom: var(--sp-5);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.alert-success { background: rgba(34,197,94,.1);  border: 1px solid rgba(34,197,94,.3);  color: #86efac; }
.alert-error   { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.3);  color: #fca5a5; }
.alert-warning { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
.alert-info    { background: rgba(59,130,246,.1); border: 1px solid rgba(59,130,246,.3); color: #93c5fd; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
}

.badge-success   { background: rgba(34,197,94,.15);  color: #86efac; }
.badge-warning   { background: rgba(245,158,11,.15); color: #fcd34d; }
.badge-danger    { background: rgba(239,68,68,.15);  color: #fca5a5; }
.badge-info      { background: rgba(59,130,246,.15); color: #93c5fd; }
.badge-secondary { background: var(--bg-raised);     color: var(--text-muted); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

table th {
    background: var(--bg-raised);
    padding: 14px 18px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: .04em;
    text-transform: uppercase;
}

table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    vertical-align: middle;
}

table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--bg-hover); }

/* ============================================================
   PROGRESS BARS
   ============================================================ */
.progress-bar-wrap {
    background: var(--bg-raised);
    border-radius: 99px;
    height: 8px;
    overflow: hidden;
    width: 100%;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--color-primary);
    transition: width 0.6s ease;
}

.progress-bar-fill.green  { background: var(--success); }
.progress-bar-fill.orange { background: var(--warning); }
.progress-bar-fill.red    { background: var(--danger); }

/* ============================================================
   LESSON ITEMS (admin sidebar panel)
   ============================================================ */
.lesson-item {
    background: var(--bg-raised);
    border-radius: var(--r-lg);
    padding: var(--sp-5);
    margin-bottom: var(--sp-4);
}

.lesson-item-header {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--sp-2);
}

.lesson-order {
    background: var(--color-primary);
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.lesson-icon { font-size: 18px; }

.lesson-item h3 {
    font-size: 14px;
    font-weight: 600;
    margin: var(--sp-2) 0;
    color: var(--text-primary);
}

.lesson-tags { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-bottom: var(--sp-3); }

.lesson-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-top: var(--sp-3);
}

/* ============================================================
   EMPTY STATES
   ============================================================ */
.empty-state {
    text-align: center;
    padding: var(--sp-10);
    color: var(--text-muted);
}

.empty-state p { font-size: 15px; }

/* ============================================================
   NOTES BOX
   ============================================================ */
.notes-box {
    background: var(--bg-raised);
    border-radius: var(--r-md);
    padding: var(--sp-5);
}

.notes-box h4 { font-size: 15px; font-weight: 600; margin-bottom: var(--sp-2); }
.notes-box p  { color: var(--text-secondary); font-size: 14px; line-height: 1.7; }

.lesson-content-preview {
    background: var(--bg-raised);
    border-radius: var(--r-md);
    padding: var(--sp-6);
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-secondary);
}

/* ============================================================
   UTILITIES
   ============================================================ */
.mt-3 { margin-top: var(--sp-6); }
.mt-4 { margin-top: var(--sp-8); }
.text-muted   { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-center  { text-align: center; }
.fw-bold { font-weight: 700; }
.d-flex { display: flex; }
.gap-2  { gap: var(--sp-4); }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease forwards; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .5; }
}

.skeleton {
    background: var(--bg-raised);
    border-radius: var(--r-sm);
    animation: pulse 1.5s ease-in-out infinite;
}

/* ============================================================
   DARK MODE TOGGLE
   ============================================================ */
.dark-mode-toggle {
    background: var(--bg-raised);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-primary);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
    .two-col-layout { flex-direction: column; }
    .sidebar-panel  { width: 100%; position: relative; max-height: none; }
}

@media (max-width: 768px) {
    .main-content { padding: var(--sp-5); }
    .topbar h1    { font-size: 26px; }
    .topbar       { flex-direction: column; align-items: flex-start; }
    .stat-grid    { grid-template-columns: 1fr 1fr; }
    .admin-layout { flex-direction: column; }
    .form-row .flex-2 { grid-column: span 1; }
    table { min-width: 100%; }
    .lesson-actions { flex-direction: column; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 24px 20px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-raised); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-color); }

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .admin-layout, .sidebar-panel, .lesson-actions, .topbar .btn { display: none !important; }
    .main-content { padding: 0; }
    body { background: #fff; color: #000; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
