/* =========================================================
   El Ai — tema "Liquid Glass"
   Latar gradien yang bergerak + panel kaca (blur, sorotan, tepi bercahaya)
   ========================================================= */

:root {
  --bg: #090913;
  --text: #f5f5fc;
  --muted: rgba(245, 245, 252, 0.62);
  --accent: #8b7bff;
  --accent-2: #d96bff;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.15);
  --glass-border: rgba(255, 255, 255, 0.2);
  --hl: rgba(255, 255, 255, 0.5);
  --sheen: rgba(255, 255, 255, 0.2);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.38);
  --code-bg: rgba(0, 0, 0, 0.3);
  --hover: rgba(255, 255, 255, 0.1);
  --user-1: rgba(122, 108, 255, 0.62);
  --user-2: rgba(200, 94, 255, 0.5);
  --blob-a: 0.55;
  --blur: 18px;
  --sidebar-w: 288px;
  --r: 28px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eceffb;
  --text: #15152a;
  --muted: rgba(21, 21, 42, 0.62);
  --accent: #5b4bff;
  --accent-2: #b43dff;
  --glass: rgba(255, 255, 255, 0.34);
  --glass-strong: rgba(255, 255, 255, 0.66);
  --glass-border: rgba(255, 255, 255, 0.85);
  --hl: rgba(255, 255, 255, 1);
  --sheen: rgba(255, 255, 255, 0.7);
  --shadow: 0 10px 40px rgba(60, 60, 130, 0.16);
  --code-bg: rgba(255, 255, 255, 0.55);
  --hover: rgba(20, 20, 60, 0.07);
  --user-1: rgba(98, 84, 255, 0.86);
  --user-2: rgba(176, 70, 255, 0.78);
  --blob-a: 0.5;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Latar bergerak ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; opacity: var(--blob-a); will-change: transform; transform: translateZ(0); }
