:root {
    --primary-blue: #1a4b84;
    --secondary-blue: #eef2f7;
    --accent-blue: #007bff;
    --text-dark: #333;
    --white: #ffffff;
    --success-green: #28a745;
    --gray-text: #6c757d;
    --danger-red: #dc3545;
    --hover-blue: #e3f2fd; 
}

body {
    font-family: 'Sarabun', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f9;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    background-color: var(--white);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 0.5rem 5%; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 35px;
}

.logo-img {
    height: 55px;
    width: auto;
    display: block;
}

.logo-text {
    font-weight: bold;
    font-size: 1.5rem;
    color: var(--primary-blue);
}

.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    z-index: 1100;
}

.menu-toggle span {
    width: 30px;
    height: 3px;
    background-color: var(--primary-blue);
    transition: 0.3s;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 20px;
    margin: 0;
    padding: 0;
}

nav a {
    text-decoration: none;
    color: var(--text-dark);
    font-weight: 500;
    transition: 0.3s;
    cursor: pointer;
}

nav a:hover, nav a.active { color: var(--accent-blue); border-bottom: 2px solid var(--accent-blue); }

main {
    flex: 1;
    padding: 2rem 2%;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

#home-page { max-width: 1103px; }
#realtime-page { max-width: 98%; }
#note-page { max-width: 900px; }

.setup-section {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
}

.scanner-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

@media (max-width: 768px) {
    .logo-text { font-size: 1.1rem; }
    .logo-area { gap: 15px; }
    .menu-toggle { display: flex; }
    nav ul {
        position: fixed;
        right: -100%;
        top: 0;
        width: 280px;
        height: 100vh;
        background: var(--white);
        flex-direction: column;
        gap: 0;
        padding: 80px 0;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        transition: 0.4s ease;
        z-index: 1050;
    }
    nav ul.active { right: 0; }
    nav ul li { width: 100%; }
    nav a {
        font-size: 1.1rem;
        display: block;
        padding: 15px 25px;
        border-bottom: none;
    }
    nav a:hover {
        background-color: var(--hover-blue);
        color: var(--accent-blue);
        border-bottom: none;
    }
    nav a.active {
        background-color: var(--secondary-blue);
        border-bottom: none;
    }
    .scanner-container { grid-template-columns: 1fr; }
    
    /* ปรับให้หน้า Realtime บนมือถือยังดูดี */
    .realtime-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }
    .realtime-header .search-input {
        width: 100%;
    }
}

.scanner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: nowrap;
    gap: 15px;
}

/* เพิ่มส่วนนี้เพื่อให้หัวข้อ 3 และ Search Box อยู่บรรทัดเดียวกัน */
.realtime-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.header-line-navy {
    height: 4px;
    background-color: var(--primary-blue);
    width: 100%;
    margin-bottom: 20px;
    border-radius: 2px;
}

.search-group { display: flex; gap: 5px; }

.search-input {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 5px;
    outline: none;
    width: 220px;
    font-family: 'Sarabun', sans-serif;
}

.btn-search {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.result-card {
    background: var(--white);
    border: 3px solid var(--primary-blue);
    border-radius: 15px;
    padding: 25px;
    position: relative;
    display: none; 
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.card-header {
    border-bottom: 2px solid var(--secondary-blue);
    margin-bottom: 20px;
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--primary-blue);
}

#display-id {
    background-color: var(--primary-blue);
    color: white;
    padding: 5px 15px;
    border-radius: 5px;
    font-weight: bold;
    display: inline-block;
}

.info-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 15px;
    font-size: 1.1rem;
}

.label { font-weight: bold; color: #666; }
.value { font-weight: 700; color: var(--text-dark); }

.status-badge {
    background: var(--success-green);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 20px;
}

.table-container, .note-container {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #ddd;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    table-layout: fixed;
}

th, td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid #ddd;
    vertical-align: top;
}

th {
    background-color: var(--primary-blue);
    color: white;
    white-space: nowrap;
    overflow: auto;
    resize: horizontal;
}

td {
    white-space: normal;
    word-break: break-word;
}

th:nth-child(1) { width: 50px; }
th:nth-child(2) { width: 130px; }
th:nth-child(3) { width: 180px; }
th:nth-child(4) { width: auto; }
th:nth-child(5) { width: 80px; }
th:nth-child(6) { width: 160px; }
th:nth-child(7) { width: 100px; }

tr:hover { background-color: #f9f9f9; }

.status-present { color: var(--success-green); font-weight: bold; }
.status-none { color: var(--gray-text); font-style: italic; }

.summary-container {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.summary-item { text-align: center; }
.summary-label { font-size: 0.9rem; color: var(--gray-text); margin-bottom: 5px; }
.summary-value { font-size: 1.5rem; font-weight: bold; color: var(--primary-blue); }
.summary-value.success { color: var(--success-green); }
.summary-value.danger { color: var(--danger-red); }

.note-textarea {
    width: 100%;
    height: 400px;
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-family: 'Sarabun', sans-serif;
    font-size: 1rem;
    resize: vertical;
    box-sizing: border-box;
    outline: none;
}
.note-textarea:focus { border-color: var(--accent-blue); box-shadow: 0 0 5px rgba(0,123,255,0.2); }
.save-status { font-size: 0.85rem; color: var(--gray-text); margin-top: 10px; display: block; }

footer {
    background: var(--primary-blue);
    color: white;
    text-align: center;
    padding: 0rem;
    margin-top: auto;
}

input[type="file"] {
    padding: 10px;
    background: var(--secondary-blue);
    border-radius: 5px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.btn-download {
    background: var(--success-green);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    display: none;
    margin-top: 10px;
    width: 100%;
}
.btn-download:hover { background: #218838; }
.btn-clear { display: none; }