:root {
  --bg: #f6f6f8;
  --panel: #ffffff;
  --text: #1c1c22;
  --muted: #6b6b76;
  --line: #e2e2e8;
  --accent: #4b3fd6;
  --accent-text: #ffffff;
  --unread: #eef0ff;
  --danger: #b42318;
  --warn-bg: #fff4e5;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141418;
    --panel: #1d1d23;
    --text: #ececf1;
    --muted: #9a9aa6;
    --line: #2e2e36;
    --accent: #8b82ff;
    --accent-text: #0f0f14;
    --unread: #24233a;
    --danger: #ff6b5e;
    --warn-bg: #3a2c14;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
button {
  font: inherit; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--text); cursor: pointer; min-height: 36px;
}
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
[hidden] { display: none !important; }

.signin { max-width: 360px; margin: 18vh auto; padding: 32px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.signin h1 { margin: 0 0 4px; font-size: 22px; }
.signin p { color: var(--muted); }

.app {
  display: grid; height: 100vh;
  grid-template-columns: 180px minmax(280px, 380px) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "folders list reader";
}
.topbar { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-size: 16px; }
.spacer { flex: 1; }
.folders { grid-area: folders; display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; border-right: 1px solid var(--line); }
.folders button { border: 0; background: transparent; text-align: left; }
.folders button[aria-current="true"] { background: var(--unread); font-weight: 600; }

.list { grid-area: list; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 17px; }
.messages { list-style: none; margin: 0; padding: 0; }
.messages li button {
  display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  border-radius: 0; padding: 10px 16px; background: transparent;
}
.messages li button.unread { background: var(--unread); }
.messages li button.unread .m-from, .messages li button.unread .m-subject { font-weight: 700; }
.messages li button[aria-current="true"] { box-shadow: inset 3px 0 0 var(--accent); }
.m-top { display: flex; justify-content: space-between; gap: 8px; }
.m-from, .m-subject, .m-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-date { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.m-snippet { color: var(--muted); font-size: 13px; }
#more-btn { margin: 12px 16px; }
#list-status { padding: 0 16px; }

.reader { grid-area: reader; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.reader h2 { margin: 4px 0 8px; font-size: 20px; overflow-wrap: anywhere; }
.r-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 12px; font-size: 14px; }
.r-meta dt { color: var(--muted); }
.r-meta dd { margin: 0; overflow-wrap: anywhere; }
.warning { background: var(--warn-bg); padding: 8px 12px; border-radius: 6px; }
#r-html { width: 100%; flex: 1; min-height: 400px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
#r-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.attachments { padding-left: 18px; }

.compose { width: min(680px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); padding: 20px; }
.compose::backdrop { background: rgb(0 0 0 / 0.4); }
.compose h2 { margin: 0 0 12px; font-size: 18px; }
.compose label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
.compose input, .compose textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.compose textarea { resize: vertical; }
.compose-actions { display: flex; justify-content: flex-end; gap: 8px; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "list"; }
  .app.show-folders { grid-template-areas: "top" "folders"; }
  .app.show-folders .list, .app.show-reader .list { display: none; }
  .app.show-reader { grid-template-areas: "top" "reader"; }
  .folders { display: none; border-right: 0; }
  .app.show-folders .folders { display: flex; }
  .reader { padding: 12px 16px; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
}
