/* Simpul: gaya antarmuka. Warna hanya dari peran di tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-ui);
  line-height: var(--lh-ui);
  font-weight: var(--w-regular);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-underline-offset: .18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-control); }
::selection { background: var(--accent-soft); color: var(--text); }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 1.125rem; height: 1.125rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i.fill { fill: currentColor; stroke: none; }

/* ---------- Primitif ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.25rem; padding: 0 .875rem;
  border: 1px solid var(--border); border-radius: var(--r-control);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-ui); font-weight: var(--w-medium);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-input); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.icon { width: 2rem; min-height: 2rem; padding: 0; }
.btn.small { min-height: 1.875rem; padding: 0 .625rem; font-size: var(--fs-small); }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 1rem; height: 1rem; border-radius: 50%;
  border: 2px solid var(--text-muted); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: .375rem; }
.field > label, .field > span { font-weight: var(--w-medium); }
.field small { color: var(--text-muted); font-size: var(--fs-small); }
.input, .textarea, .select {
  width: 100%; min-height: 2.5rem; padding: .5rem .75rem;
  background: var(--surface); border: 1px solid var(--border-input); border-radius: var(--r-control);
  font-size: var(--fs-ui);
}
.textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.form-error { color: var(--danger); font-size: var(--fs-small); min-height: 1.2em; }
.switch { display: inline-flex; align-items: center; gap: .625rem; cursor: pointer; }
.switch input { appearance: none; width: 2.25rem; height: 1.25rem; border-radius: var(--r-pill); background: var(--border-input); position: relative; margin: 0; transition: background var(--t-fast); flex: none; }
.switch input::after { content: ""; position: absolute; top: .1875rem; left: .1875rem; width: .875rem; height: .875rem; border-radius: 50%; background: var(--surface); transition: transform var(--t-fast); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(1rem); }

.chip {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 1.5rem; padding: 0 .5rem;
  border: 0; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent-ink);
  font-size: var(--fs-small); font-weight: var(--w-medium);
}
button.chip:hover { outline: 1px solid var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.tag { display: inline-flex; align-items: center; gap: .25rem; font-size: var(--fs-small); color: var(--text-muted); }

/* ---------- Kerangka ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; }
.shell.preview-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) minmax(22rem, 46%); }
.shell.sidebar-hidden { grid-template-columns: 0 minmax(0, 1fr); }
.shell.sidebar-hidden.preview-open { grid-template-columns: 0 minmax(0, 1fr) minmax(22rem, 46%); }
.shell.sidebar-hidden .sidebar { visibility: hidden; }

.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.brand { display: flex; align-items: center; gap: .625rem; padding: .875rem .875rem .5rem 1rem; }
.brand-mark { width: 1.75rem; height: 1.75rem; }
.brand-name { font-size: 1.0625rem; font-weight: var(--w-strong); letter-spacing: -.01em; flex: 1; }
.side-actions { display: grid; gap: .125rem; padding: .25rem .5rem .5rem; }
.side-link {
  display: flex; align-items: center; gap: .625rem; width: 100%;
  min-height: 2.25rem; padding: 0 .625rem; border: 0; border-radius: var(--r-control);
  background: transparent; color: var(--text); text-decoration: none; text-align: left;
  font-weight: var(--w-medium);
}
.side-link:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.side-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }
.side-link .count { margin-left: auto; color: var(--text-faint); font-size: var(--fs-small); font-weight: var(--w-regular); }
.side-search { margin: 0 .5rem .25rem; position: relative; }
.side-search .input { padding-left: 2rem; min-height: 2.125rem; background: color-mix(in srgb, var(--surface) 70%, transparent); border-color: var(--border); }
.side-search svg { position: absolute; left: .625rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); width: 1rem; height: 1rem; }
.history { flex: 1; overflow-y: auto; padding: .25rem .5rem 1rem; overscroll-behavior: contain; }
.history h2 { font-size: var(--fs-small); font-weight: var(--w-medium); color: var(--text-muted); margin: 1rem .625rem .25rem; }
.history .empty { color: var(--text-muted); padding: .75rem .625rem; font-size: var(--fs-small); }
.conv-row { display: flex; align-items: center; border-radius: var(--r-control); position: relative; }
.conv-row:hover, .conv-row:focus-within { background: color-mix(in srgb, var(--text) 6%, transparent); }
.conv-row.active { background: var(--accent-soft); }
.conv-row a {
  flex: 1; min-width: 0; padding: .4375rem .625rem; color: var(--text); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-row.active a { color: var(--accent-ink); font-weight: var(--w-medium); }
.conv-row .btn.icon { opacity: 0; width: 1.75rem; min-height: 1.75rem; margin-right: .125rem; }
.conv-row:hover .btn.icon, .conv-row:focus-within .btn.icon, .conv-row.active .btn.icon { opacity: 1; }
.side-foot { border-top: 1px solid var(--border); padding: .5rem; display: grid; gap: .125rem; }
.credit-meter { padding: .5rem .625rem .25rem; font-size: var(--fs-small); color: var(--text-muted); display: grid; gap: .375rem; }
.credit-meter { text-decoration: none; }
.credit-meter strong { color: var(--text); font-weight: var(--w-medium); }
.bar { height: .25rem; border-radius: var(--r-pill); background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar.warn > i { background: var(--warning); }
.bar.over > i { background: var(--danger); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar {
  display: flex; align-items: center; gap: .5rem; min-height: 3.25rem; padding: .5rem .75rem;
  border-bottom: 1px solid transparent;
}
.topbar.lined { border-bottom-color: var(--border); }
.topbar .title-btn {
  min-width: 0; max-width: 32rem; border: 0; background: transparent; padding: .25rem .5rem; border-radius: var(--r-control);
  font-weight: var(--w-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.topbar .title-btn:hover { background: var(--surface-2); }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--text-muted); font-size: var(--fs-small); }
.scroller { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; scroll-padding-bottom: 8rem; }
.column { width: 100%; max-width: var(--column); margin: 0 auto; padding: 0 1.25rem; }

/* ---------- Beranda chat baru ---------- */
.home { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 2rem 0 18vh; }
.greeting {
  font-size: var(--fs-greeting); line-height: var(--lh-heading); font-weight: var(--w-medium);
  letter-spacing: -.025em; margin: 0 0 .5rem;
}
.home-sub { color: var(--text-muted); font-size: var(--fs-body); margin: 0 0 1.75rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.home-sub .knot { color: var(--accent); }
.starters { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.starters .btn { font-weight: var(--w-regular); color: var(--text-muted); }

/* ---------- Pesan ---------- */
.thread { padding: 1.5rem 0 1rem; display: grid; gap: 1.25rem; }
.msg { display: grid; gap: .5rem; }
.msg.user { justify-items: end; }
.bubble {
  max-width: min(36rem, 92%); background: var(--user-bubble); border-radius: var(--r-panel);
  padding: .625rem .9375rem; font-size: var(--fs-body); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere;
}
.attach-list { display: flex; flex-wrap: wrap; gap: .375rem; justify-content: flex-end; }
.attach {
  display: inline-flex; align-items: center; gap: .375rem; max-width: 16rem;
  padding: .25rem .5rem; border: 1px solid var(--border); border-radius: var(--r-control); background: var(--surface);
  font-size: var(--fs-small); color: var(--text-muted);
}
.attach span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach img { width: 2.5rem; height: 2.5rem; object-fit: cover; border-radius: calc(var(--r-control) - 2px); }
.attach.thumb { padding: .1875rem; }
.msg-actions { display: flex; align-items: center; gap: .125rem; color: var(--text-faint); min-height: 2rem; flex-wrap: wrap; }
.msg.user .msg-actions { opacity: 0; transition: opacity var(--t-fast); }
.msg.user:hover .msg-actions, .msg.user:focus-within .msg-actions { opacity: 1; }
.msg-meta { font-size: var(--fs-small); color: var(--text-faint); margin-left: .375rem; }
.msg-meta.est::after { content: " (perkiraan)"; }
@media (hover: none) { .msg.user .msg-actions { opacity: 1; } }

.prose { font-size: var(--fs-body); line-height: var(--lh-body); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose table, .prose pre { margin: 0 0 1em; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: var(--lh-heading); font-weight: var(--w-strong); margin: 1.5em 0 .5em; letter-spacing: -.01em; }
.prose h1 { font-size: 1.5rem; } .prose h2 { font-size: 1.3125rem; } .prose h3 { font-size: 1.125rem; } .prose h4 { font-size: 1rem; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin: .25em 0; }
.prose li::marker { color: var(--text-muted); }
.prose strong { font-weight: var(--w-strong); }
.prose blockquote { border-left: 3px solid var(--border-input); padding-left: 1em; color: var(--text-muted); }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.prose code { font-family: var(--mono); font-size: .875em; background: var(--surface-2); border: 1px solid var(--border); padding: .08em .35em; border-radius: .3rem; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: var(--fs-ui); }
.prose th, .prose td { border: 1px solid var(--border); padding: .4em .7em; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: var(--w-medium); }
.prose img { max-width: 100%; border-radius: var(--r-control); }
.code { border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface-2); margin: 0 0 1em; overflow: hidden; }
.code-head { display: flex; align-items: center; gap: .25rem; padding: .25rem .375rem .25rem .875rem; border-bottom: 1px solid var(--border); font-size: var(--fs-small); color: var(--text-muted); }
.code-head .lang { flex: 1; }
.code pre { margin: 0; padding: .875rem 1rem; overflow-x: auto; }
.code pre code { background: none; border: 0; padding: 0; font-size: .8125rem; line-height: 1.6; white-space: pre; }
.cursor::after { content: ""; display: inline-block; width: .5em; height: 1.1em; margin-left: .1em; vertical-align: text-bottom; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { display: inline-flex; gap: .3rem; padding: .5rem 0; }
.thinking i { width: .4375rem; height: .4375rem; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: none; } }

.msg-error {
  border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger);
  border-radius: var(--r-control); padding: .625rem .875rem; display: flex; gap: .75rem; align-items: flex-start; flex-wrap: wrap;
}
.msg-error p { margin: 0; flex: 1; min-width: 12rem; }
.msg-note { font-size: var(--fs-small); color: var(--text-muted); }

/* Benang ingatan: elemen yang paling diingat */
.thread-line { display: grid; gap: .5rem; }
.thread-toggle {
  display: inline-flex; align-items: center; gap: .5rem; width: fit-content;
  border: 0; background: transparent; padding: .25rem .375rem .25rem 0; border-radius: var(--r-control);
  color: var(--text-muted); font-size: var(--fs-small);
}
.thread-toggle:hover { color: var(--accent-ink); }
.knots { display: inline-flex; align-items: center; height: 1rem; }
.knots svg { height: 1rem; width: auto; overflow: visible; }
.knots line { stroke: var(--accent); stroke-width: 1.5; }
.knots circle { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; transition: fill var(--t-base); }
.thread-toggle[aria-expanded="true"] .knots circle, .thread-toggle:hover .knots circle { fill: var(--accent); }
.thread-list { display: grid; gap: .25rem; margin: 0; padding: .5rem 0 .5rem .875rem; border-left: 1.5px solid var(--accent); list-style: none; }
.thread-list li { font-size: var(--fs-small); color: var(--text-muted); }
.thread-list a { color: inherit; text-decoration: none; }
.thread-list a:hover { color: var(--accent-ink); text-decoration: underline; }
.learned { font-size: var(--fs-small); color: var(--accent-ink); display: inline-flex; align-items: center; gap: .375rem; }
.learned a { color: inherit; }

/* Langkah komputer */
.tool {
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface);
  margin: 0 0 1em; overflow: hidden;
}
.tool.risky { border-color: var(--warning); }
.tool.blocked, .tool.rejected { border-color: var(--danger); }
.tool-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; font-size: var(--fs-small); }
.tool-head .kind { font-weight: var(--w-medium); }
.tool-head .status { margin-left: auto; color: var(--text-muted); display: inline-flex; align-items: center; gap: .375rem; }
.tool-head .status.ok { color: var(--accent-ink); }
.tool-head .status.bad { color: var(--danger); }
.tool-head .status.warn { color: var(--warning); }
.tool-cmd { margin: 0; padding: .625rem .875rem; background: var(--surface-2); border-top: 1px solid var(--border); font-family: var(--mono); font-size: .8125rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14rem; overflow-y: auto; }
.tool-reason { padding: .5rem .875rem 0; color: var(--text-muted); font-size: var(--fs-small); }
.tool-ask { display: flex; gap: .5rem; padding: .625rem .875rem; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); }
.tool-ask p { margin: 0 auto 0 0; font-size: var(--fs-small); color: var(--warning); }
.tool details { border-top: 1px solid var(--border); }
.tool summary { padding: .5rem .875rem; cursor: pointer; font-size: var(--fs-small); color: var(--text-muted); }
.tool details pre { margin: 0; padding: 0 .875rem .75rem; font-family: var(--mono); font-size: .78rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 20rem; overflow-y: auto; }

