/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --info: #0ea5e9;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

/* --- Navbar --- */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.nav-brand a { color: white; font-size: 1.25rem; font-weight: 700; text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-user { color: rgba(255,255,255,0.85); }

/* --- Container --- */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.5); color: white; }
.btn-outline:hover { background: rgba(255,255,255,0.15); text-decoration: none; }
.btn-block { width: 100%; text-align: center; }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-weight: 500; font-size: 0.9rem; }
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: white;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }

.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; padding: 0.75rem 0; }
.inline-form input,
.inline-form select { padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.3rem; font-weight: normal; cursor: pointer; }

/* --- Alerts --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* --- Sections --- */
.section { margin-bottom: 2.5rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h2 { margin: 0; }

/* --- Tables --- */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f1f5f9; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; }
td { font-size: 0.9rem; }
.actions { white-space: nowrap; display: flex; gap: 0.3rem; }

/* --- Cards --- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-accepted { border-left: 4px solid var(--success); }
.card-rejected { border-left: 4px solid var(--danger); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; gap: 0.5rem; flex-wrap: wrap; }
.card-header h3 { margin: 0; font-size: 1.05rem; }
.card-text { color: #475569; margin-bottom: 0.5rem; }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; flex-wrap: wrap; }

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fef2f2; color: #991b1b; }

/* --- Call banner (big, student page) --- */
.call-banner-big {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    padding: 1.5rem 2rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.3);
    animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 4px 20px rgba(79, 70, 229, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(79, 70, 229, 0.5); }
}
.call-icon { font-size: 2.5rem; line-height: 1; }
.call-info { flex: 1; }
.call-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.15rem; }
.call-date-display { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.15rem; }
.call-link-url { font-size: 0.8rem; opacity: 0.75; word-break: break-all; }
.call-date-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--primary); margin-bottom: 0.2rem; }
.btn-call {
    background: white;
    color: var(--primary);
    padding: 0.75rem 1.75rem;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 1rem;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-call:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); text-decoration: none; }

