/* ============================================================
   PanCoder — coding agent & app maker
   Arah desain: neo-brutalis "kertas & tinta".
   Hard border hitam, bayangan offset tanpa blur, palet biru listrik.
   Sengaja dijauhkan dari gaya glassmorphism gelap + aksen amber.
   ============================================================ */

/* Aturan author dengan `display` eksplisit mengalahkan [hidden] bawaan
   browser, sehingga `el.hidden = true` diam-diam gagal menyembunyikan. */
[hidden] { display: none !important; }

:root {
  --paper: #f4f1ea;
  --paper-2: #fffdf7;
  --paper-3: #e8e3d7;
  --ink: #10100e;
  --ink-2: #3a3a34;
  --ink-3: #7c7a70;
  --ink-4: #5f5d54;
  --line: #10100e;
  --line-soft: rgba(16, 16, 14, .18);

  --blue: #2f5bff;
  --blue-deep: #1c3fd6;
  /* Warna teks di atas aksen: putih saat aksen gelap, tinta saat aksen terang. */
  --on-accent: #ffffff;
  --green: #00b862;
  --coral: #ff5a5f;
  --yellow: #ffd500;
  --violet: #7a4dff;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --bd: 2px;
  --bd-fat: 3px;
  --pop: 5px 5px 0 var(--line);
  --pop-sm: 3px 3px 0 var(--line);
  --pop-lg: 7px 7px 0 var(--line);

  --font: "Space Grotesk", ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Archivo Black", "Space Grotesk", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --paper: #10100e;
  --paper-2: #191916;
  --paper-3: #232320;
  --ink: #f4f1ea;
  --ink-2: #c9c5b8;
  --ink-3: #8b887c;
  --ink-4: #9d9a8e;
  --line: #f4f1ea;
  --line-soft: rgba(244, 241, 234, .22);
  --blue: #6d8cff;
  --blue-deep: #2f5bff;
  /* Aksen mode gelap terlalu terang untuk teks putih — pakai tinta. */
  --on-accent: #10100e;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* Grid titik halus — latar kertas bergrafis, tanpa blur/glow. */
  background-image: radial-gradient(var(--line-soft) 1px, transparent 1px);
  background-size: 22px 22px;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--blue); font-weight: 600; }
code {
  font-family: var(--mono); font-size: .9em;
  background: var(--paper-3); border: 1px solid var(--line-soft);
  padding: 1px 6px; border-radius: 6px;
}

/* Elemen dekoratif lama: dipertahankan sebagai pita diagonal, bukan glow. */
.glow-a, .glow-b { display: none; }

.layout { position: relative; display: flex; height: 100dvh; gap: 18px; padding: 18px; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 280px; flex: 0 0 280px;
  background: var(--paper-2);
  border: var(--bd) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--pop);
  display: flex; flex-direction: column;
  padding: 14px; min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 40px;
  background: var(--blue);
  border: var(--bd) solid var(--line);
  color: var(--on-accent); font-family: var(--font-display); display: grid; place-items: center;
  font-size: 19px; box-shadow: var(--pop-sm);
  transform: rotate(-4deg);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-name { font-family: var(--font-display); letter-spacing: -.6px; font-size: 17px; text-transform: uppercase; }
.brand-tag {
  font-size: 10px; color: var(--ink-4); letter-spacing: .16em;
  text-transform: uppercase; font-weight: 700;
}
.brand .icon-btn { margin-left: auto; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: var(--bd) solid var(--line); background: var(--paper-2);
  cursor: pointer; display: grid; place-items: center;
  color: var(--ink); transition: .12s; flex: 0 0 auto; box-shadow: var(--pop-sm);
}
.icon-btn:hover { background: var(--yellow); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--line); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.icon-btn.primary { background: var(--blue); border: var(--bd) solid var(--line); color: var(--on-accent); font-size: 17px; line-height: 1; }

