
:root {
    --primary: #4a90e2; 
    --success: #1dd1a1; 
    --danger: #ff6b6b; 
    --warning: #feca57; 
    --text-color: #2f3542;
    --card-bg: #ffffff;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f7f6;
    color: var(--text-color);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
}

/* --- HEADER AND NAVIGATION --- */
header {
    background: var(--card-bg);
    padding: 15px 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--primary);
}
header h1 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--primary);
}
.nav-btn {
    text-decoration: none;
    padding: 8px 15px;
    background: #e9eef2;
    color: var(--text-color);
    border-radius: 6px;
    font-weight: bold;
    transition: background 0.2s;
}
.nav-btn:hover {
    background: #dcdfe3;
}

/* --- CLASS SELECTION AND CONTROLS --- */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
select, input[type="text"], input[type="number"], input[type="url"], input[type="color"] {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
    box-sizing: border-box; 
}
select:focus, input:focus {
    border-color: var(--primary);
}
.sort-controls button {
    margin-left: 8px;
}

/* --- STUDENT GRID --- */
#studentGrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); 
    gap: 20px; 
    padding-top: 10px;
    padding-bottom: 80px; 
}

.student-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 15px; 
    box-shadow: var(--shadow);
    text-align: center;
    position: relative;
    border: 4px solid transparent;
    transition: 0.3s;
    display: flex; 
    flex-direction: column;
    justify-content: space-between;
}

.avatar-wrapper {
    width: 80px; 
    height: 80px;
    border-radius: 50%;
    margin: 0 auto 8px; 
    overflow: hidden;
    border: 3px solid; 
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
    transition: transform 0.2s;
}
/* Hiệu ứng hover cho avatar để gợi ý click đổi quà */
.avatar-wrapper:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(74, 144, 226, 0.5);
}

.avatar-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.student-card h3 {
    font-size: 1.1rem;
}
.rank-badge {
    padding: 3px 10px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 8px;
}

/* Progress Bar */
.progress-container {
    background-color: #e9ecef;
    border-radius: 10px;
    margin: 8px 0;
    height: 8px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    transition: width 0.5s ease;
}

/* Action Controls */
.actions-group {
    width: 100%;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}
.point-input {
    width: 50px; 
    text-align: center; 
    padding: 6px;
    font-size: 0.9rem;
    margin-right: 5px;
    display: inline-block;
}
.reason-input { 
    width: 90%; 
    margin-top: 5px; 
    margin-bottom: 8px;
    font-size: 0.85rem; 
    padding: 6px 8px;
    box-sizing: border-box;
}
.actions { 
    display: grid;
    grid-template-columns: 1fr 1fr auto; 
    gap: 5px; 
    margin-top: 5px;
}
.actions button {
    padding: 8px 3px;
    font-size: 0.8rem;
    width: 100%;
}

/* --- GENERAL BUTTONS & FORMS --- */
button {
    cursor: pointer;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    font-weight: bold;
    transition: opacity 0.2s, transform 0.1s;
}
button:hover {
    opacity: 0.9;
}
button:active {
    transform: scale(0.98);
}
button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary { background-color: var(--primary); color: white; }
.btn-success { background-color: var(--success); color: white; }
.btn-danger { background-color: var(--danger); color: white; }
.btn-warning { background-color: var(--warning); color: var(--text-color); }
.btn-info { background-color: #3498db; color: white; }


/* --- MODALS (Chung) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(2px);
    padding-top: 60px;
}
.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    position: relative;
    animation: fadeIn 0.3s;
}
.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}
.close:hover, .close:focus {
    color: var(--danger);
    text-decoration: none;
    cursor: pointer;
}
@keyframes fadeIn {
    from {opacity: 0;}
    to {opacity: 1;}
}


/* --- LEVEL UP/DOWN MODAL --- */
.modal h2 { margin-top: 0; }
.level-up .modal-content { border: 5px solid var(--success); }
.level-down .modal-content { border: 5px solid var(--danger); }
#levelTitle {
    font-size: 1.8rem;
    text-align: center;
    color: var(--primary);
}
#levelDesc {
    text-align: center;
    margin: 15px 0;
    font-size: 1.1rem;
}
#levelImg {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: block;
    margin: 10px auto;
    border: 4px solid #fff;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    object-fit: cover;
}

