:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --hover: #eef2f8;
  --border: #e2e7ef;
  --text: #1f2937;
  --muted: #6b7280;
  --brand: #1565c0;          /* biru ikon */
  --brand-2: #e53935;        /* merah ikon */
  --brand-soft: #e7effb;
  --unread: #0f172a;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 20px rgba(15, 23, 42, .05);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #0f172a;
  --hover: #1a2334;
  --border: #1f2a3d;
  --text: #e5e9f0;
  --muted: #94a3b8;
  --brand: #3b8beb;
  --brand-soft: #16263f;
  --unread: #ffffff;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; height: 100vh; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; transform: scale(.94); } }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Logo: versi putih dipakai di tema gelap */
.logo { display: block; height: 34px; width: auto; }
.logo.white { display: none; }
:root[data-theme="dark"] .logo.dark { display: none; }
:root[data-theme="dark"] .logo.white { display: block; }

/* ---------- Tombol & input ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon { width: 38px; padding: 0; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.input {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; line-height: 1.6; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--brand) 14%, transparent) 0, transparent 40%),
              radial-gradient(circle at 85% 90%, color-mix(in srgb, var(--brand-2) 10%, transparent) 0, transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 36px 32px; box-shadow: var(--shadow); }
.login-card .logo { height: 44px; margin: 0 auto 26px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card p.sub { color: var(--muted); margin: 0 0 24px; text-align: center; font-size: 13.5px; }
.login-card .btn { width: 100%; height: 44px; margin-top: 6px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- Layout utama ---------- */
.shell { display: grid; grid-template-rows: 60px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .spacer { flex: 1; }
.me { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 13px; color: #fff; flex: none; text-transform: uppercase; }
.panes { display: grid; grid-template-columns: 230px 380px 1fr; min-height: 0; }
.pane { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* Folder */
.folders { background: var(--surface-2); border-right: 1px solid var(--border); padding: 14px 10px; overflow-y: auto; }
.compose-btn { width: 100%; height: 44px; margin-bottom: 14px; border-radius: 12px; }
.folder { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: none; cursor: pointer; text-align: left; font-weight: 500; }
.folder:hover { background: var(--hover); }
.folder.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.folder span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Daftar email */
.list { background: var(--surface); border-right: 1px solid var(--border); }
.list-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.list-head h2 { font-size: 16px; margin: 0; flex: 1; }
.list-body { overflow-y: auto; flex: 1; }
.msg { display: grid; grid-template-columns: 36px 1fr auto; gap: 4px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; width: 100%; background: none; border-left: 3px solid transparent; border-top: 0; border-right: 0; text-align: left; }
.msg:hover { background: var(--hover); }
.msg.active { background: var(--brand-soft); border-left-color: var(--brand); }
.msg .avatar { grid-row: span 2; width: 36px; height: 36px; }
.msg .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.msg .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg .subject { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
.msg.unread .from, .msg.unread .subject { color: var(--unread); font-weight: 700; }
.msg.unread .date { color: var(--brand); font-weight: 600; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg.i { width: 40px; height: 40px; opacity: .4; margin-bottom: 8px; }
.loading { padding: 40px; display: grid; place-items: center; color: var(--muted); }

/* Pembaca */
.reader { background: var(--surface); }
.reader-head { padding: 18px 24px 14px; border-bottom: 1px solid var(--border); }
.reader-head h1 { font-size: 20px; margin: 0 0 14px; line-height: 1.35; word-break: break-word; }
.sender { display: flex; gap: 12px; align-items: flex-start; }
.sender .who { flex: 1; min-width: 0; }
.sender .who b { display: block; word-break: break-all; }
.sender .when { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.sender .who small { color: var(--muted); font-size: 12.5px; display: block; word-break: break-all; }
.reader-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.reader-body { flex: 1; overflow-y: auto; padding: 8px 24px 24px; }
.reader-body iframe { width: 100%; border: 0; display: block; min-height: 120px; background: #fff; border-radius: 8px; }
.reader-body pre { white-space: pre-wrap; word-break: break-word; font-family: inherit; margin: 12px 0; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 24px; border-top: 1px solid var(--border); }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 99px; font-size: 12.5px; background: var(--surface-2); max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip small { color: var(--muted); }
.back-btn { display: none; }

/* Modal tulis email */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .15s; }
.modal { width: 100%; max-width: 680px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: pop .18s; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal textarea { min-height: 260px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* Toast */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-weight: 500; animation: pop .2s; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }

/* ---------- Responsif ---------- */
@media (max-width: 1100px) { .panes { grid-template-columns: 200px 320px 1fr; } }
@media (max-width: 860px) {
  .panes { grid-template-columns: 1fr; }
  .folders { display: none; }
  .shell.show-folders .folders { display: block; position: fixed; top: 60px; bottom: 0; left: 0; width: 260px; z-index: 40; box-shadow: 0 0 0 100vmax rgba(2,6,23,.45); }
  .shell.reading .list { display: none; }
  .shell:not(.reading) .reader { display: none; }
  .back-btn { display: inline-flex; margin-bottom: 8px; }
  .sender { flex-wrap: wrap; }
  .sender .when { width: 100%; padding-left: 48px; }
  .me .addr { display: none; }
  .reader-head, .reader-body { padding-left: 16px; padding-right: 16px; }
  .logo { height: 28px; }
}
@media (min-width: 861px) { .menu-btn { display: none; } }
