:root {
  --bg: #0d0d0f;
  --bg2: #16161a;
  --bg3: #1e1e24;
  --border: #2a2a35;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --text: #e8e8f0;
  --text-muted: #888899;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* LOGIN */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: radial-gradient(ellipse at center, #1a0a2e 0%, var(--bg) 70%); }
.login-box { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 48px 40px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.logo { font-size: 1.1rem; color: var(--accent); font-weight: 700; margin-bottom: 8px; letter-spacing: 0.05em; }
.login-box h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 32px; }
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.field input { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--text); font-size: 0.95rem; outline: none; transition: border 0.2s; }
.field input:focus { border-color: var(--accent); }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-bottom: 12px; padding: 8px 12px; background: rgba(239,68,68,0.1); border-radius: 6px; }
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }
#login-btn { width: 100%; background: var(--accent); color: white; border: none; border-radius: var(--radius); padding: 13px; font-size: 0.95rem; font-weight: 600; margin-top: 8px; transition: background 0.2s; }
#login-btn:hover { background: var(--accent-hover); }

/* DASHBOARD */
#dashboard-screen { display: flex; height: 100vh; }
.sidebar { width: 220px; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 24px 0; flex-shrink: 0; }
.sidebar-logo { font-size: 1rem; font-weight: 700; color: var(--accent); padding: 0 20px 24px; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.nav-links { list-style: none; flex: 1; }
.nav-links li { margin: 2px 8px; }
.nav-link { display: block; padding: 10px 14px; border-radius: 8px; color: var(--text-muted); text-decoration: none; font-size: 0.9rem; transition: background 0.15s, color 0.15s; }
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: rgba(124,58,237,0.15); color: var(--accent); font-weight: 600; }
.sidebar-footer { padding: 16px 20px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
#user-display { font-size: 0.8rem; color: var(--text-muted); }
#logout-btn { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; padding: 8px; font-size: 0.8rem; transition: all 0.2s; }
#logout-btn:hover { border-color: var(--danger); color: var(--danger); }
.content { flex: 1; overflow-y: auto; padding: 32px; }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.view-header h2 { font-size: 1.4rem; font-weight: 600; }

.btn-primary { background: var(--accent); color: white; border: none; border-radius: 8px; padding: 9px 18px; font-size: 0.85rem; font-weight: 600; transition: background 0.2s; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* AGENTS GRID */
.agents-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.agent-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; padding: 22px; cursor: pointer; transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s; }
.agent-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 30px rgba(124,58,237,0.15); }
.agent-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.agent-name { font-weight: 600; font-size: 1rem; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.error { background: var(--danger); }
.agent-desc { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 14px; min-height: 20px; line-height: 1.4; }
.agent-actions { display: flex; gap: 8px; margin-top: 12px; }
.agent-chat-hint { font-size: 0.75rem; color: var(--accent); margin-top: 10px; opacity: 0.7; }
.btn-sm { padding: 6px 12px; border-radius: 6px; font-size: 0.78rem; font-weight: 600; border: 1px solid var(--border); background: transparent; color: var(--text-muted); transition: all 0.15s; }
.btn-sm:hover { background: var(--bg3); color: var(--text); }
.btn-sm.danger:hover { border-color: var(--danger); color: var(--danger); }
.empty-state { text-align: center; color: var(--text-muted); padding: 60px 20px; grid-column: 1 / -1; }

/* TABLE */
.data-table { width: 100%; border-collapse: collapse; background: var(--bg2); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.data-table th { background: var(--bg3); padding: 12px 16px; text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 16px; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.admin { background: rgba(124,58,237,0.2); color: var(--accent); }
.badge.user { background: rgba(136,136,153,0.15); color: var(--text-muted); }

/* TOGGLE VIEW */
.view-toggle { display:flex; gap:4px; background:var(--bg3); border-radius:8px; padding:3px; border:1px solid var(--border); }
.toggle-btn { background:transparent; border:none; color:var(--text-muted); border-radius:6px; padding:6px 12px; font-size:0.8rem; font-weight:500; transition:all 0.15s; }
.toggle-btn.active { background:var(--bg2); color:var(--text); box-shadow:0 1px 3px rgba(0,0,0,0.3); }

/* ORGANIGRAMA */
.agents-org { width:100%; overflow:auto; min-height:400px; }
.org-svg { display:block; margin:0 auto; }

.org-node { cursor:pointer; }
.org-node rect {
  fill: var(--bg2);
  stroke: var(--border);
  stroke-width: 1.5;
  rx: 10; ry: 10;
  transition: fill 0.2s, stroke 0.2s;
}
.org-node:hover rect { fill: var(--bg3); stroke: var(--accent); }
.org-node.master rect { stroke: var(--accent); stroke-width: 2; fill: rgba(124,58,237,0.12); }
.org-node text { fill: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; pointer-events: none; }
.org-node .node-name { font-size: 13px; font-weight: 600; }
.org-node .node-desc { font-size: 10px; fill: var(--text-muted); }
.org-node .node-status { font-size: 9px; }
.org-connector { stroke: var(--border); stroke-width: 1.5; fill: none; }
.org-node.online rect { stroke: var(--success); }
.org-node.online.master rect { stroke: var(--accent); }

/* MODAL genérico */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(4px); }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; width: 420px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: transparent; border: none; color: var(--text-muted); font-size: 1rem; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { color: var(--text); }
#modal-body { padding: 24px; }
.modal-field { margin-bottom: 16px; }
.modal-field label { display: block; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.modal-field input, .modal-field select { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 0.9rem; outline: none; font-family: inherit; }
.modal-field input:focus, .modal-field select:focus { border-color: var(--accent); }
.modal-field select option { background: var(--bg3); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.btn-cancel { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; padding: 9px 18px; font-size: 0.85rem; transition: all 0.15s; }
.btn-cancel:hover { border-color: var(--text-muted); color: var(--text); }

/* MODAL AGENTE */
.modal-agent { width: 780px; max-width: 96vw; height: 82vh; display: flex; flex-direction: column; }
.agent-modal-header { display: flex; align-items: center; gap: 16px; padding: 18px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.agent-modal-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.agent-modal-info h3 { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.am-desc { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.agent-modal-tabs { display: flex; gap: 4px; }
.am-tab { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; padding: 7px 14px; font-size: 0.82rem; font-weight: 500; transition: all 0.15s; }
.am-tab:hover { background: var(--bg3); color: var(--text); }
.am-tab.active { background: rgba(124,58,237,0.15); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.am-tab-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Chat */
.am-messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.am-message { max-width: 78%; display: flex; flex-direction: column; gap: 4px; }
.am-message.user { align-self: flex-end; }
.am-message.assistant { align-self: flex-start; }
.am-bubble { padding: 11px 16px; border-radius: 14px; font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.am-message.user .am-bubble { background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.am-message.assistant .am-bubble { background: var(--bg3); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.am-time { font-size: 0.7rem; color: var(--text-muted); padding: 0 4px; }
.am-message.user .am-time { text-align: right; }
.am-typing { align-self: flex-start; display: flex; gap: 5px; align-items: center; padding: 12px 16px; background: var(--bg3); border: 1px solid var(--border); border-radius: 14px; border-bottom-left-radius: 4px; }
.am-typing span { width: 7px; height: 7px; background: var(--text-muted); border-radius: 50%; animation: typing 1.2s infinite; }
.am-typing span:nth-child(2) { animation-delay: 0.2s; }
.am-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100%{opacity:.3;transform:scale(1)} 30%{opacity:1;transform:scale(1.2)} }
.am-empty-chat { text-align: center; color: var(--text-muted); padding: 40px 20px; font-size: 0.9rem; }
.am-input-bar { display: flex; gap: 10px; padding: 12px 24px; border-top: 1px solid var(--border); align-items: flex-end; }
#am-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--text); font-size: 0.9rem; outline: none; resize: none; font-family: inherit; max-height: 120px; }
#am-input:focus { border-color: var(--accent); }
#am-send { background: var(--accent); color: white; border: none; border-radius: 10px; width: 42px; height: 42px; font-size: 1rem; flex-shrink: 0; transition: background 0.15s; }
#am-send:hover { background: var(--accent-hover); }
.am-chat-footer { padding: 6px 24px 12px; display: flex; justify-content: flex-end; }

/* Prompt */
#am-tab-prompt { padding: 24px; gap: 14px; }
.am-prompt-info { font-size: 0.82rem; color: var(--text-muted); background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.am-prompt-editor { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 14px; color: var(--text); font-size: 0.88rem; outline: none; resize: none; font-family: 'SF Mono', 'Fira Code', monospace; line-height: 1.6; }
.am-prompt-editor:focus { border-color: var(--accent); }
.am-prompt-actions { display: flex; gap: 10px; }

/* Docs */
#am-tab-docs { padding: 20px 24px; gap: 14px; overflow-y: auto; }
.am-docs-bar { display: flex; justify-content: flex-end; }
.am-docs-list { display: flex; flex-direction: column; gap: 10px; }
.am-doc-item { background: var(--bg3); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.am-doc-info h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; }
.am-doc-info p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.am-doc-empty { color: var(--text-muted); font-size: 0.88rem; text-align: center; padding: 30px; }

/* Misc */
.coming-soon { text-align: center; color: var(--text-muted); padding: 80px 20px; font-size: 1.1rem; }