.new-session {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px; cursor: pointer;
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  background: var(--blue); color: var(--on-accent);
  font-family: var(--font-display); font-size: 13.5px;
  text-transform: uppercase; letter-spacing: .02em;
  box-shadow: var(--pop-sm);
  transition: transform .12s, box-shadow .12s, background .12s;
  margin-bottom: 16px;
}
.new-session span { font-size: 18px; line-height: 1; }
.new-session:hover { background: var(--blue-deep); transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--line); }
.new-session:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }

.section-label {
  font-size: 10.5px; letter-spacing: .18em; color: var(--ink-4);
  font-weight: 700; margin: 0 4px 8px; text-transform: uppercase;
  display: flex; align-items: center; gap: 7px;
}
.section-label::after { content: ""; flex: 1; height: 0; border-top: 2px dashed var(--line-soft); }
.sessions { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 2px; min-height: 0; }
.sessions::-webkit-scrollbar, .chat::-webkit-scrollbar, .modal-card::-webkit-scrollbar,
.code-view::-webkit-scrollbar, .file-list::-webkit-scrollbar, .db-preview::-webkit-scrollbar, pre.result::-webkit-scrollbar { width: 9px; height: 9px; }
.sessions::-webkit-scrollbar-thumb, .chat::-webkit-scrollbar-thumb, .modal-card::-webkit-scrollbar-thumb,
.code-view::-webkit-scrollbar-thumb, .file-list::-webkit-scrollbar-thumb, .db-preview::-webkit-scrollbar-thumb, pre.result::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 99px; border: 2px solid var(--paper-2);
}
.empty-small { color: var(--ink-4); font-size: 13px; padding: 10px 6px; }

.session-item {
  position: relative;
  padding: 10px 34px 10px 11px; border-radius: var(--radius-sm); cursor: pointer;
  border: var(--bd) solid transparent; display: flex; gap: 9px; align-items: flex-start;
  transition: background .12s, border-color .12s, transform .12s, box-shadow .12s;
  user-select: none;
}
.session-item:hover { background: var(--paper-3); border-color: var(--line); }
.session-item.active {
  background: var(--blue); border-color: var(--line);
  box-shadow: var(--pop-sm); color: var(--on-accent);
}
.session-item.active .session-meta { color: rgba(255, 255, 255, .8); }
.session-item.active .dot { background: var(--yellow); }
.session-item:active { transform: translate(2px, 2px); }
.dot {
  width: 9px; height: 9px; border-radius: 3px; background: var(--blue);
  border: 1.5px solid var(--line); margin-top: 6px; flex: 0 0 9px;
}
.session-body { min-width: 0; flex: 1; }
.session-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 10.5px; color: var(--ink-4); font-family: var(--mono); }
.session-item.active .session-meta { color: rgba(255, 255, 255, .92); }
.del-session {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border-radius: 7px; cursor: pointer;
  border: var(--bd) solid transparent; background: transparent; color: var(--ink-3);
  display: grid; place-items: center; font-size: 12px; opacity: 0; transition: .12s;
}
.session-item:hover .del-session, .session-item:focus-within .del-session { opacity: 1; }
.session-item.active .del-session { color: rgba(255, 255, 255, .85); }
.del-session:hover { background: var(--coral); border-color: var(--line); color: #fff; }

.sidebar-foot {
  border-top: var(--bd) dashed var(--line-soft); padding-top: 10px;
  margin-top: 10px; display: flex; flex-direction: column; gap: 5px;
}
.foot-btn {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: none; border: var(--bd) solid transparent; padding: 9px 10px;
  border-radius: var(--radius-sm); color: var(--ink-2); cursor: pointer;
  font-size: 12.5px; font-weight: 600; text-align: left; transition: .12s;
}
.foot-btn:hover { background: var(--paper-3); border-color: var(--line); color: var(--ink); }
.foot-btn .ico { display: inline-flex; align-items: center; color: var(--ink-2); }

/* ---------- main ---------- */
.main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--paper-2);
  border: var(--bd) solid var(--line); border-radius: var(--radius);
  box-shadow: var(--pop); overflow: hidden; min-height: 0;
}
/* Anak-anak .main wajib boleh menyusut. Tanpa min-height: 0 pada .chat,
   keduanya berhenti di ukuran kontennya sendiri: di viewport pendek
   (HP landscape) composer melar melewati .main yang overflow:hidden, sehingga
   baris chip lampiran terpotong dan tak bisa dijangkau karena body juga
   overflow:hidden. Composer sendiri justru TIDAK boleh menyusut — kalau ia
   mengecil di bawah tinggi kontennya, chip lampiran yang baru diunggah
   menghilang dari layar. Ruang diambil dari .chat. */
