:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel2: #1d222b;
  --garis: #272d38;
  --teks: #e6e9ef;
  --redup: #98a2b3;
  --aksen: #4f8cff;
  --aksen2: #2f6fe0;
  --hijau: #2ecc8f;
  --merah: #ff6b6b;
  --kuning: #f5c451;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--teks);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--aksen); }

/* --- kerangka --- */
.app { display: grid; grid-template-columns: 220px 340px 1fr; height: 100vh; }
.kolom { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--garis); }
.kolom:last-child { border-right: 0; }
.kepala {
  padding: 12px 14px; border-bottom: 1px solid var(--garis);
  display: flex; align-items: center; gap: 10px; min-height: 56px;
}
.merek { font-weight: 700; letter-spacing: .3px; }
.merek small { display: block; font-weight: 400; color: var(--redup); font-size: 11px; }

/* --- sidebar --- */
.nav { padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.nav button {
  background: transparent; border: 0; text-align: left; padding: 9px 10px;
  border-radius: 8px; color: var(--teks); display: flex; align-items: center; gap: 8px;
}
.nav button:hover { background: var(--panel2); }
.nav button.aktif { background: var(--aksen); color: #fff; }
.nav .angka { margin-left: auto; background: rgba(255,255,255,.14); border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.tombol-tulis {
  margin: 6px 10px 12px; padding: 11px; border: 0; border-radius: 10px;
  background: linear-gradient(180deg, var(--aksen), var(--aksen2)); color: #fff; font-weight: 600;
}
.tombol-tulis:hover { filter: brightness(1.08); }
.kaki { margin-top: auto; padding: 10px; border-top: 1px solid var(--garis); font-size: 12px; color: var(--redup); }
.kaki button { background: transparent; border: 1px solid var(--garis); color: var(--teks); border-radius: 8px; padding: 6px 10px; width: 100%; }

/* --- daftar surat --- */
.cari { padding: 8px 10px; border-bottom: 1px solid var(--garis); }
.cari input { width: 100%; background: var(--panel2); border: 1px solid var(--garis); border-radius: 8px; padding: 8px 10px; }
.daftar { overflow-y: auto; flex: 1; }
.item {
  padding: 11px 13px; border-bottom: 1px solid var(--garis); cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
}
.item:hover { background: var(--panel); }
.item.aktif { background: var(--panel2); box-shadow: inset 3px 0 0 var(--aksen); }
.item .b1 { display: flex; gap: 8px; align-items: baseline; }
.item .pengirim { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.item .waktu { font-size: 11px; color: var(--redup); white-space: nowrap; }
.item .subjek { color: var(--teks); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .cuplik { color: var(--redup); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.belum .pengirim, .item.belum .subjek { font-weight: 700; }
.tanda { font-size: 10px; border: 1px solid var(--garis); border-radius: 6px; padding: 0 5px; color: var(--redup); }
.tanda.belum { background: var(--aksen); border-color: var(--aksen); color: #fff; }

/* --- baca surat --- */
.baca { overflow-y: auto; flex: 1; padding: 18px 22px; }
.baca h2 { margin: 0 0 10px; font-size: 19px; line-height: 1.35; }
.meta { color: var(--redup); font-size: 12.5px; margin-bottom: 14px; line-height: 1.7; }
.meta b { color: var(--teks); font-weight: 600; }
.aksi { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.aksi button {
  background: var(--panel2); border: 1px solid var(--garis); border-radius: 8px;
  padding: 7px 13px; color: var(--teks);
}
.aksi button:hover { border-color: var(--aksen); }
.aksi button.bahaya:hover { border-color: var(--merah); color: var(--merah); }
.isi { background: #fff; color: #111; border-radius: 10px; overflow: hidden; }
.isi iframe { width: 100%; border: 0; display: block; min-height: 380px; }
.isi-teks { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.65; padding: 16px; background: var(--panel); color: var(--teks); border-radius: 10px; }
.lampiran { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.lampiran a {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  background: var(--panel2); border: 1px solid var(--garis); border-radius: 8px; padding: 8px 12px; color: var(--teks);
}
.lampiran a:hover { border-color: var(--aksen); }
.lampiran small { color: var(--redup); }

/* --- tulis --- */
.tulis { overflow-y: auto; flex: 1; padding: 18px 22px; }
.baris { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.baris label { font-size: 12px; color: var(--redup); }
.baris input, .baris textarea, .baris select {
  background: var(--panel2); border: 1px solid var(--garis); border-radius: 8px; padding: 9px 11px; width: 100%;
}
.baris textarea { min-height: 260px; resize: vertical; font-family: inherit; line-height: 1.6; }
.baris input:focus, .baris textarea:focus { outline: 2px solid var(--aksen2); border-color: var(--aksen); }
.tombol-utama {
  background: linear-gradient(180deg, var(--aksen), var(--aksen2)); border: 0; color: #fff;
  font-weight: 600; border-radius: 9px; padding: 10px 20px;
}
.tombol-utama:disabled { opacity: .55; cursor: not-allowed; }
.tombol-biasa { background: var(--panel2); border: 1px solid var(--garis); border-radius: 9px; padding: 10px 16px; color: var(--teks); }
.pil { display: inline-flex; gap: 6px; align-items: center; background: var(--panel2); border: 1px solid var(--garis); border-radius: 20px; padding: 4px 12px; font-size: 12px; color: var(--redup); }
.daftar-lampiran { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.daftar-lampiran .berkas { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--garis); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; }
.daftar-lampiran .berkas button { margin-left: auto; background: transparent; border: 0; color: var(--merah); }

/* --- pesan sistem --- */
.kosong { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--redup); text-align: center; padding: 30px; }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--garis); border-radius: 10px;
  padding: 11px 18px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 50; max-width: 90vw;
}
.toast.gagal { border-color: var(--merah); }
.toast.ok { border-color: var(--hijau); }

/* --- layar masuk / penyiapan --- */
.tengah { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.kotak {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--garis);
  border-radius: 14px; padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.kotak h1 { margin: 0 0 4px; font-size: 20px; }
.kotak p.ket { color: var(--redup); margin: 0 0 18px; font-size: 13px; }
.kotak .baris input { padding: 11px 12px; }
.kotak button { width: 100%; margin-top: 6px; }
.galat { color: var(--merah); font-size: 13px; margin-top: 10px; min-height: 18px; }
.petunjuk { font-size: 12px; color: var(--redup); margin-top: 12px; line-height: 1.6; }
.sandi-bungkus { position: relative; }
.sandi-bungkus button { position: absolute; right: 6px; top: 6px; width: auto; margin: 0; background: transparent; border: 0; color: var(--redup); padding: 4px 8px; }

.tombol-kembali {
  display: none; background: transparent; border: 1px solid var(--garis);
  border-radius: 8px; padding: 6px 11px; color: var(--teks); flex: none;
}
.kepala .merek { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kepala .merek small { overflow: hidden; text-overflow: ellipsis; }
.daftar, .baca, .tulis { -webkit-overflow-scrolling: touch; }

/* --- bilah tab bawah (hanya tampil di HP) --- */
.bilah-bawah { display: none; }
.tampil-hp { display: none; }

/* =====================================================================
   TAMPILAN HP / TABLET (< 900px)
   Satu panel penuh pada satu waktu, dengan bilah tab di bawah.
   Panel diganti lewat kelas .aktif (diatur app.js).
   ===================================================================== */
@media (max-width: 900px) {
  html, body { height: 100%; overflow: hidden; }
  .app { display: block; height: 100vh; height: 100dvh; }

  /* semua panel disembunyikan, hanya yang .aktif yang tampil */
  .kolom {
    display: none; height: 100vh; height: 100dvh;
    border-right: 0; width: 100%;
  }
  .kolom.aktif { display: flex; }

  /* sisakan ruang untuk bilah tab bawah */
  .kolom-daftar.aktif, .kolom-baca.aktif {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  .tombol-kembali { display: inline-flex; }
  .tampil-hp { display: inline-flex; }
  .bilah-bawah {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--panel); border-top: 1px solid var(--garis);
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around; align-items: stretch;
  }
  .bilah-bawah button {
    flex: 1; background: transparent; border: 0; color: var(--redup);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    padding: 7px 2px; border-radius: 10px; font-size: 10.5px; line-height: 1.2;
    position: relative; min-height: 46px;
  }
  .bilah-bawah button .ikon { font-size: 19px; line-height: 1; }
  .bilah-bawah button.aktif { color: var(--aksen); background: rgba(79, 140, 255, .13); }
  .bilah-bawah .lencana {
    position: absolute; top: 3px; left: 50%; transform: translateX(6px);
    background: var(--aksen); color: #fff; border-radius: 9px;
    font-size: 10px; padding: 0 5px; min-width: 16px; text-align: center;
  }

  /* sasaran sentuh lebih besar + cegah iOS auto-zoom saat mengetik */
  .baris input, .baris textarea, .cari input, .kotak input { font-size: 16px; }
  .item { padding: 13px 14px; }
  .aksi button { padding: 12px 15px; min-height: 44px; }
  .aksi { gap: 8px; }
  .tulis .aksi button { flex: 1 1 auto; }
  .tombol-utama, .tombol-biasa { min-height: 44px; }
  .nav button { padding: 12px 12px; }
  .kepala { padding: 10px 12px; min-height: 52px; }
  .baca, .tulis { padding: 14px; }
  .baris textarea { min-height: 190px; }
  .baca h2 { font-size: 17px; }
  .kotak { padding: 20px; }
  .tengah { padding: 14px; }
  /* tombol intip sandi: sasaran sentuh lebih besar di HP */
  .sandi-bungkus button { min-height: 44px; min-width: 44px; padding: 4px 12px; top: 2px; right: 2px; font-size: 15px; }
  .toast { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
}

/* layar sangat kecil (HP lama) */
@media (max-width: 380px) {
  .bilah-bawah button { font-size: 9.5px; }
  .baca, .tulis { padding: 11px; }
  .isi iframe { min-height: 260px; }
}

