/* ห้อง Server — โทนห้องเย็น: น้ำเงินหมึก + พื้นเทาอมฟ้า, สีสถานะใช้เฉพาะค่าที่วัดได้ */
:root {
    --ink: #0f3347;
    --ink-2: #1c4a63;
    --surface: #edf1f3;
    --line: #d5dde2;
    --cool: #178a9c;
    --warn: #c07a00;
    --hot: #c2352b;
    --bs-primary: #0f3347;
    --bs-primary-rgb: 15, 51, 71;
    --bs-body-font-family: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
    --nav-h: 64px;
}

body { background: var(--surface); color: #1d2a31; }
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
@media (min-width: 768px) { body.has-nav { padding-bottom: 32px; } }

.btn-primary { --bs-btn-bg: var(--ink); --bs-btn-border-color: var(--ink); --bs-btn-hover-bg: var(--ink-2); --bs-btn-hover-border-color: var(--ink-2); --bs-btn-active-bg: #0a2433; }
.btn-outline-primary { --bs-btn-color: var(--ink); --bs-btn-border-color: var(--ink); --bs-btn-hover-bg: var(--ink); --bs-btn-hover-border-color: var(--ink); }
.form-control:focus, .form-select:focus { border-color: var(--cool); box-shadow: 0 0 0 .2rem rgba(23, 138, 156, .25); }
:focus-visible { outline: 3px solid var(--cool); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.app-top { background: var(--ink); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 0 10px; position: sticky; top: 0; z-index: 1030; }
.brand { color: #fff; text-decoration: none; font-weight: 600; font-size: 1.1rem; }
.top-links { gap: 4px; }
.top-links a { color: #c9d8e0; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.top-links a.active, .top-links a:hover { color: #fff; background: rgba(255,255,255,.1); }
.user-btn { background: none; border: 0; color: #fff; display: flex; align-items: center; gap: 6px; max-width: 60vw; }
.user-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Bottom nav (มือถือ) ---------- */
.bottom-nav { position: fixed; inset: auto 0 0 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    display: flex; background: #fff; border-top: 1px solid var(--line); z-index: 1030; }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: #6b7b84; text-decoration: none; font-size: .74rem; position: relative; }
.bottom-nav a i { font-size: 1.35rem; }
.bottom-nav a.active { color: var(--ink); font-weight: 600; }
.bottom-nav a.active::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--cool); }

.page-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }

/* ---------- Dashboard: แผงห้อง ---------- */
.room-panel { background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--line); border-radius: 12px; padding: 16px; height: 100%; }
.room-panel.level-ok { border-left-color: var(--cool); }
.room-panel.level-warn { border-left-color: var(--warn); }
.room-panel.level-hot { border-left-color: var(--hot); }
.room-name { font-size: 1.05rem; font-weight: 600; margin: 0 0 2px; }

.reading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 14px 0 6px; }
.reading-value { font-size: 3.4rem; font-weight: 700; line-height: .9; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.level-hot .reading-value { color: var(--hot); }
.reading-unit { font-size: 1.3rem; font-weight: 500; margin-left: 2px; vertical-align: top; color: #56666f; }
.reading-label { font-size: .8rem; color: #6b7b84; margin-top: 4px; }
.reading-side { margin: 0; text-align: right; }
.reading-side div { display: flex; gap: 10px; justify-content: flex-end; align-items: baseline; }
.reading-side dt { font-weight: 400; font-size: .8rem; color: #6b7b84; }
.reading-side dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* แถบเทอร์โมมิเตอร์: จุดเดียวที่ใช้สีไล่ระดับ เพื่อบอกว่าค่าอยู่ใกล้เกณฑ์แค่ไหน */
.thermo { position: relative; height: 38px; margin: 26px 0 8px; }
.thermo-track { position: absolute; top: 8px; left: 0; right: 0; height: 8px; border-radius: 4px;
    background: linear-gradient(90deg, #2a9fd6 0%, var(--cool) 40%, #e3b23c 62%, var(--hot) 100%); }
.thermo-dot { position: absolute; top: 2px; width: 20px; height: 20px; margin-left: -10px; border-radius: 50%; background: #fff; border: 4px solid var(--ink); }
.thermo-limit { position: absolute; top: 2px; height: 20px; border-left: 2px dashed var(--ink); }
.thermo-limit span { position: absolute; top: -18px; left: -2px; transform: translateX(-50%); font-size: .7rem; color: var(--ink); white-space: nowrap; }
.thermo-scale { position: absolute; top: 20px; left: 0; right: 0; display: flex; justify-content: space-between; font-size: .7rem; color: #8a979e; }

.alert-line { font-size: .88rem; font-weight: 500; margin: 4px 0 8px; }
.alert-line.hot, .text-hot { color: var(--hot); }
.alert-line.warn, .text-warn { color: var(--warn); }

.in-room-banner { background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }

/* ---------- รายการบันทึก ---------- */
.filter-bar { display: grid; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; }
@media (min-width: 768px) { .filter-bar { grid-template-columns: 1fr 1.4fr auto auto; align-items: center; } }

.log-list { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.log-list:not(:has(.log-item)) { display: none; }
.log-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.log-item:last-child { border-bottom: 0; }
a.log-item:active, a.log-item:hover { background: #f6f9fa; }
.log-item.is-hot { box-shadow: inset 4px 0 0 var(--hot); }
.log-item.is-warn { box-shadow: inset 4px 0 0 var(--warn); }
.log-item.is-open { box-shadow: inset 4px 0 0 var(--warn); background: #fffaf0; }
.log-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.log-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.log-meta { font-size: .85rem; color: #5f6f78; }
.log-temp { font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.is-hot .log-temp { color: var(--hot); }
.seq { width: 44px; flex-shrink: 0; text-align: center; font-size: .85rem; color: #6b7b84; font-variant-numeric: tabular-nums; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: #e3e9ec; }
.thumb-empty { display: flex; align-items: center; justify-content: center; color: #9aa7ae; }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); width: 58px; height: 58px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 1.6rem; color: #fff; background: var(--cool);
    box-shadow: 0 6px 16px rgba(15, 51, 71, .3); z-index: 1020; text-decoration: none; }
.fab:hover { color: #fff; background: #12798a; }
@media (min-width: 768px) { .fab { bottom: 28px; } }

/* ---------- ฟอร์ม ---------- */
.form-narrow { max-width: 640px; }
.req::after { content: " *"; color: var(--cool); }
.form-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 8px; }
.photo-drop { display: flex; align-items: center; justify-content: center; min-height: 150px; width: 100%; border: 2px dashed #b9c6cd;
    border-radius: 10px; background: #fff; cursor: pointer; overflow: hidden; }
.photo-drop img { display: block; max-width: 100%; max-height: 340px; }
.photo-drop img:not(.d-none) + .photo-hint { display: none; }
.photo-hint { display: flex; flex-direction: column; align-items: center; gap: 4px; color: #6b7b84; }
.photo-hint i { font-size: 2.2rem; color: var(--ink); }

.detail-list dt { font-weight: 400; font-size: .85rem; color: #6b7b84; }
.detail-list dd { font-size: 1.15rem; font-weight: 500; margin-bottom: 12px; }
.detail-photo { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }

.empty-state { text-align: center; color: #5f6f78; padding: 48px 16px; }
.empty-state > i { font-size: 2.6rem; display: block; margin-bottom: 8px; color: #9aa7ae; }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login-mark { width: 64px; height: 64px; border-radius: 16px; background: var(--ink); color: #fff; font-size: 2rem;
    display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- อ่านตัวเลขจากรูป ---------- */
.ocr-status { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; padding: 10px 12px; border-radius: 10px;
    background: #e6f1f3; color: #2c4b58; font-size: .9rem; }
.ocr-status > i, .ocr-status > .spinner-border { flex-shrink: 0; margin-top: 3px; }
.ocr-status.busy { background: #eef3f6; }
.ocr-status.done { background: #e3f4ee; color: #1d6048; }
.ocr-status.partial { background: #fff4df; color: #7a4d00; }
.ocr-status.fail { background: #fde8e6; color: #8e261e; }
.form-control.ocr-filled { background: #f1fafb; border-color: var(--cool); }
.ocr-note { font-size: .8rem; min-height: 0; margin-top: 4px; }
.ocr-note:empty { display: none; }
.ocr-note.ok { color: var(--cool); }
.ocr-note.miss { color: var(--warn); }

/* ปุ่มกล้องข้างช่อง + รูปย่อ */
.field-cam { display: flex; align-items: center; background: #fff; }
.field-cam i { font-size: 1.2rem; color: var(--ink); }
.field-photo { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.field-photo:not(:has(img:not(.d-none))):not(:has(.ocr-note:not(:empty))) { display: none; }
.field-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); flex-shrink: 0; }
.field-photo .ocr-note { margin-top: 0; }
.ocr-note.busy { color: #5f6f78; }
.detail-photo-sm { max-width: 60%; }
.field-photo .ocr-note { line-height: 1.3; }