.main > .chat { min-height: 0; flex: 1 1 0; }
.main > .composer { flex: 0 0 auto; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: var(--bd) solid var(--line);
  background: var(--paper-3); flex-wrap: wrap;
}
.title-wrap { min-width: 0; flex: 1 1 180px; }
.title { font-weight: 700; font-size: 15px; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 11px; color: var(--ink-4); font-family: var(--mono); }
.topbar-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.chip {
  border: var(--bd) solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: var(--radius-pill); padding: 5px 12px; font-size: 11.5px;
  font-weight: 700; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  transition: transform .12s, box-shadow .12s, background .12s;
  box-shadow: 2px 2px 0 var(--line);
}
.chip:hover { background: var(--yellow); transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--line); }
.chip:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.chip.accent { background: var(--green); border-color: var(--line); color: #06210f; }
.chip.kredit { cursor: default; color: var(--ink-3); box-shadow: none; }

/* Status dibedakan bentuknya dari chip aksi: bukan pill, tanpa bayangan. */
.status {
  display: inline-flex; align-items: center; gap: 7px; font-size: 10.5px;
  color: var(--ink); padding: 4px 10px; font-weight: 700;
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  background: transparent; font-family: var(--mono); text-transform: uppercase;
  letter-spacing: .08em;
}
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); border: 1.5px solid var(--line); }
[data-theme="dark"] .status { color: var(--ink-2); border-color: var(--ink-3); }
[data-theme="dark"] .status i { background: var(--ink-2); }
.status.running { background: var(--yellow); color: var(--ink); }
.status.running i { background: var(--coral); animation: blink .9s steps(2, start) infinite; }
.status.waiting { background: var(--coral); color: #fff; }
.status.waiting i { background: #fff; }
@keyframes blink { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

/* ---------- chat ---------- */
.chat {
  flex: 1; overflow-y: auto; padding: 24px 24px 10px;
  scroll-padding-top: 12px;
  scroll-behavior: smooth;
  /* Kolom flex supaya hero kosong bisa di tengah vertikal (margin:auto). */
  display: flex; flex-direction: column;
}

.welcome { text-align: center; margin: auto; max-width: 620px; color: var(--ink-2); }
.welcome-logo {
  width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 20px;
  background: var(--blue); border: var(--bd-fat) solid var(--line);
  color: var(--on-accent); display: grid; place-items: center;
  font-family: var(--font-display); font-size: 32px;
  box-shadow: var(--pop-lg);
  transform: rotate(-5deg);
}
.welcome h1 {
  font-family: var(--font-display); font-size: 30px; margin: 0 0 10px;
  color: var(--ink); letter-spacing: -1.2px; text-transform: uppercase;
  line-height: 1.05;
}
.welcome h1 em { font-style: normal; color: var(--blue); }
.welcome p { margin: 0 0 8px; font-size: 14.5px; }

/* Pita berjalan — bagian dari sistem brutalist: balok hitam bertepi tegas,
   bukan gradient. Animasi marquee supaya teks tidak terlihat "terpotong". */
.ticker {
  position: relative;
  background: var(--ink);
  color: var(--paper);
  overflow: hidden;
  margin: 0 auto 22px;
  padding: 9px 0;
  white-space: nowrap;
  border: var(--bd) solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--pop-sm);
}
[data-theme="dark"] .ticker { background: var(--blue); color: var(--on-accent); }
.ticker-track {
  display: inline-block; animation: slide 26s linear infinite;
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
  font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
}
.ticker-track span { padding: 0 14px; }
@keyframes slide { from { transform: translateX(0) } to { transform: translateX(-50%) } }

.idea-row { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.idea {
  border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-pill); padding: 9px 16px; font-size: 13px;
  font-weight: 700; cursor: pointer; color: var(--ink); transition: .12s;
  box-shadow: var(--pop-sm); display: inline-flex; align-items: center; gap: 7px;
}
.idea svg { color: var(--blue); flex: 0 0 auto; }
.idea:hover { background: var(--yellow); transform: translate(-2px, -2px); box-shadow: 5px 5px 0 var(--line); }
.idea:hover svg { color: var(--ink); }
.idea:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }

.msg { display: flex; gap: 11px; margin-bottom: 18px; max-width: 900px; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  border: var(--bd) solid var(--line); font-family: var(--mono);
  box-shadow: var(--pop-sm);
}
.msg.user .avatar { background: var(--yellow); color: var(--ink); }
.msg.agent .avatar { background: var(--blue); color: var(--on-accent); }
.msg .body { min-width: 0; flex: 1; }
.msg .who {
  font-size: 9.5px; letter-spacing: .16em; color: var(--ink-3);
  font-weight: 700; margin-bottom: 5px; text-transform: uppercase;
  font-family: var(--mono);
}
.bubble { word-wrap: break-word; }
/* Markdown agent: jarak antar blok rapat supaya tetap terasa satu pesan. */
.msg.agent .bubble > *:first-child { margin-top: 0; }
.msg.agent .bubble > *:last-child { margin-bottom: 0; }
.msg.agent .bubble p { margin: 0 0 9px; }
.msg.agent .bubble ul, .msg.agent .bubble ol { margin: 0 0 9px; padding-left: 22px; }
.msg.agent .bubble li { margin: 2px 0; }
.msg.agent .bubble li::marker { color: var(--blue); font-weight: 700; }
.msg.agent .bubble .md-h {
  font-family: var(--font-display); text-transform: uppercase;
  letter-spacing: -.3px; line-height: 1.2; margin: 14px 0 7px; color: var(--ink);
}
.msg.agent .bubble .md-h1 { font-size: 17px; }
.msg.agent .bubble .md-h2 { font-size: 15px; }
.msg.agent .bubble .md-h3, .msg.agent .bubble .md-h4 { font-size: 13px; letter-spacing: .02em; }
.msg.agent .bubble hr { border: 0; border-top: var(--bd) dashed var(--line-soft); margin: 12px 0; }
.msg.agent .bubble .md-code {
  font-family: var(--mono); font-size: 12px; background: var(--ink);
  color: var(--paper); border: var(--bd) solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 13px;
  margin: 9px 0; overflow-x: auto; white-space: pre;
}
[data-theme="dark"] .msg.agent .bubble .md-code { background: #050504; }
.msg.agent .bubble a { color: var(--blue); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.msg.agent .bubble strong { font-weight: 700; color: var(--ink); }
.msg.agent .bubble { font-size: 14.5px; }
.msg.user .bubble {
  background: var(--paper-2);
  border: var(--bd) solid var(--line);
  padding: 10px 14px; border-radius: 12px 12px 12px 3px; display: inline-block;
  box-shadow: var(--pop-sm);
}

/* ---------- workbench: satu aksi agent = satu langkah bernomor ---------- */
.tool {
  display: flex; gap: 9px; align-items: flex-start; font-family: var(--mono);
  font-size: 12px; background: var(--paper-2);
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 11px; margin: 4px 0 4px 45px;
  box-shadow: 2px 2px 0 var(--line);
  animation: rise .18s ease;
}
.tool .tag {
  color: #06210f; font-weight: 700; flex: 0 0 auto;
  background: var(--green); border: 1.5px solid var(--line);
  border-radius: 6px; padding: 1px 7px; font-size: 10.5px; text-transform: uppercase;
}
.tool.running .tag { background: var(--yellow); color: var(--ink); }
.tool.fail .tag { background: var(--coral); color: #fff; }
.tool .cmd { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tool .det {
  color: var(--blue); cursor: pointer; flex: 0 0 auto;
  font-weight: 700; border-bottom: 1.5px dotted var(--blue);
}
pre.result {
  font-family: var(--mono); font-size: 11.5px; background: var(--ink);
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 13px; margin: 3px 0 10px 45px; max-height: 320px; overflow: auto;
  white-space: pre-wrap; color: var(--paper);
}
[data-theme="dark"] pre.result { background: #050504; }
pre.result.fail { border-color: var(--coral); border-left-width: 6px; }
.sys { font-size: 12px; color: var(--ink-3); margin: 6px 0 10px 45px; font-family: var(--mono); }
.sys.error { color: var(--coral); font-weight: 700; }

.question {
  border: var(--bd-fat) solid var(--line); background: var(--yellow);
  border-radius: var(--radius); padding: 16px; margin: 8px 0 16px 45px;
  max-width: 640px; box-shadow: var(--pop); color: var(--ink);
  animation: rise .22s ease;
}
.q-title {
  font-size: 10.5px; color: var(--ink); font-family: var(--mono);
  font-weight: 700; letter-spacing: .12em; margin-bottom: 12px;
  text-transform: uppercase;
}
.q-block { margin-bottom: 15px; }
.q-block:last-of-type { margin-bottom: 11px; }
.q-text { font-size: 14.5px; margin-bottom: 9px; font-weight: 700; }
.opt {
  display: block; width: 100%; text-align: left;
  border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-sm); padding: 10px 13px; margin-bottom: 7px;
  cursor: pointer; font-size: 13.5px; font-weight: 600; transition: .12s; color: var(--ink);
}
.opt:hover { background: var(--paper-3); transform: translate(-2px, -2px); box-shadow: 3px 3px 0 var(--line); }
.opt.sel { background: var(--blue); border-color: var(--line); color: var(--on-accent); box-shadow: var(--pop-sm); }

/* ---------- composer ---------- */
.composer { padding: 12px 22px 16px; }
.composer-inner {
  display: flex; gap: 8px; align-items: flex-end;
  border: var(--bd) solid var(--line); border-radius: var(--radius);
  padding: 9px 9px 9px 16px;
  background: var(--paper-2);
  box-shadow: var(--pop-sm);
  transition: box-shadow .14s, transform .14s;
}
.composer-inner:focus-within { box-shadow: var(--pop); transform: translate(-1px, -1px); }
#input {
  flex: 1; border: 0; background: none; outline: none; resize: none;
  max-height: 180px; padding: 7px 0; line-height: 1.55; font-size: 14.5px;
}
#input::placeholder { color: var(--ink-4); }
.send, .stop {
  width: 40px; height: 40px; border-radius: 11px; cursor: pointer;
  border: var(--bd) solid var(--line);
  display: grid; place-items: center; font-size: 17px; flex: 0 0 40px;
  transition: transform .12s, box-shadow .12s; box-shadow: var(--pop-sm);
}
.send { background: var(--blue); color: var(--on-accent); }
.send:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--line); }
.send:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.send:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: var(--pop-sm); }
.stop { background: var(--coral); color: #fff; }
.composer-hint { font-size: 11.5px; color: var(--ink-4); padding: 7px 6px 0; min-height: 16px; font-family: var(--mono); }

/* ---------- lampiran (upload foto & berkas) ---------- */
/* Chip lampiran & tombol + harus satu keluarga visual dengan chip lain:
   tinggi seragam, kotak membulat, bukan lingkaran yang memotong gambar. */
.attach {
  width: 40px; height: 40px; border-radius: 11px; cursor: pointer; flex: 0 0 40px;
  border: var(--bd) solid var(--line); background: var(--paper-2); color: var(--ink);
  display: grid; place-items: center; font-size: 21px; font-weight: 700; line-height: 1;
  transition: transform .12s, box-shadow .12s, background .12s; box-shadow: var(--pop-sm);
  user-select: none;
}
/* Input berkas diletakkan menumpuk di bawah label, bukan display:none — iOS Safari
   dan beberapa browser mobile menolak membuka picker dari input yang disembunyikan. */
.file-input {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  opacity: 0; pointer-events: none;
}
.attach:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
/* Zona lepas berkas: seluruh composer menyala saat ada berkas diseret. */
.composer.dragover .composer-inner {
  background: var(--yellow);
  box-shadow: var(--pop);
  transform: translate(-1px, -1px);
}
.composer.dragover { position: relative; }
.composer.dragover::after {
  content: "Lepas berkas di sini";
  position: absolute; inset: 6px 22px 6px; display: grid; place-items: center;
  border: var(--bd) dashed var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--yellow) 82%, transparent);
  font-size: 13px; font-weight: 800; letter-spacing: .02em;
  pointer-events: none; z-index: 5;
}
.attach:hover { background: var(--yellow); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--line); }
.attach:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.attach.busy { background: var(--paper-3); color: var(--ink-4); cursor: wait; }
/* Saat mengunggah, tombol jadi indikator berputar tanpa emoji/ikon tambahan. */
.attach.busy::after {
  content: ""; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line-soft); border-top-color: var(--ink);
  animation: spin .7s linear infinite;
}
.attach.busy { font-size: 0; }
@keyframes spin { to { transform: rotate(360deg) } }

