:root {
  --pink: #f8a4c8;
  --pink-light: #fce4ec;
  --pink-dark: #e91e78;
  --bg: #fff5f9;
  --sidebar-bg: #fce4ec;
  --bubble-user: #f8a4c8;
  --bubble-ai: #ffffff;
  --text: #333;
  --text-light: #888;
  --border: #f3d0de;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; }
#app { display: flex; height: 100dvh; }

/* Sidebar */
aside#sidebar {
  width: 220px; background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; gap: 16px; flex-shrink: 0;
}
.sidebar-header {
  font-size: 20px; font-weight: 700; color: var(--pink-dark); text-align: center; padding: 8px 0;
}
.section-label { font-size: 11px; text-transform: uppercase; color: var(--text-light); margin-bottom: 6px; }
.agent-item {
  padding: 10px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 4px;
  transition: background 0.15s; font-size: 14px;
}
.agent-item:hover { background: rgba(248,164,200,0.2); }
.agent-item.active { background: var(--pink); color: #fff; font-weight: 600; }
.agent-desc { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.status-text { font-size: 13px; color: var(--text-light); }
.model-text { font-size: 11px; color: var(--text-light); margin-top: 4px; }
.cost-text { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

/* Main */
main#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Chat log */
.chat-log {
  flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.history-load {
  display: flex;
  justify-content: center;
  padding: 4px 0;
  align-self: stretch;
}
.history-load-btn {
  background: transparent;
  color: var(--pink-dark);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
}
.history-load-btn:hover { background: rgba(248,164,200,0.16); }
.msg { display: flex; max-width: 80%; }
.msg-user { align-self: flex-end; }
.msg-ai { align-self: flex-start; }
.msg-bubble {
  padding: 10px 16px; border-radius: var(--radius); font-size: 14px; line-height: 1.6;
  word-break: break-word; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.msg-user .msg-bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 4px; }
.msg-ai .msg-bubble { background: var(--bubble-ai); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-ai .msg-bubble pre { background: #f8f0f4; padding: 8px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.msg-ai .msg-bubble code { font-size: 13px; font-family: 'Fira Code', monospace; }
.msg-ai .msg-bubble pre code { background: none; padding: 0; }
.msg-ai .msg-bubble code:not(pre code) { background: #f8f0f4; padding: 1px 5px; border-radius: 4px; }

/* System / error */
.msg-system { text-align: center; font-size: 12px; color: var(--text-light); padding: 4px 0; }
.msg-error { text-align: center; font-size: 12px; color: #e53935; padding: 4px 0; }

/* Tool display - V99 style */
.msg-tool-inline {
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-light);
  padding: 4px 0; align-self: flex-start;
}
.tool-spinner {
  width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--pink);
  border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tool-done-icon { color: #4caf50; font-weight: 700; font-size: 13px; }
.msg-tool { font-size: 12px; color: var(--text-light); align-self: flex-start; margin: 2px 0; }
.msg-tool summary { cursor: pointer; padding: 2px 0; }
.msg-tool-body { background: #f8f0f4; padding: 8px; border-radius: 6px; margin-top: 4px; font-family: monospace; white-space: pre-wrap; word-break: break-all; max-height: 200px; overflow-y: auto; }

/* Thinking */
.msg-thinking {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-light);
  padding: 6px 0; align-self: flex-start;
}
.thinking-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--pink);
  animation: blink 1.2s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Input */
.chat-form { padding: 12px 20px; padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: #fff; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
#msgInput {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; font-family: var(--font); outline: none;
  max-height: 120px; line-height: 1.4;
}
#msgInput:focus { border-color: var(--pink); box-shadow: 0 0 0 2px rgba(248,164,200,0.2); }
.send-btn {
  background: var(--pink); color: #fff; border: none; border-radius: 10px;
  padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.send-btn:hover { background: var(--pink-dark); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.send-btn.stop-mode { background: #e53935; }
.send-btn.stop-mode:hover { background: #c62828; }
.interrupt-btn {
  background: #e53935; color: #fff; border: none; border-radius: 10px;
  padding: 10px 16px; font-size: 14px; cursor: pointer;
}
.hidden { display: none !important; }

/* Mobile */
@media (max-width: 768px) {
  body { height: 100dvh; }
  #app { height: 100dvh; }
  aside#sidebar {
    position: fixed; z-index: 100; top: 0; bottom: 0; left: 0; width: min(82vw, 320px);
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    border-right: 1px solid var(--border); transform: translateX(-100%);
    transition: transform 0.15s ease-out; box-shadow: 0 10px 24px rgba(0,0,0,0.12);
  }
  aside#sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,0.18);
  }
  .sidebar-toggle {
    display: block; position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
    z-index: 80; background: var(--pink); color: #fff; border: none; border-radius: 10px;
    padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
  }
  main#main { padding-top: 44px; }
  .chat-log { padding: 12px; gap: 10px; }
  .chat-form { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .input-row { gap: 6px; }
  #msgInput { font-size: 16px; padding: 10px 12px; }
  .send-btn, .interrupt-btn { padding: 10px 12px; }
  .msg { max-width: 90%; }
}

/* Scrollbar */
.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chat-log::-webkit-scrollbar-thumb:hover { background: var(--pink); }
