:root {
  --bg: #0a0c10;
  --surface: #12151c;
  --surface-2: #191d27;
  --surface-3: #1f2430;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #edeff4;
  --text-dim: #939aad;
  --text-faint: #5c6272;
  --accent: #ff5a1f;
  --accent-bright: #ff7a3d;
  --accent-soft: rgba(255, 90, 31, 0.14);
  --amber: #ffc24b;
  --success: #34d399;
  --danger: #fb7185;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-w: 288px;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.app {
  display: flex;
  position: fixed;
  left: 0;
  top: var(--app-top, 0px);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: var(--app-vh, 100dvh);
  animation: app-in 0.5s ease both;
  overflow: hidden;
  background: var(--bg);
}

@keyframes app-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .app { animation: none; }
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  box-shadow: none;
}

.icon-btn svg { width: 17px; height: 17px; }

.icon-btn:hover {
  color: var(--text);
  border-color: var(--text-faint);
  background: var(--surface-2);
  transform: none;
  box-shadow: none;
  filter: none;
}

.menu-btn { display: none; }
.sidebar-close { display: none; margin-left: auto; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.6);
  backdrop-filter: blur(2px);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  /* Transparan polos aja (bukan blur kaca) - biar nggak nutupin isi chat. */
  background: rgba(14, 17, 23, 0.4);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  padding: 22px 20px;
  padding-top: max(22px, env(safe-area-inset-top, 0px));
  padding-bottom: max(22px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(155deg, var(--accent), var(--amber));
  color: #10090a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  animation: mark-pulse 3.2s ease-in-out infinite;
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-mark-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes mark-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 90, 31, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08) inset; }
  50% { box-shadow: 0 0 0 6px rgba(255, 90, 31, 0), 0 0 0 1px rgba(255, 255, 255, 0.08) inset; }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark { animation: none; }
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-faint);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
}

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--surface-3);
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  appearance: none;
  padding-right: 34px;
}

.select-caret {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 11px;
  height: 7px;
  color: var(--text-faint);
  pointer-events: none;
}

button {
  background: var(--accent);
  background: linear-gradient(155deg, var(--accent-bright), var(--accent));
  color: #150a06;
  border: none;
  border-radius: var(--radius-pill);
  padding: 11px 16px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

button:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(255, 90, 31, 0.22); }
button:active { transform: translateY(0); }

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}

button.secondary svg { width: 15px; height: 15px; }

button.secondary:hover {
  border-color: var(--text-faint);
  background: var(--surface-2);
  color: var(--text);
  filter: none;
  box-shadow: none;
}

.status {
  font-size: 12.5px;
  min-height: 16px;
  color: var(--text-faint);
}

.status.ok { color: var(--success); }
.status.ok::before { content: "●"; margin-right: 6px; font-size: 9px; vertical-align: 1px; }
.status.err { color: var(--danger); }
.status.err::before { content: "●"; margin-right: 6px; font-size: 9px; vertical-align: 1px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
  transform: none;
  box-shadow: none;
  filter: none;
}

.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-bright);
}

#btn-delete-provider {
  padding: 9px 14px;
  font-size: 12.5px;
}

.sidebar-bottom-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-bottom-actions button { justify-content: flex-start; padding: 10px 13px; font-size: 13.5px; }
.sidebar-bottom-actions button svg { width: 15px; height: 15px; }

.sidebar-footer {
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---------- Modal pengaturan (provider & model) ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.6);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.modal-overlay.open { display: block; opacity: 1; }

.app-modal {
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 41;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 32px));
  max-height: min(600px, calc(100dvh - 64px));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.97);
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  overflow: hidden;
}

.app-modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

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

.app-modal-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.app-modal-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px;
  overflow-y: auto;
}

/* ---------- Daftar link bantuan (email/telegram/tiktok/instagram/sociabuz admin) ---------- */

.support-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.support-link-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.support-link-row:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.support-link-row .support-link-icon {
  flex: none;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--accent-bright);
}

.support-link-row .support-link-icon svg { width: 17px; height: 17px; }

.support-link-row .support-link-text {
  flex: 1;
  min-width: 0;
}

.support-link-row .support-link-label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
}

