:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  color: #192736;
  background: #fff;
  --header: #22394e;
  --muted: #4f6070;
  --line: #dce4eb;
  --blue: #155886;
  --selection: #e5f0f8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
}

h1, h2, p { margin: 0; }

.app-header {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 5vw, 4rem);
  padding: 0.7rem 1.25rem;
  background: var(--header);
  color: #fff;
}

.app-header h1 {
  font-size: 1.125rem;
  font-weight: 650;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.875rem;
}

.search-box label { white-space: nowrap; }

.search-box input {
  width: min(28vw, 22rem);
  min-width: 13rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid #b3c5d5;
  border-radius: 4px;
  font: inherit;
  color: #192736;
  background: #f5f8fb;
}

.mailbox {
  display: grid;
  grid-template-columns: 11.5rem minmax(19rem, 26rem) minmax(0, 1fr);
}

.mailbox-sidebar {
  min-height: calc(100vh - 3.75rem);
  padding: 1.3rem 0.75rem;
  background: #f3f6f9;
  border-right: 1px solid var(--line);
  font-size: 0.875rem;
}

.mailbox-sidebar > p,
.mailbox-sidebar > span { padding-inline: 0.55rem; }
.mailbox-sidebar > p { font-weight: 650; }
.mailbox-sidebar > span { color: var(--muted); }

.folder {
  display: grid;
  grid-template-columns: 1.1rem 1fr auto;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding: 0.5rem 0.55rem;
  border-radius: 4px;
  color: #1e4a6b;
  background: #dfebf5;
}

.envelope {
  width: 0.95rem;
  height: 0.7rem;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  overflow: hidden;
}

.envelope::after {
  display: block;
  width: 0.6rem;
  height: 0.6rem;
  margin: -0.4rem auto 0;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  transform: rotate(45deg);
}

.mail-list {
  border-right: 1px solid var(--line);
  background: #fafcfd;
}

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.list-header h2 { font-size: 1.125rem; }

#show-reply {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 0.8125rem;
  text-decoration: underline;
  cursor: pointer;
}

#result-count, #list-status, #reading-placeholder {
  color: var(--muted);
  font-size: 0.875rem;
}

#list-status:not(:empty) { padding: 1rem 1.1rem; }
#messages { padding: 0; margin: 0; list-style: none; }

.message {
  display: grid;
  gap: 0.28rem;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  padding: 0.62rem 1rem 0.62rem calc(1rem - 3px);
  color: inherit;
  font-size: 0.875rem;
  text-decoration: none;
}

.message:hover { background: #eff5fa; }
.message[aria-current] { background: var(--selection); border-left-color: var(--blue); }

.message-top, .message-bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.55rem;
}

.message .subject { font-weight: 550; }

.message .preview, .message .subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message time, .attachment-count { white-space: nowrap; }
.message time, .message-bottom { font-size: 0.8125rem; color: var(--muted); }

.reading-pane {
  min-width: 0;
  padding: 1.4rem clamp(1rem, 2.6vw, 2.5rem);
}

.reading-pane > h2 {
  margin-bottom: 1.2rem;
  font-size: clamp(1.125rem, 1.7vw, 1.4rem);
}

.thread-message {
  margin-bottom: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.thread-message summary {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  background: #f6f8fa;
  border-radius: 5px;
  cursor: pointer;
  list-style: none;
}

.thread-message summary::-webkit-details-marker { display: none; }

.avatar {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #dce9f3;
  color: #254562;
  font-size: 0.8125rem;
  font-weight: 700;
}

.message-person {
  display: grid;
  gap: 0.15rem;
  font-size: 0.875rem;
}

.address { overflow-wrap: anywhere; }

.address, .thread-message time, .recipient {
  font-size: 0.8125rem;
  color: var(--muted);
}

.thread-message time { text-align: right; }

.message-content {
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.body {
  margin-top: 1rem;
  white-space: pre-line;
  line-height: 1.6;
}

.attachments:not(:empty) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.4rem;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid #bfcfdb;
  border-radius: 4px;
  color: #154b73;
  font-size: 0.875rem;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.attachment:hover { background: var(--selection); text-decoration: underline; }

.file-type {
  padding: 0.12rem 0.22rem;
  border-radius: 2px;
  background: #f2e7e6;
  color: #812c29;
  font-size: 0.75rem;
  font-weight: 700;
}

:focus-visible { outline: 2px solid #236eaa; outline-offset: 2px; }
.message:focus-visible { outline-offset: -2px; }

@media (max-width: 1080px) {
  .mailbox { grid-template-columns: 10rem minmax(17rem, 31vw) minmax(0, 1fr); }
  .thread-message summary { grid-template-columns: 2rem minmax(0, 1fr); }
  .thread-message time { grid-column: 2; text-align: left; }
}

@media (min-width: 801px) {
  .app-header { height: 3.75rem; }
  .mailbox { height: calc(100vh - 3.75rem); }
  .mail-list, .reading-pane { min-height: 0; overflow: auto; }
  .list-header { position: sticky; top: 0; z-index: 1; }
}

@media (max-width: 800px) {
  .app-header { align-items: flex-start; flex-direction: column; gap: 0.6rem; }
  .search-box input { width: min(50vw, 22rem); min-width: 0; }
  .mailbox { grid-template-columns: minmax(0, 1fr); }
  .mailbox-sidebar { display: none; }
  .mail-list { max-height: 42vh; overflow: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .reading-pane { min-height: 50vh; }
}
