:root{--bg:#f6f6f7;--surface:#fff;--text:#18181b;--muted:#71717a;--border:#e4e4e7;--accent:#18181b;--accent-t:#fff;--user:#18181b;--user-t:#fff;--bot:#fff;--code:#f1f1f3;--shadow:0 4px 24px rgba(0,0,0,.06);--danger:#e5484d}
[data-theme=dark]{--bg:#0b0b0d;--surface:#141417;--text:#ececf0;--muted:#8a8a93;--border:#25252b;--accent:#ececf0;--accent-t:#0b0b0d;--user:#ececf0;--user-t:#0b0b0d;--bot:#141417;--code:#0b0b0d;--shadow:0 4px 24px rgba(0,0,0,.5)}
*{box-sizing:border-box;margin:0;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{background:var(--bg);color:var(--text);font:15px/1.6 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;transition:background .25s,color .25s}
a{color:inherit}
button,input,textarea{font:inherit}

/* logo: hitam di tema terang, putih di tema gelap */
.logo{height:30px;width:auto;display:block}
.logo-dark{display:none}
[data-theme=dark] .logo-dark{display:block}
[data-theme=dark] .logo-light{display:none}

.ib{width:36px;height:36px;border-radius:10px;border:1px solid var(--border);background:var(--surface);color:var(--text);cursor:pointer;display:grid;place-items:center;text-decoration:none;font-size:12px;flex-shrink:0}
.ib:hover{transform:translateY(-1px)}
.ib svg{width:18px;height:18px;stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.btn{padding:10px 16px;border-radius:10px;border:1px solid var(--border);background:var(--surface);color:var(--text);cursor:pointer}
.btn:disabled{opacity:.5;cursor:not-allowed}
.btn.p{background:var(--accent);color:var(--accent-t);border-color:var(--accent)}
input[type=text],input[type=email],input[type=password]{width:100%;padding:11px 12px;border-radius:10px;border:1px solid var(--border);background:var(--bg);color:var(--text);outline:none}
input:focus{border-color:var(--muted)}
.muted{color:var(--muted)}
.err{color:var(--danger);font-size:13px;min-height:1.2em;margin-top:6px}

/* ---------- auth pages ---------- */
.fixed-theme{position:fixed;top:14px;right:14px;z-index:5}
.auth-wrap{min-height:100dvh;display:grid;place-items:center;padding:20px}
.auth{width:min(92vw,400px);background:var(--surface);border:1px solid var(--border);border-radius:20px;padding:28px;box-shadow:var(--shadow)}
.auth .logo{margin:0 auto 14px;height:44px}
.auth h1{text-align:center;font-size:20px;margin-bottom:4px}
.auth .sub{text-align:center;color:var(--muted);font-size:13px;margin-bottom:20px}
.field{margin-bottom:12px}
.field label{display:block;font-size:12px;color:var(--muted);margin-bottom:5px}
.check{display:flex;gap:8px;align-items:flex-start;font-size:13px;color:var(--muted);margin:6px 0 14px}
.check a{color:var(--text);font-weight:600}
.ts{display:flex;justify-content:center;margin:6px 0 10px;min-height:65px}
.btn.full{width:100%;padding:12px;font-weight:600}
.switch{text-align:center;font-size:13px;margin-top:16px;color:var(--muted)}
.switch a{color:var(--text);font-weight:600}

/* ---------- legal pages ---------- */
.legal{max-width:760px;margin:0 auto;padding:28px 20px 60px;line-height:1.75}
.legal .top{display:flex;align-items:center;justify-content:space-between;margin-bottom:24px}
.legal .top a{font-size:13px;color:var(--muted)}
.legal h1{font-size:24px;letter-spacing:-.02em;margin-bottom:4px}
.legal .date{color:var(--muted);font-size:13px;margin-bottom:22px}
.legal h2{font-size:16px;margin:24px 0 8px}
.legal p{margin-bottom:10px}
.legal ul,.legal ol{padding-left:22px;margin-bottom:10px}
.legal hr{border:none;border-top:1px solid var(--border);margin:28px 0}
.legal .foot{text-align:center;color:var(--muted);font-size:13px}

/* ---------- app ---------- */
.app{height:100dvh;display:flex;overflow:hidden}
.sidebar{width:270px;background:var(--surface);border-right:1px solid var(--border);display:flex;flex-direction:column;padding:14px;gap:12px;flex-shrink:0;z-index:20;padding-top:calc(14px + env(safe-area-inset-top))}
.side-top{display:flex;align-items:center;gap:10px}
.btn-new{flex:1;padding:10px 12px;border-radius:10px;border:1px solid var(--border);background:var(--bg);color:var(--text);cursor:pointer;font-weight:600;text-align:left}
.btn-new:hover{border-color:var(--muted)}
.history-label{font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--muted);padding:4px 6px}
.history{flex:1;overflow-y:auto;display:flex;flex-direction:column;gap:2px}
.item{display:flex;align-items:center;border-radius:10px}
.item:hover,.item.active{background:var(--bg)}
.item-title{flex:1;min-width:0;text-align:left;background:none;border:none;color:var(--text);padding:9px 10px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:14px}
.item-del{background:none;border:none;color:var(--muted);cursor:pointer;font-size:18px;padding:4px 8px;opacity:0}
.item:hover .item-del,.item.active .item-del{opacity:1}
@media(hover:none){.item-del{opacity:.6}}
.empty-hist{color:var(--muted);font-size:13px;padding:8px}
.side-bottom{border-top:1px solid var(--border);padding-top:12px;display:flex;flex-direction:column;gap:10px}
.user{font-size:13px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.side-actions{display:flex;align-items:center;gap:6px}
.links{font-size:11px;color:var(--muted);display:flex;gap:10px}
.links a{color:var(--muted)}
.logout{margin-left:auto;background:none;border:none;color:var(--danger);cursor:pointer;font-size:13px;padding:6px}

.main{flex:1;display:flex;flex-direction:column;min-width:0;padding-top:env(safe-area-inset-top)}
.topbar{display:flex;align-items:center;gap:10px;padding:12px 16px;border-bottom:1px solid var(--border)}
.topbar .title{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.menu{display:none}
.overlay{display:none}
#chat{flex:1;overflow-y:auto;padding:20px 16px;display:flex;flex-direction:column;gap:14px;scroll-behavior:smooth}
.empty{margin:auto;text-align:center;color:var(--muted);animation:fade .5s}
.empty h2{color:var(--text);font-size:22px;font-weight:600;margin-bottom:6px;letter-spacing:-.02em}
.chips{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;margin-top:18px}
.chip{border:1px solid var(--border);background:var(--surface);color:var(--text);padding:8px 14px;border-radius:99px;font-size:13px;cursor:pointer;transition:.15s}
.chip:hover{border-color:var(--muted);transform:translateY(-1px)}
.msg{display:flex;flex-direction:column;max-width:88%;animation:rise .25s ease}
.msg.user{align-self:flex-end;align-items:flex-end}
.bub{padding:10px 14px;border-radius:16px;word-wrap:break-word;overflow-wrap:anywhere;box-shadow:var(--shadow)}
.user .bub{background:var(--user);color:var(--user-t);border-bottom-right-radius:5px}
.bot .bub{background:var(--bot);border:1px solid var(--border);border-bottom-left-radius:5px}
.err .bub{border-color:var(--danger);color:var(--danger)}
.bub pre{background:var(--code);border:1px solid var(--border);border-radius:10px;padding:10px 12px;overflow-x:auto;margin:8px 0;font-size:13px}
.bub code{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:.9em}
.bub :not(pre)>code{background:var(--code);padding:1px 6px;border-radius:5px}
.acts{display:flex;gap:6px;margin-top:4px;opacity:0;transition:opacity .2s}
.msg:hover .acts{opacity:1}
@media(hover:none){.acts{opacity:.7}}
.acts button{background:none;border:none;color:var(--muted);font-size:12px;cursor:pointer;padding:2px 6px;border-radius:6px}
.acts button:hover{color:var(--text)}
.dots{display:inline-flex;gap:4px;padding:4px 0}
.dots i{width:6px;height:6px;border-radius:50%;background:var(--muted);animation:b 1.2s infinite}
.dots i:nth-child(2){animation-delay:.15s}.dots i:nth-child(3){animation-delay:.3s}
.bar{padding:10px 16px calc(12px + env(safe-area-inset-bottom))}
.box{display:flex;align-items:flex-end;gap:8px;background:var(--surface);border:1px solid var(--border);border-radius:18px;padding:8px;box-shadow:var(--shadow);transition:border-color .2s}
.box:focus-within{border-color:var(--muted)}
textarea{flex:1;border:none;outline:none;background:none;color:var(--text);resize:none;max-height:160px;padding:6px 8px}
textarea::placeholder{color:var(--muted)}
#send{width:38px;height:38px;border-radius:12px;border:none;background:var(--accent);color:var(--accent-t);cursor:pointer;display:grid;place-items:center;transition:transform .15s,opacity .2s;flex-shrink:0}
#send:active{transform:scale(.92)}
#send:disabled{opacity:.35;cursor:not-allowed}
#send svg{width:18px;height:18px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.hint{text-align:center;font-size:11px;color:var(--muted);margin-top:6px}

@keyframes rise{from{opacity:0;transform:translateY(8px)}}
@keyframes fade{from{opacity:0}}
@keyframes b{0%,80%,100%{transform:translateY(0);opacity:.4}40%{transform:translateY(-4px);opacity:1}}

/* mobile: sidebar jadi drawer */
@media(max-width:859px){
  .sidebar{position:fixed;top:0;bottom:0;left:0;transform:translateX(-100%);transition:transform .25s ease;box-shadow:var(--shadow)}
  .sidebar.open{transform:none}
  .overlay.show{display:block;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:10}
  .menu{display:grid}
  .msg{max-width:88%}
}
@media(min-width:860px){
  #chat{padding:28px 24px}
  .msg{max-width:78%}
}