/* ---------- Composer ---------- */
.composer-wrap { padding: .5rem 0 1rem; background: linear-gradient(to bottom, transparent, var(--bg) 1.25rem); position: sticky; bottom: 0; }
.composer {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel);
  box-shadow: var(--shadow-composer); padding: .625rem .625rem .5rem .875rem;
  display: grid; gap: .375rem;
}
.composer:focus-within { border-color: var(--border-input); }
.composer.drag { outline: 2px dashed var(--accent); outline-offset: 2px; }
.composer textarea {
  width: 100%; border: 0; outline: none; resize: none; background: transparent;
  font-size: var(--fs-body); line-height: 1.5; min-height: 1.5rem; max-height: 40vh; padding: .25rem 0;
}
.home .composer textarea { min-height: 3rem; }
.composer-row { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.composer-row .spacer { flex: 1; }
.composer .pending { display: flex; flex-wrap: wrap; gap: .375rem; }
.composer .pending .attach { padding-right: .125rem; }
.composer .pending .btn.icon { width: 1.5rem; min-height: 1.5rem; }
.send { width: 2.125rem; min-height: 2.125rem; padding: 0; border-radius: var(--r-control); }
.composer-hint { font-size: var(--fs-small); color: var(--text-faint); text-align: center; padding-top: .5rem; }
.pc-toggle {
  display: inline-flex; align-items: center; gap: .375rem; min-height: 1.875rem; padding: 0 .5rem;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: transparent; color: var(--text-muted);
  font-size: var(--fs-small);
}
.pc-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.pc-toggle .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--text-faint); }
.pc-toggle .dot.on { background: var(--accent); }

