/* ธีมสีขาว + น้ำเงิน ตามเว็บไซต์ตรวจคนเข้าเมืองจังหวัดระยอง (rayongimmigration.go.th)
   สะอาดตา อ่านง่าย สบายตา ใช้พื้นขาวเป็นหลัก น้ำเงินเป็นสีเน้น */
:root {
  --navy: #123a70;         /* น้ำเงินหลัก (ข้อความ/เส้นขอบ/ปุ่ม) */
  --navy-deep: #0c2c57;    /* น้ำเงินเข้ม (หัวข้อ/hover) */
  --navy-soft: #eef3fb;    /* น้ำเงินอ่อนมาก (พื้นการ์ด/พาเนล) */
  --red: #d9464f;          /* แดง (LIVE เท่านั้น) */

  --bg: #ffffff;
  --panel: #f5f8fd;
  --panel-2: var(--navy-soft);
  --accent: var(--navy);
  --accent-2: var(--navy);
  --text: #16233d;
  --muted: #64748b;
  --danger: var(--red);
  --line: #dde5f2;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Kanit", "Noto Sans Thai", "Segoe UI", "TH Sarabun New", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- DISPLAY PAGE ---------- */

.display-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(10px, 1.6vh, 20px) clamp(16px, 2.2vw, 36px);
  background: #fff;
  border-bottom: 2px solid var(--navy);
}

.brand {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.2vw, 16px);
  font-weight: 700;
  letter-spacing: 0.2px;
}

.logo-chip {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

.brand img.logo {
  height: clamp(26px, 3.6vh, 42px);
  width: auto;
  display: block;
}

.brand .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.brand .brand-text .th {
  font-size: clamp(0.9rem, 1.5vw, 1.35rem);
  font-weight: 700;
  color: var(--navy-deep);
}

.brand .brand-text .en {
  font-size: clamp(0.6rem, 0.9vw, 0.8rem);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.dot {
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0 rgba(217,70,79,.5);
  animation: pulse 2.4s infinite;
  margin-right: 2px;
  flex-shrink: 0;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(217,70,79,.4); }
  70%  { box-shadow: 0 0 0 10px rgba(217,70,79,0); }
  100% { box-shadow: 0 0 0 0 rgba(217,70,79,0); }
}

.clock {
  display: flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.85rem, 1.3vw, 1.3rem);
  color: var(--muted);
  text-align: right;
}

.clock .live-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(217,70,79,0.08);
  border: 1px solid rgba(217,70,79,0.35);
  color: var(--red);
  border-radius: 999px;
  padding: 3px 11px;
  font-size: clamp(0.6rem, 0.85vw, 0.78rem);
  font-weight: 700;
  letter-spacing: 1px;
  margin-right: 12px;
  vertical-align: middle;
}

.video-panel {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: clamp(12px, 1.6vh, 26px);
}

/* ขนาดจริง (px) ของ .video-frame ถูกคำนวณด้วย JS (ดูใน display.html) ให้เป็นกล่อง 16:9
   ที่ใหญ่ที่สุดเท่าที่จะพอดีในพื้นที่ที่มี — กันปัญหา CSS aspect-ratio คำนวณผิดพลาดในบางเบราว์เซอร์
   พื้นที่ที่เหลือรอบๆ จะเป็นพื้นหลังเว็บ (สีขาว) แทนแถบดำ และภาพจะไม่ถูกครอปขอบเลย */
.video-frame {
  position: relative;
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
}

.video-panel video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: #9aa6c4;
  font-size: clamp(0.9rem, 1.6vw, 1.3rem);
  text-align: center;
  padding: 1rem;
}

.video-status.hidden { display: none; }

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: #6f97d6;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.announce-panel {
  background: #fff;
  display: flex;
  flex-direction: column;
  padding: clamp(12px, 1.6vh, 26px);
  gap: clamp(10px, 1.3vh, 18px);
  overflow: hidden;
  border-left: 1px solid var(--line);
}

.announce-frame {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
}

.announce-badge {
  position: absolute;
  top: clamp(10px, 1.6vh, 16px);
  left: clamp(10px, 1.6vw, 16px);
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.4px;
  font-size: clamp(0.7rem, 0.95vw, 0.88rem);
  padding: 6px 14px;
  border-radius: 999px;
  z-index: 3;
  box-shadow: 0 3px 8px rgba(12,44,87,0.25);
}

.announce-frame img#announceImg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

.announce-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: clamp(0.85rem, 1.2vw, 1.1rem);
}

.announce-empty.hidden { display: none; }

.announce-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.a-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  cursor: pointer;
}

.a-dot.active { background: var(--navy); }

