/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #080d16;
  --surface:     #0e1624;
  --surface-2:   #131e2e;
  --surface-3:   #1a2740;
  --border:      #1e3050;
  --border-2:    #263a5a;
  --text:        #e2eaf6;
  --text-2:      #c8d8ef;
  --muted:       #5a7799;
  --green:       #10b981;
  --green-glow:  rgba(16,185,129,.35);
  --red:         #f43f5e;
  --blue:        #3b82f6;
  --blue-dim:    #2563eb;
  --blue-glow:   rgba(59,130,246,.3);
  --amber:       #f59e0b;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --shadow-panel: 0 24px 60px rgba(0,0,0,.7);
}

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  height: 52px;
  background: rgba(8,13,22,.85);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: flex; align-items: center; gap: 10px;
}
.brand-icon {
  width: 22px; height: 22px; color: var(--blue);
  flex-shrink: 0;
}
.brand-name {
  font-size: 15px; font-weight: 700; letter-spacing: -.02em;
  color: var(--text);
}

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

.agents-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.25);
  border-radius: 99px;
  font-size: 12px; font-weight: 500; color: var(--green);
}
.agents-badge[hidden] { display: none !important; }
.badge-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  animation: pulse-green 2s ease-in-out infinite;
}
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 var(--green-glow); }
  50%       { box-shadow: 0 0 0 4px transparent; }
}

.server-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px; color: var(--muted); font-family: monospace;
}
.server-live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
}

/* ── Grid ────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
  padding: 24px;
  align-content: start;
  min-height: calc(100vh - 52px);
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  min-height: 340px;
  color: var(--muted);
  text-align: center;
  user-select: none;
}
.empty-icon {
  width: 80px; height: 80px;
  opacity: .35;
}
.empty-title {
  font-size: 15px; font-weight: 600; color: var(--text-2); margin-top: 4px;
}
.empty-sub {
  font-size: 13px; color: var(--muted); max-width: 280px;
}

/* ── Monitor card ────────────────────────────────────────── */
.monitor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex; flex-direction: column;
  cursor: pointer;
  transition: border-color .2s ease, box-shadow .2s ease, transform .15s ease;
}
.monitor-card:hover {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue), var(--shadow-panel);
  transform: translateY(-2px);
}
.monitor-card:active { transform: translateY(0); }

.card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.card-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 var(--green-glow);
  animation: pulse-green 2.5s ease-in-out infinite;
  flex-shrink: 0;
  transition: background .3s;
}
.card-dot.offline {
  background: var(--red);
  box-shadow: none;
  animation: none;
}

.card-id {
  flex: 1;
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-fps {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 46px; text-align: right;
}
.btn-tl {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  flex-shrink: 0;
}
.btn-tl svg { width: 13px; height: 13px; }
.btn-tl:hover { border-color: var(--blue); color: var(--text); background: rgba(59,130,246,.08); }

.card-screen-wrap {
  position: relative;
  width: 100%; aspect-ratio: 16/9;
  background: #000;
  overflow: hidden;
}
.card-screen {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .3s;
}
/* Overlay on hover */
.card-screen-wrap::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 50%, rgba(0,0,0,.55));
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.monitor-card:hover .card-screen-wrap::after { opacity: 1; }

/* ── Backdrop ────────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4,8,16,.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in .18s ease;
}
.backdrop[hidden] { display: none !important; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ── Panel (base para todos os modais) ───────────────────── */
.panel {
  position: fixed; z-index: 100;
  inset: 36px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-panel);
  animation: slide-up .2s ease;
}
.panel[hidden] { display: none !important; }

/* ── Panel header (shared) ───────────────────────────────── */
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
  min-height: 48px;
}
.panel-title-row {
  display: flex; align-items: center; gap: 8px;
  overflow: hidden;
  flex: 1;
}
.panel-title {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  animation: pulse-green 2.5s ease-in-out infinite;
  flex-shrink: 0;
}
.panel-btns {
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
}

/* ── Icon buttons ────────────────────────────────────────── */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
  flex-shrink: 0;
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { border-color: var(--border-2); color: var(--text); background: var(--surface-3); }

.icon-sm  { width: 15px; height: 15px; flex-shrink: 0; }
.icon-xs  { width: 12px; height: 12px; flex-shrink: 0; }
.muted    { color: var(--muted); }

/* ── FPS badge ───────────────────────────────────────────── */
.fps-badge {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding: 2px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  white-space: nowrap;
}