/* Pemilih (model, asisten) */
.picker { position: relative; }
.picker-btn {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 1.875rem; max-width: 15rem;
  padding: 0 .5rem; border: 0; border-radius: var(--r-control); background: transparent;
  color: var(--text-muted); font-size: var(--fs-small); font-weight: var(--w-medium);
}
.picker-btn:hover, .picker-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.picker-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu {
  position: absolute; z-index: 40; min-width: 15rem; max-width: 20rem; max-height: 22rem;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel);
  box-shadow: var(--shadow-composer); padding: .375rem; overflow: hidden;
}
.menu.up { bottom: calc(100% + .375rem); }
.menu.down { top: calc(100% + .375rem); }
.menu.right { right: 0; }
.menu .input { min-height: 2rem; margin-bottom: .25rem; }
.menu ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.menu li button, .menu > button {
  display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left;
  padding: .4375rem .625rem; border: 0; background: transparent; border-radius: var(--r-control);
}
.menu li button:hover, .menu li button.hl, .menu > button:hover { background: var(--surface-2); }
.menu li button[aria-selected="true"] { color: var(--accent-ink); font-weight: var(--w-medium); }
.menu .price { margin-left: auto; color: var(--text-faint); font-size: var(--fs-small); }
.menu .none { padding: .5rem .625rem; color: var(--text-muted); }
.menu > button.danger { color: var(--danger); }

