:root {
  color-scheme: light;
  --ink: #111d42;
  --muted: #6b7280;
  --sidebar: #f3f4f6;
  --list: #fafafc;
  --paper: #ffffff;
  --line: #e5e7eb;
  --accent: #111d42;
  --unread: #2563eb;
  --selected: #e0e7ff;
  --hover: #eef0f4;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-family: "Plus Jakarta Sans", Inter, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 220px 360px minmax(0, 1fr);
}

.folders {
  background: var(--sidebar);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  padding: 16px 16px 8px;
}

.logo {
  display: block;
  width: 148px;
  height: auto;
}

.account {
  margin: 8px 0 0;
  padding: 0 16px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sign-out {
  margin: 4px 16px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}

.sign-out .folder-icon {
  display: none;
}

.sign-out[hidden] {
  display: none;
}

.sign-out:hover {
  color: var(--ink);
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--list);
}

.gate[hidden] {
  display: none;
}

.login {
  width: min(400px, 100%);
  display: grid;
  gap: 16px;
  padding: 32px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.login .logo {
  width: 180px;
}

.login-lead {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.login .banner {
  margin: 0;
}

.app[hidden] {
  display: none;
}

.compose {
  margin: 8px 16px 12px;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.compose:hover {
  background: #1a2b5c;
}

.inbox-jump,
.menu-toggle {
  display: none;
}

.folder-menu {
  display: contents;
}

@media (min-width: 901px) {
  .brand { order: 1; }
  .account { order: 2; }
  .sign-out { order: 3; }
  .compose { order: 4; }
  #folder-list { order: 5; }
}

.menu-icon {
  width: 18px;
  height: 18px;
}

.menu-close {
  display: none;
}

#folder-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  overflow: auto;
}

.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.folder-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.folder:hover {
  background: #e7e9ee;
}

.folder[aria-current="true"] {
  background: #fff;
  box-shadow: var(--shadow);
}

.folder.is-key {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.app.keys-folders .folders {
  box-shadow: inset -2px 0 0 var(--accent);
}

.app.keys-message .read-pane,
.app.keys-reply .read-pane {
  box-shadow: inset 2px 0 0 var(--accent);
}

.list-pane,
.read-pane {
  min-height: 0;
  min-width: 0;
}

.list-pane {
  background: var(--list);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
}

.list-head h1,
.count,
.banner,
.empty,
.empty-read p,
.subject,
.meta,
.people,
.attachments {
  margin: 0;
}

.list-head h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.count,
.meta,
.people,
.attachment-size,
.loading {
  color: var(--muted);
  font-size: 13px;
}

.refresh,
.back,
.reply,
.action {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.refresh:hover,
.back:hover,
.reply:hover,
.action:hover {
  background: var(--hover);
}

.banner {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #eef2ff;
  color: var(--ink);
  font-size: 13px;
}

.message-list {
  overflow: auto;
  flex: 1;
  padding: 8px;
  scroll-padding: 8px;
}

.message-row {
  display: flex;
  align-items: stretch;
  margin-bottom: 2px;
  border-radius: 8px;
  padding-left: calc(var(--depth, 0) * 16px);
}

.message-row:hover {
  background: var(--hover);
}

.message-row:has(.message[aria-current="true"]),
.message-row.is-cursor:has(.message[aria-current="true"]) {
  background: var(--selected);
}

.message-row.is-selected,
.message-row.is-selected:hover {
  background: var(--selected);
  box-shadow: inset 2px 0 0 var(--accent);
}

.message-row.is-cursor {
  box-shadow: inset 2px 0 0 var(--accent);
}

.message:focus,
.twist:focus {
  outline: none;
}

.message-row:focus-within {
  outline: 2px solid var(--unread);
  outline-offset: 0;
}

.twist,
.branch {
  flex: 0 0 20px;
  display: inline-flex;
  align-items: flex-start;
  justify-content: center;
  margin: 12px 0 0 6px;
  color: var(--muted);
}

.twist {
  width: 20px;
  height: 20px;
  margin-top: 6px;
  align-items: center;
  border: 0;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.twist:hover {
  color: var(--ink);
}

.twist-icon,
.branch-icon {
  width: 14px;
  height: 14px;
}

.message {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 2px 8px;
  width: auto;
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 8px 8px 4px;
  cursor: pointer;
  border-radius: 8px;
}

.message:hover,
.message[aria-current="true"],
.message.is-selected,
.message.is-selected:hover {
  background: transparent;
}

.dot {
  width: 7px;
  height: 7px;
  margin-top: 5px;
  border-radius: 50%;
  background: transparent;
}

.message.unread .dot {
  background: var(--unread);
}

.message.unread .from,
.message.unread .subject {
  font-weight: 600;
}

.from,
.subject,
.when {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.from {
  grid-column: 2;
  font-size: 13px;
  font-weight: 600;
}

.when {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  grid-column: 3;
  min-width: max-content;
  overflow: visible;
  color: var(--muted);
  font-size: 12px;
}

.last-reply {
  color: var(--ink);
  font-weight: 600;
}

.last-reply::before {
  content: "·";
  margin-right: 6px;
  color: var(--muted);
  font-weight: 400;
}

.clip-wrap {
  display: inline-flex;
  color: var(--muted);
}

.clip {
  width: 14px;
  height: 14px;
}

.subject {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 450;
}

.message.unread .subject {
  color: var(--ink);
}

.empty,
.loading {
  padding: 24px 8px;
  color: var(--muted);
  font-size: 13px;
}

.read-pane {
  position: relative;
  overflow: auto;
  min-height: 0;
  background: var(--paper);
}

.read-pane:focus {
  outline: none;
}

.empty-read {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  color: var(--muted);
  font-size: 15px;
}

#reader-view:has(.empty-read) {
  height: 100%;
}

.summary {
  width: min(420px, 100%);
  margin-inline: auto;
  padding: 32px;
  text-align: center;
}

.empty-read .summary-count {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.empty-read .summary-detail {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.45;
}

.reader {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px;
}

.back {
  display: none;
}

.reader-tools .back {
  margin-bottom: 0;
}

.reader .subject {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--ink);
  white-space: normal;
  overflow: visible;
}

.reader .meta {
  margin-top: 8px;
}

.reader-tools {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 24px;
}

.reader-tools-start {
  display: flex;
  gap: 8px;
  align-items: center;
}

.danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.danger:hover {
  background: #fee2e2;
}

.danger:disabled,
.action:disabled,
.send:disabled {
  opacity: 0.55;
  cursor: default;
}

.icon {
  width: 16px;
  height: 16px;
}

.selection-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.summary > .banner {
  margin: 16px 0 0;
}

.summary > .back {
  position: absolute;
  top: 16px;
  left: 16px;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-row .subject {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.avatars {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.avatars[hidden] {
  display: none;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.people {
  margin-top: 16px;
  display: grid;
  gap: 4px;
  font-size: 14px;
}

.person strong {
  font-weight: 600;
}

.body {
  margin-top: 24px;
  line-height: 1.55;
  font-size: 15px;
}

.body pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 15px;
}

.body iframe {
  width: 100%;
  border: 0;
  min-height: 80px;
  background: white;
}

.body.can-reply {
  cursor: pointer;
}

.body.can-reply iframe {
  pointer-events: none;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--list);
  border-radius: 8px;
  padding: 6px 10px;
  color: inherit;
  font-size: 13px;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.attachment:hover {
  background: var(--hover);
}

.attachment.download-all {
  border: 0;
  background: var(--accent);
  color: #fff;
}

.attachment.download-all .attachment-size {
  color: #dbe1f0;
}

.compose-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compose-form[hidden],
#reader-view[hidden] {
  display: none;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field textarea {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.field textarea {
  min-height: 220px;
  resize: vertical;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
}

.message-field {
  flex: 1;
}

.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.attach-list:empty {
  display: none;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  border: 1px solid var(--line);
  background: var(--list);
  border-radius: 8px;
  padding: 6px 8px 6px 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.attach-remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.attach-remove:hover {
  color: var(--ink);
}

.attach-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.compose-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.send {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

@media (max-width: 900px) {
  .app {
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .folders {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
    position: relative;
    z-index: 3;
    padding: 8px 12px;
  }

  .brand {
    padding: 0;
    flex: 0 1 auto;
    min-width: 0;
  }

  .logo {
    width: 88px;
    max-width: 24vw;
  }

  .compose {
    margin: 0;
    padding: 6px 10px;
    flex: 0 0 auto;
  }

  .inbox-jump {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: var(--ink);
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
  }

  .inbox-jump[aria-current="true"] {
    background: #fff;
    box-shadow: var(--shadow);
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    margin-left: auto;
    border: 1px solid var(--line);
    background: var(--paper);
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
    box-shadow: var(--shadow);
  }

  .app.is-menu-open .menu-open {
    display: none;
  }

  .app.is-menu-open .menu-close {
    display: block;
  }

  .folder-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 2px;
    padding: 8px;
    background: var(--sidebar);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px rgba(17, 29, 66, 0.08);
  }

  .app.is-menu-open .folder-menu {
    display: flex;
  }

  .account {
    margin: 0;
    padding: 8px 8px 10px;
  }

  .sign-out:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin: 0;
    padding: 8px;
    border-radius: 8px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
  }

  .sign-out .folder-icon {
    display: block;
  }

  .sign-out:hover {
    background: #e7e9ee;
  }

  #folder-list {
    flex-direction: column;
    padding: 0;
    overflow: visible;
  }

  .folder {
    width: 100%;
  }

  .folder[data-use="other"] {
    display: none;
  }

  .folder[aria-current="true"] {
    box-shadow: var(--shadow);
  }

  .app:not(.is-reading) .read-pane {
    display: none;
  }

  .app.is-reading .folders,
  .app.is-reading .list-pane {
    display: none;
  }

  .app.is-reading {
    grid-template-rows: 1fr;
  }

  .reader-tools .back,
  .summary > .back {
    display: inline-flex;
  }

  .reader {
    padding: 16px 16px 40px;
  }

  .reader .subject {
    font-size: 22px;
  }
}
