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

:root { 
    --p: #6A1B29; --s: #8B2332; --accent: #D69E2E; --ok: #276749; --err: #9B2C2C;
    --bg: #F0F4F8; --bg-card: #FFFFFF; --text-main: #2D3748; 
    --border: #E2E8F0; --bg-th: #F8FAFC; --bg-hover: #F1F5F9;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Sarabun', sans-serif; }
body { background: var(--bg); color: var(--text-main); }

/* 🌟 ปรับขนาดโลโก้ให้เท่าตัวหนังสือ และวางคู่กันได้สวยงาม */
    .header-logo { 
        height: 2.2em; /* บังคับความสูงให้สัมพัทธ์กับตัวอักษร K-MIS */
        width: auto;   /* ให้ความกว้างปรับตามอัตราส่วนภาพ */
        vertical-align: text-bottom; /* จัดให้ฐานรูปอยู่แนวเดียวกับฐานตัวหนังสือ */
        cursor: pointer; 
        transition: transform 0.2s;
        margin-right: 5px; /* ระยะห่างระหว่างโลโก้กับตัวอักษร K-MIS */
    }
    .header-logo:hover { transform: scale(2.05); }

.header { background: linear-gradient(135deg, var(--p), var(--s)); border-bottom: 4px solid var(--accent); color: white; padding: 12px 25px; }
.header-content { display: flex; align-items: center; justify-content: flex-start; gap: 12px; max-width: 2200px;   /* patch53: เดิม 1200px ทำให้จอกว้างมีขอบว่างข้างละหลายร้อยพิกเซล — ตอนนี้ใช้เต็มความกว้างจอ (จำกัดไว้ที่จอ 2200px ขึ้นไป) */ margin: 0 auto; }
.header-kmis { font-size: 34px; font-weight: bold; line-height: 1; letter-spacing: 1px; text-shadow: 1px 1px 2px rgba(0,0,0,0.3); margin-right: 5px; }
.header-divider { width: 2px; height: 35px; background: rgba(255,255,255,0.3); margin: 0 8px; border-radius: 2px; }
.header-text .title-th { font-size: 13px; font-weight: bold; }
.header-text .title-sub { font-size: 13px; color: rgba(255,255,255,0.85); }

.app-wrapper { display: flex; max-width: 2200px;   /* patch53: ดูหมายเหตุที่ .header-content */ margin: 25px auto; padding: 0 15px; gap: 25px; align-items: flex-start; }
.navbar { flex: 0 0 240px; background: var(--bg-card); border-radius: 16px; padding: 15px; box-shadow: 0 4px 20px rgba(0,0,0,0.03); border: 1px solid var(--border); }
.nav-item { padding: 12px 16px; cursor: pointer; font-weight: bold; color: var(--text-main); font-size: 14px; border-radius: 10px; margin-bottom: 6px; display: flex; align-items: center; gap: 12px; transition: 0.3s; }
.nav-item:hover { background-color: var(--bg-hover); } 
.nav-item.active { background: linear-gradient(135deg, #F6E05E, #D69E2E); color: #1A202C; box-shadow: 0 4px 15px rgba(214, 158, 46, 0.2); }

/* เมนูย่อย */
.nav-submenu { display: none; flex-direction: column; padding-left: 15px; margin-top: 5px; margin-bottom: 5px; border-left: 2px solid var(--border); margin-left: 15px; }
.nav-submenu.open { display: flex; }
.nav-subitem { padding: 8px 12px; margin-bottom: 4px; border-radius: 8px; cursor: pointer; font-size: 13px; color: #4A5568; transition: all 0.2s; display: flex; align-items: center; gap: 8px; }
.nav-subitem:hover { background-color: var(--border); color: var(--p); }
.nav-arrow { font-size: 10px; margin-left: auto; transition: transform 0.3s; }
.nav-accordion-header.open .nav-arrow { transform: rotate(180deg); }

.container { flex: 1; min-width: 0; }
.page { display: none; } .page.active { display: block; }
.card { background: var(--bg-card); border-radius: 16px; border: 1px solid var(--border); padding: 24px; margin-bottom: 24px; box-shadow: 0 2px 10px rgba(0,0,0,0.02); }

#searchBoxCard { max-width: 850px; margin: 0 auto; }
input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 16px; transition: 0.2s; outline:none; }
input:focus { border-color: var(--s); box-shadow: 0 0 0 3px rgba(106, 27, 41, 0.1); }

.btn { background: var(--p); color: white; border: none; padding: 10px 16px; font-weight: bold; border-radius: 6px; cursor: pointer; font-size: 15px; transition: 0.2s; }
.btn:hover { background: var(--s); transform: translateY(-1px); }

.emp-badge { background: var(--bg-th); border: 1px solid var(--border); padding: 12px; margin-bottom: 8px; border-radius: 6px; cursor: pointer; transition: 0.2s; }
.emp-badge:hover { border-color: var(--p); background: var(--bg-hover); }

.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 15px; overflow-x: auto; gap: 4px; }
.tab-btn { padding: 12px 16px; cursor: pointer; font-weight: bold; color: #718096; white-space: nowrap; border-bottom: 3px solid transparent; transition: 0.2s; }
.tab-btn.active { color: var(--p); border-bottom: 3px solid var(--accent); }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; } 
th, td { padding: 14px 16px; text-align: center; border-bottom: 1px solid var(--border); } 
th { background: var(--bg-th); color: var(--s); }
tr:last-child td { border-bottom: none; }

.skeleton-box { background-color: var(--border); border-radius: 4px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

.nav-text-desktop { display: inline; } 
.nav-text-mobile { display: none; }

@media screen and (min-width: 769px) { #mobile-ui { display: none !important; } }
@media screen and (max-width: 768px) { #desktop-ui { display: none !important; } }

/* ====== สไตล์สำหรับระบบรับรองสำเนา (Watermark) ====== */
.wm-a4-preview {
    background: white; width: 210mm; min-height: 297mm; padding-top: 3.5cm;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); display: flex; flex-direction: column;
    align-items: center; position: relative; box-sizing: border-box; transform-origin: top center;
}
.wm-doc-wrapper { position: relative; display: flex; flex-direction: column; gap: 15px; align-items: center; width: fit-content; }
.wm-image-clip { background: #f8fafc; border: 2px dashed #cbd5e0; border-radius: 4px; overflow: hidden; display: flex; justify-content: center; align-items: center; }
.size-id .wm-image-clip { width: 86mm; height: 54mm; }
.size-house .wm-image-clip, .size-house-1 .wm-image-clip { width: 165mm; height: 95mm; }
.wm-diagonal {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-35deg);
    color: rgba(229, 62, 62, 0.35) !important; font-size: 24px; font-weight: normal !important;
    border-top: 1px solid rgba(229, 62, 62, 0.35) !important; border-bottom: 1px solid rgba(229, 62, 62, 0.35) !important;
    padding: 8px 30px; text-align: center; line-height: 1.3; width: max-content; min-width: 130%;
    white-space: pre-wrap; z-index: 10; pointer-events: none;
}
.wm-bottom-text { text-align: center; margin-top: 40px; color: black; font-size: 16pt; line-height: 1.5; }

/* ========================================================= */
/* 🎨 สไตล์กล่องพับ (Accordion) และปุ่มสวิตช์ (Toggle Switch) */
/* ========================================================= */
.acc-header {
    background: var(--bg-th, #F8FAFC);
    color: var(--p, #1A365D);
    padding: 12px 16px;
    border: 1px solid var(--border, #E2E8F0);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.acc-header:hover {
    background: var(--bg-hover, #EDF2F7);
}
.acc-body {
    display: none; /* ซ่อนเนื้อหาไว้เป็นค่าเริ่มต้น กดแล้วค่อยกางออก */
    padding: 16px;
    border: 1px solid var(--border, #E2E8F0);
    border-radius: 8px;
    margin-top: -4px;
    margin-bottom: 14px;
    background: var(--bg-card, #FFFFFF);
}

/* ปุ่มสวิตช์เลื่อนเปิด-ปิดสีเขียว */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    margin: 0;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #CBD5E0;
    transition: .3s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input:checked + .slider {
    background-color: var(--ok, #2F855A);
}
input:checked + .slider:before {
    transform: translateX(22px);
}