:root {
  color-scheme: light;
  --page: #f4f1ea;
  --panel: #fbfaf6;
  --ink: #1f2724;
  --muted: #66716b;
  --line: #d8d4ca;
  --accent: #0f6b5e;
  --accent-strong: #0b4f45;
  --amber: #b56a1c;
  --bad: #b7342c;
  --blue: #2d5f86;
  --shadow: 0 18px 44px rgba(43, 39, 30, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: ui-sans-serif, "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 10px 10px 24px;
  overflow-x: hidden;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.login-box {
  display: grid;
  width: min(100%, 360px);
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 0 0 4px;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-box label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-box input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0 12px;
}

.login-message {
  min-height: 18px;
  margin: 0;
  color: var(--bad);
  font-size: 13px;
  line-height: 1.4;
}

.status-strip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.ok {
  background: var(--accent);
}

.dot.bad {
  background: var(--bad);
}

.live-panel {
  background: #121714;
  border-radius: 0;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(43, 39, 30, 0.16);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(64px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #eee9dd;
}

.segment {
  height: 38px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segment.active {
  background: var(--accent);
  color: #f7fff8;
  font-weight: 800;
}

.video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #121714;
  max-height: 72vh;
  min-height: 420px;
}

#liveVideo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #121714;
}

.feed-state {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: calc(100% - 28px);
  color: #f8f2e6;
  background: rgba(18, 23, 20, 0.72);
  border: 1px solid rgba(248, 242, 230, 0.18);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
}

.feed-state.hidden {
  display: none;
}

.camera-strip {
  margin-top: 10px;
  min-width: 0;
  overflow: hidden;
}

.camera-list {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-auto-rows: minmax(84px, auto);
  gap: 8px;
  overflow: hidden;
}

.text-button,
.camera-button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
}

.text-button {
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.text-button.primary {
  width: 100%;
  background: var(--blue);
  border-color: var(--blue);
  color: #f6fbff;
}

.text-button.quiet {
  color: var(--muted);
  background: #f7f4ec;
}

.camera-button {
  position: relative;
  min-width: 0;
  max-width: 100%;
  height: auto;
  min-height: 84px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  text-align: left;
  padding: 0;
  background: #121714;
  border-color: #2a302b;
}

.camera-button img {
  display: block;
  width: 100%;
  min-width: 0;
  height: 100%;
  object-fit: cover;
  opacity: 0.92;
}

.camera-button.active {
  border-color: var(--bad);
}

.camera-button.active::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 6px var(--bad);
  z-index: 2;
}

.camera-button.snapshot-error::after {
  content: "ไม่มีภาพ";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(248, 242, 230, 0.72);
  background: #202722;
  font-size: 12px;
  z-index: 1;
}

.controls-panel {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-bottom: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.control-row {
  display: flex;
  align-items: end;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: visible;
}

.toolband {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 8px;
  align-items: end;
}

.playback-form {
  display: grid;
  grid-template-columns: minmax(136px, 1fr) minmax(126px, 0.9fr) minmax(118px, 0.75fr) auto minmax(96px, auto);
  flex: 1 1 auto;
  align-items: end;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.playback-form label {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.playback-form label span {
  flex: 0 0 auto;
}

.playback-form input,
.playback-form select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0 10px;
}

.playback-form .text-button.primary {
  width: auto;
  min-width: 86px;
}

.toolbar-status {
  justify-content: center;
  min-width: 96px;
  max-width: 170px;
  padding: 0 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
}

.playback-result {
  min-height: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.playback-result:empty {
  display: none;
}

.playback-result img {
  display: block;
  width: 100%;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

@media (max-width: 900px) {
  .shell {
    width: 100%;
    max-width: 760px;
    padding-inline: 6px;
    padding-top: 6px;
  }

  .video-wrap {
    min-height: 220px;
  }

  .control-row {
    flex-wrap: wrap;
  }

  .playback-form {
    flex-basis: 100%;
  }
}

@media (max-width: 720px) {
  .camera-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .camera-button {
    min-height: 64px;
  }

}
