:root {
  --bg: #0a0f1e;
  --panel: #101830;
  --box: #14203c;
  --line: #22315a;
  --text: #e9eefb;
  --muted: #93a3c8;
  --brand: #0068ff;
  --brand-hover: #2f82ff;
  --brand2: #4d9aff;
  --danger: #ff5c72;
  --ok: #2ecc9a;
  --warn: #f5c451;
  --radius: 14px;
}
* { box-sizing: border-box; }
/* Garante que o atributo hidden sempre esconda o elemento,
   mesmo quando a classe define display (grid/flex). */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
body.editor-open { overflow: hidden; }
h1, h2, h3 { margin: 0 0 .5rem; }
a { color: var(--brand2); }
code { background: #0008; padding: 2px 6px; border-radius: 6px; }
.muted { color: var(--muted); font-size: .88rem; }
.hint { color: var(--muted); font-size: .82rem; margin-top: .4rem; }
.error { color: var(--danger); }
.success { color: var(--ok); }

/* ---- Login ---- */
.login-bg {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 20% -10%, #00337a55, transparent),
              radial-gradient(1000px 500px at 100% 100%, #0068ff22, transparent), var(--bg);
}
.login-card {
  width: min(400px, 92vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 2.2rem;
  display: flex; flex-direction: column; gap: .8rem; box-shadow: 0 20px 60px #0009;
}
.login-logo { width: 190px; align-self: center; margin-bottom: .2rem; }
.login-title { text-align: center; font-size: 1.25rem; margin: 0; }
.login-sub { text-align: center; margin-bottom: .8rem; }
.brand { display: flex; align-items: center; gap: .55rem; }
.brand-accent { color: var(--brand2); }
.logo-img { width: 30px; height: 30px; object-fit: contain; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }

/* ---- Layout ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.tabs { display: flex; gap: .3rem; flex: 1; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: .5rem .8rem; border-radius: 10px; cursor: pointer; font-size: .9rem;
  display: inline-flex; align-items: center; gap: .4rem;
}
.tab .icon { width: 17px; height: 17px; }
.tab:hover { color: var(--text); background: #ffffff08; }
.tab.active { color: #fff; background: var(--brand); }

/* ícones genéricos */
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.btn-ghost, .btn-primary { display: inline-flex; align-items: center; gap: .4rem; }
.btn-ghost .icon, .btn-primary .icon { width: 16px; height: 16px; }
h3 .icon { width: 18px; height: 18px; color: var(--brand2); vertical-align: -4px; margin-right: .25rem; }
.topbar-right { display: flex; align-items: center; gap: .8rem; }
.container { max-width: 1080px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.box {
  background: var(--box); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1.1rem;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .6rem; }
input, textarea, select {
  width: 100%; margin-top: .25rem; padding: .6rem .7rem; border-radius: 10px;
  border: 1px solid var(--line); background: #0d1528; color: var(--text);
  font-size: .92rem; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); border-color: transparent; }

/* ---- Buttons ---- */
button { font-family: inherit; }
.btn-primary {
  background: linear-gradient(180deg, #1a76ff, var(--brand)); color: #fff; border: none;
  padding: .6rem 1.1rem; border-radius: 10px; cursor: pointer; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 104, 255, .35);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn-primary:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0, 104, 255, .45); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: .45rem .8rem; border-radius: 10px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  background: transparent; color: var(--danger); border: 1px solid #ff5c7255;
  padding: .4rem .7rem; border-radius: 8px; cursor: pointer; font-size: .82rem;
}
.btn-danger:hover { background: #ff5c7215; }

/* ---- Cards de status ---- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 760px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--box); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.card-top { display: flex; align-items: center; gap: .5rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.card.on .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.card.off .dot { background: var(--danger); }
.badge { display: inline-block; margin: .5rem 0; font-size: .75rem; padding: .2rem .5rem; border-radius: 20px; background: #ffffff10; }
.card.on .badge, .badge-on { background: #2ecc9a22; color: var(--ok); }

/* ---- Perfil / mídias ---- */
.result { margin-top: .7rem; font-size: .9rem; min-height: 1.2rem; }
.profile { display: flex; gap: .8rem; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.stats { display: flex; gap: 1rem; margin-top: .3rem; font-size: .85rem; color: var(--muted); }
.stats b { color: var(--text); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; margin-top: .6rem; }
.media-item { position: relative; border-radius: 10px; overflow: hidden; display: block; }
.media-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.media-meta { position: absolute; bottom: 0; left: 0; right: 0; padding: .3rem .4rem; font-size: .72rem; background: linear-gradient(transparent, #000c); display: flex; gap: .7rem; }
.media-meta span { display: inline-flex; align-items: center; gap: .25rem; }
.media-meta .icon { width: 13px; height: 13px; }

/* ---- Lista de fluxos (cards) ---- */
.flow-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-top: 1rem; }
.flow-card {
  background: var(--box); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; cursor: pointer; transition: border-color .15s, transform .15s;
}
.flow-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.flow-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.flow-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: .8rem; }

/* ---- Listas / logs ---- */
.list { display: flex; flex-direction: column; gap: .5rem; }
.list.small { max-height: 420px; overflow: auto; }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: .8rem;
  background: #ffffff06; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem;
}
.tag {
  display: inline-block; font-size: .7rem; padding: .12rem .45rem; border-radius: 6px;
  background: #ffffff12; color: var(--muted); margin-right: .3rem;
}
.status-pending { color: var(--warn); } .status-done { color: var(--ok); } .status-error { color: var(--danger); }
.log-line { border-bottom: 1px solid var(--line); padding: .5rem 0; font-size: .82rem; }

/* ---- Switch ---- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { display: none; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 20px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch-inline { display: flex; align-items: center; gap: .5rem; margin: 0; }

/* ==================== EDITOR (tela cheia) ==================== */
.editor {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: grid;
  grid-template-rows: 54px 1fr;
  grid-template-columns: 1fr;
}
.ed-top {
  grid-row: 1; display: flex; align-items: center; gap: .8rem;
  padding: 0 1rem; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 20;
}
.ed-name {
  width: auto; min-width: 160px; max-width: 340px; margin: 0;
  background: transparent; border: 1px solid transparent; font-size: 1rem; font-weight: 600;
  padding: .4rem .6rem;
}
.ed-name:hover, .ed-name:focus { border-color: var(--line); background: #0d1528; }
.ed-savestate { font-size: .78rem; min-width: 70px; }
.ed-top-right { margin-left: auto; display: flex; align-items: center; gap: .8rem; }

.ed-canvas {
  grid-row: 2; position: relative; overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(#ffffff14 1.2px, transparent 1.2px);
  background-size: 22px 22px;
  cursor: grab;
}
.ed-canvas:active { cursor: grabbing; }
.ed-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
#edSvg { position: absolute; left: 0; top: 0; width: 2px; height: 2px; overflow: visible; }
#edSvg .edge { fill: none; stroke: var(--brand); stroke-width: 2.5; pointer-events: none; }
#edSvg .edge.temp { stroke-dasharray: 6 5; opacity: .7; }
#edSvg .edge-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
#edSvg .edge-hit:hover + .edge { stroke: var(--danger); }
#edNodes { position: absolute; left: 0; top: 0; }
.ed-canvas-empty {
  position: absolute; left: 40px; top: 40px; color: var(--muted); font-size: 1rem; white-space: nowrap;
}

/* paleta flutuante à esquerda */
.ed-palette {
  position: absolute; left: 14px; top: 68px; bottom: 14px; width: 200px; z-index: 15;
  background: #101830ee; border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem; overflow: auto; backdrop-filter: blur(6px);
}
.ed-palette h4 { margin: .7rem 0 .35rem; font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.ed-palette h4:first-child { margin-top: 0; }
.palette-item {
  display: flex; align-items: center; gap: .5rem;
  background: #ffffff08; border: 1px solid var(--line); border-radius: 9px;
  padding: .5rem .6rem; margin-bottom: .35rem; font-size: .84rem; cursor: pointer; user-select: none;
}
.palette-item:hover { background: var(--brand); color: #fff; border-color: transparent; }
.palette-item [data-icon] { display: inline-flex; color: var(--brand2); flex-shrink: 0; }
.palette-item:hover [data-icon] { color: #fff; }
.palette-item .icon { width: 16px; height: 16px; }
.palette-help { margin-top: .8rem; line-height: 1.5; }

/* inspector flutuante à direita */
.ed-inspector {
  position: absolute; right: 14px; top: 68px; width: 270px; max-height: calc(100% - 100px); z-index: 15;
  background: #101830ee; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; overflow: auto; backdrop-filter: blur(6px);
}
.insp-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .3rem; }
.insp-icon { display: inline-flex; color: var(--brand2); }
.insp-close { margin-left: auto; padding: .2rem .5rem; }
.insp-del { width: 100%; margin-top: .6rem; }
.var-box { margin: .6rem 0; }
.var-chip {
  background: #0068ff22; color: var(--brand); border: 1px solid #0068ff55;
  border-radius: 7px; padding: .25rem .5rem; margin: 0 .3rem .3rem 0;
  cursor: pointer; font-size: .78rem; font-family: monospace;
}
.var-chip:hover { background: var(--brand); color: #fff; }

/* nós */
.ed-node {
  position: absolute; width: 210px; min-height: 60px;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px;
  display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem;
  box-shadow: 0 8px 22px #0007; user-select: none; cursor: move;
}
.ed-node.selected { border-color: var(--brand); box-shadow: 0 0 0 3px #0068ff44, 0 8px 22px #0007; }
.ed-node.cat-trigger { border-left: 4px solid var(--ok); }
.ed-node.cat-logic { border-left: 4px solid var(--warn); }
.ed-node.cat-action { border-left: 4px solid var(--brand); }
.ed-node.run-ok { border-color: var(--ok); }
.ed-node.run-err { border-color: var(--danger); box-shadow: 0 0 0 3px #ff5c7244; }
.ed-node-icon { flex-shrink: 0; display: inline-flex; color: var(--brand2); }
.ed-node.cat-trigger .ed-node-icon { color: var(--ok); }
.ed-node.cat-logic .ed-node-icon { color: var(--warn); }
.run-step .icon { vertical-align: -3px; margin-right: .25rem; }
.ed-node-info { min-width: 0; }
.ed-node-name { font-weight: 600; font-size: .86rem; }
.ed-node-sub { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.port {
  position: absolute; width: 15px; height: 15px; border-radius: 50%;
  background: var(--bg); border: 2.5px solid var(--brand);
  top: 50%; transform: translateY(-50%); cursor: crosshair; z-index: 3;
}
.port-in { left: -8px; }
.port-out { right: -8px; }
.port:hover { background: var(--brand); box-shadow: 0 0 8px var(--brand); }

/* painel de teste */
.ed-testpanel {
  position: absolute; right: 14px; bottom: 14px; width: 320px; z-index: 16;
  background: #101830f5; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; backdrop-filter: blur(6px);
}
.ed-testlog { margin-top: .6rem; max-height: 220px; overflow: auto; font-size: .82rem; }
.run-step { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.run-step.erro { color: var(--danger); }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: #000a; backdrop-filter: blur(3px);
}
.modal-card {
  width: min(400px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 1.4rem; box-shadow: 0 20px 60px #000a;
}
.modal-card h3 { margin-bottom: .8rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  padding: .7rem 1.2rem; border-radius: 12px; background: #111; border: 1px solid var(--line);
  box-shadow: 0 10px 30px #0008; z-index: 300; font-size: .9rem;
}
.toast.success { border-color: var(--ok); }
.toast.error { border-color: var(--danger); color: #ffd7dd; }

/* ==================== DASHBOARD COMERCIAL ==================== */
.dash-controls { display: flex; align-items: center; gap: .6rem; }
.dash-controls select { width: auto; margin: 0; }
.dash-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
@media (max-width: 820px) { .dash-grid-2 { grid-template-columns: 1fr; } }

/* KPIs */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: .9rem; margin: 1rem 0 1.2rem; }
@media (max-width: 960px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .kpi-row { grid-template-columns: 1fr; } }
.kpi {
  background: var(--box); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; display: flex; align-items: center; gap: .8rem;
}
.kpi-icon {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 11px;
  display: grid; place-items: center; color: var(--kc);
  background: color-mix(in srgb, var(--kc) 16%, transparent);
}
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: .76rem; color: var(--muted); }

/* status compacto */
.status-mini { display: flex; flex-direction: column; gap: .5rem; margin-top: .3rem; }
.status-item { display: flex; align-items: center; gap: .55rem; font-size: .9rem; padding: .4rem .2rem; }
.status-item .icon { width: 18px; height: 18px; }
.status-item.on .icon { color: var(--ok); }
.status-item.off .icon { color: var(--danger); }
.status-item .badge { margin-left: auto; }

/* gráficos */
.chart-area { margin-top: .4rem; }
.svg-chart { width: 100%; height: auto; display: block; }
.chart-tick { fill: var(--muted); font-size: 10px; }
.chart-legend { display: flex; gap: 1.2rem; margin-top: .5rem; font-size: .8rem; color: var(--muted); }
.chart-legend i, .legend-row i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

.donut-wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.svg-donut { width: 150px; height: 150px; flex-shrink: 0; }
.donut-total { fill: var(--text); font-size: 22px; font-weight: 700; }
.donut-sub { fill: var(--muted); font-size: 9px; }
.donut-legend { flex: 1; min-width: 160px; }
.legend-row { display: flex; align-items: center; gap: .4rem; font-size: .85rem; padding: .18rem 0; }
.legend-row b { margin-left: auto; }
.legend-row .muted { min-width: 34px; text-align: right; }

.chart-bars { margin-top: .3rem; }
.bars { display: flex; flex-direction: column; gap: .5rem; }
.bar-row { display: flex; align-items: center; gap: .6rem; font-size: .84rem; }
.bar-label { width: 34%; min-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 12px; background: #ffffff10; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transition: width .4s ease; min-width: 3px; }
.bar-val { width: 34px; text-align: right; color: var(--muted); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.tag-bubble {
  background: #0068ff18; border: 1px solid #0068ff40; color: var(--text);
  border-radius: 20px; padding: .28rem .7rem; line-height: 1;
}
.tag-bubble b { color: var(--brand2); }
