:root {
    --primary: #2563eb; 
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --bg-body: #f1f5f9;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    margin: 0; padding: 0; 
    color: var(--text-main);
    -webkit-tap-highlight-color: transparent;
}

/* HEADER */
header {
    background: var(--surface);
    padding: 12px 16px;
    position: sticky; top: 0; z-index: 50;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.header-content {
    max-width: 500px; margin: 0 auto;
    display: flex; justify-content: space-between; align-items: center;
}
header h3 { margin: 0; font-weight: 700; color: var(--primary); font-size: 1.15rem; }

/* Buttons Header */
.btn-login {
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    padding: 8px 16px; border-radius: 8px;
    font-weight: 600; font-size: 0.85rem; cursor: pointer;
    transition: all 0.2s;
}
.btn-login:active { transform: scale(0.96); }
.btn-login.logout-mode { background: var(--danger-bg); color: var(--danger); }

/* MAIN LAYOUT */
main { max-width: 500px; margin: 0 auto; padding: 24px 16px; }
.section-title { font-size: 0.85rem; text-transform: uppercase; color: var(--text-sub); margin-bottom: 16px; font-weight: 600; letter-spacing: 0.5px; }

/* SUBJECT GRID */
.subject-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.subject-card {
    background: var(--surface); padding: 24px 16px;
    border-radius: 20px;
    cursor: pointer; text-align: center;
    border: 1px solid transparent;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    transition: all 0.2s;
}
.subject-card:active { transform: scale(0.96); background: #f8fafc; }
.subject-icon-box {
    font-size: 36px; color: var(--primary);
    margin-bottom: 12px; display: block;
}
.sbj-name { font-weight: 600; font-size: 1rem; display: block; color: var(--text-main); }

/* DETAIL & LIST */
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.btn-back {
    display: flex; align-items: center; gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 16px; border-radius: 12px;
    font-weight: 600; font-size: 0.9rem;
    color: var(--text-sub); cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.btn-back i { font-size: 1.2rem; }
.btn-back:active { background: #f1f5f9; }

.subject-badge { 
    background: var(--primary); color: white; 
    padding: 6px 14px; border-radius: 20px; 
    font-weight: 600; font-size: 0.9rem; 
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

/* SEARCH BOX */
.search-container {
    background: var(--surface);
    border-radius: 14px;
    padding: 10px 16px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.search-container i { color: var(--text-sub); font-size: 1.1rem; }
.search-container input {
    border: none; outline: none; width: 100%;
    font-size: 1rem; font-family: 'Inter', sans-serif;
    color: var(--text-main);
}
.search-container input::placeholder { color: #94a3b8; }
.search-container:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }


.list-container { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.student-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.student-row:last-child { border-bottom: none; }
.student-row:active { background: #f8fafc; }
.s-name { font-weight: 500; font-size: 1rem; }
.s-score { font-weight: 700; font-size: 1.1rem; }
.pos { color: var(--success); } .neg { color: var(--danger); } .neu { color: #ccc; }

/* MODALS CHUNG */
.modal {
    display: none; position: fixed; z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(15, 23, 42, 0.85); 
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    display: flex; align-items: center; justify-content: center; /* Center modal vertically */
}
/* Ẩn modal lúc đầu */
#modal-login, #modal-add, #modal-history, #modal-logout-confirm, #modal-delete-confirm, #modal-options {
    display: none;
}
.modal[style*="display: block"] {
    display: flex !important;
}

.modal-content {
    background: var(--surface); 
    margin: 0 auto;
    border-radius: 24px; width: 85%; max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: popUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    overflow: hidden;
    position: relative;
    max-height: 90vh; /* Tránh tràn màn hình */
    display: flex; flex-direction: column;
}

@keyframes popUp { from {transform: scale(0.9); opacity: 0;} to {transform: scale(1); opacity: 1;} }

.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;}
.close-btn { 
    background: #f1f5f9; width: 32px; height: 32px; border-radius: 50%; 
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: var(--text-sub); cursor: pointer; 
}
.modal-body { padding: 24px 20px; overflow-y: auto;}

/* INPUT FORM HIỆN ĐẠI */
.form-group { margin-bottom: 20px; }
label { display: block; font-size: 0.9rem; font-weight: 600; color: var(--text-main); margin-bottom: 8px; }

.modern-input {
    width: 100%; padding: 14px; 
    border: 2px solid transparent;
    background: #f1f5f9; 
    border-radius: 12px; 
    font-size: 1rem; outline: none; 
    color: var(--text-main);
    box-sizing: border-box; 
    transition: all 0.2s;
    font-weight: 500;
}
.modern-input:focus { 
    background: #fff; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.modern-input::placeholder { color: #94a3b8; }

.error-text { 
    color: var(--danger); background: #fef2f2; 
    padding: 12px; border-radius: 12px; 
    text-align: center; display: none; margin-bottom: 16px; font-size: 0.9rem; font-weight: 500;
}

/* BUTTONS */
.action-buttons.horizontal { display: flex; gap: 12px; }

.btn-primary { 
    background: var(--primary); color: white; border: none; 
    padding: 14px; border-radius: 14px; font-weight: 600; font-size: 1rem; 
    cursor: pointer; width: 100%; box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
}
.btn-primary:active { background: var(--primary-dark); transform: translateY(1px); }

.btn-secondary { 
    background: #f1f5f9; color: var(--text-sub); border: none; 
    padding: 14px; border-radius: 14px; font-weight: 600; cursor: pointer; 
    flex: 1; font-size: 1rem;
}
.btn-secondary:active { background: #e2e8f0; }

.btn-danger { 
    background: var(--danger); color: white; border: none; 
    padding: 14px; border-radius: 14px; font-weight: 600; cursor: pointer; 
    flex: 1; font-size: 1rem;
    box-shadow: 0 4px 6px -1px rgba(220, 38, 38, 0.3);
}
.btn-danger-soft {
    background: #fef2f2; color: var(--danger); border: 1px solid transparent;
    padding: 14px; border-radius: 14px; font-weight: 600; cursor: pointer; 
    flex: 1; font-size: 1rem;
}
.btn-danger-soft:active { border-color: var(--danger); }

/* ICON WARNING MODAL */
.icon-warning-circle {
    width: 60px; height: 60px; background: #fef2f2; 
    border-radius: 50%; color: var(--danger); 
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px; font-size: 28px;
}

/* SHEET MENU */
.bottom-sheet-styled {
    position: absolute; bottom: 0; margin: 0; width: 100%; max-width: 100%;
    border-radius: 24px 24px 0 0; padding-bottom: 20px;
    animation: slideUp 0.3s ease-out;
}
@keyframes slideUp { from {transform: translateY(100%);} to {transform: translateY(0);} }

.sheet-header { padding: 20px; text-align: center; border-bottom: 1px solid var(--border); }
.sheet-subtitle { margin: 4px 0 0; color: var(--text-sub); font-size: 0.9rem; }
.sheet-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet-btn {
    width: 100%; padding: 16px; border: none; border-radius: 16px;
    font-size: 1rem; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.sheet-btn.primary { background: var(--primary); color: white; }
.sheet-btn.secondary { background: #f1f5f9; color: var(--text-main); }
.sheet-btn.cancel { background: white; color: var(--danger); border: 1px solid #e2e8f0; margin-top: 8px; }

/* TABLE HISTORY */
.table-wrapper { max-height: 50vh; overflow-y: auto; }
.styled-table { width: 100%; border-collapse: collapse; }
.styled-table th { text-align: left; padding: 12px; color: var(--text-sub); font-size: 0.8rem; font-weight: 600; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.styled-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 0.9rem; }
.user-tag { display: block; font-size: 0.75rem; color: var(--text-sub); margin-top: 4px; }
.btn-del-text { color: var(--danger); background: rgba(220, 38, 38, 0.1); padding: 4px 8px; border-radius: 6px; border: none; font-weight: 600; font-size: 0.75rem; cursor: pointer; margin-left: 8px;}

/* Deleted Row Styling */
.row-deleted { background-color: #fef2f2; }
.row-deleted .s-score-cell { text-decoration: line-through; color: #94a3b8 !important; }
.deleted-info { display: block; font-size: 0.75rem; color: var(--danger); font-style: italic; margin-top: 4px; }

/* TOAST */
#toast-container { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 3000; width: max-content; pointer-events: none; }
.toast {
    background: rgba(15, 23, 42, 0.95); color: white; padding: 12px 24px; border-radius: 50px;
    font-size: 0.9rem; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    animation: fadeIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    margin-bottom: 10px;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ========================================= */
/* GIAO DIỆN NHẬP ĐIỂM MỚI (MODERN)    */
/* ========================================= */

.modal-input-styled {
    border-radius: 32px;
    max-width: 380px;
    background: #ffffff;
    width: 90%;
}

.modal-header.no-border { padding-bottom: 0; border-bottom: none; }

.header-info { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.header-info .top-row { display: flex; justify-content: space-between; align-items: flex-start; width: 100%; }

/* Nút close nhỏ trong modal add */
.close-btn-mini {
    width: 28px; height: 28px; background: #f1f5f9; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-sub); cursor: pointer; font-size: 18px;
}

.badge-subject { 
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; 
    color: var(--text-sub); font-weight: 700; background: #f1f5f9; 
    padding: 4px 8px; border-radius: 6px;
}

/* XỬ LÝ TÊN HỌC SINH DÀI */
#add-student-name {
    font-size: 1.4rem; color: var(--text-main); margin: 4px 0 0 0;
    word-break: break-word; /* Tự xuống dòng nếu từ quá dài */
    overflow-wrap: break-word;
    line-height: 1.3;
    max-width: 100%;
}

.modal-body.tight-pad { padding: 16px 24px 24px; }

/* 1. Segmented Control (Nút chuyển Cộng/Trừ) */
.segmented-control {
    display: flex; background: #f1f5f9;
    padding: 4px; border-radius: 16px;
    margin-bottom: 24px; position: relative;
    border: 1px solid var(--border);
}
.seg-option {
    flex: 1; text-align: center; padding: 10px;
    font-weight: 600; font-size: 0.95rem;
    z-index: 2; cursor: pointer; color: var(--text-sub);
    display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: color 0.2s;
}
.seg-option.active { color: var(--text-main); }
.seg-option i { font-size: 1.1rem; }

/* Hiệu ứng trượt nền trắng */
.seg-bg {
    position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px);
    background: white; border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 1;
}
/* Logic đổi màu khi chọn */
.segmented-control.is-minus .seg-bg { transform: translateX(100%); background: #fef2f2; }
.segmented-control.is-minus .seg-option.active { color: var(--danger); }
.segmented-control.is-plus .seg-bg { background: #f0fdf4; }
.segmented-control.is-plus .seg-option.active { color: var(--success); }

/* 2. Hero Input (Ô nhập to) */
.hero-input-container {
    background: #ffffff; border: 2px solid #e2e8f0;
    border-radius: 24px; padding: 20px 10px;
    text-align: center; margin-bottom: 24px;
    transition: all 0.2s; position: relative;
}
.hero-input-container:focus-within { border-color: var(--success); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.1); }
.hero-input-container.minus-mode:focus-within { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.1); }

.hero-input {
    width: 100%; border: none; outline: none;
    font-size: 3.5rem; font-weight: 800;
    text-align: center; color: var(--text-main);
    background: transparent; margin: 0; padding: 0;
    font-family: 'Inter', sans-serif;
}
.hero-input::placeholder { color: #cbd5e1; }
.input-label { display: block; font-size: 0.85rem; color: var(--text-sub); font-weight: 600; margin-top: -5px; }

/* 4. Reason Box (Lý do) */
.reason-box {
    display: flex; align-items: center; gap: 12px;
    background: #f8fafc; padding: 0 16px;
    border-radius: 16px; margin-bottom: 24px;
    height: 52px; border: 1px solid transparent;
}
.reason-box:focus-within { background: white; border-color: var(--primary); }
.reason-box i { color: var(--text-sub); font-size: 1.2rem; }
.transparent-input {
    flex: 1; border: none; background: transparent;
    font-size: 0.95rem; outline: none; height: 100%; color: var(--text-main);
}

/* 5. Footer Button */
.vertical-actions .large-save {
    background: var(--text-main);
    box-shadow: 0 8px 20px -6px rgba(15, 23, 42, 0.3);
    font-size: 1.1rem; padding: 16px;
}
.vertical-actions .large-save:active { transform: scale(0.98); }
