/* Gravit Flows — styles. Light base (:root), dark override ([data-theme="dark"]).
   Type accent colors are shared across themes. */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e4e8f0;
  --grid: #e7ebf2;
  --edge: #93a0b5;
  --accent: #6d28d9;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(2, 6, 23, .08), 0 10px 26px rgba(2, 6, 23, .06);
  --shadow-sm: 0 1px 2px rgba(2, 6, 23, .08);

  --t-trigger: #16a34a;
  --t-ai: #7c3aed;
  --t-tool: #2563eb;
  --t-decision: #d97706;
  --t-output: #0d9488;
}
:root[data-theme="dark"] {
  --bg: #0a0e18;
  --panel: #101626;
  --card: #141c30;
  --ink: #e6eaf3;
  --muted: #8a96ac;
  --line: #212c47;
  --grid: #141b2e;
  --edge: #3b496b;
  --accent: #8b5cf6;
  --accent-ink: #ffffff;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 12px 34px rgba(0, 0, 0, .45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);

  --t-trigger: #22c55e;
  --t-ai: #a78bfa;
  --t-tool: #60a5fa;
  --t-decision: #fbbf24;
  --t-output: #2dd4bf;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { font-size: 20px; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -.2px; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.pill {
  font-size: 11.5px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; white-space: nowrap;
}
.pill-btn { cursor: pointer; background: var(--card); color: var(--ink); transition: border-color .15s; }
.pill-btn:hover { border-color: var(--accent); }
.icon-btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); width: 34px; height: 34px; border-radius: 9px;
  font-size: 16px; display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- Banner ---------- */
.banner {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  padding: 8px 18px; font-size: 13px; flex: none;
}
.hidden { display: none !important; }

/* ---------- Unlock bar (access gate) ---------- */
.unlock-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px; flex: none;
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
  border-bottom: 1px solid var(--line);
}
.unlock-lead { font-size: 13px; color: var(--ink); }
.unlock-input {
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px; font-size: 13px; font-family: inherit; min-width: 220px;
}
.unlock-input:focus { outline: none; border-color: var(--accent); }
.unlock-bar .btn { height: 34px; }

/* ---------- Composer ---------- */
.composer {
  display: flex; gap: 10px; align-items: stretch;
  padding: 12px 18px 6px;
  flex: none;
}
#composer-input {
  flex: 1; resize: none;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font-size: 14px; line-height: 1.4;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}
#composer-input:focus { outline: none; border-color: var(--accent); }
.btn {
  cursor: pointer; border: none; border-radius: 12px;
  font-size: 14px; font-weight: 650; padding: 0 18px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  transition: transform .08s, opacity .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ico { font-size: 15px; }

/* ---------- Example chips ---------- */
.examples { display: flex; gap: 8px; padding: 4px 18px 12px; flex-wrap: wrap; flex: none; }
.chip {
  cursor: pointer; font-size: 12.5px; color: var(--muted);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.chip:hover { color: var(--ink); border-color: var(--accent); }

/* ---------- Stage: canvas + run dock ---------- */
.stage { flex: 1; display: flex; min-height: 0; }
.canvas-wrap { position: relative; flex: 1; min-width: 0; }
#drawflow {
  width: 100%; height: 100%;
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 1.3px, transparent 1.3px);
  background-size: 22px 22px;
}

.empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); text-align: center; pointer-events: none; padding: 20px;
}
.empty-emoji { font-size: 40px; opacity: .8; }
.empty-hint p { margin: 0; font-size: 14px; line-height: 1.5; }

.canvas-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px); z-index: 5; text-align: center; padding: 20px;
}
#overlay-msg { color: var(--ink); font-size: 15px; font-weight: 600; max-width: 320px; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.zoom-controls {
  position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px; box-shadow: var(--shadow-sm);
}
.zoom-controls .icon-btn { width: 30px; height: 30px; border: none; }

