* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1115;
  --bar: #15181d;
  --panel: #1b1e24;
  --tile: #262a31;
  --line: #333a44;
  --text: #e8eaed;
  --muted: #9aa0a8;
  --green: #46c46a;
  --red: #ef4d4d;
  --amber: #f0a83a;
  --blue: #7aa2e3;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
  overflow: hidden;
  user-select: none;
}
/* ซ่อนเมาส์เฉพาะตอนตั้ง ui.hide_cursor: true (สำหรับจอสัมผัส kiosk) */
body.no-cursor, body.no-cursor * { cursor: none !important; }
body { display: flex; flex-direction: column; height: 100vh; }

/* แถบแจ้งอัปเดต */
.update-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: #1f4a7a; color: #fff; padding: 8px 16px; font-size: 14px; gap: 12px;
}
.update-bar button {
  border: none; background: #fff; color: #1f4a7a; font-weight: 600;
  border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.update-bar button:disabled { opacity: .6; cursor: default; }

/* แถบบน */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bar);
}
.brand { font-size: 16px; font-weight: 600; }
.brand .ti { color: var(--blue); margin-right: 6px; }
.clock { color: var(--muted); font-size: 14px; }

/* เนื้อหา */
.main { flex: 1; display: flex; min-height: 0; padding: 8px; gap: 8px; }

