/* ============================================================
   JiMail — mengikuti design.md, revisi 3 warna
   Hitam #0F172A · Putih #FFFFFF · Biru #1E40AF (satu-satunya aksen)
   Abu-abu diganti hitam transparan agar tetap 3 hue.
   Tanpa emoji di seluruh UI.
   8-point grid · radius: kartu 16px, tombol pill, input 8px
   ============================================================ */

:root {
  --black: #0F172A;
  --white: #FFFFFF;
  --blue: #1E40AF;              /* satu-satunya biru */
  --blue-hover: #1E3A8A;
  --text: #0F172A;
  --text-secondary: rgba(15, 23, 42, 0.65);
  --muted: rgba(15, 23, 42, 0.45);
  --border: rgba(15, 23, 42, 0.14);
  --subtle: rgba(15, 23, 42, 0.03);
  --badge-bg: rgba(30, 64, 175, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--white);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.container {
  max-width: 768px;
  margin: 0 auto;
  padding: 48px 24px 64px;
}

/* ---- Header ---- */
header { margin-bottom: 32px; }
.logo {
  margin: 0 0 8px;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.logo .ji { color: var(--blue); }
.logo .mail { color: var(--text); }
.subtitle { color: var(--text-secondary); margin: 0; font-size: 1rem; }

/* ---- Kartu inbox ---- */
.inbox-bar {
  position: relative;
  z-index: 20; /* pastikan dropdown selalu di atas section Pesan Masuk */
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

select, input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  margin-bottom: 16px;
}
select:focus-visible, input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-color: var(--blue);
}

/* ---- Daftar inbox: dropdown buka-tutup + cari + paginasi ---- */
.inbox-picker { position: relative; margin-bottom: 16px; }
.inbox-togglebar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 8px 6px 6px;
  min-height: 56px;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}
.inbox-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  border-radius: 12px;
  padding: 8px;
  min-height: 0;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.inbox-toggle:hover { background: none; border: none; }
.inbox-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.inbox-chevbox {
  flex: none;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--subtle);
  border-radius: 12px;
}
.inbox-chevron {
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 150ms ease-out;
}
.inbox-toggle[aria-expanded="true"] .inbox-chevron {
  transform: rotate(225deg) translateY(-1px);
}
.inbox-toggle-text {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inbox-copybtn {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 12px;
  padding: 0;
  min-height: 0;
  color: var(--text);
  cursor: pointer;
}
.inbox-copybtn:hover { background: var(--subtle); border: none; }
.inbox-copybtn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.inbox-copybtn svg { width: 22px; height: 22px; display: block; }
.inbox-copybtn.copied { color: var(--blue); }
.inbox-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
  overflow: hidden;
}
#inboxSearch {
  margin-bottom: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
#inboxSearch:focus-visible { outline: none; border-bottom-color: var(--blue); }
.inbox-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--white);
}
.inbox-dropdown .inbox-list {
  border: none;
  border-radius: 0;
  max-height: 280px;
}
.inbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.inbox-item:last-child { border-bottom: none; }
.inbox-item:hover { background: var(--subtle); }
.inbox-item.active { background: var(--badge-bg); }
.inbox-addr {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inbox-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.inbox-del {
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 1.15rem;
  line-height: 1;
  padding: 6px 10px;
  min-height: 0;
  border-radius: 8px;
}
.inbox-del:hover { color: var(--text); background: var(--subtle); border: none; }
.inbox-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.inbox-more {
  width: 100%;
  border: none;
  background: none;
  color: var(--blue);
  font-weight: 600;
  padding: 12px;
  margin-top: 8px;
}
.inbox-more:hover { background: var(--subtle); text-decoration: underline; border: none; }

/* ---- Tombol ---- */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
button:hover { background: var(--subtle); border-color: var(--text); }
button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

#randomBtn {
  background: var(--black);
  border-color: var(--black);
  color: var(--white);
}
#randomBtn:hover { background: var(--blue-hover); border-color: var(--blue-hover); }

