:root {
  --bg: #f4efe8;
  --panel: #fbf8f4;
  --surface: #ffffff;
  --ink: #221d18;
  --ink-soft: #6d635a;
  --line: #e6ddd2;
  --accent: #a8814f;
  --accent-ink: #ffffff;
  --accent-soft: #efe4d4;
  --bubble-user: #2b241e;
  --bubble-user-ink: #f7f1ea;
  --bubble-ai: #ffffff;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 8px 24px rgba(40, 30, 20, .06);
  --radius: 18px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --panel: #1b1713;
    --surface: #221d18;
    --ink: #f1ebe3;
    --ink-soft: #a89c8f;
    --line: #342c24;
    --accent: #c9a36f;
    --accent-ink: #1b1713;
    --accent-soft: #2f2619;
    --bubble-user: #c9a36f;
    --bubble-user-ink: #1b1713;
    --bubble-ai: #26201a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---------- Profile ---------- */
.profile {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.video-wrap {
  position: relative;
  aspect-ratio: 9 / 13;
  flex-shrink: 0;
  overflow: hidden;
  background: #cbbfae;
}
.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  display: block;
}
.video-fade {
  position: absolute;
  inset: auto 0 0 0;
  height: 45%;
  background: linear-gradient(to top, rgba(20, 15, 10, .82), rgba(20, 15, 10, 0));
  pointer-events: none;
}
.hero-text {
  position: absolute;
  left: 24px; right: 24px; bottom: 20px;
  color: #fff;
}
.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #e8d3b4;
}
.hero-text h1 {
  margin: 0;
  font: 600 52px/1 var(--serif);
  letter-spacing: .01em;
}
.subtitle { margin: 6px 0 0; font-size: 13px; opacity: .88; }
.sound-btn {
  position: absolute;
  top: 14px; right: 14px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: rgba(20, 15, 10, .45);
  color: #fff;
  backdrop-filter: blur(6px);
}
.sound-btn.on #muteSlash { display: none; }

.profile-body { padding: 22px 24px 28px; display: grid; gap: 22px; }
.profile-body h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}
.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li {
  font-size: 12.5px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
}
.facts { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.fact { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; background: var(--surface); font-size: 13.5px; }
.fact-k { color: var(--ink-soft); }
.fact-v { font-weight: 500; text-align: right; }
.disclaimer { margin: 0; font-size: 12px; line-height: 1.5; color: var(--ink-soft); }

/* ---------- Chat ---------- */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.avatar-btn { position: relative; border: 0; background: none; padding: 0; display: none; }
.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; object-position: center 25%; display: block; }
.online-dot {
  position: absolute; right: 1px; bottom: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: #3fb37f; border: 2px solid var(--bg);
}
.chat-title { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.chat-title strong { font: 600 22px/1.1 var(--serif); }
.chat-title span { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.ghost-btn:hover { border-color: var(--accent); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 10px; max-width: 760px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }
.msg .mini-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; object-position: center 25%; flex-shrink: 0; margin-top: 2px; }
.bubble {
  padding: 11px 16px;
  border-radius: var(--radius);
  max-width: min(620px, 85%);
  overflow-wrap: anywhere;
}
.msg.ai .bubble { background: var(--bubble-ai); border: 1px solid var(--line); border-top-left-radius: 6px; box-shadow: var(--shadow); }
.msg.user .bubble { background: var(--bubble-user); color: var(--bubble-user-ink); border-top-right-radius: 6px; white-space: pre-wrap; }
.msg.error .bubble { border-color: #d9826b; background: color-mix(in srgb, #d9826b 10%, var(--bubble-ai)); }

.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .65em; }
.bubble ul, .bubble ol { margin: 0 0 .65em; padding-left: 1.3em; }
.bubble li { margin: .15em 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 15px; margin: .9em 0 .35em; font-weight: 700; }
.bubble strong { font-weight: 650; }
.bubble a { color: var(--accent); }
.bubble code { font-size: .9em; background: var(--accent-soft); padding: .1em .35em; border-radius: 5px; }
.bubble pre { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble blockquote { margin: 0 0 .65em; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--ink-soft); }
.bubble table { border-collapse: collapse; margin: .3em 0 .8em; font-size: 13.5px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.bubble th { background: var(--accent-soft); font-weight: 600; }

.stream-error { margin: .6em 0 0; font-size: 12.5px; color: var(--ink-soft); font-style: italic; }
.searching { color: var(--ink-soft); font-size: 13.5px; }
.sources {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-soft);
}
.sources a {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  text-decoration: none;
  max-width: 180px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sources a:hover { color: var(--accent); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-3px); } }

