:root {
  --bg: #12100e;
  --panel: #1a1714;
  --panel-2: #221e1a;
  --line: #2e2924;
  --line-2: #3b352f;
  --text: #ede7e0;
  --muted: #9a9087;
  --faint: #6d655d;
  --ember: #ff6a3d;
  --ember-2: #ff8a5c;
  --ember-bg: rgba(255, 106, 61, 0.12);
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 10px;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --serif: 'Instrument Serif', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--ember-2); }
::selection { background: rgba(255, 106, 61, 0.35); }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

/* ---------- elementos base ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--text); transition: background .15s, border-color .15s; }
.btn:hover { border-color: #4d453d; background: #2a2520; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ember); border-color: var(--ember); color: #1a0d07; }
.btn.primary:hover { background: var(--ember-2); border-color: var(--ember-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.danger { color: var(--err); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.sm.icon { width: 28px; }
.btn svg { width: 16px; height: 16px; flex: none; }

.input, .textarea, select.input { width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 12px; outline: none; transition: border-color .15s; }
.input:focus, .textarea:focus { border-color: var(--ember); }
.textarea { resize: vertical; min-height: 80px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.live { color: var(--ok); border-color: rgba(74, 222, 128, .3); background: rgba(74, 222, 128, .08); }
.badge.live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.badge.ember { color: var(--ember-2); border-color: rgba(255, 106, 61, .3); background: var(--ember-bg); }
.err-text { color: var(--err); font-size: 13px; min-height: 18px; margin: 4px 0 10px; white-space: pre-wrap; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--ember); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- marca ---------- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 24px; letter-spacing: .2px; color: var(--text); text-decoration: none; }
.brand-mark { width: 26px; height: 26px; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(800px 400px at 50% -10%, rgba(255, 106, 61, .14), transparent 70%); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { font-size: 34px; margin-bottom: 6px; }
.auth-card h1 { font-family: var(--serif); font-weight: 400; font-size: 30px; margin: 22px 0 4px; }
.auth-card p.lead { margin: 0 0 22px; color: var(--muted); }
.auth-card .btn.primary { width: 100%; justify-content: center; height: 40px; }

/* ---------- topo ---------- */
.topbar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--ember-2); cursor: pointer; }