/* ── Panel body (live viewer) ────────────────────────────── */
.panel-body {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #000; overflow: hidden;
}
.panel-body img {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
}

/* ── Accent button ───────────────────────────────────────── */
.btn-accent {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--blue);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.btn-accent svg { width: 14px; height: 14px; }
.btn-accent:hover  { background: var(--blue-dim); }
.btn-accent:active { background: #1d4ed8; }
.btn-accent:disabled { opacity: .4; cursor: not-allowed; }

/* ── Select wrap ─────────────────────────────────────────── */
.select-wrap {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px;
  height: 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.select-wrap select {
  background: transparent; border: none;
  color: var(--text); font-size: 12px;
  cursor: pointer; outline: none;
  font-family: inherit;
}

/* ── Timeline panel ──────────────────────────────────────── */
.tl-panel { inset: 28px; }

.tl-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  align-content: start;
}

.tl-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.tl-item:hover {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue-glow);
  transform: translateY(-1px);
}
.tl-item--active {
  border-color: var(--blue) !important;
  box-shadow: 0 0 0 2px var(--blue-glow) !important;
}

.tl-thumb {
  width: 100%; aspect-ratio: 16/9;
  object-fit: cover; display: block;
  background: #000;
}
.tl-ts {
  display: block;
  padding: 5px 8px;
  font-size: 11px; font-family: monospace;
  color: var(--muted); text-align: center;
}
.tl-empty {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: center;
  padding: 60px 0;
  color: var(--muted);
  font-size: 13px;
}

/* ── Player panel ────────────────────────────────────────── */
.player-panel { inset: 20px; z-index: 101; }

.player-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #000; overflow: hidden;
}
.player-screen img {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
}

.player-controls {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
  background: var(--surface-2);
}

.ctrl-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.ctrl-btn svg { width: 16px; height: 16px; }
.ctrl-btn:hover { border-color: var(--border-2); background: var(--surface); }

.ctrl-btn--primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  width: 38px; height: 38px;
}
.ctrl-btn--primary:hover { background: var(--blue-dim); border-color: var(--blue-dim); }
.ctrl-btn--primary svg  { width: 18px; height: 18px; }

.scrubber-track {
  flex: 1; min-width: 100px;
  display: flex; align-items: center;
}
#player-scrubber {
  width: 100%;
  height: 4px;
  accent-color: var(--blue);
  cursor: pointer;
  border-radius: 99px;
}

.player-counter {
  font-size: 12px; color: var(--muted);
  font-family: monospace; white-space: nowrap;
  min-width: 58px; text-align: center;
}

.speed-select-wrap {
  display: flex; align-items: center; gap: 5px;
  padding: 0 8px; height: 30px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  flex-shrink: 0;
}
.speed-select-wrap select {
  background: transparent; border: none;
  color: var(--text); font-size: 12px;
  cursor: pointer; outline: none;
  font-family: inherit;
}

/* ── Login overlay (gerado pelo JS) ──────────────────────── */
#login-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  background-image: radial-gradient(ellipse at 60% 40%, rgba(59,130,246,.06) 0%, transparent 60%);
}
#login-overlay[hidden] { display: none !important; }

.login-box {
  width: 360px;
  padding: 36px 32px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-panel);
  animation: slide-up .25s ease;
}

.login-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 4px;
}
.login-logo svg {
  width: 28px; height: 28px; color: var(--blue);
}
.login-logo-name {
  font-size: 20px; font-weight: 700; letter-spacing: -.02em;
}

.login-box h2 {
  font-size: 15px; font-weight: 600; text-align: center;
  color: var(--text); margin-bottom: -4px;
}
.login-box > p {
  font-size: 13px; color: var(--muted); text-align: center;
}

.login-field {
  display: flex; flex-direction: column; gap: 6px;
}
.login-field label {
  font-size: 12px; font-weight: 500; color: var(--muted);
}
.login-box input[type="password"] {
  width: 100%; padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text); font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.login-box input[type="password"]:focus { border-color: var(--blue); }
.login-box input[type="password"]::placeholder { color: var(--muted); opacity: .6; }

.login-box button[id="token-submit"] {
  width: 100%; padding: 11px;
  background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: background .15s;
}
.login-box button[id="token-submit"]:hover { background: var(--blue-dim); }

.token-error {
  font-size: 12px; color: var(--red) !important;
  text-align: center; font-weight: 500;
}
