:root {
  --canvas: #f1f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #64748b;
  --brand: #1d4ed8;
  --brand-ink: #1e3a8a;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--canvas); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink-2); }
.brand b { color: var(--ink); }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.poc { font-size: 11px; font-weight: 700; color: var(--brand-ink); border: 1px solid #93c5fd; background: #eff6ff; border-radius: 6px; padding: 1px 6px; }

.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .06); }
.login-card label { font-weight: 600; margin-top: 10px; }
.login-card input { border: 1px solid var(--line-strong); border-radius: 10px; padding: 11px 12px; font-size: 15px; }
.login-card button { margin-top: 6px; border: 0; border-radius: 10px; padding: 11px; background: var(--brand); color: #fff; font-weight: 700; }
.login-card button:disabled { background: #94a3b8; cursor: default; }
.login-error { margin: 0; color: var(--bad); font-size: 13px; }

.app { height: 100%; display: grid; grid-template-columns: 370px 1fr; }
.chat { display: flex; flex-direction: column; background: var(--surface-soft); border-right: 1px solid var(--line); min-height: 0; }
.chat-head { padding: 16px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 300px; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; }
.msg.eu { align-self: flex-end; background: var(--brand-ink); color: #fff; }
.msg.ia { background: var(--surface); border: 1px solid var(--line); }
.msg.erro { background: var(--surface); border: 1px solid var(--line-strong); color: var(--bad); }
.msg .retry { display: block; margin-top: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); border-radius: 8px; padding: 4px 10px; font-size: 12.5px; }
.typing { display: inline-flex; gap: 4px; padding: 12px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; animation: blink 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #93c5fd; color: var(--brand-ink); background: #eff6ff; border-radius: 999px; padding: 5px 11px; font-size: 12.5px; }
.chip:hover { background: #dbeafe; }
.ask { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--surface); }
.ask textarea { flex: 1; resize: none; border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 11px; font: inherit; }
.ask button { border: 0; border-radius: 10px; padding: 0 16px; background: var(--brand); color: #fff; font-weight: 700; }
.ask button:disabled { background: #94a3b8; cursor: default; }

.stage { min-width: 0; overflow-y: auto; padding: 18px 22px 28px; }
.board-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.board-head h1 { margin: 0; font-size: 22px; }
.board-subtitle { margin: 2px 0 0; color: var(--ink-3); }
.board-meta { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.sample { font-size: 11.5px; font-weight: 700; color: #92400e; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 6px; padding: 2px 8px; }
.timing { font-size: 12.5px; color: var(--ink-3); }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 52px; grid-auto-flow: row dense; gap: 14px; }
.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; overflow: hidden; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); }
.card.h1 { grid-row: span 2; }
.card.h2 { grid-row: span 5; }
.card.h3 { grid-row: span 8; }
.card .card-title { margin: 0; padding: 11px 14px 0; font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.card .viz { position: relative; flex: 1; min-height: 0; }
.card.loading .viz { margin: 10px 14px 14px; border-radius: 10px; background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.card.ready { animation: arrive .45s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.card.failed .viz { display: grid; place-items: center; color: var(--ink-3); font-size: 13px; padding: 12px; text-align: center; }

.kpi { padding: 4px 14px 10px; display: grid; grid-template-columns: 1fr auto; align-items: end; height: 100%; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; }
.kpi-value small { font-size: 15px; font-weight: 700; color: var(--ink-3); margin-left: 2px; }
.kpi-delta { font-size: 12.5px; font-weight: 700; }
.kpi-delta.good { color: var(--good); }
.kpi-delta.bad { color: var(--bad); }
.kpi-spark { width: 110px; height: 38px; }

.fab-label { background: rgba(255, 255, 255, .95); border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px 9px; font: 11.5px system-ui, sans-serif; color: var(--ink); box-shadow: 0 3px 10px rgba(15, 23, 42, .12); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.fab-label i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.fab-oee { font-weight: 800; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .chat { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .card { grid-column: span 12 !important; }
}

.ask { align-items: stretch; }
.attach { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); border-radius: 10px; width: 42px; display: grid; place-items: center; }
.attach:hover { background: var(--canvas); }
.attach:disabled { opacity: .5; cursor: default; }
.dataset { margin: 0 12px 8px; display: flex; align-items: center; gap: 8px; border: 1px solid #93c5fd; background: #eff6ff; color: var(--brand-ink); border-radius: 10px; padding: 7px 10px; font-size: 12.5px; font-weight: 600; }
.dataset-icon { font-size: 15px; }
.dataset #dataset-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dataset-remove { border: 0; background: transparent; color: var(--brand-ink); font-size: 18px; line-height: 1; padding: 0 2px; }
.chat.dropping { outline: 3px dashed var(--brand); outline-offset: -8px; }
.card .viz iframe.sandbox { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; opacity: 0; transition: opacity .4s ease-out; }
.card.ready .viz iframe.sandbox { opacity: 1; }
.card.ready .viz { margin: 0; background: none; animation: none; }
.builder { position: absolute; left: 18px; right: 18px; bottom: 30px; top: 18px; display: none; align-items: flex-end; gap: 8px; }
.card.building .builder { display: flex; }
.card.h1 .builder { top: 8px; bottom: 26px; }
.builder i { flex: 1; border-radius: 6px 6px 2px 2px; background: linear-gradient(180deg, #93c5fd, #2563eb); opacity: .85; transform-origin: bottom; animation: rise 1.4s ease-in-out infinite; }
.builder i:nth-child(1) { height: 45%; animation-delay: 0s; }
.builder i:nth-child(2) { height: 70%; animation-delay: .12s; }
.builder i:nth-child(3) { height: 55%; animation-delay: .24s; }
.builder i:nth-child(4) { height: 85%; animation-delay: .36s; }
.builder i:nth-child(5) { height: 60%; animation-delay: .48s; }
.builder i:nth-child(6) { height: 75%; animation-delay: .6s; }
.builder i:nth-child(7) { height: 50%; animation-delay: .72s; }
@keyframes rise { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
.card.building .viz { background: var(--surface-soft); animation: none; }
.code-progress { position: absolute; left: 14px; bottom: 7px; font-size: 11.5px; font-weight: 700; color: var(--brand-ink); }
.card.ready .builder, .card.ready .code-progress { display: none; }
.card.failed .code-progress { position: static; display: grid; place-items: center; height: 100%; color: var(--ink-3); font-weight: 600; }
