:root {
    --primary-color: #87ad16;
    --primary-light: rgba(135, 173, 22, 0.1);
    --primary-linear: linear-gradient(135deg, #87ad16 0%, #a2cc1d 100%);
    --secondary-color: #6c757d;
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #343a40;
    --orange-color: #e5981d;
    --danger-color: #dc3545;
    --glass-effect: rgba(255, 255, 255, 0.8);
}

/* ========== Scrollbar Styling ========== */
/* For Chrome, Safari, and Edge */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #769713;
    /* Slightly darker than #87ad16 */
}

/* For Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f5f9;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--background-color);
    color: var(--text-color);
    font-family: "Prompt", sans-serif;
    font-weight: 400;
    overflow-x: hidden;
}

.superscript {
    font-size: 0.8em;
    /* กำหนดขนาดตัวอักษรให้เล็กลง */
    color: var(--orange-color);
    vertical-align: super;
    /* จัดตำแหน่งให้สูงขึ้น */
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.3s ease;
}

a:hover {
    color: var(--primary-color);
}

footer {
    background-color: var(--card-background);
    padding: 10px 0;
    text-align: center;
    font-size: 0.8rem;
    color: var(--secondary-color);
    border-top: 1px solid #dee2e6;
}

/* ========== Layout หลัก ========== */
.dashboard-container {
    display: flex;
    max-width: 100%;
    min-height: 100vh;
}

/* ========== Sidebar - เดสก์ท็อป ========== */
.sidebar {
    width: 250px;
    background-color: var(--card-background);
    padding: 20px 0;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    /* Use dynamic viewport height if supported */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    z-index: 100;
}

.logo {
    text-align: center;
    margin-bottom: 30px;
    padding: 0 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Sidebar Server Status */
.sidebar-server-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 2px 8px;
    background: rgba(135, 173, 22, 0.1);
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--primary-color);
}

.status-dot {
    width: 5px;
    height: 5px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
}

@keyframes pulse-dot {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    70% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

/* Sidebar User Card for Mobile */
.sidebar-user-card {
    display: none;
    padding: 15px;
    margin: 0 15px 20px;
    background: #f8fafc;
    border-radius: 12px;
    align-items: center;
    gap: 12px;
    border: 1px solid #e2e8f0;
}

@media (max-width: 768px) {
    .sidebar-user-card {
        display: flex;
    }
}

.sidebar-user-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    overflow: hidden;
    background: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-user-details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-user-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-color);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--secondary-color);
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: block;
    padding: 12px 20px;
    color: var(--text-color);
    text-decoration: none;
    transition: background-color 0.2s;
}

.sidebar-nav li a:hover,
.sidebar-nav li.active a {
    background-color: #e9ecef;
    color: var(--primary-color);
}

.sidebar-nav li a i {
    margin-right: 10px;
}

/* ========== Main Content ========== */
.main-content {
    flex-grow: 1;
    padding: 30px;
    width: 80%;
}

/* ========== Top Bar - เดสก์ท็อป ========== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #dee2e6;
}

/* ========== Header Actions & Dropdowns ========== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Notification */
.notification-wrapper {
    position: relative;
}

.notification-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    color: var(--secondary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.notification-icon:hover {
    background: #e2e8f0;
    color: var(--primary-color);
}

.notification-dot {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* Profile Trigger */
.user-profile-wrapper {
    position: relative;
}

.user-profile-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
}

.user-profile-trigger:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-linear);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.9em;
}

.user-detail-web {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-detail-web .u-name {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-color);
}

.user-detail-web .u-role {
    font-size: 0.7em;
    color: var(--secondary-color);
}

.arrow-icon {
    font-size: 0.7em;
    color: var(--secondary-color);
}

/* General Dropdown Style */
.header-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
    min-width: 220px;
    z-index: 1000;
    display: none;
    overflow: hidden;
    animation: slideDown 0.2s ease-out;
}

