/* chat.css — pesan, contoh pertanyaan, chat tools, riwayat, composer. */

/* ---------- Pesan chat ---------- */
.msg { margin-bottom: 18px; animation: rise 0.2s ease; flex: none; }
.who {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.bubble {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 84%;
  overflow-wrap: break-word;
}
.msg.user .who { text-align: right; }
 .msg.user .bubble {
  margin-left: auto;
  background: var(--bubble-user);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-bottom-right-radius: 5px;
}
.msg.assistant .bubble {
  background: var(--bubble-assistant);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.msg.refuse .bubble {
  background: var(--surface2);
  border-color: var(--line-strong);
}
.cites {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cite {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text-secondary);
  max-width: 290px;
}
.cite b { color: var(--accent-text); font-weight: 600; display: block; margin-bottom: 2px; }
.kv { color: var(--muted); font-size: 13px; }
.badges {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
}
.badge.ok { color: var(--ok); border-color: transparent; background: transparent; }
.badge.conflict { color: var(--warn); border-color: rgba(226, 183, 106, 0.4); }
.badge.inject { color: var(--danger); border-color: transparent; background: transparent; }
.badge.pii { color: var(--ok); border-color: rgba(53, 183, 137, 0.4); }
.badge.warn { color: var(--warn); border-color: rgba(226, 183, 106, 0.4); }
.note { margin-top: 8px; font-size: 13px; color: var(--warn); }
.link-btn {
  background: none;
  border: none;
  color: var(--accent-text);
  cursor: pointer;
  font-size: 13.5px;
  padding: 0;
  font: inherit;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Chat tools (chat baru / riwayat) ---------- */
.chat-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px 0;
  flex: none;
}
.chat-tool {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chat-tool:hover { background: var(--surface3); color: var(--ink); border-color: var(--line-strong); }
.chat-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat-tool svg { flex: none; }

/* Judul layar chat: satu-satunya h1 di dokumen saat workspace terbuka.
   Ukurannya sengaja kecil — ini nama layar, bukan headline pemasaran. */
.chat-title {
  margin: 0 10px 0 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* ---------- Riwayat chat (rail kanan) ---------- */
.fb.sent { opacity: 0.55; }
.hist { display: flex; flex-direction: column; height: 100%; padding: 14px 12px 10px; gap: 10px; }
.hist-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px;
}
.hist-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0;
  color: var(--faint);
}
.hist-new {
  border: 0; background: none; color: var(--accent-text);
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
  cursor: pointer; padding: 4px 6px; border-radius: 7px;
}
.hist-new:hover { background: var(--surface3); color: var(--accent-hi); }
.hist-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.hist-row {
  display: flex; align-items: center; gap: 4px;
  border-radius: 9px; padding: 2px 4px 2px 2px;
  transition: background 110ms ease;
}
.hist-row:hover { background: var(--surface3); }
.hist-row.active { background: var(--surface2); }
.hist-open {
  flex: 1; min-width: 0; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 8px 8px; border-radius: 7px; color: inherit;
  font-family: var(--font-ui);
  display: flex; flex-direction: column; gap: 2px;
}
.hist-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.hist-name {
  font-size: 13px; font-weight: 550; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hist-meta { font-size: 11px; color: var(--faint); }
.hist-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 110ms ease; }
.hist-row:hover .hist-actions, .hist-row:focus-within .hist-actions { opacity: 1; }
.hist-icon {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: none; border-radius: 7px;
  color: var(--faint); cursor: pointer;
}
.hist-icon:hover { background: var(--surface2); color: var(--ink); }
.hist-icon.danger:hover { color: var(--danger); }
.hist-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hist-empty { font-size: 12.5px; color: var(--faint); padding: 10px 6px; line-height: 1.5; }
/* Paging riwayat: baris aksi, bukan percakapan — sengaja lebih redup dan
   tanpa border kartu supaya tidak terbaca sebagai sesi ke-sekian. */
.hist-more {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  background: transparent;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.hist-more:hover { background: var(--surface2); color: var(--ink); border-color: var(--line-strong); }
.hist-more:disabled { cursor: default; color: var(--faint); }
.hist-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hist-note { font-size: 11px; color: var(--faint); padding: 0 6px; line-height: 1.45; }
/* Perangkat sentuh tidak punya hover: aksi rename/hapus harus selalu terlihat. */
@media (hover: none) {
  .hist-actions { opacity: 1; }
}

/* ---------- Panel rekomendasi (empty state) ----------
   Struktur mengikuti referensi: header + aksi di kanan, lalu grid kartu.
   Kartu adalah pintasan tugas nyata; klik hanya mengisi composer. */
.recs-wrap { width: 100%; max-width: 920px; margin: 0 auto; }
.recs-wrap.gone { display: none; }
.recs { display: flex; flex-direction: column; gap: 12px; }
.recs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}
.recs-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
}
.recs-actions { display: flex; align-items: center; gap: 2px; }
.recs-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.recs-icon:hover { background: var(--surface2); color: var(--ink); }
.recs-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.recs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.rec-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  min-width: 0;
  text-align: left;
  padding: 15px 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: inherit;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 130ms ease, border-color 130ms ease;
}
.rec-card:hover { background: var(--surface2); border-color: var(--line-strong); }
.rec-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rec-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-bottom: 3px;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--muted);
  transition: color 130ms ease, background 130ms ease;
}
.rec-card:hover .rec-icon { color: var(--ink); background: var(--surface3); }
.rec-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.rec-desc {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--faint);
  overflow-wrap: anywhere;
}