/* --- REDEEM MODAL STYLES (NEW) --- */
.redeem-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
}

.redeem-item-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    transition: 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.redeem-item-card.selected {
    border-color: var(--primary);
    background-color: #f0f8ff;
    box-shadow: 0 4px 8px rgba(74, 144, 226, 0.3);
}

.redeem-img-wrapper {
    width: 80px;
    height: 80px;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9f9f9;
    border-radius: 8px;
    overflow: hidden;
}

.redeem-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.redeem-img-wrapper .no-img {
    font-size: 40px;
}

.redeem-info h4 {
    margin: 5px 0;
    font-size: 1rem;
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}

.redeem-cost {
    font-weight: bold;
    color: var(--danger);
    font-size: 0.9em;
    margin-bottom: 10px;
}

.redeem-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
}

.btn-minus, .btn-plus {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-minus { background: #eee; color: #333; }
.btn-plus { background: var(--success); color: white; }

.qty-display {
    font-weight: bold;
    min-width: 20px;
}


/* --- HISTORY MODAL (Phân trang & Lọc) --- */
#historyModal .modal-content {
    max-width: 650px;
    padding-bottom: 15px;
}
.filter-controls {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
    text-align: left;
}
.filter-controls label {
    font-weight: bold;
    margin-right: 10px;
}
.history-item {
    padding: 12px 5px;
    border-bottom: 1px solid #eef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}
.history-item:last-child {
    border-bottom: none;
}
.history-plus { color: var(--success); font-weight: bold; }
.history-minus { color: var(--danger); font-weight: bold; }
.history-time { color: #888; font-size: 0.85rem; }

/* Phân trang */
.pagination-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid #eee;
    margin-top: 15px;
}
#pageInfo {
    font-weight: bold;
    color: var(--primary);
}


/* --- ADMIN PAGE STYLES --- */
.admin-section {
    background: var(--card-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.admin-section h2 {
    color: var(--primary);
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    margin-top: 0;
}
.admin-section h3 {
    margin-top: 25px;
    font-size: 1.2rem;
    color: var(--text-color);
}

/* Input/Controls trong Admin */
.admin-section .input-group > input, 
.admin-section .input-group > select, 
.admin-section .input-group > button {
    margin-right: 10px;
    margin-bottom: 0; 
}

/* Danh sách Item */
.item-list {
    margin-top: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}
.item-list > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    background: #fff;
}
.item-list > div:last-child {
    border-bottom: none;
}
.item-list > div span {
    font-weight: 600;
}


/* --- CUSTOM NOTIFICATION SYSTEM --- */
#customNotification {
    position: fixed; 
    top: 20px;
    right: 20px; 
    z-index: 10000; 
    opacity: 0; 
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    max-width: 350px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    pointer-events: none; 
}

#customNotification.notification-show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; 
}

.notification-info { background-color: #3498db; color: white; }
.notification-success { background-color: #2ecc71; color: white; }
.notification-error { background-color: #e74c3c; color: white; }
.notification-warning { background-color: #f39c12; color: white; }


/* --- CUSTOM ADMIN MODAL --- */
#customAdminModal .modal-content {
    max-width: 400px;
    text-align: center;
}
#customModalMessage {
    text-align: left; 
    margin-bottom: 20px;
    color: var(--text-color); 
}
#customModalMessage p {
    margin: 10px 0 5px 0;
    font-weight: 500;
}

.modal-input {
    width: 100% !important;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box; 
    font-size: 1rem;
    display: block; 
    margin: 5px 0 15px 0;
}

#customModalInput {
    padding: 10px;
    font-size: 1rem;
    width: 90% !important;
    display: block;
    margin: 10px auto;
    box-sizing: border-box;
}

#customAdminModal .modal-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 25px;
}
#customAdminModal .modal-actions button {
    flex: 1;
    max-width: 120px;
}

