:root {
  /* Paleta = Design System Maestro (../design-system/tokens.css), a mesma
     usada no hub e no mapeamento-idr. Os nomes abaixo são só um alias pros
     tokens semânticos do Maestro — nenhuma regra depois deste bloco mudou
     de seletor, só o valor por trás de cada variável. */
  --bg:        var(--color-bg-layout);
  --surface:   var(--color-bg-container);
  --surface2:  var(--brand-main-1);
  --border:    var(--color-border-secondary);
  --border2:   var(--color-border-default);
  --green:     var(--color-primary);
  --green-dim: var(--brand-main-1);
  --blue:      var(--color-link);
  --red:       var(--color-error);
  --amber:     var(--color-warning);
  --purple:    var(--brand-purple-6);
  --teal:      var(--color-success);
  --orange:    var(--color-warning);
  --text:      var(--color-text-base);
  --text-dim:  var(--color-text-secondary);
  --font-ui:   var(--font-family-product);
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius:    var(--radius-base);
  --radius-lg: 20px;

  /* Painéis de código/log/grafo (console de eventos, JSON, canvas do fluxo)
     mantêm um tema escuro próprio — não fazem parte da "chrome" do app, e
     um editor/console com fundo escuro embutido numa página clara é um
     padrão comum e legível. Valores literais, independentes da paleta clara
     acima. */
  --code-bg:       #0d0f12;
  --code-surface:  #151821;
  --code-surface2: #1e2330;
  --code-border:   #272d3e;
  --code-border2:  #333d55;
  --code-text:     #e8eaf0;
  --code-text-dim: #7a849a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 14px; line-height: 1.6; min-height: 100vh; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* LOGIN */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 48px 40px; width: 100%; max-width: 380px; text-align: center; }
.logo-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--green); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 16px; }
.login-card h1 { font-family: var(--font-family-brand); font-size: 20px; font-weight: 600; letter-spacing: -.4px; margin-bottom: 6px; }
.login-card p { color: var(--text-dim); font-size: 13px; margin-bottom: 28px; }
.field-label { display: block; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; letter-spacing: .5px; text-transform: uppercase; }
.field-label .req { color: var(--red); }
input[type=password], input[type=text], textarea, select {
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius);
  color: var(--text); font-family: var(--font-ui); font-size: 13px; padding: 9px 12px;
  outline: none; transition: border-color .15s; width: 100%;
}
input[type=password]:focus, input[type=text]:focus, textarea:focus, select:focus { border-color: var(--green); }
.login-error { color: var(--red); font-size: 12px; margin: 8px 0; min-height: 16px; }

/* HUB — tela pós-login pra escolher a ferramenta */
#hub-screen { display: none; min-height: 100vh; flex-direction: column; background: var(--bg); }
#hub-screen.visible { display: flex; }
.hub-topbar { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0; }
.hub-topbar .brand { display: flex; align-items: center; gap: 12px; }
.hub-topbar .brand img { display: block; }
.hub-topbar .brand h1 { margin: 0; font-family: var(--font-family-brand); font-size: 20px; font-weight: 600; color: var(--text); }
.hub-main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 56px 24px; gap: 8px; }
.hub-main h1 { font-family: var(--font-family-brand); font-size: 24px; font-weight: 600; color: var(--text); }
.hub-main .hub-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 36px; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; width: 100%; max-width: 920px; }
.hub-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 24px 22px; text-align: left; cursor: pointer; font-family: var(--font-ui);
  display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.hub-tile:hover { border-color: var(--green); box-shadow: 0 4px 16px rgba(0,121,204,.12); transform: translateY(-1px); }