/* --- Admin call link button --- */
.btn-outline-dark {
    background: transparent;
    border: 1px solid var(--border);
    color: #64748b;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
}
.btn-outline-dark:hover { background: #f1f5f9; text-decoration: none; }

/* --- Teacher comment --- */
.teacher-comment {
    background: #fef3c7;
    padding: 0.75rem;
    border-radius: var(--radius);
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

/* --- Submit form --- */
.submit-form {
    border-top: 1px solid var(--border);
    margin-top: 1rem;
    padding-top: 1rem;
}
.submit-form h4 { margin-bottom: 0.75rem; font-size: 0.95rem; }

/* --- Due date --- */
.due-date { font-size: 0.85rem; color: #64748b; margin-bottom: 0.5rem; }

/* --- Login --- */
.login-wrapper { display: flex; justify-content: center; align-items: center; min-height: 70vh; }
.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
}
.login-card h1 { margin-bottom: 0.25rem; text-align: center; }
.subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.5rem; }

/* --- Tests --- */
.question-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.question-number {
    background: var(--primary);
    color: white;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
    margin-top: 0.3rem;
}
.question-fields { flex: 1; }
.question-fields .form-group { margin-bottom: 0.5rem; }

.question-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.question-header { margin-bottom: 0.5rem; }
.question-num { font-weight: 700; color: var(--primary); }
.question-text { margin-bottom: 0.75rem; font-size: 1.05rem; }
.test-form .btn-block { margin-top: 1.5rem; padding: 0.75rem; font-size: 1.05rem; }

.result-banner {
    text-align: center;
    padding: 2rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    color: white;
}
.result-perfect { background: linear-gradient(135deg, #16a34a, #22c55e); }
.result-good { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.result-bad { background: linear-gradient(135deg, #dc2626, #ef4444); }
.result-score { font-size: 2.5rem; font-weight: 800; }
.result-percent { font-size: 1.2rem; opacity: 0.9; margin-top: 0.25rem; }

.answer-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}
.answer-correct { border-left: 4px solid var(--success); background: #f0fdf4; }
.answer-wrong { border-left: 4px solid var(--danger); background: #fef2f2; }
.answer-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.correct-answer { color: var(--success); }

.row-correct { background: #f0fdf4; }
.row-wrong { background: #fef2f2; }
.row-warning { background: #fffbeb; }

/* --- Admin alerts --- */
.alert-banner {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}
.alert-banner-danger {
    background: #fef2f2;
    border: 2px solid #fca5a5;
    color: #991b1b;
}
.alert-student { font-weight: 600; color: #991b1b; }

.row-no-hw { background: #fff5f5 !important; }
.row-no-hw td:first-child { border-left: 4px solid var(--danger); }

.no-hw-badge {
    display: inline-block;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.4rem;
    vertical-align: middle;
    animation: blink-badge 2s ease-in-out infinite;
}
@keyframes blink-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- Archive --- */
.archive-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.assign-form { margin-top: 0.75rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.assign-form details summary { list-style: none; }
.assign-form details summary::-webkit-details-marker { display: none; }

/* --- Student profile --- */
.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0 1.5rem;
    flex-wrap: wrap;
}
.profile-header h1 { margin: 0; }

.student-note-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.2rem;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card.stat-success { border-left: 4px solid var(--success); }
.stat-card.stat-danger { border-left: 4px solid var(--danger); }
.stat-card.stat-warning { border-left: 4px solid var(--warning); }
.stat-number { font-size: 2rem; font-weight: 800; color: var(--text); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }

/* Chart */
.chart-container {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    overflow-x: auto;
}

/* Test results list */
.test-results-list { display: flex; flex-direction: column; gap: 0.5rem; }
.test-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    flex-wrap: wrap;
}
.result-item-perfect { background: #f0fdf4; border-left: 3px solid var(--success); }
.result-item-good { background: #eff6ff; border-left: 3px solid #2563eb; }
.result-item-bad { background: #fef2f2; border-left: 3px solid var(--danger); }
.test-score { margin-left: auto; font-weight: 700; }

/* Error bar */
.error-bar {
    position: relative;
    background: #f1f5f9;
    border-radius: 4px;
    height: 24px;
    min-width: 120px;
    overflow: hidden;
}
.error-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: linear-gradient(90deg, #fbbf24, #ef4444);
    border-radius: 4px;
    transition: width 0.3s;
}
.error-bar span {
    position: relative;
    z-index: 1;
    padding: 0 8px;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 24px;
}

/* Lesson history */
.lessons-list { display: flex; flex-direction: column; gap: 0.5rem; }
.lesson-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.lesson-date {
    min-width: 90px;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.85rem;
}
.lesson-content { flex: 1; }
.lesson-content p { margin-top: 0.25rem; font-size: 0.85rem; }

/* --- Canvas annotator --- */
.annotator-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 1rem 0;
}
.tool-group {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.tool-btn {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s;
}
.tool-btn:hover { background: #f1f5f9; }
.tool-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

.canvas-wrapper {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: white;
}
.canvas-wrapper canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
    touch-action: none;
}

.text-input-overlay {
    position: fixed;
    z-index: 1000;
    display: flex;
    gap: 0.3rem;
    padding: 0.5rem;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.text-input-overlay input {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
    width: 200px;
}

#colorPicker {
    width: 36px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}
#lineWidth {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}

/* --- Calendar --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    margin-top: 1rem;
}
.calendar-day {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 120px;
    overflow: hidden;
}
.calendar-today {
    border-color: var(--primary);
    border-width: 2px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15);
}
.calendar-day-header {
    background: #f1f5f9;
    padding: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}
.calendar-today .calendar-day-header { background: #eef2ff; color: var(--primary); }
.calendar-date { color: var(--text-muted); font-size: 0.8rem; }
.calendar-lessons { padding: 0.5rem; }
.calendar-lesson {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem;
    margin-bottom: 0.3rem;
    border-radius: 4px;
    background: #f8fafc;
    flex-wrap: wrap;
}
.calendar-lesson.lesson-passed { background: #fef3c7; border-left: 3px solid var(--warning); }
.lesson-time { font-weight: 700; font-size: 0.85rem; color: var(--primary); min-width: 40px; }
.lesson-name { font-size: 0.85rem; font-weight: 500; flex: 1; }
.lesson-link { font-size: 1rem; text-decoration: none; }
.lesson-action { font-size: 0.7rem; padding: 0.15rem 0.4rem; }
.calendar-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 1rem 0; }

/* --- Post lesson --- */
.post-lesson-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.post-lesson-section:last-of-type { border-bottom: none; }
.post-lesson-section h3 { margin-bottom: 0.75rem; }

.hw-quick-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}
.hw-quick-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: normal;
}
.hw-quick-item:hover { background: #eef2ff; }
.hw-quick-item input[type="checkbox"] { flex-shrink: 0; }

/* --- Utilities --- */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.link { color: var(--primary); font-weight: 500; }

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .container { padding: 1rem; }

    .form-row { flex-direction: column; gap: 0; }
    .form-row .form-group { min-width: 100%; }

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

    .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }

    .call-banner-big { flex-direction: column; text-align: center; padding: 1.25rem; }
    .call-icon { font-size: 2rem; }
    .btn-call { width: 100%; text-align: center; }

    .inline-form { flex-direction: column; align-items: stretch; }

    table { font-size: 0.8rem; }
    th, td { padding: 0.5rem; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }

    .profile-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }

    .annotator-toolbar { flex-direction: column; align-items: stretch; }
    .tool-group { justify-content: center; }

    .navbar { padding: 0.5rem 1rem; }
    .nav-brand a { font-size: 1.1rem; }
    .nav-user { font-size: 0.85rem; }

    .lesson-item { flex-direction: column; gap: 0.25rem; }
    .lesson-date { min-width: auto; }

    .test-result-item { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
    .test-score { margin-left: 0; }

    .actions { flex-direction: column; }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }

    .calendar-grid { grid-template-columns: 1fr; }
    .calendar-day { min-height: auto; }
}

@media (max-width: 480px) {
    .container { padding: 0.75rem; }
    .stat-number { font-size: 1.5rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .stat-card { padding: 0.75rem; }
}
