/* Nocturne theme from the box's home screen (the "DPTN TV App" design, android res/values/colors.xml).
   Always dark, like the TV. */
:root {
  color-scheme: dark;
  --bg: #161826;
  --bg-top: #1c1f33;
  --card: #232532;
  --text: #e9e9ed;
  --muted: #9397ab;
  --soft: #b2b6ca;
  --border: #3f424d;
  --divider: #2f3240;
  --accent: #9184d9;
  --accent-hover: #a99ef0;
  --accent-soft: #2b2741;
  --accent-text: #e7e5fe;
  --on-accent: #161826;
  --ok: #7dd3a0;
  --warn: #e8bd6c;
  --bad: #f08a80;
  --pill: #2b2741;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 6px 18px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.55 "Inter", "Noto Sans Thai", "Sarabun", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 0 0, var(--bg-top), transparent 70%) no-repeat, var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 16px;
  padding: 10px 20px; border-bottom: 1px solid var(--divider);
  background: linear-gradient(180deg, var(--bg-top), rgba(22, 24, 38, .92)); backdrop-filter: blur(8px);
}
h1 { display: flex; align-items: center; gap: 12px; font-size: 20px; font-weight: 500; margin: 0; }
h1 .logo { height: 40px; width: auto; display: block; }
h2 { font-size: 18px; font-weight: 500; margin: 0 0 10px; letter-spacing: .01em; }
.sub { font-weight: 400; color: var(--muted); font-size: 15px; }
.top-right { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
#server-time { font-variant-numeric: tabular-nums; color: var(--soft); }
main { max-width: 1400px; margin: 0 auto; padding: 20px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.narrow { max-width: 400px; margin: 56px auto; }
.card-head p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
tbody tr:hover { background: rgba(145, 132, 217, .05); }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--divider); vertical-align: top; }
th { color: var(--muted); font-weight: 500; white-space: nowrap; font-size: 12.5px; letter-spacing: .02em; }
td .line { display: block; white-space: nowrap; }
.pill { display: inline-block; background: var(--pill); color: var(--accent-text); border-radius: 999px; padding: 2px 11px; font-size: 12.5px; font-weight: 400; vertical-align: middle; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; color: var(--soft); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
input, select, button { font: inherit; }
input[type=text], input[type=password], input[type=number], input[type=time], select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input::placeholder { color: #75798c; }
input[type=file] { color: var(--soft); }
input[type=file]::file-selector-button { margin-right: 10px; padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent-text); cursor: pointer; }
input[type=text] { width: 100%; }
button {
  padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent);
  font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { background: transparent; color: var(--accent-text); border-color: var(--border); font-weight: 500; }
button.ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); color: var(--on-accent); }
button.danger:hover:not(:disabled) { background: #f6a49c; border-color: #f6a49c; }
button:disabled { opacity: .5; cursor: not-allowed; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.danger-zone { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.danger-zone p { margin: 6px 0 0; }
fieldset.days { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 10px; }
form > label { margin-bottom: 10px; }
h3 { font-size: 15px; margin: 14px 0 6px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
legend { color: var(--soft); font-size: 13.5px; padding: 0 4px; }
.nowrap { white-space: nowrap; }
button.danger-text { color: var(--bad); border-color: var(--bad); }
button.danger-text:hover:not(:disabled) { background: rgba(240, 138, 128, .12); border-color: var(--bad); }
.save-row { margin-top: 12px; }
.library { border-top: 1px solid var(--divider); padding: 10px 0; }
.library p { margin: 2px 0 6px; }
.lan-link { display: inline-block; margin-left: 8px; padding: 2px 10px; border: 1px solid var(--accent); border-radius: 999px; font-size: 13px; }
details { margin: 2px 0; }
summary { cursor: pointer; }
code { background: var(--pill); color: var(--accent-text); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
summary::marker { color: var(--accent); }
.playlist { margin: 0 0 10px; padding-left: 22px; }
.playlist li { padding: 3px 0; }
.playlist li > span:first-child { margin-right: 8px; }
/* Videos on a box: rename / move (app 1.3.8+) */
.playlist li.file-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--divider); }
.playlist li.file-row::marker { color: var(--muted); }
.playlist li.file-row .file-name { flex: 1; min-width: 0; overflow-wrap: anywhere; margin: 0; }
.playlist li.file-row input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.icon-btn { padding: 2px 10px; font-size: 15px; line-height: 1.4; min-width: 36px; min-height: 32px; flex: none; }
summary .icon-btn { margin-left: 8px; vertical-align: middle; }
.bulk-bar { position: sticky; bottom: 12px; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; padding: 10px 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.bulk-bar select { flex: 1; min-width: 140px; }
.fileops { list-style: none; margin: 4px 0 8px; padding: 0; }
.fileops li { padding: 2px 0; overflow-wrap: anywhere; }
.file-dialog { width: min(480px, calc(100vw - 32px)); background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.file-dialog::backdrop { background: rgba(10, 11, 20, .65); }
.file-dialog h3 { margin: 0 0 4px; }
.file-dialog [hidden] { display: none !important; }
.file-dialog label.check input { width: auto; flex: none; margin-top: 3px; }
.file-dialog label { display: block; margin: 10px 0; }
.file-dialog label.check { display: flex; gap: 8px; align-items: flex-start; }
.file-dialog input[type=text], .file-dialog select { width: 100%; }
.name-ext { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.name-ext input { flex: 1; min-width: 0; }

.dropzone {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 84px; margin: 10px 0;
  border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); cursor: pointer; padding: 12px;
}
.dropzone:hover { border-color: var(--accent); color: var(--accent-text); }
.dropzone.over { border-color: var(--accent); color: var(--accent-text); background: var(--pill); }
.dropzone.busy { opacity: .6; pointer-events: none; }
/* ---------------------------------------------------------------- จอสด (live preview TVs) */
.live-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.live-head h2 { margin: 0; }
#live > p { margin: 6px 0 14px; }
.tvs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 22px 18px; align-items: start; }
.tv { margin: 0; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.tv.big { grid-column: 1 / -1; max-width: 900px; width: 100%; justify-self: center; }
.tv-body {
  display: block; width: 100%; padding: 9px 9px 0; border: 0; border-radius: 14px; cursor: zoom-in;
  background: linear-gradient(160deg, #3a404c, #1a1d24 60%); box-shadow: 0 6px 18px rgba(0, 0, 0, .25), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.tv-body:hover:not(:disabled) { background: linear-gradient(160deg, #464b63, #1c1f2b 60%); }
.tv.big .tv-body { cursor: zoom-out; }
.tv-screen {
  position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden;
  aspect-ratio: 16 / 9; border-radius: 6px; background: #05070a; box-shadow: inset 0 0 0 1px #000, inset 0 0 24px rgba(0, 0, 0, .8);
}
.tv-screen img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* Soft glass reflection so it reads as a screen. */
.tv-screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(125deg, rgba(255, 255, 255, .10) 0%, rgba(255, 255, 255, 0) 38%);
}
.tv-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; color: #e8ecf2; font-size: 15px; line-height: 1.4; text-align: center; }
.tv-msg:empty { display: none; }
.tv-msg small { color: var(--soft); font-size: 12.5px; }
.tv[data-mode="idle"] .tv-screen, .tv[data-mode="waiting"] .tv-screen, .tv[data-mode="none"] .tv-screen {
  background: radial-gradient(ellipse at 50% 40%, #262a60, #161826 70%);
}
.tv[data-mode="offline"] .tv-screen {
  background:
    repeating-radial-gradient(circle at 17% 31%, #9aa0a8 0 1px, transparent 1px 3px),
    repeating-radial-gradient(circle at 71% 62%, #5c626b 0 1px, transparent 1px 2px),
    #2a2e35;
  animation: tv-static .25s steps(3) infinite;
}
.tv[data-mode="offline"] .tv-msg { background: rgba(0, 0, 0, .45); }
@keyframes tv-static { 0% { background-position: 0 0, 0 0; } 50% { background-position: 3px -2px, -2px 1px; } 100% { background-position: -1px 2px, 2px -3px; } }
.tv.paused .tv-msg { background: rgba(0, 0, 0, .35); font-size: 18px; }
.tv.stale img { filter: grayscale(.8) brightness(.7); }
.tv-badge {
  position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 5px; z-index: 1;
  padding: 1px 8px; border-radius: 999px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11.5px; font-weight: 600;
}
.tv-badge b { font-weight: 600; }
.tv-badge:has(b:empty) { display: none; }
.tv-badge i { width: 7px; height: 7px; border-radius: 50%; background: #ff4d4f; animation: tv-pulse 2s ease-in-out infinite; }
.tv.stale .tv-badge i, .tv[data-mode="offline"] .tv-badge i { background: #9aa3b2; animation: none; }
@keyframes tv-pulse { 50% { opacity: .25; } }
.tv-now {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 14px 10px 6px; color: #fff; font-size: 12.5px; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: linear-gradient(transparent, rgba(0, 0, 0, .75));
}
.tv-now:empty { display: none; }
.tv.big .tv-now { font-size: 15px; }
.tv-chin { display: flex; align-items: center; justify-content: center; position: relative; height: 18px; }
.tv-brand { color: var(--muted); font-size: 9px; letter-spacing: .18em; font-weight: 700; }
.tv-led { position: absolute; right: 12px; width: 5px; height: 5px; border-radius: 50%; background: #3fb950; box-shadow: 0 0 6px #3fb950; }
.tv[data-mode="offline"] .tv-led, .tv[data-mode="none"] .tv-led { background: #f85149; box-shadow: 0 0 6px #f85149; }
.tv[data-mode="idle"] .tv-led { background: #d29922; box-shadow: 0 0 6px #d29922; }
.tv-stand { width: 26%; height: 14px; background: linear-gradient(#2b3039, #14171c); clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%); }
.tv figcaption { margin-top: 8px; text-align: center; display: flex; flex-direction: column; gap: 1px; max-width: 100%; }
.tv figcaption span:empty { display: none; }
#live.live-off .tvs { opacity: .55; }
#camera > label { display: block; margin: 12px 0 16px; }
.cam-tv { margin: 0 auto; }
.cam-tv .tv-body { cursor: default; }
.cam-tv[data-mode="error"] .tv-screen, .cam-tv[data-mode="none"] .tv-screen { background: #10131a; }


.pl-slots { margin: 8px 0; padding: 0; list-style: none; }
.pl-slots .pos { width: 1.6em; text-align: right; font-weight: 600; }
.pl-slots li { display: flex; gap: 6px; align-items: center; padding: 3px 0; }
.pl-slots select { flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- pages + navigation */
.small-btn { padding: 5px 12px; font-size: 13px; }
a.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none;
}
a.btn:hover { background: var(--accent-hover); color: var(--on-accent); text-decoration: none; }
a.brand { display: block; }
body:not([data-role="admin"]) .admin-only { display: none !important; }

.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); max-width: 1480px; margin: 0 auto; }
.shell > main { max-width: none; margin: 0; padding: 22px 24px 40px; min-width: 0; }
.side {
  position: sticky; top: 61px; align-self: start; height: calc(100vh - 61px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px; padding: 18px 10px; border-right: 1px solid var(--divider);
}
.side a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--soft); font-size: 14.5px; text-decoration: none; transition: background .15s, color .15s;
}
.side a:hover { background: rgba(145, 132, 217, .08); color: var(--text); text-decoration: none; }
.side a.active { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 3px 0 0 var(--accent); }
.side svg { width: 20px; height: 20px; flex: none; fill: currentColor; opacity: .9; }
.side a span { flex: 1; white-space: nowrap; }
.nav-badge { font-style: normal; font-weight: 500; font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--pill); color: var(--accent-text); }
.nav-badge:empty { display: none; }
.nav-badge.warn { color: var(--warn); }
.page-head { margin-bottom: 14px; }
.page-head h2 { font-size: 22px; margin: 0 0 2px; }
.page-head p { margin: 0; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.row-head h3 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.subcard { background: var(--bg); border: 1px solid var(--divider); border-radius: var(--radius); padding: 4px 16px 14px; }
.sticky-save { position: sticky; bottom: 0; background: var(--card); padding: 12px 0 4px; border-top: 1px solid var(--divider); }

/* Overview */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); text-decoration: none;
}
.stat:hover { border-color: var(--accent); text-decoration: none; color: var(--text); }
.stat strong { font-size: 30px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat strong small { font-size: 17px; color: var(--muted); font-weight: 500; }
.stat-label { color: var(--soft); font-size: 13px; }
.stat.ok strong { color: var(--ok); }
.stat.warn strong { color: var(--warn); }
.stat.bad strong { color: var(--bad); }
.mini-devices { display: flex; flex-direction: column; }
.mini {
  display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-top: 1px solid var(--divider);
  color: var(--text); text-decoration: none; border-radius: 6px;
}
.mini:first-child { border-top: 0; }
.mini:hover { background: rgba(145, 132, 217, .06); text-decoration: none; color: var(--text); }
.mini-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-now { color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-side { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.pdot { flex: none; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.on > .pdot { background: var(--ok); box-shadow: 0 0 6px rgba(125, 211, 160, .6); }
.ov-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--divider); }
.ov-row:first-child { border-top: 0; }
.ov-row > span:last-child { text-align: right; }

/* Device chips used to pick target boxes */
.picker { margin: 4px 0 14px; }
.pick-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.pick-chip {
  flex-direction: row; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); user-select: none;
}
.pick-chip input { margin: 0; }
.pick-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.pick-chip.off span { color: var(--muted); }

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
/* Phones and small tablets: the menu becomes a bottom tab bar. */
@media (max-width: 860px) {
  .top { padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  h1 .logo { height: 32px; }
  .top .sub, #server-time { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .shell > main { padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }
  .side {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 6; height: auto;
    flex-direction: row; gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-top: 1px solid var(--divider); background: rgba(28, 31, 51, .96); backdrop-filter: blur(10px);
    scrollbar-width: none;
  }
  .side::-webkit-scrollbar { display: none; }
  .bulk-bar { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .side a { flex: 1 0 68px; flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11.5px; position: relative; text-align: center; }
  .side a.active { box-shadow: none; }
  .side a span { flex: none; }
  .side .nav-badge { position: absolute; top: 2px; right: 8px; font-size: 10px; padding: 0 5px; }
  .card { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat strong { font-size: 24px; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .row { flex-direction: column; }
}
code.copy { cursor: copy; font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--pill); }
code.copy[data-copied]::after { content: ' ✓ คัดลอกแล้ว'; color: var(--accent-text); }