.suggestions {
  display: flex;
  gap: 8px;
  padding: 4px 24px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 808px;
  width: 100%;
  margin: 0 auto;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions:empty { display: none; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 808px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px calc(18px + env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 22px;
  padding: 12px 18px;
  font: inherit;
  font-size: 16px; /* below 16px iOS Safari zooms the page on focus */
  max-height: 180px;
  outline: none;
  box-shadow: var(--shadow);
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 46px; height: 46px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn .icon-stop { display: none; }
.send-btn.streaming .icon-send { display: none; }
.send-btn.streaming .icon-stop { display: block; }

/* ---------- Images ---------- */
.attach-btn {
  width: 46px; height: 46px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  display: grid; place-items: center;
}
.attach-btn:hover { color: var(--accent); border-color: var(--accent); }
.attachments {
  display: flex;
  gap: 8px;
  max-width: 808px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px 10px;
  overflow-x: auto;
}
.attachments:empty { display: none; }
.thumb { position: relative; flex-shrink: 0; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); display: block; }
.thumb-del {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px; line-height: 1;
}
.thumb.loading { opacity: .6; }
.file-chip {
  display: flex; align-items: center; gap: 10px;
  height: 64px; max-width: 240px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}
.file-icon {
  flex-shrink: 0;
  width: 38px; height: 44px;
  border-radius: 6px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px; font-weight: 700; letter-spacing: .04em;
}
.file-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.file-meta strong { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta small { font-size: 11.5px; color: var(--ink-soft); }
.bubble-images .file-chip { height: 56px; }
.notice {
  max-width: 760px;
  width: calc(100% - 48px);
  margin: 0 auto 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #e0a58f;
  background: color-mix(in srgb, #d9826b 12%, var(--surface));
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}
.notice[hidden] { display: none; }
.bubble-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.bubble-images img { max-width: 200px; max-height: 200px; border-radius: 12px; display: block; object-fit: cover; }
.msg.user .bubble.has-images:not(.has-text) { padding: 6px; }
.chat.dragging::after {
  content: "Lepas gambar di sini";
  position: fixed; inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  display: grid; place-items: center;
  font-weight: 600; color: var(--accent);
  z-index: 30;
  pointer-events: none;
}

.backdrop { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .avatar-btn { display: block; }
  .profile {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(400px, 88vw);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .28s ease, visibility .28s;
    visibility: hidden;
  }
  body.profile-open .profile { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .4);
    z-index: 10;
    opacity: 0; pointer-events: none;
    transition: opacity .28s ease;
  }
  body.profile-open .backdrop { opacity: 1; pointer-events: auto; }
  .chat-header { padding: 10px 16px; }
  .ghost-btn span { display: none; }
  .ghost-btn { padding: 8px; }
  .messages { padding: 18px 16px 8px; }
  .suggestions { padding: 4px 16px 10px; }
  .composer { padding: 0 16px calc(12px + env(safe-area-inset-bottom)); gap: 8px; }
  .attachments { padding: 0 16px 8px; }
  .notice { width: calc(100% - 32px); }
  .attach-btn { width: 42px; height: 42px; }
  .bubble-images img { max-width: 140px; max-height: 140px; }
  .bubble { max-width: 88%; }
}
