/* ============================================================
   Jaspertech LLM — Stylesheet
   ============================================================ */

:root {
  --bg: #0b0f19;
  --bg-soft: #111726;
  --bg-elev: #161d2f;
  --bg-hover: #1c2438;
  --border: #232c42;
  --text: #e8ecf4;
  --text-dim: #97a3bb;
  --accent: #5b8cff;
  --accent-2: #8b5cf6;
  --user-bubble: #2a3550;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  --font-size: 15px;
  --sidebar-w: 280px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Tombol pada toolbar blok kode — disesuaikan per tema */
  --code-btn-bg: rgba(255,255,255,.09);
  --code-btn-border: rgba(255,255,255,.16);
  --code-btn-text: #cbd5e1;
  --code-btn-hover: rgba(255,255,255,.2);
  --code-btn-text-hover: #ffffff;
}

html[data-theme="light"] {
  --bg: #f6f8fc;
  --bg-soft: #ffffff;
  --bg-elev: #ffffff;
  --bg-hover: #eef2f9;
  --border: #dde4ef;
  --text: #16203a;
  --text-dim: #63708c;
  --accent: #2f6bff;
  --accent-2: #7c3aed;
  --user-bubble: #e4ecff;
}

/* Blok kode mengikuti tema agar kontras teks tetap terbaca */
html[data-theme="light"] .bubble pre { background: #f6f8fa; }
html[data-theme="light"] .bubble pre code { color: #24292f; }

/* Tombol toolbar kode pada tema terang */
html[data-theme="light"] {
  --code-btn-bg: rgba(0,0,0,.05);
  --code-btn-border: rgba(0,0,0,.14);
  --code-btn-text: #3f4a5a;
  --code-btn-hover: rgba(0,0,0,.11);
  --code-btn-text-hover: #16203a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: var(--font-size);
  line-height: 1.6;
  display: flex;
  overflow: hidden;
}

html[data-wide="1"] { --sidebar-w: 260px; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform .22s ease;
  z-index: 40;
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 8px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.3px; }
.brand-logo {
  font-size: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-text small { font-weight: 500; color: var(--accent); margin-left: 4px; font-size: .75em; }

.btn-new {
  margin: 6px 12px 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(91,140,255,.16), rgba(139,92,246,.14));
  color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: .15s;
}
.btn-new:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-new .plus { font-size: 17px; }

.side-search { padding: 0 12px 8px; }
.side-search input {
  width: 100%; padding: 8px 11px;
  border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: .88em;
}
.side-search input:focus { outline: none; border-color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text-dim); font-size: .9em;
  transition: .13s;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-hover); color: var(--text); font-weight: 600; }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-del {
  opacity: 0; border: none; background: none; cursor: pointer;
  color: var(--err); font-size: 15px; padding: 0 3px; line-height: 1;
}
.chat-item:hover .ci-del { opacity: .75; }
.chat-item .ci-del:hover { opacity: 1; }

.chat-empty { color: var(--text-dim); font-size: .85em; text-align: center; padding: 22px 12px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 9px;
  display: flex; flex-wrap: wrap; gap: 5px;
}
.foot-btn {
  flex: 1 1 auto; min-width: 0;
  padding: 8px 9px; border-radius: 9px;
  border: 1px solid transparent; background: transparent;
  color: var(--text-dim); font: inherit; font-size: .82em; cursor: pointer;
  white-space: nowrap;
}
.foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.storage-info { flex-basis: 100%; font-size: .72em; color: var(--text-dim); padding: 4px 6px 0; }

/* ---------------- Main ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.topbar-spacer { flex: 1; }

.model-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-soft);
  color: var(--text); font: inherit; font-size: .88em; font-weight: 600; cursor: pointer;
  max-width: 46vw;
}
.model-btn:hover { border-color: var(--accent); }
.model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--text-dim); font-size: .8em; }

.usage-chip {
  font-size: .76em; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 10px; white-space: nowrap;
}

.icon-btn {
  border: none; background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 6px 8px; border-radius: 8px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }


/* ---------------- Messages ---------------- */
.messages {
  flex: 1; overflow-y: auto; padding: 26px 16px 12px;
  scroll-behavior: smooth;
}
.msg {
  max-width: 900px; margin: 0 auto 22px;
  display: flex; gap: 13px;
}
html[data-wide="1"] .msg { max-width: 1200px; }

.avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px;
  background: var(--bg-elev); border: 1px solid var(--border);
}
.msg.user .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none; }
.msg.assistant .avatar { background: linear-gradient(135deg, #1f2937, #111827); }
html[data-theme="light"] .msg.assistant .avatar { background: linear-gradient(135deg, #dbeafe, #ede9fe); }

.bubble-wrap { flex: 1; min-width: 0; }
.bubble-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 5px;
  font-size: .78em; color: var(--text-dim);
}
.bubble-head .who { font-weight: 700; color: var(--text); }
.bubble-head .model-tag {
  border: 1px solid var(--border); border-radius: 20px; padding: 1px 8px;
  font-size: .93em; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.bubble { word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble {
  background: var(--user-bubble);
  padding: 11px 15px; border-radius: 4px 14px 14px 14px;
  display: inline-block; max-width: 100%;
}
.msg.assistant .bubble { padding: 1px 0; }

.bubble :first-child { margin-top: 0; }
.bubble :last-child { margin-bottom: 0; }
.bubble p { margin: .6em 0; }
.bubble ul, .bubble ol { padding-left: 1.4em; }
.bubble li { margin: .25em 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 1.1em 0 .5em; line-height: 1.3; }
.bubble h1 { font-size: 1.45em; } .bubble h2 { font-size: 1.25em; } .bubble h3 { font-size: 1.1em; }
.bubble a { color: var(--accent); }
.bubble blockquote {
  margin: .7em 0; padding: .3em 1em;
  border-left: 3px solid var(--accent); color: var(--text-dim);
  background: var(--bg-soft); border-radius: 0 8px 8px 0;
}
.bubble table { border-collapse: collapse; width: 100%; margin: .8em 0; font-size: .93em; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.bubble th { background: var(--bg-soft); font-weight: 600; }
.bubble img { max-width: 100%; border-radius: 10px; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

.bubble code {
  font-family: var(--mono); font-size: .88em;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 5px; padding: .12em .4em;
}
.bubble pre {
  background: #0d1117; border: 1px solid var(--border);
  border-radius: 10px; padding: 13px 15px; overflow-x: auto;
  margin: .8em 0; position: relative;
}
.bubble pre code { background: none; border: none; padding: 0; font-size: .86em; line-height: 1.55; }

/* ---------------- Blok kode: toolbar salin / unduh / pratinjau ---------------- */
.code-wrap {
  margin: .8em 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #0d1117;
}
html[data-theme="light"] .code-wrap { background: #f6f8fa; }

/* pre di dalam wrap tidak perlu bingkai sendiri */
.bubble .code-wrap pre {
  margin: 0; border: none; border-radius: 0;
  background: transparent;
}

.code-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 4px 8px 4px 10px;
  background: rgba(127,127,127,.1);
  border-bottom: 1px solid var(--border);
}
.code-lang {
  font-family: var(--mono);
  font-size: .68em; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.code-actions { display: flex; gap: 4px; flex: 0 0 auto; }

.code-btn {
  font-family: inherit; font-size: .74em;
  padding: 3px 9px; border-radius: 7px; cursor: pointer;
  background: var(--code-btn-bg);
  border: 1px solid var(--code-btn-border);
  color: var(--code-btn-text);
  transition: background .14s, color .14s;
  white-space: nowrap;
}
.code-btn:hover { background: var(--code-btn-hover); color: var(--code-btn-text-hover); }
.code-btn.utama { background: var(--accent); border-color: var(--accent); color: #fff; }
.code-btn.utama:hover { filter: brightness(1.12); }

/* Tombol aksi selalu tampak pada perangkat sentuh (tidak ada hover) */
@media (hover: none) {
  .code-actions { opacity: 1; }
}

/* ---------------- Modal pratinjau kode ---------------- */
.modal-card.code-modal { max-width: 1020px; height: 88vh; }
.code-modal-body {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px 16px; min-height: 0;
}
.code-preview-frame {
  flex: 1; min-height: 0;
  border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; background: #fff;
}
.code-preview-frame iframe { width: 100%; height: 100%; border: none; display: block; }

.code-console { flex: 0 0 auto; max-height: 34%; display: flex; flex-direction: column; min-height: 0; }
.code-console-head {
  font-size: .72em; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-dim); margin-bottom: 4px;
}
.code-console-out {
  flex: 1; overflow-y: auto; min-height: 64px;
  background: #0d1117; border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px;
  font-family: var(--mono); font-size: .78em; line-height: 1.55;
}
html[data-theme="light"] .code-console-out { background: #f6f8fa; }
.code-console-line { color: #cbd5e1; white-space: pre-wrap; word-break: break-word; }
html[data-theme="light"] .code-console-line { color: #3f4a5a; }
.code-console-line.error { color: #f87171; }
.code-console-line.warn { color: #fbbf24; }
.code-console-line.info { color: #7dd3fc; }
.code-console-line.selesai { color: var(--text-dim); font-style: italic; }

.msg-actions { display: flex; gap: 3px; margin-top: 7px; opacity: 0; transition: .15s; }
.msg:hover .msg-actions { opacity: 1; }
.act-btn {
  border: none; background: transparent; color: var(--text-dim);
  cursor: pointer; font-size: .76em; padding: 3px 8px; border-radius: 7px;
  font-family: inherit;
}
.act-btn:hover { background: var(--bg-hover); color: var(--text); }

.cursor-blink {
  display: inline-block; width: 8px; height: 1.05em;
  background: var(--accent); vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite; border-radius: 2px;
}
@keyframes blink { 0%,50% { opacity: 1 } 51%,100% { opacity: 0 } }

.thinking { color: var(--text-dim); font-size: .9em; font-style: italic; }
.err-box {
  border: 1px solid var(--err); border-radius: 10px;
  background: color-mix(in srgb, var(--err) 12%, transparent);
  padding: 11px 14px; color: var(--err); font-size: .9em;
}

/* ---------------- Composer ---------------- */
.composer-wrap { padding: 6px 16px 16px; background: linear-gradient(transparent, var(--bg) 30%); }
.composer {
  max-width: 900px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 7px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 18px; padding: 8px 9px 8px 11px;
  transition: border-color .15s, box-shadow .15s;
}
html[data-wide="1"] .composer { max-width: 1200px; }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.composer textarea {
  flex: 1; resize: none; border: none; background: transparent;
  color: var(--text); font: inherit; line-height: 1.5;
  max-height: 210px; padding: 6px 2px; outline: none;
}
.composer textarea::placeholder { color: var(--text-dim); }
.attach { font-size: 15px; }

.send-btn {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; cursor: pointer; display: grid; place-items: center;
  transition: .15s;
}
.send-btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.composer-hint {
  max-width: 900px; margin: 6px auto 0;
  display: flex; gap: 7px; justify-content: center; align-items: center;
  font-size: .72em; color: var(--text-dim);
}
html[data-wide="1"] .composer-hint { max-width: 1200px; }
.composer-hint .dot { opacity: .5; }
kbd {
  font-family: var(--mono); font-size: .9em;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 4px; background: var(--bg-soft);
}

.attach-preview {
  max-width: 900px; margin: 0 auto 8px;
  display: flex; gap: 8px; flex-wrap: wrap;
}
html[data-wide="1"] .attach-preview { max-width: 1200px; }
.thumb { position: relative; width: 68px; height: 68px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,.65); color: #fff; border: none;
  border-radius: 50%; width: 18px; height: 18px; cursor: pointer;
  font-size: 11px; line-height: 1; padding: 0;
}

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 18px;
}
/* Atribut hidden harus menang atas display:grid di atas */
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 660px; max-height: 88vh;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  animation: pop .16s ease;
}
.modal-card.small { max-width: 440px; }
@keyframes pop { from { transform: scale(.97); opacity: .6 } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.05em; }
.modal-body { padding: 16px 18px 20px; overflow-y: auto; }
.modal-tools { padding: 12px 18px 0; display: flex; flex-direction: column; gap: 10px; }
.modal-tools input[type="search"], .field input[type="text"], .field input[type="number"], .field textarea, #editText, .field select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: .92em;
}
.field select { cursor: pointer; }
.field select:focus { outline: none; border-color: var(--accent); }
.field textarea, #editText { resize: vertical; font-family: inherit; }
.modal-tools input:focus, .field input:focus, .field textarea:focus, #editText:focus {
  outline: none; border-color: var(--accent);
}

.model-list { overflow-y: auto; padding: 12px 18px 18px; display: flex; flex-direction: column; gap: 6px; }
.model-row {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px;
  cursor: pointer; transition: .13s;
}
.model-row:hover { background: var(--bg-hover); border-color: var(--accent); }
.model-row.sel { border-color: var(--accent); background: var(--bg-hover); }
.model-row .mr-top { display: flex; align-items: center; gap: 8px; }
.model-row .mr-name { font-weight: 600; font-size: .92em; flex: 1; }
.model-row .mr-price { font-size: .75em; color: var(--text-dim); white-space: nowrap; }
.model-row .mr-desc { font-size: .78em; color: var(--text-dim); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge-free { font-size: .7em; background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); border-radius: 20px; padding: 1px 8px; font-weight: 600; }

.settings-group { margin-bottom: 22px; }
.settings-group h3 { font-size: .82em; text-transform: uppercase; letter-spacing: .7px; color: var(--text-dim); margin: 0 0 11px; }
.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: .85em; margin-bottom: 5px; color: var(--text-dim); }
.field > span output { color: var(--text); font-weight: 600; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }

.switch { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; font-size: .9em; }
.switch input { display: none; }
.switch span {
  width: 38px; height: 21px; border-radius: 20px; background: var(--border);
  position: relative; transition: .18s; flex: 0 0 auto;
}
.switch span::after {
  content: ""; position: absolute; top: 2.5px; left: 2.5px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .18s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(17px); }

.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-sec {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-soft); color: var(--text); font: inherit; font-size: .86em;
  cursor: pointer; transition: .14s;
}
.btn-sec:hover { border-color: var(--accent); }
.btn-sec.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.muted { color: var(--text-dim); font-size: .85em; }

.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 18px; }
.persona-card {
  border: 1px solid var(--border); border-radius: 11px; padding: 11px;
  cursor: pointer; transition: .14s; text-align: left; background: var(--bg-soft);
  color: var(--text); font: inherit;
}
.persona-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.persona-card strong { display: block; font-size: .88em; margin-bottom: 3px; }
.persona-card small { color: var(--text-dim); font-size: .74em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed; bottom: 20px; right: 20px; z-index: 120;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 10px 15px; border-radius: 10px; font-size: .87em;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  animation: slideIn .2s ease; max-width: 340px;
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0 } }

.overlay { display: none; }
.only-mobile { display: none; }

/* ---------------- Scrollbar ---------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---------------- Responsif ---------------- */
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; height: 100%;
    transform: translateX(-102%); box-shadow: 0 0 50px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }
  .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; opacity: 0; pointer-events: none; transition: .2s; }
  .overlay.show { opacity: 1; pointer-events: auto; }
  .messages { padding: 16px 12px 8px; }
  .composer-wrap { padding: 6px 10px 12px; }
  .msg { gap: 10px; }
  .avatar { flex-basis: 28px; width: 28px; height: 28px; font-size: 13px; }
  .model-btn { max-width: 55vw; }
  .composer-hint { display: none; }
  .usage-chip { display: none; }
}

@media print {
  .sidebar, .topbar, .composer-wrap, .msg-actions, .toast-wrap { display: none !important; }
  body { background: #fff; color: #000; display: block; }
  .messages { overflow: visible; }
}
