:root {
    --bg: #121a16;
    --surface: #1b2620;
    --surface-2: #26362d;
    --line: #2c3c33;
    --text: #ecebe3;
    --muted: #94a59a;
    --accent: #d9b44a;
    --accent-ink: #1c1a0e;
    --danger: #e08a7a;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 720px;
    margin: 0 auto;
}

.bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--line);
}

/* ---------- Percakapan ---------- */
.log {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 26px;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}

.kosong {
    margin: auto;
    font-family: var(--serif);
    font-size: 26px;
    color: var(--muted);
}

.msg { max-width: 100%; overflow-wrap: anywhere; }

.msg.user {
    align-self: flex-end;
    max-width: 82%;
    padding: 10px 16px;
    background: var(--surface-2);
    border-radius: 18px 18px 4px 18px;
    font-size: 15.5px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.msg.ai {
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.7;
}
.msg.ai .teks { white-space: pre-wrap; }
.msg.ai strong { font-weight: 700; }

.msg.ai code {
    padding: 1px 6px;
    background: var(--surface-2);
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 0.86em;
}

.msg.ai pre {
    margin: 12px 0;
    padding: 14px 16px;
    background: #0d1310;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre;
}
.msg.ai pre code { padding: 0; background: none; font-size: inherit; }

.msg.error {
    padding: 10px 14px;
    border-left: 3px solid var(--danger);
    color: var(--danger);
    font-size: 15px;
    line-height: 1.5;
}

.salin {
    margin-top: 6px;
    padding: 4px 0;
    background: none;
    border: none;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 13px;
    cursor: pointer;
}
.salin:hover { color: var(--text); }

/* indikator mengetik */
.titik { display: inline-flex; gap: 5px; padding: 8px 0; }
.titik span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: denyut 1.1s ease-in-out infinite;
}
.titik span:nth-child(2) { animation-delay: 0.15s; }
.titik span:nth-child(3) { animation-delay: 0.3s; }
@keyframes denyut {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

/* ---------- Kotak ketik ---------- */
.dock { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); }

.kotak {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 8px 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 26px;
}
.kotak:focus-within { border-color: var(--accent); }

.kotak textarea {
    flex: 1;
    max-height: 140px;
    padding: 9px 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.4;
    resize: none;
}
.kotak textarea::placeholder { color: var(--muted); }

.kotak .kirim {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: var(--accent-ink);
    cursor: pointer;
}
.kotak .kirim:hover { filter: brightness(1.08); }
.kotak .kirim:disabled { opacity: 0.35; cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
    .titik span { animation: none; opacity: 0.6; }
}

/* ---------- Foto ---------- */
.kotak .ikon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
}
.kotak .ikon:hover { color: var(--text); background: var(--surface-2); }

.preview {
    position: relative;
    display: inline-block;
    margin: 0 0 10px 6px;
}
.preview[hidden] { display: none; }
.preview img {
    display: block;
    max-height: 96px;
    max-width: 160px;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.preview button {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.msg.user img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    margin-bottom: 8px;
    border-radius: 12px;
}

/* ---------- Blok perintah ---------- */
.run {
    margin: 12px 0;
    border: 1px solid var(--accent);
    border-radius: 12px;
    overflow: hidden;
}
.run pre { margin: 0; border: none; border-radius: 0; }
.run .aksi {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}
.run .aksi button {
    padding: 8px 16px;
    background: var(--accent);
    border: none;
    border-radius: 999px;
    color: var(--accent-ink);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.run .aksi button.sekunder {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
}
.run .aksi button:disabled { opacity: 0.5; cursor: not-allowed; }
.run .hasil {
    margin: 0;
    padding: 12px 16px;
    max-height: 260px;
    overflow: auto;
    background: #0a100d;
    border-top: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    color: var(--muted);
}

/* ---------- Tombol kunci pemilik ---------- */
.bar button {
    padding: 5px 14px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-family: var(--sans);
    font-size: 13px;
    cursor: pointer;
}
.bar button:hover { color: var(--text); }
.bar button.aktif { border-color: var(--accent); color: var(--accent); }
