:root {
  --bg: #f4f7f5;
  --bg-glow: rgba(31,168,120,.10);
  --surface: #ffffff;
  --surface-2: #eaf0ed;
  --border: rgba(20,40,30,.09);
  --text: #101a16;
  --muted: #6a7872;
  --accent: #14a06f;
  --accent-2: #0e7f8c;
  --grad: linear-gradient(135deg, #1bb985 0%, #0e8f9a 100%);
  --on-accent: #ffffff;
  --read: #0e9fb5;
  --err-bg: #fdeeed;
  --err-text: #b3392f;
  --shadow: 0 6px 24px rgba(16,40,30,.08);
  --glass: rgba(244,247,245,.72);
  --radius: 20px;
  --maxw: 780px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1210;
    --bg-glow: rgba(40,200,150,.10);
    --surface: #131c18;
    --surface-2: #1a2621;
    --border: rgba(255,255,255,.08);
    --text: #e9f1ed;
    --muted: #8a9a93;
    --accent: #36c595;
    --accent-2: #2aa3b3;
    --grad: linear-gradient(135deg, #2fbf8f 0%, #1f8fa0 100%);
    --on-accent: #06130e;
    --read: #5ad7ee;
    --err-bg: #2b1816;
    --err-text: #f2a79e;
    --shadow: 0 8px 28px rgba(0,0,0,.4);
    --glass: rgba(11,18,16,.72);
  }
}

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: radial-gradient(900px 420px at 50% -120px, var(--bg-glow), transparent 70%), var(--bg);
  color: var(--text);
  font: 15px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: flex; flex-direction: column; height: 100%; max-width: var(--maxw); margin: 0 auto; }

/* Header kaca */
.bar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 6px;
  padding-top: max(12px, env(safe-area-inset-top));
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; letter-spacing: -.015em; }
.brand .accent { color: var(--accent); margin-left: -4px; }
.logo-dot {
  width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--grad); color: #fff;
  box-shadow: 0 4px 12px rgba(20,160,111,.35);
}
.logo-dot svg { width: 17px; height: 17px; fill: currentColor; stroke: none; }
.bar-actions { display: flex; gap: 2px; }
.btn-icon {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 12px; color: var(--muted);
  transition: background .15s, color .15s, transform .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon:active { transform: scale(.94); }

/* Mode: pill bergeser */
.modes {
  position: relative; z-index: 2;
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin: 6px 16px 0; padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
}
.modes .pill {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 8px) / 3);
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  transition: transform .28s cubic-bezier(.3,.8,.3,1);
}
.modes[data-i="1"] .pill { transform: translateX(100%); }
.modes[data-i="2"] .pill { transform: translateX(200%); }
.modes button {
  position: relative; padding: 7px 10px;
  color: var(--muted); font-weight: 550; font-size: 14px;
  border-radius: 10px; transition: color .2s;
}
.modes button[aria-selected="true"] { color: var(--text); }

/* Area pesan */
.msgs {
  flex: 1; overflow-y: auto; scroll-behavior: smooth;
  padding: 22px 16px 12px;
  display: flex; flex-direction: column; gap: 16px;
}
.row { display: flex; animation: rise .32s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.row.user { flex-direction: column; align-items: flex-end; gap: 4px; }
.row.user .bubble {
  max-width: 86%;
  background: var(--grad); color: var(--on-accent);
  padding: 10px 16px;
  border-radius: var(--radius) var(--radius) 6px var(--radius);
  white-space: pre-wrap; word-wrap: break-word;
  box-shadow: 0 4px 14px rgba(20,160,111,.22);
}

.row.ai { gap: 10px; align-items: flex-start; }
.avatar {
  width: 30px; height: 30px; border-radius: 10px; margin-top: 2px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--border);
}
.avatar svg { width: 16px; height: 16px; }
.col { min-width: 0; flex: 1; }
.row.ai .bubble { padding: 2px 0; word-wrap: break-word; }
.row.err .bubble {
  background: var(--err-bg); color: var(--err-text);
  padding: 10px 14px; border-radius: 14px; display: inline-block;
}

