:root {
  --bg: #0b0e14;
  --bg2: #0f131c;
  --surface: #151a26;
  --surface2: #1b2130;
  --border: #262d3d;
  --border2: #313a4e;
  --text: #eef2f8;
  --muted: #93a0b5;
  --faint: #66718a;
  --accent: #7c6cff;
  --accent2: #9a8dff;
  --accent-glow: rgba(124, 108, 255, .35);
  --green: #2fd07a;
  --yellow: #ffb547;
  --red: #ff5c5c;
  --r: 14px;
  --r-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2036 0%, var(--bg) 55%);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 24px; }
.brand-mark {
  font-size: 22px; color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; color: var(--muted);
  padding: 11px 14px; border-radius: var(--r-sm); cursor: pointer;
  font-size: 14px; font-weight: 500; font-family: inherit; text-align: left;
  transition: all .15s;
}
.nav-item svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, var(--accent), #6455e0);
  color: #fff; box-shadow: 0 6px 18px var(--accent-glow);
}
.sidebar-foot { margin-top: auto; padding: 8px; }
.db-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--faint); }

/* ---------- CONTENT ---------- */
.content { flex: 1; padding: 34px 40px 80px; max-width: 1000px; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 26px; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 12px; }
.sub { color: var(--muted); margin-top: 4px; }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin: 22px 0 12px; }
.section-label.mt { margin-top: 38px; }

/* ---------- FORM / PUBLICAR ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.dropzone {
  border: 2px dashed var(--border2); border-radius: var(--r);
  background: var(--surface); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-height: 220px; transition: all .18s; text-align: center;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--surface2); }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px; }
.dz-icon { width: 40px; height: 40px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 6px; }
.dz-inner strong { font-size: 15px; }
.dz-inner span { color: var(--muted); font-size: 13px; }
.dz-inner em { color: var(--green); font-style: normal; font-weight: 600; margin-top: 6px; word-break: break-all; }

.fields { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }

input, textarea, select {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); padding: 11px 13px; border-radius: var(--r-sm);
  font-size: 14px; font-family: inherit; width: 100%; transition: border .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
textarea { resize: vertical; }

/* ---------- BOTOES ---------- */
.btn {
  border: none; border-radius: var(--r-sm); padding: 10px 18px;
  font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
  color: #fff; background: var(--surface2); transition: all .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #6455e0); box-shadow: 0 6px 18px var(--accent-glow); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: linear-gradient(135deg, #ff5c5c, #e04545); }
.btn-ghost { background: transparent; border: 1px solid var(--border2); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn-lg { padding: 14px 26px; font-size: 15px; width: 100%; margin-top: 22px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- TARGET GRID (chips de plataforma) ---------- */
.target-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.target {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); cursor: pointer; transition: all .15s; user-select: none;
}
.target:hover { border-color: var(--border2); }
.target.on { border-color: var(--accent); background: var(--surface2); box-shadow: 0 0 0 3px var(--accent-glow); }
.target.disabled { opacity: .4; cursor: not-allowed; }
.target .pf-icon { width: 26px; height: 26px; flex-shrink: 0; }
.target .t-name { font-weight: 600; font-size: 13.5px; }
.target .t-sub { font-size: 11px; color: var(--faint); }
.target .check { margin-left: auto; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border2); flex-shrink: 0; display: grid; place-items: center; }
.target.on .check { background: var(--accent); border-color: var(--accent); }
.target.on .check::after { content: '✓'; font-size: 11px; color: #fff; }

/* ---------- PLATFORM CARDS (conexoes) ---------- */
.platform-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.pf-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 20px; position: relative; overflow: hidden;
  transition: border .15s, transform .15s;
}
.pf-card:hover { transform: translateY(-2px); border-color: var(--border2); }
.pf-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--pf-color, var(--accent)); opacity: .9; }
.pf-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.pf-icon { width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center; }
.pf-icon svg { width: 100%; height: 100%; }
.pf-meta { flex: 1; }
.pf-name { font-weight: 700; font-size: 15.5px; }
.pf-kind { font-size: 11.5px; color: var(--faint); }
.pf-status { display: flex; align-items: center; gap: 7px; font-size: 12.5px; margin-bottom: 14px; }
.pf-note { font-size: 12px; color: var(--muted); margin-bottom: 16px; min-height: 32px; line-height: 1.5; }
.pf-actions { display: flex; gap: 8px; }
.pf-actions .btn { padding: 9px 14px; font-size: 13px; flex: 1; }

