/* ================================================================
   Beppe Ajan — Stiller
   ================================================================ */


  :root {
    --bg: #08080e;
    --surface: #0f0f18;
    --surface2: #14141f;
    --surface3: #1a1a28;
    --border: #1c1c2e;
    --border2: #262638;
    --text: #e8e8f4;
    --text2: #7878a0;
    --text3: #44445a;
    --ai: #06b6d4;
    --ai2: #22d3ee;
    --ai-bg: rgba(6,182,212,0.08);
    --ai-glow: rgba(6,182,212,0.15);
    --ai-glow2: rgba(6,182,212,0.25);
    --accent: #7c3aed;
    --accent2: #a78bfa;
    --accent-bg: rgba(124,58,237,0.1);
    --green: #10b981;
    --green-bg: rgba(16,185,129,0.1);
    --red: #f43f5e;
    --red-bg: rgba(244,63,94,0.1);
    --yellow: #f59e0b;
    --yellow-bg: rgba(245,158,11,0.1);
    --orange: #f97316;
    --orange-bg: rgba(249,115,22,0.1);
    --radius: 14px;
    --radius-sm: 9px;
    --sat: env(safe-area-inset-top,    0px);
    --sar: env(safe-area-inset-right,  0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left,   0px);
  }
  * { margin:0; padding:0; box-sizing:border-box; scroll-behavior:smooth; }
  html { height: 100%; scroll-behavior:smooth; }
  body {
    font-family:'Inter',system-ui,-apple-system,sans-serif;
    background:var(--bg); color:var(--text);
    height:100vh; display:flex; overflow:hidden; min-height:0;
  }

  /* ── SIDEBAR ── */
  .sidebar {
    width:260px; height:100vh; background:var(--surface);
    border-right:1px solid var(--border);
    display:flex; flex-direction:column; flex-shrink:0;
  }
  .logo {
    padding:22px 18px; border-bottom:1px solid var(--border);
    display:flex; align-items:center; gap:12px;
  }
  .logo-icon {
    width:38px; height:38px; flex-shrink:0;
    background:linear-gradient(135deg,var(--accent),var(--ai));
    border-radius:12px; display:flex; align-items:center; justify-content:center;
    font-size:18px; box-shadow:0 4px 16px var(--ai-glow);
  }
  .logo-text { font-size:15px; font-weight:800; letter-spacing:-.3px; }
  .logo-sub { font-size:10px; color:var(--text3); margin-top:1px; text-transform:uppercase; letter-spacing:.08em; }

  /* Agent selector */
  .agent-section { padding:14px 12px; border-bottom:1px solid var(--border); }
  .section-label { font-size:10px; font-weight:700; color:var(--text3); text-transform:uppercase; letter-spacing:.08em; padding:0 6px; margin-bottom:8px; }
  .agent-card {
    padding:10px 12px; border-radius:10px; cursor:pointer;
    display:flex; align-items:center; gap:10px; margin-bottom:4px;
    border:1px solid transparent; transition:all .15s;
  }
  .agent-card:hover { background:var(--surface2); }
  .agent-card.active { background:var(--ai-bg); border-color:rgba(6,182,212,0.2); }
  .agent-avatar {
    width:32px; height:32px; border-radius:9px; flex-shrink:0;
    display:flex; align-items:center; justify-content:center; font-size:15px;
  }
  .agent-name { font-size:13px; font-weight:600; color:var(--text); }
  .agent-role { font-size:11px; color:var(--text2); }
  .agent-status {
    margin-left:auto; width:7px; height:7px; border-radius:50%;
    background:var(--text3); flex-shrink:0;
  }
  .agent-status.online { background:var(--green); box-shadow:0 0 6px var(--green); animation:agentPulse 2s infinite; }
  .agent-status.busy  { background:#f59e0b; box-shadow:0 0 8px #f59e0b; animation:agentBusy .7s infinite; }
  @keyframes agentPulse { 0%,100%{opacity:1}50%{opacity:.4} }
  @keyframes agentBusy  { 0%,100%{transform:scale(1)}50%{transform:scale(1.5)} }

  /* Memory panel */
  .memory-section { padding:12px; border-bottom:1px solid var(--border); flex:1; overflow:hidden; display:flex; flex-direction:column; }
  .memory-list { overflow-y:auto; flex:1; }
  .memory-item {
    display:flex; align-items:flex-start; gap:8px; padding:8px 6px;
    border-radius:8px; margin-bottom:2px; font-size:11.5px;
    color:var(--text2); cursor:pointer; transition:background .1s;
  }
  .memory-item:hover { background:var(--surface2); }
  .memory-icon { font-size:13px; margin-top:1px; flex-shrink:0; }
  .memory-text { line-height:1.5; }
  .memory-time { font-size:10px; color:var(--text3); margin-top:2px; }

  /* Tool section */
  .tools-section { padding:12px; border-bottom:1px solid var(--border); }
  .tool-chip {
    display:inline-flex; align-items:center; gap:5px; padding:4px 10px;
    background:var(--surface2); border:1px solid var(--border2); border-radius:20px;
    font-size:11px; color:var(--text2); cursor:pointer; margin:3px;
    transition:all .15s;
  }
  .tool-chip:hover { background:var(--ai-bg); border-color:var(--ai); color:var(--ai); }
  .tool-chip.active { background:var(--ai-bg); border-color:var(--ai); color:var(--ai); }

  /* Footer */
  .sidebar-footer { padding:12px; }
  .api-btn {
    width:100%; padding:9px 12px; background:var(--surface2);
    border:1px solid var(--border2); border-radius:10px; cursor:pointer;
    display:flex; align-items:center; gap:8px; font-size:12px;
    color:var(--text2); transition:all .15s;
  }
  .api-btn:hover { border-color:var(--ai); color:var(--ai); background:var(--ai-bg); }
  .api-dot { width:7px; height:7px; border-radius:50%; background:var(--text3); flex-shrink:0; transition:all .3s; }
  .api-dot.on { background:var(--ai); box-shadow:0 0 8px var(--ai); }

  /* ── MAIN ── */
  .main { flex:1; display:flex; flex-direction:column; height:100vh; overflow:hidden; min-height:0; }

  /* Topbar */
  .topbar {
    height:56px; background:var(--surface); border-bottom:1px solid var(--border);
    display:flex; align-items:center; padding:0 20px; gap:12px; flex-shrink:0;
  }
  .topbar-agent { display:flex; align-items:center; gap:10px; }
  .ta-avatar { width:30px; height:30px; border-radius:8px; display:flex; align-items:center; justify-content:center; font-size:15px; }
  .ta-name { font-size:14px; font-weight:700; }
  .ta-mode { font-size:11px; color:var(--text2); }
  .topbar-right { margin-left:auto; display:flex; align-items:center; gap:8px; }

  .btn {
    display:inline-flex; align-items:center; gap:6px; padding:7px 14px;
    border-radius:var(--radius-sm); font-size:13px; font-weight:500;
    cursor:pointer; transition:all .15s; border:none;
  }
  .btn-primary { background:var(--accent); color:#fff; }
  .btn-primary:hover { opacity:.9; box-shadow:0 0 16px var(--accent-bg); }
  .btn-ai { background:linear-gradient(135deg,var(--ai),var(--accent)); color:#fff; }
  .btn-ai:hover { opacity:.9; box-shadow:0 0 24px var(--ai-glow2); }
  .btn-ghost { background:transparent; color:var(--text2); border:1px solid var(--border2); }
  .btn-ghost:hover { background:var(--surface2); color:var(--text); }
  .btn-sm { padding:5px 11px; font-size:12px; }
  .btn-xs { padding:3px 8px; font-size:11px; }
  .btn-danger { background:var(--red-bg); color:var(--red); border:1px solid rgba(244,63,94,.2); }
  .btn-danger:hover { background:var(--red); color:#fff; }

  /* ── PANELS ── */
  .panels { flex:1; display:flex; overflow:hidden; min-height:0; }

  /* Chat panel */
  .chat-panel { flex:1; display:flex; flex-direction:column; overflow:hidden; min-width:0; min-height:0; }

  /* Step tracker */
  .step-tracker {
    background:var(--surface2); border-bottom:1px solid var(--border);
    padding:10px 20px; display:none; overflow-x:auto;
  }
  .step-tracker.visible { display:flex; align-items:center; gap:0; }
  .step { display:flex; align-items:center; gap:8px; flex-shrink:0; }
  .step-dot {
    width:26px; height:26px; border-radius:50%; border:2px solid var(--border2);
    display:flex; align-items:center; justify-content:center; font-size:10px;
    font-weight:700; color:var(--text3); flex-shrink:0; transition:all .3s;
  }
  .step-dot.done { background:var(--green); border-color:var(--green); color:#fff; }
  .step-dot.active { background:var(--ai-bg); border-color:var(--ai); color:var(--ai); animation:stepPulse 1.5s infinite; }
  .step-dot.pending { border-color:var(--border2); }
  @keyframes stepPulse { 0%,100%{box-shadow:0 0 0 0 var(--ai-glow)} 50%{box-shadow:0 0 0 4px var(--ai-glow)} }
  .step-label { font-size:11px; color:var(--text2); white-space:nowrap; }
  .step-arrow { color:var(--text3); font-size:12px; margin:0 4px; }

  /* Messages */
  .messages {
    flex:1; overflow-y:auto; padding:24px 20px;
    display:flex; flex-direction:column; gap:20px; min-height:0;
  }

  .msg { display:flex; gap:12px; max-width:80%; contain:layout style; }
  .msg.user { align-self:flex-end; flex-direction:row-reverse; }
  .msg.system { align-self:center; max-width:90%; }

  .msg-avatar {
    width:32px; height:32px; border-radius:9px; flex-shrink:0;
    display:flex; align-items:center; justify-content:center; font-size:14px; font-weight:700;
  }
  .msg.ai .msg-avatar { background:linear-gradient(135deg,var(--accent),var(--ai)); color:#fff; }
  .msg.user .msg-avatar { background:var(--surface3); border:1px solid var(--border2); }
  .msg.tool .msg-avatar { background:var(--accent-bg); border:1px solid rgba(124,58,237,.3); font-size:16px; }

  .msg-body { display:flex; flex-direction:column; gap:6px; }

  .msg-bubble {
    padding:13px 16px; border-radius:14px; font-size:13.5px; line-height:1.7;
  }
  .msg.ai .msg-bubble {
    background:var(--surface2); border:1px solid var(--border2);
    border-radius:4px 14px 14px 14px; color:var(--text);
  }
  .msg.user .msg-bubble {
    background:linear-gradient(135deg,var(--accent),#6d28d9);
    color:#fff; border-radius:14px 4px 14px 14px;
  }
  .msg.tool .msg-bubble {
    background:var(--accent-bg); border:1px solid rgba(124,58,237,.2);
    border-radius:8px; font-family:monospace; font-size:12px; color:var(--accent2);
  }
  .msg.system .msg-bubble {
    background:var(--surface2); border:1px solid var(--border);
    border-radius:10px; font-size:12px; color:var(--text2); text-align:center; padding:8px 16px;
  }

  .msg-meta { font-size:10px; color:var(--text3); display:flex; align-items:center; gap:6px; }
  .msg.user .msg-meta { justify-content:flex-end; }

  /* Streaming cursor */
  .stream-cursor {
    display:inline-block; width:2px; height:14px; background:var(--ai);
    margin-left:2px; vertical-align:middle; animation:blink .7s infinite;
  }
  @keyframes blink { 0%,100%{opacity:1}50%{opacity:0} }

  /* Thinking badge */
  .thinking-badge {
    display:inline-flex; align-items:center; gap:5px;
    font-size:11px; color:var(--accent2); background:var(--accent-bg);
    border:1px solid rgba(108,99,255,.25); border-radius:20px;
    padding:3px 10px; margin-bottom:8px; animation:agentPulse 1.5s infinite;
  }

  /* Typing */
  .typing { display:flex; align-items:center; gap:5px; padding:14px 18px; }
  .typing-dot { width:6px; height:6px; border-radius:50%; background:var(--ai); animation:typingB 1.2s infinite; }
  .typing-dot:nth-child(2){animation-delay:.2s}
  .typing-dot:nth-child(3){animation-delay:.4s}
  @keyframes typingB{0%,80%,100%{transform:translateY(0)}40%{transform:translateY(-6px)}}

  /* Tool call card */
  .tool-call {
    background:var(--surface2); border:1px solid var(--border2);
    border-radius:10px; padding:10px 14px; font-size:12px; margin:4px 0;
    display:flex; align-items:flex-start; gap:10px;
  }
  .tool-call-icon { font-size:16px; flex-shrink:0; margin-top:1px; }
  .tool-call-name { font-weight:700; color:var(--ai); margin-bottom:2px; }
  .tool-call-body { color:var(--text2); line-height:1.5; }

  /* Result card */
  .result-card {
    background:var(--surface3); border:1px solid var(--border2);
    border-left:3px solid var(--ai); border-radius:0 10px 10px 0;
    padding:12px 14px; font-size:12.5px; margin:4px 0; color:var(--text);
    line-height:1.7;
  }
  .result-card.green { border-left-color:var(--green); }
  .result-card.red { border-left-color:var(--red); }
  .result-card.yellow { border-left-color:var(--yellow); }

  /* Input area */
  .input-area {
    padding:16px 20px; background:var(--surface); border-top:1px solid var(--border);
    flex-shrink:0; padding-bottom:max(16px, calc(16px + var(--sab)));
    padding-left:max(20px, calc(20px + var(--sal)));
    padding-right:max(20px, calc(20px + var(--sar)));
  }
  .quick-actions { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:10px; }
  .qa-btn {
    padding:5px 12px; background:var(--surface2); border:1px solid var(--border2);
    border-radius:20px; font-size:11.5px; color:var(--text2); cursor:pointer; transition:all .15s;
    white-space:nowrap;
  }
  .qa-btn:hover { background:var(--ai-bg); border-color:rgba(6,182,212,.4); color:var(--ai2); }

  .input-row {
    display:flex; gap:10px; background:var(--surface2); border:1px solid var(--border2);
    border-radius:12px; padding:4px 4px 4px 14px; align-items:flex-end;
    transition:border-color .2s;
  }
  .input-row:focus-within { border-color:var(--ai); box-shadow:0 0 0 3px var(--ai-glow); }
  .input-row textarea {
    flex:1; background:transparent; border:none; outline:none; resize:none;
    color:var(--text); font-size:13.5px; font-family:inherit; line-height:1.5;
    padding:8px 0; min-height:42px; max-height:160px;
  }
  .input-row textarea::placeholder { color:var(--text3); }
  .input-row textarea::-webkit-scrollbar { display:none; }
  .send-btn {
    width:38px; height:38px; border-radius:9px; flex-shrink:0;
    background:linear-gradient(135deg,var(--ai),var(--accent));
    border:none; cursor:pointer; display:flex; align-items:center; justify-content:center;
    font-size:16px; transition:all .15s; margin:2px;
  }
  .send-btn:hover { opacity:.9; box-shadow:0 0 16px var(--ai-glow2); }
  .send-btn:disabled { opacity:.4; cursor:not-allowed; }
  .send-all-btn {
    height:38px; padding:0 12px; border-radius:9px; flex-shrink:0;
    background:linear-gradient(135deg,#f59e0b,#f43f5e);
    border:none; cursor:pointer; font-size:11px; font-weight:700;
    color:#fff; white-space:nowrap; transition:all .15s; margin:2px;
    letter-spacing:.02em;
  }
  .send-all-btn:hover { opacity:.9; box-shadow:0 0 14px rgba(245,158,11,.4); }
  .send-all-btn:disabled { opacity:.4; cursor:not-allowed; }

  /* ── RIGHT PANEL (Tasks / Context) ── */
  .right-panel {
    width:300px; border-left:1px solid var(--border);
    background:var(--surface); display:flex; flex-direction:column; overflow:hidden;
    flex-shrink:0;
  }
  .rp-tabs { display:flex; border-bottom:1px solid var(--border); }
  .rp-tab {
    flex:1; padding:12px 8px; text-align:center; font-size:12px; font-weight:600;
    color:var(--text3); cursor:pointer; border-bottom:2px solid transparent; transition:all .15s;
  }
  .rp-tab.active { color:var(--ai); border-bottom-color:var(--ai); }
  .rp-body { flex:1; overflow-y:auto; padding:14px; }

  /* Task item */
  .task-item {
    background:var(--surface2); border:1px solid var(--border2); border-radius:10px;
    padding:12px 14px; margin-bottom:8px; position:relative; overflow:hidden;
  }
  .task-item::before { content:''; position:absolute; left:0; top:0; bottom:0; width:3px; border-radius:3px 0 0 3px; }
  .task-item.pending::before { background:var(--text3); }
  .task-item.running::before { background:var(--ai); animation:taskGlow 1.5s infinite; }
  .task-item.done::before { background:var(--green); }
  .task-item.error::before { background:var(--red); }
  @keyframes taskGlow { 0%,100%{opacity:1}50%{opacity:.3} }
  .task-title { font-size:12.5px; font-weight:600; color:var(--text); margin-bottom:4px; }
  .task-sub { font-size:11px; color:var(--text2); line-height:1.5; }
  .task-status { font-size:10px; font-weight:700; margin-top:6px; }
  .task-status.pending { color:var(--text3); }
  .task-status.running { color:var(--ai); }
  .task-status.done { color:var(--green); }
  .task-status.error { color:var(--red); }

  /* Context cards */
  .ctx-card {
    background:var(--surface2); border:1px solid var(--border2); border-radius:10px;
    padding:12px 14px; margin-bottom:8px;
  }
  .ctx-title { font-size:11px; font-weight:700; color:var(--text3); text-transform:uppercase; letter-spacing:.06em; margin-bottom:8px; }
  .ctx-row { display:flex; justify-content:space-between; font-size:12px; margin-bottom:4px; }
  .ctx-key { color:var(--text2); }
  .ctx-val { color:var(--text); font-weight:500; font-family:monospace; }

  /* Modal */
  .modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.8); backdrop-filter:blur(6px); z-index:100; display:none; align-items:center; justify-content:center; }
  .modal-overlay.open { display:flex; }
  .modal { background:var(--surface); border:1px solid var(--border2); border-radius:18px; width:100%; max-width:480px; box-shadow:0 24px 80px rgba(0,0,0,0.6); animation:mIn .2s ease; }
  @keyframes mIn { from{opacity:0;transform:scale(.95) translateY(10px)} to{opacity:1;transform:none} }
  .modal-header { padding:20px 22px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
  .modal-title { font-size:15px; font-weight:700; }
  .modal-close { width:28px; height:28px; border-radius:7px; background:var(--surface2); border:1px solid var(--border); cursor:pointer; display:flex; align-items:center; justify-content:center; color:var(--text2); transition:all .15s; }
  .modal-close:hover { background:var(--red-bg); color:var(--red); }
  .modal-body { padding:22px; }
  .modal-footer { padding:14px 22px; border-top:1px solid var(--border); display:flex; gap:8px; justify-content:flex-end; }
  .form-group { margin-bottom:14px; }
  label { font-size:12px; font-weight:500; color:var(--text2); display:block; margin-bottom:5px; }
  input, select, textarea { width:100%; background:var(--surface2); border:1px solid var(--border2); border-radius:var(--radius-sm); padding:8px 12px; color:var(--text); font-size:13px; font-family:inherit; outline:none; transition:border-color .15s; }
  input:focus, select:focus, textarea:focus { border-color:var(--ai); box-shadow:0 0 0 3px var(--ai-glow); }
  select option { background:var(--surface2); }

  /* Scrollbar */
  ::-webkit-scrollbar { width:4px; height:4px; }
  ::-webkit-scrollbar-track { background:transparent; }
  ::-webkit-scrollbar-thumb { background:var(--border2); border-radius:2px; }

  /* Badge */
  .badge { display:inline-flex; align-items:center; gap:4px; padding:2px 8px; border-radius:20px; font-size:10.5px; font-weight:700; }
  .badge-ai { background:var(--ai-bg); color:var(--ai2); }
  .badge-green { background:var(--green-bg); color:var(--green); }
  .badge-red { background:var(--red-bg); color:var(--red); }
  .badge-yellow { background:var(--yellow-bg); color:var(--yellow); }
  .badge-purple { background:var(--accent-bg); color:var(--accent2); }

  .divider { height:1px; background:var(--border); margin:12px 0; }
  .ai-color { color:var(--ai2); }
  .mono { font-family:monospace; }

  /* Welcome */
  .welcome {
    flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center;
    padding:40px; text-align:center; gap:16px;
  }
  .welcome-icon {
    width:72px; height:72px; border-radius:20px;
    background:linear-gradient(135deg,var(--accent),var(--ai));
    display:flex; align-items:center; justify-content:center; font-size:32px;
    box-shadow:0 8px 40px var(--ai-glow2); animation:welcomeFloat 3s ease-in-out infinite;
  }
  @keyframes welcomeFloat { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
  .welcome h2 { font-size:22px; font-weight:800; }
  .welcome p { font-size:13px; color:var(--text2); max-width:380px; line-height:1.7; }
  .welcome-chips { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; margin-top:8px; }
  .w-chip {
    padding:8px 16px; background:var(--surface2); border:1px solid var(--border2);
    border-radius:24px; font-size:12.5px; color:var(--text2); cursor:pointer; transition:all .2s;
  }
  .w-chip:hover { background:var(--ai-bg); border-color:rgba(6,182,212,.3); color:var(--ai2); transform:translateY(-2px); }