.support-link-row .support-link-value {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.support-link-row .support-link-arrow {
  flex: none;
  color: var(--text-faint);
  width: 14px;
  height: 14px;
}

.support-empty {
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  padding: 12px 0;
}

/* ---------- Modal Bahasa ---------- */
.app-modal-sm { width: min(320px, calc(100vw - 32px)); }

.lang-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.lang-option:hover { background: var(--surface-3); border-color: var(--border-strong); }
.lang-option.active { border-color: var(--accent-bright); background: var(--surface-3); }

.lang-flag { font-size: 18px; flex: none; line-height: 1; }
.lang-native { flex: 1; font-size: 13.5px; font-weight: 600; }
.lang-check { flex: none; color: var(--accent-bright); font-weight: 700; }

@media (max-width: 520px) {
  .app-modal {
    left: 16px;
    right: 16px;
    top: auto;
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    width: auto;
    transform: translateY(12px) scale(0.99);
  }
  .app-modal.open { transform: translateY(0) scale(1); }
}

/* ---------- Sesi riwayat chat ---------- */

.session-field {
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.btn-new-chat {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-dim);
  justify-content: flex-start;
  padding: 10px 13px;
}

.btn-new-chat:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface-2);
  box-shadow: none;
}

.btn-new-chat svg { width: 15px; height: 15px; }

.session-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 230px;
  overflow-y: auto;
}

.session-list:empty { display: none; }

.session-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 8px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
}

.session-item:hover { background: var(--surface-2); }

.session-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.session-item-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item.active .session-item-title { color: var(--text); }

.session-item-pin {
  background: transparent;
  border: none;
  padding: 5px;
  border-radius: 6px;
  color: var(--text-faint);
  opacity: 0;
  box-shadow: none;
  transform: none;
}

.session-item-pin svg { width: 13px; height: 13px; }

.session-item:hover .session-item-pin,
.session-item.active .session-item-pin,
.session-item.pinned .session-item-pin { opacity: 1; }

.session-item-pin:hover {
  color: var(--text);
  background: var(--surface-3);
  box-shadow: none;
  transform: none;
  filter: none;
}

.session-item.pinned .session-item-pin {
  color: var(--accent-bright);
}

.session-item.pinned .session-item-pin svg path {
  fill: var(--accent-bright);
  fill-opacity: 0.25;
}

.session-item-del {
  background: transparent;
  border: none;
  padding: 5px;
  border-radius: 6px;
  color: var(--text-faint);
  opacity: 0;
  box-shadow: none;
  transform: none;
}

.session-item-del svg { width: 13px; height: 13px; }

.session-item:hover .session-item-del,
.session-item.active .session-item-del { opacity: 1; }

.session-item-del:hover {
  color: var(--danger);
  background: rgba(251, 113, 133, 0.12);
  box-shadow: none;
  transform: none;
  filter: none;
}

/* ---------- Chat area ---------- */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(255, 90, 31, 0.06), transparent 60%),
    var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 52px;
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
  /* Transparan polos (bukan blur kaca) - biar nggak nutupin/ngeblur isi chat
     yang scroll di belakangnya, cuma nembus keliatan aja. */
  background: rgba(10, 12, 16, 0.4);
}

.chat-header-model {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.conn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-faint);
  flex: none;
}

.conn-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.conn-indicator.connected { color: var(--success); }
.conn-indicator.connected .dot {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

.conn-indicator.error { color: var(--danger); }
.conn-indicator.error .dot { background: var(--danger); }

/* Saklar "Auto" - pakai provider bawaan (mis. Groq) otomatis tanpa perlu
   API key sendiri. Hijau/ON kalau aktif, merah/OFF kalau nonaktif (provider
   diatur manual). Disembunyikan lewat .auto-switch.is-hidden kalau
   config.js -> app.defaultProvider tidak diaktifkan (tidak ada apa-apa buat
   di-toggle). */
.auto-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  cursor: pointer;
  user-select: none;
}

.auto-switch.is-hidden { display: none; }

.auto-switch-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.auto-switch-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.auto-switch-track {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 24px;
  border-radius: 999px;
  background: var(--danger);
  transition: background 0.2s ease;
  flex: none;
}

.auto-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease;
}

