@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600&family=Inter:wght@300;400;500;600&display=swap');

:root {
    --bg: #fdfdfd;
    --card-bg: #ffffff;
    --primary: #1e3a8a;
    --primary-soft: #eff6ff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #f3f4f6;
    --accent: #fbbf24;
    --radius: 16px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Sarabun', 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
    width: 100%;
}

/* Header */
header {
    padding: 2rem 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-content img {
    height: 48px;
    width: auto;
}

.header-content h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: -0.01em;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    align-items: center;
    padding-bottom: 4rem;
}

.split-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: start;
}

/* Login Section */
.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.login-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    background: #f9fafb;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.btn-login {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 1rem;
}

.btn-login:hover {
    background: #172554;
    transform: translateY(-1px);
}

/* Links Section */
.links-section h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.links-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.link-item {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
}

.link-item:hover {
    border-color: var(--primary);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

.link-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.link-item span {
    font-weight: 500;
    font-size: 0.95rem;
}

.link-item p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Footer */
footer {
    padding: 2rem 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
}

/* Responsive */
@media (max-width: 850px) {
    .split-layout {
        grid-template-columns: 1fr;
        gap: 3rem;
    }
    main {
        padding-top: 2rem;
    }
}

@media (max-width: 480px) {
    .links-grid {
        grid-template-columns: 1fr;
    }
}

/* Admin Dashboard Styles - Truly Premium Redesign */
.admin-container {
    display: flex;
    min-height: 100vh;
    background-color: #f8fafc; /* Subtle slate background */
}

.sidebar {
    width: 280px;
    background: #fff;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    border-right: 1px solid #f1f5f9;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Class สำหรับพับเมนู */
.sidebar.collapsed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 2rem;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-menu {
    list-style: none !important;
    padding: 1.5rem 1rem !important;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom Scrollbar for sidebar */
.sidebar-menu::-webkit-scrollbar {
    width: 5px;
}
.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}
.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

.sidebar-menu li {
    list-style: none !important;
    margin-bottom: 0.35rem;
}

.sidebar-menu li.menu-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 1.2rem;
    margin-bottom: 0.6rem;
    padding-left: 1rem;
}
.sidebar-menu li.menu-header:first-child {
    margin-top: 0;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    color: #475569;
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.2s ease;
    font-weight: 600;
}

.sidebar-menu a:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.sidebar-menu a.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid #f1f5f9;
    background: #f8fafc;
    margin-top: auto; /* ดันลงล่างสุด */
}

.footer-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
    margin-bottom: 0.5rem;
}

.footer-btn.home { color: #64748b; background: #fff; border: 1px solid #e2e8f0; }
.footer-btn.logout { color: #ef4444; background: #fee2e2; }

.footer-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }

/* Main content adjustment when sidebar is active */
.admin-main {
    transition: all 0.3s ease;
    margin-left: 280px;
    width: calc(100% - 280px);
    display: block !important;
    padding: 2.5rem 4rem;
    min-height: 100vh;
}

.admin-main.full-width {
    margin-left: 0;
    width: 100%;
}

.menu-toggle {
    display: flex;
    width: 40px;
    height: 40px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--primary);
    transition: all 0.2s;
}

.open-toggle {
    display: none; /* ซ่อนปุ่มเปิดในโหมด Desktop ปกติ */
}

.sidebar.collapsed ~ .admin-main .open-toggle {
    display: flex; /* แสดงปุ่มเปิดเมื่อ Sidebar พับเก็บ */
}

/* ปรับปรุงการแสดงผลบน Mobile */
@media (max-width: 1024px) {
    .menu-toggle.open-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 45px;
        height: 45px;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        color: var(--primary);
        font-size: 1.2rem;
        cursor: pointer;
        z-index: 1001; /* ให้สูงกว่า Sidebar เล็กน้อย */
    }
}

.menu-toggle:hover {
    background: var(--primary);
    color: #fff;
}

@media (max-width: 1024px) {
    .sidebar {
        left: -280px;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.active {
        left: 0;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    }
    
    .admin-main {
        margin-left: 0;
        width: 100%;
        padding: 1.5rem;
    }
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    background: #fff;
    padding: 1.5rem 2rem;
    border-radius: 20px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.content-card {
    background: #fff;
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    border: 1px solid #f1f5f9;
}

/* Dashboard Grid */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Force 3 columns on desktop */
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: #fff;
    padding: 1.75rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 1px solid #f1f5f9;
    transition: transform 0.2s;
}

.stat-card:hover { transform: translateY(-3px); }

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

/* Modern Data Table */
.table-responsive {
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 700;
}

td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

tr:last-child td { border-bottom: none; }

.badge {
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-admin { background: #fee2e2; color: #ef4444; }
.badge-teacher { background: #fef3c7; color: #d97706; }
.badge-student { background: #dcfce7; color: #16a34a; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: #fff;
    padding: 3rem;
    border-radius: 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Custom Alert Modal - Floating Center */
.custom-alert-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
}

.custom-alert-box {
    background: #fff;
    padding: 2.5rem;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.9);
    animation: alertPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes alertPop {
    to { transform: scale(1); opacity: 1; }
}

.alert-icon {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
}

.alert-icon.success { color: #10b981; }
.alert-icon.error { color: #ef4444; }
.alert-icon.warning { color: #f59e0b; }

.alert-message {
    font-size: 1.1rem;
    color: #1e293b;
    font-weight: 600;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.alert-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.85rem 2rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.alert-btn:hover {
    background: #1e3a8a;
    transform: translateY(-2px);
}

/* Global Page Loader & Transitions */
.page-loader {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 3px;
    background: linear-gradient(to right, #6366f1, #a855f7);
    z-index: 10001;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}

.page-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.page-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid #f1f5f9;
    border-top: 3px solid #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.close-toggle {
    display: none;
    font-size: 1.25rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 5px;
}

@media (max-width: 1024px) {
    .close-toggle {
        display: block;
    }
}
