:root {
  --bg: #ece5d9;
  --surface: #f1ebe1;
  --surface-2: #e3dbcd;
  --tinta: #2b2722;
  --redup: #5f584e;
  --aksen: #0f5257;
  --aksen-tinta: #f7f3ec;
  --jalan: #2c5a82;
  --nunggu: #934a12;
  --gagal: #a1382a;
  --bayang-terang: rgba(255, 255, 255, 0.75);
  --bayang-gelap: rgba(120, 104, 80, 0.28);
  --kode-bg: #2b2722;
  --kode-tinta: #efe8dc;
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1b18;
    --surface: #26231f;
    --surface-2: #191714;
    --tinta: #ede6da;
    --redup: #b3aa9c;
    --aksen: #4fa3a5;
    --aksen-tinta: #10201f;
    --jalan: #7fb0dc;
    --nunggu: #e0a060;
    --gagal: #e07a6a;
    --bayang-terang: rgba(255, 255, 255, 0.05);
    --bayang-gelap: rgba(0, 0, 0, 0.55);
    --kode-bg: #12110f;
    --kode-tinta: #e8e1d5;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1d1b18;
  --surface: #26231f;
  --surface-2: #191714;
  --tinta: #ede6da;
  --redup: #b3aa9c;
  --aksen: #4fa3a5;
  --aksen-tinta: #10201f;
  --jalan: #7fb0dc;
  --nunggu: #e0a060;
  --gagal: #e07a6a;
  --bayang-terang: rgba(255, 255, 255, 0.05);
  --bayang-gelap: rgba(0, 0, 0, 0.55);
  --kode-bg: #12110f;
  --kode-tinta: #e8e1d5;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--tinta);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { height: 100%; }

.layar {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

#layar-muat, #layar-kunci {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

[hidden] { display: none !important; }

.redup { color: var(--redup); }

.kartu {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 8px 8px 18px var(--bayang-gelap), -8px -8px 18px var(--bayang-terang);
  padding: 24px;
}

.kunci {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kunci h1 { margin: 4px 0 0; font-size: 1.5rem; }
.kunci p { margin: 0; }
.kunci form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--aksen);
  color: var(--aksen-tinta);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.2rem;
}
.logo.kecil { width: 38px; height: 38px; border-radius: 12px; font-size: 0.95rem; }

label { font-size: 0.9rem; color: var(--redup); }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--tinta);
  background: var(--surface-2);
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: inset 4px 4px 8px var(--bayang-gelap), inset -4px -4px 8px var(--bayang-terang);
  outline: none;
}
input:focus-visible, textarea:focus-visible { box-shadow: inset 4px 4px 8px var(--bayang-gelap), inset -4px -4px 8px var(--bayang-terang), 0 0 0 3px var(--aksen); }

button {
  font: inherit;
  font-weight: 600;
  color: var(--tinta);
  background: var(--surface);
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: 5px 5px 10px var(--bayang-gelap), -5px -5px 10px var(--bayang-terang);
}
button:active { box-shadow: inset 3px 3px 6px var(--bayang-gelap), inset -3px -3px 6px var(--bayang-terang); }
button:focus-visible { outline: 3px solid var(--aksen); outline-offset: 2px; }
button:disabled { opacity: 0.55; cursor: default; }
button.utama { background: var(--aksen); color: var(--aksen-tinta); }
button.bahaya { background: var(--gagal); color: #fff; }
button.kecil { padding: 7px 13px; min-height: 36px; font-size: 0.9rem; }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88rem; }

.pesan {
  margin: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}
.pesan.galat { color: var(--gagal); }
.pesan.peringatan { margin: 8px 16px 0; color: var(--nunggu); }

/* ---------------------------------------------------------------- konsol */

#layar-konsol { height: 100%; min-height: 0; }

.kepala {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  flex-wrap: wrap;
}
.judul { display: flex; align-items: center; gap: 10px; min-width: 0; }
.judul > div:last-child { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
#status-kerja { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aksi-kepala { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.lencana {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--redup);
  font-variant-numeric: tabular-nums;
}
.lencana.Pulihkan { background: var(--jalan); color: #fff; }
.lencana.Ubah { background: var(--nunggu); color: #fff; }
.lencana.Bahaya { background: var(--gagal); color: #fff; }
.lencana.hampir { background: var(--nunggu); color: #fff; }

.daftar {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gelembung {
  max-width: min(760px, 92%);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 5px 5px 12px var(--bayang-gelap), -5px -5px 12px var(--bayang-terang);
  overflow-wrap: anywhere;
}
.gelembung.user { align-self: flex-end; background: var(--aksen); color: var(--aksen-tinta); white-space: pre-wrap; }
.gelembung.ai { align-self: flex-start; }
.gelembung p { margin: 0 0 8px; }
.gelembung p:last-child, .gelembung ul:last-child, .gelembung ol:last-child, .gelembung pre:last-child { margin-bottom: 0; }
.gelembung ul, .gelembung ol { margin: 0 0 8px; padding-left: 22px; }
.gelembung h3 { margin: 4px 0 6px; font-size: 1rem; }
.gelembung pre, .hasil pre, .izin pre {
  background: var(--kode-bg);
  color: var(--kode-tinta);
  padding: 10px 12px;
  border-radius: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0 0 8px;
}
.gelembung code.inline { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }

.baris-alat {
  align-self: flex-start;
  max-width: min(760px, 92%);
  font-size: 0.88rem;
  color: var(--redup);
  padding: 2px 4px;
}
.baris-alat code { color: var(--tinta); overflow-wrap: anywhere; }
.baris-alat details { margin-top: 4px; }
.baris-alat summary { cursor: pointer; }
.baris-alat.galat { color: var(--gagal); }

.izin {
  align-self: stretch;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 6px solid var(--nunggu);
}
.izin.Bahaya { border-left-color: var(--gagal); }
.izin.Pulihkan { border-left-color: var(--jalan); }
.izin h3 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.izin .label { font-size: 0.8rem; color: var(--redup); margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.izin .isi { margin: 0; white-space: pre-wrap; }
.izin .tombol { display: flex; gap: 10px; flex-wrap: wrap; }
.izin .paham { display: flex; gap: 8px; align-items: flex-start; font-size: 0.92rem; color: var(--tinta); }
.izin .paham input { width: auto; margin-top: 4px; box-shadow: none; }
.izin .status { font-weight: 600; }

.catatan {
  align-self: center;
  font-size: 0.82rem;
  color: var(--redup);
  text-align: center;
}

.penulis {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.penulis textarea { resize: none; max-height: 40vh; }
.tombol-penulis { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 520px) {
  .penulis { flex-direction: column; align-items: stretch; }
  .tombol-penulis { flex-direction: row; justify-content: flex-end; }
  .gelembung, .baris-alat { max-width: 100%; }
}
