/* Ported from opd-dashboard-wnk (static/flow.css) — MIT, Copyright (c) 2026 Phadetchai Singhon,
   Wang Nam Khiao Hospital (full notice in assets/js/flow.js). Fonts: Kanit / Sarabun, SIL Open Font License 1.1. */
@font-face { font-family: 'Kanit'; font-weight: 500;
             src: url('../fonts/Kanit-Medium.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Kanit'; font-weight: 600;
             src: url('../fonts/Kanit-SemiBold.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Sarabun'; font-weight: 400;
             src: url('../fonts/Sarabun-Regular.ttf') format('truetype'); font-display: block; }
@font-face { font-family: 'Sarabun'; font-weight: 600;
             src: url('../fonts/Sarabun-SemiBold.ttf') format('truetype'); font-display: block; }

:root {
  /* สีของระบบมาจาก <html style> ที่ flow.php ใส่ (Theme::palette) — ค่าในวงเล็บคือสำรอง */
  --navy: var(--brand-dark, #0f2a5c);
  --blue: var(--brand, #1565d8);
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e5e9f0;
  --ok: #1fa463;
  --mid: #f59e0b;
  --high: #e5484d;
  --card: rgba(255, 255, 255, .94);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Sarabun', 'Leelawadee UI', sans-serif;
  color: var(--ink);
  background: #e9f3ea;
  -webkit-tap-highlight-color: transparent;
}
#map { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.drag { cursor: grabbing; }

button {
  font: 600 13px 'Sarabun', sans-serif;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 4px 9px; cursor: pointer;
}
button:hover { border-color: #b8c4d6; }
button.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.card {
  position: fixed; background: var(--card); border-radius: 14px;
  box-shadow: 0 6px 24px rgb(var(--ink-rgb) / .14); backdrop-filter: blur(6px);
}

/* ---------------------------------------------------------- แถบบน */
.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 18px; padding: 8px 16px;
  background: linear-gradient(90deg, var(--brand-from), var(--brand-to)); color: var(--on-brand);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .2);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--on-brand); text-decoration: none; }
.brand-logo { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: #fff; color: var(--navy); }
.brand-logo .knh-icon { width: 22px; height: 22px; }
.brand b { display: block; font: 600 18px 'Kanit', sans-serif; line-height: 1.1; }
.brand small { font-size: 12px; opacity: .8; }
.manual-link { color: var(--on-brand); text-decoration: none; font-size: 13px; background: rgba(255,255,255,.14);
               border-radius: 8px; padding: 3px 10px; }
.clock { display: flex; align-items: baseline; gap: 6px; margin-left: auto; }
.clock b { font: 600 30px 'Kanit', sans-serif; letter-spacing: .5px; }
.clock small { font-size: 13px; opacity: .8; }
.clock .dot { width: 10px; height: 10px; border-radius: 50%; background: #34d399; align-self: center;
              box-shadow: 0 0 0 0 rgba(52, 211, 153, .7); animation: pulse 1.6s infinite; }
.clock .dot.replay { background: #fbbf24; animation: none; }
.clock .mode { font: 600 12px 'Kanit', sans-serif; padding: 1px 8px; border-radius: 99px;
               background: rgba(255, 255, 255, .16); }
.clock .date { font-size: 13px; opacity: .9; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }
.stats { display: flex; gap: 6px; }
.stats div { background: rgba(0, 0, 0, .2); border-radius: 10px; padding: 3px 12px; text-align: center; min-width: 74px; }
.stats small { display: block; font-size: 11px; opacity: .8; }
.stats b { font: 600 19px 'Kanit', sans-serif; }
.stats .worst b { font-size: 14px; white-space: nowrap; }

/* ---------------------------------------------------------- ตัวควบคุม */
.ctrl { top: 68px; left: 14px; width: 430px; padding: 10px 12px; z-index: 2; }
.ctrl .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ctrl input[type=date] { font: 600 13px 'Sarabun', sans-serif; border: 1px solid var(--line);
                         border-radius: 8px; padding: 3px 6px; color: var(--ink); }
.ctrl .live { color: #059669; }
.ctrl .live.on { background: #059669; border-color: #059669; color: #fff; }
.speeds { display: flex; gap: 3px; }
.speeds button { padding: 4px 6px; font-size: 12px; }
.tl { margin-top: 8px; height: 58px; position: relative; }
#timeline { width: 100%; height: 100%; display: block; cursor: pointer; touch-action: none; }
.note { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------------------------------------------------------- จุดบริการ */
.panel { top: 68px; right: 14px; width: 300px; max-height: calc(100% - 140px); overflow: auto;
         padding: 10px 12px 8px; z-index: 2; }
.panel h3 { font: 600 15px 'Kanit', sans-serif; color: var(--navy); margin-bottom: 6px; }
.panel h3 small { font: 400 11px 'Sarabun', sans-serif; color: var(--muted); }
.arow { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 4px 4px 5px;
        border-radius: 8px; cursor: pointer; }
.arow:hover { background: #f1f5fb; }
.arow .n { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arow .v { font-size: 12.5px; text-align: right; white-space: nowrap; }
.arow .v b { font-family: 'Kanit', sans-serif; font-weight: 600; font-size: 14px; }
.arow .trk { grid-column: 1 / -1; height: 5px; background: #e8ecf2; border-radius: 3px; margin-top: 3px; overflow: hidden; }
.arow .trk i { display: block; height: 100%; border-radius: 3px; transition: width .4s; }
.arow.zero { opacity: .45; }
.arow[hidden] { display: none; }
.arow .sv { color: var(--brand-dark); font-weight: 600; font-size: 12px; }
.dlegend { display: flex; gap: 10px; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.dlegend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 3px; vertical-align: -1px; }
.stats .dens b { font-size: 15px; white-space: nowrap; }
.remote:empty { display: none; }
.remote { font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 6px; }
.fold { display: none; }

.zoom { position: fixed; right: 330px; bottom: 18px; display: flex; flex-direction: column; gap: 5px; z-index: 2; }
.zoom button { width: 34px; height: 34px; font-size: 17px; padding: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); }

.legend { left: 14px; bottom: 14px; padding: 7px 12px; font-size: 12px; display: flex; gap: 12px;
          flex-wrap: wrap; align-items: center; z-index: 2; max-width: calc(100% - 400px); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.legend .muted { color: var(--muted); }
.legend .grp { font-weight: 600; color: var(--navy); margin-left: 4px; }
.legend { gap: 8px 10px; }

/* ---------------------------------------------------------- ชี้ดูเวลารอรายคน */
.tip { position: fixed; z-index: 5; pointer-events: none; background: rgb(var(--ink-rgb) / .94); color: #fff;
       border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.45;
       box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 260px; }
.tip b { font: 600 15px 'Kanit', sans-serif; }
.tip .w { font: 600 15px 'Kanit', sans-serif; }
.tip .w.ok { color: #6ee7b7; } .tip .w.mid { color: #fcd34d; } .tip .w.high { color: #fca5a5; }
.tip .hn { font: 600 14px 'Kanit', sans-serif; letter-spacing: .02em; color: #bfdbfe; }
.tip .u i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px;
            vertical-align: -1px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .6); }

/* ---------------------------------------------------------- จอทีวี (?tv=1) */
body.tv .ctrl, body.tv .zoom { display: none; }

/* ---------------------------------------------------------- มือถือ */
@media (max-width: 900px) {
  .bar { flex-wrap: wrap; gap: 6px 12px; padding: 6px 10px; }
  .brand-logo { width: 30px; height: 30px; }
  .brand b { font-size: 15px; }
  .clock { margin-left: auto; }
  .clock b { font-size: 22px; }
  .clock .date { display: none; }
  .stats { width: 100%; }
  .stats div { flex: 1; min-width: 0; padding: 2px 4px; }
  .stats b { font-size: 15px; }
  .stats .worst b { font-size: 11px; white-space: normal; line-height: 1.15; display: block; }
  .ctrl { top: auto; bottom: 8px; left: 8px; right: 8px; width: auto; }
  .panel { top: 112px; right: 8px; width: 210px; max-height: 45%; padding: 8px; }
  .panel.folded #rows, .panel.folded .remote, .panel.folded .dlegend { display: none; }
  .fold { display: block; position: absolute; top: 6px; right: 6px; padding: 0 7px; }
  .arow .n { font-size: 12px; }
  .legend { display: none; }
  .zoom { right: 8px; bottom: auto; top: 50%; }
}

/* ---------------------------------------------------------- KNHDAS: ปรับหน้าตา + เมนูมุมมอง */
.card {
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(255, 255, 255, .7);
  box-shadow: 0 10px 30px rgb(var(--ink-rgb) / .16), 0 1px 0 rgba(255, 255, 255, .8) inset;
  backdrop-filter: blur(12px) saturate(1.2);
}
.bar { background: linear-gradient(100deg, var(--brand-from) 0%, var(--brand) 55%, var(--brand-to) 100%); }
.stats div { backdrop-filter: blur(4px); border: 1px solid rgba(255, 255, 255, .12); }
button { transition: background .15s, border-color .15s, color .15s, transform .1s; }
button:active { transform: translateY(1px); }
.zoom button { border-radius: 10px; background: rgba(255, 255, 255, .92); }
.zoom button.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }

.viewmenu { right: 380px; bottom: 18px; width: 300px; padding: 12px 14px; z-index: 4; }
.viewmenu[hidden] { display: none; }
.viewmenu header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.viewmenu header b { font: 600 15px 'Kanit', sans-serif; color: var(--navy); }
.viewmenu .x { border: 0; background: transparent; font-size: 20px; line-height: 1; padding: 0 4px; color: var(--muted); }
.vm-rotate { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 2px 0 8px; }
.vm-rotate button { width: 38px; height: 38px; border-radius: 50%; font-size: 18px; padding: 0; }
.compass {
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff, #e8eef7); border: 1px solid var(--line);
  box-shadow: inset 0 1px 4px rgb(var(--ink-rgb) / .12);
}
.compass span {
  position: relative; width: 100%; height: 100%; transform: rotate(var(--a, 0deg)); transition: transform .08s linear;
}
.compass span::before { /* เข็มชี้ทิศเหนือ */
  content: ""; position: absolute; left: 50%; top: 5px; width: 0; height: 0; margin-left: -5px;
  border: 5px solid transparent; border-bottom: 15px solid #dc2626; border-top: 0;
}
.compass span::after {
  content: ""; position: absolute; left: 50%; bottom: 5px; width: 0; height: 0; margin-left: -5px;
  border: 5px solid transparent; border-top: 15px solid #94a3b8; border-bottom: 0;
}
.compass span i {
  position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; font: 600 10px Kanit, sans-serif; font-style: normal; color: #dc2626;
  transform: rotate(calc(var(--a, 0deg) * -1)); box-shadow: 0 0 0 1px #e5e9f0;
}
.vm-range { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; font-weight: 600; margin-top: 6px; }
.vm-range output { font: 600 13px 'Kanit', sans-serif; color: var(--navy); }
.vm-range input { grid-column: 1 / -1; width: 100%; accent-color: var(--brand); }
.vm-presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; margin-top: 10px; }
.vm-presets button.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.vm-opts { display: grid; gap: 4px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 13px; }
.vm-opts input { accent-color: var(--brand); margin-right: 6px; vertical-align: -1px; }
.viewmenu footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.viewmenu footer small { color: var(--muted); font-size: 11px; text-align: right; }
body.tv .viewmenu { display: none; }
@media (max-width: 900px) {
  .viewmenu { left: 8px; right: 8px; width: auto; bottom: 150px; }
}

.viewmenu footer button { white-space: nowrap; }