.b1 { width: 52vmax; height: 52vmax; left: -14vmax; top: -16vmax; background: radial-gradient(circle at 30% 30%, #6a5cff, transparent 68%); animation: drift1 26s ease-in-out infinite alternate; }
.b2 { width: 46vmax; height: 46vmax; right: -14vmax; top: 6vmax; background: radial-gradient(circle at 60% 40%, #ff5fa8, transparent 68%); animation: drift2 31s ease-in-out infinite alternate; }
.b3 { width: 50vmax; height: 50vmax; left: -8vmax; bottom: -22vmax; background: radial-gradient(circle at 50% 50%, #19d0ff, transparent 68%); animation: drift3 29s ease-in-out infinite alternate; }
.b4 { width: 34vmax; height: 34vmax; right: 4vmax; bottom: -12vmax; background: radial-gradient(circle at 50% 50%, #ffb347, transparent 68%); animation: drift4 34s ease-in-out infinite alternate; opacity: calc(var(--blob-a) * 0.75); }
@keyframes drift1 { to { transform: translate(12vmax, 10vmax) scale(1.15); } }
@keyframes drift2 { to { transform: translate(-10vmax, 14vmax) scale(0.92); } }
@keyframes drift3 { to { transform: translate(14vmax, -8vmax) scale(1.1); } }
@keyframes drift4 { to { transform: translate(-12vmax, -10vmax) scale(1.2); } }

/* ---------- Kaca ---------- */
.glass {
  background:
    linear-gradient(160deg, var(--sheen) 0%, rgba(255, 255, 255, 0) 42%),
    linear-gradient(135deg, var(--glass-strong), var(--glass));
  -webkit-backdrop-filter: blur(var(--blur)) saturate(150%);
  backdrop-filter: blur(var(--blur)) saturate(150%);
  border: 1px solid var(--glass-border);
  box-shadow:
    inset 0 1px 0 var(--hl),
    inset 0 -1px 0 rgba(255, 255, 255, 0.07),
    inset 0 0 26px rgba(255, 255, 255, 0.05),
    var(--shadow);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .glass { background: var(--glass-strong); }
  :root:not([data-theme="light"]) .glass { background: rgba(40, 38, 70, 0.92); }
}
@media (prefers-reduced-transparency: reduce) {
  .glass { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--glass-strong); }
  :root:not([data-theme="light"]) .glass { background: rgba(40, 38, 70, 0.96); }
}

.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; padding: 14px; gap: 14px; }

/* ---------- Logo ---------- */
.logo {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 4px 14px rgba(120, 90, 255, 0.45);
  color: #fff; font-family: var(--serif); font-weight: 700; font-size: 15px;
}
.logo-lg { width: 50px; height: 50px; border-radius: 17px; font-size: 22px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w); flex: none; border-radius: var(--r);
  display: flex; flex-direction: column; padding: 16px 14px; z-index: 30;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: 0.2px; }

.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 18px;
  padding: 11px 16px; font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 8px 22px rgba(120, 90, 255, 0.35);
  transition: transform 0.15s, filter 0.15s;
}
.new-chat:hover { transform: translateY(-1px); filter: brightness(1.08); }
.new-chat:active { transform: scale(0.98); }

.side-label { margin: 20px 8px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; margin: 0 -6px; padding: 0 6px; }
.chat-empty { color: var(--muted); font-size: 14px; padding: 8px; }

.chat-item { display: flex; align-items: center; gap: 4px; border-radius: 14px; padding: 0 4px 0 0; border: 1px solid transparent; transition: background 0.15s; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--glass-strong); border-color: var(--glass-border); box-shadow: inset 0 1px 0 var(--hl); }
.chat-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 9px 12px; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-del { opacity: 0; background: none; border: 0; color: var(--muted); width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; }
.chat-item:hover .chat-del, .chat-item.active .chat-del, .chat-del:focus-visible { opacity: 1; }
.chat-del:hover { color: #ff6b6b; background: var(--hover); }

.side-foot { padding-top: 10px; border-top: 1px solid var(--glass-border); margin-top: 8px; }
.ghost-btn { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; border-radius: 14px; padding: 10px 12px; color: var(--muted); }
.ghost-btn:hover { background: var(--hover); color: var(--text); }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }

.icon-btn { background: none; border: 0; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { color: var(--text); }
.icon-btn.glass { color: var(--text); }
.only-mobile { display: none; }
.overlay { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 2px 10px; min-height: 44px; }
.top-title { padding: 7px 18px; border-radius: 999px; font-weight: 500; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(60vw, 520px); }
.top-spacer { flex: 1; }

.chat {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.thread { max-width: 780px; margin: 0 auto; padding: 14px 4px 32px; }
.thread:empty { display: none; }

/* ---------- Sambutan ---------- */
.welcome { max-width: 780px; margin: 0 auto; padding: 8vh 4px 24px; }
.welcome[hidden] { display: none; }
.hello { display: flex; align-items: center; gap: 18px; margin-bottom: 36px; }
.hello h1 {
  margin: 0; font-family: var(--serif); font-weight: 500; line-height: 1.2; letter-spacing: -0.01em;
  font-size: clamp(1.75rem, 4.6vw, 2.6rem);
  background: linear-gradient(120deg, var(--text) 30%, var(--accent) 75%, var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.chip {
  text-align: left; border-radius: 24px; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 3px; transition: transform 0.2s, box-shadow 0.2s;
}
.chip:hover { transform: translateY(-3px); box-shadow: inset 0 1px 0 var(--hl), 0 16px 44px rgba(110, 90, 255, 0.28); }
.chip:active { transform: scale(0.985); }
.chip strong { font-weight: 600; font-size: 15.5px; }
.chip span { color: var(--muted); font-size: 13.5px; }

/* ---------- Pesan ---------- */
/* Performa scroll: elemen yang jumlahnya banyak tidak memakai backdrop-filter */
.content.glass, .att-file.glass {
  -webkit-backdrop-filter: none; backdrop-filter: none;
  box-shadow: inset 0 1px 0 var(--hl);
}
:root:not([data-theme="light"]) .content.glass { background: linear-gradient(135deg, rgba(255,255,255,0.13), rgba(255,255,255,0.07)); }
:root[data-theme="light"] .content.glass { background: rgba(255, 255, 255, 0.62); }

.msg { display: flex; gap: 12px; margin: 20px 0; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 8px; }
.bubble {
  background: linear-gradient(135deg, var(--user-1), var(--user-2));
  color: #fff; padding: 11px 18px; border-radius: 24px 24px 8px 24px; max-width: 86%;
  white-space: pre-wrap; overflow-wrap: anywhere;
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}
.msg.assistant .logo { width: 30px; height: 30px; border-radius: 10px; font-size: 13px; margin-top: 8px; }
.msg-body { flex: 1; min-width: 0; }
.content { overflow-wrap: anywhere; padding: 14px 20px; border-radius: 8px 26px 26px 26px; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p { margin: 0 0 0.85em; }
.content h2, .content h3, .content h4, .content h5 { font-family: var(--serif); line-height: 1.3; margin: 1.3em 0 0.5em; font-weight: 600; }
.content h2 { font-size: 1.4em; } .content h3 { font-size: 1.2em; } .content h4, .content h5 { font-size: 1.05em; }
.content ul, .content ol { margin: 0 0 0.9em; padding-left: 1.5em; }
.content li { margin: 0.25em 0; }
.content a { color: var(--accent); text-underline-offset: 2px; }
.content hr { border: 0; border-top: 1px solid var(--glass-border); margin: 1.4em 0; }
.content blockquote { margin: 0 0 0.9em; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.content code { background: var(--code-bg); border: 1px solid var(--glass-border); border-radius: 7px; padding: 1px 6px; font-size: 0.88em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.code { margin: 0 0 1em; border: 1px solid var(--glass-border); border-radius: 18px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 16px; font-size: 12.5px; color: var(--muted); border-bottom: 1px solid var(--glass-border); }
.copy-code { background: none; border: 0; color: var(--muted); padding: 4px 11px; border-radius: 10px; font-size: 12.5px; }
.copy-code:hover { background: var(--hover); color: var(--text); }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code pre code { background: none; border: 0; padding: 0; font-size: 13.5px; line-height: 1.55; white-space: pre; }

.table-wrap { overflow-x: auto; margin: 0 0 1em; border-radius: 14px; }
.content table { border-collapse: collapse; font-size: 0.95em; min-width: 60%; }
.content th, .content td { border: 1px solid var(--glass-border); padding: 8px 13px; text-align: left; }
.content th { background: var(--glass-strong); font-weight: 600; }

.msg-actions { display: flex; gap: 4px; margin-top: 6px; padding-left: 8px; }
.msg.streaming .msg-actions { display: none; }
.act { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 5px 10px; border-radius: 10px; }
.act:hover { background: var(--hover); color: var(--text); }

.error-box { color: #b3261e; background: rgba(255, 90, 80, 0.14); border: 1px solid rgba(255, 90, 80, 0.4); border-radius: 16px; padding: 10px 14px; }
:root[data-theme="dark"] .error-box { color: #ffb0a8; }

.dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* ---------- Lampiran di pesan ---------- */
.atts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; max-width: 86%; }
.att-img { width: 120px; height: 120px; object-fit: cover; border-radius: 20px; border: 1px solid var(--glass-border); box-shadow: var(--shadow); }
.att-file {
  display: inline-flex; align-items: center; gap: 8px; max-width: 240px;
  padding: 8px 14px 8px 10px; border-radius: 16px; font-size: 13.5px;
}
.att-file svg { flex: none; color: var(--accent); }
.att-file span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Composer ---------- */
.composer-wrap { padding: 8px 2px calc(2px + env(safe-area-inset-bottom)); }
.composer { max-width: 780px; margin: 0 auto; border-radius: 32px; padding: 8px; transition: box-shadow 0.2s; }
.composer:focus-within { box-shadow: inset 0 1px 0 var(--hl), 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent), var(--shadow); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; line-height: 1.5; padding: 10px 4px; max-height: 200px; min-height: 28px;
}
.composer textarea::placeholder { color: var(--muted); }

.attach {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--glass-strong); border: 1px solid var(--glass-border); color: var(--text);
  box-shadow: inset 0 1px 0 var(--hl); transition: transform 0.15s, background 0.15s;
}
.attach:hover { transform: rotate(90deg) scale(1.05); background: var(--hover); }
.attach:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 6px 18px rgba(120, 90, 255, 0.45);
  transition: opacity 0.15s, transform 0.15s;
}
.send:hover:not(:disabled) { transform: scale(1.07); }
.send:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }
.send .i-stop { display: none; }
.send.busy .i-stop { display: block; }
.send.busy .i-send { display: none; }

.tray { display: flex; gap: 10px; overflow-x: auto; padding: 6px 6px 10px; }
.tray[hidden] { display: none; }
.tray-item { position: relative; flex: none; }
.tray-item img { display: block; width: 64px; height: 64px; object-fit: cover; border-radius: 16px; border: 1px solid var(--glass-border); }
.tray-file {
  display: flex; align-items: center; gap: 8px; height: 64px; max-width: 220px; padding: 0 14px 0 12px;
  border-radius: 16px; background: var(--glass-strong); border: 1px solid var(--glass-border); font-size: 13px;
}
.tray-file svg { flex: none; color: var(--accent); }
.tray-file .meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.tray-file .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.tray-file .sub { color: var(--muted); font-size: 11.5px; }
.tray-item.loading { opacity: 0.6; }
.tray-x {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; padding: 0; font-size: 14px; line-height: 1;
  background: var(--text); color: var(--bg); border: 0; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

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

.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 50;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: min(90vw, 460px); text-align: center;
}
.toast[hidden] { display: none; }

/* drag & drop */
.app.dragging .composer { box-shadow: inset 0 1px 0 var(--hl), 0 0 0 3px var(--accent), var(--shadow); }

/* ---------- Scrollbar ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(160, 160, 190, 0.35) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(160, 160, 190, 0.35); border-radius: 8px; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .app { padding: 10px; gap: 0; }
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; top: 10px; bottom: 10px; left: 10px; width: min(86vw, 320px);
    transform: translateX(calc(-100% - 20px)); transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .sidebar.open { transform: none; }
  .overlay { display: block; position: fixed; inset: 0; background: rgba(5, 5, 20, 0.45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 20; }
  .overlay.show { opacity: 1; pointer-events: auto; }
  .chips { grid-template-columns: 1fr; }
  .welcome { padding-top: 4vh; }
  .chat-del { opacity: 1; }
  .toast { bottom: 118px; }
  .bubble, .atts { max-width: 92%; }
  .blob { animation: none; }
}

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

/* ---------- Senter ---------- */
.light-btn { margin-left: auto; }
.light-btn.on { color: #ffd84d; filter: drop-shadow(0 0 8px rgba(255, 216, 77, 0.8)); }
.light-screen {
  position: fixed; inset: 0; z-index: 100; background: #fff; color: #333;
  display: grid; place-items: end center; padding: 0 0 calc(40px + env(safe-area-inset-bottom));
  font-size: 15px; cursor: pointer;
}
.light-screen[hidden] { display: none; }
.light-bar {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 60;
  display: inline-flex; align-items: center; gap: 10px; padding: 9px 10px 9px 18px; border-radius: 999px; font-size: 14px;
}
.light-bar[hidden] { display: none; }
.light-bar button { background: var(--text); color: var(--bg); border: 0; border-radius: 999px; padding: 5px 14px; font-size: 13px; font-weight: 600; }
