/* ========================================
   Main CSS for Music Instrument System
   ======================================== */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Header */
.header {
    background: linear-gradient(135deg,  #205122 0%,  #4bcd50 100%);
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
}

.university-name {
    font-size: 1.5rem;
    font-weight: 700;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    font-weight: 600;
}

.user-role {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* Navigation */
.nav {
    background: #efefef00;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto;
}

.nav-container {
    max-width: 1600px;
    margin: 0 auto;
}

.nav-menu {
    list-style: none;
    display: flex;
    gap: 0.3rem;
    flex-wrap: nowrap;
    align-items: center;
}

.nav-item {
    flex: 0 0 auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;

    padding: 0.7rem 1rem;
    color: #333;
    text-decoration: none;
    transition: background 0.3s;

    white-space: nowrap;
    font-size: 14px;
}

.nav-link i {
    font-size: 14px;
}

.nav-link:hover {
    background: #f0f0f0;
}

.nav-link.active {
    background: #4CAF50;
    color: white;
}

.nav-link span{
    white-space: nowrap;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2E7D32;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #f9f9f9;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.875rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1.125rem; }

.btn-primary { background: #4CAF50; color: white; }
.btn-primary:hover { background: #45a049; }

.btn-success { background: #2E7D32; color: white; }
.btn-success:hover { background: #1b5e20; }

.btn-danger { background: #d32f2f; color: white; }
.btn-danger:hover { background: #c62828; }

.btn-warning { background: #f57c00; color: white; }
.btn-warning:hover { background: #ef6c00; }

.btn-info { background: #0288d1; color: white; }
.btn-info:hover { background: #0277bd; }

.btn-secondary { background: #757575; color: white; }
.btn-secondary:hover { background: #616161; }

.btn-group { display: inline-flex; gap: 0.25rem; }

/* Alerts */
.alert {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    border-left: 4px solid;
}

.alert-success { background: #e8f5e9; border-color: #4caf50; color: #2e7d32; }
.alert-danger { background: #ffebee; border-color: #f44336; color: #c62828; }
.alert-warning { background: #fff3e0; border-color: #ff9800; color: #e65100; }
.alert-info { background: #e3f2fd; border-color: #2196f3; color: #0d47a1; }

.alert-close {
    float: right;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.6;
}

.alert-close:hover { opacity: 1; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 4px;
}

.badge-success { background: #4caf50; color: white; }
.badge-danger { background: #f44336; color: white; }
.badge-warning { background: #ff9800; color: white; }
.badge-info { background: #2196f3; color: white; }
.badge-primary { background: #3f51b5; color: white; }
.badge-secondary { background: #9e9e9e; color: white; }
.badge-lg { padding: 0.5rem 1rem; font-size: 0.875rem; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
    color: #333;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: #4caf50;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.table thead th {
    background: #f5f5f5;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #e0e0e0;
}

.table tbody td {
    padding: 0.75rem;
    border-bottom: 1px solid #e0e0e0;
}

.table tbody tr:hover {
    background: #f9f9f9;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #4caf50;
}

.stat-label {
    color: #757575;
    margin-top: 0.5rem;
}

/* Breadcrumbs */
.breadcrumb {
    display: flex;
    list-style: none;
    padding: 0.75rem 1rem;
    background: #f5f5f5;
    border-radius: 4px;
}

.breadcrumb-item {
    display: inline-block;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    padding: 0 0.5rem;
    color: #757575;
}

.breadcrumb-item a {
    color: #4caf50;
    text-decoration: none;
}

.breadcrumb-item.active {
    color: #757575;
}

/* Footer */
.footer {
    background: #333;
    color: white;
    padding: 2rem;
    margin-top: 3rem;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
}

.footer-text {
    margin: 0.5rem 0;
}

.footer-links {
    margin-top: 1rem;
}

.footer-link {
    color: #4caf50;
    text-decoration: none;
    margin: 0 0.5rem;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

.pagination {
    display: flex;
    gap: 0.25rem;
}

.page-link {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    color: #333;
    text-decoration: none;
    border-radius: 4px;
}

.page-link:hover {
    background: #f0f0f0;
}

.page-link.active {
    background: #4caf50;
    color: white;
    border-color: #4caf50;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: #757575; }
.text-danger { color: #d32f2f; }
.text-success { color: #4caf50; }
.text-primary { color: #2E7D32; }

.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1.5rem; }

.row { display: flex; flex-wrap: wrap; margin: 0 -0.5rem; }
.col-md-4 { flex: 0 0 33.333%; max-width: 33.333%; padding: 0 0.5rem; }
.col-md-6 { flex: 0 0 50%; max-width: 50%; padding: 0 0.5rem; }
.col-md-8 { flex: 0 0 66.666%; max-width: 66.666%; padding: 0 0.5rem; }
.offset-md-2 { margin-left: 16.666%; }

/* Tooltips */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.35rem 0.6rem;
    background: #333;
    color: white;
    font-size: 0.75rem;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
    margin-bottom: 4px;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

.menu-toggle {
    display: none;
}

.system-name {
    font-size: 40px; /* ขนาดที่ต้องการในคอม */
    font-weight: bold;
    line-height: 1.2;
    white-space: nowrap;
}

/* เมื่อหน้าจอเล็กลงกว่า 768px (Tablet และ Mobile) */
@media (max-width: 768px) {
    .system-name {
        font-size: 15px; 
        white-space: normal;
        display: block;
        text-align: center;
        margin-top: 5px;
        word-wrap: break-word;
    }
    
    .header-content {
        flex-direction: column;
        padding: 1.5rem 1rem;
    }


    .logo {
        margin-bottom: 10px;
    }

    .user-details {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .user-actions {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
    }

    .nav {
        overflow-x: visible; /* เปลี่ยนจาก auto เป็น visible */
    }

    /* สั่งให้เมนูเรียงตัวแบบแนวตั้ง (Column) */
    .nav-menu {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        display: flex;
        flex-direction: column;
    }

    .nav-menu.show {
        max-height: 2000px;
    }

    .menu-toggle {
        display: block;
        width:100%; 
        margin: 10px auto;
        background: #2E7D32; /* สีพื้นหลังปุ่ม */
        color: #fff;         /* สีไอคอน/ตัวอักษร */
        border: none;
        padding: 12px;
        border-radius: 8px;
        font-size: 1rem;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        cursor: pointer;
    }

    .menu-toggle:hover {
        background: #1B5E20;
    }

    .nav-container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 15px;
    }

    /* ปรับตัวเมนูแต่ละอันให้เต็มความกว้าง */
    .nav-item {
        width: 100%;
        border-bottom: 1px solid #eee; /* เพิ่มเส้นคั่นระหว่างเมนูให้อ่านง่าย */
    }

    /* ปรับหน้าตาของ Link ให้กดง่ายขึ้นบนมือถือ */
    .nav-link {
        padding: 1rem 1.5rem; /* เพิ่มพื้นที่กด (Padding) ให้ใหญ่ขึ้น */
        width: 100%;
        box-sizing: border-box;
        justify-content: flex-start; /* ให้ข้อความชิดซ้าย */
    }

    /* บังคับให้ช่องสถิติเรียงลงมาเป็นแนวตั้งแถวละ 1 ช่อง */
    .stats-grid {
        grid-template-columns: 1fr !important; 
        gap: 1rem;
    }

    /* ปรับขนาดตัวเลขสถิติให้เล็กลงนิดหน่อย จะได้ไม่เบียดขอบการ์ด */
    .stat-number {
        font-size: 1.8rem;
    }

    .stat-card {
        padding: 1.5rem 10px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .stat-label {
        font-size: 0.9rem; /* ลดขนาดคำบรรยายลงนิดนึงเพื่อรับมือกับฟอนต์ Android ที่ตัวใหญ่ */
        line-height: 1.2;
    }

    .row {
        flex-direction: column;
        margin-left: 0;
        margin-right: 0;
    }

    .col-md-4, .col-md-6, .col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
        padding: 0; 
        margin-bottom: 1rem; /* เพิ่มช่องว่างระหว่างการ์ดที่เรียงต่อกัน */
    }

    /* ลด Padding ของคอนเทนเนอร์หลักลงเล็กน้อยเพื่อให้เหลือพื้นที่เนื้อหามากขึ้น */
    .container {
        margin: 1rem auto;
        padding: 0 0.8rem;
    }

    /* ลด Padding ภายในการ์ดแต่ละใบ */
    .card-body {
        padding: 1rem;
    }

    .col-md-8.offset-md-2 {
        margin-left: 0 !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* ปรับความสูงสไลด์ให้พอดี ไม่ให้โย่งเกินไปในมือถือ */
    .knowledge-slider {
        height: auto !important;
        min-height: 350px;
    }

    /* ปรับรูปภาพในสไลด์ให้เล็กลงหน่อย จะได้ไม่เบียดข้อความ */
    .slide-image-box img {
        max-width: 200px !important;
    }

    /* ลดช่องว่างสีขาวรอบๆ Card ในมือถือเพื่อให้มีพื้นที่แสดงผลมากขึ้น */
    .card-body {
        padding: 20px !important;
    }

    .table thead {
        display: none;
    }

    .table, .table tbody, .table tr, .table td {
        display: block !important;
        width: 100%;
    }

    .table tr {
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 10px;
        background: white;
    }

    .table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
    }

    .table td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: 45%;
        text-align: left;
        font-weight: bold;
    }

    .alert {
        font-size: 0.9rem;
    }
}