/* Gavioli Builder — interface */
:root {
  --bg: #f7f7fb; --panel: #ffffff; --panel-2: #f2f2f7; --line: #e5e5ee; --line-2: #d6d6e2;
  --text: #16161d; --muted: #6b6b7b; --faint: #9b9bab;
  --brand: #6d5dfc; --brand-2: #8b5cf6; --brand-ink: #ffffff; --brand-soft: #efedff;
  --ok: #059669; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --err: #dc2626; --err-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(20,20,40,.05), 0 8px 28px -12px rgba(20,20,40,.18);
  --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #6d5dfc 45%, #ec4899 100%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e14; --panel: #16161f; --panel-2: #1d1d28; --line: #262634; --line-2: #33334a;
    --text: #ececf3; --muted: #a0a0b4; --faint: #6f6f86;
    --brand: #8b7dff; --brand-soft: #25224a; --ok: #34d399; --ok-soft: #0c2e25; --warn: #fbbf24; --warn-soft: #33270b; --err: #f87171; --err-soft: #3a1414;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Botões e campos */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.grad { background: var(--grad); border: 0; color: #fff; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.input, textarea.input, select.input { width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--panel); outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.box { padding: 10px 12px; border-radius: 9px; margin: 10px 0; font-size: 13.5px; }
.box.err { background: var(--err-soft); color: var(--err); }
.box.ok { background: var(--ok-soft); color: var(--ok); }
.box.warn { background: var(--warn-soft); color: var(--warn); }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Topo */
.top { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
.logo { display: flex; align-items: center; gap: 9px; font-weight: 750; letter-spacing: -.01em; color: var(--text); }
.logo img { width: 28px; height: 28px; }
.logo:hover { text-decoration: none; }
.usage { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; }
.usage .bar { width: 80px; height: 6px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.usage .bar i { display: block; height: 100%; background: var(--brand); }
.menu { position: relative; }
.menu > .pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 50; }
.menu > .pop.left { right: auto; left: 0; }
.pop a, .pop button.item { display: flex; width: 100%; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text); background: none; border: 0; cursor: pointer; text-align: left; }
.pop a:hover, .pop button.item:hover { background: var(--panel-2); text-decoration: none; }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* Entrar */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent); }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth h1 { margin: 12px 0 4px; font-size: 22px; }