/* ---------- Halaman (asisten, memori, pemakaian, pengaturan) ---------- */
.page { padding: 1.5rem 0 4rem; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { font-size: var(--fs-title); line-height: var(--lh-heading); margin: 0; font-weight: var(--w-strong); letter-spacing: -.015em; }
.page-head p { margin: .375rem 0 0; color: var(--text-muted); max-width: 38rem; }
.page-head .grow { flex: 1; min-width: 14rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar .input { max-width: 18rem; }
.toolbar .select { width: auto; }
.list { display: grid; gap: .625rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel); padding: 1rem 1.125rem; }
.card.hl { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.dim { border-style: dashed; }
.card h3 { margin: 0; font-size: var(--fs-body); font-weight: var(--w-strong); }
.card-row { display: flex; gap: .75rem; align-items: flex-start; }
.card-row .grow { flex: 1; min-width: 0; }
.card-meta { display: flex; flex-wrap: wrap; gap: .375rem .875rem; align-items: center; margin-top: .625rem; color: var(--text-muted); font-size: var(--fs-small); }
.card-actions { display: flex; gap: .125rem; flex: none; }
.mem-text { margin: 0; font-size: var(--fs-body); line-height: 1.5; overflow-wrap: anywhere; }
.mem-old { margin: .375rem 0 0; font-size: var(--fs-small); color: var(--text-faint); text-decoration: line-through; }
.pin-on { color: var(--accent); }
.empty-state { text-align: left; padding: 2rem 1.25rem; border: 1px dashed var(--border-input); border-radius: var(--r-panel); color: var(--text-muted); }
.empty-state h3 { color: var(--text); margin: 0 0 .375rem; font-size: var(--fs-body); }
.empty-state p { margin: 0 0 1rem; max-width: 34rem; }
.topics { display: flex; flex-wrap: wrap; gap: .375rem; margin-bottom: 1.25rem; }
.topics .chip { cursor: pointer; }
.topics .chip b { font-weight: var(--w-regular); opacity: .7; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .625rem; margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-panel); padding: .875rem 1rem; display: grid; gap: .25rem; }
.stat span { color: var(--text-muted); font-size: var(--fs-small); }
.stat strong { font-size: 1.375rem; font-weight: var(--w-medium); letter-spacing: -.01em; }
.stat small { color: var(--text-faint); font-size: var(--fs-small); }
.days { display: grid; grid-template-columns: repeat(14, 1fr); gap: .25rem; align-items: end; height: 7.5rem; padding: .75rem 0 0; }
.days div { display: grid; grid-template-rows: 1fr auto; gap: .25rem; height: 100%; }
.days i { align-self: end; display: block; background: var(--accent); border-radius: .25rem .25rem 0 0; min-height: 2px; }
.days i.zero { background: var(--border); }
.days span { font-size: .6875rem; color: var(--text-faint); text-align: center; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-ui); }
table.data th, table.data td { padding: .5625rem .875rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-weight: var(--w-medium); color: var(--text-muted); background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:last-child td { border-bottom: 0; }
section.block { margin-bottom: 2.25rem; }
section.block > h2 { font-size: 1.0625rem; margin: 0 0 .25rem; font-weight: var(--w-strong); }
section.block > p { margin: 0 0 1rem; color: var(--text-muted); max-width: 40rem; }
.form-grid { display: grid; gap: 1rem; max-width: 34rem; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.ok-text { color: var(--accent-ink); font-size: var(--fs-small); }
.secret-box { display: flex; gap: .5rem; align-items: center; padding: .5rem .5rem .5rem .75rem; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: var(--r-control); }
.secret-box code { flex: 1; font-family: var(--mono); font-size: .8125rem; overflow-wrap: anywhere; color: var(--accent-ink); }
pre.howto { font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control); padding: .75rem; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-input); border-radius: var(--r-control); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .375rem .75rem; font-size: var(--fs-small); font-weight: var(--w-medium); color: var(--text-muted); }
.seg button + button { border-left: 1px solid var(--border-input); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.device-status { display: inline-flex; align-items: center; gap: .375rem; }
.device-status .dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--text-faint); }
.device-status .dot.on { background: var(--accent); }
.warn-box { border: 1px solid var(--warning); border-radius: var(--r-control); padding: .75rem .875rem; color: var(--text); background: color-mix(in srgb, var(--warning) 9%, var(--surface)); font-size: var(--fs-small); max-width: 40rem; }