/* กล้อง */
.video-area {
  flex: 1.7; position: relative; background: #08090c;
  border-radius: 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
#preview { width: 100%; height: 100%; object-fit: contain; background: #08090c; }
.rec-badge {
  position: absolute; top: 14px; left: 14px;
  background: var(--red); color: #fff; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; font-size: 18px; letter-spacing: 1px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: .25; } }
.cam-tag {
  position: absolute; top: 14px; right: 14px;
  color: #6b7280; font-size: 13px;
}
.flip-controls {
  position: absolute; left: 14px; bottom: 86px;
  display: flex; gap: 8px; flex-wrap: wrap; max-width: calc(100% - 28px);
}
.flip-btn {
  border: 1px solid rgba(255,255,255,.18); background: rgba(22,24,29,.78);
  color: var(--text); border-radius: 10px; padding: 10px 14px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
}
.flip-btn.active {
  border-color: rgba(122,162,227,.75);
  color: #d7e5ff;
  background: rgba(31,74,122,.82);
}
.flip-btn:active { transform: scale(.98); }
.flip-btn:disabled { opacity: .55; cursor: default; }
.dup-warn {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: var(--red); color: #fff; font-size: 17px; font-weight: 600;
  padding: 10px 18px; border-radius: 10px; max-width: 90%;
  animation: blink 1s steps(2, start) infinite;
}
.track-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 16px 18px; background: rgba(0,0,0,.55);
}
.track-label { color: var(--muted); font-size: 12px; }
.track-big { font-size: 30px; font-weight: 600; letter-spacing: .5px; margin-top: 2px; }

/* แผงขวา */
.panel {
  width: 38%; min-width: 300px; background: var(--panel);
  border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.status-row { display: flex; align-items: center; justify-content: space-between; }
.status { font-size: 22px; font-weight: 600; }
.status.ready { color: var(--green); }
.status.rec   { color: var(--red); }
.status.warning { color: var(--amber); }
.timer { font-size: 26px; font-weight: 600; }

.cancel-btn {
  border: 2px solid var(--red); background: transparent; color: var(--red);
  border-radius: 12px; font-size: 16px; font-weight: 600; padding: 14px 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .05s;
}
.cancel-btn:active { transform: scale(.97); }

.mob-conn-btn {
  border: 2px solid var(--green); background: transparent; color: var(--green);
  border-radius: 12px; font-size: 16px; font-weight: 600; padding: 14px 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .05s;
  width: 100%;
}
.mob-conn-btn:active { transform: scale(.97); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--tile); border-radius: 10px; padding: 12px 14px; }
.tile-label { color: var(--muted); font-size: 12px; }
.tile-num { font-size: 30px; font-weight: 600; margin-top: 2px; }

.disk .disk-head { display: flex; justify-content: space-between; align-items: baseline; }
.disk-num { font-size: 20px; font-weight: 600; margin: 4px 0 8px; }
.disk-cap { color: #5f636b; font-size: 13px; font-weight: 400; }
.disk-track { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.disk-bar { height: 100%; width: 0; background: var(--green); transition: width .4s; }

.view-btn {
  border: 1px solid var(--line); background: var(--tile); color: var(--text);
  border-radius: 10px; font-size: 15px; font-weight: 600; padding: 13px 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.view-btn:active { transform: scale(.98); }

.sync {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 8px 10px; border-radius: 8px;
  background: var(--tile); color: var(--muted);
}
.sync.ok   { color: var(--green); }
.sync.wait { color: var(--amber); }
.sync.off  { color: var(--muted); }

.recent-wrap { flex: 1; display: flex; flex-direction: column; min-height: 80px; }
.recent-log {
  flex: 1; list-style: none; overflow-y: auto; margin-top: 6px;
  background: var(--tile); border-radius: 10px; padding: 4px;
}
.recent-log li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 10px; border-bottom: 1px solid #2a2e35;
}
.recent-log li:last-child { border-bottom: none; }
.rl-track { font-size: 14px; font-weight: 600; word-break: break-all; }
.rl-time { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: 10px; }
.recent-empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 13px; }

.selectors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.camera-select {
  background: var(--tile); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; font-size: 13px; width: 100%;
}
.spacer { flex: 1; }
.msg { color: var(--muted); font-size: 12px; min-height: 18px; text-align: center; }

/* ปุ่มใหญ่สำหรับจอสัมผัส */
.power-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bigbtn {
  border: none; color: #fff; border-radius: 12px;
  font-size: 16px; font-weight: 600; padding: 16px 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .05s;
}
.bigbtn:active { transform: scale(.97); }
.bigbtn.shutdown { background: #b23535; }
.bigbtn.restart  { background: #b5781f; }

/* popup ยืนยัน */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal-card { background: var(--panel); border-radius: 14px; padding: 26px 28px; width: 340px; text-align: center; }
.modal-icon { font-size: 44px; color: var(--red); }
.modal-text { font-size: 18px; font-weight: 600; margin: 12px 0 22px; }
.dup-code { font-size: 16px; color: var(--amber); font-weight: 600; word-break: break-all; }
.modal-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mbtn { border: none; border-radius: 10px; padding: 14px 0; font-size: 15px; font-weight: 600; cursor: pointer; }
.mbtn.cancel { background: #2f343c; color: var(--text); }
.mbtn.ok { background: #b23535; color: #fff; }

/* หน้าดูคลิป */
.viewer {
  position: fixed; inset: 0; background: var(--bg); z-index: 20;
  display: flex; flex-direction: column;
}
.viewer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bar); gap: 12px;
}
.viewer-title { font-size: 18px; font-weight: 600; }
.date-nav { display: flex; align-items: center; gap: 10px; }
.date-text { font-size: 15px; color: var(--text); min-width: 150px; text-align: center; }
.dnav {
  border: 1px solid var(--line); background: var(--tile); color: var(--text);
  width: 46px; height: 46px; border-radius: 10px; font-size: 20px; cursor: pointer;
}
.close-btn {
  border: none; background: #2f343c; color: var(--text);
  padding: 12px 18px; border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.viewer-body { flex: 1; display: flex; min-height: 0; padding: 12px; gap: 12px; }
.clip-list {
  width: 320px; list-style: none; overflow-y: auto;
  background: var(--panel); border-radius: 12px; padding: 8px;
}
.clip-item {
  padding: 12px 14px; border-radius: 8px; cursor: pointer;
  border-bottom: 1px solid #2a2e35;
}
.clip-item:active { background: var(--tile); }
.clip-item.active { background: var(--tile); }
.clip-track { font-size: 15px; font-weight: 600; word-break: break-all; }
.clip-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.clip-empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.player-wrap {
  flex: 1; background: #000; border-radius: 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.player { width: 100%; height: 100%; object-fit: contain; }
.player-hint { position: absolute; color: var(--muted); font-size: 15px; }

/* หน้าล็อกเมื่อ license ไม่ผ่าน */
.license-block {
  position: fixed; inset: 0; background: #0b0d10; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.lb-card { text-align: center; max-width: 460px; padding: 30px; }
.lb-icon { font-size: 64px; color: var(--red); }
.lb-title { font-size: 24px; font-weight: 600; margin: 16px 0 8px; }
.lb-reason { font-size: 18px; color: var(--amber); margin-bottom: 18px; }
.lb-meta { font-size: 13px; color: var(--muted); line-height: 1.6; }
.lb-devrow { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px;
  background: var(--tile); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 6px 6px 12px; max-width: 100%; }
.lb-devrow #lbDevice { color: var(--text); font-family: monospace; font-size: 14px;
  user-select: all; -webkit-user-select: all; word-break: break-all; }
.lb-copy { flex: none; border: none; background: var(--green); color: #fff;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; }
.lb-copy:active { transform: scale(0.96); }
.lb-copy.done { background: var(--panel); color: var(--green); border: 1px solid var(--green); }
.lb-input {
  margin-top: 18px; width: 100%; max-width: 360px; padding: 13px 14px;
  border: 1px solid var(--line); background: var(--tile); color: var(--text);
  border-radius: 10px; font-size: 16px; text-align: center; letter-spacing: 1px;
  font-family: monospace;
}
.lb-btn {
  margin-top: 14px; border: none; background: var(--green); color: #fff;
  padding: 14px 32px; border-radius: 10px; font-size: 16px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.lb-btn2 {
  margin: 10px 0 0 10px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); padding: 13px 20px; border-radius: 10px; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}

/* แถบ license (ชื่อร้าน + วันหมดอายุ + ปุ่มจัดการ) */
.lic-bar { background: var(--tile); border-radius: 10px; padding: 9px 11px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lic-info { min-width: 0; }
.lic-shop { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lic-shop .ti { color: var(--green); }
.lic-exp { font-size: 11px; color: var(--muted); margin-top: 1px; }
.lic-btns { display: flex; gap: 4px; flex: none; }
.lic-btns button { background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.lic-btns button:hover { color: var(--text); border-color: var(--muted); }
.set-label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.set-input { width: 100%; padding: 11px; border: 1px solid var(--line); background: var(--tile);
  color: var(--text); border-radius: 9px; font-size: 15px; }

.hidden { display: none !important; }

/* Responsive Mobile Styles */
@media (max-width: 768px) {
  html, body {
    overflow: auto;
  }
  body {
    height: auto;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 12px;
  }
  .topbar > div:last-child {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
  }
  .main {
    flex-direction: column;
    height: auto;
    overflow: visible;
    padding: 6px;
    gap: 6px;
  }
  .video-area {
    position: sticky;
    top: 6px;
    z-index: 5;
    height: auto;
    flex: none;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  #preview {
    order: 1;
    height: 42vh;
    background: #08090c;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  }
  .track-overlay {
    order: 2;
    position: static;
    margin-top: 6px;
    padding: 8px 12px;
    background: var(--tile);
    border-radius: 8px;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
  }
  .flip-controls {
    order: 3;
    position: static;
    margin-top: 6px;
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: none;
    gap: 6px;
  }
  .flip-btn {
    flex: 1;
    justify-content: center;
    padding: 8px;
    font-size: 13px;
    background: var(--tile);
  }
  .power-row {
    display: none !important;
  }
  .panel {
    width: 100%;
    min-width: unset;
    height: auto;
    flex: none;
    padding: 10px;
    gap: 10px;
    border-radius: 8px;
  }
  #mobileConnectBtn {
    display: none !important;
  }
  .recent-wrap {
    min-height: 200px;
  }
  .recent-log {
    max-height: 300px;
  }
  
  /* Viewer Modal in Mobile */
  .viewer-body {
    flex-direction: column;
    height: auto;
    overflow-y: auto;
    padding: 8px;
    gap: 8px;
  }
  .clip-list {
    width: 100%;
    height: 200px;
    flex: none;
  }
  .player-wrap {
    height: 45vh;
    flex: none;
  }
  
  /* Settings and License Modal */
  .modal-card {
    width: 90%;
    padding: 20px;
  }
}

/* QR Scanner Styles */
.lb-scan-btn {
  background: var(--tile);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  width: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s;
}
.lb-scan-btn:hover {
  background: var(--bg);
  border-color: var(--primary);
  color: var(--primary);
}

@keyframes scanline {
  0% { top: 20%; }
  50% { top: 80%; }
  100% { top: 20%; }
}
