/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  background-color: #07101e;
}
body {
  background-color: #07101e;
  padding-bottom: env(safe-area-inset-bottom);
}

/* iPhone safe-area: input bar tidak boleh terpotong bottom bar */
.input-bar,
.chat-input-wrapper,
.input-area,
.message-input-container,
#input-area {
  position: sticky;
  bottom: env(safe-area-inset-bottom);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background-color: #07101e;
  z-index: 10;
}

/* Pastikan chat messages tidak tertutup input bar */
.chat-messages,
.messages-container,
#chat-messages,
#messages-area {
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

:root {
  --bg: #0b1220;
  --bg-2: #121a2a;
  --bg-3: #151e30;
  --bg-4: #1a253a;
  --border: #25314a;
  --accent: #14b8a6;
  --accent-hover: #2dd4bf;
  --accent-dim: rgba(20, 184, 166, 0.15);
  --text: #eef2ff;
  --text-muted: #9aa7bd;
  --text-dim: #4a5568;
  --green: #22c55e;
  --red: #ff4d6a;
  --yellow: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --sidebar-w: 260px;
  --transition: 180ms ease;
}

html, body { height: 100%; overflow: hidden; }
html { background-color: #0b1220; }
body {
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, #1b2944 0%, #0b1220 55%),
    radial-gradient(circle at 80% 20%, rgba(15, 118, 110, 0.18), transparent 55%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Prevent iOS zoom on input focus */
input, textarea, select {
  font-size: 16px !important;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--bg);
}

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

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
  overflow: visible;
}

/* Logo always visible even when sidebar is collapsed */
#sidebar.collapsed .sidebar-header {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  z-index: 300;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  border-bottom: none;
  padding: 12px 14px;
  overflow: visible;
}
#sidebar.collapsed .sidebar-logo-wrap {
  overflow: visible;
}
#sidebar.collapsed .sidebar-new-row,
#sidebar.collapsed .sidebar-search,
#sidebar.collapsed .sidebar-search-panel,
#sidebar.collapsed .conv-list-label,
#sidebar.collapsed #conv-list,
#sidebar.collapsed #folder-bar,
#sidebar.collapsed #select-bar,
#sidebar.collapsed .sidebar-footer {
  display: none;
}

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

.sidebar-logo-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.sidebar-logo-names {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  gap: 1px;
  min-width: 0;
}
.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(90deg, #38bdf8, #14b8a6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}
.sidebar-logo-sub {
  font-size: 9px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  white-space: nowrap;
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}
.sidebar-logo span { color: var(--text); }

/* New chat + select mode row */
.sidebar-new-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 12px 10px 6px;
}

#btn-new-chat {
  flex: 1;
  padding: 9px 12px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
#btn-new-chat:hover {
  background: var(--accent);
  color: #fff;
}

/* (select-mode button styling moved to .conv-list-select-btn — see conv-list-label area) */

/* Select mode bar */
#select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--accent-dim);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
#select-count {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
}
#btn-delete-selected {
  padding: 5px 10px;
  background: #ff4d4f22;
  border: 1px solid #ff4d4f66;
  color: #ff4d4f;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background var(--transition);
}
#btn-delete-selected:hover:not([disabled]) {
  background: #ff4d4f44;
}
#btn-delete-selected[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* Conversation item in select mode */
.conv-item.selected {
  background: var(--accent-dim);
  outline: 1px solid var(--accent);
}
.conv-item-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-right: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Folder chip menu button */
.folder-chip-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  border-radius: 4px;
  margin-left: 2px;
}
.folder-chip:hover .folder-chip-menu-btn {
  display: inline-flex;
  align-items: center;
}
.folder-chip-menu-btn:hover {
  background: rgba(0,0,0,0.15);
}
.folder-chip-label {
  cursor: pointer;
}


.conv-list-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}
.conv-list-label > span {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.conv-list-search-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 4px; border-radius: 5px; line-height: 0; display: flex; align-items: center;
  transition: background 0.15s, color 0.15s;
}
.conv-list-search-btn:hover { background: var(--bg-3); color: var(--accent); }
.conv-list-search-btn.active { background: var(--bg-3); color: var(--accent); }

/* Select mode — yellow accent (delete/bulk action) */
.conv-list-select-btn:hover { color: var(--yellow); }
.conv-list-select-btn.active {
  background: rgba(245, 158, 11, 0.15);
  color: var(--yellow);
}

/* Mode chips – admin only (Quick Chat) */
.mode-chips {
  display: flex;
  gap: 6px;
  margin: 0 10px 8px;
}

.mode-chip {
  flex: 1;
  padding: 6px 10px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all 0.15s;
  text-align: center;
}
.mode-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.mode-chip:hover:not(.active) {
  border-color: var(--accent);
  color: var(--text);
}

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 8px;
  transition: background var(--transition);
  overflow: hidden;
}
.conv-item:hover { background: var(--bg-3); }
.conv-item.active { background: var(--accent-dim); }

.conv-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text);
}
.conv-item.active .conv-item-title { color: var(--accent); }

.conv-item-del {
  display: none;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  padding: 0 2px;
  border-radius: 3px;
  transition: color var(--transition);
}
.conv-item:hover .conv-item-del { display: flex; align-items: center; }
.conv-item-del:hover { color: var(--red); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.sidebar-footer strong { color: var(--accent); }

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

/* ── Topbar ──────────────────────────────────────────────────────────────── */
#topbar {
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

#btn-toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  flex-shrink: 0;
}
#btn-toggle-sidebar:hover { color: var(--text); }

#conv-title-display {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

#quick-badge {
  display: none;
  background: #f59e0b;
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: default;
  flex-shrink: 0;
  vertical-align: middle;
}
#quick-badge.visible { display: inline-block; }

.topbar-user {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  display: none;
}
.topbar-user strong { color: var(--green); }

/* ── Messages Area ───────────────────────────────────────────────────────── */
#messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.msg-row {
  display: flex;
  padding: 6px 20px;
  gap: 12px;
  max-width: 100%;
}
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-row.user .msg-avatar { background: var(--accent-dim); color: var(--accent); }
.msg-row.assistant .msg-avatar { background: var(--bg-4); color: var(--green); }

.msg-bubble {
  max-width: min(680px, 82%);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(20, 184, 166, 0.25);
  color: var(--text);
  border-bottom-right-radius: 3px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

/* Markdown inside assistant bubbles */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
  margin: 12px 0 6px;
  color: var(--text);
  font-weight: 700;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 14px; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg-bubble li { margin: 3px 0; }
.msg-bubble code {
  background: var(--bg-4);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--green);
}
.msg-bubble pre {
  background: #0a0a12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  position: relative;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  color: var(--text);
}
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-muted);
}
.msg-bubble a { color: var(--accent); text-decoration: underline; }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; max-width: 100%; table-layout: fixed; word-wrap: break-word; font-size: 13px; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; word-break: break-word; white-space: normal; }
.msg-bubble th { background: var(--bg-4); color: var(--text); }
.msg-bubble .table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 8px 0;
  border-radius: var(--radius-sm);
}

