/* assets/css/style.css */

/* --- Import Font --- */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;700&display=swap');

/* --- Theme Colors (ตามคำขอ) --- */
:root {
    --color-primary: #26A69A;  /* Main Theme */
    --color-success: #AED581;
    --color-warning: #FFCA28;
    --color-info: #FF8A65;
    --color-danger: #EF5350;
    
    --color-text: #333;
    --color-bg: #f4f7f6;
    --color-white: #ffffff;
    --color-border: #e0e0e0;
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --sidebar-hover: #34495e;
}

/* --- Base & Font --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Kanit', sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

/* --- Loading Spinner (ตามคำขอ) --- */
#loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    z-index: 9999;
    display: none; /* ซ่อนไว้ก่อน */
    justify-content: center;
    align-items: center;
}
#loading-spinner.show {
    display: flex;
}
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Layout --- */
.app-layout {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* --- Sidebar (เมนูซ้าย Responsive) --- */
#sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    transition: all 0.3s;
    position: fixed;
    height: 100%;
    z-index: 100;
    left: -250px; /* ซ่อนเมนูเริ่มต้น */
}
#sidebar.active {
    left: 0;
}
#sidebar .sidebar-header {
    padding: 20px;
    background: #1f2c39;
    text-align: center;
}
#sidebar ul.components {
    padding: 20px 0;
    border-bottom: 1px solid #47748b;
}
#sidebar ul p {
    padding: 10px;
    font-size: 1.1em;
    display: block;
}
#sidebar ul li a {
    padding: 10px 20px;
    font-size: 1.1em;
    display: block;
    color: inherit;
    text-decoration: none;
    transition: all 0.3s;
}
#sidebar ul li a:hover {
    background: var(--sidebar-hover);
    color: var(--color-primary);
}
#sidebar ul li.active > a {
    background: var(--color-primary);
    color: var(--color-white);
}

/* --- Submenu Styles --- */
#sidebar ul li.has-submenu {
    position: relative;
}
#sidebar ul li.has-submenu > a::after {
    content: '\f078'; /* FontAwesome chevron-down */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    float: right;
    transition: transform 0.3s;
}
#sidebar ul li.has-submenu.open > a::after {
    transform: rotate(180deg);
}
#sidebar ul.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: rgba(0, 0, 0, 0.2);
    padding: 0;
}
#sidebar ul li.has-submenu.open > ul.submenu {
    max-height: 500px;
    padding: 5px 0;
}
#sidebar ul.submenu li a {
    padding: 8px 20px 8px 40px;
    font-size: 0.95em;
}
#sidebar ul.submenu li a:hover {
    background: rgba(38, 166, 154, 0.2);
    color: var(--color-primary);
}

/* --- Content Wrapper --- */
#content-wrapper {
    width: 100%;
    transition: all 0.3s;
    padding-left: 0; /* เริ่มต้นเต็มจอ */
}
#sidebar.active + #content-wrapper {
    padding-left: 250px; /* เว้นที่ให้ sidebar */
}

/* --- Header --- */
.app-header {
    padding: 15px 20px;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
#sidebar-toggle {
    margin-right: 15px;
}

/* --- Main Content --- */
#main-content {
    padding: 20px;
    min-height: calc(100vh - 121px); /* (Header + Footer height) */
}

/* --- Footer --- */
.app-footer {
    padding: 20px;
    background: var(--color-white);
    border-top: 1px solid var(--color-border);
    text-align: center;
    font-size: 0.9em;
}