/* Meta: waktu, centang, aksi */
.meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); min-height: 22px; }
.row.ai .meta { margin-top: 6px; }
.meta-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; margin-left: -4px; border-radius: 8px;
  color: var(--muted); font-size: 12px; transition: background .15s, color .15s;
}
.meta-btn svg { width: 14px; height: 14px; }
.meta-btn:hover { background: var(--surface-2); color: var(--text); }
.meta-btn.retry { margin: 8px 0 0; color: var(--err-text); }

/* Centang modern */
.ticks { display: inline-flex; color: var(--muted); }
.ticks svg { width: 19px; height: 19px; stroke-width: 2.3; overflow: visible; }
.ticks path { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .38s cubic-bezier(.3,.8,.3,1), stroke .25s; }
.ticks .t1 { stroke-dashoffset: 0; }
.ticks.sent .t2 { stroke-dashoffset: 1; }
.ticks.read { color: var(--read); }
.ticks.read .t2 { stroke-dashoffset: 0; transition-delay: .12s; }
.ticks.failed { color: var(--err-text); }
.ticks.failed path { stroke-dashoffset: 1; }
.ticks.failed::before {
  content: "!"; display: grid; place-items: center;
  width: 15px; height: 15px; margin: 2px;
  border-radius: 50%; border: 1.8px solid currentColor;
  font-size: 10px; font-weight: 800; line-height: 1;
}
.ticks.failed svg { display: none; }

/* Markdown */
.md p, .md ul, .md ol, .md h4, .md .tbl { margin-bottom: 10px; }
.md > :last-child { margin-bottom: 0; }
.md h4 { font-size: 15.5px; font-weight: 650; margin-top: 14px; letter-spacing: -.01em; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin-bottom: 4px; }
.md li::marker { color: var(--accent); }
.md a { color: var(--accent); text-underline-offset: 2px; font-weight: 600; }
.md code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.tbl { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.tbl table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.tbl th, .tbl td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { background: var(--surface-2); font-weight: 600; }

.typing { display: flex; align-items: center; gap: 5px; height: 34px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

/* Kondisi kosong */
.empty { margin: auto; text-align: center; padding: 24px 0; max-width: 480px; width: 100%; }
.empty h1 {
  font-size: 28px; font-weight: 700; letter-spacing: -.03em; margin-bottom: 8px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.empty p { color: var(--muted); margin-bottom: 24px; }
.starters { display: grid; gap: 10px; }
.starters button {
  padding: 14px 16px; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.starters button:hover { border-color: var(--accent); transform: translateY(-1px); }
.starters button:active { transform: scale(.99); }

/* Composer melayang */
.dock { padding: 8px 16px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; box-shadow: var(--shadow);
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(20,160,111,.12), var(--shadow); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent;
  padding: 8px 0; max-height: 160px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 14px; background: var(--grad); color: #fff;
  transition: transform .15s, opacity .2s;
}
.send:hover { transform: translateY(-1px); }
.send:active { transform: scale(.93); }
.send:disabled { opacity: .35; transform: none; cursor: default; }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* Riwayat */
.drawer {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0,0,0,.4); backdrop-filter: blur(3px);
  display: flex; justify-content: flex-end;
  animation: fade .2s both;
}
.drawer[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-card {
  width: min(360px, 100%); height: 100%;
  background: var(--surface); padding: 16px; overflow-y: auto;
  border-left: 1px solid var(--border);
  animation: slide .28s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-head h2 { font-size: 17px; font-weight: 650; }
.hist-row { display: flex; align-items: center; gap: 4px; border-radius: 12px; }
.hist-row:hover { background: var(--surface-2); }
.hist-open { flex: 1; min-width: 0; text-align: left; padding: 10px; display: grid; }
.hist-open span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.hist-open small { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); padding: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (min-width: 861px) { .msgs { padding-left: 24px; padding-right: 24px; } }