.hub-tile .hub-tile-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--surface2); color: var(--green); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.hub-tile h2 { font-family: var(--font-family-brand); font-size: 16px; font-weight: 600; color: var(--text); }
.hub-tile p { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }
.hub-back { background: none; border: none; color: var(--text-dim); font-family: var(--font-ui); font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.hub-back:hover { color: var(--text); }

/* LAYOUT */
#app { display: none; height: 100vh; flex-direction: column; }
#app.visible { display: flex; }

.topbar { height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0; }
.topbar-logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; font-family: var(--font-family-brand); }
.topbar-logo .mark { width: 24px; height: 24px; border-radius: 5px; background: var(--green); display: flex; align-items: center; justify-content: center; }
.topbar-logo span { color: var(--green); }
.divider { width: 1px; height: 24px; background: var(--border); }
.topbar-sub { font-size: 13px; color: var(--text-dim); }
.spacer { flex: 1; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border2); transition: background .3s; }
.status-dot.on { background: var(--color-success); box-shadow: 0 0 6px var(--color-success); }
.status-lbl { font-size: 12px; color: var(--text-dim); }

.workspace { flex: 1; display: grid; grid-template-columns: 340px 1fr; overflow: hidden; }

/* SIDEBAR */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.field-group { display: flex; flex-direction: column; gap: 5px; }
.hint { font-size: 11px; color: var(--text-dim); }
textarea { resize: none; min-height: 72px; }
select { cursor: pointer; }

.upload-zone { border: 1.5px dashed var(--border2); border-radius: var(--radius); padding: 22px 16px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; position: relative; }
.upload-zone:hover, .upload-zone.drag { border-color: var(--green); background: rgba(0,121,204,.04); }
.upload-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-text { font-size: 13px; color: var(--text-dim); }
.upload-text strong { color: var(--green); font-weight: 500; }
.upload-name { font-size: 11px; color: var(--color-success); margin-top: 5px; font-family: var(--font-mono); }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* LOG — console de eventos, tema escuro próprio */
.log-panel { border-top: 1px solid var(--code-border); flex-shrink: 0; max-height: 150px; overflow-y: auto; background: var(--code-bg); }
.log-header { display: flex; align-items: center; justify-content: space-between; padding: 5px 14px; border-bottom: 1px solid var(--code-border); background: var(--code-bg); position: sticky; top: 0; }
.log-title { font-size: 10px; font-weight: 600; color: var(--code-text-dim); text-transform: uppercase; letter-spacing: .6px; }
.log-clear { background: none; border: none; color: var(--code-text-dim); font-size: 11px; cursor: pointer; }
.log-clear:hover { color: var(--code-text); }
.log-entry { padding: 4px 14px; font-family: var(--font-mono); font-size: 11px; line-height: 1.5; border-bottom: 1px solid var(--code-border); display: flex; gap: 8px; word-break: break-all; }
.log-entry.error { color: var(--red); }
.log-entry.success { color: var(--color-success); }
.log-entry.info { color: var(--code-text-dim); }
.log-time { color: var(--code-text-dim); flex-shrink: 0; }
.log-empty { padding: 8px 14px; font-size: 11px; color: var(--code-text-dim); font-family: var(--font-mono); }

/* RESULT */
.result-panel { display: flex; flex-direction: column; overflow: hidden; }
.tabs-bar { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 0 16px; gap: 4px; background: var(--surface); flex-shrink: 0; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-dim); cursor: pointer; font-family: var(--font-ui); font-size: 13px; font-weight: 500; padding: 13px 11px 11px; transition: color .15s, border-color .15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--green); border-bottom-color: var(--green); }
.tab-badge { background: var(--surface2); border-radius: 10px; font-size: 10px; padding: 1px 6px; margin-left: 4px; color: var(--text-dim); }
.tab.active .tab-badge { background: var(--green-dim); color: var(--green); }
.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; flex-direction: column; }

/* publish btn */
.publish-btn { margin-left: auto; display: none; }
.publish-btn.visible { display: flex; }

/* EMPTY STATE */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-dim); text-align: center; padding: 40px; gap: 10px; }
.empty-state svg { opacity: .25; }
.empty-state h3 { font-size: 15px; font-weight: 500; color: var(--text); opacity: .5; }
.empty-state p { font-size: 13px; max-width: 240px; }