/* ── Per-message copy button (inline chip at end of bubble) ────────────────── */
.message-actions {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.msg-row:hover .message-actions,
.msg-row:focus-within .message-actions,
.message-actions:hover,
.message-actions:focus-within {
  opacity: 1;
}
@media (max-width: 768px) {
  .message-actions { opacity: 0.85; }
}
.copy-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: var(--text-secondary, var(--text-muted));
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.copy-btn:hover {
  background: var(--bg-hover, var(--bg-3));
  color: var(--text);
}
.msg-bubble .table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin: 8px 0;
  border-radius: var(--radius-sm);
}
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; color: var(--text-muted); }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Copy button on code blocks */
.code-wrapper { position: relative; }
.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: color var(--transition);
}
.copy-code-btn:hover { color: var(--text); }

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

/* Attachments in user bubble */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-attachment-thumb { max-width: 120px; max-height: 80px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }

/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 16px;
  color: var(--text-muted);
  text-align: center;
}
.empty-logo { font-size: 48px; }
.empty-title { font-size: 22px; font-weight: 700; color: var(--text); }
.empty-subtitle { font-size: 14px; max-width: 360px; line-height: 1.7; }
.empty-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}
.tip-chip {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}
.tip-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Input Area ──────────────────────────────────────────────────────────── */
#input-area {
  padding: 12px 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#quick-chat-banner {
  display: none;
  align-items: center;
  gap: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: #92400e;
}
#quick-chat-banner.visible { display: flex; }
#quick-chat-banner .qc-icon { font-size: 15px; flex-shrink: 0; }
#quick-chat-banner .qc-text { flex: 1; }
#quick-chat-banner .qc-hint { font-size: 11px; color: #b45309; opacity: 0.8; }
#quick-chat-banner .qc-close {
  background: none;
  border: none;
  color: #b45309;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  opacity: 0.6;
  line-height: 1;
}
#quick-chat-banner .qc-close:hover { opacity: 1; }

#attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.att-preview-item {
  position: relative;
}
.att-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.att-preview-del {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--red);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px;
  transition: border-color var(--transition);
}
.input-row:focus-within { border-color: var(--accent); }

#msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 4px 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#msg-input::placeholder { color: var(--text-dim); }

#btn-attach {
  background: none;
  border: none;
  color: #10b981;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), transform 0.15s ease;
  flex-shrink: 0;
}
#btn-attach:hover { color: #34d399; transform: scale(1.1); }
#btn-attach:active { transform: scale(0.95); }

#btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:active { transform: scale(0.97); }
#btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.input-hint {
  padding: 4px 8px 0;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Loading / Thinking indicator ─────────────────────────────────────────── */
.thinking-row {
  display: flex;
  padding: 6px 20px;
  gap: 12px;
  align-items: center;
}
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ── AI Tool indicators ───────────────────────────────────────────────────── */
.tool-indicator {
  padding: 8px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-2);
  animation: fade-in 0.3s ease;
}
.tool-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 44px 0;
  width: 100%;
}
.tool-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); color: var(--red); }

/* ── Scrollbar global ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; }
  #sidebar.collapsed { transform: translateX(-100%); }
  #sidebar.collapsed { width: var(--sidebar-w); min-width: var(--sidebar-w); }
  .msg-bubble { max-width: 90%; }
}

/* ── Phase 2 additions ─────────────────────────────────────────────────────── */

/* Sidebar header with settings button */
.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
#btn-settings {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 5px; border-radius: 6px; line-height: 0; flex-shrink: 0;
}
#btn-settings:hover { background: var(--bg-3); color: var(--accent); }
#btn-apikeys {
  background: var(--accent-dim); border: 1px solid var(--accent);
  color: var(--accent); cursor: pointer;
  padding: 5px; border-radius: 6px; line-height: 0; flex-shrink: 0;
}
#btn-apikeys:hover { background: var(--accent); color: #fff; }

/* Sidebar search panel — collapsible di bawah baris Riwayat */
.sidebar-search-panel {
  padding: 4px 12px 8px;
  animation: slideDown 0.15s ease-out;
}
.sidebar-search-panel[hidden] { display: none; }
.sidebar-search-panel #search-input {
  width: 100%; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; color: var(--text); font-size: 13px;
  outline: none;
}
.sidebar-search-panel #search-input:focus { border-color: var(--accent); }
.sidebar-search-panel #search-input::placeholder { color: var(--text-dim); }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Folder chips */
#folder-bar {
  display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto;
  scrollbar-width: none;
}
#folder-bar::-webkit-scrollbar { display: none; }
.folder-chip {
  flex-shrink: 0; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-muted); padding: 4px 10px; border-radius: 20px;
  font-size: 11px; cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
  transition: background 0.15s, border-color 0.15s;
}
.folder-chip:hover { background: var(--bg-4); }
.folder-chip.active {
  background: var(--accent-dim); border-color: var(--accent);
  color: var(--accent);
}
.folder-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--chip-color, var(--accent));
}

/* Conversation list sections */
.conv-section-label {
  font-size: 10px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.05em; padding: 8px 14px 2px;
  display: flex; align-items: center; gap: 5px;
}
.conv-empty {
  padding: 10px 14px; font-size: 12px; color: var(--text-dim);
}
.conv-pin-icon { font-size: 10px; margin-right: 3px; }

/* Conv item options button */
.conv-item-menu {
  display: none; background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1;
  border-radius: 4px;
}
.conv-item:hover .conv-item-menu { display: block; }
.conv-item-menu:hover { background: var(--bg-4); color: var(--text); }

/* Search snippet */
.conv-search-snippet {
  font-size: 11px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-search-snippet mark {
  background: rgba(20, 184, 166, 0.3); color: var(--accent); border-radius: 2px;
}

/* Context menu */
.ctx-menu {
  position: fixed; z-index: 500;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 160px; padding: 4px 0; overflow: hidden;
}
.ctx-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.ctx-menu button:hover { background: var(--bg-4); }

/* Topbar actions */
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.topbar-icon-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 6px; border-radius: 6px; line-height: 0;
}
.topbar-icon-btn:hover { background: var(--bg-3); color: var(--text); }
.topbar-icon-btn.active { color: var(--accent); }

