/* ==========================================================================
   Ruang12 Code — style utama
   Tema gelap (default) + tema terang. Mirror layout: sidebar | editor | chat
   ========================================================================== */

/* ==========================================================================
   Ruang12 Code — style utama
   Tema gelap (default) + tema terang, dipilih lewat <html data-theme="...">.
   Semua warna memakai CSS variable di bawah, jadi cukup ganti nilainya.
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg:        #0f1218;
  --bg-2:      #151a23;
  --bg-3:      #1b212c;
  --bg-hover:  #222a37;
  --border:    #262f3d;
  --border-2:  #313c4d;
  --text:      #e4e8f0;
  --text-dim:  #8b94a8;
  --text-dimmer:#5d6779;
  --accent:    #4f9cf9;
  --accent-2:  #2d6fd6;
  --accent-ink:#ffffff;
  --ok:        #3fb950;
  --warn:      #d29922;
  --err:       #f85149;
  --purple:    #a371f7;
  --cyan:      #39c5cf;

  /* khusus terminal & blok kode — mengikuti tema */
  --term-bg:   #0a0d12;
  --term-text: #c8d0dd;
  --term-info: #9fb0c9;
  --code-bg:   #0f141c;
  --code-text: #d7dde8;
  --overlay:   rgba(0, 0, 0, .6);
  --backdrop:  rgba(0, 0, 0, .35);

  --radius:    8px;
  --radius-sm: 5px;
  --shadow:    0 8px 24px rgba(0, 0, 0, .45);
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --bg:        #f4f6fa;
  --bg-2:      #ffffff;
  --bg-3:      #eef1f7;
  --bg-hover:  #e4e9f2;
  --border:    #d6dce8;
  --border-2:  #c2cbdb;
  --text:      #1a2230;
  --text-dim:  #5a657a;
  --text-dimmer:#8b94a8;
  --accent:    #1f6feb;
  --accent-2:  #1158c7;
  --accent-ink:#ffffff;
  --ok:        #1a7f37;
  --warn:      #9a6700;
  --err:       #cf222e;
  --purple:    #8250df;
  --cyan:      #0b7285;

  --term-bg:   #1c2128;
  --term-text: #e6edf3;
  --term-info: #b6c2d1;
  --code-bg:   #f0f2f6;
  --code-text: #24292f;
  --overlay:   rgba(15, 23, 42, .45);
  --backdrop:  rgba(15, 23, 42, .2);

  --shadow:    0 8px 24px rgba(20, 30, 50, .12);
}

/* Transisi halus saat tema diganti (tidak ikut saat halaman pertama dimuat) */
html.animasi-tema *,
html.animasi-tema *::before,
html.animasi-tema *::after {
  transition: background-color .18s ease, border-color .18s ease,
              color .18s ease, box-shadow .18s ease !important;
}
@media (prefers-reduced-motion: reduce) {
  html.animasi-tema *,
  html.animasi-tema *::before,
  html.animasi-tema *::after { transition: none !important; }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }
a { color: var(--accent); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dimmer); }

/* ============================== TOPBAR ============================== */
.topbar {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.brand .logo { font-size: 22px; }
.brand strong { display: block; font-size: 14px; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; color: var(--text-dim); }

.topbar-center { display: flex; align-items: center; gap: 8px; flex: 1; }
.topbar-right  { display: flex; align-items: center; gap: 8px; }

.model-badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--purple);
  background: rgba(163, 113, 247, .12);
  border: 1px solid rgba(163, 113, 247, .3);
  padding: 3px 8px;
  border-radius: 20px;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--err); box-shadow: 0 0 8px currentColor; }
.conn-dot.ok { background: var(--ok); }