/* ---------- Masuk & pemasangan ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1.25rem; }
.gate-box { width: 100%; max-width: 24rem; }
.gate-box .brand { padding: 0 0 2rem; }
.gate-box h1 { font-size: var(--fs-title); margin: 0 0 .375rem; letter-spacing: -.015em; font-weight: var(--w-strong); }
.gate-box > p { margin: 0 0 1.5rem; color: var(--text-muted); }
.gate-box form { display: grid; gap: 1rem; }

/* ---------- Pratinjau ---------- */
.preview { border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.preview-head { display: flex; align-items: center; gap: .25rem; padding: .5rem .5rem .5rem 1rem; border-bottom: 1px solid var(--border); min-height: 3.25rem; }
.preview-head strong { flex: 1; font-weight: var(--w-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview iframe { flex: 1; border: 0; width: 100%; background: #fff; }
.preview .seg { margin-right: .25rem; }
.preview pre { flex: 1; margin: 0; overflow: auto; padding: 1rem; font-family: var(--mono); font-size: .8125rem; background: var(--surface-2); }

/* ---------- Dialog & toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface); color: var(--text);
  padding: 0; width: min(32rem, calc(100vw - 2rem)); box-shadow: var(--shadow-composer);
}
dialog::backdrop { background: color-mix(in srgb, var(--text) 35%, transparent); }
dialog[open] { animation: rise var(--t-base) ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(.5rem); } }
.dialog-body { padding: 1.25rem 1.25rem 1rem; display: grid; gap: 1rem; }
.dialog-body h2 { margin: 0; font-size: 1.125rem; font-weight: var(--w-strong); }
.dialog-body p { margin: 0; color: var(--text-muted); }
.dialog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .875rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-panel) var(--r-panel); }
.toasts { position: fixed; z-index: 90; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; width: min(26rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: .75rem; align-items: center; padding: .625rem .625rem .625rem .875rem; border-radius: var(--r-control); background: var(--text); color: var(--bg); box-shadow: var(--shadow-composer); animation: rise var(--t-base) ease-out; }
.toast.error { background: var(--danger); color: var(--on-accent); }
.toast p { margin: 0; flex: 1; }
.toast .btn.icon { color: inherit; width: 1.75rem; min-height: 1.75rem; }
.toast .btn.icon:hover { background: color-mix(in srgb, currentColor 15%, transparent); }

.overlay { display: none; }
.boot { min-height: 100dvh; display: grid; place-items: center; color: var(--text-muted); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .shell, .shell.preview-open, .shell.sidebar-hidden, .shell.sidebar-hidden.preview-open { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(19rem, 86vw);
    transform: translateX(-100%); transition: transform var(--t-base) ease; visibility: hidden;
  }
  .shell.sidebar-open .sidebar { transform: none; visibility: visible; }
  .shell.sidebar-open .overlay { display: block; position: fixed; inset: 0; z-index: 55; background: color-mix(in srgb, var(--text) 35%, transparent); }
  .shell.sidebar-hidden .sidebar { visibility: hidden; }
  .preview { position: fixed; inset: 0; z-index: 70; border: 0; }
  .greeting { font-size: 1.875rem; }
  .home { padding-bottom: 8vh; }
  .column { padding: 0 .875rem; }
  .topbar .who { display: none; }
  .bubble { max-width: 96%; }
}
@media (min-width: 861px) { .only-mobile { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.card-text { margin: .375rem 0 0; color: var(--text-muted); font-size: var(--fs-ui); line-height: 1.5; overflow-wrap: anywhere; }
.card h3 .tag { margin-left: .5rem; font-weight: var(--w-regular); }
.device-list { margin: 1rem 0; }
.device-actions { margin-top: .75rem; }
.bubble-edit { width: min(36rem, 100%); display: grid; gap: .5rem; }
.bubble-edit .form-actions { justify-content: flex-end; }
details > .jobs-log { margin-top: .75rem; }
#sec-komputer details { margin-top: 1rem; }
#sec-komputer details > summary { cursor: pointer; color: var(--text-muted); }
.howto-wrap { margin-top: 1rem; }

.days span { font-variant-numeric: tabular-nums; }
.msg.user .msg-actions { min-height: 1.75rem; }

/* Kolom pesan tidak boleh melebar melebihi layar */
.msg { grid-template-columns: minmax(0, 1fr); min-width: 0; }
.msg.user { grid-template-columns: minmax(0, auto); }
.prose, .tool, .code { min-width: 0; max-width: 100%; }
.composer-row { flex-wrap: nowrap; min-width: 0; }
.composer-row .picker { min-width: 0; }
.composer-row .picker-btn { max-width: 100%; }
@media (max-width: 860px) {
  .composer-row .picker-btn { max-width: 9.5rem; }
  .pc-toggle .pc-name { display: none; }
  .composer-row > .picker:first-of-type .picker-btn span { max-width: 5rem; }
}

/* ---------- Konektor ---------- */
.menu-switch { padding: .4375rem .625rem; border-radius: var(--r-control); gap: .5rem; }
.menu-switch:hover { background: var(--surface-2); }
.menu-switch span:nth-child(2) { flex: 1; }
.menu-link { display: block; padding: .5rem .625rem; margin-top: .25rem; border-top: 1px solid var(--border); font-size: var(--fs-small); }
.conn-url { font-family: var(--mono); font-size: .75rem; overflow-wrap: anywhere; }
.conn-error { margin: .5rem 0 0; }
.conn-actions { margin-top: .875rem; }
.card-meta .status.ok { color: var(--accent-ink); }
.card-meta .status.bad { color: var(--danger); }
.conn-tools { margin-top: .875rem; border-top: 1px solid var(--border); padding-top: .625rem; }
.conn-tools > summary { cursor: pointer; color: var(--text-muted); font-size: var(--fs-small); padding: .25rem 0; }
.tool-perm { display: flex; gap: .75rem; align-items: flex-start; padding: .625rem 0; border-bottom: 1px solid var(--border); }
.tool-perm:last-child { border-bottom: 0; }
.tool-perm.all { align-items: center; color: var(--text-muted); }
.tool-perm.all > span { flex: 1; font-weight: var(--w-medium); }
.tool-perm strong { font-weight: var(--w-medium); margin-right: .5rem; }
.tool-perm code { font-family: var(--mono); font-size: .75rem; color: var(--text-muted); margin-right: .5rem; }
.tool-perm p { margin: .25rem 0 0; color: var(--text-muted); font-size: var(--fs-small); }
.tool-perm .seg { flex: none; }
.tag.warn { color: var(--warning); }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: .5rem; }
.catalog-item { display: grid; gap: .125rem; text-align: left; padding: .75rem .875rem; border: 1px solid var(--border); border-radius: var(--r-panel); background: var(--surface); }
.catalog-item:hover { border-color: var(--accent); }
.catalog-item strong { font-weight: var(--w-medium); }
.catalog-item span { color: var(--text-muted); font-size: var(--fs-small); }
#sec-claude .secret-box { margin: 0 0 1rem; max-width: 40rem; }
#sec-claude .warn-box { margin-bottom: 1rem; }
ol.steps { margin: 0 0 1rem; padding-left: 1.25rem; display: grid; gap: .375rem; max-width: 40rem; }
h3.sub { font-size: var(--fs-body); font-weight: var(--w-strong); margin: 1.5rem 0 .625rem; }
.consent .warn-box { margin: 0 0 1rem; }
.consent p { color: var(--text-muted); }
.consent-form { display: grid; gap: 1rem; margin: 1.25rem 0; }
.consent-form .form-actions { justify-content: flex-end; }
@media (max-width: 860px) {
  .tool-perm { flex-direction: column; gap: .5rem; }
  .tool-ask { gap: .375rem; }
}

.page .list + section.block, .page .list + .block { margin-top: 2.25rem; }

/* ---------- Skill ---------- */
.orch-toggle .i { width: 1rem; height: 1rem; color: var(--accent); }
.orch-toggle { text-align: left; }
.skill-load { display: flex; align-items: center; gap: .375rem; color: var(--text-muted); font-size: var(--fs-small); margin: 0 0 .75rem; }
.skill-load .i { width: 1rem; height: 1rem; color: var(--accent); }
.skill-body { font-family: var(--mono); font-size: .8125rem; min-height: 14rem; }
.skill-form .check-list { display: grid; gap: .375rem; }
dialog:has(.skill-form) { width: min(44rem, calc(100vw - 2rem)); }
.auto-models { display: grid; gap: .5rem; max-width: 44rem; }
.auto-row { display: grid; grid-template-columns: minmax(10rem, 15rem) 1fr auto; gap: .5rem; align-items: center; }
.composer { position: relative; }
.composer > .menu { left: 0; bottom: calc(100% + .375rem); top: auto; min-width: 18rem; }
@media (max-width: 860px) {
  .auto-row { grid-template-columns: 1fr auto; }
  .auto-row .input { grid-column: 1 / -1; grid-row: 2; }
}

a.btn { text-decoration: none; }
.field > .seg { justify-self: start; }
.skill-form { max-width: none; }
.skill-trust { margin: 1rem 0 0; }
