:root {
  --canvas: #E7EBE4;
  --surface: #FFFFFF;
  --surface-2: #F4F6F2;
  --ink: #1B2420;
  --muted: #68726C;
  --line: #D5DBD2;
  --pine: #22443A;
  --pine-hi: #2F5C4F;
  --pine-ink: #E6EEE9;
  --brass: #B5862B;
  --danger: #A23A2B;
  --unread: #EEF3EF;
  --open: #DCE7E0;
  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-float: 0 18px 50px -12px rgba(20, 36, 30, .35);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #121815;
    --surface: #1A221E;
    --surface-2: #202A25;
    --ink: #E3E8E3;
    --muted: #97A39B;
    --line: #2C3832;
    --pine: #0E1B16;
    --pine-hi: #1D3A31;
    --pine-ink: #D9E4DD;
    --brass: #D4A64C;
    --danger: #E07A68;
    --unread: #1F2B25;
    --open: #253830;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 var(--font);
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--pine-hi); }
@media (prefers-color-scheme: dark) { a { color: #8FC7B4; } }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- tombol ---------- */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 20px; border: 0; border-radius: 999px;
  background: var(--pine); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary:hover { background: var(--pine-hi); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-primary.block { display: flex; width: 100%; }
@media (prefers-color-scheme: dark) { .btn-primary { background: #3C7563; } .btn-primary:hover { background: #468a74; } }
.btn-outline {
  padding: 7px 18px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-weight: 500;
}
.btn-outline:hover { border-color: var(--muted); }
.tool {
  padding: 6px 12px; border: 0; border-radius: var(--radius-s);
  background: transparent; cursor: pointer; color: var(--ink); font-size: 13px; font-weight: 500;
}
.tool:hover { background: var(--surface-2); }
.tool.danger { color: var(--danger); }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.link { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.link:hover { color: var(--ink); }

/* ---------- kerangka ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; height: 100dvh; }
.only-mobile { display: none; }
.scrim { display: none; }

.sidebar {
  display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px 14px; background: var(--pine); color: var(--pine-ink);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 14px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 1.5px solid var(--brass); border-radius: 8px; color: var(--brass);
  font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.brand-name { font-weight: 700; font-size: 19px; letter-spacing: -.01em; }
.compose-btn {
  margin: 0 0 14px; padding: 12px 16px; border: 0; border-radius: var(--radius-m);
  background: var(--brass); color: #1E1609; font-weight: 700; cursor: pointer; text-align: left;
}
.compose-btn:hover { filter: brightness(1.07); }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folders a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: var(--radius-s);
  color: var(--pine-ink); text-decoration: none; opacity: .78; font-weight: 500;
}
.folders a:hover { opacity: 1; background: rgba(255, 255, 255, .06); }
.folders a.active { opacity: 1; background: var(--pine-hi); font-weight: 700; box-shadow: inset 3px 0 0 var(--brass); }
.badge { font-size: 12px; font-weight: 700; color: var(--brass); }
.me {
  margin-top: auto; display: flex; align-items: center; gap: 10px;
  padding: 12px 8px 4px; border-top: 1px solid rgba(255, 255, 255, .1);
}
.me-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.me-text b, .me-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { opacity: .7; }
.logout { color: var(--pine-ink); opacity: .7; font-size: 12.5px; text-decoration: none; }
.logout:hover { opacity: 1; text-decoration: underline; }

.avatar {
  flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  color: #fff; font-weight: 600; font-size: 13px;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

.content { display: grid; grid-template-columns: minmax(340px, 430px) 1fr; min-width: 0; min-height: 0; }

/* ---------- daftar ---------- */
.list-pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
}
.list-top { display: flex; align-items: center; gap: 10px; padding: 16px 16px 8px; }
.list-top h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.search { flex: 1; min-width: 0; }
.search input {
  width: 100%; padding: 7px 12px; border: 1px solid transparent; border-radius: 999px;
  background: var(--surface-2);
}
.search input:focus { outline: none; border-color: var(--pine-hi); background: var(--surface); }
.toolbar {
  display: flex; align-items: center; gap: 4px; min-height: 42px;
  padding: 4px 12px; border-bottom: 1px solid var(--line);
}
.bulk { display: flex; flex-wrap: wrap; gap: 2px; }
.pager { margin-left: auto; display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: 12.5px; }
.pager span { margin-right: 4px; }
.chk { display: inline-grid; place-items: center; width: 28px; height: 28px; cursor: pointer; }
.chk input { width: 15px; height: 15px; accent-color: var(--pine-hi); cursor: pointer; }

.list { flex: 1; overflow-y: auto; }
.list.loading { opacity: .55; }
.list-empty { padding: 48px 28px; color: var(--muted); text-align: center; max-width: 34ch; margin: 0 auto; }
.row {
  display: grid; grid-template-columns: 28px 1fr auto; grid-template-areas: "chk who meta" "star subj subj";
  column-gap: 8px; row-gap: 1px; align-items: center;
  padding: 10px 14px 10px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row.unread { background: var(--unread); box-shadow: inset 3px 0 0 var(--pine-hi); }
.row.open { background: var(--open); }
.row.sel { background: var(--open); }
.row .chk { grid-area: chk; }
.row .star { grid-area: star; }
.row .who { grid-area: who; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .subj { grid-area: subj; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.row .subj .s { color: var(--ink); margin-right: 8px; }
.row .meta { grid-area: meta; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.row .clip { display: grid; }
.row time { font-size: 12px; white-space: nowrap; }
.row.unread .who, .row.unread .subj .s, .row.unread time { font-weight: 700; color: var(--ink); }
.star {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer;
}
.star:hover { background: var(--surface-2); }
.star.on { color: var(--brass); }

/* ---------- baca ---------- */
.read-pane { min-width: 0; min-height: 0; overflow-y: auto; background: var(--surface); }
.empty-state { display: grid; place-items: center; height: 100%; padding: 24px; color: var(--muted); text-align: center; }
.reader { max-width: 820px; padding: 12px 32px 48px; }
.reader-bar {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 4px;
  margin: 0 -8px; padding: 6px 0; background: var(--surface);
}
.reader-bar .star { margin-left: auto; }
.reader-subject { margin: 14px 0 20px; font-size: 22px; line-height: 1.3; font-weight: 700; letter-spacing: -.015em; }
.msg-head { display: flex; align-items: flex-start; gap: 12px; }
.msg-meta { flex: 1; min-width: 0; line-height: 1.45; }
.msg-head time { white-space: nowrap; }
.msg-body {
  margin: 22px 0 0 48px; max-width: 72ch; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.65;
}
.atts { margin: 28px 0 0 48px; padding-top: 16px; border-top: 1px solid var(--line); }
.atts h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.att-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.att {
  display: flex; align-items: center; gap: 10px; width: 240px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface-2);
}
.att-icon { color: var(--pine-hi); display: grid; }
@media (prefers-color-scheme: dark) { .att-icon { color: #8FC7B4; } }
.att-text { display: flex; flex-direction: column; min-width: 0; }
.att-name { color: var(--ink); font-weight: 600; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-name:hover { text-decoration: underline; }
.att-text small { display: flex; gap: 10px; color: var(--muted); }
.reply-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 32px 0 0 48px; }

/* ---------- tulis ---------- */
.compose {
  position: fixed; right: 24px; bottom: 0; z-index: 30;
  display: flex; flex-direction: column; width: 560px; max-width: calc(100vw - 32px); height: min(580px, calc(100vh - 40px));
  background: var(--surface); border-radius: var(--radius-m) var(--radius-m) 0 0; box-shadow: var(--shadow-float);
}
.compose.min { height: auto; }
.compose.min .compose-body, .compose.min .compose-foot { display: none; }
.compose.drop { outline: 2px dashed var(--brass); outline-offset: -6px; }
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 16px; border-radius: var(--radius-m) var(--radius-m) 0 0;
  background: var(--pine); color: var(--pine-ink); font-weight: 600; cursor: default; user-select: none;
}
.compose-head .icon-btn { color: var(--pine-ink); width: 28px; height: 28px; }
.compose-head .icon-btn:hover { background: rgba(255, 255, 255, .1); }
.compose-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.field { display: flex; align-items: center; gap: 8px; margin: 0 16px; border-bottom: 1px solid var(--line); }
.field label { color: var(--muted); font-size: 13px; min-width: 44px; }
.field input { flex: 1; min-width: 0; padding: 9px 0; border: 0; background: none; }
.field input:focus { outline: none; }
.compose textarea {
  flex: 1; min-height: 180px; margin: 0; padding: 12px 16px; border: 0; resize: none;
  background: none; line-height: 1.6;
}
.compose textarea:focus { outline: none; }
.catts { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 8px; }
.catt {
  position: relative; display: grid; grid-template-columns: 1fr auto 28px; align-items: center; gap: 10px;
  padding: 6px 6px 8px 12px; border-radius: var(--radius-s); background: var(--surface-2); overflow: hidden;
}
.catt-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catt-size { font-size: 12px; color: var(--muted); white-space: nowrap; }
.catt.error .catt-size { color: var(--danger); }
.catt .icon-btn { width: 26px; height: 26px; }
.catt .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.catt .bar i { display: block; height: 100%; background: var(--brass); transition: width .2s linear; }
.catt.ready .bar { display: none; }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 10px 16px 14px; }
.attach-btn { cursor: pointer; }
.compose-hint { font-size: 12.5px; color: var(--muted); }
.compose-hint.ext { color: var(--ink); padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--brass) 18%, transparent); }
.ext-addr { border-bottom: 1px dotted var(--brass); }
.suggest {
  position: absolute; z-index: 5; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface); box-shadow: var(--shadow-float); max-height: 260px; overflow-y: auto;
}
.sg { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-s); cursor: pointer; }
.sg div { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sg small { color: var(--muted); }
.sg.act, .sg:hover { background: var(--surface-2); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translateX(-50%);
  padding: 10px 18px; border-radius: var(--radius-s); background: var(--ink); color: var(--surface);
  box-shadow: var(--shadow-float); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- responsif ---------- */
@media (max-width: 1100px) {
  .content { grid-template-columns: 1fr; }
  .read-pane { display: none; }
  body.reading .list-pane { display: none; }
  body.reading .read-pane { display: block; }
  .only-mobile { display: inline-grid; }
  .list-top .only-mobile { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .list-top .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: 260px;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .35); display: none; }
  body.nav-open .scrim { display: block; }
  .reader { padding: 8px 16px 40px; }
  .msg-body, .atts, .reply-row { margin-left: 0; }
  .att { width: 100%; }
  .compose { inset: 0; right: 0; width: auto; max-width: none; height: auto; border-radius: 0; }
  .compose-head { border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- halaman masuk/daftar ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--pine); }
.auth-card {
  width: 100%; max-width: 400px; padding: 32px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-float);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-brand .brand-name { color: var(--ink); }
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -.015em; }
.auth-sub { margin: 4px 0 20px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; }
.auth-form input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface); font-weight: 400; font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--pine-hi); box-shadow: 0 0 0 3px rgba(47, 92, 79, .15); }
.auth-form .btn-primary { margin-top: 6px; padding: 11px; }
.addr-input { display: flex; align-items: stretch; }
.addr-input input { flex: 1; min-width: 0; border-radius: var(--radius-s) 0 0 var(--radius-s); }
.addr-input span {
  display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-left: 0;
  border-radius: 0 var(--radius-s) var(--radius-s) 0; background: var(--surface-2); color: var(--muted); font-weight: 500;
}
.auth-alert, .auth-ok { margin-bottom: 16px; padding: 10px 12px; border-radius: var(--radius-s); font-size: 13.5px; }
.auth-alert { background: rgba(162, 58, 43, .1); color: var(--danger); }
.auth-ok { background: rgba(47, 92, 79, .12); }
.auth-status { color: var(--muted); }
.auth-foot { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 13.5px; }