/* ---------- Composer ----------
   Dua tingkat seperti referensi:
   .composer-shell  = panel luar (tanpa border, hanya surface sedikit terangkat)
   .composer-box    = kotak input (border tipis) tempat textarea + aksi.
   Tidak ada ring/shadow biru saat fokus. */
/* Composer adalah KOLOM: shell, lalu menu popover, lalu hint — bertumpuk
   vertikal. Dengan arah baris (default), `.cb-menu` yang absolut tetap aman,
   tetapi `.cb-hint` akan tampil di samping shell, bukan di bawahnya. */
.composer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 20px 4px;
  flex: none;
}
.composer-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  background: var(--composer-shell);
  border: 1px solid var(--composer-line);
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
}
.composer-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 43px;
  padding: 0 7px;
  min-width: 0;
}
.cb-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  height: 30px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--composer-chip);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.cb-chip:hover { background: var(--surface3); color: var(--ink); }
.cb-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cb-chip svg { flex: none; }
.cb-chip-label {
  min-width: 0;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Kotak input menempel penuh selebar shell dan flush ke bawah (referensi):
   margin negatif menutup border shell di kiri/kanan/bawah, lalu shell yang
   memotong sudutnya (overflow:hidden + radius 14). */
.composer-box {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: auto;
  margin: 0 -1px -1px;
  background: var(--composer-box);
  border: 1px solid var(--composer-line-inner);
  /* Sudut bawah sengaja kotak: garis bawah menempel rata ke shell dan hanya
     lengkung shell (radius 14) yang terlihat — persis referensi. */
  border-radius: 12px 12px 0 0;
  padding: 14px 12px 12px;
  transition: border-color 140ms ease;
}
.composer-box:focus-within { border-color: var(--line-strong); }

.composer textarea {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 15px;
  font-family: var(--font-ui);
  line-height: 1.5;
  outline: none;
  resize: none;
  padding: 4px 4px 6px;
  min-height: 40px;
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}
.composer textarea::placeholder { color: var(--composer-ph); opacity: 1; }
.composer textarea:focus,
.composer textarea:focus-visible {
  outline: none;
  box-shadow: none;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.cb-spacer { flex: 1 1 auto; }
.cb-icon {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--composer-chip);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.cb-icon:hover { background: var(--surface3); color: var(--ink); border-color: var(--line-strong); }
.cb-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cb-icon.plain { border-color: transparent; }
.cb-icon.plain:hover { background: transparent; border-color: transparent; color: var(--ink); }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--composer-send);
  border: 0;
  color: var(--composer-send-ink);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 100ms ease;
}
.send-btn .stop-icon { display: none; }
.send-btn:hover { color: var(--ink); }
.send-btn:active { transform: scale(0.94); }
.send-btn.has-input,
.send-btn.busy {
  background: #FFFFFF;
  color: #000000;
}
.send-btn.busy .send-icon { display: none; }
.send-btn.busy .stop-icon { display: block; }
.send-btn[disabled] {
  cursor: not-allowed;
  background: var(--composer-send);
  color: var(--composer-send-ink);
}
.send-btn[disabled]:hover { color: var(--composer-send-ink); }
.send-btn[disabled]:active { transform: none; }

/* Dropdown Cloud / Proyek — fixed, di-clamp ke viewport oleh JS. */
.cb-menu {
  position: fixed;
  z-index: 96;
  min-width: 200px;
  max-width: min(280px, calc(100vw - 16px));
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
  animation: rise 0.12s ease;
}
.cb-menu[hidden] { display: none; }
.cb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
.cb-item:hover { background: var(--surface3); color: var(--ink); }
.cb-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cb-item[aria-checked="true"] { color: var(--ink); }
.cb-item[aria-checked="true"] .cb-item-label::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.cb-item[aria-disabled="true"] { color: var(--faint); cursor: not-allowed; }
.cb-item[aria-disabled="true"]:hover { background: transparent; color: var(--faint); }
.cb-item-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cb-item-note { flex: none; font-size: 11px; color: var(--faint); }
.cb-empty { padding: 8px 10px; font-size: 12px; color: var(--faint); }

.cb-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}
.cb-hint[hidden] { display: none; }

