/* ============================================================
   eai.muktiaji.web.id — styles.css
   Design layer: dark desktop theme.
   Tailwind CDN is primary; everything below is the RESILIENT
   FALLBACK so the app remains fully usable when the CDN is
   unreachable (data-tailwind="fallback" is set by app.js).
   ============================================================ */

:root {
  --bg0: #0b0e14; --bg1: #11151f; --bg2: #151a26; --bg3: #1a2030;
  --line: #1a2030; --line2: #232b3d;
  --tx1: #dbe2ee; --tx2: #b7c1d4; --tx3: #8b97b0; --tx4: #66738f;
  --brand: #6c5ce7; --brand3: #a89dff; --brand6: #5a4bd4;
  --ok: #3ecf8e; --warn: #f5b84f; --err: #ff6b6b;
  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg0); color: var(--tx1); font-family: var(--font-ui); font-size: 14px; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
a { color: var(--brand3); text-decoration: none; }
code, pre, .font-mono { font-family: var(--font-mono); }
kbd { background: var(--bg2); border: 1px solid var(--line2); border-radius: 4px; padding: 1px 5px; font-size: 10px; font-family: var(--font-mono); }
.hidden { display: none !important; }
.thin-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.thin-scroll::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }
.thin-scroll::-webkit-scrollbar-thumb:hover { background: #2e3a52; }
.thin-scroll::-webkit-scrollbar-track { background: transparent; }

/* ---------- layout shell ---------- */
.app-shell { height: 100vh; }
.left-sidebar, .inspector-panel { min-height: 0; }

/* ---------- modals ---------- */
.modal-backdrop[style*="flex"] { display: flex; }
.modal-backdrop { display: flex; }
.modal-card { animation: pop-in .14s ease-out; }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- settings tabs / toggles ---------- */
.settings-tab { color: var(--tx4); }
.settings-tab:hover { color: var(--tx2); background: var(--bg2); }
.settings-tab.active { color: #fff; background: var(--brand); }
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle input { display: none; }
.toggle span { position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--line2); border-radius: 999px; transition: background .15s; }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--tx3); transition: transform .15s, background .15s; }
.toggle input:checked + span { background: var(--brand); border-color: var(--brand); }
.toggle input:checked + span::after { transform: translateX(16px); background: #fff; }

/* ---------- chat rows ---------- */
.chat-row { display: flex; gap: 12px; align-items: flex-start; }
.chat-row.user { flex-direction: row-reverse; }
.msg-col { max-width: 88%; min-width: 0; display: flex; flex-direction: column; }
.chat-row.user .msg-col { align-items: flex-end; }
.chat-row.assistant .msg-col { width: 100%; max-width: 100%; }
.avatar { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; margin-top: 2px; }
.avatar.user { background: var(--bg3); border: 1px solid var(--line2); }
.avatar.assistant { background: rgba(108, 92, 231, .22); border: 1px solid rgba(108, 92, 231, .4); color: var(--brand3); }
.avatar.error { background: rgba(255, 107, 107, .15); border: 1px solid rgba(255, 107, 107, .35); color: var(--err); }
.bubble { width: 100%; min-width: 0; }
.chat-row.user .bubble { width: fit-content; max-width: 100%; background: var(--bg3); border: 1px solid var(--line2); border-radius: 14px 14px 4px 14px; }
.chat-row.assistant .bubble { background: var(--bg1); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; }
.chat-row.error .bubble { background: rgba(255, 107, 107, .07); border: 1px solid rgba(255, 107, 107, .3); border-radius: 14px; }
.bubble-inner { padding: 10px 14px; overflow-wrap: anywhere; }
.msg-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; padding: 0 4px; }
.msg-meta .t { font-size: 10px; color: var(--tx4); }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.chat-row:hover .msg-actions { opacity: 1; }
.msg-actions button { font-size: 11px; color: var(--tx4); padding: 3px 7px; border-radius: 6px; }
.msg-actions button:hover { background: var(--bg2); color: var(--tx2); }