.auto-switch-text {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.auto-switch-text-on { left: 6px; }
.auto-switch-text-off { right: 6px; opacity: 1; }

.auto-switch-input:checked ~ .auto-switch-track { background: var(--success); }
.auto-switch-input:checked ~ .auto-switch-track .auto-switch-thumb { transform: translateX(28px); }
.auto-switch-input:checked ~ .auto-switch-track .auto-switch-text-on { opacity: 1; }
.auto-switch-input:checked ~ .auto-switch-track .auto-switch-text-off { opacity: 0; }

.auto-switch-input:focus-visible ~ .auto-switch-track {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* Di layar sempit, sembunyikan teks "Auto" - saklarnya sendiri sudah cukup
   jelas (ada teks ON/OFF di dalamnya), biar model/status tidak kepotong. */
@media (max-width: 480px) {
  .auto-switch-label { display: none; }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.msg {
  max-width: 72%;
  padding: 13px 17px;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-bottom-right-radius: 4px;
}

.msg-user-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.msg-user-files + .msg-user-text {
  margin-top: 10px;
}

.msg-user-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.msg-user-images + .msg-user-files,
.msg-user-images + .msg-user-text {
  margin-top: 10px;
}
.msg-user-image {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
}
.msg-user-image-wrap {
  position: relative;
  width: 120px;
  height: 120px;
}
.msg-user-image-wrap .msg-user-image {
  width: 100%;
  height: 100%;
}
.msg-video-badge {
  left: 6px;
  top: 6px;
  margin-top: 0;
}

.msg-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 5px 10px 5px 8px;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 200px;
}
.msg-file-chip svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent-bright);
}
.msg-file-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-user-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  max-width: 480px;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 13.5px;
}

.msg.bot.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 16px 17px;
}

.msg.bot.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing-bounce 1.1s ease-in-out infinite;
}

.msg.bot.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.msg.bot.typing .dot:nth-child(3) { animation-delay: 0.3s; }

/* Status singkat selagi jawaban masih di-generate (lihat
   renderStreamingStatus() di app.js) - TIDAK menampilkan isi jawaban sama
   sekali, cuma label seperti "Membuat index.html..." + titik berjalan.
   Hasil lengkapnya (teks + kartu file) baru muncul sekali jadi begitu
   stream-nya selesai. */
.streaming-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  color: var(--text-dim);
  font-size: 13.5px;
}

.streaming-status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.generating-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.generating-dots .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing-bounce 1.1s ease-in-out infinite;
}

.generating-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.generating-dots .dot:nth-child(3) { animation-delay: 0.3s; }

.msg.bot.has-code {
  max-width: 92%;
}

.msg-text {
  white-space: normal;
  word-wrap: break-word;
}

.msg-text > *:first-child { margin-top: 0; }
.msg-text > *:last-child { margin-bottom: 0; }

.msg-text p {
  margin: 0 0 10px;
}

.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  margin: 16px 0 8px;
}
.msg-text h1 { font-size: 19px; }
.msg-text h2 { font-size: 17px; }
.msg-text h3 { font-size: 15.5px; }
.msg-text h4 { font-size: 14.5px; }

.msg-text strong { color: var(--text); font-weight: 700; }
.msg-text em { color: var(--text); font-style: italic; }

