:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --ink: #1a1c1e;
  --ink-2: #5a5f64;
  --ink-3: #8a8f94;
  --line: #e4e4e0;
  --accent: #1d4e89;
  --accent-2: #16395f;
  --danger: #b3402e;
  --ok: #2e7d4f;
  --radius: 12px;
  --font: "Inter Tight", "Inter", system-ui, -apple-system, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

.app { display: flex; flex-direction: column; height: 100dvh; }

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

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

.brand-mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 8px;
  font-size: 15px;
}

.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.model-picker { display: flex; align-items: center; gap: 12px; }

.model-picker select {
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.rag-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.rag-toggle input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ── Layout ─────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

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

.panel-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 12px;
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 12px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: center;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #f4f7fa;
}

.dz-icon {
  font-size: 20px; color: var(--accent);
  font-weight: 500; line-height: 1;
}

.dz-text { font-size: 13px; font-weight: 600; }
.dz-hint { font-size: 11px; color: var(--ink-3); }

/* Document list */
.doc-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.doc-meta { min-width: 0; }
.doc-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; }

.doc-actions { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 26px; height: 26px;
  border-radius: 7px;
  display: grid; place-items: center;
  color: var(--ink-2);
  font-size: 14px;
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: #f8ece9; color: var(--danger); }

.doc-empty {
  font-size: 12px; color: var(--ink-3);
  text-align: center; padding: 14px 0;
}

/* Activity */
.activity-list { display: flex; flex-direction: column; gap: 2px; }

.activity-item {
  display: flex;
  gap: 8px;
  padding: 6px 2px;
  font-size: 12px;
}

.activity-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.activity-dot.upload { background: var(--ok); }
.activity-dot.update { background: var(--accent); }
.activity-dot.delete { background: var(--danger); }

.activity-body { min-width: 0; }
.activity-title { font-weight: 500; }
.activity-time { color: var(--ink-3); font-size: 11px; }

/* ── Chat pane ──────────────────────────────────── */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--bg);
}

.messages {
  flex: 1;
  min-height: 0; /* wajib: biar container bisa menyusut dan scroll aktif */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome { text-align: center; padding: 48px 24px; }
.welcome-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.welcome-sub { font-size: 13px; color: var(--ink-2); margin-top: 6px; max-width: 44ch; margin-left: auto; margin-right: auto; }

.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg.assistant .bubble.error { border-color: #e8c9c2; color: var(--danger); }

/* ── Markdown dalam bubble ─────────────────────── */
.bubble.md p { margin: 0 0 8px; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md h1, .bubble.md h2, .bubble.md h3, .bubble.md h4 {
  margin: 14px 0 6px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.bubble.md h1 { font-size: 17px; }
.bubble.md h2 { font-size: 16px; }
.bubble.md h3 { font-size: 15px; }
.bubble.md ul, .bubble.md ol { margin: 0 0 8px; padding-left: 20px; }
.bubble.md li { margin-bottom: 3px; }
.bubble.md code {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
}
.bubble.md pre {
  background: #1a1c1e;
  color: #e8e8e6;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.bubble.md pre code { background: transparent; color: inherit; padding: 0; font-size: 12.5px; }
.bubble.md blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 0 0 8px;
  color: var(--ink-2);
}
.bubble.md table {
  border-collapse: collapse;
  margin: 0 0 8px;
  font-size: 13px;
}
.bubble.md th, .bubble.md td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
}
.bubble.md th { background: var(--surface-2); font-weight: 600; }
.bubble.md a { color: var(--accent); text-decoration: underline; }
.bubble.md strong { font-weight: 600; }

/* ── Citation chip ──────────────────────────────── */
.cite-chip {
  border: none;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--font);
  font-size: 11.5px;
  padding: 0 2px;
  cursor: default;
  vertical-align: super;
  font-weight: 600;
}

.cite-chip.linked {
  color: var(--accent);
  cursor: pointer;
}

.cite-chip.linked:hover {
  text-decoration: underline;
}

.sources {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
}

.source-chip summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 500;
  list-style: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

.source-chip summary::before { content: "▸"; font-size: 10px; color: var(--accent); }
.source-chip[open] summary::before { transform: rotate(90deg); }

.source-text {
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 12px;
  max-height: 150px;
  overflow-y: auto;
  white-space: pre-wrap;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.typing { display: inline-flex; gap: 3px; padding: 4px 2px; }
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ── Composer ───────────────────────────────────── */
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 20px 18px;
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  resize: none;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  max-height: 160px;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.1);
}

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.06s ease;
  flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-2); }
.send-btn:active { transform: scale(0.98); }
.send-btn:disabled { background: #9fb2c6; cursor: not-allowed; }

/* ── Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  max-width: 80vw;
}

.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open {
    display: flex;
    position: absolute;
    top: 56px; left: 0; bottom: 0;
    width: 280px;
    z-index: 40;
    box-shadow: 4px 0 16px rgba(0,0,0,0.08);
  }
  .msg { max-width: 92%; }
}
