* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f6f3ec;
  color: #1c1a17;
  font-size: 16px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: #6b655c; }
.small { font-size: 13px; }
.error { color: #a33; margin: 8px 0; }
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid #d8d2c4; background: #fff; padding: 8px 14px; }
button.primary { background: #7d5c10; border-color: #7d5c10; color: #fffefa; }
button.quiet { background: transparent; border-color: transparent; color: #7d5c10; }
button.icon-btn { border: none; background: transparent; font-size: 22px; padding: 4px 10px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea {
  font: inherit; width: 100%; padding: 10px; border: 1px solid #d8d2c4;
  border-radius: 6px; background: #fff; color: inherit;
}
input:focus, textarea:focus { outline: 2px solid #b08d57; border-color: #b08d57; }

/* login */
#login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fffefa; border: 1px solid #d8d2c4; border-radius: 10px; padding: 28px; width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; }
.login-sub { margin: 0 0 20px; color: #6b655c; }
.login-card label { display: block; margin-bottom: 6px; font-weight: 600; }
.login-card button { width: 100%; margin-top: 14px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  background: #fffefa; border-bottom: 1px solid #d8d2c4;
  padding: 10px 14px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 19px; white-space: nowrap; }
#search { max-width: 420px; }
.account { margin-left: auto; color: #6b655c; font-size: 14px; white-space: nowrap; }
#signout-btn { white-space: nowrap; }

/* layout */
.layout { display: flex; align-items: flex-start; }
.folders { width: 200px; flex: none; padding: 14px 8px; position: sticky; top: 57px; }
.folders button {
  display: flex; justify-content: space-between; width: 100%;
  border: none; background: transparent; padding: 10px 12px;
  text-align: left; border-radius: 0 20px 20px 0; font-size: 15px;
}
.folders button.active { background: #e8dfc9; font-weight: 700; }
.folders .count { color: #6b655c; font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 10px 16px 40px; }
.list-head { display: flex; align-items: baseline; gap: 10px; }
.list-head h2 { margin: 8px 0; font-size: 20px; }

.message-list { background: #fffefa; border: 1px solid #d8d2c4; border-radius: 8px; overflow: hidden; }
.msg {
  display: grid; grid-template-columns: 200px 1fr auto; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid #eee9db; cursor: pointer;
  align-items: baseline;
}
.msg:last-child { border-bottom: none; }
.msg:hover { background: #faf7ef; }
.msg.unread { background: #fff; font-weight: 700; }
.msg.unread .snippet { font-weight: 400; }
.msg .sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .subject-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .snippet { color: #6b655c; font-weight: 400; }
.msg .date { color: #6b655c; font-size: 13px; white-space: nowrap; }
.empty { padding: 30px; text-align: center; color: #6b655c; }
#more-btn { display: block; margin: 14px auto; }

/* reader */
.reader { background: #fffefa; border: 1px solid #d8d2c4; border-radius: 8px; padding: 18px 20px; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.reader-actions .spacer { flex: 1; }
.reader h2 { margin: 0 0 6px; font-size: 21px; }
.reader-body { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 16px 0 0; }
.attachments a { display: inline-block; margin: 4px 8px 4px 0; color: #7d5c10; }

/* compose */
.compose {
  position: fixed; inset: 0; background: rgba(28, 26, 23, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.compose-card {
  background: #fffefa; width: 100%; max-width: 720px; max-height: 92vh;
  overflow-y: auto; border-radius: 12px 12px 0 0; padding: 18px 20px 24px;
}
.compose-head { display: flex; justify-content: space-between; align-items: center; }
.compose-head h2 { margin: 0 0 10px; font-size: 19px; }
.compose-card label { display: block; margin-bottom: 10px; font-weight: 600; font-size: 14px; }
.compose-card label input { margin-top: 4px; font-weight: 400; }
.compose-card textarea { min-height: 220px; resize: vertical; }
.compose-actions { display: flex; gap: 8px; margin-top: 12px; }

/* mobile */
@media (max-width: 760px) {
  .account { display: none; }
  #search { min-width: 0; }
  .layout { flex-direction: column; }
  .folders {
    width: 100%; position: static; display: flex; gap: 4px;
    overflow-x: auto; padding: 8px; border-bottom: 1px solid #d8d2c4;
  }
  .folders button { width: auto; flex: none; border-radius: 20px; padding: 8px 12px; }
  .main { padding: 8px 10px 40px; width: 100%; }
  .msg { grid-template-columns: 1fr auto; }
  .msg .subject-line { grid-column: 1 / -1; }
  .msg .snippet { display: none; }
  .compose-card { max-height: 96vh; }
  .reader-actions button { padding: 7px 10px; font-size: 14px; }
}