@media (max-width: 1100px) {
  .recs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .recs-grid { grid-template-columns: 1fr; }
  .recs-wrap { max-width: none; }
}
@media (max-width: 600px) {
  .composer { padding: 8px 12px 2px; }
  .composer-bar { height: 36px; padding: 0 6px; }
  .cb-chip { font-size: 12px; padding: 0 6px; }
  .cb-chip-label { max-width: 120px; }
  /* 18px menyamai .page-inner di ponsel; 12px membuat judul "Chat" menempel
     ke tepi (12px dari tepi = WARN inspector). */
  .chat-tools { padding: 8px 18px 0; }
  .ai-note { padding: 0 18px; }
  .chat-tool span { display: none; }
  .chat-tool { padding: 0 9px; }
  .composer-box { padding: 8px 8px 6px; }
  .composer textarea { font-size: 15px; }
  .composer-actions { gap: 4px; }
  .cb-icon, .send-btn { width: 30px; height: 30px; }
}

/* Catatan AI di bawah composer */
.ai-note {
  width: 100%;
  /* Padding mendatar wajib: catatan ini selebar .chat-box, jadi tanpa padding
     baris terpanjangnya menempel ke tepi layar (15px pada 768px). Samakan
     dengan padding .composer agar sumbu teksnya konsisten. */
  padding: 0 24px;
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  text-align: center;
  user-select: none;
}

/* ---------- Latar dekoratif chat kosong ----------
   Hanya aktif saat #chatPane belum punya pesan (`.is-empty` dipasang/dilepas
   oleh view.js). Mozaik wireframe UI diletakkan pada lapisan pseudo selebar
   pane — bukan pada .chat-box yang hanya 960px — supaya tetap mengisi seluruh
   area body dan tidak terpotong. Lapisan ini non-interaktif dan berada di
   bawah konten (z-index 0 vs .chat-box z-index 1).
   Bagian tengah dimask agar kartu rekomendasi & composer tetap bersih. */
#chatPane { position: relative; }
#chatPane::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--chat-mosaic);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  opacity: 0;
  -webkit-mask-image: var(--chat-mosaic-mask);
  mask-image: var(--chat-mosaic-mask);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
  transition: opacity 220ms var(--motion-ease);
}
#chatPane.is-empty::before { opacity: var(--chat-mosaic-opacity); }
#chatPane > .chat-box { position: relative; z-index: 1; }

/* Layar sempit: pane hanya selebar viewport, jadi mozaik dibuat lebih pudar
   agar tidak mengganggu keterbacaan teks di atasnya. */
@media (max-width: 900px) {
  #chatPane.is-empty::before { opacity: calc(var(--chat-mosaic-opacity) * 0.6); }
}
/* Hormati preferensi minim gerak: tidak ada transisi pudar. */
@media (prefers-reduced-motion: reduce) {
  #chatPane::before { transition: none; }
}

/* ---------- Jejak kerja agent ----------
   Ringkas dan tidak menonjol: pengguna yang tidak ingin detail cukup melihat
   ringkasan "N langkah diproses" tanpa harus membaca setiap tool. */
.trace {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.trace > summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.trace > summary::-webkit-details-marker { display: none; }
.trace > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  opacity: 0.7;
}
.trace[open] > summary::before { transform: rotate(90deg); }
.trace > summary:hover { background: var(--surface3); color: var(--ink); }
.trace > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tr-list {
  list-style: none;
  margin: 0;
  padding: 2px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tr-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--line);
}
.tr-item:first-child { border-top: 0; }
.tr-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  transform: translateY(-1px);
}
.tr-item.bad .tr-dot { background: var(--danger); }
.tr-label { color: var(--ink); }
.tr-hint {
  color: var(--faint);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ---------- Kartu konfirmasi draft ----------
   Draft belum berefek apa pun sampai tombol ditekan, jadi kartunya dibuat
   tegas (border aksen tipis) tanpa warna latar besar. */
.prep {
  margin-top: 10px;
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
}
.prep.done { border-left-color: var(--ok); }
.prep-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.prep-kind { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.prep-state {
  font-size: 11.5px;
  color: var(--faint);
  text-transform: lowercase;
}
.prep-body {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.prep-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.prep-actions button {
  font-family: inherit;
  font-size: 12.5px;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  border: 1px solid var(--line-strong);
  background: var(--surface2);
  color: var(--ink);
  transition: background 0.15s, border-color 0.15s;
}
.prep-actions button:hover { background: var(--surface3); }
.prep-actions button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.prep-actions button:disabled { opacity: 0.55; cursor: default; }
.prep-ok {
  background: var(--accent-fill) !important;
  border-color: var(--accent-fill) !important;
  color: var(--accent-ink) !important;
  font-weight: 600;
}
.prep-ok:hover { background: var(--accent-hi) !important; border-color: var(--accent-hi) !important; }
