@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  color-scheme: dark;
  --bg: #0f0f14;
  --panel: #16161d;
  --panel-2: #1e1e27;
  --panel-hover: #272731;
  --text: #ececf1;
  --muted: #9a9aa8;
  --border: #2a2a35;
  --accent: #8b83ff;
  --accent-strong: #7468ff;
  --user-bubble: #23232e;
  --shadow: 0 10px 40px rgba(0,0,0,.28);
  --code-bg: #0b0b10;
  --code-head: #17171f;
  --code-border: #2a2a35;
  --code-text: #e6e6ef;
  --tok-c: #6c7086; --tok-s: #a6e3a1; --tok-n: #fab387; --tok-k: #c4a7ff; --tok-f: #8ab4f8; --tok-v: #f5c2e7;
  --danger: #f38ba8;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
body.light {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #f7f7f9;
  --panel-2: #efeff3;
  --panel-hover: #e7e7ed;
  --text: #1f1f27;
  --muted: #6f6f7d;
  --border: #e3e3ea;
  --accent: #6255e7;
  --accent-strong: #5144d6;
  --user-bubble: #f0eefe;
  --shadow: 0 10px 40px rgba(20,20,40,.1);
  --code-bg: #14141b;
  --code-head: #1d1d27;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; }
button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

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

/* ---------- Sidebar ---------- */
.sidebar { width: 268px; flex: 0 0 268px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 14px 10px 10px; z-index: 20; transition: margin-left .22s ease; }
body.sidebar-collapsed .sidebar { margin-left: -268px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 8px 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.3px; }
.brand-mark, .welcome-logo { display: grid; place-items: center; background: linear-gradient(135deg, #9a8fff, #6555eb); color: #fff; font-weight: 700; border-radius: 10px; width: 30px; height: 30px; font-size: 15px; box-shadow: 0 4px 16px #6555eb40; }
.brand-name { font-size: 16px; }
.new-chat { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: transparent; padding: 10px 12px; border-radius: 12px; text-align: left; font-size: 14px; font-weight: 500; transition: background .15s; }
.new-chat:hover { background: var(--panel-hover); }
.new-chat svg { width: 18px; height: 18px; color: var(--accent); }
.history-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 2px; margin: 8px -2px 0; padding: 0 2px; }
.history-heading { font-size: 11px; font-weight: 600; color: var(--muted); padding: 16px 10px 6px; }
.history-item { color: var(--muted); padding: 9px 10px; border-radius: 9px; display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
.history-item:hover, .history-item.active { background: var(--panel-hover); color: var(--text); }
.history-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; font-size: 13.5px; }
.delete-chat { opacity: 0; border: 0; color: var(--muted); background: transparent; padding: 0 5px; font-size: 18px; line-height: 1; border-radius: 6px; }
.delete-chat:hover { color: var(--danger); }
.history-item:hover .delete-chat, .history-item.active .delete-chat { opacity: 1; }
@media (hover: none) { .delete-chat { opacity: .7; } }
.sidebar-bottom { display: flex; align-items: center; gap: 10px; padding: 10px 6px 2px; border-top: 1px solid var(--border); margin-top: 8px; }
.user-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #36314e; color: #c8c0ff; font-weight: 700; font-size: 13px; }
.user-meta { flex: 1; display: flex; flex-direction: column; gap: 1px; font-size: 13px; min-width: 0; }
.user-meta span { color: var(--muted); font-size: 11px; }

/* ---------- Main ---------- */
.main { min-width: 0; flex: 1; display: flex; flex-direction: column; position: relative; }
.topbar { height: 56px; flex: 0 0 56px; display: flex; align-items: center; gap: 10px; padding: 0 14px; }
.model-wrap { position: relative; margin-right: auto; }
.model-wrap select { appearance: none; -webkit-appearance: none; background: transparent; border: 1px solid transparent; padding: 8px 30px 8px 12px; border-radius: 10px; max-width: min(60vw, 280px); outline: none; font-size: 14px; font-weight: 600; cursor: pointer; text-overflow: ellipsis; }
.model-wrap select:hover, .model-wrap select:focus { background: var(--panel-hover); }
.model-wrap select option { background: var(--panel); color: var(--text); }
.chevron { position: absolute; right: 9px; top: 11px; width: 16px; height: 16px; pointer-events: none; color: var(--muted); }
.icon-button { display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: 9px; width: 36px; height: 36px; flex: 0 0 36px; }
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover { background: var(--panel-hover); color: var(--text); }
.mobile-close { display: none; font-size: 22px; }

.chat-area { flex: 1; overflow-y: auto; padding: 8px 20px 16px; overscroll-behavior: contain; }
.welcome { max-width: 680px; margin: min(12vh, 110px) auto 20px; text-align: center; animation: rise .4s ease both; }
.welcome-logo { margin: 0 auto 22px; width: 54px; height: 54px; border-radius: 17px; font-size: 24px; }
.welcome h1 { font-size: clamp(24px, 4.2vw, 34px); letter-spacing: -.8px; margin: 0 0 10px; font-weight: 600; }
.welcome p { color: var(--muted); font-size: 15px; margin: 0 0 30px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 600px; margin: auto; }
.suggestion { display: flex; flex-direction: column; gap: 3px; text-align: left; border: 1px solid var(--border); background: transparent; padding: 14px 16px; border-radius: 14px; transition: background .15s, border-color .15s; }
.suggestion b { font-size: 14px; font-weight: 600; }
.suggestion span { font-size: 12.5px; color: var(--muted); }
.suggestion:hover { background: var(--panel); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }

.messages { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; padding: 6px 0 24px; }
.message { display: flex; align-items: flex-start; gap: 14px; animation: rise .2s ease both; }
.message.user { flex-direction: column; align-items: flex-end; gap: 4px; }
.message .avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #9a8fff, #6555eb); color: #fff; font-size: 13px; font-weight: 700; margin-top: 2px; }
.assistant-col { flex: 1; min-width: 0; }
.message-body { min-width: 0; font-size: 15.5px; line-height: 1.7; overflow-wrap: anywhere; }
.message.user .message-body { max-width: min(86%, 620px); background: var(--user-bubble); border-radius: 20px 20px 6px 20px; padding: 10px 16px; }
.user-text { white-space: pre-wrap; }
.message.user .message-attachments:not(:first-child) { margin-top: 10px; }

.message-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.message:hover .message-actions, .message:focus-within .message-actions, .message:last-child .message-actions { opacity: 1; }
@media (hover: none) { .message-actions { opacity: 1; } }
.msg-btn { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 4px 9px; font-size: 12.5px; }
.msg-btn:hover { color: var(--text); background: var(--panel-hover); }
.note { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.note.warn { color: #f9b872; }

/* markdown */
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p { margin: 0 0 12px; }
.message-body h1, .message-body h2, .message-body h3, .message-body h4 { line-height: 1.3; margin: 22px 0 10px; letter-spacing: -.2px; }
.message-body h1 { font-size: 1.45em; } .message-body h2 { font-size: 1.28em; } .message-body h3 { font-size: 1.12em; } .message-body h4, .message-body h5, .message-body h6 { font-size: 1em; margin: 16px 0 8px; }
.message-body ul, .message-body ol { margin: 0 0 12px; padding-left: 24px; }
.message-body li { margin: 4px 0; padding-left: 2px; }
.message-body li > ul, .message-body li > ol { margin: 4px 0; }
.message-body a { color: var(--accent); text-underline-offset: 2px; }
.message-body hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.message-body blockquote { margin: 0 0 12px; padding: 2px 0 2px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.message-body del { opacity: .7; }
.inline-code { font-family: var(--mono); background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: .86em; }
.table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--border); border-radius: 12px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table-wrap th, .table-wrap td { padding: 9px 13px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table-wrap td { white-space: normal; min-width: 90px; }
.table-wrap th { background: var(--panel); font-weight: 600; }
.table-wrap tr:last-child td { border-bottom: 0; }

/* kode */
.code-card { margin: 14px 0; border: 1px solid var(--code-border); border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; background: var(--code-head); border-bottom: 1px solid var(--code-border); font-size: 12px; color: #a9a9b8; }
.code-lang { font-family: var(--mono); }
.code-actions { display: flex; gap: 2px; }
.code-btn { border: 0; background: transparent; color: #c6c6d4; border-radius: 7px; padding: 4px 9px; font-size: 12px; }
.code-btn:hover { background: #2a2a36; color: #fff; }
.code-card pre { margin: 0; padding: 14px 16px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.6; color: var(--code-text); tab-size: 2; }
.code-card code { font-family: inherit; }
.tok-c { color: var(--tok-c); font-style: italic; } .tok-s { color: var(--tok-s); } .tok-n { color: var(--tok-n); } .tok-k { color: var(--tok-k); } .tok-f { color: var(--tok-f); } .tok-v { color: var(--tok-v); }

/* streaming */
.message-body.streaming > :last-child:not(.code-card):not(.table-wrap)::after { content: ''; display: inline-block; width: 8px; height: 8px; margin-left: 5px; border-radius: 50%; background: var(--accent); vertical-align: middle; animation: pulse 1s ease-in-out infinite; }
.typing { display: flex; gap: 5px; align-items: center; padding: 10px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }

.error-box { border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: 12px; padding: 12px 14px; }
.error-box b { color: var(--danger); font-size: 14px; }
.error-box p { margin: 4px 0 8px; font-size: 14px; color: var(--text); }
.error-box .msg-btn { border: 1px solid var(--border); }

/* lampiran */
.message-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.message-attachment, .attachment-chip { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); padding: 7px 10px; max-width: 250px; min-width: 0; }
.message.user .message-attachment { background: var(--bg); }
.message-attachment.is-image { padding: 0; border: 0; background: transparent; }
.message-attachment img { display: block; max-width: 220px; max-height: 180px; border-radius: 12px; object-fit: cover; }
.file-badge { flex: 0 0 auto; min-width: 36px; height: 36px; padding: 0 6px; display: grid; place-items: center; border-radius: 9px; background: linear-gradient(135deg, #9a8fff, #6555eb); color: #fff; font-size: 10.5px; font-weight: 700; letter-spacing: .3px; }
.file-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.file-info b { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info small { font-size: 11px; color: var(--muted); }
.attachment-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px 10px; }
.attachment-chip img { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; }
.attachment-chip button { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: 6px; }
.attachment-chip button:hover { color: var(--text); background: var(--panel-hover); }

/* composer */
.composer-area { width: min(760px, calc(100% - 32px)); margin: 0 auto; padding: 6px 0 calc(12px + env(safe-area-inset-bottom, 0px)); }
.composer { display: flex; align-items: flex-end; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 26px; padding: 8px 8px 8px 10px; box-shadow: var(--shadow); transition: border-color .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.composer textarea { flex: 1; resize: none; max-height: 200px; border: 0; outline: 0; background: transparent; padding: 8px 4px; font-size: 15.5px; line-height: 1.5; }
.composer textarea::placeholder { color: var(--muted); }
.attach-button, .send-button { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border: 0; border-radius: 50%; }
.attach-button { background: transparent; color: var(--muted); }
.attach-button:hover { color: var(--text); background: var(--panel-hover); }
.attach-button svg { width: 22px; height: 22px; }
.send-button { background: var(--text); color: var(--bg); transition: transform .12s, opacity .15s; }
.send-button svg { width: 19px; height: 19px; stroke-width: 2.2; }
.send-button:hover { transform: scale(1.05); }
.send-button.is-stop { background: var(--accent-strong); color: #fff; }
.disclaimer { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 9px; }

.scroll-down { position: absolute; left: 50%; bottom: 128px; transform: translateX(-50%); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); color: var(--text); box-shadow: var(--shadow); z-index: 5; }
.scroll-down svg { width: 18px; height: 18px; }

.drop-overlay { position: absolute; inset: 0; z-index: 30; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px); border: 2px dashed var(--accent); border-radius: 16px; margin: 8px; text-align: center; font-size: 18px; font-weight: 600; pointer-events: none; }
.drop-overlay small { display: block; margin-top: 6px; font-size: 13px; font-weight: 400; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 14px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 13px; box-shadow: var(--shadow); transition: .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-scrim { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

/* layar kosong: composer naik ke tengah seperti aplikasi AI lain */
@media (min-width: 761px) {
  .main.is-empty { justify-content: center; }
  .main.is-empty .topbar { position: absolute; top: 0; left: 0; right: 0; }
  .main.is-empty .chat-area { flex: 0 0 auto; overflow: visible; padding-bottom: 0; }
  .main.is-empty .welcome { margin-top: 0; }
  .main.is-empty .composer-area { padding-top: 10px; }
  .main.is-empty .disclaimer { display: none; }
}

@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 290px; transform: translateX(-102%); transition: transform .24s ease; margin-left: 0 !important; padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .mobile-scrim.show { display: block; position: fixed; inset: 0; background: #0009; z-index: 15; }
  .mobile-close { display: grid; }
  .topbar { padding: calc(env(safe-area-inset-top, 0px)) 8px 0; }
  .model-wrap select { max-width: 52vw; font-size: 13.5px; }
  .chat-area { padding: 6px 14px 12px; }
  .welcome { margin: 7vh auto 16px; }
  .suggestions { grid-template-columns: 1fr; gap: 8px; }
  .suggestion { padding: 12px 14px; }
  .messages { gap: 22px; }
  .message { gap: 11px; }
  .message-body { font-size: 15px; }
  .message.user .message-body { max-width: 92%; }
  .composer-area { width: calc(100% - 20px); }
  .disclaimer { font-size: 10.5px; }
  .scroll-down { bottom: 112px; }
  .code-card pre { font-size: 12.5px; padding: 12px; }
}

/* file berlabel path & tombol ZIP */
.code-lang.has-path { color: #d8d8e6; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-btn.primary { color: var(--accent); font-weight: 600; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.msg-btn.primary:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