/* Tombol Buat & Klaim: hitam font putih seperti + Random */
#createCustomBtn, #klaimBtn {
  background: var(--black);
  border-color: var(--black);
  color: var(--white);
}
#createCustomBtn:hover, #klaimBtn:hover { background: var(--blue-hover); border-color: var(--blue-hover); }

/* ---- Box custom / email lama ---- */
.box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 24px;
  display: flex;
  gap: 8px;
}
.box input { flex: 1; margin-bottom: 0; }
.box select { width: auto; margin-bottom: 0; }
.box button { border-radius: 8px; }
.hidden { display: none; }

/* ---- Kepala daftar pesan ---- */
.messages-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 8px;
}
.messages-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.sync {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--badge-bg);
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 32px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--blue);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.current-inbox {
  font-size: 0.85rem;
  color: var(--text);
  background: var(--subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  word-break: break-all;
}

/* ---- Baris pesan ringkas (klik untuk buka) ---- */
.message-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-top: 8px;
  cursor: pointer;
  transition: border-color 150ms ease-out;
}
.message-row:hover { border-color: var(--blue); }
.message-row:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.message-row-main { min-width: 0; flex: 1; }
.message-row-sender {
  font-weight: 700; font-size: 0.875rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.message-row-subject {
  font-size: 0.875rem; color: var(--text-secondary); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.message-row-side { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.message-row-time { font-size: 0.75rem; color: var(--muted); }

.del-msg {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  cursor: pointer;
  border-radius: 8px;
}
.del-msg:hover { color: var(--text); background: var(--subtle); }

/* ---- Modal detail pesan (design.md 5.5) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 672px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-subject {
  font-weight: 700; font-size: 1.125rem; color: var(--text);
  letter-spacing: -0.01em; word-break: break-word;
}
.modal-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 8px; }
.modal-close {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 8px;
  font-size: 1rem;
  flex-shrink: 0;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}
.modal .expiry { padding: 0 24px 24px; }

/* Iframe isi email versi HTML: terisolasi (sandbox), tinggi tetap + scroll internal */
.modal-html {
  display: block;
  width: 100%;
  height: 420px;
  border: 0;
  background: #fff;
}

/* Kode OTP: satu-satunya aksen biru yang menonjol — bisa diklik untuk salin */
.otp {
  display: inline-block;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--blue);
  margin: 8px 0;
  padding: 6px 12px 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease-out;
}
.otp:hover { background: rgba(30, 64, 175, 0.07); }
.otp.flash { background: rgba(30, 64, 175, 0.14); }
.otp-tip {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 999px;
  padding: 3px 10px;
  margin-left: 10px;
  vertical-align: middle;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  pointer-events: none;
}
.otp-tip.show { opacity: 1; transform: translateY(0); }

.expiry { color: var(--muted); font-size: 0.75rem; margin-top: 8px; }

/* ---- Empty state (tanpa ikon emoji) ---- */
.empty-state { text-align: center; padding: 48px 16px; }
.empty-state .title { font-weight: 700; font-size: 1rem; color: var(--text); margin-bottom: 4px; }
.empty-state .sub { font-size: 0.875rem; color: var(--text-secondary); }

/* ---- Animasi masuk halaman: fade-up halus, stagger per section ---- */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
header { animation: fade-up 450ms ease-out both; }
.inbox-bar { animation: fade-up 450ms ease-out 70ms both; }
.messages { animation: fade-up 450ms ease-out 140ms both; }
footer { animation: fade-up 450ms ease-out 210ms both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---- Footer ---- */
footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 64px;
  line-height: 1.6;
}
.powered { color: var(--muted); }
.powered a { color: var(--blue); text-decoration: none; }
.powered a:hover { text-decoration: underline; }

/* ---- Toast ---- */
#toastContainer {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: var(--black);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px;
  display: flex;
  align-items: center;
  transition: opacity 200ms ease-out;
}
.toast.fadeout { opacity: 0; }