.attach-row {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 9px 4px 0;
  /* Banyak lampiran tidak boleh mendorong composer keluar layar: baris chip
     menggulir sendiri dan dibatasi tingginya. */
  max-height: 33vh; overflow-y: auto; overscroll-behavior: contain;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 260px;
  border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-sm); padding: 3px 5px 3px 9px;
  font-size: 11.5px; font-weight: 700; box-shadow: var(--pop-sm);
  min-height: 32px;
}
.attach-chip .nm {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 150px; font-family: var(--mono); font-weight: 700;
}
.attach-chip .sz { color: var(--ink-4); font-family: var(--mono); font-size: 10.5px; }
.attach-chip.thumb { padding-left: 3px; }
.attach-chip .thumb-img {
  width: 26px; height: 26px; border-radius: 6px; object-fit: cover;
  border: var(--bd) solid var(--line); flex: 0 0 auto; display: block;
}
.attach-chip .x {
  border: 0; background: none; cursor: pointer; color: var(--ink-4);
  font-size: 15px; line-height: 1; padding: 0 3px; font-weight: 700;
}
.attach-chip .x:hover { color: var(--coral); }

/* Lampiran yang menempel pada pesan user di dalam chat. */
.msg .attach-list {
  display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px;
  align-items: flex-start;      /* tanpa ini, chip berkas melar setinggi gambar */
}
.msg .attach-list .attach-chip { background: var(--paper); }
.msg .attach-list img.attach-img {
  max-width: 240px; max-height: 200px; width: auto; border-radius: var(--radius-sm);
  border: var(--bd) solid var(--line); box-shadow: var(--pop-sm); display: block;
  cursor: zoom-in; object-fit: cover;
}
.msg .attach-list .attach-file {
  display: inline-flex; align-items: center; gap: 6px;
  border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-sm); padding: 5px 12px;
  font-size: 11.5px; font-weight: 700; color: var(--ink); text-decoration: none;
  box-shadow: var(--pop-sm); max-width: 280px;
}
.msg .attach-list .attach-file span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono);
}
.msg .attach-list .attach-file:hover { background: var(--yellow); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(16, 16, 14, .55);
  display: grid; place-items: center; z-index: 50; padding: 20px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  background: var(--paper-2); border: var(--bd-fat) solid var(--line);
  border-radius: var(--radius); width: min(580px, 100%);
  max-height: 86vh; overflow: auto; padding: 22px;
  box-shadow: var(--pop-lg);
  animation: pop .18s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px) } to { opacity: 1; transform: none } }