/* ปุ่มลูกศรเลื่อนดูประกาศเอง (ซ้าย/ขวา) ซ้อนอยู่บนกรอบประกาศ */
.announce-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: clamp(28px, 3.2vw, 36px);
  height: clamp(28px, 3.2vw, 36px);
  border-radius: 50%;
  border: none;
  background: rgba(12, 44, 87, 0.45);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
  padding: 0;
  transition: background 0.15s ease;
}

.announce-nav svg {
  width: 55%;
  height: 55%;
}

.announce-nav:hover { background: rgba(12, 44, 87, 0.75); }
.announce-nav.hidden { display: none; }
.announce-nav-prev { left: clamp(6px, 1vw, 12px); }
.announce-nav-next { right: clamp(6px, 1vw, 12px); }

.contact-icon {
  width: clamp(16px, 1.6vw, 20px);
  height: clamp(16px, 1.6vw, 20px);
  flex-shrink: 0;
}

/* มาสคอส + กล่องข้อความ (ทักทาย + ช่องทางติดต่อ): มุมล่างขวาของพาเนลประกาศ */
.welcome-corner {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

/* ปุ่มจองคิวออนไลน์ + กล่องข้อความมาสคอส: จับคู่กันในแถวเดียว ความกว้าง/ความสูงเท่ากันเป๊ะ */
.welcome-boxes {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-bottom: clamp(10px, 3vh, 30px);
}

.booking-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  width: 170px;
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: clamp(0.75rem, 1vw, 0.92rem);
  padding: 12px 10px;
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(18,58,112,0.25);
  transition: background 0.15s ease, transform 0.15s ease;
}

.booking-btn:hover { background: var(--navy-deep); }
.booking-btn:active { transform: scale(0.97); }

.booking-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.welcome-corner .speech-bubble {
  background: #fff;
  color: var(--navy-deep);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  width: 170px;
  flex-shrink: 0;
  text-align: center;
  box-shadow: 0 4px 10px rgba(18,58,112,0.08);
}

.speech-text {
  margin: 0 0 10px;
  font-size: clamp(0.75rem, 1vw, 0.95rem);
  font-weight: 600;
  line-height: 1.4;
}

.speech-contact {
  display: flex;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.speech-contact-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  border-radius: 8px;
  background: var(--navy-soft, #eef3fb);
  color: var(--navy-deep);
  text-decoration: none;
  font-weight: 700;
  font-size: clamp(0.62rem, 0.82vw, 0.78rem);
  transition: background 0.15s ease;
}

.speech-contact-link:hover { background: var(--navy); color: #fff; }

.welcome-corner .mascot {
  height: clamp(80px, 16vh, 160px);
  width: auto;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(18,58,112,0.18));
}

/* มือถือ/แนวตั้ง: ซ้อนวิดีโอไว้บน ประกาศไว้ล่าง */
@media (max-width: 820px), (orientation: portrait) {
  .display-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: auto 40vh 1fr;
  }
  .video-panel { min-height: 220px; }
  .announce-panel { border-left: none; border-top: 1px solid var(--line); }
  .welcome-corner .mascot { height: clamp(50px, 11vh, 100px); }
  .welcome-boxes { margin-bottom: clamp(6px, 2vh, 18px); }
  .welcome-corner .speech-bubble { width: 120px; }
  .speech-contact-link span { display: none; }
  .booking-btn { width: 120px; padding: 8px; font-size: 0.66rem; }
  .booking-icon { width: 15px; height: 15px; }
}

/* ---------- CONTROL PAGE ---------- */

body.control-body {
  background: #f5f8fd;
  color: var(--text);
}

.control-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  padding: 16px clamp(16px, 4vw, 32px);
  border-bottom: 2px solid var(--navy);
}

.control-topbar img.logo {
  height: 32px;
  width: auto;
  display: block;
}

.control-topbar .brand-text .th {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy-deep);
}

.control-topbar .brand-text .en {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.control-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 18px 64px;
}

.control-wrap h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--navy-deep);
}

.control-wrap .sub {
  color: var(--muted);
  margin-top: 0;
  margin-bottom: 26px;
  font-size: 0.95rem;
}

.card {
  background: #ffffff;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
}

.card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 14px;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-left: 3px solid var(--navy);
  padding-left: 10px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

select, input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 1rem;
  flex: 1 1 160px;
}

button {
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

button.primary { background: var(--navy-deep); }
button.secondary { background: var(--muted); }
button:active { transform: scale(0.98); }

.counter-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.counter-row:last-child { border-bottom: none; }

.counter-row .live-num {
  min-width: 60px;
  text-align: center;
  font-weight: 700;
  color: var(--navy);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy-deep);
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

/* กล่องยืนยันรหัสผ่านซ้ำ (เช่นก่อนอัปโหลดรูป) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 44, 87, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  margin: 0;
}

input[type="password"] {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 1rem;
  box-sizing: border-box;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 1.2em;
}
