/* ============================
   TOKENS & RESET
   ============================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #07060D;
  --bg-2:     #0E0B1A;
  --bg-3:     #130F22;
  --bg-card:  rgba(255,255,255,0.04);
  --bg-card-h:rgba(255,255,255,0.07);
  --br:       rgba(255,255,255,0.08);
  --br-2:     rgba(255,255,255,0.12);

  --pink:     #F06292;
  --pink-hl:  #F48FB1;
  --lilac:    #CE93D8;
  --teal:     #4DD0E1;
  --amber:    #FFD54F;
  --green:    #25D366;
  --white:    #FFFFFF;
  --text-1:   #F0EBF8;
  --text-2:   #C5B8DC;
  --text-3:   #8B7BAB;
  --text-4:   #5A4D73;

  --sidebar-w: 260px;
  --topbar-h:  64px;
  --display: 'Space Grotesk', sans-serif;
  --body: 'Inter', sans-serif;

  --radius: 12px;
  --radius-lg: 16px;
}

html, body {
  height: 100%;
  font-family: var(--body);
  background: var(--bg);
  color: var(--text-1);
  overflow: hidden;
}

/* ============================
   LAYOUT
   ============================ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================
   SIDEBAR
   ============================ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--br);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
}

.sidebar__header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--br);
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(240,98,146,0.2), rgba(206,147,216,0.15));
  border: 1px solid rgba(240,98,146,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
  color: var(--white);
}

.logo-sub {
  font-size: 10px;
  color: var(--text-4);
  letter-spacing: 0.04em;
}

.sidebar__section-label {
  padding: 16px 16px 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-4);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ============================
   AGENT BUTTONS
   ============================ */
.agent-list {
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
  text-align: left;
  position: relative;
}

.agent-btn:hover { background: var(--bg-card); }
.agent-btn.active { background: var(--bg-card-h); }

.agent-btn__emoji {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.agent-btn__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.agent-btn__name {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-1);
}

.agent-btn__desc {
  font-size: 11px;
  color: var(--text-3);
}

.agent-btn__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.7;
}

/* ============================
   QUICK ACTIONS
   ============================ */
.quick-actions {
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quick-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-3);
  font-size: 12px;
  text-align: left;
  width: 100%;
  transition: all 0.2s;
  line-height: 1.3;
}

.quick-action-btn:hover {
  background: var(--bg-card);
  color: var(--text-1);
}

.quick-action-btn .qa-icon {
  font-size: 13px;
  flex-shrink: 0;
}

/* ============================
   SIDEBAR FOOTER
   ============================ */
.sidebar__footer {
  margin-top: auto;
  padding: 12px 8px 16px;
  border-top: 1px solid var(--br);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-3);
  font-size: 12px;
  transition: all 0.2s;
}

.sidebar-link:hover { background: var(--bg-card); color: var(--text-1); }

/* ============================
   MAIN AREA
   ============================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ============================
   TOPBAR
   ============================ */
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--br);
  background: rgba(14,11,26,0.8);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar__menu {
  display: none;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.topbar__menu:hover { color: var(--text-1); background: var(--bg-card); }

.topbar__agent {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.topbar__emoji {
  font-size: 24px;
  line-height: 1;
}

.topbar__name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  color: var(--white);
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-3);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar__btn {
  background: none;
  border: 1px solid var(--br);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.2s;
}
.topbar__btn:hover { background: var(--bg-card); color: var(--text-1); border-color: var(--br-2); }

.api-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-4);
}
.api-status.ok { background: #4ade80; }
.api-status.error { background: #EF5350; }

/* ============================
   CHAT AREA
   ============================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 2px; }

/* ============================
   WELCOME SCREEN
   ============================ */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 540px;
  margin: auto;
  padding: 20px;
}

.welcome-emoji {
  font-size: 52px;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 24px rgba(240,98,146,0.4));
}

.chat-welcome h2 {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 800;
  color: var(--white);
  margin-bottom: 12px;
}

.chat-welcome p {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.welcome-hints {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.hint-btn {
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--br);
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  line-height: 1.4;
}
.hint-btn:hover { background: var(--bg-card-h); border-color: var(--br-2); color: var(--text-1); }

/* ============================
   MESSAGES
   ============================ */
.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--user {
  flex-direction: row-reverse;
}

.msg__avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--bg-3);
  border: 1px solid var(--br);
}

.msg--user .msg__avatar {
  background: linear-gradient(135deg, var(--pink), var(--lilac));
  border: none;
  font-size: 14px;
  font-weight: 700;
  color: white;
}

.msg__content {
  flex: 1;
  min-width: 0;
}

.msg--user .msg__content {
  display: flex;
  justify-content: flex-end;
}

.msg__bubble {
  max-width: 85%;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-1);
}

.msg--agent .msg__bubble {
  background: var(--bg-card);
  border: 1px solid var(--br);
  border-radius: 4px 16px 16px 16px;
}