/* PDF / text-file attachment preview */
.att-preview-pdf {
  background: var(--bg-4); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; color: var(--text);
  max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-pdf-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-4); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--text-muted);
}

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(0,0,0,0.6); display: flex;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-panel,
.modal-box {
  background: var(--bg-2) !important;
  background-color: var(--bg-2) !important;
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  color: var(--text);
}
.modal-box {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 480px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-section { display: flex; flex-direction: column; gap: 8px; }
.modal-label { font-size: 13px; font-weight: 600; color: var(--text); }
.modal-desc { font-size: 12px; color: var(--text-dim); margin: 0; }
.modal-input {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; color: var(--text);
  font-size: 13px; outline: none; font-family: inherit;
}
.modal-input:focus { border-color: var(--accent); }

/* Buttons */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: 8px; font-size: 13px;
  cursor: pointer; font-weight: 500;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  background: var(--bg-4); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-3); }

/* API Keys chip buttons */
.chip-btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip-btn.danger:hover { border-color: #ef4444; color: #ef4444; }
.chip-btn.refresh:hover { border-color: var(--accent); color: var(--accent); }

/* Prompt list */
.prompt-list { display: flex; flex-direction: column; gap: 8px; }
.prompt-empty { font-size: 12px; color: var(--text-dim); text-align: center; padding: 16px; }
.prompt-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.prompt-info { flex: 1; min-width: 0; }
.prompt-title { font-size: 13px; font-weight: 600; }
.prompt-preview { font-size: 11px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prompt-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-use-prompt {
  background: var(--accent); color: #fff; border: none;
  padding: 5px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.btn-del-prompt {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 4px; border-radius: 4px; font-size: 14px;
}
.btn-del-prompt:hover { color: var(--red); }

/* Folder manager */
.folder-manager-list { display: flex; flex-direction: column; gap: 6px; }
.folder-mgr-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
}
.folder-dot-lg { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.folder-mgr-name { flex: 1; font-size: 13px; }
.btn-del-folder {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 3px; border-radius: 4px; font-size: 14px;
}
.btn-del-folder:hover { color: var(--red); }

/* Usage stats */
.usage-today { font-size: 13px; margin-bottom: 10px; }
.usage-bar {
  height: 5px; background: var(--bg-4); border-radius: 3px;
  margin-top: 6px; overflow: hidden;
}
.usage-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s; }
.usage-history { display: flex; flex-direction: column; gap: 4px; }
.usage-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); }
.usage-date { }
.usage-val { color: var(--text); }

/* ── Phase 3: Mobile sidebar overlay ────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}
#sidebar-overlay.show { display: block; }

@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    border-right: 1px solid var(--border) !important;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
  }
  #main { width: 100%; }
  .msg-row { padding: 6px 12px; }
  .msg-bubble { max-width: 92%; }
  #topbar { padding: 10px 12px; gap: 8px; }
  #conv-title-display { font-size: 14px; }
  #input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-box { max-height: 92vh; margin: 4vh auto; }
  .topbar-user { display: none; }
  .input-hint { display: none; }
  .sidebar-header { padding-top: max(14px, env(safe-area-inset-top)); }
  #topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  button, .clickable {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ── Phase 3: Regenerate button ──────────────────────────────────────────── */
.msg-regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.msg-regen-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Phase 3: Settings use_context toggle ────────────────────────────────── */
.modal-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.modal-toggle-row label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.modal-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.modal-toggle-row.ctx-soon { opacity: 0.45; pointer-events: none; }
.ctx-desc { font-size: 11px; color: var(--text-muted); }
.badge-soon {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(108,99,255,0.12);
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Phase 3: Mobile sidebar overlay ────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}
#sidebar-overlay.show { display: block; }

@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    border-right: 1px solid var(--border) !important;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
  }
  #main { width: 100%; }
  .msg-row { padding: 6px 12px; }
  .msg-bubble { max-width: 92%; }
  #topbar { padding: 10px 12px; gap: 8px; }
  #conv-title-display { font-size: 14px; }
  #input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-box { max-height: 92vh; margin: 4vh auto; }
  .topbar-user { display: none; }
  .input-hint { display: none; }
  .sidebar-header { padding-top: max(14px, env(safe-area-inset-top)); }
  #topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  button, .clickable {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ── Phase 3: Regenerate button ──────────────────────────────────────────── */
.msg-regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.msg-regen-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Phase 3: Settings use_context toggle ────────────────────────────────── */
.modal-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.modal-toggle-row label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.modal-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════════════════════
   Phase 6 — Second Brain UI
   ══════════════════════════════════════════════════════════════════════════════ */

/* Settings tab nav */
.settings-tabs-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 0;
}
.settings-tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.settings-tab-btn:hover { color: var(--text); }
.settings-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.settings-tab-content { animation: fade-in 0.2s ease; }

/* Second Brain inner tabs */
.brain-tabs-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.brain-tab-btn {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}
.brain-tab-btn:hover { border-color: var(--accent); color: var(--accent); }
.brain-tab-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.brain-tab-content { animation: fade-in 0.2s ease; }

/* Brain lists */
.brain-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.brain-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.brain-empty strong { display: block; color: var(--text-muted); font-size: 14px; margin-bottom: 6px; }