/* ---------- dashboard ---------- */
.dash { max-width: 1120px; margin: 0 auto; padding: 48px 24px 80px; }
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(36px, 5vw, 54px); line-height: 1.05; margin: 0 0 8px; letter-spacing: -.5px; }
.hero h1 em { color: var(--ember); }
.hero p { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.composer { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 14px; box-shadow: 0 20px 60px -30px rgba(0, 0, 0, .8); }
.composer:focus-within { border-color: #5a4a3e; }
.composer textarea { width: 100%; border: 0; background: transparent; resize: none; outline: none; font-size: 15px; min-height: 76px; }
.composer .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.composer .row .input { width: auto; flex: 1 1 160px; height: 34px; padding: 6px 10px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button svg { width: 15px; height: 15px; }
.stack-hint { font-size: 12.5px; color: var(--faint); margin: 10px 2px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 5px 12px; color: var(--muted); cursor: pointer; font-size: 13px; }
.chip:hover { color: var(--text); border-color: var(--line-2); }

.section-head { display: flex; align-items: center; gap: 12px; margin: 56px 0 16px; }
.section-head h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 0; }
.section-head .input { max-width: 240px; height: 34px; padding: 6px 10px; margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s; position: relative; }
.card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.thumb { height: 150px; background: #fff; position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.thumb iframe { width: 1280px; height: 800px; border: 0; transform: scale(.2); transform-origin: 0 0; pointer-events: none; background: #fff; }
.card .meta { padding: 12px 14px 14px; }
.card .title { font-weight: 600; margin: 0 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .menu-btn { position: absolute; top: 8px; right: 8px; background: rgba(18, 16, 14, .85); border-color: var(--line-2); }
.empty { border: 1px dashed var(--line-2); border-radius: 12px; padding: 40px; text-align: center; color: var(--muted); }

/* ---------- menu suspenso ---------- */
.pop { position: fixed; z-index: 50; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 5px; min-width: 190px; box-shadow: 0 16px 40px -10px rgba(0, 0, 0, .7); }
.pop button, .pop a { display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text); text-decoration: none; font-size: 13.5px; }
.pop button:hover, .pop a:hover { background: #2e2823; }
.pop .danger { color: var(--err); }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
.pop svg { width: 15px; height: 15px; color: var(--muted); }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 40; padding: 20px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 22px; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 720px; }
.modal h3 { font-family: var(--serif); font-weight: 400; font-size: 26px; margin: 0 0 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
table.list { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.list th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }

/* ---------- editor ---------- */
.editor { height: 100vh; display: grid; grid-template-rows: 52px 1fr; }
.ebar { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.ebar .name { font-weight: 600; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px; min-width: 60px; max-width: 260px; outline: none; }
.ebar .name:hover { border-color: var(--line); }
.ebar .name:focus { border-color: var(--ember); }
.ebar .spacer { flex: 1; }
.ebody { display: grid; grid-template-columns: var(--chat-w, 400px) 1fr; min-height: 0; }
.chat { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: var(--panel); }
.msgs { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px 12px 4px 12px; padding: 9px 12px; max-width: 88%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .who { font-size: 11px; color: var(--faint); margin-bottom: 2px; }
.msg.ai { color: #ddd5cc; word-wrap: break-word; }
.msg.ai p { margin: 0 0 8px; }
.msg.ai code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.msg.ai ul { margin: 0 0 8px; padding-left: 20px; }
.files { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.file-chip { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; }
.file-chip .ico { color: var(--ok); }
.file-chip.writing { color: var(--text); border-color: rgba(255, 106, 61, .35); }
.file-chip.deleted { text-decoration: line-through; }
.status-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.build-err { background: rgba(248, 113, 113, .08); border: 1px solid rgba(248, 113, 113, .3); color: #fecaca; border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; max-height: 160px; overflow: auto; }
.tokens { font-size: 11px; color: var(--faint); margin-top: 4px; }
.welcome { color: var(--muted); padding: 10px 4px; }
.welcome h4 { font-family: var(--serif); font-weight: 400; font-size: 22px; color: var(--text); margin: 0 0 6px; }

.chat-input { border-top: 1px solid var(--line); padding: 12px; }
.chat-box { background: var(--bg); border: 1px solid var(--line-2); border-radius: 12px; padding: 8px 8px 6px 12px; }
.chat-box:focus-within { border-color: #5a4a3e; }
.chat-box textarea { width: 100%; border: 0; background: transparent; outline: none; resize: none; max-height: 220px; min-height: 44px; }
.chat-box .row { display: flex; align-items: center; gap: 6px; }
.chat-box .row .spacer { flex: 1; }
.attach-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.attach { position: relative; width: 54px; height: 54px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line-2); }
.attach img { width: 100%; height: 100%; object-fit: cover; }
.attach button { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .7); color: #fff; cursor: pointer; font-size: 11px; line-height: 1; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #0d0b0a; }
.stage-bar { height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
.stage-bar .url { flex: 1; min-width: 0; height: 28px; display: flex; align-items: center; padding: 0 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; font-family: var(--mono); font-size: 12px; color: var(--faint); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview-wrap { flex: 1; display: flex; justify-content: center; overflow: auto; padding: 0; min-height: 0; position: relative; }
.preview-wrap.framed { padding: 18px; }
.preview-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; transition: width .25s; }
.preview-wrap.framed iframe { border-radius: 14px; box-shadow: 0 0 0 1px var(--line-2), 0 20px 50px -20px #000; }
.preview-busy { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 99px; padding: 6px 14px; display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); z-index: 2; box-shadow: 0 8px 20px -8px #000; }

.code { flex: 1; display: grid; grid-template-columns: 220px 1fr; min-height: 0; }
.tree { border-right: 1px solid var(--line); overflow-y: auto; padding: 8px; background: var(--bg); }
.tree button.f { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; font-family: var(--mono); font-size: 12px; color: var(--muted); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree button.f:hover { background: var(--panel); color: var(--text); }
.tree button.f.on { background: var(--ember-bg); color: var(--ember-2); }
.tree button.f.dirty::after { content: ' •'; color: var(--ember); }
.code-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.code-head { height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.code-head .spacer { flex: 1; }
.code-area { flex: 1; display: flex; min-height: 0; overflow: hidden; }
.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; background: var(--bg); }
.code-area textarea { flex: 1; border: 0; outline: none; resize: none; background: var(--bg); color: #e7e0d8; font: 12.5px/1.6 var(--mono); padding: 12px; white-space: pre; overflow: auto; tab-size: 2; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 360px; max-width: 100%; background: var(--panel); border-left: 1px solid var(--line-2); z-index: 30; display: flex; flex-direction: column; box-shadow: -20px 0 50px -20px #000; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 22px; flex: 1; }
.drawer-body { overflow-y: auto; padding: 8px; }
.ver { padding: 10px; border-radius: 8px; display: flex; gap: 10px; align-items: flex-start; }
.ver:hover { background: var(--panel-2); }
.ver .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--line-2); flex: none; }
.ver.current .dot { background: var(--ember); }
.ver .t { font-size: 13.5px; }
.ver .s { font-size: 12px; color: var(--faint); }
.ver .acts { margin-left: auto; display: flex; gap: 4px; opacity: 0; }
.ver:hover .acts { opacity: 1; }

.publish-box { width: 340px; padding: 14px; }
.publish-box h4 { margin: 0 0 4px; font-size: 14px; }
.publish-box .link { display: flex; gap: 6px; margin: 10px 0; }
.publish-box .link .input { font-family: var(--mono); font-size: 12px; height: 32px; padding: 4px 8px; }

#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); padding: 9px 14px; border-radius: 9px; box-shadow: 0 10px 30px -10px #000; animation: fade .2s; max-width: 90vw; }
.toast.err { border-color: rgba(248, 113, 113, .4); color: #fecaca; }

.banner { background: rgba(251, 191, 36, .08); border-bottom: 1px solid rgba(251, 191, 36, .25); color: #fde68a; font-size: 13px; padding: 7px 20px; text-align: center; }

@media (max-width: 900px) {
  .ebody { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .ebody.show-preview .chat { display: none; }
  .ebody:not(.show-preview) .stage { display: none; }
  .mobile-only { display: inline-flex !important; }
  .hide-mobile { display: none !important; }
  .code { grid-template-columns: 1fr; }
  .tree { max-height: 140px; border-right: 0; border-bottom: 1px solid var(--line); }
}
.mobile-only { display: none !important; }
.file-chip svg, .code-head svg { width: 14px; height: 14px; flex: none; }
@media (max-width: 900px) {
  .ebar { gap: 4px; padding: 0 6px; overflow-x: auto; }
  .ebar .name { max-width: 110px; }
  .ebar .seg button { padding: 0 8px; }
}