.msg-text ul, .msg-text ol {
  margin: 4px 0 12px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.msg-text li { padding-left: 2px; }
.msg-text li::marker { color: var(--accent-bright); }

.msg-text blockquote {
  margin: 8px 0;
  padding: 6px 14px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.msg-text a {
  color: var(--accent-bright);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

.md-table th, .md-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}

.md-table th {
  background: var(--surface-3);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.md-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }

.msg-text code {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--amber);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.msg-text + .msg-text {
  margin-top: 12px;
}

.msg-text + .code-files,
.msg-text + .zip-all-btn {
  margin-top: 12px;
}

.code-files {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code-files + .zip-all-btn {
  margin-top: 10px;
}

.code-block {
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-family: "Space Grotesk", monospace;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
}

.code-block:not(.collapsed) .code-block-header {
  border-bottom: 1px solid var(--border);
}

.code-block-header:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: -2px;
}

.code-block-body {
  display: block;
}

.code-block.collapsed .code-block-body {
  display: none;
}

.code-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.code-text {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.code-file-icon {
  display: flex;
  flex-shrink: 0;
  color: var(--accent-bright);
}
.code-file-icon svg { width: 16px; height: 16px; }

.code-filename {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.code-meta {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

.code-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.code-chevron {
  display: flex;
  color: var(--text-dim);
}
.code-chevron svg {
  width: 16px;
  height: 16px;
  transition: transform 0.18s ease;
}
.code-block:not(.collapsed) .code-chevron svg {
  transform: rotate(180deg);
}

.code-actions {
  display: flex;
  gap: 6px;
}

.code-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
}

.code-btn:hover {
  border-color: var(--text-faint);
  background: var(--surface-3);
  color: var(--text);
  transform: none;
  box-shadow: none;
  filter: none;
}

.code-btn.ok {
  border-color: var(--success);
  color: var(--success);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  max-width: 100%;
}

.code-block pre code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #d6e2ff;
  white-space: pre;
}

.zip-all-btn {
  margin-top: 4px;
  width: 100%;
  justify-content: center;
}

.chat-input {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 18px;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  /* Efek "jelly"/kaca blur - panel transparan dengan gradasi + highlight +
     shadow, biar kelihatan jelas sebagai panel kaca walau background chat-nya
     gelap polos (blur doang nggak kelihatan kalau yang di belakangnya flat). */
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03) 60%, rgba(18, 21, 28, 0.6));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 5;
  flex-shrink: 0;
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .chat-input {
    -webkit-backdrop-filter: blur(22px) saturate(180%);
    backdrop-filter: blur(22px) saturate(180%);
  }
}

/* Kotak teks sekarang baris sendiri, selebar penuh (seperti input Claude) -
   supaya tidak ada ruang kosong di kanan/kiri waktu ngetik. Tombol "+" dan
   kirim pindah ke baris toolbar di bawahnya. */
.chat-input textarea {
  width: 100%;
  resize: none;
  max-height: 45vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  /* Kotak teksnya sendiri juga dibuat kaca/jelly - transparan + blur + highlight
     tipis di tepi atas, bukan kotak gelap solid. */
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 10px rgba(0, 0, 0, 0.2);
}
@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .chat-input textarea {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}
.chat-input textarea:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--accent);
}

/* Baris toolbar di bawah kotak teks: "+" di kiri, tombol kirim di kanan -
   mirip tata letak Claude, bukan berdampingan dengan kotak teks lagi. */
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.chat-input-row button,
.chat-input-row .attach-btn {
  align-self: center;
}

/* Ruang kosong di tengah toolbar (antara "+" dan tombol kirim) dipakai buat
   ganti model dengan cepat, tanpa perlu buka Pengaturan tiap mau pindah model. */
.quick-model-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.quick-model-select {
  width: 100%;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: var(--radius-pill);
  appearance: none;
  -webkit-appearance: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quick-model-select:disabled {
  opacity: 0.5;
}
.quick-model-select:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}

/* Tombol kirim sekarang ikon pesawat bulat polos (kayak app chat umumnya)
   biar hemat tempat horizontal -> kotak teks jadi lebih lega buat nulis. */
.chat-input button[type="submit"] {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-input button[type="submit"] svg { width: 18px; height: 18px; }
#btn-send.stop-mode svg { width: 14px; height: 14px; }

.chat-input button svg { width: 15px; height: 15px; }

.attach-menu-wrap {
  position: relative;
  flex-shrink: 0;
  align-self: flex-end;
}

.attach-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-lg);
  flex-shrink: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.attach-btn svg { width: 18px; height: 18px; }

/* Menu popup "+" (pilih Upload file / Upload gambar) - muncul di atas tombolnya. */
.attach-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 170px;
  padding: 6px;
  background: var(--surface-2, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 20;
}
.attach-menu[hidden] { display: none; }

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.attach-menu-item:hover,
.attach-menu-item:focus-visible {
  background: var(--surface-hover, rgba(255, 255, 255, 0.06));
  outline: none;
}
.attach-menu-item svg { width: 17px; height: 17px; flex-shrink: 0; }

#btn-attach-menu.has-files {
  border-color: var(--accent);
  color: var(--accent-bright);
}

