:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
    --radius: 12px;
    --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
}

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

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    font-size: 26px;
    color: var(--primary);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 14px;
}

.logo-icon {
    text-align: center;
    font-size: 48px;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    transition: border-color .2s;
    background: var(--card);
    -webkit-appearance: none;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    word-break: break-word;
}

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

/* Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #fff;
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform .3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    margin-bottom: 12px;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-header .role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
    background: rgba(255,255,255,.15);
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 20px;
    color: rgba(255,255,255,.7);
    font-size: 14px;
    transition: all .2s;
    text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.sidebar-nav a .icon {
    font-size: 18px;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid rgba(255,255,255,.1);
    margin-top: auto;
    position: absolute;
    bottom: 0;
    width: 100%;
}

.sidebar-footer a {
    color: rgba(255,255,255,.7);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
}

.sidebar-footer a:hover { color: #fff; }

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 28px;
    min-height: 100vh;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.menu-toggle {
    display: none;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 200;
    box-shadow: var(--shadow);
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 8px;
    flex-wrap: wrap;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 12px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card .stat-icon {
    font-size: 28px;
    margin-bottom: 4px;
}

.stat-card .stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    word-break: break-all;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-card.positive .stat-value { color: var(--success); }
.stat-card.negative .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }

/* Table */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -20px;
    padding: 0 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 400px;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .5px;
}

tr:hover { background: #f8fafc; }

/* Points badge */
.points-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

.points-badge.positive {
    background: #dcfce7;
    color: #16a34a;
}

.points-badge.negative {
    background: #fef2f2;
    color: #dc2626;
}

.points-badge.neutral {
    background: #f1f5f9;
    color: #64748b;
}

/* Category badge */
.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    background: #f1f5f9;
    color: var(--text-muted);
}

/* Achievement list */
.achievement-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    transition: transform .2s;
}

.achievement-item:hover {
    transform: translateX(2px);
}

.achievement-icon {
    font-size: 22px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border-radius: 50%;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.achievement-info {
    flex: 1;
    min-width: 0;
}

.achievement-info .desc {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.achievement-info .meta {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.comment-text {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.achievement-points {
    flex-shrink: 0;
}

/* Forms */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 {
    margin-bottom: 20px;
    font-size: 18px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

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

.card, .stat-card, .achievement-item {
    animation: fadeIn .3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ===== MOBILE 768px ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .menu-toggle {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 64px;
    }

    .page-header {
        margin-bottom: 16px;
        flex-direction: column;
        align-items: stretch;
    }

    .page-header h1 {
        font-size: 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px 8px;
    }

    .stat-card .stat-icon {
        font-size: 24px;
    }

    .stat-card .stat-value {
        font-size: 18px;
    }

    .stat-card .stat-label {
        font-size: 11px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 14px;
        margin-bottom: 14px;
        border-radius: 10px;
    }

    .card-header {
        margin-bottom: 12px;
    }

    .card-header h2 {
        font-size: 15px;
    }

    .achievement-item {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }

    .achievement-icon {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .achievement-info {
        min-width: 0;
        flex: 1 1 0;
    }

    .achievement-info .desc {
        font-size: 13px;
    }

    .achievement-info .meta {
        white-space: normal;
        word-break: break-word;
        font-size: 11px;
    }

    .achievement-points {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-shrink: 0;
    }

    .modal {
        padding: 20px;
        margin: 8px;
        border-radius: 10px;
    }

    th, td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .table-wrapper {
        margin: 0 -14px;
        padding: 0 14px;
    }

    .btn-sm {
        padding: 5px 10px;
        font-size: 12px;
    }

    .alert {
        padding: 8px 12px;
        font-size: 12px;
        margin-bottom: 12px;
    }

    /* Admin users table -> card layout */
    .users-table { min-width: 0; width: 100%; }
    .users-table thead { display: none !important; }
    .users-table,
    .users-table tbody,
    .users-table tr,
    .users-table th,
    .users-table td {
        display: block;
        width: 100% !important;
        max-width: 100%;
        box-sizing: border-box;
    }
    .users-table tbody { padding: 0; }
    .users-table tbody tr {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border);
        background: var(--bg);
        border-radius: 8px;
        margin-bottom: 8px;
        overflow: hidden;
    }
    .users-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 8px;
        padding: 4px 0;
        border: none;
        white-space: normal;
        word-break: break-word;
        font-size: 13px;
        text-align: right;
    }
    .users-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 11px;
        text-transform: uppercase;
        flex-shrink: 0;
        text-align: left;
    }
    .users-table tbody td:last-child {
        justify-content: flex-end;
        gap: 6px;
        margin-top: 6px;
        padding-top: 8px;
        border-top: 1px solid var(--border);
    }
    .users-table tbody td:last-child::before {
        display: none;
    }

    .parents-list {
        justify-content: flex-end;
    }

    .table-wrapper {
        margin: 0;
        padding: 0;
        overflow: visible;
    }
}

/* ===== SMALL 480px ===== */
@media (max-width: 480px) {
    .main-content {
        padding: 12px;
        padding-top: 60px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .login-card {
        padding: 24px 18px;
        border-radius: 10px;
    }

    .login-card h1 {
        font-size: 22px;
    }

    .page-header h1 {
        font-size: 18px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .card-header .btn {
        width: 100%;
    }

    .achievement-item {
        padding: 10px 8px;
    }

    .achievement-info .desc {
        font-size: 12px;
    }

    .achievement-info .meta {
        font-size: 10px;
        white-space: normal;
        word-break: break-word;
    }

    .stat-card .btn {
        font-size: 12px;
        padding: 6px 10px;
    }

    .modal h2 {
        font-size: 16px;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn {
        width: 100%;
    }

    .table-wrapper {
        margin: 0;
        padding: 0;
        overflow: visible;
    }

    th, td {
        padding: 6px 8px;
        font-size: 11px;
    }
}
