/* =====================================================================
   VARIÁVEIS E RESET
   ===================================================================== */
:root {
  --bg:#0b1220; --panel:#101a33; --panel2:#0f1a30; --stroke:rgba(255,255,255,.12);
  --text:#e8f0ff; --muted:#90a4c7;
  --ok:#3ddc97; --bad:#ff5c7a; --warn:#ffd166;
  --btn:#142149; --btn2:#1a2a5a; --shadow:0 18px 60px rgba(0,0,0,.45); --r:16px;
  --header-h: 60px;
}
.light {
  --bg:#f5f7fb; --panel:#fff; --panel2:#fff; --stroke:rgba(0,0,0,.10);
  --text:#0b1220; --muted:#4b5f86; --btn:#e9eef8; --btn2:#dfe8fb; --shadow:0 18px 60px rgba(10,20,60,.12);
}
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }

body {
  margin: 0;
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 20% 0%, rgba(61,220,151,.10), transparent 60%),
    radial-gradient(900px 500px at 95% 20%, rgba(255,209,102,.10), transparent 55%),
    var(--bg);
  min-height: 100%;
}

/* =====================================================================
   HEADER
   ===================================================================== */
header {
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(10px);
  background: linear-gradient(to bottom, rgba(0,0,0,.40), rgba(0,0,0,0));
  border-bottom: 1px solid var(--stroke);
}
.wrap { max-width: 1340px; margin: 0 auto; padding: 0 16px; }
.top {
  display: flex; gap: 10px; align-items: center;
  justify-content: space-between; flex-wrap: nowrap;
  min-height: var(--header-h); padding: 8px 0;
}
.brand { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.logo { height: 36px; width: auto; display: block; filter: drop-shadow(0 0 10px rgba(0,224,255,.20)); }
h1 { margin: 0; font-size: 15px; line-height: 1.2; }
.sub { color: var(--muted); font-size: 11px; margin-top: 2px; display: none; }

/* HAMBÚRGUER */
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

/* ACTIONS */
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input[type="file"] { display: none; }

/* =====================================================================
   BOTÕES
   ===================================================================== */
.btn {
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, var(--btn2), var(--btn));
  color: var(--text); padding: 8px 12px; border-radius: 10px;
  cursor: pointer; font-weight: 800; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); white-space: nowrap; transition: opacity .15s;
}
.btn.ghost { background: transparent; box-shadow: none; }
.btn:active { opacity: .7; }
.sep { width: 1px; height: 22px; background: rgba(255,255,255,.12); margin: 0 2px; }
.initctl {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px; background: rgba(10,16,26,.35);
}
.initctl span { font-size: 12px; opacity: .85; white-space: nowrap; }
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding: 6px 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06); color: inherit; outline: none; font-size: 12px;
}
.select:focus { border-color: rgba(25,211,255,.55); box-shadow: 0 0 0 3px rgba(25,211,255,.15); }

/* =====================================================================
   GRID PRINCIPAL
   ===================================================================== */
main { padding: 12px 16px 24px; max-width: 1340px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: 1.85fr .75fr; gap: 14px; align-items: start; }

/* =====================================================================
   CARDS
   ===================================================================== */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,0)), var(--panel);
  border: 1px solid var(--stroke); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden;
}
.hd { padding: 12px 14px; border-bottom: 1px solid var(--stroke); display: flex; justify-content: space-between; gap: 10px; align-items: flex-end; }
.hd h2 { margin: 0; font-size: 14px; }
.hd p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.bd { padding: 12px 14px; }

/* =====================================================================
   EDITOR
   ===================================================================== */
.editor {
  position: relative; height: 580px;
  border: 1px dashed var(--stroke); border-radius: 14px;
  background: rgba(0,0,0,.08); overflow: auto;
  touch-action: pan-x pan-y;
}
.light .editor { background: rgba(10,20,60,.05); }
.editor::-webkit-scrollbar { height: 8px; width: 8px; }
.editor::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 10px; }
.editor::-webkit-scrollbar-track { background: rgba(0,0,0,.10); }