/* Memory item */
.brain-memory-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.brain-memory-text { flex: 1; font-size: 13px; line-height: 1.5; }
.brain-memory-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.memory-date {
  font-size: 10px;
  color: var(--color-text-tertiary);
  margin-left: auto;
  flex-shrink: 0;
}
.brain-cat-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.brain-cat-pekerjaan { background: rgba(3,105,161,0.15); color: #0369a1; }
.brain-cat-keluarga  { background: rgba(22,163,74,0.15);  color: #16a34a; }
.brain-cat-hobi      { background: rgba(8,145,178,0.15);  color: #0891b2; }
.brain-cat-preferensi { background: rgba(217,119,6,0.15); color: #d97706; }
.brain-cat-general  { background: rgba(107,114,128,0.15); color: #6b7280; }
.brain-del-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px;
  border-radius: 4px;
  font-size: 15px;
  flex-shrink: 0;
  transition: color var(--transition);
}
.brain-del-btn:hover { color: var(--red); }

/* Knowledge item */
.brain-knowledge-item {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.brain-knowledge-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.brain-knowledge-title { font-size: 14px; font-weight: 600; flex: 1; }
.brain-level-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.brain-level-basic      { background: rgba(107,114,128,0.15); color: #6b7280; }
.brain-level-intermediate { background: rgba(245,158,11,0.15); color: #d97706; }
.brain-level-advanced  { background: rgba(20,184,166,0.15); color: var(--accent); }
.brain-knowledge-summary {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
.brain-knowledge-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brain-knowledge-date { font-size: 11px; color: var(--text-dim); }
.brain-knowledge-actions { display: flex; gap: 6px; align-items: center; }
.brain-expand-btn, .brain-del-kn-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  transition: all var(--transition);
}
.brain-expand-btn:hover, .brain-del-kn-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.brain-del-kn-btn:hover { border-color: var(--red); color: var(--red); }

/* Expandable detail */
.brain-knowledge-detail {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  animation: fade-in 0.2s ease;
}
.brain-detail-section { margin-bottom: 10px; }
.brain-detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 5px;
}
.brain-detail-points { display: flex; flex-wrap: wrap; gap: 5px; }
.brain-point-tag {
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--text);
}
.brain-question-tag {
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  color: #d97706;
}

/* Danger button small */
.btn-danger-sm {
  background: rgba(255,77,106,0.1);
  border: 1px solid rgba(255,77,106,0.3);
  color: #ff4d6a;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-danger-sm:hover { background: rgba(255,77,106,0.2); border-color: #ff4d6a; }

/* Second Brain SSE pill indicator */
#brain-updated-pill {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-3);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 300;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(20,184,166,0.2);
}
#brain-updated-pill.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
#brain-updated-pill:hover { background: var(--accent-dim); }

/* Smart scroll: tombol "Lanjut ke bawah" saat streaming */
#scrollToBottom {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 4px 16px rgba(20,184,166,0.3);
}
#scrollToBottom.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
#scrollToBottom:hover { background: var(--accent-dim); }

/* ── Home / Chat view containers ───────────────────────────────────────────── */
#home-view {
  display: flex;
  flex: 1;
  overflow: hidden;
  animation: fade-in 0.3s ease;
}
#chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  animation: fade-in 0.25s ease;
}

/* ── 3-column home layout ──────────────────────────────────────────────────── */
.home-col {
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.home-col-left {
  width: 0;
  min-width: 0;
  border-right: none;
  background: var(--bg);
  flex-shrink: 0;
}
.home-col-center {
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px 24px;
  text-align: center;
}
.home-col-right {
  width: 190px;
  min-width: 190px;
  border-left: 1px solid var(--border);
  background: var(--bg-2);
}

/* ── Topic cards ───────────────────────────────────────────────────────────── */
.topic-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color var(--transition);
  flex-shrink: 0;
}
.topic-card:hover { border-color: var(--accent); }
.topic-card-name { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.topic-bar { height: 3px; background: var(--bg-4); border-radius: 2px; overflow: hidden; }
.topic-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.6s ease; }
.topic-card-pct { font-size: 10px; color: var(--text-dim); margin-top: 4px; }

/* ── Orb / Globe animation ─────────────────────────────────────────────────── */
.home-orb-wrapper { position: relative; width: 180px; height: 180px; margin: 0 auto 4px; flex-shrink: 0; }
.home-orb { width: 180px; height: 180px; position: relative; }
.home-orb-ring {
  position: absolute; border-radius: 50%;
  border: 1px solid rgba(20, 184, 166, 0.22);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: orb-pulse 3.5s ease-in-out infinite;
}
.home-orb-ring.r1 { width: 180px; height: 180px; animation-delay: 0s; }
.home-orb-ring.r2 { width: 138px; height: 138px; animation-delay: 0.5s; border-color: rgba(20,184,166,0.3); }
.home-orb-ring.r3 { width: 96px;  height: 96px;  animation-delay: 1s;   border-color: rgba(20,184,166,0.4); }
@keyframes orb-pulse {
  0%, 100% { opacity: 0.35; transform: translate(-50%, -50%) scale(1); }
  50%       { opacity: 0.8;  transform: translate(-50%, -50%) scale(1.04); }
}
.home-orb-core {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 66px; height: 66px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(20,184,166,0.55), rgba(20,184,166,0.15));
  border: 1px solid rgba(20,184,166,0.55);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: var(--accent); letter-spacing: -0.5px;
  font-family: var(--font);
  box-shadow: 0 0 28px rgba(20,184,166,0.22), inset 0 0 14px rgba(20,184,166,0.12);
  animation: orb-glow 3.5s ease-in-out infinite;
}
@keyframes orb-glow {
  0%, 100% { box-shadow: 0 0 22px rgba(20,184,166,0.18), inset 0 0 10px rgba(20,184,166,0.1); }
  50%       { box-shadow: 0 0 44px rgba(20,184,166,0.35), inset 0 0 22px rgba(20,184,166,0.18); }
}

/* ── Home / Chat view containers ───────────────────────────────────────────── */
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  flex-shrink: 0;
}

.home-wordmark {
  display: flex;
  align-items: baseline;
  line-height: 1;
  gap: 0;
  flex-shrink: 0;
}
.wordmark-n {
  font-size: 52px;
  font-weight: 800;
  font-family: var(--font);
  color: var(--text);
  letter-spacing: -2px;
}
.wordmark-garti {
  font-size: 52px;
  font-weight: 400;
  font-family: var(--font);
  color: var(--text-muted);
  letter-spacing: -2px;
}
.wordmark-q {
  font-size: 52px;
  font-weight: 700;
  font-family: var(--font);
  color: var(--accent);
  letter-spacing: -2px;
  margin-left: 1px;
}

.home-nevi-exp {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  flex-shrink: 0;
}
.nevi-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.nevi-letter {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}
.nevi-desc {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 500;
  letter-spacing: 0.3px;
}

.home-divider {
  width: 40px;
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.home-tagline-sub {
  font-size: 14px;
  color: #ffffff;
  font-style: italic;
  font-weight: 400;
  flex-shrink: 0;
}
.home-tagline-sub em {
  font-style: italic;
  font-weight: 500;
  color: #ffffff;
}
.tagline-wrap {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.tagline-main {
  color: #ffffff;
  font-style: italic;
  font-weight: 500;
}
.tagline-sunda {
  color: var(--accent);
  font-style: italic;
  font-weight: 500;
}

.home-nevi-label {
  font-size: 11px;
  color: #ffffff;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* Chips: horizontal flex-wrap */
.home-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 400px;
  flex-shrink: 0;
}

.home-chip {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--transition), color var(--transition);
}
.home-chip:hover { border-color: var(--accent); color: var(--accent); }

/* New chat button in home center: large solid style */
#btn-home-new-chat {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #fff;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}
#btn-home-new-chat:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
#btn-home-new-chat:active { transform: scale(0.97); }

/* Home center action buttons — side by side pill row */
.home-action-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
}
#btn-home-new-chat {
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 20px;
  color: #fff;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}
#btn-home-quick-chat {
  background: transparent;
  border: 1.5px solid #f59e0b;
  border-radius: 20px;
  color: #f59e0b;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