/* ============================== BUTTONS ============================= */
.btn {
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-danger { background: #8b2b26; border-color: #a4372f; color: #fff; }
.btn-danger:hover { background: var(--err); }
.btn-ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  font-size: 13px;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.ctl {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  min-width: 150px;
  max-width: 320px;
}
.ctl:focus { outline: none; border-color: var(--accent); }
.ctl.small { padding: 4px 8px; font-size: 12px; min-width: 120px; }
.ctl.tiny  { padding: 3px 6px; font-size: 11px; min-width: 90px; max-width: 150px; }

/* ============================== LAYOUT ============================== */
.layout {
  height: calc(100vh - 50px);
  display: grid;
  grid-template-columns: 250px 1fr 390px;
  gap: 1px;
  background: var(--border);
}
.layout.no-left    { grid-template-columns: 0 1fr 390px; }
.layout.no-right   { grid-template-columns: 250px 1fr 0; }
.layout.no-left.no-right { grid-template-columns: 0 1fr 0; }

.panel { background: var(--bg); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.panel-left  { }
.panel-right { }

.panel-head {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  flex: 0 0 auto;
}
.panel-head-actions { display: flex; gap: 2px; }
.panel-foot { border-top: 1px solid var(--border); padding: 7px 10px; flex: 0 0 auto; }
.stat-line { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

/* ============================== TREE ================================ */
.search-box { padding: 8px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.search-box input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 12px;
}
.search-box input:focus { outline: none; border-color: var(--accent); }

.tree { flex: 1; overflow: auto; padding: 6px 4px; font-size: 13px; }
.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: rgba(79, 156, 249, .16); color: var(--accent); }
[data-theme="light"] .tree-item.active,
[data-theme="light"] .wf-item.active { background: rgba(31, 111, 235, .12); }
.tree-item .icon { width: 14px; text-align: center; opacity: .8; font-size: 12px; }
.tree-item .name { overflow: hidden; text-overflow: ellipsis; }
.tree-item .badge {
  margin-left: auto;
  font-size: 9px;
  color: var(--err);
  background: rgba(248, 81, 73, .15);
  border: 1px solid rgba(248, 81, 73, .4);
  border-radius: 3px;
  padding: 0 4px;
}
.tree-children { margin-left: 12px; border-left: 1px solid var(--border); padding-left: 4px; }
.empty-hint { padding: 20px 12px; color: var(--text-dimmer); font-size: 12px; text-align: center; line-height: 1.7; }

/* ============================== CENTER ============================== */
.panel-center { background: var(--bg-2); }
.tabs {
  height: 38px;
  display: flex;
  align-items: stretch;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.tab {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0 16px;
  cursor: pointer;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text); background: var(--bg-3); }
.tab.active { color: var(--accent); background: var(--bg); box-shadow: inset 0 -2px 0 var(--accent); }
.tabs-right { margin-left: auto; display: flex; align-items: center; gap: 6px; padding-right: 8px; }
.path-label { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tab-body { flex: 1; position: relative; min-height: 0; }
.tab-pane { position: absolute; inset: 0; display: none; flex-direction: column; }
.tab-pane.active { display: flex; }

.editor-host { flex: 1; min-height: 0; }
.editor-fallback { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-fallback textarea {
  flex: 1;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13.5px;
  padding: 14px;
  resize: none;
  outline: none;
  tab-size: 4;
}
.notice-inline {
  padding: 8px 12px;
  background: rgba(210, 153, 34, .12);
  border-bottom: 1px solid var(--border);
  color: var(--warn);
  font-size: 12px;
}

/* preview */
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
#previewFrame { flex: 1; border: none; background: #fff; }
.chk { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; margin-left: auto; }

/* terminal */
.terminal {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.3px;
  line-height: 1.65;
  background: var(--term-bg);
  color: var(--term-text);
  white-space: pre-wrap;
  word-break: break-word;
}
.terminal-foot {
  display: flex; gap: 6px; justify-content: flex-end;
  padding: 6px 10px; border-top: 1px solid var(--border); background: var(--bg-3); flex: 0 0 auto;
}
.t-line { white-space: pre-wrap; word-break: break-word; }
.t-info { color: var(--term-info); }
.t-ok   { color: var(--ok); }
.t-warn { color: var(--warn); }
.t-err  { color: var(--err); }
.t-cmd  { color: var(--accent); }
.t-dim  { color: var(--text-dimmer); }

/* ============================== WORKFLOW ============================ */
.workflow { border-bottom: 1px solid var(--border); background: var(--bg-2); flex: 0 0 auto; max-height: 42vh; overflow: auto; }
.workflow.collapsed { display: none; }
.workflow-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; font-size: 11px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .5px;
}
.wf-meta { font-weight: 400; text-transform: none; letter-spacing: 0; }
.wf-list { list-style: none; margin: 0; padding: 0 6px 8px; }
.wf-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 4px 6px; border-radius: var(--radius-sm); font-size: 12.2px;
}
.wf-item + .wf-item { margin-top: 1px; }
.wf-item:hover { background: var(--bg-3); }
.wf-num {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--border-2); color: var(--text-dimmer);
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; font-family: var(--mono);
}
.wf-body { min-width: 0; flex: 1; }
.wf-title { font-weight: 600; }
.wf-sum { color: var(--text-dim); font-size: 11.5px; margin-top: 1px; word-break: break-word; }
.wf-item.active { background: rgba(79, 156, 249, .1); }
.wf-item.active .wf-num { border-color: var(--accent); color: var(--accent); animation: pulse 1.1s infinite; }
.wf-item.done .wf-num { border-color: var(--ok); background: rgba(63, 185, 80, .16); color: var(--ok); }
.wf-item.done .wf-title { color: var(--text); }
.wf-item.warn .wf-num { border-color: var(--warn); color: var(--warn); }
.wf-item.error .wf-num { border-color: var(--err); color: var(--err); }
.wf-item.skip { opacity: .5; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ============================== CHAT =============================== */
.chat { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

.msg { border-radius: var(--radius); padding: 9px 12px; font-size: 13px; line-height: 1.62; max-width: 100%; word-wrap: break-word; }
.msg.user { background: var(--accent-2); color: var(--accent-ink); align-self: flex-end; max-width: 88%; white-space: pre-wrap; }
.msg.bot  { background: var(--bg-3); border: 1px solid var(--border); }
.msg.bot.streaming { border-color: var(--accent); }
.msg .role { font-size: 10px; color: var(--text-dimmer); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; font-weight: 700; }
.msg.user .role { color: rgba(255, 255, 255, .65); }
.msg.bot.error { border-color: var(--err); background: rgba(248, 81, 73, .08); }
.msg pre {
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px; overflow: auto; font-family: var(--mono); font-size: 12px; margin: 8px 0;
}
.msg code { font-family: var(--mono); font-size: 12px; background: rgba(127, 127, 127, .18); padding: 1px 4px; border-radius: 3px; }
.msg pre code { background: none; padding: 0; }
.msg h3 { margin: 10px 0 4px; font-size: 13.5px; }
.msg ul, .msg ol { margin: 6px 0; padding-left: 20px; }
.msg table { border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.msg th, .msg td { border: 1px solid var(--border-2); padding: 3px 8px; }
.msg .files-added { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
.msg .files-added .fchip {
  font-family: var(--mono); font-size: 11px; background: rgba(63, 185, 80, .12);
  border: 1px solid rgba(63, 185, 80, .35); color: var(--ok);
  border-radius: 12px; padding: 2px 9px; cursor: pointer;
}
.msg .files-added .fchip:hover { background: rgba(63, 185, 80, .25); }
.msg .actions { margin-top: 10px; display: flex; gap: 8px; }

/* thinking dots */
.thinking { display: inline-flex; gap: 4px; align-items: center; }
.thinking i { width: 6px; height: 6px; background: var(--text-dim); border-radius: 50%; animation: bounce 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: .4 } 30% { transform: translateY(-5px); opacity: 1 } }

.tool-card {
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  background: var(--bg-2); border-radius: var(--radius-sm);
  padding: 7px 9px; font-size: 12px; margin: 5px 0;
  font-family: var(--mono); overflow: hidden;
}
.tool-card.bad { border-left-color: var(--err); }
.tool-card.fix { border-left-color: var(--purple); }
.tool-card .tname { color: var(--accent); font-weight: 700; }
.tool-card.bad .tname { color: var(--err); }
.tool-card .targs { color: var(--text-dim); margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-card .tout { color: var(--text-dim); margin-top: 4px; white-space: pre-wrap; font-size: 11.5px; max-height: 120px; overflow: auto; }

/* ============================== COMPOSER ============================ */
.composer { border-top: 1px solid var(--border); background: var(--bg-2); flex: 0 0 auto; }
.composer-tabs { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0; }
.mode-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 3px 9px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; cursor: pointer; font-size: 12px;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--bg-3); border-color: var(--border); color: var(--accent); border-bottom-color: var(--bg-3); }
#convPicker { margin-left: auto; }
.composer-box { padding: 8px; }
#prompt {
  width: 100%;
  background: var(--bg-3); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 9px 11px; resize: vertical; min-height: 62px; max-height: 220px; font-size: 13px; line-height: 1.55;
}
#prompt:focus { outline: none; border-color: var(--accent); }
.composer-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.hint { font-size: 11px; color: var(--text-dimmer); margin-right: auto; }

/* ============================== MODAL =============================== */
.modal {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow); width: min(680px, 92vw); max-height: 86vh;
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px;
}
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.form-row { margin-bottom: 13px; }
.form-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 600; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--accent); }
.form-row .desc { font-size: 11px; color: var(--text-dimmer); margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.hint-box {
  background: rgba(79, 156, 249, .08); border: 1px solid rgba(79, 156, 249, .3);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12px; color: var(--text-dim);
  margin-bottom: 14px; line-height: 1.7;
}
[data-theme="light"] .hint-box { border-color: rgba(31, 111, 235, .3); }

/* tombol tema di topbar */
.theme-btn {
  font-size: 15px;
  line-height: 1;
  padding: 5px 9px;
  border: 1px solid var(--border);
  background: var(--bg-3);
}
/* Ikon menunjukkan aksi, bukan kondisi: di tema gelap tampil matahari
   (klik untuk jadi terang), di tema terang tampil bulan. */
.theme-btn .ikon-gelap { display: inline; }
.theme-btn .ikon-terang { display: none; }
[data-theme="light"] .theme-btn .ikon-gelap { display: none; }
[data-theme="light"] .theme-btn .ikon-terang { display: inline; }
.hint-box code { font-family: var(--mono); background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 3px; color: var(--cyan); }
.preview-shell { background: var(--bg-2); }
.examples { display: grid; gap: 6px; }
.examples button {
  text-align: left; background: var(--bg-3); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 9px 12px; cursor: pointer; font-size: 12.5px; line-height: 1.5;
}
.examples button:hover { border-color: var(--accent); background: var(--bg-hover); }

/* ============================== TOAST =============================== */
.toast-wrap { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--bg-3); border: 1px solid var(--border-2); border-left: 3px solid var(--accent);
  padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 13px; animation: toastIn .2s ease; max-width: 460px;
}
.toast.ok  { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn{ border-left-color: var(--warn); }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ============================== RESPONSIVE ========================== */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 210px 1fr 330px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 0 1fr 320px; }
  .panel-left { position: absolute; z-index: 30; height: calc(100vh - 50px); width: 250px; }
  .brand small { display: none; }
}