:root {
  --bg: #ffffff;
  --text: #10233f;
  --muted: #5f7188;
  --line: #d7e5f5;
  --card: #f8fbff;
  --accent: #4b8ef8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 108px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: rgba(185, 220, 255, 0.55);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 96px;
  height: 96px;
  object-fit: contain;
}

.brand-text {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ── Main area ───────────────────────────────────────────────────────────── */
.main-area {
  flex: 1;
  padding: 18px 16px 28px;
}

/* ── Top panel row: upload (3/4) + stats (1/4) ───────────────────────────── */
.panel-row {
  display: flex;
  gap: 16px;
  align-items: stretch;
}

.upload-panel {
  flex: 3;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px 14px;
  min-width: 0;
}

.upload-panel h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  letter-spacing: 0.2px;
}

.subtext {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Stats panel (1/4) ───────────────────────────────────────────────────── */
.stats-panel {
  flex: 1;
  min-width: 160px;
  background: #f2f7fe;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-panel-title {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

/* ── Stat card ───────────────────────────────────────────────────────────── */
.sidebar-stat {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px 10px;
  transition: background 0.35s ease, border-color 0.35s ease;
}

.sidebar-stat.usage-ok {
  background: rgba(40, 200, 105, 0.08);
  border-color: #2ed07a;
}

.sidebar-stat.usage-high {
  background: rgba(220, 55, 55, 0.09);
  border-color: #e05252;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.stat-icon  { font-size: 0.85rem; color: var(--muted); line-height: 1; }
.stat-label { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); flex: 1; }
.stat-value { font-size: 0.88rem; font-weight: 700; color: var(--text); white-space: nowrap; }

/* ── Gauge bar ───────────────────────────────────────────────────────────── */
.gauge-track {
  width: 100%;
  height: 6px;
  background: #dde9f8;
  border-radius: 999px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4b8ef8, #79b8ff);
  transition: width 0.5s ease, background 0.35s ease;
}

.sidebar-stat.usage-ok   .gauge-fill { background: linear-gradient(90deg, #28c46a, #5ddf96); }
.sidebar-stat.usage-high .gauge-fill { background: linear-gradient(90deg, #e04040, #f07070); }

/* ── Controls row ────────────────────────────────────────────────────────── */
.controls-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

#uploadForm {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-width: 0;
}

#videoInput {
  width: 100%;
  border: 1px solid #cde1f7;
  background: #ffffff;
  border-radius: 10px;
  padding: 10px 12px;
  color: #304964;
  font-size: 0.93rem;
}

#videoInput::file-selector-button {
  border: none;
  background: #e6f1ff;
  color: #20529c;
  border-radius: 8px;
  padding: 7px 10px;
  margin-right: 10px;
  font-weight: 600;
  cursor: pointer;
}

#processBtn {
  border: 1px solid #3f7de4;
  background: linear-gradient(135deg, #3d82ff 0%, #5da7ff 100%);
  color: #fff;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.2px;
  box-shadow: 0 8px 18px rgba(76, 142, 248, 0.26);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

#processBtn:hover    { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(76,142,248,.32); }
#processBtn:disabled { opacity: 0.7; cursor: not-allowed; }

.status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── RTSP button ─────────────────────────────────────────────────────────── */
.btn-rtsp {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  border: 1px solid #1dbb6e;
  background: linear-gradient(135deg, #18a85e 0%, #2ed07a 100%);
  color: #fff;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.93rem;
  box-shadow: 0 8px 18px rgba(30, 185, 105, 0.26);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-rtsp:hover    { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(30,185,105,.32); }
.btn-rtsp:disabled { opacity: 0.6; cursor: not-allowed; }

.rtsp-btn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
}

.btn-rtsp.live .rtsp-btn-dot { animation: pulse-dot 1.1s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.7); }
}

/* ── Disconnect button ───────────────────────────────────────────────────── */
.btn-disconnect {
  margin-top: 8px;
  border: 1px solid #e05252;
  background: linear-gradient(135deg, #d94040 0%, #f06060 100%);
  color: #fff;
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: 0 5px 14px rgba(220, 60, 60, 0.2);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.btn-disconnect:hover { transform: translateY(-1px); box-shadow: 0 9px 18px rgba(220,60,60,.28); }

/* ── Video section ───────────────────────────────────────────────────────── */
.videos {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.video-card {
  background: #fff;
  border: 0.5px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.video-card h2 { margin: 0 0 10px; font-size: 1rem; }

video {
  width: 100%;
  min-height: 420px;
  background: #0c1726;
  border-radius: 10px;
  border: 1px solid #bfd7f4;
}

/* Wrapper positions the transparent overlay exactly over the video. */
.input-video-wrap {
  position: relative;
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
}

/* No pointer events on the video itself: Chrome's hover-controls overlay only
   triggers when the mouse hovers the <video> element. With pointer-events:none
   the video never receives hover/click, so the overlay never appears.
   All interaction is handled through #inputVideoOverlay instead. */
#inputVideo {
  pointer-events: none;
}

/* Transparent overlay captures clicks and cursor, forwarded to video by JS. */
.input-video-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: pointer;
  background: transparent;
}

.stream-img {
  width: 100%;
  min-height: 420px;
  background: #0c1726;
  border-radius: 10px;
  border: 1px solid #bfd7f4;
  object-fit: contain;
  display: block;
}

.output-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 420px;
  background: #0c1726;
  border-radius: 10px;
  border: 1px solid #bfd7f4;
  color: #5a8ab8;
  font-size: 0.95rem;
  text-align: center;
}

/* ── LIVE badge ──────────────────────────────────────────────────────────── */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #e53535;
  color: #fff;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  padding: 2px 7px;
  border-radius: 5px;
  vertical-align: middle;
  margin-left: 7px;
  animation: badge-pulse 1.4s ease-in-out infinite;
}

.live-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: pulse-dot 1.1s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.75; }
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(8, 20, 38, 0.62);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px 36px 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 60px rgba(10, 30, 70, 0.22);
  animation: modal-in 0.18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-box h2  { margin: 0 0 6px; font-size: 1.4rem; }
.modal-sub     { margin: 0 0 20px; color: var(--muted); font-size: 0.93rem; }
.modal-label   { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.3px; }

.modal-input {
  width: 100%;
  border: 1.5px solid #cde1f7;
  background: #f8fbff;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 0.97rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s;
}
.modal-input:focus { border-color: var(--accent); }

.modal-status       { margin: 10px 0 0; font-size: 0.88rem; color: var(--muted); min-height: 1.3em; }
.modal-status.error { color: #d94040; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.btn-modal-connect {
  flex: 1;
  border: 1px solid #3f7de4;
  background: linear-gradient(135deg, #3d82ff 0%, #5da7ff 100%);
  color: #fff;
  border-radius: 10px;
  padding: 11px 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.97rem;
  box-shadow: 0 8px 18px rgba(76,142,248,.26);
  transition: transform 0.18s, box-shadow 0.18s;
}
.btn-modal-connect:hover    { transform: translateY(-1px); box-shadow: 0 12px 22px rgba(76,142,248,.32); }
.btn-modal-connect:disabled { opacity: 0.65; cursor: not-allowed; }

.btn-modal-cancel {
  flex: 1;
  border: 1.5px solid var(--line);
  background: #f4f8fe;
  color: var(--muted);
  border-radius: 10px;
  padding: 11px 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.97rem;
  transition: background 0.18s;
}
.btn-modal-cancel:hover { background: #e8f1fb; }

/* ── Output video player ─────────────────────────────────────────────────── */
#outputVideo {
  width: 100%;
  min-height: 420px;
  background: #0c1726;
  border-radius: 10px;
  border: 1px solid #bfd7f4;
  display: block;
  pointer-events: none;
}

.output-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.oc-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.oc-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #c0d8f4;
  background: #edf4ff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.18s, transform 0.15s;
}

.oc-btn:hover { background: #d8eaff; transform: translateY(-1px); }

.oc-play {
  border-color: #3f7de4;
  background: linear-gradient(135deg, #3d82ff 0%, #5da7ff 100%);
  color: #fff;
  box-shadow: 0 6px 16px rgba(76, 142, 248, 0.24);
}

.oc-play:hover { background: linear-gradient(135deg, #2d72ef 0%, #4d97ef 100%); }

.oc-download {
  border-color: #1dbb6e;
  background: linear-gradient(135deg, #18a85e 0%, #2ed07a 100%);
  color: #fff;
  box-shadow: 0 6px 16px rgba(30, 185, 105, 0.22);
}

.oc-download:hover { background: linear-gradient(135deg, #0e9850 0%, #22c06a 100%); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .panel-row { flex-direction: column; }
  .stats-panel { flex-direction: row; flex-wrap: wrap; gap: 10px; }
  .sidebar-stat { flex: 1; min-width: 120px; }
  #uploadForm { grid-template-columns: 1fr; }
  .controls-row { flex-direction: column; align-items: stretch; }
  .btn-rtsp { justify-content: center; }
  .videos { grid-template-columns: 1fr; }
  video, .stream-img, .output-placeholder, #outputVideo { min-height: 280px; }
  .output-controls { flex-direction: column; align-items: stretch; }
  .oc-buttons { justify-content: center; }
  .oc-download { text-align: center; justify-content: center; }
  .modal-box { margin: 16px; padding: 24px 20px 20px; }
}
