/* ============================================================
   Chat Interface Stylesheet
   Credit: lautandigital.id
   ============================================================ */

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

:root {
  --bg-base:        #0d0d0d;
  --bg-sidebar:     #111111;
  --bg-chat:        #141414;
  --bg-input:       #1c1c1c;
  --bg-hover:       #1e1e1e;
  --bg-card:        #1a1a1a;
  --border:         #2a2a2a;
  --accent:         #6c63ff;
  --accent-hover:   #5a52e0;
  --accent-glow:    rgba(108, 99, 255, 0.18);
  --text-primary:   #e8e8e8;
  --text-secondary: #888;
  --text-muted:     #555;
  --user-bubble:    #6c63ff;
  --ai-bubble:      #1e1e1e;
  --radius-sm:      6px;
  --radius-md:      12px;
  --radius-lg:      18px;
  --radius-xl:      24px;
  --font:           'Segoe UI', system-ui, -apple-system, sans-serif;
  --sidebar-w:      260px;
  --transition:     0.2s ease;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* ── Layout ─────────────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition), opacity var(--transition);
  overflow: hidden;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}

.logo-icon {
  color: var(--accent);
  font-size: 18px;
}

.btn-new-chat {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.btn-new-chat:hover {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

/* sidebar nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 4px 8px 8px;
}

.chat-history {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}

.chat-history-item:hover,
.chat-history-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chat-history-item .item-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

/* sidebar footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name { font-weight: 600; font-size: 13px; }
.user-plan { font-size: 11px; color: var(--text-muted); }

.credit-link {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  text-align: center;
  transition: color var(--transition);
}

.credit-link:hover {
  color: var(--accent);
}

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

/* Top Bar */
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-chat);
  min-height: 56px;
}

.topbar-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  gap: 4px;
}

/* Generic icon button */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0;
  display: flex;
  flex-direction: column;
}

/* Welcome Screen */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 16px;
}

.welcome-icon {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 4px;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.08); }
}

.welcome-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

.welcome-sub {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
  margin-top: 8px;
}

.suggestion-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-primary);
}

.sug-icon { font-size: 18px; flex-shrink: 0; }

/* Message Bubbles */
.message-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto 8px;
  animation: fadeSlideIn 0.25s ease;
}

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

.message-group.user { align-items: flex-end; }
.message-group.ai   { align-items: flex-start; }

.message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 4px;
}

.message-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-group.user .message-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.message-group.ai .message-bubble {
  background: var(--ai-bubble);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ── Input Footer ────────────────────────────────────────────── */
.chat-footer {
  padding: 16px 24px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 14px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-attach {
  flex-shrink: 0;
  margin-bottom: 1px;
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 1px 0;
}

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

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  margin-bottom: 1px;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.08);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.footer-note {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* ── Code blocks inside messages ─────────────────────────────── */
.message-bubble code {
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
}

.message-bubble pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin-top: 10px;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar {
    position: absolute;
    z-index: 10;
    height: 100%;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  .message-bubble {
    max-width: 92%;
  }

  .chat-footer { padding: 12px 14px 10px; }
  .chat-messages { padding: 20px 0; }
}
