* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Prompt', sans-serif;
}

body {
    background: #0f172a;
    color: white;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.card {
    width: 100%;
    max-width: 500px;
    background: #1e293b;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

h1 {
    text-align: center;
    margin-bottom: 25px;
    font-weight: 600;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #cbd5e1;
}

input, select {
    width: 100%;
    padding: 14px;
    border: 1px solid #475569;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 16px;
    background-color: #334155;
    color: white;
    transition: 0.3s;
}

input:focus, select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

button:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.search-btn { background: #2563eb; color: white; }
.check-btn { background: #16a34a; color: white; }
.calendar-btn { background: #7c3aed; color: white; margin-top: 10px; }
.snap-btn { background: #ea580c; color: white; }
.upload-btn { background: #0284c7; color: white; }
.cancel-btn { background: #64748b; color: white; margin-top: 10px; }
.reset-btn { background: transparent; border: 1px solid #64748b; color: #cbd5e1; }

.info {
    margin-top: 20px;
    background: #334155;
    padding: 20px;
    border-radius: 10px;
    line-height: 1.8;
}

.history-item {
    background: #334155;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #3b82f6;
}

.history-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #475569;
}

/* --- ระบบ Video กล้อง Responsive --- */
.video-container {
    width: 100%;
    max-height: 50vh; /* บังคับไม่ให้ล้นจอในมือถือ */
    overflow: hidden;
    border-radius: 10px;
    background: #000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

#camera-stream {
    width: 100%;
    height: 100%;
    object-fit: cover; /* ตัดขอบให้พอดีแบบไม่เบี้ยว */
}

/* --- แอนิเมชันตอนเปลี่ยนหน้าต่าง (State Transitions) --- */
.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- ระบบ Button Loading (วงกลมหมุนบนปุ่ม) --- */
.btn-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* --- ระบบ Loading เต็มจอ (ใช้แค่ตอนโหลดเว็บแรกเริ่ม) --- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.95);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 9999; color: white;
}
.spinner {
    width: 50px; height: 50px; border: 5px solid #334155;
    border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- ระบบ Skeleton Loading (กระดูกสันหลังตอนรอข้อมูล) --- */
.skeleton {
    background: #475569;
    background-image: linear-gradient(90deg, #475569 0px, #64748b 40px, #475569 80px);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
    margin-bottom: 10px;
}
.skel-text { height: 20px; width: 100%; }
.skel-text.short { width: 60%; }
.skel-btn { height: 45px; margin-top: 15px; border-radius: 8px; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- ระบบ Custom Smart Dropdown --- */
.search-container { position: relative; width: 100%; }
.autocomplete-items {
    position: absolute; background-color: #1e293b; border: 1px solid #475569;
    border-radius: 8px; z-index: 99; top: 100%; left: 0; right: 0;
    max-height: 250px; overflow-y: auto; box-shadow: 0 10px 25px rgba(0,0,0,0.6);
    display: none; margin-top: -15px; margin-bottom: 20px;
}
.autocomplete-items div {
    padding: 12px 15px; cursor: pointer; border-bottom: 1px solid #334155;
    transition: all 0.2s ease; font-size: 15px; color: #f8fafc;
}
.autocomplete-items div:hover { background-color: #3b82f6; padding-left: 20px; }
.autocomplete-items strong { color: #60a5fa; }
.autocomplete-items div:hover strong { color: white; }
.text-muted { color: #94a3b8; font-size: 13px; display: block; margin-top: 4px; }
.autocomplete-items div:hover .text-muted { color: #e2e8f0; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #1e293b; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* --- Mobile Responsiveness --- */
@media (max-width: 500px) {
    .card { padding: 20px; border-radius: 0; min-height: 100vh; }
    body { padding: 0; align-items: flex-start; }
    h1 { font-size: 22px; margin-bottom: 15px; }
}