/* --- MINI RANK BOARD STYLES --- */

.mini-rank-board-container {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 25px;
}

.mini-rank-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}

.mini-rank-card {
    display: flex;
    align-items: center;
    padding: 15px;
    border-radius: 8px;
    background-color: #f7f7f7;
    border-left: 5px solid; 
    position: relative;
    overflow: hidden;
}

.mini-rank-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.05;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-size="90" fill="%23000000">🏆</text></svg>');
    background-repeat: no-repeat;
    background-position: right -10px bottom -20px;
    background-size: 80px;
}

.rank-number {
    font-size: 2.5em;
    font-weight: bold;
    color: #999;
    margin-right: 15px;
    font-family: Arial Black, sans-serif;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
    z-index: 1;
}

.rank-1 .rank-number { color: #ffd700; } 
.rank-2 .rank-number { color: #c0c0c0; } 
.rank-3 .rank-number { color: #cd7f32; } 

.mini-rank-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 15px;
    border: 3px solid white;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    z-index: 1;
}

.rank-info {
    display: flex;
    flex-direction: column;
    text-align: left;
    z-index: 1;
}

.rank-name {
    font-weight: bold;
    font-size: 1.1em;
    color: var(--text-color);
}

.rank-points {
    color: #555;
    font-size: 0.9em;
}

.mini-rank-card .rank-badge {
    padding: 3px 8px;
    font-size: 0.8em;
    border-radius: 4px;
    display: inline-block;
    max-width: fit-content;
}

/* --- EFFECTS (Level Up) --- */
#levelModal .modal-content {
    background: #fff;
    border-radius: 25px;
    padding: 30px;
    text-align: center;
    position: relative;
    overflow: hidden; 
    animation: zoomIn 0.5s ease-out;
}

#levelModal .level-up #levelModalContent {
    border: 5px solid var(--primary-color);
    box-shadow: 0 0 40px rgba(46, 204, 113, 0.7); 
}

#levelModal .level-down #levelModalContent {
    border: 5px solid #ff6b6b;
    box-shadow: 0 0 40px rgba(231, 76, 60, 0.7); 
}

.particle {
    position: absolute;
    font-size: 20px;
    pointer-events: none;
    user-select: none;
    transform: translate(-50%, -50%); 
    z-index: 100;
}

@keyframes fireworks {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; top: 80%; }
    50% { transform: translate(-50%, -50%) scale(1.2) rotate(360deg); opacity: 0.8; }
    100% { transform: translate(-50%, -150%) scale(0.1); opacity: 0; top: 0%; }
}

@keyframes rain {
    0% { transform: translateY(0) rotate(0); opacity: 1; top: -10%; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@keyframes zoomIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* --- BULK ACTION STYLES --- */
.student-card .bulk-checkbox-container {
    position: absolute;
    top: 10px;
    right: 10px;
    display: none; 
    z-index: 10;
}

.student-card .bulk-checkbox {
    width: 25px;
    height: 25px;
    cursor: pointer;
    transform: scale(1.2);
}

.student-card.bulk-mode-item {
    cursor: pointer;
}

.student-card.selected-card {
    border-color: var(--primary) !important;
    background-color: #f0f8ff;
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

#bulkActionBar {
    position: fixed;
    bottom: -100px; 
    left: 0;
    width: 100%;
    background-color: var(--card-bg);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    padding: 15px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    transition: bottom 0.3s ease-in-out;
    z-index: 999;
    box-sizing: border-box;
    border-top: 3px solid var(--primary);
}

#bulkActionBar.show-bar {
    bottom: 0;
}

#bulkActionBar .selection-count {
    font-weight: bold;
    color: var(--primary);
    margin-right: 15px;
    min-width: 120px;
}

#bulkActionBar input {
    margin: 0;
}

/* --- RANDOM PICKER STYLES --- */
.student-card.random-highlight {
    border-color: #9b59b6 !important;
    background-color: #fff0ff !important;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(155, 89, 182, 0.6);
    z-index: 100;
}