/* GRAFO — canvas do fluxo, mesma família visual escura do console */
#preview-wrap { flex: 1; position: relative; overflow: hidden; }
#graph-canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#graph-canvas.grabbing { cursor: grabbing; }
.graph-controls { position: absolute; bottom: 14px; right: 14px; display: flex; flex-direction: column; gap: 5px; }
.graph-hint { position: absolute; bottom: 14px; left: 14px; font-size: 11px; color: var(--code-text-dim); background: rgba(13,15,18,.85); padding: 4px 10px; border-radius: 4px; border: 1px solid var(--code-border); }
.graph-legend { position: absolute; top: 14px; right: 14px; background: rgba(13,15,18,.9); border: 1px solid var(--code-border); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 5px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--code-text-dim); }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* JSON — mesma família visual escura do console */
.json-toolbar { display: flex; align-items: center; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--code-border); background: var(--code-surface); flex-shrink: 0; }
.json-stats { font-size: 11px; color: var(--code-text-dim); font-family: var(--font-mono); flex: 1; }
.json-out { flex: 1; overflow-y: auto; padding: 14px; font-family: var(--font-mono); font-size: 12px; line-height: 1.7; white-space: pre; color: #c9d1d9; background: var(--code-bg); }
.jk { color: #79b8ff; } .js { color: #9ecbff; } .jn { color: #f8c555; } .jb { color: var(--blue); } .jl { color: var(--code-text-dim); }

/* REVIEW */
#review-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.review-item { background: var(--surface2); border: 1px solid var(--border); border-left: 3px solid var(--amber); border-radius: var(--radius); padding: 10px 13px; }
.review-tag { font-size: 10px; font-weight: 600; color: var(--amber); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 3px; }
.review-text { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.review-id { font-family: var(--font-mono); font-size: 11px; color: var(--blue); margin-top: 3px; }

/* BOTOES */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: var(--radius); cursor: pointer; font-family: var(--font-ui); font-size: 13px; font-weight: 500; padding: 9px 14px; transition: opacity .15s, transform .1s; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--green); color: var(--base-white); width: 100%; font-size: 14px; padding: 11px; font-weight: 600; }
.btn-primary:hover:not(:disabled) { opacity: .9; }
.btn-ghost { background: transparent; border: 1px solid var(--border2); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-publish { background: var(--blue); color: #fff; padding: 7px 14px; font-size: 12px; }
.btn-publish:hover:not(:disabled) { opacity: .85; }
.icon-btn { background: var(--code-surface2); border: 1px solid var(--code-border2); color: var(--code-text-dim); cursor: pointer; padding: 7px; display: flex; align-items: center; justify-content: center; transition: color .15s; }
.icon-btn:hover { color: var(--code-text); }

/* MODAL PUBLISH */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 150; backdrop-filter: blur(3px); }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 400px; }
.modal h2 { font-family: var(--font-family-brand); font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; }
.modal-footer { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; }

/* LOADING — overlay escuro, texto/anel claros por cima */
.loading-overlay { position: fixed; inset: 0; background: rgba(13,15,18,.85); display: none; flex-direction: column; align-items: center; justify-content: center; z-index: 100; gap: 14px; backdrop-filter: blur(4px); }
.loading-overlay.visible { display: flex; }
.spinner { width: 38px; height: 38px; border: 2px solid rgba(255,255,255,.25); border-top-color: var(--base-white); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-bar-wrap { width: 200px; height: 2px; background: rgba(255,255,255,.25); border-radius: 1px; overflow: hidden; }
.loading-bar { height: 100%; background: var(--base-white); border-radius: 1px; width: 0%; transition: width .4s ease; }
.loading-msg { font-size: 12px; color: rgba(255,255,255,.8); font-family: var(--font-mono); }

/* TOAST */
#toast-area { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 7px; z-index: 200; }
.toast { background: var(--surface2); border: 1px solid var(--border2); border-radius: var(--radius); padding: 10px 15px; font-size: 13px; display: flex; align-items: center; gap: 9px; animation: slide-in .2s ease; max-width: 340px; cursor: pointer; }
@keyframes slide-in { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.toast.success { border-left: 3px solid var(--color-success); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
