@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;600;800&display=swap');

:root {
    --font-main: 'Sarabun', sans-serif;
    --glass-bg: rgba(255, 255, 255, 0.95); 
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --text-dark: #2d3436;
    --text-muted: #636e72;
    --accent-blue: #0984e3;
    --accent-red: #d63031;
    --accent-green: #00b894;
    --header-height: 100px; 
    --footer-height: 50px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font-main);
    background: var(--primary-gradient);
    background-attachment: fixed;
    height: 100vh; overflow: hidden;
    color: var(--text-dark);
}

/* Force Font */
input, button, select, textarea, option, table, h1, h2, h3, h4, h5, p, span, div, a, label {
    font-family: var(--font-main) !important;
}

/* === LAYOUT === */
.bg-shape { position: fixed; border-radius: 50%; filter: blur(80px); z-index: -1; opacity: 0.6; }
.shape-1 { width: 400px; height: 400px; background: #a29bfe; top: -100px; left: -100px; }
.shape-2 { width: 300px; height: 300px; background: #74b9ff; bottom: -50px; right: -50px; }

.glass-header, .glass-card, .glass-footer {
    background: var(--glass-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
}

/* === HEADER === */
.fixed-top {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    width: 95%; max-width: 1200px; z-index: 1000; border-radius: 20px; height: var(--header-height);
    display: flex; align-items: center; padding: 0 30px;
}
.header-content { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.logo-area { display: flex; align-items: center; gap: 15px; }

.logo-icon { 
    font-size: 2.2rem; color: #6c5ce7; background: white; width: 55px; height: 55px; 
    display: flex; align-items: center; justify-content: center; border-radius: 50%; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); overflow: hidden; flex-shrink: 0;
}
.logo-icon img { width: 100%; height: 100%; object-fit: contain; }

.logo-text h1 { font-size: 1.4rem; font-weight: 800; margin: 0; line-height: 1.2; }
.logo-text p { font-size: 0.85rem; color: var(--text-muted); margin: 0; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.date-display { font-weight: 600; color: #6c5ce7; background: rgba(255,255,255,0.6); padding: 8px 15px; border-radius: 20px; font-size: 0.9rem; }

.btn-logout {
    background: rgba(255, 255, 255, 0.4); border: 1px solid white; color: var(--text-dark);
    padding: 8px 15px; border-radius: 15px; cursor: pointer; font-size: 0.9rem; font-weight: 600;
    transition: 0.3s; display: flex; align-items: center; gap: 5px;
}
.btn-logout:hover { background: var(--accent-red); color: white; border-color: var(--accent-red); }

/* ปุ่ม Setting */
.btn-setting {
    background: rgba(255, 255, 255, 0.4); border: 1px solid white; color: var(--text-dark);
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: 0.3s;
    display: none; align-items: center; justify-content: center; font-size: 1.2rem;
}
.btn-setting:hover { background: white; transform: rotate(90deg); color: var(--accent-blue); }

/* ปุ่ม Report (Header) */
.btn-report-header {
    background: rgba(255, 255, 255, 0.4); border: 1px solid white; color: var(--text-dark);
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer; transition: 0.3s;
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.btn-report-header:hover { background: white; color: var(--accent-green); box-shadow: 0 2px 10px rgba(0,0,0,0.1); }

/* === CONTENT === */
.fixed-bottom {
    position: fixed; bottom: 0; left: 0; width: 100%; height: var(--footer-height); z-index: 1000;
    display: flex; align-items: center; justify-content: center; border-radius: 20px 20px 0 0;
    font-size: 0.85rem; color: var(--text-muted);
}
.scrollable-content {
    height: 100vh; overflow-y: auto; padding-top: calc(var(--header-height) + 40px); padding-bottom: calc(var(--footer-height) + 20px);
    scrollbar-width: thin;
}
.main-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Stats */
.stats-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { padding: 20px; display: flex; align-items: center; gap: 20px; border-radius: 16px; transition: transform 0.3s ease; }
.stat-card:hover { transform: translateY(-3px); }
.icon-box { width: 60px; height: 60px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: white; flex-shrink: 0; }
.color-blue { background: linear-gradient(135deg, #74b9ff, #0984e3); }
.color-red { background: linear-gradient(135deg, #ff7675, #d63031); }
.color-green { background: linear-gradient(135deg, #55efc4, #00b894); }
.stat-info h2 { font-size: 2.2rem; font-weight: 800; line-height: 1.1; margin: 5px 0; }
.text-danger { color: var(--accent-red); }

/* Grid */
.content-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; color: white; }
.student-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

.student-card {
    background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.6); box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: all 0.3s ease; animation: fadeIn 0.5s ease forwards; position: relative; overflow: hidden;
    display: flex; flex-direction: column; gap: 10px;
}
.student-card:hover { transform: translateY(-5px) scale(1.02); z-index: 10; }
.student-card::before { content: ''; position: absolute; top: 0; left: 0; width: 5px; height: 100%; background: var(--accent-blue); }
.student-card.overdue::before { background: var(--accent-red); }
.card-header { display: flex; justify-content: space-between; align-items: center; }
.st-name { font-size: 1.1rem; font-weight: 700; }
.st-class { background: #dfe6e9; color: #636e72; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; font-weight: 600; }
.card-body { display: flex; flex-direction: column; gap: 8px; }

.time-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 0px;
    width: 100%;
}
.time-row span {
    display: flex; align-items: center; gap: 5px;
}

.reason-box { 
    margin-top: 5px;
    padding: 6px 15px; 
    background-color: rgba(108, 92, 231, 0.08);
    color: #6c5ce7;
    border-radius: 20px; 
    font-size: 0.85rem; 
    font-weight: 600;
    text-align: center; 
    width: 100%;
}
.time-badge { font-weight: bold; color: var(--accent-blue); }

/* === BUTTONS & INPUTS === */
.fab-btn {
    position: fixed; right: 30px; width: 65px; height: 65px; 
    border-radius: 50%; border: none; color: white; font-size: 1.8rem; 
    cursor: pointer; z-index: 2000; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.fab-btn:hover { transform: scale(1.1) rotate(5deg); }
.tooltip {
    position: absolute; right: 80px; background: rgba(0,0,0,0.8); color: white;
    padding: 6px 12px; border-radius: 8px; font-size: 0.9rem;
    opacity: 0; pointer-events: none; transition: 0.2s; white-space: nowrap; transform: translateX(10px);
}
.fab-btn:hover .tooltip { opacity: 1; transform: translateX(0); }

.fab-create { bottom: 90px; background: linear-gradient(135deg, #00b894, #00cec9); }
.fab-return { bottom: 170px; background: linear-gradient(135deg, #d63031, #ff7675); }

/* Form Elements */
.relative { position: relative; } 
.form-group { margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-weight: bold; margin-bottom: 8px; color: #333; }
.form-group input, .form-group select { 
    width: 100%; padding: 12px; border: 2px solid #e0e0e0; border-radius: 10px; font-size: 1rem; transition: 0.3s; 
    font-family: var(--font-main) !important;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent-blue); outline: none; }

.btn-primary-full { width: 100%; background: var(--accent-blue); color: white; padding: 12px; border: none; border-radius: 10px; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: 0.3s; }
.btn-primary-full:hover { background: #0069d9; }
.btn-text-only { background: none; border: none; color: #888; text-decoration: underline; margin-top: 15px; cursor: pointer; }
.btn-icon-small { background: none; border: none; color: #ff4d4f; cursor: pointer; font-size: 1rem; }

/* === MODALS === */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(5px);
    z-index: 3000;
    display: none; align-items: center; justify-content: center;
}
.modal-box {
    width: 90%; max-width: 500px; padding: 30px; border-radius: 20px;
    background: white; animation: slideUp 0.3s ease; position: relative;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.btn-close-absolute { position: absolute; top: 20px; right: 20px; background: none; border: none; font-size: 1.5rem; color: #888; cursor: pointer; z-index: 10; }

/* Settings Tabs */
.tabs-header { display: flex; border-bottom: 2px solid #eee; margin-bottom: 20px; }
.tab-btn {
    padding: 10px 20px; cursor: pointer; border: none; background: none;
    font-weight: bold; color: #888; border-bottom: 3px solid transparent; transition: 0.3s;
}
.tab-btn.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }
.tab-content { display: none; animation: fadeIn 0.3s; }
.tab-content.active { display: block; }

/* Tables */
.user-table-container {
    max-height: 300px; overflow-y: auto; margin-top: 15px;
    border: 1px solid #eee; border-radius: 10px; background: white;
}
.user-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.user-table th, .user-table td { padding: 12px; text-align: left; border-bottom: 1px solid #eee; color: var(--text-dark); }
.user-table th { background: #f8f9fa; position: sticky; top: 0; z-index: 1; color: #555; }
.user-table tr:hover { background: #f1f2f6; }

.action-btn { border: none; background: none; cursor: pointer; margin: 0 5px; font-size: 1rem; transition: 0.2s; }
.btn-edit { color: var(--accent-blue); } .btn-delete { color: var(--accent-red); }
.btn-edit:hover, .btn-delete:hover { transform: scale(1.2); }
.btn-delete:disabled { color: #ccc; cursor: not-allowed; transform: none; }

/* Switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 34px;
}
.slider:before {
    position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
    background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent-green); }
input:checked + .slider:before { transform: translateX(18px); }
input:disabled + .slider { background-color: #eee; cursor: not-allowed; opacity: 0.6; }

/* Add User Form */
.add-user-form { background: #f8f9fa; padding: 20px; border-radius: 12px; margin-bottom: 20px; border: 1px solid #eee; }
.add-user-form h4 { margin-bottom: 15px; color: #333; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

/* Admin Tools */
.tools-bar { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; background: #f1f2f6; padding: 10px; border-radius: 10px; }
.filter-group { display: flex; align-items: center; gap: 10px; }
.btn-warning { background: #e67e22; color: white; border: none; padding: 8px 15px; border-radius: 8px; cursor: pointer; }
.btn-danger { background: var(--accent-red); color: white; border: none; padding: 8px 15px; border-radius: 8px; cursor: pointer; }
.badge-count { background: var(--accent-blue); color: white; padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; margin-left: 5px; }
.csv-upload-box { border: 2px dashed #ccc; padding: 20px; text-align: center; border-radius: 10px; background: #fff; cursor: pointer; transition: 0.3s; }
.csv-upload-box:hover { border-color: var(--accent-blue); background: #f0f8ff; }

/* Logo Preview */
.logo-preview-box {
    width: 100px; height: 100px; border: 2px dashed #ccc; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    margin-bottom: 10px; background: #f9f9f9; position: relative;
}
.logo-preview-box img { width: 100%; height: 100%; object-fit: contain; }

/* Search Dropdown */
.search-dropdown { position: absolute; top: 100%; left: 0; width: 100%; max-height: 200px; overflow-y: auto; background: white; border: 1px solid #ddd; border-radius: 0 0 10px 10px; z-index: 10; display: none; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.search-item { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; }
.search-item:hover { background-color: #f9f9f9; }
.selected-card { display: flex; justify-content: space-between; align-items: center; background: #e6f7ff; border: 1px solid #91d5ff; padding: 10px 15px; border-radius: 10px; }
.badge-id { background: var(--accent-blue); color: white; padding: 2px 6px; border-radius: 4px; font-size: 0.8rem; }

/* Sub Modals */
.sub-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 4000; display: none; align-items: center; justify-content: center; }
.sub-modal-box { background: white; padding: 25px; border-radius: 15px; width: 350px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); text-align: left; }
.confirm-box { text-align: center; }
.confirm-box h3 { margin-bottom: 10px; color: var(--text-dark); }
.confirm-box p { margin-bottom: 25px; color: var(--text-muted); }
.btn-group { display: flex; gap: 15px; justify-content: center; margin-top: 20px; }
.btn-confirm-yes { background: var(--accent-red); color: white; border: none; padding: 10px 25px; border-radius: 10px; cursor: pointer; font-weight: bold; }
.btn-confirm-no { background: #dfe6e9; color: #636e72; border: none; padding: 10px 25px; border-radius: 10px; cursor: pointer; font-weight: bold; }

/* Import Result */
.import-result-list { max-height: 200px; overflow-y: auto; text-align: left; margin-top: 15px; border: 1px solid #eee; padding: 10px; border-radius: 8px; }
.result-item { font-size: 0.85rem; padding: 5px 0; border-bottom: 1px solid #f9f9f9; display: flex; justify-content: space-between; }
.res-success { color: var(--accent-green); } .res-skip { color: #e67e22; } .res-fail { color: var(--accent-red); }
.progress-bar-container { width: 100%; background: #eee; height: 10px; border-radius: 5px; margin: 15px 0; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent-blue); width: 0%; transition: width 0.3s; }

/* === 7. ANIMATIONS === */
.nfc-animation { position: relative; width: 100px; height: 100px; margin: 20px auto; display: flex; align-items: center; justify-content: center; }
.nfc-icon { font-size: 4rem; z-index: 2; }
.circle-pulse { position: absolute; width: 100%; height: 100%; border-radius: 50%; animation: pulse-ring 1.5s infinite; opacity: 0; }
.icon-green { color: var(--accent-green); } .pulse-green { border: 3px solid var(--accent-green); } .ready-green { color: var(--accent-green); font-size: 2rem; font-weight: 800; margin: 10px 0; }
.icon-red { color: var(--accent-red); } .pulse-red { border: 3px solid var(--accent-red); } .ready-red { color: var(--accent-red); font-size: 2rem; font-weight: 800; margin: 10px 0; }
@keyframes pulse-ring { 0% { transform: scale(0.8); opacity: 0.5; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes slideUp { from { transform: translateY(50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.toast-container { position: fixed; top: 130px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: white; padding: 15px 20px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); display: flex; align-items: center; gap: 15px; animation: slideIn 0.3s ease forwards; border-left: 5px solid #ccc; min-width: 280px; }
.toast.success { border-left-color: var(--accent-green); }
.toast.error { border-left-color: var(--accent-red); }

/* === 8. LOGIN PAGE === */
.login-wrapper { height: 100vh; display: flex; justify-content: center; align-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; padding: 40px 30px; border-radius: 20px; text-align: center; }
.login-header { margin-bottom: 30px; }
.login-card .logo-icon { margin: 0 auto 15px auto; }
.input-icon-wrapper { position: relative; }
.input-icon-wrapper i { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #888; }
.input-icon-wrapper input { padding-left: 45px; }
.mt-20 { margin-top: 20px; }
.login-error { margin-top: 15px; color: var(--accent-red); font-size: 0.9rem; background: rgba(214, 48, 49, 0.1); padding: 10px; border-radius: 8px; border: 1px solid var(--accent-red); animation: fadeIn 0.3s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25%, 75% { transform: translateX(-5px); } 50% { transform: translateX(5px); } }
.shake { animation: shake 0.4s ease-in-out; }

@media (max-width: 768px) {
    .student-grid { grid-template-columns: 1fr; }
    .fixed-top { width: 100%; top: 0; border-radius: 0 0 20px 20px; }
    .header-content { flex-direction: column; gap: 10px; }
    .date-display { display: none; }
    .logout-text { display: none; }
    .grid-2 { grid-template-columns: 1fr; }
}