/* ห้อง 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; } }

/* ---------- Check in / Visit ---------- */
.admin-link { color: #c9d8e0; text-decoration: none; font-size: .9rem; }
.admin-link:hover { color: #fff; }
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }
.visit-head { background: #fff; border: 1px solid var(--line); border-left: 6px solid #9aa7ae; border-radius: 12px; padding: 12px 14px; }
.visit-head.is-open { border-left-color: var(--warn); }
.reading-value-sm { font-size: 2.2rem; }
.detail-photo-sm { max-width: 60%; }

/* แท็บหน้าตั้งค่า */
.settings-tabs { display: flex; gap: 6px; overflow-x: auto; }
.settings-tabs a { flex-shrink: 0; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff;
    color: #3d4f58; text-decoration: none; font-size: .9rem; }
.settings-tabs a.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ช่วงอุณหภูมิ/ความชื้นที่ยอมรับ */
:root { --cold: #1f6fb2; }
.range-group { border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px 14px; background: #fff; }
.range-group legend { float: none; width: auto; font-size: .9rem; font-weight: 600; padding: 0 6px; margin: 0 0 4px -6px; }
.thermo-range { position: absolute; top: 6px; height: 12px; border-radius: 6px; border: 2px solid var(--ink); opacity: .55; }
.thermo-limit span { top: -18px; }
.alert-line.cold, .text-cold { color: var(--cold); }

/* Check in: เลือกประเภทการเข้าห้อง */
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-option { display: flex; gap: 10px; align-items: center; padding: 12px; border: 2px solid var(--line); border-radius: 10px;
    background: #fff; cursor: pointer; line-height: 1.25; }
.mode-option > i { font-size: 1.6rem; color: var(--ink); }
.mode-option small { display: block; color: #6b7b84; font-size: .78rem; }
.btn-check:checked + .mode-option { border-color: var(--ink); background: #eef4f7; box-shadow: inset 0 0 0 1px var(--ink); }
.btn-check:focus-visible + .mode-option { outline: 3px solid var(--cool); outline-offset: 2px; }

/* หน้าเข้าห้องแบบภารกิจอื่น */
.task-note { background: #eef4f7; border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.temp-optional > summary { cursor: pointer; padding: 10px 12px; border: 1px dashed #b9c6cd; border-radius: 10px; background: #fff; color: var(--ink); font-weight: 500; }
.temp-optional[open] > summary { margin-bottom: 4px; }
.temp-optional.always-open > summary { display: none; }
.visit-remark { white-space: pre-line; }
.visit-photo { max-width: 100%; max-height: 240px; border-radius: 8px; border: 1px solid var(--line); }

/* แถบช่วงค่า: อุณหภูมิ + ความชื้น */
.range-bar { display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: start; }
.range-bar + .range-bar .thermo { margin-top: 22px; }
.range-bar-label { padding-top: 30px; font-size: .75rem; color: #6b7b84; }
.range-bar + .range-bar .range-bar-label { padding-top: 26px; }
.bar-humid .thermo-track { background: linear-gradient(90deg, #e3b23c 0%, #cfc06a 30%, var(--cool) 45%, var(--cool) 60%, #2a7fd0 80%, #1d4fa8 100%); }

.danger-zone { border: 1px solid #f1c3bf; background: #fff8f7; border-radius: 10px; padding: 14px; }
