:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --line: #ececec;
  --text: #1a1a1a;
  --muted: #6b7280;
  --muted-strong: #5b6270;
  --red: #e0242f;
  --red-ink: #b3161f;
  --red-soft: #fdecec;
  --red-line: #f3b6ba;
  --green-ink: #157347;
  --green-soft: #e9f7ef;
  --green-line: #bfe6cd;
  --radius-control: 10px;
  --radius-card: 14px;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

button, input, textarea { font: inherit; color: inherit; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--red-ink);
  outline-offset: 2px;
}

.composer-field textarea:focus-visible { outline: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red-ink); font-size: 13px; margin: 0; }
[hidden] { display: none !important; }

.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--red); color: #fff;
  font-weight: 700; font-size: 22px;
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 9px; font-size: 15px; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 9px 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 500; }
.btn.primary:hover { background: #c81c28; }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover { color: var(--text); background: #f4f4f4; border-color: transparent; }
.btn.block { width: 100%; }
.btn.google { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: #1f1f1f; border-color: #dadce0; font-weight: 500; }
.btn.google:hover { background: #f8f9fa; }
.btn.google .google-g { width: 18px; height: 18px; flex: none; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--red-ink); border-color: #f0b4ae; }
.btn.danger:hover { background: #fff5f5; color: var(--red-ink); }
.btn.danger:disabled { opacity: 0.5; cursor: default; }
.btn.toggled { background: var(--red-soft); border-color: var(--red-line); color: var(--red-ink); }

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

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.3);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: #fff; border-radius: 20px; padding: 22px;
  display: grid; gap: 10px; box-shadow: var(--shadow);
}
.modal-card input, .modal-card textarea {
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px;
  background: #fff; width: 100%;
}
.modal-card select {
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px;
  background: #fff; width: 100%; font-size: 13px;
}
.modal-card textarea { resize: vertical; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.model-pick { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.model-pick label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.bot-icon-preview { display: grid; place-items: center; padding: 2px 0 4px; }
.bot-icon-preview .bot-avatar { width: 76px; height: 76px; }
.bot-shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.icon-choice {
  height: 62px; padding: 4px; border: 1px solid var(--line); border-radius: 14px;
  background: #fff; cursor: pointer;
}
.icon-choice .bot-mascot { width: 100%; height: 100%; object-fit: contain; }
.icon-choice:hover { background: #f7f7f7; }
.icon-choice.active { box-shadow: inset 0 0 0 2px var(--red); background: #fff; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 34px; height: 34px; border-radius: 10px;
  font-size: 18px; color: var(--muted);
}
.icon-btn:hover { background: #f1f1f1; color: var(--text); }

.only-mobile { display: none; }
.only-wide { display: none; }
.panel-toggle { display: none; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 12px;
  text-align: center;
}
.login-card .brand-mark { margin: 0 auto; }
.login-card h1 { font-size: 22px; }
.login-card input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  background: #fff;
  text-align: center;
}
.login-card input:focus { outline: 2px solid var(--red-ink); outline-offset: 0; border-color: transparent; }

/* ---------- shell ---------- */
.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 60px 288px minmax(0, 1fr) 340px;
}

/* ---------- rel ikon ala Muse (kiri, selalu terlihat di desktop) ---------- */
.rail {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  min-height: 0;
  overflow-y: auto;
}
@media (min-width: 821px) {
  .rail { display: flex; }
  .sidebar .brand { display: none; }
}
.rail-btn {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--muted-strong);
  cursor: pointer; text-decoration: none;
}
.rail-btn:hover { background: #f0f0f1; color: var(--text); }
.rail-btn.active { background: #ececee; color: var(--text); }
.rail-btn svg { display: block; }
.rail-logo { padding: 0; }
.rail-logo .brand-mark.small { width: 30px; height: 30px; border-radius: 10px; }
.rail-sep { width: 26px; border-top: 1px solid var(--line); margin: 6px 0; }
.rail-spacer { flex: 1; }

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px; }
.brand-name { font-weight: 650; font-size: 16px; }
.brand .icon-btn { margin-left: auto; }
.section-head { display: flex; align-items: center; gap: 8px; }
.section-head .section-label { padding: 0 6px; }
.section-head + .bot-list { margin-top: -4px; }
#new-bot {
  margin-left: auto; margin-right: 2px;
  width: 26px; height: 26px; padding: 0; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--muted-strong);
  font-size: 16px; line-height: 1; cursor: pointer;
}
#new-bot:hover { background: #f4f4f4; border-color: #e3e3e3; color: var(--text); }
.section-add {
  margin-left: auto; margin-right: 2px;
  width: 26px; height: 26px; padding: 0; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--muted-strong);
  font-size: 16px; line-height: 1; cursor: pointer;
}
.section-add:hover { background: #f4f4f4; border-color: #e3e3e3; color: var(--text); }
.session-list.other { flex: 0 1 auto; max-height: 26vh; }
.session-bot {
  flex: none; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; color: var(--muted);
}

.bot-list { flex: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; max-height: 190px; overflow-y: auto; }
.bot-row { min-width: 0; }
.bot-item {
  display: flex; align-items: center; gap: 7px;
  border: 0; background: transparent; cursor: pointer; text-align: left;
  padding: 3px 6px; border-radius: 9px; color: #333; width: 100%;
}
.bot-item:hover { background: #f4f4f4; }
.bot-item.active { background: var(--red-soft); }
.bot-item.active .bot-name { color: var(--red-ink); }
.bot-avatar {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  transition: transform 160ms ease;
}
.bot-avatar .bot-mascot, .bot-avatar svg { width: 100%; height: 100%; display: block; object-fit: contain; }
.bot-avatar .avatar-emoji { font-size: 19px; line-height: 1; }
.bot-item .bot-avatar { width: 22px; height: 22px; }
.bot-item .bot-avatar .avatar-emoji { font-size: 15px; }
.bot-avatar.working .bot-mascot, .bot-avatar.working svg { display: none; }
.bot-avatar.working { animation: bot-work 900ms ease-in-out infinite; }
.bot-item:hover .bot-avatar { transform: translateY(-1px) rotate(-3deg); }
@keyframes bot-work {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-4deg); }
}
@media (prefers-reduced-motion: reduce) {
  .bot-avatar.working { animation: none; }
  .bot-item:hover .bot-avatar { transform: none; }
}
.bot-name {
  font-weight: 500; font-size: 13px; min-width: 0;
  display: flex; align-items: center;
  white-space: nowrap; overflow: hidden;
}
.bot-name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.muted-line { font-size: 12px; color: var(--muted); }

.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--muted); padding: 6px 6px 0;
}
.section-label:has(+ .task-list:empty) { display: none; }