.random-winner-item {
    width: 100px;
    text-align: center;
}
.random-winner-item img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #9b59b6;
    margin-bottom: 5px;
}
.random-winner-item div {
    font-weight: bold;
    font-size: 0.9em;
}

/* --- GROUP SORTER STYLES (NEW) --- */
.group-result-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    max-height: 500px;
    overflow-y: auto;
    text-align: left;
}

.group-box {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.group-header {
    background-color: var(--primary);
    color: white;
    padding: 10px;
    text-align: center;
    font-weight: bold;
}

.group-list {
    padding: 10px;
    list-style: none;
    margin: 0;
    flex-grow: 1;
}

.group-student-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #eee;
}
.group-student-item:last-child {
    border-bottom: none;
}
.group-student-item img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}

/* --- TIMER STYLES (NEW) --- */
.timer-input-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 1.5em;
}
.timer-input-group input {
    width: 80px;
    text-align: center;
    font-size: 1.2em;
}
.timer-display {
    font-size: 4em;
    font-weight: bold;
    color: #34495e;
    margin: 20px 0;
    font-family: 'Courier New', Courier, monospace;
    letter-spacing: 2px;
}
.timer-progress-bar {
    width: 100%;
    height: 10px;
    background-color: #ecf0f1;
    border-radius: 5px;
    margin-bottom: 25px;
    overflow: hidden;
}
#timerProgressFill {
    height: 100%;
    background-color: var(--success);
    transition: width 1s linear, background-color 0.3s;
}
.timer-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
}
.timer-controls button {
    font-size: 1.1em;
    padding: 10px 20px;
}

/* Hiệu ứng nhấp nháy khi sắp hết giờ */
.timer-critical {
    animation: criticalPulse 1s infinite;
    color: #e74c3c;
}
.timer-critical-bar {
    background-color: #e74c3c !important;
}

@keyframes criticalPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}


/* --- NOISE METER STYLES (NEW) --- */
.noise-emoji-display {
    font-size: 5em;
    margin: 10px 0;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.noise-emoji-bounce {
    animation: bounce 0.5s infinite alternate;
}
@keyframes bounce {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

.noise-meter-container {
    width: 100%;
    height: 40px;
    background: #ecf0f1;
    border-radius: 20px;
    position: relative;
    overflow: hidden;
    margin: 20px 0;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

.noise-meter-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #2ecc71, #f1c40f, #e74c3c);
    transition: width 0.1s linear;
    border-radius: 20px;
}

.noise-threshold-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #2c3e50;
    left: 50%;
    z-index: 10;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    cursor: ew-resize; /* In a real draggable UI */
}

.noise-controls-panel {
    text-align: left;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.noise-control-group {
    margin-bottom: 10px;
}

.noise-control-group label {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
}

.noise-control-group input[type=range] {
    width: 100%;
}

.noise-status-text {
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 10px;
    min-height: 30px;
}

.noise-warning-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(231, 76, 60, 0.9);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    border-radius: var(--border-radius);
    animation: flashRed 0.5s infinite;
}

@keyframes flashRed {
    0% { opacity: 0.9; }
    50% { opacity: 1; }
    100% { opacity: 0.9; }
}

.warning-content {
    text-align: center;
}
.warning-content h1 {
    font-size: 3em;
    margin: 0;
    text-transform: uppercase;
}
.warning-content p {
    font-size: 1.5em;
}


@media (max-width: 768px) {
    .container { padding: 10px; }
    .controls { flex-direction: column; align-items: stretch; }
    .sort-controls { margin-top: 10px; text-align: center; }
    .student-card { max-width: 100%; }
    .actions { grid-template-columns: 1fr 1fr; }
    .actions button:last-child { grid-column: span 2; }
    
    #bulkActionBar {
        flex-direction: column;
        gap: 10px;
        padding: 15px 10px;
    }
    #bulkActionBar .selection-count {
        margin-right: 0;
        text-align: center;
    }
    #bulkActionBar .action-inputs, #bulkActionBar .action-buttons {
        display: flex; width: 100%; gap: 5px;
    }
    #bulkActionBar input, #bulkActionBar button { flex: 1; }
    
    .redeem-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}
