/* ============================================================
   AI Chat — ChatGPT-like UI
   Light/dark theme via [data-theme] on <html>.
   ============================================================ */

:root {
  --bg: #ffffff;
  --bg-secondary: #f9f9f9;
  --bg-sidebar: #f9f9f9;
  --bg-composer: #ffffff;
  --bg-hover: #ececec;
  --bg-active: #e3e3e3;
  --bg-user-msg: #f4f4f4;
  --text: #0d0d0d;
  --text-secondary: #5d5d5d;
  --text-muted: #8f8f8f;
  --border: #e5e5e5;
  --border-strong: #d9d9d9;
  --accent: #0d0d0d;
  --accent-text: #ffffff;
  --danger: #d93025;
  --code-bg: #f6f8fa;
  --code-header: #eaeef2;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --radius-lg: 24px;
  --sidebar-w: 260px;
  --input-max-h: 200px; /* tinggi maks textarea, dipangkas di mobile */
  --kb: 0px;            /* kompensasi tinggi keyboard (diisi JS via visualViewport) */
}

html[data-theme='dark'] {
  --bg: #212121;
  --bg-secondary: #171717;
  --bg-sidebar: #171717;
  --bg-composer: #303030;
  --bg-hover: #2f2f2f;
  --bg-active: #383838;
  --bg-user-msg: #303030;
  --text: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8e8e;
  --border: #ffffff1a;
  --border-strong: #ffffff2e;
  --accent: #ffffff;
  --accent-text: #0d0d0d;
  --danger: #f28b82;
  --code-bg: #0d0d0d;
  --code-header: #1c1c1c;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none; /* cegah pull-to-refresh ganggu saat mengetik */
}

button { font-family: inherit; }

.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.22s ease, transform 0.22s ease;
}

.sidebar.collapsed { margin-left: calc(var(--sidebar-w) * -1); }

.sidebar-top { padding: 10px 12px 4px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--bg-hover); }

.sidebar-search {
  position: relative;
  margin: 8px 0 4px;
}
.sidebar-search .search-ic {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.sidebar-search input:hover { background: var(--bg-hover); }
.sidebar-search input:focus { border-color: var(--border-strong); background: var(--bg); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.nav-section { margin-bottom: 12px; }
.nav-label {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 10px 4px;
  font-weight: 600;
}

.convo-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.convo-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.convo-item:hover, .convo-item.active { background: var(--bg-hover); }

.convo-title {
  flex: 1;
  padding: 9px 8px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.convo-menu-btn {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  margin-right: 4px;
}
.convo-item:hover .convo-menu-btn, .convo-item.menu-open .convo-menu-btn { opacity: 1; }
.convo-menu-btn:hover { background: var(--bg-active); }

.convo-context {
  position: fixed;
  z-index: 100;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 150px;
  padding: 4px;
  animation: pop 0.12s ease;
}
.convo-context button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.convo-context button:hover { background: var(--bg-hover); }
.convo-context button.danger { color: var(--danger); }

.empty-list {
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 10px;
}

/* Rename input */
.rename-input {
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
}

/* Sidebar bottom */
.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 8px 12px 12px;
  position: relative;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--bg-hover); }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 0;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.user-meta { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; }
.user-status { font-size: 12px; color: var(--text-muted); }

.user-menu {
  position: absolute;
  bottom: 52px;
  left: 12px;
  right: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 60;
}
.user-menu button {
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.user-menu button:hover { background: var(--bg-hover); }

.sidebar-backdrop {
  display: none;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 52px;
  position: relative;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); }

.model-btn, .reasoning-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.model-btn:hover, .reasoning-btn:hover { background: var(--bg-hover); }
.reasoning-btn {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.header-spacer { flex: 1; }

.model-dropdown {
  position: absolute;
  top: 52px;
  left: 60px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 280px;
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
  z-index: 80;
  animation: pop 0.14s ease;
}
.model-dropdown .dd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.model-dropdown .dd-item:hover { background: var(--bg-hover); }
.model-dropdown .dd-item.selected { background: var(--bg-active); }
.dd-check { color: var(--text); font-weight: 700; }

/* ---------- Welcome ---------- */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.welcome-inner { width: 100%; max-width: 720px; text-align: center; }
.welcome-title { font-size: 30px; font-weight: 500; margin: 0 0 28px; }

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.suggestion {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, transform 0.1s;
}
.suggestion:hover { background: var(--bg-hover); transform: translateY(-1px); }
.sug-ic { font-size: 16px; }

/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.messages-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px 20px 24px;
}

.msg { margin-bottom: 24px; display: flex; gap: 14px; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}
.msg.user .msg-avatar { background: var(--accent); color: var(--accent-text); }
.msg.assistant .msg-avatar { background: var(--bg-hover); border: 1px solid var(--border); }

.msg-body { flex: 1; min-width: 0; }
.msg-content { overflow-wrap: anywhere; } /* URL/teks panjang tidak merusak layout HP */

.msg.user .msg-content {
  background: var(--bg-user-msg);
  border-radius: 16px;
  padding: 10px 16px;
  display: inline-block;
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.assistant .msg-content { line-height: 1.65; }

/* Markdown content */
.md p { margin: 0 0 12px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.35; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md a { color: #10a37f; text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md blockquote {
  margin: 12px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-secondary);
}
.md code.inline {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5px 6px;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.88em;
}
.md table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
  font-size: 14px;
  display: block;
  overflow-x: auto;
}
.md th, .md td {
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  text-align: left;
}
.md th { background: var(--bg-hover); font-weight: 600; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* Code blocks */
.codeblock {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--code-bg);
}
.codeblock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--code-header);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.codeblock-lang { font-family: ui-monospace, Consolas, monospace; text-transform: lowercase; }
.codeblock-actions { display: flex; gap: 4px; }
.codeblock-actions button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.codeblock-actions button:hover { background: var(--bg-hover); }
.codeblock pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 13.2px;
  line-height: 1.55;
}
.codeblock.collapsed pre { max-height: 220px; overflow: hidden; }
.codeblock .expand-btn { font-weight: 600; }