/* --- Modals (ตามคำขอ) --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    max-width: 450px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    position: relative;
    animation: fadeIn 0.3s;
}
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
.close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.modal-content h3 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--color-primary);
}
.modal-content form input[type="text"],
.modal-content form input[type="password"],
.modal-content form select,
.modal-content form textarea {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid var(--color-border);
    border-radius: 5px;
    font-family: 'Kanit', sans-serif;
    font-size: 1em;
    background-color: white;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.modal-content form input[type="text"]:focus,
.modal-content form input[type="password"]:focus,
.modal-content form select:focus,
.modal-content form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(38, 166, 154, 0.1);
}

.modal-content form select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 35px;
}

.modal-content form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.modal-content form select:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.7;
}

.modal-content form input[type="radio"] {
    width: auto;
    margin-right: 5px;
    cursor: pointer;
}

.modal-content form input[type="text"]:disabled,
.modal-content form input[type="password"]:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

/* --- Search and Filter Styles --- */
.page-header input[type="text"],
.page-header select {
    padding: 10px 15px;
    border: 1px solid var(--color-border);
    border-radius: 5px;
    font-family: 'Kanit', sans-serif;
    font-size: 1em;
    background-color: white;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.page-header input[type="text"]:focus,
.page-header select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(38, 166, 154, 0.1);
}

.page-header select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 35px;
    min-width: 80px;
}

.page-header input[type="text"]::placeholder {
    color: #999;
    font-style: italic;
}

.page-header {
    margin-bottom: 20px;
}

.page-header h2 {
    margin-bottom: 15px;
    color: var(--color-text);
}

/* Search bar container */
.page-header > div[style*="display:flex"] {
    background: white;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* --- Utility Classes (Buttons, Badges, Tables) --- */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Kanit', sans-serif;
    font-size: 1em;
    transition: all 0.2s;
}
.btn:hover {
    opacity: 0.9;
}
.btn.btn-primary { background-color: var(--color-primary); color: white; }
.btn.btn-success { background-color: #4CAF50; color: white; }
.btn.btn-danger { background-color: var(--color-danger); color: white; }
.btn.btn-warning { background-color: var(--color-warning); color: #333; }
.btn.btn-secondary { background-color: #6c757d; color: white; }
.btn.btn-info { background-color: #17a2b8; color: white; }
.btn.btn-light { background-color: #f8f9fa; color: #333; border: 1px solid var(--color-border); }
.btn.btn-icon { background: none; border: none; font-size: 1.2em; }

.btn.btn-sm {
    padding: 6px 12px;
    font-size: 0.9em;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 500;
    color: white;
}
.badge-primary { background-color: var(--color-primary); }
.badge-success { background-color: #4CAF50; }
.badge-warning { background-color: var(--color-warning); color: #333; }
.badge-info { background-color: #17a2b8; }
.badge-secondary { background-color: #6c757d; }

.table-overflow {
    overflow-x: auto;
}
table.modern-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: var(--color-white);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
table.modern-table th,
table.modern-table td {
    padding: 12px 15px;
    border: 1px solid var(--color-border);
    text-align: left;
}
table.modern-table th {
    background-color: #f8f9fa;
    font-weight: 500;
}

/* --- Responsive (ตามคำขอ) --- */
@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        left: -100%; /* ซ่อนไปทางซ้ายสุด */
        z-index: 1000;
    }
    #sidebar.active {
        left: 0;
    }
    #sidebar.active + #content-wrapper {
        padding-left: 0; /* เนื้อหาเต็มจอเสมอ */
    }
    #content-wrapper {
        padding-left: 0;
    }
    /* เมื่อเมนูเปิด ให้มีปุ่มปิดทับเนื้อหา */
    #sidebar.active ~ #content-wrapper {
        position: relative;
    }
}

/* --- Dashboard Gradient (ตามคำขอ) --- */
.dashboard-card {
    padding: 20px;
    border-radius: 8px;
    color: white;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.dashboard-card.gradient-1 {
    background-image: linear-gradient(135deg, #26A69A 0%, #AED581 100%);
}
.dashboard-card.gradient-2 {
    background-image: linear-gradient(135deg, #FFCA28 0%, #FF8A65 100%);
}
.dashboard-card.gradient-3 {
    background-image: linear-gradient(135deg, #EF5350 0%, #FF8A65 100%);
}