/* InsightSerenity AI Assistant — style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0f1117;
  --bg-sidebar: #13151f;
  --bg-chat: #1a1d27;
  --bg-user: #ffc451;
  --bg-ai: #23263a;
  --text: #f1f1f1;
  --text-muted: #9ca3af;
  --primary: #ffc451;
  --border: #2a2d3e;
  --radius: 0.75rem;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  margin: 0;
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── Back to Main ── */
.back-to-main {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .875rem;
  border: 1.5px solid rgba(255,196,81,0.3);
  border-radius: .5rem;
  font-size: .8125rem;
  font-weight: 600;
  color: #ffc451;
  background: rgba(255,196,81,0.08);
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.back-to-main:hover { background: #ffc451; color: #000; }

.sidebar-back {
  display: block;
  margin: 0.75rem 1rem 0;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-top {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-logo span.logo-icon {
  font-size: 1.1rem;
}

.new-chat-btn {
  width: 100%;
  padding: 0.625rem;
  background: rgba(255, 196, 81, 0.1);
  border: 1px solid rgba(255, 196, 81, 0.2);
  border-radius: 0.5rem;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: 'Inter', sans-serif;
}

.new-chat-btn:hover {
  background: rgba(255, 196, 81, 0.2);
}

.sidebar-section {
  padding: 0.875rem 1rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.suggestion-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  border-radius: 0.375rem;
  transition: background 0.15s, color 0.15s;
  font-family: 'Inter', sans-serif;
}

.suggestion-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.suggestion-btn span.icon {
  font-size: 1rem;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

.sidebar-footer a {
  color: var(--primary);
  text-decoration: none;
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-chat);
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-sidebar);
  flex-shrink: 0;
}

.ai-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #000;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
}

.chat-header-info h2 {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

.chat-header-info p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
  animation: pulse-dot 2s infinite;
}

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

/* ── Chat Header Actions ── */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255,196,81,0.1);
  border-color: rgba(255,196,81,0.3);
  color: var(--primary);
}

.icon-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 82%;
}

.message.user {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.message.ai {
  align-self: flex-start;
}

.msg-animate {
  animation: fadeIn 0.3s ease;
}

.msg-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.msg-avatar.user {
  background: var(--primary);
  color: #000;
}

.msg-avatar.ai {
  background: var(--bg-ai);
  border: 1px solid var(--border);
  color: var(--primary);
}

.msg-content {
  display: flex;
  flex-direction: column;
  position: relative;
}

.msg-bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.65;
  max-width: 100%;
  position: relative;
}

.msg-bubble p {
  margin: 0 0 0.5em;
}

.msg-bubble p:last-of-type {
  margin-bottom: 0;
}

.msg-bubble ul {
  margin: 0.25em 0 0.5em 1.25em;
  padding: 0;
}

.msg-bubble li {
  margin-bottom: 0.25em;
}

.message.user .msg-bubble {
  background: var(--primary);
  color: #000;
  border-radius: var(--radius) 0.25rem var(--radius) var(--radius);
  font-weight: 500;
}

.message.ai .msg-bubble {
  background: var(--bg-ai);
  border: 1px solid var(--border);
  border-radius: 0.25rem var(--radius) var(--radius) var(--radius);
  color: var(--text);
}

/* Bold text in AI bubbles */
.message.ai .msg-bubble strong {
  color: var(--primary);
}

/* Inline code in AI bubbles */
.msg-bubble code {
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 0.8em;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
  color: #93c5fd;
}

.message.user .msg-bubble code {
  background: rgba(0,0,0,0.15);
  border-color: rgba(0,0,0,0.1);
  color: #333;
}

.msg-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  text-align: right;
}

.message.ai .msg-time {
  text-align: left;
}

/* ── Copy Button ── */
.copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.25rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.msg-bubble:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}

/* ── Follow-up Chips ── */
.followup-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  padding-left: 2.5rem;
  animation: fadeIn 0.3s ease;
}

.followup-chip {
  padding: 0.3rem 0.875rem;
  background: rgba(255, 196, 81, 0.06);
  border: 1px solid rgba(255, 196, 81, 0.2);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
  text-align: left;
  line-height: 1.4;
}

.followup-chip:hover {
  background: rgba(255, 196, 81, 0.15);
  border-color: rgba(255, 196, 81, 0.45);
}

/* ── Typing Indicator ── */
.typing-wrapper {
  display: flex;
  gap: 0.75rem;
  align-self: flex-start;
  animation: fadeIn 0.3s ease;
}

.typing-indicator {
  display: flex;
  gap: 0.3rem;
  padding: 0.75rem 1rem;
  background: var(--bg-ai);
  border: 1px solid var(--border);
  border-radius: 0.25rem var(--radius) var(--radius) var(--radius);
  width: fit-content;
  align-items: center;
}

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

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

/* ── Input Area ── */
.input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-chat);
  flex-shrink: 0;
}

.quick-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.chip {
  padding: 0.3rem 0.75rem;
  background: rgba(255, 196, 81, 0.08);
  border: 1px solid rgba(255, 196, 81, 0.2);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}

.chip:hover {
  background: rgba(255, 196, 81, 0.15);
  border-color: rgba(255, 196, 81, 0.4);
}

#chat-form {
  margin: 0;
}

.input-row {
  display: flex;
  gap: 0.625rem;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg-ai);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: 'Inter', sans-serif;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  line-height: 1.5;
}

.chat-input:focus {
  border-color: var(--primary);
}

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

.send-btn {
  background: var(--primary);
  color: #000;
  border: none;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.82rem;
  font-family: 'Inter', sans-serif;
  height: 44px;
  flex-shrink: 0;
}

.send-btn:hover {
  background: #e6b048;
}

.send-btn svg {
  width: 14px;
  height: 14px;
}

/* ── Input Footer (disclaimer + counter) ── */
.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.375rem;
}

.disclaimer {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin: 0;
}

/* ── Character Counter ── */
.char-counter {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.15s;
}

.char-counter.warn {
  color: #f59e0b;
}

.char-counter.limit {
  color: #ef4444;
  font-weight: 700;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .sidebar {
    display: none;
  }
  body {
    flex-direction: column;
  }
  .chat-area {
    width: 100%;
    min-width: 0;
  }
  .chat-header {
    padding: 0.75rem 1rem;
    gap: 0.625rem;
  }
  .chat-header h2 {
    font-size: 0.9rem;
  }
  .chat-header p {
    font-size: 0.7rem;
  }
  .chat-header-actions {
    gap: 0.375rem;
  }
  .back-to-main {
    font-size: 0.72rem;
    padding: 0.3rem 0.625rem;
  }
  .messages {
    padding: 1rem;
  }
  .message {
    max-width: 95%;
  }
  .message-bubble {
    font-size: 0.82rem;
    padding: 0.625rem 0.875rem;
  }
  .input-area {
    padding: 0.75rem 1rem;
  }
  .quick-chips {
    gap: 0.375rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    flex-wrap: nowrap;
  }
  .chip {
    white-space: nowrap;
    flex-shrink: 0;
  }
  .followup-chips {
    padding-left: 0;
    flex-wrap: wrap;
  }
  .send-btn {
    padding: 0 0.875rem;
    font-size: 0.78rem;
  }
}

@media (max-width: 420px) {
  .chat-header-actions .icon-btn {
    width: 1.75rem;
    height: 1.75rem;
  }
  .ai-avatar {
    width: 2rem;
    height: 2rem;
    font-size: 0.65rem;
  }
  .input-footer {
    flex-direction: column;
    gap: 0.25rem;
    align-items: flex-start;
  }
}