/* ---------- Run dock ---------- */
.run-dock {
  width: 360px; flex: none; background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.run-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.run-head h2 { margin: 0; font-size: 15px; font-weight: 750; }
.btn-run { background: var(--t-trigger); color: #fff; height: 34px; }
.btn-run:hover:not(:disabled) { filter: brightness(1.06); }
.run-input {
  margin: 0 16px; padding: 9px 12px; font-size: 13px; font-family: inherit;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
}
.run-input:focus { outline: none; border-color: var(--accent); }

.progress { height: 5px; background: var(--line); border-radius: 999px; margin: 12px 16px 0; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.narration { padding: 8px 16px 4px; font-size: 12.5px; color: var(--muted); min-height: 18px; }
.narration.err { color: var(--danger); }

.receipts { flex: 1; overflow-y: auto; padding: 6px 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.receipts-empty { color: var(--muted); font-size: 13px; line-height: 1.5; }
.receipt {
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--edge); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow-sm);
  animation: rise .25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.receipt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.receipt-title { font-size: 13px; font-weight: 650; }
.receipt-badge { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.receipt-body { font-size: 12.5px; color: var(--ink); line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.badge-iniciado { background: color-mix(in srgb, var(--t-trigger) 18%, transparent); color: var(--t-trigger); }
.badge-feito, .badge-entregue { background: color-mix(in srgb, var(--t-output) 18%, transparent); color: var(--t-output); }
.badge-simulado { background: color-mix(in srgb, var(--t-decision) 22%, transparent); color: var(--t-decision); }
.badge-decidido { background: color-mix(in srgb, var(--t-tool) 18%, transparent); color: var(--t-tool); }

/* ---------- Drawflow node styling ---------- */
.drawflow .drawflow-node {
  background: transparent; border: none; padding: 0; box-shadow: none;
  border-radius: 14px; width: 232px;
}
.drawflow .drawflow-node.selected { box-shadow: 0 0 0 2px var(--accent); border-radius: 14px; }
.drawflow .drawflow-node .drawflow_content_node { width: 100%; }

.gf-node {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 11px 12px; box-shadow: var(--shadow);
  border-left: 4px solid var(--edge);
  transition: box-shadow .2s, border-color .2s;
}
.gf-ico {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  color: #fff;
}
.gf-main { min-width: 0; }
.gf-kind { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.gf-title { font-size: 13.5px; font-weight: 700; margin: 1px 0 2px; line-height: 1.2; }
.gf-desc { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.gf-status { font-size: 10.5px; font-weight: 700; margin-top: 5px; color: var(--t-trigger); min-height: 0; }
.gf-status:empty { display: none; }

/* type accents */
.gf-trigger { border-left-color: var(--t-trigger); } .gf-trigger .gf-ico { background: var(--t-trigger); }
.gf-ai       { border-left-color: var(--t-ai); }      .gf-ai .gf-ico       { background: var(--t-ai); }
.gf-tool     { border-left-color: var(--t-tool); }    .gf-tool .gf-ico     { background: var(--t-tool); }
.gf-decision { border-left-color: var(--t-decision); }.gf-decision .gf-ico { background: var(--t-decision); }
.gf-output   { border-left-color: var(--t-output); }  .gf-output .gf-ico   { background: var(--t-output); }

/* run states (class on .drawflow-node) */
.drawflow-node.gf-running .gf-node { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent), var(--shadow); }
.drawflow-node.gf-running .gf-node::after {
  content: ""; position: absolute;
}
.drawflow-node.gf-running { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { filter: none; } 50% { filter: brightness(1.04); } }
.drawflow-node.gf-done .gf-node { border-left-width: 4px; }

/* Drawflow ports + connections */
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output {
  background: var(--card); border: 2px solid var(--edge); height: 13px; width: 13px;
}
.drawflow .drawflow-node .output:hover, .drawflow .drawflow-node .input:hover { border-color: var(--accent); }
.drawflow .connection .main-path { stroke: var(--edge); stroke-width: 2.4px; }
.drawflow .connection .main-path:hover { stroke: var(--accent); }

/* ---------- Context panel (what the flow knows) ---------- */
.context-panel { padding: 0 16px 8px; }
.context-title { font-size: 12px; font-weight: 750; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 4px 0 8px; }
.context-list { display: flex; flex-direction: column; gap: 6px; }
.ctx-item {
  display: flex; gap: 8px; align-items: baseline;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
.ctx-key { font-size: 10.5px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.ctx-val { font-size: 12px; color: var(--ink); word-break: break-word; overflow: hidden; }

/* ---------- Step drawer (fill a step) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .35); z-index: 40;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.step-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 92vw; z-index: 41;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(2, 6, 23, .25);
  display: flex; flex-direction: column; padding: 16px 18px;
  animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.step-drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.step-drawer-heading .gf-kind { display: block; }
.step-drawer-heading h3 { margin: 2px 0 0; font-size: 18px; font-weight: 750; }
.step-desc { color: var(--muted); font-size: 13px; line-height: 1.45; margin: 8px 0 14px; }
.step-form { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.field-label .req { color: var(--danger); margin-left: 3px; }
.field-type { font-size: 10.5px; color: var(--muted); font-weight: 500; margin-left: 6px; text-transform: uppercase; letter-spacing: .3px; }
.field input[type="text"], .field input[type="email"], .field input[type="number"],
.field input[type="date"], .field textarea, .field select {
  width: 100%; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font-size: 13.5px; font-family: inherit;
}
.field textarea { min-height: 78px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); }
.field-check { flex-direction: row; align-items: center; gap: 8px; }
.field-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.field-file input[type="file"] { font-size: 12.5px; color: var(--muted); }
.field-filled input, .field-filled textarea, .field-filled select { border-color: color-mix(in srgb, var(--t-output) 55%, var(--line)); }
.step-form-empty { color: var(--muted); font-size: 13px; }
.step-actions { display: flex; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); margin-top: 12px; }
.step-actions .btn { flex: 1; justify-content: center; height: 38px; }

.drawflow-node.gf-filled .gf-node { border-color: color-mix(in srgb, var(--t-output) 45%, var(--line)); }
.drawflow-node .gf-node { cursor: pointer; }

@media (max-width: 560px) { .step-drawer { width: 100vw; } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50;
  max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .stage { flex-direction: column; }
  .run-dock { width: auto; border-left: none; border-top: 1px solid var(--line); max-height: 44%; }
  .brand-sub { display: none; }
}