/* Painel inicial */
.home { max-width: 1080px; margin: 0 auto; padding: 44px 20px 80px; }
.hero { text-align: center; padding: 20px 0 30px; }
.hero h1 { font-size: clamp(28px, 4vw, 42px); letter-spacing: -.025em; margin: 0 0 10px; }
.hero h1 b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 0 0 24px; font-size: 16px; }
.prompt-box { max-width: 760px; margin: 0 auto; text-align: left; padding: 12px; border-radius: 18px; }
.prompt-box textarea { width: 100%; min-height: 96px; border: 0; background: transparent; resize: none; outline: none; font-size: 16px; padding: 6px 8px; }
.prompt-box .actions { display: flex; align-items: center; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; font-size: 13px; color: var(--text); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 44px 0 14px; }
.section-title h2 { font-size: 17px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.pcard { position: relative; padding: 16px; cursor: pointer; transition: transform .12s, border-color .12s; }
.pcard:hover { transform: translateY(-2px); border-color: var(--line-2); }
.pcard .thumb { height: 110px; border-radius: 10px; background: var(--panel-2); display: grid; place-items: center; font-size: 40px; margin-bottom: 12px; border: 1px solid var(--line); }
.pcard h3 { margin: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.pcard .menu { position: absolute; top: 10px; right: 10px; }
.empty { text-align: center; padding: 40px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 14px; }

/* Editor */
.editor { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.etop { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); min-width: 0; }
.etop .name { font-weight: 650; border: 1px solid transparent; background: none; padding: 5px 8px; border-radius: 8px; max-width: 260px; min-width: 60px; }
.etop .name:hover { border-color: var(--line-2); }
.etop .name:focus { border-color: var(--brand); outline: none; }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; height: 28px; padding: 0 10px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; font-weight: 550; font-size: 13px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ebody { display: grid; grid-template-columns: var(--chat-w, 400px) 1fr; min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.msgs { flex: 1; overflow-y: auto; padding: 16px 14px 8px; }
.msg { margin-bottom: 16px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--brand-soft); color: var(--text); border-radius: 14px 14px 4px 14px; padding: 9px 13px; max-width: 88%; white-space: pre-wrap; word-wrap: break-word; }
.msg .who { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 13px; margin-bottom: 6px; }
.msg .who .av { width: 22px; height: 22px; border-radius: 7px; background: var(--grad); display: grid; place-items: center; color: #fff; font-size: 12px; }
.md { word-wrap: break-word; }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 10px; overflow: auto; font-size: 12.5px; }
.md pre code { background: none; padding: 0; }
.thinking { margin: 4px 0 8px; font-size: 12.5px; color: var(--muted); }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; gap: 6px; align-items: center; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking .body { white-space: pre-wrap; border-left: 2px solid var(--line-2); padding-left: 10px; margin-top: 6px; max-height: 220px; overflow: auto; }
.ops { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; overflow: hidden; }
.ops .op { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 12.5px; border-top: 1px solid var(--line); }
.ops .op:first-child { border-top: 0; }
.ops .op .p { font-family: var(--mono); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ops .op.err { color: var(--err); }
.spin { width: 14px; height: 14px; border: 2px solid var(--line-2); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.vtag { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.suggest button { border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; text-align: left; }
.suggest button:hover { border-color: var(--brand); color: var(--brand); }
.composer { border-top: 1px solid var(--line); padding: 10px; }
.composer .boxc { border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); padding: 8px; }
.composer .boxc:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent); }
.composer textarea { width: 100%; border: 0; resize: none; outline: none; background: transparent; min-height: 44px; max-height: 220px; padding: 4px 6px; }
.composer .tools { display: flex; align-items: center; gap: 4px; }
.attach { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attach .a { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; border-radius: 8px; background: var(--panel-2); font-size: 12.5px; max-width: 100%; }
.attach .a img { width: 22px; height: 22px; object-fit: cover; border-radius: 4px; }
.attach .a button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; }
.errbar { margin: 0 10px 8px; padding: 8px 10px; border-radius: 10px; background: var(--err-soft); color: var(--err); font-size: 12.5px; display: flex; gap: 8px; align-items: center; }
.errbar .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Área da direita */
.stage { position: relative; min-width: 0; min-height: 0; background: var(--bg); display: flex; flex-direction: column; }
.urlbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.urlbar .url { flex: 1; min-width: 0; height: 28px; display: flex; align-items: center; padding: 0 10px; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.frame-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; overflow: auto; padding: 0; }
.frame-wrap.device { padding: 18px; }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.frame-wrap.device iframe { border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line-2); }
.frame-wrap.tablet iframe { width: 820px; max-width: 100%; }
.frame-wrap.mobile iframe { width: 390px; max-width: 100%; }
.loading-over { position: absolute; inset: 44px 0 0 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 3; }
.selecting-hint { position: absolute; left: 50%; top: 54px; transform: translateX(-50%); background: var(--brand); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 12.5px; z-index: 4; box-shadow: var(--shadow); }

/* Código */
.code { flex: 1; display: grid; grid-template-columns: 240px 1fr; min-height: 0; }
.tree { border-right: 1px solid var(--line); overflow: auto; padding: 8px; background: var(--panel); }
.tree .f { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; cursor: pointer; font-size: 13px; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .f:hover { background: var(--panel-2); }
.tree .f.on { background: var(--brand-soft); color: var(--brand); }
.tree .dir { color: var(--muted); font-size: 12px; padding: 8px 8px 2px; font-family: var(--mono); }
.ed { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ed .bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.ed .area { flex: 1; display: flex; min-height: 0; overflow: hidden; background: var(--panel); }
.ed .gutter { padding: 12px 8px 12px 12px; text-align: right; color: var(--faint); font: 12.5px/1.6 var(--mono); user-select: none; overflow: hidden; white-space: pre; border-right: 1px solid var(--line); background: var(--panel-2); }
.ed textarea { flex: 1; border: 0; outline: none; resize: none; padding: 12px; font: 12.5px/1.6 var(--mono); background: var(--panel); white-space: pre; overflow: auto; tab-size: 2; }

/* Histórico, banco, painéis */
.pane { flex: 1; overflow: auto; padding: 22px; }
.pane h2 { margin: 0 0 4px; font-size: 18px; }
.list { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.list .li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.list .li:first-child { border-top: 0; }
.list .li .num { font-weight: 700; color: var(--muted); width: 38px; font-variant-numeric: tabular-nums; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
table.t th { color: var(--muted); font-weight: 600; background: var(--panel-2); border-top: 0; }
table.t td.json { font-family: var(--mono); font-size: 12px; max-width: 520px; word-break: break-all; }
.drawer-bg { position: fixed; inset: 0; background: rgba(10,10,20,.35); z-index: 60; display: flex; justify-content: flex-end; }
.drawer { width: min(460px, 100%); height: 100%; background: var(--panel); border-left: 1px solid var(--line); padding: 22px; overflow: auto; box-shadow: var(--shadow); }
.drawer h2 { margin: 0 0 16px; font-size: 18px; display: flex; align-items: center; justify-content: space-between; }
.drawer h3 { font-size: 14px; margin: 22px 0 8px; }
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,20,.4); z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal { width: min(520px, 100%); background: var(--panel); border-radius: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 22px; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.publish-url { display: flex; gap: 6px; align-items: center; padding: 8px 10px; border-radius: 9px; background: var(--panel-2); font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1b1b24; color: #fff; padding: 9px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; max-width: 90vw; }
.toast.err { background: var(--err); }
.page { max-width: 820px; margin: 0 auto; padding: 30px 20px 80px; }
.page h1 { font-size: 24px; margin: 0 0 18px; }
.page .card { padding: 20px; margin-bottom: 16px; }
.page .card h2 { margin: 0 0 14px; font-size: 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 99px; background: var(--line-2); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { left: 18px; }

/* Celular: chat e preview alternam */
.mobile-switch { display: none; }
@media (max-width: 860px) {
  .ebody { grid-template-columns: 1fr; }
  .editor.show-stage .chat { display: none; }
  .editor:not(.show-stage) .stage { display: none; }
  .mobile-switch { display: inline-flex; }
  .etop .hide-sm { display: none; }
  .code { grid-template-columns: 1fr; grid-template-rows: 140px 1fr; }
  .tree { border-right: 0; border-bottom: 1px solid var(--line); }
  .top .usage { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Complementos */
a.btn:hover { text-decoration: none; }
.btn.danger-fill { background: var(--err); border-color: var(--err); color: #fff; }
.pop button.item.danger { color: var(--err); }
@media (max-width: 860px) { .hide-sm { display: none !important; } }
@media (max-width: 860px) {
  .etop { gap: 6px; padding: 0 8px; }
  .etop .name, .etop .emoji { display: none; }
  .seg button { padding: 0 8px; }
}