.file-chips {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.file-chips.show { display: flex; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 5px 8px 5px 12px;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 220px;
}
.file-chip .fc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip.file-chip-img {
  padding: 4px 10px 4px 4px;
}
.file-chip .fc-thumb {
  width: 26px;
  height: 26px;
  object-fit: cover;
  border-radius: 50%;
  flex-shrink: 0;
}
.file-chip .fc-remove {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 3px;
  border-radius: 50%;
  display: inline-flex;
}
.file-chip .fc-remove:hover {
  color: var(--danger);
  background: rgba(251, 113, 133, 0.12);
}
.file-chip.err {
  border-color: var(--danger);
  color: var(--danger);
}

/* Chip lagi "memproses..." - file/gambar belum siap dibaca sistem/dikirim
   ke AI. Thumbnail preview instan (kalau gambar) dibikin agak redup +
   ditumpuk spinner, biar jelas beda dari chip yang sudah siap. */
.file-chip.pending {
  border-color: var(--border-strong);
  color: var(--text-faint);
}
.file-chip.pending .fc-thumb {
  opacity: 0.45;
  filter: grayscale(35%);
}
.fc-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-bright);
  flex-shrink: 0;
  animation: fc-spin 0.7s linear infinite;
}
/* Untuk chip gambar, spinner ditumpuk PAS di atas thumbnail (posisi &
   ukuran sama persis dengan .fc-thumb, lihat padding 4px di
   .file-chip-img) - bukan elemen terpisah di sebelahnya. */
.file-chip.file-chip-img { position: relative; }
.file-chip.file-chip-img.pending .fc-spinner {
  position: absolute;
  left: 4px;
  top: 50%;
  margin-top: -13px; /* setengah tinggi 26px - dipakai daripada transform, biar tidak bentrok sama animasi rotate di bawah */
  width: 26px;
  height: 26px;
  border-width: 2px;
}

/* Badge ikon play di atas thumbnail chip video - beda sedikit dari chip
   foto biasa, menunjukkan ini 1 frame yang diambil dari videonya. */
.fc-video-badge {
  position: absolute;
  left: 4px;
  top: 50%;
  margin-top: -13px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  pointer-events: none;
}
.fc-video-badge svg { width: 13px; height: 13px; }
@keyframes fc-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Responsive: sidebar becomes a drawer ---------- */

@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .sidebar-close { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    width: min(84vw, 320px);
    min-width: 0;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open {
    display: block;
    opacity: 1;
  }

  .chat-area { width: 100%; }

  .msg { max-width: 88%; }
  .msg.bot.has-code { max-width: 96%; }
  .chat-header { padding: 12px 14px; gap: 10px; }
  .messages { padding: 20px 14px; }
  .chat-input { padding: 12px 14px; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
  .chat-input-row { gap: 6px; }
  .attach-btn { width: 40px; height: 40px; }
  .chat-input button[type="submit"] { padding: 11px 14px; }

  .code-btn {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 30px;
  }
  .code-meta { font-size: 11px; }
  /* Di layar sempit: nama file (termasuk folder, mis. data/truths.json) tampil penuh,
     info bahasa & jumlah baris pindah ke bawahnya - bukan kepotong "data.js…". */
  .code-text { flex-direction: column; align-items: flex-start; gap: 1px; }
  .code-filename { white-space: normal; overflow-wrap: anywhere; }
  .code-block-header { padding: 8px; gap: 6px; }
  .code-header-right { gap: 6px; }
}

@media (min-width: 861px) {
  .sidebar-overlay { display: none !important; }
}
/* Blok teks polos (tanpa bahasa) - tampil biasa, bukan kartu file .txt */
.plain-pre {
  margin: 8px 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}


/* ---------- Mode Preview (HTML/CSS/JS) ---------- */
.code-btn-preview {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-color: var(--accent);
  color: var(--accent-bright);
  background: var(--accent-soft);
}
.code-btn-preview:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.code-block-header { flex-wrap: wrap; }
.code-header-right { margin-left: auto; }

body.preview-open { overflow: hidden; }

.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
}
.preview-title {
  flex: 1 1 140px;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-devices {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
}
.preview-dev-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  box-shadow: none;
}
.preview-dev-btn.active { background: var(--accent); color: #fff; }
.preview-tools { display: flex; gap: 6px; align-items: center; }
.preview-close { padding: 4px 10px; }

.preview-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: auto;
  padding: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.06) 1px, transparent 0) 0 0 / 18px 18px,
    var(--bg);
}
.preview-frame {
  border: 0;
  background: #fff;
  max-width: 100%;
  height: 100%;
  flex-shrink: 0;
}
.preview-frame.framed {
  margin: 14px 0;
  height: calc(100% - 28px);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 0 1px var(--border-strong);
}
@media (max-width: 860px) {
  .preview-devices { order: 3; width: 100%; justify-content: center; }
  .preview-dev-btn { flex: 1; }
}

