:root {
  --bg: #0b1220;
  --bg-card: #121c2e;
  --bg-elev: #19253b;
  --border: #263653;
  --text: #e6edf7;
  --muted: #93a4c3;
  --accent: #0f9f7f;
  --accent-hover: #13b893;
  --amber: #e2a438;
  --danger: #e05252;
  --info: #4b9ce2;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Noto Sans Thai', sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent-hover);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}

.tab-btn.active {
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #22314d;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #061813;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-danger {
  background: rgba(224, 82, 82, 0.15);
  border-color: rgba(224, 82, 82, 0.5);
  color: #ff9a9a;
}

.btn-amber {
  background: rgba(226, 164, 56, 0.16);
  border-color: rgba(226, 164, 56, 0.5);
  color: #ffd384;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

.badge-online {
  background: rgba(15, 159, 127, 0.18);
  border-color: rgba(15, 159, 127, 0.5);
  color: #66f0cb;
}

.badge-offline {
  background: rgba(147, 164, 195, 0.14);
  border-color: rgba(147, 164, 195, 0.35);
  color: var(--muted);
}

.badge-warn {
  background: rgba(226, 164, 56, 0.18);
  border-color: rgba(226, 164, 56, 0.5);
  color: #ffd384;
}

.badge-danger {
  background: rgba(224, 82, 82, 0.18);
  border-color: rgba(224, 82, 82, 0.5);
  color: #ff9a9a;
}

.cam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
}

.cam-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cam-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.cam-title {
  font-weight: 700;
  font-size: 1.02rem;
}

.video-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05080f;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.video-shell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(5, 8, 15, 0.72);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 12px;
}

.telemetry-row,
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field-group label {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.input {
  background: #0d1525;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  width: 100%;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
}

.playback-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
}

@media (max-width: 920px) {
  .playback-layout {
    grid-template-columns: 1fr;
  }
}

.clip-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 520px;
  overflow-y: auto;
}

.clip-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.clip-item.active {
  border-color: var(--accent);
}

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.alert-danger {
  border-color: rgba(224, 82, 82, 0.55);
  background: rgba(224, 82, 82, 0.14);
  color: #ffb1b1;
}

.alert-success {
  border-color: rgba(15, 159, 127, 0.55);
  background: rgba(15, 159, 127, 0.14);
  color: #84f5d7;
}

.code-box {
  background: #060b14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  color: #b9d7ff;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 540px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.muted {
  color: var(--muted);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
