@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #334155;
    --sidebar-text: #cbd5e1;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text: #0f172a;
    --text-secondary: #334155;
    --muted: #64748b;
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #0284c7;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
    --header-h: 52px;
    --sidebar-w: 220px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-weight: 400;
}

a { color: var(--primary); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--primary-dark); }

/* Header */
.top-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 0.75rem; }

.menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    color: var(--text);
    font-size: 1.1rem;
    line-height: 1;
}

.header-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; font-size: 0.95rem; color: var(--text); }
.brand-icon {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    width: 32px; height: 32px;
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.brand-text { white-space: nowrap; }
.brand-text-short { display: none; }

.header-user { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.user-name { font-weight: 500; color: var(--text-secondary); }

.role-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: capitalize;
}

/* Layout */
.app-container { display: flex; min-height: calc(100vh - var(--header-h) - 40px); }

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    flex-shrink: 0;
    overflow-y: auto;
    transition: transform 0.2s ease;
}

.sidebar nav { padding: 0.5rem 0; }

.sidebar .nav-section {
    color: #64748b;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.85rem 1rem 0.3rem;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--sidebar-text);
    padding: 0.45rem 1rem;
    margin: 1px 0.5rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-link:hover { background: var(--sidebar-hover); color: #f1f5f9; text-decoration: none; }
.sidebar .nav-link.active { background: var(--sidebar-active); color: #fff; }

.main-content {
    flex: 1;
    padding: 1rem 1.25rem;
    overflow-x: hidden;
    min-width: 0;
}

/* Page */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--muted);
    font-size: 0.85rem;
    margin: -0.5rem 0 1rem;
}

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

.card h2 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.85rem;
    color: var(--text);
}

.card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.85rem 1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stat-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.stat-icon.blue { background: #eff6ff; color: #2563eb; }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.purple { background: #f5f3ff; color: #7c3aed; }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }

.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-card .stat-label { color: var(--muted); font-size: 0.75rem; font-weight: 500; }

/* Tables */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    position: sticky;
    top: 0;
}

tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: none; }

/* Forms */
.form-group { margin-bottom: 0.85rem; }
.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--card);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-inline { display: flex; gap: 0.65rem; align-items: end; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.42rem 0.85rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; text-decoration: none; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { color: white; text-decoration: none; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { color: white; text-decoration: none; }
.btn-outline { background: var(--card); border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { background: #f8fafc; text-decoration: none; color: var(--text); }
.btn-sm { padding: 0.28rem 0.6rem; font-size: 0.75rem; }

/* Alerts & Badges */
.alert {
    padding: 0.65rem 0.85rem;
    border-radius: 6px;
    margin-bottom: 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }

.badge {
    display: inline-block;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: #f1f5f9; color: var(--muted); }
.badge-draft { background: var(--warning-bg); color: var(--warning); }
.badge-submitted { background: var(--success-bg); color: var(--success); }

.grade-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 700;
}
.grade-a, .grade-pill.grade-a { background: #ecfdf5; color: #059669; }
.grade-b, .grade-pill.grade-b { background: #eff6ff; color: #2563eb; }
.grade-c, .grade-pill.grade-c { background: #fffbeb; color: #d97706; }
.grade-d, .grade-e, .grade-u,
.grade-pill.grade-d, .grade-pill.grade-e, .grade-pill.grade-u { background: #fef2f2; color: #dc2626; }

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }

/* Auth */
.auth-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    padding: 1.5rem;
}

.login-card {
    background: white;
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

.login-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-brand .brand-icon {
    width: 48px; height: 48px;
    font-size: 0.85rem;
    margin: 0 auto 0.75rem;
    border-radius: 12px;
}

.login-card h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.2rem;
}

.login-card .subtitle {
    color: var(--muted);
    font-size: 0.85rem;
}

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
}

.auth-footer a { color: rgba(255, 255, 255, 0.75); font-weight: 500; }
.auth-footer a:hover { color: #fff; }

/* Footer */
.footer {
    text-align: center;
    padding: 0.6rem 1rem;
    color: var(--muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--card);
}

.footer a {
    color: var(--primary);
    font-weight: 600;
}

.footer a:hover { color: var(--primary-dark); }

/* Assignment cards */
.assignment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}

.assignment-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
}

.assignment-card:hover { box-shadow: var(--shadow); }
.assignment-card h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.15rem; }
.assignment-card p { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.65rem; }

.score-input { width: 64px; padding: 0.3rem; text-align: center; font-size: 0.8rem; }
.comment-input { width: 100%; min-width: 100px; font-size: 0.8rem; }

/* Report */
.report-card { padding: 1.25rem; }

.report-banner {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
}

.report-banner h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
    color: white;
}

.report-banner p { font-size: 0.8rem; opacity: 0.85; }

.report-meta {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.report-meta-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
}

.report-meta-item label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    display: block;
    margin-bottom: 0.15rem;
}

.report-meta-item strong { font-size: 0.9rem; font-weight: 600; color: var(--text); }

.report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.summary-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
}

.summary-box .value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.summary-box .label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--muted);
    margin-top: 0.15rem;
}

.report-section { margin-top: 1.25rem; }
.report-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--primary-light);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 0.5rem;
}

.chart-card {
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
}

.chart-card h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.chart-container {
    position: relative;
    height: 220px;
}

.chart-container.tall { height: 260px; }

.comments-list { display: flex; flex-direction: column; gap: 0.5rem; }

.comment-item {
    background: #f8fafc;
    border-left: 3px solid var(--primary);
    padding: 0.6rem 0.85rem;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.85rem;
}

.comment-item strong {
    color: var(--primary);
    font-size: 0.8rem;
    display: block;
    margin-bottom: 0.15rem;
}

.attendance-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.attendance-track {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    min-width: 60px;
}

.attendance-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), #34d399);
    border-radius: 999px;
}

.quick-list { padding-left: 1.1rem; color: var(--muted); font-size: 0.85rem; }
.quick-list li { margin-bottom: 0.35rem; }

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 90;
}

.sidebar-overlay.active { display: block; }

/* Print */
@media print {
    .sidebar, .top-header, .footer, .no-print, .sidebar-overlay { display: none !important; }
    .main-content, .app-container { padding: 0; margin: 0; }
    body { background: white; font-size: 12px; }
    .report-banner { background: #4f46e5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Responsive */
@media (max-width: 900px) {
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .menu-toggle { display: block; }

    .brand-text { display: none; }
    .brand-text-short { display: inline; }

    .sidebar {
        position: fixed;
        top: var(--header-h);
        left: 0;
        bottom: 0;
        z-index: 95;
        transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open { transform: translateX(0); }

    .user-name { display: none; }

    .main-content { padding: 0.85rem; }
    .form-row { grid-template-columns: 1fr; }
    .report-meta { grid-template-columns: 1fr; }
    .page-header h1 { font-size: 1.1rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .report-summary { grid-template-columns: repeat(2, 1fr); }
}