/* ---------- markdown content ---------- */
.md-content { line-height: 1.65; font-size: 14px; }
.md-content > *:first-child { margin-top: 0; }
.md-content > *:last-child { margin-bottom: 0; }
.md-content p { margin: 0 0 10px; }
.md-content h1, .md-content h2, .md-content h3, .md-content h4 { margin: 18px 0 8px; line-height: 1.3; font-weight: 650; }
.md-content h1 { font-size: 20px; } .md-content h2 { font-size: 17px; } .md-content h3 { font-size: 15px; } .md-content h4 { font-size: 14px; }
.md-content ul, .md-content ol { margin: 0 0 10px; padding-left: 22px; }
.md-content li { margin: 3px 0; }
.md-content blockquote { margin: 0 0 10px; padding: 2px 14px; border-left: 3px solid var(--brand); background: var(--bg2); border-radius: 0 8px 8px 0; color: var(--tx2); }
.md-content a { color: var(--brand3); text-decoration: underline; text-underline-offset: 2px; }
.md-content img { max-width: 100%; border-radius: 8px; }
.md-content hr { border: none; border-top: 1px solid var(--line2); margin: 16px 0; }
.md-content table { border-collapse: collapse; margin: 0 0 10px; width: 100%; font-size: 13px; }
.md-content th, .md-content td { border: 1px solid var(--line2); padding: 6px 10px; text-align: left; }
.md-content th { background: var(--bg2); }
.md-content code:not(pre code) { background: var(--bg2); border: 1px solid var(--line2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.md-content pre { background: #0d1117; border: 1px solid var(--line2); border-radius: 10px; padding: 0; margin: 0 0 12px; overflow: hidden; position: relative; }
.md-content pre code { display: block; padding: 14px 16px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; background: transparent; border: none; }
.code-copy-btn { position: absolute; top: 6px; right: 6px; font-size: 10px; color: var(--tx3); background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px; padding: 3px 8px; opacity: 0; transition: opacity .12s; }
.md-content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: #fff; }

/* ---------- reasoning / thinking accordion (built with native DOM) ---------- */
.reason-acc { margin: 0 0 10px; border: 1px solid var(--line2); border-radius: 10px; background: var(--bg2); overflow: hidden; }
.reason-acc > summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 12px; color: var(--tx3); cursor: pointer; list-style: none; user-select: none; }
.reason-acc > summary::-webkit-details-marker { display: none; }
.reason-acc > summary::before { content: "▸"; transition: transform .15s; font-size: 10px; }
.reason-acc[open] > summary::before { transform: rotate(90deg); }
.reason-acc .reason-body { padding: 2px 14px 12px; font-size: 12.5px; color: var(--tx3); white-space: pre-wrap; font-family: var(--font-mono); line-height: 1.6; max-height: 320px; overflow-y: auto; }

/* ---------- sources block ---------- */
.sources-block { margin: 0 0 10px; border: 1px dashed var(--line2); border-radius: 10px; padding: 10px 12px; }
.sources-block summary { cursor: pointer; font-size: 12px; color: var(--tx3); user-select: none; }
.sources-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.sources-list a { display: block; font-size: 12px; color: var(--tx2); }
.sources-list .s-title { color: var(--tx1); }
.sources-list .s-url { color: var(--tx4); font-size: 11px; }

/* ---------- streaming caret ---------- */
.stream-caret::after { content: "▍"; color: var(--brand3); animation: blink 1s steps(1) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- empty-state images ---------- */
.thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,.7); color: #fff; font-size: 10px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg-images img { max-height: 180px; max-width: 260px; border-radius: 8px; border: 1px solid var(--line2); }

/* ---------- sidebar items ---------- */
.side-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 7px 10px; border-radius: 8px; font-size: 13px; color: var(--tx3); transition: background .1s; }
.side-item:hover { background: var(--bg2); color: var(--tx1); }
.side-item.active { background: var(--bg3); color: var(--tx1); border: 1px solid var(--line2); }
.side-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); flex-shrink: 0; }
.side-item .pin { font-size: 10px; color: var(--tx4); }
.assistant-chip { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; color: var(--tx3); border: 1px solid transparent; }
.assistant-chip:hover { background: var(--bg2); color: var(--tx1); }
.assistant-chip.active { border-color: rgba(108,92,231,.5); background: rgba(108,92,231,.12); color: var(--brand3); }

/* ---------- capability badges ---------- */
.cap-badge { font-size: 9.5px; padding: 1.5px 6px; border-radius: 5px; border: 1px solid; white-space: nowrap; }
.cap-vision { color: #7dd3fc; border-color: rgba(125,211,252,.35); background: rgba(125,211,252,.08); }
.cap-reasoning { color: var(--brand3); border-color: rgba(108,92,231,.4); background: rgba(108,92,231,.1); }
.cap-tooluse { color: var(--ok); border-color: rgba(62,207,142,.35); background: rgba(62,207,142,.08); }

/* ---------- sync badge ---------- */
.sync-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line2); background: var(--bg2); font-size: 10.5px; }
.sync-pill .s-dot { width: 6px; height: 6px; border-radius: 50%; }
.sync-pill.kv .s-dot { background: var(--ok); }
.sync-pill.local .s-dot { background: var(--tx4); }
.sync-pill.unsynced .s-dot { background: var(--warn); }