.msg--user .msg__bubble {
  background: linear-gradient(135deg, rgba(240,98,146,0.15), rgba(206,147,216,0.1));
  border: 1px solid rgba(240,98,146,0.2);
  border-radius: 16px 4px 16px 16px;
  color: var(--text-1);
}

/* Markdown styles inside bubble */
.msg__bubble h1, .msg__bubble h2, .msg__bubble h3 {
  color: var(--white);
  font-family: var(--display);
  font-weight: 700;
  margin: 16px 0 8px;
}
.msg__bubble h1 { font-size: 20px; }
.msg__bubble h2 { font-size: 17px; }
.msg__bubble h3 { font-size: 14px; color: var(--text-1); }
.msg__bubble p { margin-bottom: 10px; }
.msg__bubble p:last-child { margin-bottom: 0; }
.msg__bubble strong { color: var(--white); font-weight: 600; }
.msg__bubble em { color: var(--pink-hl); font-style: italic; }
.msg__bubble ul, .msg__bubble ol { padding-left: 20px; margin-bottom: 10px; }
.msg__bubble li { margin-bottom: 4px; }
.msg__bubble code {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--br);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
  font-size: 13px;
  color: var(--teal);
}
.msg__bubble pre {
  background: var(--bg-3);
  border: 1px solid var(--br);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.msg__bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-1);
  font-size: 13px;
}
.msg__bubble blockquote {
  border-left: 3px solid var(--pink);
  padding-left: 12px;
  color: var(--text-2);
  margin: 10px 0;
}
.msg__bubble hr {
  border: none;
  border-top: 1px solid var(--br);
  margin: 16px 0;
}
.msg__bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 12px 0;
}
.msg__bubble th {
  background: var(--bg-3);
  color: var(--white);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border: 1px solid var(--br);
}
.msg__bubble td {
  padding: 7px 12px;
  border: 1px solid var(--br);
  color: var(--text-2);
}
.msg__bubble tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

/* ============================
   TOOL EVENTS
   ============================ */
.tool-event {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(77,208,225,0.06);
  border: 1px solid rgba(77,208,225,0.15);
  border-radius: 8px;
  font-size: 12px;
  color: var(--teal);
  margin: 4px 0;
  max-width: 480px;
}

.tool-event--result {
  background: rgba(74,222,128,0.05);
  border-color: rgba(74,222,128,0.15);
  color: #4ade80;
}

.tool-event--error {
  background: rgba(239,83,80,0.07);
  border-color: rgba(239,83,80,0.2);
  color: #EF5350;
}

/* ============================
   TYPING CURSOR
   ============================ */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--pink);
  border-radius: 1px;
  animation: blink 0.7s ease-in-out infinite;
  vertical-align: middle;
  margin-left: 2px;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ============================
   INPUT AREA
   ============================ */
.input-area {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--br);
  background: var(--bg);
  flex-shrink: 0;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--br);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
}

.input-wrap:focus-within {
  border-color: rgba(240,98,146,0.35);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-1);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
}

.chat-input::placeholder { color: var(--text-4); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--pink), var(--lilac));
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.1s;
}

.send-btn:hover { opacity: 0.9; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.input-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
  font-size: 11px;
  color: var(--text-4);
}

#contextIndicator { color: var(--teal); }
#contextIndicator.no-data { color: var(--text-4); }

/* ============================
   SETUP BANNER
   ============================ */
.setup-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(239,83,80,0.12);
  border-bottom: 1px solid rgba(239,83,80,0.25);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #EF5350;
}
.setup-banner code {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: monospace;
}

/* ============================
   MEMORY PANEL
   ============================ */
.memory-panel {
  margin: 0 8px 8px;
  background: rgba(240,98,146,0.04);
  border: 1px solid rgba(240,98,146,0.12);
  border-radius: 10px;
  padding: 10px;
  font-size: 11px;
}

.memory-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--text-3);
}

.mem-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pink);
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

.memory-items {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 100px;
  overflow-y: auto;
  margin-bottom: 8px;
}

.memory-item {
  color: var(--text-4);
  font-size: 10px;
  line-height: 1.4;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.memory-item strong { color: var(--pink-hl); font-weight: 600; }

.memory-clear-btn {
  width: 100%;
  padding: 5px;
  background: none;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 6px;
  color: var(--text-4);
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.memory-clear-btn:hover { border-color: rgba(239,83,80,0.3); color: #EF5350; }

/* Tool events for call_agent */
.tool-event--agent {
  background: rgba(240,98,146,0.06);
  border-color: rgba(240,98,146,0.2);
  color: var(--pink-hl);
}

/* ============================
   MOBILE
   ============================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  backdrop-filter: blur(4px);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .topbar__menu { display: flex; }

  .chat-area { padding: 20px 14px; }
  .input-area { padding: 12px 14px 16px; }
  .msg__bubble { max-width: 95%; font-size: 13px; }
}