.gridbg {
  position: absolute; inset: 0;
  background-image: linear-gradient(to right, rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 24px 24px; opacity: .35; pointer-events: none;
}
.light .gridbg {
  background-image: linear-gradient(to right, rgba(0,0,0,.07) 1px, transparent 1px), linear-gradient(to bottom, rgba(0,0,0,.07) 1px, transparent 1px);
  opacity: .22;
}
svg.wires { position: absolute; inset: 0; pointer-events: none; }

/* =====================================================================
   NODES
   ===================================================================== */
.node {
  position: absolute; width: 260px;
  border: 1px solid var(--stroke); border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,0));
  box-shadow: 0 16px 48px rgba(0,0,0,.25); user-select: none;
}
.node.small { width: 170px; }
.node .title {
  padding: 9px 12px; border-bottom: 1px solid var(--stroke);
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; cursor: grab; font-weight: 900; font-size: 14px;
}
.node .title:active { cursor: grabbing; }
.node .body { padding: 10px 12px; display: flex; flex-direction: column; gap: 9px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tag { font-size: 12px; color: var(--muted); }
select {
  background: rgba(0,0,0,.10); color: var(--text); border: 1px solid var(--stroke);
  border-radius: 10px; padding: 6px 9px; outline: none; font-weight: 800; font-size: 13px;
}
.light select { background: rgba(10,20,60,.05); }
.ports { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.portcol { display: flex; flex-direction: column; gap: 9px; }
.port { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot {
  width: 14px; height: 14px; border-radius: 99px;
  border: 1px solid var(--stroke); background: rgba(255,255,255,.08);
  cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0,0,0,.15); flex-shrink: 0;
}
.dot.out { background: rgba(61,220,151,.18); }
.dot.in  { background: rgba(255,209,102,.14); }
.dot.selected { outline: 2px solid rgba(255,209,102,.70); outline-offset: 2px; }
.chip {
  min-width: 42px; text-align: center; padding: 5px 9px; border-radius: 10px;
  border: 1px solid var(--stroke); font-weight: 900; letter-spacing: .5px;
  background: rgba(0,0,0,.10); font-size: 13px;
}
.chip.ok  { background: rgba(61,220,151,.16); }
.chip.bad { background: rgba(255,92,122,.16); }
.mini-actions { display: flex; gap: 8px; }
.iconbtn {
  border: 1px solid var(--stroke); background: rgba(0,0,0,.10); color: var(--text);
  padding: 6px 10px; border-radius: 10px; cursor: pointer; font-weight: 900; font-size: 12px;
}
.light .iconbtn { background: rgba(10,20,60,.05); }

/* =====================================================================
   PAINEL DE SIMULAÇÃO
   ===================================================================== */
.inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.inbox {
  border: 1px solid var(--stroke); border-radius: 12px; padding: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,0));
}
.label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.label b { font-size: 14px; }
.label span { font-size: 11px; color: var(--muted); }
.toggle { display: flex; border: 1px solid var(--stroke); border-radius: 10px; overflow: hidden; }
.toggle button {
  flex: 1; padding: 9px 0; border: 0; background: transparent;
  color: var(--text); cursor: pointer; font-weight: 900; font-size: 14px;
}
.toggle button.active { background: linear-gradient(135deg, rgba(61,220,151,.20), rgba(255,209,102,.12)); }
.final {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px; border-radius: 14px;
  border: 1px solid rgba(61,220,151,.35);
  background: linear-gradient(135deg, rgba(61,220,151,.18), rgba(255,209,102,.10)); margin-top: 10px;
}
.final .out {
  font-size: 18px; font-weight: 900; letter-spacing: 1px;
  padding: 7px 12px; border-radius: 12px; border: 1px solid var(--stroke);
  background: rgba(0,0,0,.12); min-width: 52px; text-align: center;
}
.expr {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--stroke); color: var(--muted); font-size: 12px;
  line-height: 1.5; background: rgba(0,0,0,.08);
}
.msg {
  margin-top: 10px; padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--stroke); background: rgba(0,0,0,.08);
  color: var(--muted); font-size: 12px; line-height: 1.5;
}
.msg.ok   { border-color: rgba(61,220,151,.35);  color: var(--text); background: rgba(61,220,151,.10); }
.msg.warn { border-color: rgba(255,209,102,.35); color: var(--text); background: rgba(255,209,102,.10); }
.msg.bad  { border-color: rgba(255,92,122,.35);  color: var(--text); background: rgba(255,92,122,.10); }
table { width: 100%; border-collapse: collapse; border: 1px solid var(--stroke); border-radius: 12px; overflow: hidden; }
th, td { padding: 8px 7px; border-bottom: 1px solid var(--stroke); text-align: center; font-size: 12px; }
th { font-size: 11px; color: var(--muted); background: rgba(0,0,0,.10); position: sticky; top: 0; }
.tblwrap { max-height: 320px; overflow: auto; border-radius: 12px; border: 1px solid var(--stroke); display: none; margin-top: 10px; }
.note { margin-top: 8px; color: var(--muted); font-size: 12px; }
.help {
  margin-top: 10px; font-size: 12px; color: var(--muted);
  border: 1px dashed var(--stroke); border-radius: 12px;
  padding: 12px; background: rgba(0,0,0,.06); line-height: 1.5;
}

/* =====================================================================
   TABLET (≤ 1100px)
   ===================================================================== */
@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; }
  .editor { height: 440px; }
  .sub { display: block; }
}

/* =====================================================================
   MOBILE (≤ 700px)
   ===================================================================== */
@media (max-width: 700px) {
  :root { --header-h: 54px; }
  h1 { font-size: 13px; }
  .logo { height: 28px; }
  .sub { font-size: 10px; }

  /* Hambúrguer aparece */
  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  /* Drawer vertical */
  .actions {
    display: none;
    position: absolute;
    top: var(--header-h); left: 0; right: 0;
    flex-direction: column; align-items: stretch;
    background: var(--panel);
    border-bottom: 1px solid var(--stroke);
    padding: 12px 16px; gap: 8px; z-index: 99;
    box-shadow: 0 12px 40px rgba(0,0,0,.30);
  }
  .actions.open { display: flex; }
  .actions .btn { width: 100%; text-align: center; }
  .actions .sep { width: 100%; height: 1px; background: var(--stroke); margin: 2px 0; }
  .initctl { width: 100%; justify-content: space-between; }
  .select { flex: 1; }

  /* Editor */
  .editor { height: 320px; }

  /* Inputs 2×2 */
  .inputs { grid-template-columns: repeat(2, 1fr); }

  main { padding: 10px 10px 20px; }
  .grid { gap: 10px; }
  .hd { padding: 10px 12px; }
  .bd  { padding: 10px 12px; }

  /* Nodes menores */
  .node { width: 210px; }
  .node.small { width: 145px; }
  .node .title { font-size: 13px; padding: 8px 10px; }
  .node .body { padding: 8px 10px; gap: 8px; }
}

/* =====================================================================
   TELAS MUITO PEQUENAS (≤ 360px)
   ===================================================================== */
@media (max-width: 360px) {
  h1 { font-size: 12px; }
  .logo { height: 24px; }
  .editor { height: 280px; }
  .node { width: 185px; }
  .node.small { width: 130px; }
  .inputs { gap: 6px; }
}