.header-dropdown.show {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-header {
    padding: 12px 15px;
    font-weight: 700;
    font-size: 0.9em;
    border-bottom: 1px solid #f1f5f9;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 15px;
    font-size: 0.9em;
    color: var(--text-color);
    transition: 0.2s;
}

.dropdown-item:hover {
    background: #f8fafc;
    color: var(--primary-color);
}

.dropdown-item i {
    width: 18px;
    color: var(--secondary-color);
}

.logout-item {
    color: #ef4444;
}

.logout-item:hover {
    background: #fef2f2;
    color: #dc2626;
}

.profile-info-card {
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.profile-info-card strong {
    font-size: 0.9em;
}

.profile-info-card span {
    font-size: 0.75em;
    color: var(--secondary-color);
}

/* Notification Menu specific */
.notification-menu {
    width: 280px;
}

.notification-item {
    padding: 12px 15px;
    display: flex;
    gap: 12px;
    border-bottom: 1px solid #f8fafc;
    cursor: pointer;
}

.notification-item:hover {
    background: #f8fafc;
}

.notification-item.unread {
    background: #f0f9ff;
    border-left: 3px solid #0284c7;
}

.notif-icon {
    width: 32px;
    height: 32px;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.notif-content .notif-text {
    font-size: 0.8em;
    margin: 0;
    line-height: 1.4;
}

.notif-content .notif-time {
    font-size: 0.7em;
    color: var(--secondary-color);
}

.dropdown-footer {
    padding: 10px;
    text-align: center;
    font-size: 0.8em;
    color: var(--primary-color);
    font-weight: 600;
    cursor: pointer;
    background: #f8fafc;
}

@media (max-width: 768px) {
    .user-detail-web {
        display: none;
    }

    .top-bar h2 {
        font-size: 1.1em;
    }
}

/* ========== Mobile Top Bar ========== */
.mobile-top-bar {
    display: none;
    background: var(--card-background);
    padding: 10px 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 900;
    align-items: center;
    justify-content: space-between;
}

.logo-mobile {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
}

.logo-mobile img {
    height: 40px;
    width: auto;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-color);
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    width: 44px;
    border-radius: 8px;
    transition: background 0.2s;
}

.menu-toggle:active {
    background: rgba(0, 0, 0, 0.05);
}

/* ========== Component อื่นๆ ========== */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 1200px) {
    .kpi-cards {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .kpi-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .kpi-cards {
        grid-template-columns: 1fr;
    }
}

.kpi-card {
    background-color: var(--card-background);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.kpi-card h3 {
    font-size: 1rem;
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.metric {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 5px;
}

.trend {
    font-size: 0.85rem;
    font-weight: 600;
}

.trend.up {
    color: var(--primary-color);
}

.trend.down {
    color: var(--orange-color);
}

.data-charts {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.chart-box {
    background-color: var(--card-background);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chart-box h3 {
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.placeholder {
    height: 250px;
    background-color: #e9ecef;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--secondary-color);
    border-radius: 4px;
}

.action-items {
    background-color: var(--card-background);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.order-list {
    margin-top: 15px;
}

.order-item {
    padding: 10px 0;
    border-bottom: 1px solid #f8f9fa;
    display: flex;
    justify-content: space-between;
}

.status {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.status.pending {
    background-color: #ffc107;
    color: #343a40;
}

.status.shipping {
    background-color: #17a2b8;
    color: white;
}


/* หน้าห้องเรียนและนักเรียน */

.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-family: "Prompt", sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn.btn-remove {
    background-color: var(--danger-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn.btn-back {
    background-color: var(--orange-color);
    cursor: pointer;
    transition: background-color 0.2s;
}


.btn:hover {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-family: "Prompt", sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn:active {
    transform: translateY(1px);
}

.search-box {
    margin-bottom: 20px;
}

.search-box input {
    padding: 8px;
    width: 300px;
    font-family: Prompt, sans-serif;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th,
td {
    padding: 12px;
    text-align: left;
    border: 1px solid #ddd;
}

th {
    background-color: #f4f4f4;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.action-btns a {
    margin-right: 8px;
    text-decoration: none;
    color: var(--primary-color);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: #fff;
    margin-top: 10px;
    margin-left: auto;
    margin-right: auto;
    width: 600px;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
}

.close {
    float: right;
    font-size: 24px;
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
    font-family: Prompt, sans-serif;
}

.pagination {
    margin-top: 20px;
    text-align: center;
    overflow-x: auto;
    /* ← สำคัญ! */
    padding-bottom: 10px;
    white-space: nowrap;
    /* ป้องกันขึ้นบรรทัดใหม่ */
}

.pagination a {
    display: inline-block;
    margin: 0 4px;
    padding: 8px 12px;
    text-decoration: none;
    border: 1px solid #ddd;
    color: var(--primary-color);
    min-width: 36px;
    /* ขนาดขั้นต่ำ */
    text-align: center;
}

.pagination a.active {
    background: var(--primary-color);
    color: white;
}

/* สิ้นสุดหนเาห้องเรียนและนักเรียน */



/* ========== Responsive Design ========== */

/* มือถือ: ≤768px */
@media (max-width: 1080px) {
    table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 20px;
        font-size: small;
    }

    .dashboard-container {
        display: block;
    }

    .top-bar {
        display: none !important;
        /* ซ่อน top bar เดสก์ท็อป */
    }

    .mobile-top-bar {
        display: flex;
        background: var(--card-background);
        padding: 10px 15px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        position: fixed;
        /* ← เปลี่ยนจาก sticky เป็น fixed */
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1001;
        align-items: center;
        justify-content: space-between;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 280px;
        /* Slightly wider for better touch area */
        transform: translateX(-100%);
        z-index: 1100;
        transition: transform 0.3s ease;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        background-color: var(--card-background);
        touch-action: pan-y;
        /* Allow vertical pan but block other actions if needed */
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-top: 60px;
        /* เพิ่ม margin-top เพื่อห่างจาก top bar */
        margin-left: 0;
        padding: 20px;
        width: 100%;
        position: relative;
        z-index: 1;
    }

    .data-charts,
    .kpi-cards {
        grid-template-columns: 1fr;
    }

    .logo-mobile span {
        font-size: 14px;
    }

    .logo-mobile img {
        height: 32px;
    }
}

/* ========== Schedule Module Styles ========== */
.tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    background: #e9ecef;
    padding: 5px;
    border-radius: 10px;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

.tab-link {
    padding: 10px 20px;
    border-radius: 8px;
    color: var(--secondary-color);
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}

.tab-link:hover {
    background: rgba(255, 255, 255, 0.5);
    color: var(--primary-color);
}

.tab-link.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.card {
    background-color: var(--card-background);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin-bottom: 25px;
}

.card h3 {
    margin-bottom: 20px;
    color: var(--text-color);
    border-left: 4px solid var(--primary-color);
    padding-left: 15px;
    font-size: 1.2rem;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active-content {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.action-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    margin-right: 5px;
    transition: all 0.2s;
}

.btn-edit {
    background: #e3f2fd;
    color: #1976d2;
}

.btn-edit:hover {
    background: #1976d2;
    color: white;
}

.btn-delete {
    background: #fee2e2;
    color: #dc2626;
}

.btn-delete:hover {
    background: #dc2626;
    color: white;
}

.timetable-grid {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

/* ========== PWA Install Banner ========== */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 9999;
    animation: pwaSlideUp 0.3s ease-out;
    border: 1px solid var(--primary-light);
}

@keyframes pwaSlideUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pwa-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.pwa-text h4 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-color);
}

.pwa-text p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.pwa-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-install {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Prompt', sans-serif;
}

.btn-close-pwa {
    background: none;
    border: none;
    color: var(--secondary-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
}

@media (max-width: 768px) {
    .pwa-install-banner {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 12px;
    }
}