/* Syntax highlight (simple token colors) */
.tok-key { color: #cf222e; }
.tok-str { color: #0a3069; }
.tok-com { color: #6e7781; font-style: italic; }
.tok-num { color: #0550ae; }
.tok-fn  { color: #8250df; }
html[data-theme='dark'] .tok-key { color: #ff7b72; }
html[data-theme='dark'] .tok-str { color: #a5d6ff; }
html[data-theme='dark'] .tok-com { color: #8b949e; }
html[data-theme='dark'] .tok-num { color: #79c0ff; }
html[data-theme='dark'] .tok-fn  { color: #d2a8ff; }

/* Streaming cursor */
.stream-cursor::after {
  content: '▍';
  animation: blink 1s step-start infinite;
  color: var(--text-secondary);
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Status / tool line */
.status-line {
  max-width: 820px;
  margin: 0 auto 8px;
  padding: 0 8px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-line .spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-line .tool-badge {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}
.status-line .status-elapsed {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* Error bubble */
.msg-error {
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 14px;
}
.msg-error .retry-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.msg-error .retry-btn:hover { background: var(--bg-hover); }

/* ---------- Composer ---------- */
.composer-wrap {
  padding: 0 20px 14px;
  background: linear-gradient(transparent, var(--bg) 30%);
  padding-bottom: max(14px, calc(env(safe-area-inset-bottom, 0px) + var(--kb)));
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-composer);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--text-muted);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.09);
}
.composer.dragover {
  border-color: var(--text);
  border-style: dashed;
}

.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* 16px mencegah auto-zoom iOS */
  font-family: inherit;
  line-height: 1.5;
  max-height: var(--input-max-h);
  padding: 6px 4px;
}
.composer textarea::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn:not(:disabled):hover { transform: scale(1.05); }
.send-btn.stop { background: var(--accent); }

.composer-plus { color: var(--text-muted); }
.composer-plus:hover { color: var(--text); }

.composer-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 0;
}

/* Attachment previews */
.attach-previews {
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.attach-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  max-width: 260px;
  animation: pop 0.15s ease;
}
.attach-chip .chip-ic { font-size: 16px; flex-shrink: 0; }
.attach-chip .chip-meta { display: flex; flex-direction: column; min-width: 0; }
.attach-chip .chip-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 170px; font-weight: 500;
}
.attach-chip .chip-size { font-size: 11px; color: var(--text-muted); }
.attach-chip .chip-remove {
  border: none; background: transparent; color: var(--text-secondary);
  cursor: pointer; padding: 2px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center;
}
.attach-chip .chip-remove:hover { background: var(--bg-active); color: var(--danger); }
.attach-chip.uploading .chip-name::after { content: ' ⏳'; }

/* Drop overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.drop-inner {
  border: 2px dashed var(--text-muted);
  border-radius: 18px;
  padding: 40px 60px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  box-shadow: var(--shadow);
}

/* Scroll to bottom */
.scroll-down {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  z-index: 40;
  animation: pop 0.15s ease;
}
.scroll-down:hover { background: var(--bg-hover); }

/* Image in user message */
.msg-att-img {
  max-width: 240px;
  max-height: 200px;
  border-radius: 12px;
  display: block;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.attach-note {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 8px; padding: 3px 8px; margin-bottom: 6px;
}

/* ---------- Login ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-sub { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }
.login-card input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
.login-card input:focus { border-color: var(--text-muted); }
.login-btn {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-btn:hover { opacity: 0.9; }
.login-error { color: var(--danger); font-size: 13px; margin: 0 0 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 300;
  animation: pop 0.2s ease;
  box-shadow: var(--shadow);
}

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

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
.only-collapsed { display: none; }
.app.sidebar-hidden .only-collapsed { display: inline-flex; }

/* ---------- Mobile keyboard handling (visualViewport) ----------
   Saat keyboard iOS/Android terbuka:
   - .app diberi tinggi eksplisit = visualViewport.height (JS)
   - .app.keyboard-open menonaktifkan 100dvh
   - composer menempel di atas keyboard, messages menyusut otomatis */
.app.keyboard-open { height: var(--app-h, 100dvh); }
.app.keyboard-open .composer-hint { display: none; }
.app.keyboard-open .welcome { padding-top: 12px; }
.app.keyboard-open .welcome-inner { padding: 14px 16px; box-shadow: var(--shadow); }
.app.keyboard-open .welcome-title { font-size: 17px; margin-bottom: 10px; }
.app.keyboard-open .suggestions { gap: 6px; }
.app.keyboard-open .suggestion { padding: 8px 10px; font-size: 12px; }
.app.keyboard-open .chat-header { min-height: 48px; height: 48px; }
.app.keyboard-open .messages-inner { padding-bottom: 12px; }

@media (max-width: 768px) {
  :root { --input-max-h: 96px; } /* textarea ramping di HP, layar tetap lega */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    transform: translateX(0);
    margin-left: 0 !important;
    box-shadow: var(--shadow);
  }
  .sidebar.collapsed { transform: translateX(-100%); margin-left: 0 !important; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 80;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .app:not(.sidebar-hidden) .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .app.sidebar-hidden .only-collapsed { display: inline-flex; }

  .chat-header { padding: 8px 10px; min-height: 48px; }
  .messages-inner { padding: 12px 12px 20px; }
  .composer-wrap { padding: 0 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .welcome-title { font-size: 22px; margin-bottom: 20px; }
  .suggestions { grid-template-columns: 1fr 1fr; gap: 8px; }
  .suggestion { padding: 11px 12px; font-size: 13px; }
  .model-btn { font-size: 15px; padding: 6px 8px; }
  .reasoning-btn span:last-child { display: none; }
  .model-dropdown { left: 10px; right: 10px; min-width: 0; max-height: 55dvh; }
  .convo-context { max-height: 60dvh; overflow-y: auto; }
  /* 16px di input agar iOS tidak auto-zoom saat fokus */
  .sidebar-search input, .rename-input, .login-card input { font-size: 16px; }
  .msg { gap: 10px; margin-bottom: 18px; }
  .msg-avatar { width: 26px; height: 26px; font-size: 12px; }
  .scroll-down { bottom: 120px; }
  .drop-inner { padding: 28px 36px; font-size: 15px; }

  /* Composer mobile: lebih rapat, tombol nyaman disentuh */
  .composer { padding: 6px 8px 6px 6px; border-radius: 20px; }
  .composer textarea { padding: 8px 6px; min-height: 38px; }
  .send-btn { width: 40px; height: 40px; }
  .composer-plus { width: 38px; height: 38px; }
  .attach-previews { margin-bottom: 6px; }
  .attach-chip { padding: 5px 8px; font-size: 12px; max-width: 200px; }
  .status-line { font-size: 12px; margin-bottom: 5px; }

  /* Aksi jawaban selalu terlihat & nyaman disentuh */
  .msg-actions { margin-top: 8px; gap: 4px; }
  .msg-actions button { width: 36px; height: 36px; }
  .msg-actions svg { width: 17px; height: 17px; }

  /* Bubble & kode */
  .msg.user .msg-content { border-radius: 14px 14px 4px 14px; }
  .codeblock pre { font-size: 12.5px; padding: 12px; }
  .md { font-size: 14px; }
  .md table { font-size: 12.5px; }

  /* Sidebar brand kompak */
  .sidebar-top { padding: 0 10px 6px; }
  .sidebar-search { margin-top: 54px; }
}

/* Layar pendek (keyboard terbuka tanpa visualViewport support) */
@media (max-height: 480px) {
  :root { --input-max-h: 72px; }
  .welcome-inner { padding: 12px 14px; }
  .welcome-title { font-size: 16px; margin-bottom: 8px; }
  .suggestions { display: none; }
  .composer-hint { display: none; }
  .chat-header { min-height: 44px; height: 44px; }
  .messages-inner { padding-top: 10px; }
  .msg { margin-bottom: 12px; }
}

@media (max-width: 480px) {
  .suggestions { grid-template-columns: 1fr; }
  .attach-chip { max-width: 220px; }
}

/* Desktop tanpa hover (touch screen): selalu tampil menu percakapan */
@media (hover: none) {
  .convo-menu-btn { opacity: 0.7; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