.modal-card.wide { width: min(1040px, 100%); }
.modal-card.small { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h3 {
  margin: 0; font-size: 17px; letter-spacing: -.4px; font-weight: 800;
  font-family: var(--font-display); text-transform: uppercase;
}
.modal-head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.modal-note { font-size: 12.5px; color: var(--ink-2); margin: 0 0 16px; }
.modal-foot { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.field { display: block; margin-bottom: 12px; }
.field span {
  display: block; font-size: 10.5px; color: var(--ink-2); margin-bottom: 5px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  font-family: var(--mono);
}
.field input {
  width: 100%; border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-sm); padding: 11px 14px; outline: none; transition: .12s;
}
.field input:focus { background: var(--paper); box-shadow: var(--pop-sm); transform: translate(-1px, -1px); }
.btn {
  border: var(--bd) solid var(--line); background: var(--paper-2);
  border-radius: var(--radius-sm); padding: 9px 16px; cursor: pointer;
  text-decoration: none; color: var(--ink); font-size: 13px; font-weight: 700;
  transition: transform .12s, box-shadow .12s, background .12s; box-shadow: var(--pop-sm);
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: 4px 4px 0 var(--line); background: var(--yellow); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--blue); color: var(--on-accent); }
.btn.primary:hover { background: var(--blue-deep); }
.btn.danger { color: var(--coral); border-color: var(--line); }
.btn.danger:hover { background: var(--coral); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 11.5px; }
.result { font-size: 12.5px; font-family: var(--mono); }
.result.ok { color: var(--green); font-weight: 700; }
.result.err { color: var(--coral); font-weight: 700; }

