:root {
  --bg: #0c0e14;
  --bg-panel: #12151e;
  --bg-panel-raised: #171b26;
  --border: #232838;
  --text: #e8eaf0;
  --text-dim: #8890a4;
  --text-faint: #565f75;
  --accent: #ff4d5e;
  --accent-dim: #7a1f28;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --connecting: #60a5fa;
  --radius: 10px;
  --font-display: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 28px;
}

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

.brand-name {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 0.06em;
  font-size: 15px;
}
.brand-name strong { font-weight: 700; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-panel-raised); color: var(--text); }
.nav-item.active { background: var(--bg-panel-raised); color: var(--text); }
.nav-item.active svg { color: var(--accent); }

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.dot-ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot-err { background: var(--err); box-shadow: 0 0 6px var(--err); }
.dot-warn { background: var(--connecting); box-shadow: 0 0 6px var(--connecting); }
.dot-off { background: var(--text-faint); }

/* ---------- MAIN ---------- */
.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1100px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.view-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
  margin-right: 4px;
}
.btn-back:hover { color: var(--text); }

/* ---------- CARD / TABLE ---------- */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 16px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title-row .card-title { margin: 0; }

.table {
  width: 100%;
  border-collapse: collapse;
}
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 500;
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.015); }

.empty {
  color: var(--text-faint);
  text-align: center;
  padding: 30px 0 !important;
}

.evento-titulo-link {
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.evento-titulo-link:hover { color: var(--accent); }

.evento-meta { color: var(--text-faint); font-size: 12px; margin-top: 2px; }

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ---------- BADGES ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 100px;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.badge-parado { background: rgba(139,148,171,0.12); color: var(--text-dim); }
.badge-parado::before { background: var(--text-faint); }
.badge-agendado { background: rgba(139,148,171,0.12); color: var(--text-dim); }
.badge-agendado::before { background: var(--text-faint); }
.badge-conectando { background: rgba(96,165,250,0.12); color: var(--connecting); }
.badge-conectando::before { background: var(--connecting); animation: pulse 1s infinite; }
.badge-ao_vivo { background: rgba(52,211,153,0.12); color: var(--ok); }
.badge-ao_vivo::before { background: var(--ok); animation: pulse 1s infinite; }
.badge-erro { background: rgba(248,113,113,0.12); color: var(--err); }
.badge-erro::before { background: var(--err); }
.badge-aguardando_reconexao { background: rgba(251,191,36,0.12); color: var(--warn); }
.badge-aguardando_reconexao::before { background: var(--warn); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- BUTTONS ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
}
.btn:active { filter: brightness(0.9); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }

.btn-danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: rgba(248,113,113,0.08); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 14px; }

.btn-icon {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 38px;
  cursor: pointer;
  font-size: 15px;
}
.btn-icon:hover { color: var(--text); border-color: var(--text-faint); }

.btn-link-delete {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 12px;
}
.btn-link-delete:hover { color: var(--err); }

.btn-link-edit {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 12px;
}
.btn-link-edit:hover { color: var(--text); }

/* ---------- ESTUDIO ---------- */
.grid-estudio {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .grid-estudio { grid-template-columns: 1fr; }
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin: 16px 0 6px;
  font-weight: 500;
}
.field-label:first-of-type { margin-top: 0; }

.copy-field {
  display: flex;
  gap: 8px;
}
.copy-field input {
  flex: 1;
}

input[type="text"], input[type="password"], input[type="datetime-local"] {
  width: 100%;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  outline: none;
}
input:focus { border-color: var(--accent); }

.hint {
  font-size: 12px;
  color: var(--text-faint);
  margin: 6px 0 0;
}

.callout {
  margin-top: 20px;
  padding: 14px 16px;
  background: rgba(255,77,94,0.06);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.callout strong { color: var(--text); }

.destino-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}

.destino-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.destino-row .destino-nome {
  flex: 1;
  font-weight: 500;
  font-size: 13px;
}

.destino-row .destino-erro {
  font-size: 11px;
  color: var(--err);
  margin-top: 3px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-toggle {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  min-width: 84px;
}
.btn-toggle.start { background: rgba(52,211,153,0.12); color: var(--ok); border-color: rgba(52,211,153,0.3); }
.btn-toggle.start:hover { background: rgba(52,211,153,0.2); }
.btn-toggle.stop { background: rgba(248,113,113,0.12); color: var(--err); border-color: rgba(248,113,113,0.3); }
.btn-toggle.stop:hover { background: rgba(248,113,113,0.2); }
.btn-toggle:disabled { opacity: 0.5; cursor: wait; }

/* ---------- MODAL ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5,6,10,0.7);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
}
.modal h3 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.vincular-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.vincular-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.vincular-item button {
  font-size: 12px;
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: var(--err); color: var(--err); }