.btn-update-models {
  margin-top: 8px;
  width: 100%;
}


/* ---------- Dashboard token (sidebar) ---------- */
.token-dash {
  margin-top: 4px;
  padding: 12px 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0));
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}
.td-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.td-title {
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.td-live { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-faint); }
.td-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); display: inline-block; }
.token-dash.live .td-live { color: var(--success); }
.token-dash.live .td-dot { background: var(--success); animation: td-pulse 1s ease-in-out infinite; }
@keyframes td-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(52,211,153,.55); } 50% { box-shadow: 0 0 0 5px rgba(52,211,153,0); } }
@media (prefers-reduced-motion: reduce) { .token-dash.live .td-dot { animation: none; } }

.td-main { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.td-total { font-family: var(--font-display); font-size: 26px; font-weight: 700; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.td-total small { font-family: var(--font-body); font-size: 11px; font-weight: 500; color: var(--text-faint); margin-left: 5px; }
.td-speed { font-size: 11.5px; color: var(--accent-bright); font-variant-numeric: tabular-nums; white-space: nowrap; }

.td-split { display: flex; height: 5px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.td-split i { display: block; height: 100%; width: 0; transition: width .25s ease; }
#td-bar-in { background: #6aa8ff; }
#td-bar-out { background: var(--accent); }

.td-io { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--text-dim); }
.td-io b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.td-sw { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 5px; }
.td-sw-in { background: #6aa8ff; }
.td-sw-out { background: var(--accent); }

.td-list { display: flex; flex-direction: column; gap: 5px; padding-top: 8px; border-top: 1px dashed var(--border); }
.td-list:empty { display: none; }
.td-row { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 8px; font-size: 11px; color: var(--text-dim); }
.td-row .td-n { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.td-row .td-track { height: 4px; border-radius: 99px; background: var(--surface-3); overflow: hidden; display: flex; }
.td-row .td-track i { display: block; height: 100%; }
.td-row .td-track i:first-child { background: #6aa8ff; }
.td-row .td-track i:last-child { background: var(--accent); }
.td-row .td-v { font-variant-numeric: tabular-nums; color: var(--text); text-align: right; }
.td-row .td-v small { color: var(--text-faint); font-size: 10px; margin-left: 3px; }

.td-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-faint); padding-top: 6px; border-top: 1px solid var(--border); }
.td-foot b { color: var(--text-dim); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Kartu file: nama file di tengah (layar HP) ---------- */
@media (max-width: 860px) {
  .code-block-header { flex-direction: column; align-items: stretch; gap: 8px; }
  .code-summary { flex: none; justify-content: center; }
  .code-text { flex: none; align-items: center; text-align: center; }
  .code-filename { text-align: center; }
  .code-header-right { margin: 0 auto; flex-wrap: wrap; justify-content: center; }
  .code-actions { flex-wrap: wrap; justify-content: center; }
}

/* ---------- Sidebar: dashboard token dikunci di posisi tetap ----------
   Daftar chat yang scroll sendiri; dashboard + tombol bawah selalu kelihatan. */
.sidebar { overflow: hidden; }
.session-field { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.session-list { flex: 1 1 auto; min-height: 56px; max-height: none; overflow-y: auto; overscroll-behavior: contain; }
.token-dash { flex: none; margin-top: 0; }
.sidebar-bottom-actions { flex: none; margin-top: 0; }
.sidebar-footer { flex: none; }
.sidebar .brand { flex: none; }

@media (max-width: 860px) {
  .sidebar { gap: 12px; padding-top: max(16px, env(safe-area-inset-top, 0px)); padding-bottom: max(14px, env(safe-area-inset-bottom, 0px)); }
  .sidebar-bottom-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .sidebar-bottom-actions button { padding: 9px 11px; font-size: 13px; min-width: 0; }
  .sidebar-footer { padding-top: 6px; font-size: 11px; }
  .token-dash { padding: 10px 11px 9px; gap: 7px; }
}
@media (max-width: 860px) and (max-height: 760px) {
  .td-row:nth-child(n+4) { display: none; }
}
@media (max-width: 860px) and (max-height: 620px) {
  .td-list { display: none; }
}