.code-split { display: flex; gap: 12px; height: 62vh; }
.file-list {
  flex: 0 0 250px; overflow: auto; border: var(--bd) solid var(--line);
  border-radius: var(--radius-sm); padding: 7px; background: var(--paper);
}
.file-item {
  font-family: var(--mono); font-size: 11.5px; padding: 6px 9px;
  border-radius: 7px; cursor: pointer; color: var(--ink-2); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; display: flex; justify-content: space-between; gap: 6px;
  border: 1.5px solid transparent;
}
.file-item:hover { background: var(--paper-3); color: var(--ink); border-color: var(--line-soft); }
.file-item.sel { background: var(--blue); color: var(--on-accent); border-color: var(--line); }
.file-item .sz { color: var(--ink-3); font-size: 10px; }
.file-item.sel .sz { color: rgba(255, 255, 255, .8); }
.code-view {
  flex: 1; margin: 0; overflow: auto; background: var(--ink);
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; font-family: var(--mono); font-size: 12px;
  white-space: pre; color: var(--paper);
}
[data-theme="dark"] .code-view { background: #050504; }
.db-preview {
  background: var(--ink); border: var(--bd) solid var(--line);
  border-radius: var(--radius-sm); padding: 16px; font-family: var(--mono);
  font-size: 11.5px; max-height: 58vh; overflow: auto; white-space: pre-wrap;
  margin: 0; color: var(--paper);
}
[data-theme="dark"] .db-preview { background: #050504; }
.muted { color: var(--ink-3); }

/* ---------- apps ---------- */
.apps-list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- modal pemakaian & biaya ---------- */
.usage-body { min-width: 0; }
.usage-load { font-size: 13px; color: var(--ink-3); margin: 6px 0 2px; }
.usage-total {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 12px;
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper-3); box-shadow: var(--pop-sm);
}
.usage-sum { font-size: 24px; font-weight: 800; letter-spacing: -.6px; }
.usage-note { font-size: 11.5px; color: var(--ink-3); font-family: var(--mono); }
.usage-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.usage-table th, .usage-table td {
  padding: 7px 8px; border-bottom: 1px solid var(--line-soft); text-align: left;
}
.usage-table th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.usage-table td.num, .usage-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.usage-table td.mono { font-family: var(--mono); font-size: 11px; }
.usage-table td.strong { font-weight: 800; }
.usage-foot {
  margin: 12px 0 0; font-size: 11.5px; line-height: 1.55; color: var(--ink-3);
  border-left: 3px solid var(--yellow); padding-left: 10px;
}
.app-row {
  border: var(--bd) solid var(--line); border-radius: var(--radius-sm);
  padding: 13px; display: flex; align-items: center; gap: 11px; flex-wrap: wrap;
  transition: transform .12s, box-shadow .12s; background: var(--paper-2);
}
.app-row:hover { transform: translate(-2px, -2px); box-shadow: var(--pop-sm); }
.app-row .meta { min-width: 0; flex: 1; }
.app-row .nm { font-weight: 700; font-size: 14px; }
.app-row .sub { font-size: 11px; color: var(--ink-3); font-family: var(--mono); }
.badge {
  font-size: 10.5px; padding: 3px 10px; border-radius: var(--radius-pill);
  border: var(--bd) solid var(--line); color: var(--ink-2); font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; font-family: var(--mono);
}
.badge.live { color: #06210f; background: var(--green); }
.badge.stopped { color: var(--ink-3); }
.badge.error { color: #fff; background: var(--coral); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); border: var(--bd) solid var(--line);
  border-radius: var(--radius-pill); padding: 10px 20px; font-size: 13px;
  font-weight: 700; z-index: 80; color: var(--paper);
  box-shadow: var(--pop-sm);
  animation: pop .18s cubic-bezier(.2, 1.3, .4, 1);
}
.toast.ok { background: var(--green); color: #06210f; }
.toast.err { background: var(--coral); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  /* Satu layar, tanpa scroll halaman: composer harus selalu terlihat. */
  body { overflow: hidden; }
  .layout {
    flex-direction: column; height: 100dvh; padding: 12px; gap: 10px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .sidebar { width: auto; flex: 0 0 auto; max-height: 40dvh; }
  .sessions { max-height: 26dvh; }
  .main { flex: 1 1 auto; min-height: 0; }
  .chat { padding: 16px 14px 8px; }

  /* Hero: margin auto tidak cocok di layar sempit, dan teks dipadatkan. */
  .welcome { margin: 4vh auto auto; }
  .welcome h1 { font-size: 22px; letter-spacing: -.8px; }
  .welcome p { font-size: 13.5px; }
  .welcome-logo { width: 60px; height: 60px; font-size: 26px; margin-bottom: 14px; }

  .msg { max-width: 100%; }

  /* Chip header: satu baris yang bisa digeser, bukan numpuk 2-3 baris. */
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-actions {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -ms-overflow-style: none; width: 100%; padding-bottom: 2px;
    /* Gradien tepi = isyarat bahwa baris chip bisa digeser. */
    mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent);
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent);
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .composer { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .chip, .status { flex: 0 0 auto; min-height: 40px; padding: 8px 13px; font-size: 12px; }
  .title-wrap { flex: 1 1 100%; }

  /* Teks panjang (URL, token) tidak boleh menembus bubble. */
  .msg .bubble, .msg .bubble * { overflow-wrap: anywhere; }
  .msg.agent .bubble .md-code { overflow-x: auto; }

  .question { margin-left: 0; }
  .tool, pre.result, .sys { margin-left: 0; }
  .code-split { flex-direction: column; height: auto; }
  .file-list { flex: 0 0 auto; max-height: 160px; }
}

/* Viewport pendek (HP landscape, jendela dipersempit): tata letak satu layar
   tidak mungkin lagi memuat sidebar + topbar + composer. Daripada memotong
   isi dengan overflow:hidden — yang membuat baris chip lampiran tidak bisa
   dijangkau — biarkan halaman menggulir dan beri tiap bagian tinggi alaminya. */
@media (max-height: 560px) {
  body { overflow: auto; }
  .layout {
    height: auto; min-height: 100dvh; flex-direction: column;
  }
  .sidebar { max-height: none; flex: 0 0 auto; width: auto; }
  .sessions { max-height: none; overflow: visible; }
  .main { flex: 0 0 auto; min-height: 0; overflow: visible; }
  .chat { flex: 1 1 auto; min-height: 90px; }
  .composer { flex: 0 0 auto; }
  .attach-row { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