.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.pill-ok { background: rgba(47,208,122,.16); color: var(--green); }
.pill-warn { background: rgba(255,181,71,.16); color: var(--yellow); }
.pill-soon { background: rgba(124,108,255,.16); color: var(--accent2); font-weight: 600; }
.pill-off { background: rgba(255,92,92,.14); color: var(--red); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.dot.green { background: var(--green); box-shadow: 0 0 8px rgba(47,208,122,.6); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

/* ---------- CARD / LIVE ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 22px; }
.ingest { display: block; background: var(--bg2); padding: 13px 15px; border-radius: var(--r-sm); border: 1px solid var(--border); color: var(--accent2); font-size: 13.5px; font-family: 'SF Mono', Consolas, monospace; }
.ingest b { color: var(--text); }
.live-actions { display: flex; gap: 10px; margin-top: 18px; }
.live-state { font-size: 13px; font-weight: 700; color: var(--faint); padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.live-state.on { color: var(--red); border-color: var(--red); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255,92,92,.18); } }
.logs { background: #070a10; border: 1px solid var(--border); border-radius: var(--r-sm); padding: 15px; font-size: 12px; font-family: 'SF Mono', Consolas, monospace; color: var(--muted); max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------- JOBS ---------- */
.jobs { display: grid; gap: 12px; }
.job { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 20px; }
.job-title { font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job-title .when { font-weight: 400; color: var(--faint); font-size: 12.5px; }
.job-tgt { display: flex; align-items: center; gap: 10px; font-size: 13px; padding: 4px 0; }
.job-tgt .pf-icon { width: 20px; height: 20px; }
.status-tag { font-size: 11px; padding: 3px 9px; border-radius: 6px; font-weight: 700; }
.status-tag.pendente, .status-tag.enviando { background: rgba(255,181,71,.16); color: var(--yellow); }
.status-tag.publicado { background: rgba(47,208,122,.16); color: var(--green); }
.status-tag.erro { background: rgba(255,92,92,.16); color: var(--red); }
.empty { color: var(--faint); font-size: 13.5px; padding: 8px 0; }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- MODAL ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,6,11,.72); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; animation: fade .2s; }
.modal {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 18px; padding: 28px; width: 100%; max-width: 460px;
  box-shadow: var(--shadow); position: relative;
}
.modal-close { position: absolute; top: 16px; right: 18px; background: none; border: none; color: var(--faint); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.modal-head .pf-icon { width: 34px; height: 34px; }
.modal-head h2 { font-size: 19px; font-weight: 700; }
.modal-guide { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 8px 0 16px; }
.modal-redirect { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px; margin-bottom: 16px; }
.modal-redirect > span { font-size: 11.5px; color: var(--faint); display: block; margin-bottom: 8px; }
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code { flex: 1; font-size: 12px; color: var(--accent2); font-family: 'SF Mono', Consolas, monospace; word-break: break-all; }
.copy-row .btn { padding: 6px 12px; font-size: 12px; }
#modalFields { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.modal-docs { display: inline-block; font-size: 13px; margin: 6px 0 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- TOASTS ---------- */
.toasts { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--surface2); border: 1px solid var(--border2); border-left: 3px solid var(--accent);
  padding: 13px 18px; border-radius: var(--r-sm); font-size: 13.5px; box-shadow: var(--shadow);
  min-width: 240px; max-width: 340px; animation: slideIn .25s;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }

/* ========================================================================
   MOBILE — barra lateral vira navegação inferior, layouts em coluna
   ======================================================================== */
@media (max-width: 820px) {
  body { overflow-x: hidden; }
  .app { display: block; }

  /* Mini cabeçalho fixo no topo com a marca */
  .content::before {
    content: '◉ MultiStream';
    display: flex; align-items: center;
    position: sticky; top: 0; z-index: 40;
    margin: -20px -16px 12px; padding: 14px 18px;
    background: rgba(11,14,20,.85); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    font-weight: 800; font-size: 16px; color: var(--accent);
    letter-spacing: -.01em;
  }

  /* Sidebar -> barra inferior */
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    width: 100%; height: 64px;
    flex-direction: row; align-items: stretch;
    padding: 0; border-right: none; border-top: 1px solid var(--border);
    background: var(--bg2); z-index: 60;
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; gap: 0; }
  .nav-item {
    flex: 1; flex-direction: column; gap: 3px;
    justify-content: center; align-items: center;
    padding: 8px 4px; border-radius: 0; font-size: 11px; font-weight: 600;
  }
  .nav-item svg { width: 23px; height: 23px; }
  .nav-item.active { background: transparent; color: var(--accent); box-shadow: none; }

  /* Conteúdo */
  .content { padding: 20px 16px 88px; max-width: 100%; }
  .view-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  h1 { font-size: 22px; }

  /* Layouts em coluna */
  .grid-2 { grid-template-columns: 1fr; gap: 14px; }
  .field-row { flex-direction: column; gap: 14px; }
  .platform-grid { grid-template-columns: 1fr; }
  .target-grid { grid-template-columns: 1fr 1fr; }
  .dropzone { min-height: 150px; }
  .btn-lg { margin-top: 18px; }

  /* Ao vivo */
  .live-actions { flex-direction: column; }
  .live-actions .btn { width: 100%; }
  .ingest { font-size: 12px; }

  /* Modal ocupa a largura */
  .modal { padding: 22px 18px; border-radius: 16px; }
  .copy-row { flex-direction: column; align-items: stretch; }
  .copy-row .btn { width: 100%; }

  /* Toasts acima da barra inferior, largura total */
  .toasts { left: 12px; right: 12px; bottom: 78px; }
  .toast { min-width: 0; max-width: none; }
}

/* Telas bem estreitas: chips de plataforma em 1 coluna */
@media (max-width: 380px) {
  .target-grid { grid-template-columns: 1fr; }
}
