* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6fa; --panel: #fff; --border: #e2e8f0; --text: #1e293b; --muted: #64748b;
  --primary: #16a34a; --primary-dark: #15803d; --accent: #0ea5e9; --danger: #dc2626;
  --radius: 10px;
}
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }

/* login */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg,#065f46,#16a34a); }
.login-card { background: #fff; padding: 40px; border-radius: 16px; width: 360px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { margin-bottom: 8px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card input { width: 100%; margin-bottom: 12px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* layout */
#app { display: flex; height: 100vh; }
#sidebar { width: 220px; background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column; padding: 16px 10px; flex-shrink: 0; }
#sidebar .logo { font-size: 20px; font-weight: 700; color: #fff; padding: 8px 12px 20px; }
#sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
#sidebar a { color: #cbd5e1; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
#sidebar a:hover { background: #1e293b; }
#sidebar a.active { background: var(--primary); color: #fff; }
#content { flex: 1; overflow: auto; padding: 24px; }

/* componentes */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h2 { font-size: 22px; }
.btn { border: none; border-radius: 8px; padding: 9px 16px; font-size: 14px; cursor: pointer; background: #e2e8f0; color: var(--text); }
.btn:hover { filter: brightness(.95); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: inherit; border: 1px solid var(--border); }
.btn.small { padding: 5px 10px; font-size: 12px; }
input, select, textarea { border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin: 10px 0 4px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4,1fr); }
.stat { text-align: center; }
.stat .num { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 13px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #f8fafc; font-size: 12px; text-transform: uppercase; color: var(--muted); }
tr:hover td { background: #f8fafc; }

.tag { display: inline-block; background: #dcfce7; color: #166534; border-radius: 20px; padding: 2px 10px; font-size: 12px; margin: 1px; }
.badge { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.badge.wa { background: #dcfce7; color: #166534; }
.badge.tg { background: #dbeafe; color: #1e40af; }
.badge.evo { background: #fef3c7; color: #92400e; }

/* modal */
#modal-root:not(:empty) { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 520px; max-width: 94vw; max-height: 88vh; overflow: auto; }
.modal h3 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal input, .modal select, .modal textarea { width: 100%; }

#toast { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast-item { background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fadein .2s; }
.toast-item.err { background: var(--danger); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px);} }

/* chat */
.chat-layout { display: flex; gap: 0; height: calc(100vh - 110px); background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.chat-list { width: 300px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.chat-list-item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.chat-list-item:hover, .chat-list-item.active { background: #f0fdf4; }
.chat-list-item .nm { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; }
.chat-list-item .lm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; background: #eef2f7; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 70%; padding: 9px 13px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.in { background: #fff; align-self: flex-start; border-bottom-left-radius: 3px; }
.bubble.out { background: #d1fae5; align-self: flex-end; border-bottom-right-radius: 3px; }
.bubble .tm { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; }

/* builder */
.builder-layout { display: flex; height: calc(100vh - 110px); gap: 12px; overflow-x: auto; }
.node-palette { width: 170px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.palette-item { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; cursor: grab; user-select: none; }
.palette-item:hover { border-color: var(--primary); }
#drawflow { flex: 1; min-width: 480px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); position: relative; }
.node-editor { width: 280px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-y: auto; }
.node-editor input, .node-editor select, .node-editor textarea { width: 100%; }

.drawflow .drawflow-node { background: #fff; border: 2px solid var(--border); border-radius: 10px; padding: 0; width: 200px; font-size: 13px; }
.drawflow .drawflow-node.selected { border-color: var(--primary); }
.df-node-head { padding: 7px 10px; font-weight: 600; border-radius: 8px 8px 0 0; color: #fff; font-size: 12px; }
.df-node-body { padding: 8px 10px; color: var(--muted); font-size: 12px; max-height: 80px; overflow: hidden; }
.df-start .df-node-head { background: #16a34a; }
.df-message .df-node-head { background: #0ea5e9; }
.df-question .df-node-head { background: #8b5cf6; }
.df-condition .df-node-head { background: #f59e0b; }
.df-delay .df-node-head { background: #64748b; }
.df-action .df-node-head { background: #ec4899; }
.df-http_request .df-node-head { background: #334155; }
.df-goto_flow .df-node-head { background: #7c3aed; }
.df-end .df-node-head { background: #dc2626; }
.drawflow .connection .main-path { stroke: #94a3b8; stroke-width: 3px; }
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output { background: #fff; border: 2px solid var(--primary); height: 14px; width: 14px; }

.flex { display: flex; gap: 8px; align-items: center; }
.mt { margin-top: 14px; }
.muted { color: var(--muted); font-size: 13px; }
code.copy { background: #f1f5f9; padding: 4px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; word-break: break-all; display: inline-block; }
.steps-list .step-row { display: grid; grid-template-columns: 90px 1fr 150px 34px; gap: 8px; margin-bottom: 8px; align-items: start; }
