:root {
  --bg: #0f172a;
  --bg-2: #111c34;
  --panel: #1e293b;
  --panel-2: #243347;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --accent: #22d3ee;
  --seo: #f59e0b;
  --social: #ec4899;
  --wordpress: #38bdf8;
  --b2b: #34d399;
  --sub: #a78bfa;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg-2));
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.login-card, .modal {
  background: var(--panel);
  border: 1px solid #334155;
  border-radius: var(--radius);
  padding: 28px;
  width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.login-card { text-align: center; }
.login-card h1 { margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; }
.login-card input { width: 100%; margin-bottom: 12px; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: rgba(15, 23, 42, 0.6);
  border-right: 1px solid #1f2b45;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 28px; }
.brand strong { display: block; }
.brand small { color: var(--muted); }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-head h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0; }

.hierarchy { display: flex; flex-direction: column; gap: 8px; }

.node {
  background: var(--panel);
  border: 1px solid #2b3a52;
  border-left: 4px solid var(--muted);
  border-radius: 10px;
  padding: 10px 12px;
}
.node.role-seo { border-left-color: var(--seo); }
.node.role-social { border-left-color: var(--social); }
.node.role-wordpress { border-left-color: var(--wordpress); }
.node.role-b2b { border-left-color: var(--b2b); }

.node-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.node-title { display: flex; align-items: center; gap: 8px; }
.node-title .emoji { font-size: 18px; }
.node-title strong { font-size: 14px; }
.node .label { color: var(--muted); font-size: 11px; }
.node .add-sub {
  background: transparent; border: 1px solid #3b4b66; color: var(--muted);
  border-radius: 8px; cursor: pointer; padding: 2px 8px; font-size: 12px;
}
.node .add-sub:hover { color: var(--text); border-color: var(--primary); }

.children { margin: 8px 0 0 14px; display: flex; flex-direction: column; gap: 8px;
  border-left: 2px dashed #2b3a52; padding-left: 10px; }

.subs { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.sub-item {
  background: var(--panel-2);
  border: 1px solid #33415a;
  border-left: 3px solid var(--sub);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.sub-item .meta { color: var(--muted); }
.sub-item .kind { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: #2a2350; color: var(--sub); }
.sub-item .del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; }

.status { margin-top: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.dot.bad { background: var(--danger); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  padding: 16px 22px;
  border-bottom: 1px solid #1f2b45;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.chat-header h2 { margin: 0; font-size: 16px; }
.mention-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid #3b4b66; background: var(--panel);
  color: var(--text); border-radius: 999px; padding: 4px 12px;
  font-size: 12px; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip.seo { border-color: var(--seo); }
.chip.social { border-color: var(--social); }
.chip.wordpress { border-color: var(--wordpress); }
.chip.b2b { border-color: var(--b2b); }
.chip.todos { border-color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }

.msg { max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg .bubble {
  padding: 12px 14px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap;
  border: 1px solid #2b3a52; background: var(--panel);
}
.msg.user .bubble { background: var(--primary); border-color: var(--primary-2); }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 4px 4px; display: flex; align-items: center; gap: 6px; }
.msg.agent.seo .bubble { border-left: 4px solid var(--seo); }
.msg.agent.social .bubble { border-left: 4px solid var(--social); }
.msg.agent.wordpress .bubble { border-left: 4px solid var(--wordpress); }
.msg.agent.b2b .bubble { border-left: 4px solid var(--b2b); }
.msg.subagent .bubble { border-left: 4px solid var(--sub); }
.msg.supervision .bubble {
  background: rgba(245, 158, 11, 0.08);
  border: 1px dashed var(--seo);
}

.typing { color: var(--muted); font-style: italic; }

.composer { display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid #1f2b45; }
.composer textarea { flex: 1; resize: none; }
.hint { padding: 0 22px 14px; color: var(--muted); font-size: 12px; }
.hint code { background: var(--panel); padding: 1px 5px; border-radius: 5px; }

/* ---------- Form elements ---------- */
input, textarea, select {
  background: var(--panel-2);
  border: 1px solid #3b4b66;
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input, label textarea, label select { margin-top: 6px; }

button { font-size: 14px; border-radius: 8px; padding: 10px 16px; cursor: pointer; border: 1px solid transparent; }
button.primary { background: var(--primary); color: white; }
button.primary:hover { background: var(--primary-2); }
button.ghost { background: transparent; border: 1px solid #3b4b66; color: var(--text); }
button.block { width: 100%; }

.modal h2 { margin-top: 0; }
.modal .row { display: flex; gap: 12px; }
.modal .row label { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.error { color: var(--danger); display: block; margin-top: 8px; min-height: 16px; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #33415a; border-radius: 6px; }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