#btn-home-quick-chat:hover {
  background: color-mix(in srgb, #f59e0b 12%, transparent);
}
#btn-home-new-chat:active,
#btn-home-quick-chat:active { transform: scale(0.97); }

/* .hidden utility — keeps layout flow, hides visually */
.hidden { display: none; }


/* ── Quick Chat (Phase 8) ──────────────────────────────────────────────────── */
.mode-chips {
  display: flex;
  gap: 6px;
  padding: 4px 10px;
}
.mode-chip {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.mode-chip:hover { border-color: var(--accent); color: var(--text); }
.mode-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.mode-chip.quick-chat-chip:hover {
  border-color: var(--qc-color, #f59e0b);
  color: var(--qc-color, #f59e0b);
  background: color-mix(in srgb, var(--qc-color, #f59e0b) 12%, transparent);
}
#quick-chat-banner {
  display: none;
  align-items: center;
  gap: 6px;
  margin: 0 12px 6px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--qc-color, #f59e0b) 12%, var(--bg-2));
  border: 1px solid color-mix(in srgb, var(--qc-color, #f59e0b) 30%, transparent);
  border-radius: 8px;
  font-size: 12px;
  color: var(--qc-color, #f59e0b);
  font-weight: 500;
}
#quick-chat-banner.visible { display: flex; }
#quick-chat-banner svg { flex-shrink: 0; }
.quick-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--qc-color, #f59e0b);
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
}
:root { --qc-color: #f59e0b; }

/* ── Widget cards (right column) ───────────────────────────────────────────── */
.widget-section-title {
  font-size: 10px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1.2px;
  margin-bottom: 10px; margin-top: 18px; flex-shrink: 0;
}
.widget-section-title:first-child { margin-top: 0; }
.widget-card {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; flex-shrink: 0;
}
.widget-card-label  { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.widget-card-value  { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.2; }
.widget-card-sub    { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.widget-card-sub.up   { color: var(--green); }
.widget-card-sub.down { color: var(--red); }
.tool-status-list { display: flex; flex-direction: column; gap: 7px; }
.tool-status-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.tool-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.tool-dot.on  { background: var(--green); }
.tool-dot.off { background: var(--text-dim); }
.stats-row { display: flex; gap: 8px; margin-bottom: 10px; }
.stat-item {
  flex: 1; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; text-align: center;
}
.stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.2; margin-top: 2px; }

/* ── LibreChat-style AI messages ───────────────────────────────────────────── */
.msg-row.assistant {
  align-items: flex-start;
  padding: 16px 24px 10px;
  border-bottom: 1px solid rgba(37, 49, 74, 0.55);
  gap: 14px;
}
.msg-row.assistant .msg-avatar {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--accent-dim); color: var(--accent);
  font-size: 10px; font-weight: 800; font-family: var(--font);
  flex-shrink: 0; margin-top: 1px;
}
.msg-row.assistant .msg-bubble {
  background: none; border: none; padding: 0;
  max-width: min(820px, 100%); border-radius: 0;
}
.msg-row.assistant { flex-direction: column; gap: 6px; align-items: stretch; }
.msg-row.assistant .msg-header {
  display: flex; align-items: center; gap: 6px;
  max-width: min(820px, 100%);
}
.msg-row.assistant .msg-name {
  font-size: 11px; color: var(--accent);
  font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
}
.ai-tool-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.ai-tool-badges:empty { display: none; }

/* Code block LibreChat-style header */
.code-wrapper {
  margin: 10px 0; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--border); position: relative;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-4); padding: 6px 10px; border-bottom: 1px solid var(--border);
}
.code-lang-label { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); text-transform: lowercase; }
.code-wrapper .copy-code-btn {
  position: static; background: none; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: 4px; padding: 2px 8px;
  font-size: 11px; cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.code-wrapper .copy-code-btn:hover { color: var(--text); border-color: var(--text-muted); }
.code-wrapper pre { margin: 0; border: none; border-radius: 0; }

/* ── Sidebar conv item improvements ────────────────────────────────────────── */
.conv-item.active { background: var(--accent-dim); border-left: 3px solid var(--accent); padding-left: 7px; }
.conv-item-info { flex: 1; min-width: 0; overflow: hidden; }
.conv-item-info .conv-item-title { flex: none; }
.conv-item-preview { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

/* ── Topbar logo (Ngarti branding) ─────────────────────────────────────────── */
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-logo-names {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  gap: 1px;
}
.topbar-logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .04em;
  background: linear-gradient(90deg, #38bdf8, #14b8a6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.topbar-logo-sub {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

/* ── PWA install banner ─────────────────────────────────────────────────────── */
#pwa-install-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 72px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  z-index: 300;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}
#pwa-install-banner span { font-size: 13px; color: var(--text); }
#pwa-install-banner button { font-size: 12px; padding: 5px 12px; border-radius: 8px; cursor: pointer; }
#pwa-btn-install { background: var(--accent); color: #fff; border: none; }
#pwa-btn-dismiss { background: none; color: var(--text-muted); border: 1px solid var(--border); }

/* ── Phase 5 Mobile responsive ─────────────────────────────────────────────── */
@media (max-width: 767px) {
  .home-col-left, .home-col-right { display: none; }
  .home-col-center { padding: 32px 20px; gap: 16px; }
  .home-orb-wrapper, .home-orb { width: 140px; height: 140px; }
  .home-orb-ring.r1 { width: 140px; height: 140px; }
  .home-orb-ring.r2 { width: 107px; height: 107px; }
  .home-orb-ring.r3 { width: 74px;  height: 74px; }
  .home-orb-core    { width: 52px;  height: 52px; font-size: 11px; }
  .wordmark-n, .wordmark-garti, .wordmark-q { font-size: 40px; }
  .msg-row.assistant { padding: 12px 14px 8px; }

  /* AI message: header (avatar kecil + NEVI) di atas, konten full width */
  .msg-row.assistant { flex-direction: column; gap: 6px; align-items: stretch; }
  .msg-row.assistant .msg-header { gap: 6px; max-width: 100%; }
  .msg-row.assistant .msg-avatar {
    width: 18px; height: 18px; border-radius: 50%;
    background: linear-gradient(135deg, #0369a1, #14b8a6);
    color: #fff; font-size: 9px; font-weight: 700;
    margin-top: 0;
  }
  .msg-row.assistant .msg-name { font-size: 10px; }
  .msg-row.assistant .msg-bubble { max-width: 100%; padding-left: 0; }
  .msg-row.assistant .msg-content-text { font-size: 13px; line-height: 1.65; }

  /* Tabel full width + scroll horizontal saat overflow */
  .msg-bubble .table-wrapper { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .msg-bubble table { font-size: 12px; }

  /* User message: bubble full-width, lebih ringkas */
  .msg-row.user { padding: 4px 14px; align-items: stretch; }
  .msg-row.user .msg-bubble {
    max-width: 88%;
    margin-left: auto;   /* bubble rata kanan, identik dengan assistant full-width */
    border-radius: 14px 14px 2px 14px;
    padding: 6px 10px;
    font-size: 13px; line-height: 1.4;
  }

  /* Mobile: sembunyikan copy button inline — cegah icon '⎘' di akhir text
     yang bikin bubble kelihatan tinggi / tidak sejajar. Copy pakai long-press. */
  .message-actions { display: none; }

  /* iOS: prevent auto-zoom on input focus (font ≥16px) */
  #msg-input { font-size: 16px; }
  /* Touch targets ≥44px */
  #btn-toggle-sidebar,
  #btn-new-chat,
  #btn-send,
  #btn-attach,
  .home-chip { min-height: 44px; }
  .home-chip { display: flex; align-items: center; }
  /* PWA install banner: full-width on mobile */
  #pwa-install-banner { left: 16px; right: 16px; transform: none; max-width: none; }
}

/* ── Quick Chat (Phase 8) ─────────────────────────────────────────── */

#quick-chat-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 20px 0;
  padding: 7px 14px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #92400e;
  flex-shrink: 0;
}
#btn-close-quick-chat {
  background: none;
  border: none;
  cursor: pointer;
  color: #92400e;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
#btn-close-quick-chat:hover { opacity: 1; }

#quick-badge {
  background: #f59e0b;
  color: #000;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
}

.mode-chips {
  display: flex;
  gap: 6px;
  margin: 6px 10px 4px;
}
.mode-chip {
  flex: 1;
  padding: 6px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.mode-chip:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text);
}
.mode-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.mode-chip[data-mode="quickchat"] {
  border-color: #f59e0b;
  color: #92400e;
}
.mode-chip[data-mode="quickchat"]:hover,
.mode-chip[data-mode="quickchat"].active {
  background: #fff7ed;
  border-color: #f59e0b;
  color: #92400e;
}

/* ============================================================
   AL-QURAN TOOL — Tajwid colors + card styling
   ============================================================ */

/* Tajwid color spans (server injects with parseTajweedText) */
.t-ham-wasl     { color: #cbd5e1; }
.t-slnt         { color: #94a3b8; }
.t-madda-normal { color: #60a5fa; }
.t-madda-perm   { color: #818cf8; }
.t-madda-nec    { color: #a78bfa; }
.t-madda-obl    { color: #38bdf8; }
.t-qlq          { color: #f87171; }
.t-ghn          { color: #fb923c; }
.t-ikhf         { color: #e879f9; }
.t-ikhf-shfw    { color: #f0abfc; }
.t-idgh-shfw    { color: #6ee7b7; }
.t-iqlb         { color: #22d3ee; }
.t-idgh-ghn     { color: #34d399; }
.t-idgh-wghn    { color: #86efac; }
.t-idgh-mus     { color: #fcd34d; }

/* Quran card container — used for [qrn-surah] block (server-side format) */
.msg-bubble .qrn-block {
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(20, 184, 166, 0.02));
  border: 1px solid rgba(20, 184, 166, 0.25);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 10px 0;
  font-family: inherit;
}
.msg-bubble .qrn-block + .qrn-block {
  margin-top: 12px;
}

/* Surah header inside qrn-block */
.msg-bubble .qrn-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(20, 184, 166, 0.2);
}
.msg-bubble .qrn-title {
  font-size: 15px;
  font-weight: 700;
  color: #14b8a6;
  line-height: 1.3;
}
.msg-bubble .qrn-meta {
  font-size: 11px;
  color: #5a8a9a;
  margin-top: 2px;
  font-weight: 500;
}
.msg-bubble .qrn-count {
  font-size: 11px;
  color: #14b8a6;
  background: rgba(20, 184, 166, 0.12);
  border: 1px solid rgba(20, 184, 166, 0.3);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Single ayat */
.msg-bubble .qrn-ayat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(20, 184, 166, 0.1);
}
.msg-bubble .qrn-ayat:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.msg-bubble .qrn-num {
  font-size: 10px;
  color: #14b8a6;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.7;
}

/* Arabic text — Uthmani style with tajwid colors inline */
.msg-bubble .qrn-arab {
  direction: rtl;
  text-align: right;
  font-size: 24px;
  line-height: 2.2;
  font-family: 'Amiri Quran', 'Scheherazade New', 'Traditional Arabic', 'Noto Naskh Arabic', serif;
  color: #e2e8f0;
  padding: 6px 0;
  word-spacing: 2px;
}
.msg-bubble .qrn-arab [class^="t-"] {
  font-weight: 600;
}

/* Latin transliteration */
.msg-bubble .qrn-latin {
  font-size: 13px;
  color: #8aa8b8;
  font-style: italic;
  line-height: 1.5;
  padding-left: 2px;
}

/* Indonesian translation */
.msg-bubble .qrn-id {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.6;
  padding: 4px 0 0 0;
  border-left: 2px solid rgba(20, 184, 166, 0.3);
  padding-left: 10px;
  margin-top: 2px;
}

/* Tafsir block (different accent — softer blue) */
.msg-bubble .qrn-tafsir {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.08), rgba(96, 165, 250, 0.02));
  border-color: rgba(96, 165, 250, 0.25);
}
.msg-bubble .qrn-tafsir .qrn-header {
  border-bottom-color: rgba(96, 165, 250, 0.2);
}
.msg-bubble .qrn-tafsir .qrn-title {
  color: #60a5fa;
}
.msg-bubble .qrn-tafsir .qrn-count {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.12);
  border-color: rgba(96, 165, 250, 0.3);
}
.msg-bubble .qrn-tafsir .qrn-ayat {
  border-bottom-color: rgba(96, 165, 250, 0.1);
}
.msg-bubble .qrn-tafsir .qrn-num {
  color: #60a5fa;
}
.msg-bubble .qrn-tafsir .qrn-id {
  border-left-color: rgba(96, 165, 250, 0.3);
}

/* List of surahs (compact rows) */
.msg-bubble .qrn-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  margin-top: 6px;
}
.msg-bubble .qrn-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(20, 184, 166, 0.04);
  border: 1px solid rgba(20, 184, 166, 0.12);
  border-radius: 6px;
  font-size: 12px;
  color: #cbd5e1;
}
.msg-bubble .qrn-list-num {
  font-size: 10px;
  color: #14b8a6;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  opacity: 0.8;
}
.msg-bubble .qrn-list-name {
  font-weight: 600;
  color: #e2e8f0;
}
.msg-bubble .qrn-list-meta {
  font-size: 10px;
  color: #6a8a9a;
  margin-left: auto;
}

/* Mobile responsive for Quran cards */
@media (max-width: 640px) {
  .msg-bubble .qrn-arab {
    font-size: 20px;
    line-height: 2;
  }
  .msg-bubble .qrn-list {
    grid-template-columns: 1fr;
  }
  .msg-bubble .qrn-block {
    padding: 12px;
  }
}

/* === Quran tool styling === */
.qrn-surah-header {
  background: linear-gradient(135deg, #0d2a3a 0%, #14b8a6 100%);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 12px 0 8px 0;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 8px rgba(20, 184, 166, 0.15);
}
.qrn-surah-header .qrn-arab {
  font-family: 'Scheherazade New', 'Traditional Arabic', 'Amiri', serif;
  font-size: 22px;
  margin-left: 8px;
  direction: rtl;
  display: inline-block;
  vertical-align: middle;
}
.qrn-surah-header .qrn-meta {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
  margin-top: 4px;
}
.qrn-ayat {
  background: #07101e;
  border: 1px solid #1a3a4a;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
  position: relative;
}
.qrn-ayat-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: #14b8a6;
  color: #07101e;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
  font-family: system-ui, -apple-system, sans-serif;
}
.qrn-arab {
  font-family: 'Scheherazade New', 'Traditional Arabic', 'Amiri', 'Noto Naskh Arabic', serif;
  direction: rtl;
  text-align: right;
  font-size: 24px;
  line-height: 2.2;
  color: #e2e8f0;
  margin: 6px 0;
  padding: 4px 0;
  word-spacing: 2px;
}
.qrn-latin {
  font-style: italic;
  color: #94a3b8;
  font-size: 13px;
  line-height: 1.5;
  margin: 4px 0;
  padding: 2px 0;
}
.qrn-translate {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.55;
  margin: 4px 0 2px 0;
  padding-left: 8px;
  border-left: 2px solid #14b8a6;
}
.qrn-tafsir {
  background: #0a1628;
  border-left: 3px solid #f59e0b;
  padding: 10px 12px;
  margin: 8px 0;
  border-radius: 0 6px 6px 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: #cbd5e1;
}
.qrn-tafsir-label {
  display: inline-block;
  background: #f59e0b;
  color: #07101e;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
  letter-spacing: 0.3px;
}
/* Tajwid color classes (parsed from AlQuran.cloud [x:N[text] format) */
.t-ham-wasl    { color: #cbd5e1; }
.t-slnt        { color: #94a3b8; }
.t-madda-normal { color: #60a5fa; }
.t-madda-perm  { color: #818cf8; }
.t-madda-nec   { color: #a78bfa; }
.t-madda-obl   { color: #38bdf8; }
.t-qlq         { color: #f87171; }
.t-ghn         { color: #fb923c; }
.t-ikhf        { color: #e879f9; }
.t-ikhf-shfw   { color: #f0abfc; }
.t-idgh-shfw   { color: #6ee7b7; }
.t-idgh-ghn    { color: #34d399; }
.t-idgh-wghn   { color: #86efac; }
.t-idgh-mus    { color: #fcd34d; }
.t-iqlb        { color: #22d3ee; }
/* Tajwid legend (collapsible) */
.qrn-tajwid-legend {
  margin-top: 6px;
  font-size: 10.5px;
  color: #4a7a8a;
  line-height: 1.5;
  display: none;
}
.qrn-tajwid-legend.show { display: block; }
.qrn-tajwid-legend b { color: #94a3b8; }

/* Quran-render block (server-injected, replaces parsed markdown placeholder) */
.quran-render {
  margin: 12px 0;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  overflow: hidden;
}
.tajwid-ayat-block {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.tajwid-ayat-block:last-child { border-bottom: none; }
.tajwid-ayat-block .qrn-ayat-num {
  display: inline-block;
  width: 28px; height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 50%;
  background: var(--accent, #6c63ff);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}
.tajwid-ayat-block .qrn-arab {
  font-size: 26px;
  line-height: 2.2;
  text-align: right;
  margin: 8px 0;
  font-family: 'Amiri Quran', 'Amiri', 'Scheherazade New', serif;
}
.tajwid-ayat-block .qrn-terjemah {
  font-size: 14px;
  line-height: 1.7;
  color: rgba(255,255,255,0.85);
  font-style: italic;
  margin-bottom: 10px;
}
.tajwid-level-tabs {
  display: flex;
  gap: 6px;
  margin: 8px 0 4px;
  flex-wrap: wrap;
}
.tajwid-level-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.18);
  background: transparent;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tajwid-level-btn:hover {
  border-color: var(--accent, #6c63ff);
  color: #fff;
}
.tajwid-level-btn.active {
  background: var(--accent, #6c63ff);
  color: #fff;
  border-color: var(--accent, #6c63ff);
}
.tajwid-legend {
  font-size: 11px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  margin-top: 4px;
  color: rgba(255,255,255,0.7);
}
.tajwid-legend-title {
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: capitalize;
  font-size: 11px;
  color: rgba(255,255,255,0.6);
}
.tajwid-legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.tajwid-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tajwid-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 600px) {
  .qrn-arab { font-size: 20px; line-height: 2.0; }
  .qrn-surah-header { padding: 10px 12px; font-size: 13px; }
  .qrn-surah-header .qrn-arab { font-size: 18px; }
}

/* ── Custom Category Chips (beranda + topbar badge) ─────────────────────────── */
.chips-section-label {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-top: 10px;
  margin-bottom: 2px;
  text-align: center;
  opacity: .7;
}

.category-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 400px;
  margin-top: 4px;
}

.category-chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  user-select: none;
}

.category-chip:hover,
.category-chip:active {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.category-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-dim, rgba(20, 184, 166, .12));
  border: 0.5px solid var(--accent);
  color: var(--accent);
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s;
}
.category-badge:hover { opacity: .8; }

/* ── Settings: Category Chips manager ───────────────────────────────────────── */
.category-chips-manager {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.category-chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.category-chip-row .cat-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.category-chip-row .cat-label {
  flex: 1;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-chip-row .cat-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.category-chip-row .cat-icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all .15s;
  padding: 0;
}
.category-chip-row .cat-icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.category-chip-row .cat-icon-btn.danger:hover { border-color: #ef4444; color: #ef4444; }

.category-chip-editor {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
}

.category-chip-empty {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

@media (max-width: 600px) {
  .category-chips-container { gap: 4px; }
  .category-chip { padding: 5px 10px; font-size: 10px; }
  .chips-section-label { margin-top: 8px; }
}

/* ── Redesign Ngarti: Sidebar Dashboard button + Chat banners ─────────────── */

.sidebar-new-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 6px;
}
.sidebar-dashboard-btn {
  flex: 1;
  background: #0a1428;
  border: 0.5px solid #2a4878;
  border-radius: 20px;
  padding: 10px 28px;
  font-size: 14px;
  color: #6888d4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
  white-space: nowrap;
  text-align: center;
  font-weight: 600;
  margin: 0;
  width: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.sidebar-dashboard-btn:hover {
  background: #0d1e3a;
  border-color: #4a68b4;
  color: #88a8f4;
}
.sidebar-dashboard-btn:active { transform: scale(0.97); }

/* ── Sidebar mode chips (Mau Ngarti / Quick) ───────────────────────────────
   Sama dengan style dashboard: Ngarti = solid teal, Quick = border orange.
   Sidebar sempit → padding & font lebih kecil, tapi shape pill (20px) match. */
.sidebar-mode-chips {
  display: flex;
  gap: 6px;
  padding: 0 10px 8px;
}
.sidebar-chip-ngarti {
  flex: 1;
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 20px;
  padding: 10px 28px;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s, transform .15s;
  font-weight: 600;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.sidebar-chip-ngarti:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.sidebar-chip-ngarti:active { transform: scale(0.97); }

.sidebar-chip-qc {
  flex: 1;
  background: transparent;
  border: 1.5px solid var(--qc-color, #f59e0b);
  border-radius: 20px;
  padding: 10px 28px;
  font-size: 14px;
  color: var(--qc-color, #f59e0b);
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s, color .15s, transform .15s;
  font-weight: 600;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.sidebar-chip-qc:hover {
  background: color-mix(in srgb, var(--qc-color, #f59e0b) 12%, transparent);
}
.sidebar-chip-qc:active { transform: scale(0.97); }

/* Chat banner (memory & quick) — slim, di atas input area */
.chat-banner {
  padding: 6px 14px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}
.memory-banner {
  background: #0a1e18;
  border-bottom: 0.5px solid #1a3a2a;
  color: #4a9a7a;
}
.quick-banner {
  background: #1a1400;
  border-bottom: 0.5px solid #3a2800;
  color: #c8880a;
}
.banner-close {
  cursor: pointer;
  opacity: 0.6;
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
  user-select: none;
}
.banner-close:hover {
  opacity: 1;
}

/* ── Suggestion chip with optional ⚡ Quick badge ────────────────────────── */
.suggestion-chip-wrap {
  position: relative;
  display: inline-block;
}
.chip-qc-badge {
  font-size: 9px;
  position: absolute;
  top: -4px;
  right: -4px;
  background: #1a1200;
  border: 0.5px solid #4a3800;
  border-radius: 4px;
  padding: 1px 3px;
  line-height: 1;
  z-index: 1;
}

/* ── Settings chip-row: mode toggle (Ngarti / Quick) ────────────────────── */
.chip-settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.chip-settings-row .chip-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.chip-settings-row .chip-label {
  flex: 1;
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-mode-toggle {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.toggle-opt {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  border: 0.5px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}
.toggle-opt:hover { color: var(--text); }
.toggle-opt.active[data-mode="ngarti"] {
  background: #0a2a1e;
  border-color: #1a5a3a;
  color: #4a9a7a;
}
.toggle-opt.active[data-mode="quick"] {
  background: #1a1200;
  border-color: #4a3800;
  color: #c8880a;
}

/* ── Mode flash banner (ngarti vs quick chat) ─────────────────────────────── */
.mode-flash-banner {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 500;
  z-index: 500;
  pointer-events: none;
  white-space: nowrap;
  animation: flashIn 0.25s ease;
}
.mode-flash-banner.hidden {
  display: none;
}
.mode-flash-banner.ngarti {
  background: #0a2a1e;
  border: 0.5px solid #1a5a3a;
  color: #4a9a7a;
}
.mode-flash-banner.quick {
  background: #1a1200;
  border: 0.5px solid #4a3800;
  color: #c8880a;
}
@keyframes flashIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ── Analysis Dropdown (used in input area) ─────────────────────────────── */
.analysis-dropdown {
  background: #0d1f35;
  border: 1px solid #1a3a58;
  border-radius: 12px;
  padding: 6px;
  min-width: 200px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: analysisDropIn 0.2s ease;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 100;
}

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

.analysis-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: 8px;
  color: #c8dde8;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.analysis-option:hover {
  background: #162a42;
  color: #fff;
}

.analysis-option:active {
  background: #1a3a58;
}

.analysis-icon {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.analysis-label {
  font-weight: 500;
}

/* ── Analysis Mode Chip (shown in attachment-preview) ────────────────────── */
.analysis-mode-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  animation: slideDown 0.2s ease;
}

.analysis-mode-chip.hidden {
  display: none;
}

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

.analysis-mode-chip[data-mode="image"] {
  background: linear-gradient(90deg, #0a1a2e, #0c2a42);
  border: 1px solid #1a4a6a;
  color: #4ab8d4;
}

.analysis-mode-chip[data-mode="doc"] {
  background: linear-gradient(90deg, #1a1200, #2a1e00);
  border: 1px solid #4a3800;
  color: #c8880a;
}

.analysis-mode-chip[data-mode="data"] {
  background: linear-gradient(90deg, #120a1e, #1e0c2e);
  border: 1px solid #3a1a6a;
  color: #a87cd4;
}

/* ── NEVI Mode Chips (topbar) ───────────────────────────────────────────────── */
.topbar-nevi-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-nevi-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-right: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.nevi-mode-chip {
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid #3a3a5a;
  background: #1e1e30;
  color: #c8c8e8;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.nevi-mode-chip:hover {
  background: #2a2a4e;
  border-color: #5a5a8a;
}
.nevi-mode-chip.nevi-mode-chip-active {
  background: #2a3a6a;
  border-color: #5a8aaa;
  color: #a8d8f8;
  font-weight: 600;
}

/* ── Suggestion Card Overlay (Crisis Intervention) ─────────────────────────── */
.suggestion-card-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.suggestion-card {
  background: #1e1e30;
  border: 1px solid #3a3a5a;
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.suggestion-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.suggestion-card-icon {
  font-size: 28px;
  line-height: 1;
}

.suggestion-card-label {
  font-size: 16px;
  font-weight: 600;
  color: #e0e0f0;
}

.suggestion-card-body {
  font-size: 14px;
  line-height: 1.65;
  color: #b0b0cc;
  margin: 0;
}