.session-list { flex: 1 1 0; min-height: 64px; overflow-y: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1px; align-content: start; }
.session-row { display: flex; align-items: center; gap: 2px; border-radius: 10px; min-width: 0; }
.session-row:hover { background: #f4f4f4; }
.session-row.active { background: var(--red-soft); }
.session-item {
  display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; text-align: left;
  padding: 5px 9px; border-radius: 10px; cursor: pointer;
  color: #333; font-size: 14px; line-height: 1.5; flex: 1; min-width: 0; overflow: hidden;
}
.session-title {
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item:hover { background: transparent; }
.session-item.active { color: var(--red-ink); font-weight: 500; }
.session-del {
  flex: none; border: 0; background: transparent; color: var(--muted-strong);
  width: 28px; height: 28px; border-radius: 8px;
  opacity: 0; cursor: pointer; padding: 0; font-size: 15px;
}
.session-row:hover .session-del, .session-row.active .session-del { opacity: 1; }
.session-del:hover { background: rgba(0, 0, 0, 0.05); }
.session-del:focus-visible { opacity: 1; }
div.empty { color: var(--muted); font-size: 13px; padding: 10px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
}
.chat-titles { min-width: 0; overflow: hidden; }
.chat-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chat-tools #bot-screen, .chat-tools #open-panel { margin-left: 0; }
.model-pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 5px 11px; font-size: 12.5px;
  color: var(--text); cursor: pointer;
}
.model-pill:hover { background: #f3f3f3; }
.model-pill .chev { color: var(--muted-strong); font-size: 12px; line-height: 1; }
.composer-model { position: relative; display: flex; justify-content: flex-end; }
.model-menu {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 20;
  width: 264px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px;
}
.model-group {
  padding: 8px 9px 3px; font-size: 11.5px; font-weight: 600;
  letter-spacing: 0; color: var(--muted); pointer-events: none;
}
.model-group:first-child { padding-top: 4px; }
.model-options { display: grid; gap: 2px; max-height: 260px; overflow-y: auto; padding-top: 2px; }
.model-option {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 0; background: transparent; border-radius: 9px; padding: 8px 9px;
  font-size: 13px; color: var(--text); cursor: pointer; text-align: left;
}
.model-option:hover { background: #f6f6f6; }
.model-option.active { background: var(--red-soft); color: var(--red-ink); }
.model-option-weight { color: var(--muted); font-size: 11.5px; }
.model-option.active .model-option-weight { color: var(--red-ink); }
.chat-header #open-panel { margin-left: auto; }
.chat-header #bot-screen { margin-left: auto; flex-shrink: 0; }
.chat-header #bot-screen + #open-panel { margin-left: 8px; }
.chat-titles h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.busy { color: var(--red-ink); }
.chat-avatar { display: inline-flex; vertical-align: -7px; margin-right: 5px; }
.chat-avatar .bot-avatar { width: 20px; height: 20px; }
.chat-avatar .avatar-emoji { font-size: 13px; }

/* Sapaan saat sesi masih kosong (gaya ChatGPT). */
.welcome {
  width: min(760px, 100%); margin: 0 auto; padding: 0 20px;
  display: grid; gap: 6px; text-align: center;
}
.welcome h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.welcome p { font-size: 14px; }
.chat.empty #messages { display: none; }
.chat.empty #welcome { margin-top: auto; margin-bottom: 18px; }
.chat.empty .composer { margin-bottom: auto; }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px 8px; display: grid; gap: 14px; align-content: start; }
.messages-inner { width: min(760px, 100%); margin: 0 auto; display: grid; gap: 14px; }

.bubble-row { display: flex; gap: 10px; align-items: flex-end; }
.bubble-row.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.02);
}
.bubble-row.user .bubble { background: var(--red); border-color: var(--red); color: #fff; border-bottom-right-radius: 6px; }
.bubble-row.bot .bubble { border-bottom-left-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; word-break: break-all; }
.bubble code { background: #f3f3f3; padding: 1px 5px; border-radius: 5px; font-size: 0.92em; }
.bubble-row.user .bubble code { background: rgba(255, 255, 255, 0.2); color: #fff; }
.bubble pre {
  background: #111; color: #eee; padding: 12px; border-radius: 12px;
  overflow-x: auto; margin: 8px 0 0; font-size: 13px;
}
.bubble pre code { background: transparent; padding: 0; color: inherit; }

/* Markdown bersama (chat + Edu + ekspor) */
.md-body,
.bubble {
  line-height: 1.5;
}
.md-body > :first-child,
.bubble > :first-child { margin-top: 0; }
.md-body > :last-child,
.bubble > :last-child { margin-bottom: 0; }
.md-body p,
.bubble p { margin: 0 0 0.65em; }
.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4,
.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4 {
  margin: 0.9em 0 0.4em;
  line-height: 1.25;
  font-weight: 650;
}
.md-body h1, .bubble h1 { font-size: 1.28em; }
.md-body h2, .bubble h2 { font-size: 1.14em; }
.md-body h3, .bubble h3 { font-size: 1.05em; }
.md-body h4, .bubble h4 { font-size: 1em; }
.md-body ul,
.md-body ol,
.bubble ul,
.bubble ol { margin: 0 0 0.7em; padding-left: 1.35em; }
.md-body li,
.bubble li { margin: 0.2em 0; }
.md-body blockquote,
.bubble blockquote {
  margin: 0 0 0.7em;
  padding: 0.2em 0 0.2em 0.85em;
  border-left: 3px solid var(--line);
  color: var(--muted-strong, #555);
}
.md-body hr,
.bubble hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0.9em 0;
}
.md-table-wrap {
  overflow-x: auto;
  margin: 0 0 0.75em;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface, #fff);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
}
.md-table th,
.md-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 7px 9px;
  vertical-align: top;
  text-align: left;
}
.md-table th:last-child,
.md-table td:last-child { border-right: none; }
.md-table tr:last-child td { border-bottom: none; }
.md-table th {
  background: #f3f3f3;
  font-weight: 600;
}
.bubble-row.user .md-table-wrap,
.bubble-row.user .md-table th {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
}
.md-placeholder { color: var(--muted); margin: 0; }
.code-block { margin: 8px 0 0; border-radius: 12px; overflow: hidden; background: #111; }
.code-block .code-head {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 12px; background: #1b1b1b; border-bottom: 1px solid #2b2b2b;
}
.code-block .code-lang {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: #9a9a9a;
}
.code-block .code-copy {
  margin-left: auto; font: inherit; font-size: 11.5px; padding: 2px 10px;
  border-radius: 999px; border: 1px solid #3a3a3a; background: #262626;
  color: #ddd; cursor: pointer;
}
.code-block .code-copy:hover { background: #333; }
.code-block pre { margin: 0; border-radius: 0; }
.reasoning { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; padding-left: 2px; border-left: 2px solid var(--line); }
.typing { color: var(--muted); font-size: 13px; font-style: italic; animation: blink 1.2s ease-in-out infinite; }
.typing::after { content: "…"; }
.estimate { display: block; margin-top: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  padding: 12px 20px 18px;
}
.composer-row {
  display: flex; gap: 8px; align-items: flex-end;
  width: min(760px, 100%); margin: 0 auto;
}
.composer-field {
  flex: 1; display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow);
  padding: 10px 12px 8px;
}
/* Baris bawah composer: semua tombol kecil ngumpul di sini, textarea di atas lega. */
.composer-toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.composer-toolbar .mode-pill, .composer-toolbar .mode-switch {
  align-self: center; margin-bottom: 0;
}
.composer-field:focus-within { border-color: transparent; outline: 2px solid var(--red-ink); outline-offset: 0; }
.composer.dragging .composer-field {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(179, 22, 31, 0.18);
}
.composer-field textarea {
  flex: none; width: 100%; min-width: 0; resize: none; max-height: 180px;
  border: 0; background: transparent; box-shadow: none;
  padding: 4px 0;
}
.composer-field textarea:focus { outline: none; }
.composer-model { position: relative; display: flex; align-items: center; flex-shrink: 0; margin-left: auto; }
.composer-field .model-pill {
  padding: 4px 9px; background: #f4f4f4; border-color: transparent; box-shadow: none;
}
.composer-field .model-pill:hover { background: #ececec; }
.mode-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  flex-shrink: 0; align-self: flex-end; margin-bottom: 3px;
  border: 0; background: #f4f4f4; border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; color: var(--muted-strong); cursor: pointer;
}
#attach { padding-inline: 12px; }
.mode-pill svg, .icon-btn svg { display: block; }
.mode-pill:hover { background: #ececec; }
.mode-pill.active { background: var(--red-soft); color: var(--red-ink); font-weight: 550; }
.mode-switch {
  display: inline-flex; align-items: center; flex-shrink: 0; align-self: flex-end;
  margin-bottom: 3px; padding: 2px; gap: 2px;
  background: #f1f1f1; border-radius: 999px;
}
.mode-opt {
  border: 0; background: transparent; border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; color: var(--muted-strong);
  cursor: pointer; transition: background .15s, color .15s;
}
.mode-opt:hover { background: #e6e6e6; }
.mode-opt.active { background: #fff; color: var(--red-ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.10); }
.mode-opt.locked { opacity: .38; cursor: not-allowed; }
.mode-opt.locked:hover { background: transparent; }
.reasoning-box {
  max-width: 92%; margin: 0 0 6px auto; padding: 0 12px;
  border-left: 2px solid var(--border, #e5e5e5); font-size: 12.5px; color: var(--muted);
}
.reasoning-box summary {
  cursor: pointer; list-style: none; padding: 4px 0;
  color: var(--muted-strong); font-style: italic; user-select: none;
}
.reasoning-box summary::-webkit-details-marker { display: none; }
.reasoning-box summary::before { content: "▸ "; transition: transform .15s; display: inline-block; }
.reasoning-box[open] summary::before { transform: rotate(90deg); }
.reasoning-box[open] summary { font-style: normal; }
.reasoning-content { white-space: pre-wrap; padding: 2px 0 8px 8px; line-height: 1.5; }
.attach-strip {
  width: min(760px, 100%); margin: 0 auto 8px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.attach-chip {
  position: relative; display: flex; align-items: center; gap: 8px;
  max-width: 240px; padding: 5px 8px; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.attach-chip.loading { opacity: 0.6; }
.attach-chip img, .attach-chip .ai {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 8px;
  object-fit: cover; background: #f4f4f4;
}
.attach-chip .ai { display: grid; place-items: center; font-size: 16px; }
.attach-chip .ai svg { display: block; }
.attach-chip .an { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip button {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; padding: 2px 4px; flex-shrink: 0;
  min-width: 32px; min-height: 32px; display: grid; place-items: center;
}
.attach-error {
  width: min(760px, 100%); margin: 0 auto 6px;
  font-size: 12.5px; color: var(--red-ink);
}
.bubble img { display: block; max-width: min(100%, 320px); max-height: 320px; width: auto; height: auto; object-fit: contain; border-radius: 12px; margin-top: 6px; }
.stop { padding: 11px 18px; border-radius: 14px; }
/* Kirim selalu ikon saja, tanpa teks — hemat lebar composer. */
.send { width: 48px; height: 48px; padding: 0; border-radius: 50%; display: grid; place-items: center; flex: none; }
.send .send-label { display: none; }
.send .send-icon { display: block; }
.stop { background: #111; border-color: #111; color: #fff; }

/* ---------- panel ---------- */
.panel {
  border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.tabs { display: flex; gap: 4px; padding: 12px 12px 0; align-items: center; }
.tab {
  border: 0; background: transparent; padding: 6px 7px; border-radius: 9px;
  color: var(--muted); cursor: pointer; font-size: 12px;
}
.tab.active { background: var(--red-soft); color: var(--red-ink); font-weight: 550; }
.tabs .icon-btn { margin-left: auto; }
.tab-body { padding: 16px 16px 24px; overflow-y: auto; }
.tab-body h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 8px 0 10px; }
.meta { display: grid; grid-template-columns: 84px 1fr; gap: 8px 10px; margin: 0 0 8px; font-size: 14px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.25); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 60px 272px minmax(0, 1fr); }
  .panel { display: none; }
  .panel.open {
    display: flex; position: fixed; top: 0; right: 0; bottom: 0;
    width: min(380px, 92vw); z-index: 20; box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top);
  }
  .panel-toggle { display: inline-grid; place-items: center; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; place-items: center; }
  .icon-btn { width: 44px; height: 44px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 44px; }
  .session-row { min-height: 36px; }
  .session-del { min-width: 32px; min-height: 32px; }
  #new-bot { width: 32px; height: 32px; font-size: 18px; }
  .tab { min-height: 44px; padding: 8px 6px; font-size: 12px; }
  .doc-del { min-width: 44px; min-height: 44px; }
  .bot-edit { width: 44px; height: 44px; }
  .profile-btn { min-height: 48px; }
  .profile-item { min-height: 44px; }
  .attach-chip button { min-width: 44px; min-height: 44px; }
  .source-chip { padding: 6px 10px; min-height: 44px; display: inline-flex; align-items: center; }
  .file-chip .fc-name, .file-chip .fc-get { min-height: 44px; display: inline-flex; align-items: center; }
  .lightbox-get { min-height: 44px; display: inline-flex; align-items: center; }
  .send, .stop { min-height: 44px; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(310px, 88vw);
    z-index: 30; transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    overflow-y: auto;
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform 0.22s ease; }
  .bot-list, .session-list { max-height: none; overflow: visible; grid-template-columns: minmax(0, 1fr); }
  .session-list { flex: 0 0 auto; }
  .messages { padding: 18px 14px 8px; }
  .composer { padding: 10px 14px calc(14px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 88%; }
  .welcome h1 { font-size: 21px; }
  .chat-header { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .chat-header #bot-screen { padding: 5px 8px; font-size: 12px; }
  .model-menu { width: 232px; }
}

@media (max-width: 560px) {
  .sidebar { width: min(340px, 92vw); }
  .panel.open { width: 100%; }
  .modal { align-items: start; padding: 12px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .modal-card { max-height: calc(100dvh - 24px); padding: 18px; }
  .tabs { padding: 10px 8px 0; }
  .tab-scroll { gap: 2px; }
  #close-panel { background: var(--surface); }
  .tab { padding: 8px 6px; font-size: 12.5px; }
  .chat-header #bot-screen { display: none; }
  .composer-field { padding: 8px 10px; }
  .composer-field textarea { padding: 2px 0; }
  .composer-toolbar { row-gap: 6px; }
  .mode-opt { min-height: 44px; padding-inline: 12px; }
  .mode-pill { margin-bottom: 0; align-self: center; min-height: 44px; }
  .composer-field .model-pill { min-height: 44px; }
}

.rail-icon { display: none; }

/* Sidebar desktop dilipat: panel hilang, rel ikon tetap terlihat. */
@media (min-width: 821px) {
  .only-wide { display: inline-grid; place-items: center; }
  .shell.collapsed { grid-template-columns: 60px minmax(0, 1fr); }
  .shell.collapsed .sidebar { display: none; }
}
@media (min-width: 1181px) {
  .shell.collapsed { grid-template-columns: 60px minmax(0, 1fr) 320px; }
  /* Panel kanan bisa dilipat supaya area chat tidak "motong". */
  .shell.panel-folded { grid-template-columns: 60px 288px minmax(0, 1fr) 0; }
  .shell.panel-folded.collapsed { grid-template-columns: 60px minmax(0, 1fr) 0; }
  .shell.panel-folded .panel { transform: translateX(100%); pointer-events: none; visibility: hidden; }
  .shell.panel-folded .chat { grid-column: 3; }
  .shell.panel-folded.collapsed .chat { grid-column: 2; }
  .shell.panel-folded .panel-toggle { display: inline-grid; place-items: center; }
  /* Saat panel dilipat kolom percakapan ikut melebar, bukan sekadar geser ke tengah. */
  .shell.panel-folded .messages-inner,
  .shell.panel-folded .composer-row,
  .shell.panel-folded .attach-strip,
  .shell.panel-folded .attach-error,
  .shell.panel-folded .welcome { width: min(1040px, 100%); }
}

/* Kegagalan muat data tidak boleh menyamar jadi layar masuk. */
.app-error {
  align-self: center;
  width: min(760px, calc(100% - 32px));
  margin: 12px auto 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--red-line); border-radius: 12px;
  background: #fff; box-shadow: var(--shadow);
  font-size: 13px; line-height: 1.4;
}
.app-error .btn { flex: none; margin-left: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Tab Komputer: layar Chrome milik bot (noVNC) */
.comp-screen {
  position: relative;
  border: 1px solid var(--line); border-radius: 10px;
  background: #191919; overflow: hidden; aspect-ratio: 16 / 10;
}
.comp-screen iframe { display: block; width: 100%; height: 100%; border: 0; background: #191919; }
.comp-overlay {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: #d8d8d8;
  background: rgba(25, 25, 25, 0.88); font-size: 13px; line-height: 1.5;
}
.comp-overlay[hidden] { display: none; }
.comp-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; }

/* ---------- tim bot (manager -> pegawai) ---------- */
.bot-chip {
  margin-left: 6px; padding: 1px 6px; border-radius: 8px;
  font-size: 10.5px; font-weight: 550; letter-spacing: 0.02em;
  background: var(--red-soft); color: var(--red-ink);
}
.team-list {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 10px; max-height: 180px; overflow-y: auto;
}
.team-choice {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13.5px; cursor: pointer;
}
.team-choice input[type="checkbox"] { width: 15px; height: 15px; margin-top: 2px; }

/* ---------- panel tugas ---------- */
.task-list { display: flex; flex-direction: column; gap: 6px; max-height: 160px; overflow-y: auto; }
.task-list:empty { display: none; }
.task-item {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-size: 13px; min-width: 0;
}
.task-head { display: flex; align-items: center; gap: 8px; }
.task-chip {
  padding: 1px 7px; border-radius: 8px; font-size: 10.5px; font-weight: 550;
}
.task-chip-pend { background: #f1f1f1; color: var(--muted-strong); }
.task-chip-jalan { background: #fff4d6; color: #8a6100; }
.task-chip-ok { background: #e3f4e6; color: #21692f; }
.task-chip-fail { background: #fdeaea; color: var(--red-ink); }
.task-staff { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-body { margin-top: 4px; color: var(--text, #222); }
.task-error { margin-top: 4px; color: var(--red-ink); font-size: 12px; }

/* ---------- pratinjau gambar (lightbox) ---------- */
img.msg-img { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 13, 15, 0.84);
}
.lightbox figure { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.lightbox img {
  max-width: min(94vw, 1400px); max-height: 80vh;
  border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.lightbox-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-width: 220px; max-width: min(94vw, 1400px); margin: 0 auto;
  color: #ececec; font-size: 13px;
}
.lightbox-cap {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.75;
}
.lightbox-get {
  flex-shrink: 0; color: #fff; font-weight: 600;
  text-decoration: none; padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 9px;
}
.lightbox-get:hover { background: rgba(255, 255, 255, 0.12); }
.lightbox-close {
  position: absolute; top: 18px; right: 22px;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14); color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.26); }

/* ---------- cari sesi, pin, rename, salin jawaban ---------- */
.session-search {
  width: 100%; border: 1px solid transparent; border-radius: 999px;
  background: #f1f1f2 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 12px center / 15px;
  color: var(--text);
  padding: 9px 14px 9px 34px; font-size: 13px;
}
.session-search:focus { outline: 2px solid var(--red-ink); outline-offset: 0; border-color: transparent; }
.session-search::placeholder { color: var(--muted); }
.session-pin, .session-rename {
  flex: none; border: 0; background: transparent; color: var(--muted-strong);
  width: 28px; height: 28px; border-radius: 8px;
  opacity: 0; cursor: pointer; padding: 0; font-size: 13px;
}
.session-row:hover .session-pin, .session-row.active .session-pin,
.session-row:hover .session-rename, .session-row.active .session-rename { opacity: 1; }
.session-row.pinned .session-pin { opacity: 1; }
.session-pin:hover, .session-rename:hover { background: rgba(0, 0, 0, 0.05); }
.session-pin:focus-visible, .session-rename:focus-visible { opacity: 1; }
.bubble-actions {
  display: flex; gap: 2px; padding: 3px; flex: none; align-self: flex-end;
  margin-bottom: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 120ms ease;
}
.bubble-row:hover .bubble-actions,
.bubble-row:focus-within .bubble-actions { opacity: 1; pointer-events: auto; }
.bubble-time { font-size: 12px; color: var(--muted); padding: 0 4px 0 6px; align-self: center; white-space: nowrap; }
.bubble-quote { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; margin-bottom: 6px; border-radius: 10px; background: rgba(0, 0, 0, 0.05); border-left: 3px solid var(--red); cursor: pointer; }
.bubble-quote-name { font-size: 11px; font-weight: 700; color: var(--red-ink); }
.bubble-quote-text { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble-row.user .bubble-quote { background: rgba(255, 255, 255, 0.16); border-left-color: rgba(255, 255, 255, 0.75); }
.bubble-row.user .bubble-quote-name { color: #fff; }
.bubble-row.user .bubble-quote-text { color: rgba(255, 255, 255, 0.8); }
.bubble.quote-flash { box-shadow: 0 0 0 2px var(--red); }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.reply-bar-body { flex: 1; min-width: 0; border-left: 3px solid var(--red); padding-left: 8px; }
.reply-bar-name { font-size: 12px; font-weight: 700; color: var(--red-ink); }
.reply-bar-text { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-cancel { border: 0; background: transparent; color: var(--muted); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 999px; cursor: pointer; flex: none; }
.reply-bar-cancel:hover { background: #f1f1f1; color: var(--text); }
[data-theme="dark"] .bubble-quote { background: rgba(255, 255, 255, 0.08); }
[data-theme="dark"] .reply-bar-cancel:hover { background: #2a2a2e; }
@media (hover: none) {
  .bubble-actions { opacity: 1; pointer-events: auto; }
}
.bubble-copy {
  border: 0; background: transparent; color: var(--muted);
  width: 28px; height: 28px; padding: 0; display: grid; place-items: center;
  border-radius: 999px; cursor: pointer; flex: none;
}
.bubble-copy:hover { background: #f1f1f1; color: var(--text); }
.bubble-copy svg { display: block; }
.bubble-copy.danger { color: var(--red-ink); }
.bubble-copy.armed { background: var(--red-soft); color: var(--red-ink); }
.bubble-copy.done { color: var(--green-ink); }

/* ---------- mode gelap ---------- */
[data-theme="dark"] {
  --bg: #141416;
  --surface: #1e1e21;
  --line: #2e2e33;
  --text: #ededf0;
  --muted: #9c9ca8;
  --muted-strong: #c6c6cf;
  --red-soft: #3a1e22;
  --red-line: #5c2b31;
  --red-ink: #ff6b74;
  --green-soft: #173427;
  --green-line: #245c3d;
  --green-ink: #5fce8f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .bot-item, [data-theme="dark"] .session-item { color: var(--text); }
[data-theme="dark"] .bot-item:hover, [data-theme="dark"] .session-row:hover,
[data-theme="dark"] #new-bot:hover, [data-theme="dark"] .icon-btn:hover,
[data-theme="dark"] .bubble-copy:hover { background: #2a2a2e; }
[data-theme="dark"] .rail-btn:hover, [data-theme="dark"] .rail-btn.active { background: #2a2a2e; }
[data-theme="dark"] .section-add:hover { background: #2a2a2e; }
[data-theme="dark"] .session-search { background-color: #2a2a2e; }
[data-theme="dark"] .folder-filter, [data-theme="dark"] .archive-toggle { background: #2a2a2e; }
[data-theme="dark"] .session-menu-item:hover { background: #2a2a2e; }
[data-theme="dark"] .session-menu-item.danger:hover { background: #3a1e22; }
[data-theme="dark"] .mode-pill, [data-theme="dark"] .mode-switch { background: #2a2a2e; }
[data-theme="dark"] .mode-pill:hover, [data-theme="dark"] .mode-opt:hover { background: #34343a; }
[data-theme="dark"] .mode-opt.active { background: var(--surface); }
[data-theme="dark"] .composer-field .model-pill { background: #2a2a2e; }
[data-theme="dark"] .composer-field .model-pill:hover { background: #34343a; }
[data-theme="dark"] .model-menu { background: var(--surface); }
[data-theme="dark"] .modal-card, [data-theme="dark"] .modal-card input,
[data-theme="dark"] .modal-card textarea, [data-theme="dark"] .modal-card select,
[data-theme="dark"] .login-card input { background: var(--surface); color: var(--text); }
[data-theme="dark"] .icon-choice { background: var(--surface); }
[data-theme="dark"] .icon-choice:hover { background: #2a2a2e; }
[data-theme="dark"] .btn.google { background: var(--surface); color: var(--text); border-color: #3a3a40; }
[data-theme="dark"] .btn.google:hover { background: #2a2a2e; }
[data-theme="dark"] .btn.ghost:hover { background: #2a2a2e; }
[data-theme="dark"] .btn.danger:hover { background: #3a1e22; }
[data-theme="dark"] .bubble code { background: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .attach-chip img, [data-theme="dark"] .attach-chip .ai { background: #2a2a2e; }
[data-theme="dark"] .session-pin:hover, [data-theme="dark"] .session-rename:hover,
[data-theme="dark"] .session-del:hover { background: rgba(255, 255, 255, 0.08); }

.session-rename-input {
  flex: 1; min-width: 0; padding: 5px 9px; font-size: 14px; line-height: 1.5;
  border: 1px solid var(--red-line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.session-rename-input:focus { outline: 2px solid var(--red-ink); outline-offset: 0; }

.session-filters { display: flex; gap: 6px; margin: 2px 0 4px; }
.folder-filter {
  flex: 1; min-width: 0; padding: 5px 8px; font-size: 12.5px;
  border: 1px solid transparent; border-radius: 8px;
  background: #f1f1f2; color: var(--muted-strong);
}
.archive-toggle {
  flex: none; padding: 5px 10px; font-size: 12.5px; cursor: pointer;
  border: 1px solid transparent; border-radius: 8px;
  background: #f1f1f2; color: var(--muted-strong);
}
.archive-toggle:hover { color: var(--text); }
.session-row { flex-wrap: wrap; position: relative; }
/* Tombol aksi lama tetap ada di DOM (dipakai menu popup) tapi tak terlihat. */
.session-actions { display: none; }
.session-more {
  flex: none; border: 0; background: transparent; color: var(--muted-strong);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; padding: 0;
  font-size: 13px; line-height: 1; letter-spacing: 1px;
  opacity: 0;
}
.session-row:hover .session-more, .session-row.active .session-more,
.session-row:focus-within .session-more { opacity: 1; }
.session-more:hover { background: rgba(0, 0, 0, 0.05); }
.session-more:focus-visible { opacity: 1; }
.session-pin-mark { flex: none; display: grid; place-items: center; }
.session-pin-mark svg { display: block; }
.session-menu {
  position: fixed; z-index: 60; min-width: 190px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px;
}
.session-menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: 0; background: transparent; cursor: pointer; text-align: left;
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px; color: var(--text);
}
.session-menu-item:hover { background: #f4f4f4; }
.session-menu-item.danger { color: var(--red-ink); }
.session-menu-item.danger:hover { background: var(--red-soft); }
.smi-icon { flex: none; width: 18px; display: grid; place-items: center; }
.smi-icon svg { display: block; }
.session-snippet {
  flex: 1 1 100%; order: 20; min-width: 0; display: block; text-align: left;
  border: 0; background: transparent; cursor: pointer;
  padding: 0 9px 5px 9px; font-size: 11px; line-height: 1.4;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-folder, .session-dup, .session-archive {
  flex: none; border: none; background: none; color: var(--muted);
  font-size: 13px; line-height: 1; padding: 4px 2px; cursor: pointer; opacity: 0;
}
.session-row:hover .session-folder, .session-row.active .session-folder,
.session-row:hover .session-dup, .session-row.active .session-dup,
.session-row:hover .session-archive, .session-row.active .session-archive { opacity: 1; }
.session-folder:hover, .session-dup:hover, .session-archive:hover { background: rgba(0, 0, 0, 0.05); }
.session-folder:focus-visible, .session-dup:focus-visible, .session-archive:focus-visible { opacity: 1; }
.bubble-edit {
  width: 100%; min-height: 90px; padding: 8px 10px; font: inherit; font-size: 14px;
  border: 1px solid var(--red-line); border-radius: 10px;
  background: var(--surface); color: var(--text); resize: vertical;
}
.bubble-edit-bar { display: flex; gap: 6px; margin-top: 6px; }
#mic-btn.recording { background: var(--red-soft); color: var(--red-ink); }
#mic-btn svg { display: block; }
.katex-display { margin: 8px 0; overflow-x: auto; overflow-y: hidden; }
@media print {
  #sidebar, #panel, #composer, .chat-tools, #welcome, .bubble-actions,
  #open-sidebar, #collapse-sidebar, #app-error { display: none !important; }
  body { background: #fff; }
  .chat { margin: 0; }
  .messages { overflow: visible; height: auto; }
}
