:root {
  --green: #1d8c2f; --green-dark: #156b23; --gold: #d4af37;
  --bg: #f3f6f4; --panel: #ffffff; --line: #e1e8e3; --text: #1a202c; --muted: #66707d;
  --soft: #eef7f0; --sel: #e3f2e6; --danger: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111613; --panel: #18201b; --line: #2b362f; --text: #e8eee9; --muted: #9aa69e;
          --soft: #1f2b23; --sel: #23352a; --danger: #f28b82; --green: #2fa443; --green-dark: #7fd08d; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.6 "Segoe UI", Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); min-height: 1.4em; }

button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--green); }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.primary:hover { background: #156b23; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.wide { width: 100%; padding: 10px; margin-top: 14px; }
button:disabled { opacity: .55; cursor: default; }
button.icon { padding: 4px 10px; font-size: 18px; }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; min-height: 280px; line-height: 1.8; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, #1d8c2f 0%, #156b23 55%, var(--bg) 55%); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; padding: 28px 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12); border-top: 4px solid var(--gold); }
.login-card h1 { margin: 10px 0 0; font-size: 20px; text-align: center; color: var(--green-dark); }
.login-card p.muted { text-align: center; margin: 2px 0 14px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login-logo { display: block; margin: 0 auto; height: 64px; background: #fff; border-radius: 12px; padding: 6px 8px; }

/* layout */
.app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel);
  border-bottom: 3px solid var(--gold); }
.top-logo { height: 34px; background: #fff; border-radius: 8px; padding: 3px 5px; border: 1px solid var(--line); }
.brand { display: flex; flex-direction: column; line-height: 1.3; }
.brand strong { color: var(--green-dark); }
.spacer { flex: 1; }
.panes { flex: 1; display: grid; grid-template-columns: 200px 370px 1fr; min-height: 0; }
.nav { border-inline-end: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; background: var(--panel); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; cursor: pointer; margin-bottom: 2px; }
.nav a:hover { background: var(--soft); }
.nav a.active { background: var(--sel); color: var(--green-dark); font-weight: 700; }
.nav .count { background: var(--green); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; }
.nav hr { border: 0; border-top: 1px solid var(--line); margin: 8px 4px; }
.list-pane { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.toolbar { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.toolbar button.on { background: var(--sel); border-color: var(--green); color: var(--green-dark); }
.list { overflow-y: auto; flex: 1; }
.item { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--soft); }
.item.sel { background: var(--sel); box-shadow: inset -3px 0 var(--green); }
.item .row { display: flex; justify-content: space-between; gap: 8px; }
.item .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj, .item .prev { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.item.unread .who, .item.unread .subj { color: var(--text); font-weight: 700; }
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #fbf3d9; color: #8a6d0b; font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }

/* reader */
.reader { overflow-y: auto; padding: 20px 26px; min-width: 0; }
.reader h2 { margin: 0 0 10px; font-size: 20px; }
.meta { color: var(--muted); font-size: 13px; margin-bottom: 3px; word-break: break-word; }
.actions { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.body { white-space: pre-wrap; word-wrap: break-word; border-top: 1px solid var(--line); padding-top: 16px; }
iframe.mail { width: 100%; min-height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.atts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { font-size: 13px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft);
  color: var(--text); text-decoration: none; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; padding: 0 2px; color: var(--danger); }
.back { margin-bottom: 10px; }

/* composer */
.form label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.notice { background: #fbf3d9; color: #6b5409; padding: 9px 12px; border-radius: 8px; margin-bottom: 10px; border-inline-start: 4px solid var(--gold); }
.inserts { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 4px; }
.inserts button { font-size: 13px; padding: 4px 10px; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 14px; }
.check input { width: auto; }
.preview-box { margin-top: 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--green-dark); color: #fff;
  padding: 9px 18px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 10; }
.toast.show { opacity: 1; }
.only-mobile { display: none; }

/* phone: one pane at a time */
@media (max-width: 860px) {
  .only-mobile { display: inline-block; }
  .brand span, #refreshBtn { display: none; }
  .top { padding: 8px 10px; gap: 6px; }
  .panes { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 0 0 auto; width: 240px; z-index: 5; box-shadow: -4px 0 20px rgba(0,0,0,.2); transform: translateX(110%); transition: transform .2s; }
  .nav.open { transform: none; }
  .list-pane, .reader { grid-row: 1; grid-column: 1; }
  .panes.reading .list-pane { display: none; }
  .panes:not(.reading) .reader { display: none; }
  .reader { padding: 14px; }
}