/* ---------- palette rows ---------- */
.palette-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; font-size: 13px; color: var(--tx2); cursor: pointer; }
.palette-row .ico { width: 26px; height: 26px; border-radius: 7px; background: var(--bg2); border: 1px solid var(--line2); display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
.palette-row.sel { background: var(--bg3); color: var(--tx1); }
.palette-row .hint { margin-left: auto; font-size: 10.5px; color: var(--tx4); }

/* ---------- provider editor cards ---------- */
.provider-card { border: 1px solid var(--line2); border-radius: 12px; background: var(--bg1); overflow: hidden; }
.provider-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.provider-body { padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field label { display: block; font-size: 11px; color: var(--tx4); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.field .inp { width: 100%; background: var(--bg2); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 11px; font-size: 13px; color: var(--tx1); }
.field .inp:focus { outline: none; border-color: rgba(108,92,231,.6); }
.field.wide { grid-column: 1 / -1; }
.model-row { display: grid; grid-template-columns: 1.2fr 1.2fr auto auto auto auto auto; gap: 8px; align-items: center; margin-top: 6px; }
.model-row .inp { background: var(--bg2); border: 1px solid var(--line2); border-radius: 7px; padding: 6px 9px; font-size: 12px; width: 100%; }
.model-row select.inp { width: auto; }
.url-preview { font-family: var(--font-mono); font-size: 11px; color: var(--tx3); background: var(--bg0); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; word-break: break-all; }
.url-preview.warn { color: var(--warn); border-color: rgba(245,184,79,.4); }
.key-wrap { position: relative; }
.key-wrap button { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--tx4); }
.key-wrap button:hover { color: var(--tx2); }
.check-label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--tx3); cursor: pointer; }
.check-label input { accent-color: var(--brand); width: 15px; height: 15px; }

/* ---------- toasts ---------- */
.toast { background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; padding: 11px 14px; font-size: 12.5px; color: var(--tx2); box-shadow: 0 8px 30px rgba(0,0,0,.45); animation: pop-in .16s ease-out; display: flex; gap: 9px; align-items: flex-start; }
.toast.ok { border-color: rgba(62,207,142,.4); } .toast.err { border-color: rgba(255,107,107,.45); } .toast.warn { border-color: rgba(245,184,79,.45); }
.toast .t-ico { flex-shrink: 0; }
.toast .t-x { margin-left: auto; color: var(--tx4); font-size: 11px; flex-shrink: 0; }
.toast .t-x:hover { color: var(--tx1); }

/* ---------- context menu ---------- */
.ctx-item { display: block; width: 100%; text-align: left; padding: 8px 14px; color: var(--tx2); }
.ctx-item:hover { background: var(--bg2); color: var(--tx1); }
.ctx-item.danger { color: var(--err); }
.ctx-item.danger:hover { background: rgba(255,107,107,.1); }

/* ---------- misc ---------- */
.fade-in { animation: fadein .2s ease-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
#composerInput { line-height: 1.5; }
.composer-box { box-shadow: 0 4px 24px rgba(0,0,0,.25); }

/* ============================================================
   TAILWIND FALLBACK MODE
   When the Tailwind CDN fails, app.js adds [data-tailwind="fallback"].
   These rules strip tailwind utilities (which would be no-ops) and
   pin the core layout so the app keeps working offline.
   ============================================================ */
[data-tailwind="fallback"] body { font-family: var(--font-ui); }
[data-tailwind="fallback"] .app-shell { display: flex; height: 100vh; }
[data-tailwind="fallback"] .left-sidebar { display: flex; flex-direction: column; width: 260px; border-right: 1px solid var(--line); background: var(--bg1); flex-shrink: 0; }
[data-tailwind="fallback"] .inspector-panel { display: block; width: 280px; border-left: 1px solid var(--line); background: var(--bg1); overflow-y: auto; flex-shrink: 0; }
[data-tailwind="fallback"] main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
[data-tailwind="fallback"] header { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
[data-tailwind="fallback"] footer { flex-shrink: 0; border-top: 1px solid var(--line); padding: 12px 20px 16px; }
[data-tailwind="fallback"] #scrollArea { flex: 1; overflow-y: auto; }
[data-tailwind="fallback"] #messageContainer { max-width: 920px; margin: 0 auto; padding: 24px 20px; }
[data-tailwind="fallback"] .modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60; align-items: center; justify-content: center; }
[data-tailwind="fallback"] .modal-card { background: var(--bg1); border: 1px solid var(--line2); border-radius: 12px; }
[data-tailwind="fallback"] .btn-primary { background: var(--brand); color: #fff; border-radius: 8px; padding: 8px 16px; font-size: 13px; }
[data-tailwind="fallback"] .btn-secondary { background: var(--bg3); color: var(--tx2); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 16px; font-size: 13px; }
[data-tailwind="fallback"] .text-center { text-align: center; }
[data-tailwind="fallback"] .flex { display: flex; }
[data-tailwind="fallback"] .hidden { display: none !important; }
