/* Signed-in workspace */
#app-view {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  color: var(--text);
  background: var(--page);
  overflow: hidden;
}
#app-view[hidden], #reader-detail[hidden], #reader-empty[hidden], #toast[hidden] { display: none; }
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
  min-height: 65px;
  padding: 8px clamp(20px, 2.2vw, 42px);
  border-bottom: 1px solid var(--line);
}
.app-header .brand { flex: none; }
.account {
  min-width: 0;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: .88rem;
}
.account .icon { width: 16px; height: 16px; }
#account-email { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.icon-button {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 39px;
  height: 39px;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
}
.icon-button .icon { width: 18px; height: 18px; }
.icon-button:hover:enabled, .secondary:hover:enabled, .attach-input:hover {
  color: var(--text);
  background: var(--input);
}
.icon-button:disabled, .secondary:disabled { opacity: .38; cursor: default; }
.mobile-nav, .mobile-drawer-head, .folders-scrim { display: none; }
.mail-layout {
  flex: 1;
  display: grid;
  grid-template-columns: clamp(178px, 15vw, 242px) minmax(265px, .82fr) minmax(320px, 1.18fr);
  min-height: 0;
}
.mail-nav {
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 25px clamp(13px, 1.3vw, 23px);
  border-right: 1px solid var(--line);
  background: var(--page);
}
.compose-open {
  width: 100%;
  min-height: 45px;
  justify-content: flex-start;
  padding-inline: 14px;
}
.compose-open .icon { width: 17px; height: 17px; }
.nav-title {
  margin: 37px 0 0;
  padding: 0 2px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .84rem;
  font-weight: 500;
}
#folder-list { display: grid; padding-top: 6px; }
.folder-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 40px;
  margin: 0;
  padding: 9px 10px;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: .93rem;
  font-weight: 470;
  line-height: 1.3;
  text-align: left;
}
.folder-item:hover { color: var(--text); background: var(--surface); }
.folder-item[aria-current=page] { background: var(--surface); color: var(--text); font-weight: 650; }
.folder-item[aria-current=page]::before, .message-row.is-active::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--red);
  pointer-events: none;
}
.folder-item .icon { width: 16px; height: 16px; }
.folder-item[aria-current=page] .icon { color: var(--red-soft); }
.folder-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Message index */
.list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.list-header { padding: 22px clamp(15px, 1.6vw, 28px) 0; border-bottom: 1px solid var(--line); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 15px; }
.section-title h1 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--sans);
  font-size: clamp(1.7rem, 2.2vw, 2.2rem);
  font-weight: 550;
  line-height: 1.1;
  letter-spacing: -.04em;
}
.section-title .icon-button { margin-right: -6px; }
.search-control { position: relative; display: block; }
.search-control input {
  width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 43px 0 12px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: var(--page);
  font-size: 1rem;
}
.search-control .input-action {
  position: absolute;
  inset: 1px 1px 1px auto;
  display: grid;
  place-items: center;
  width: 39px;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
}
.search-control .input-action:hover { color: var(--text); }
.search-control .icon { width: 17px; height: 17px; }
.filters { display: flex; flex-wrap: wrap; gap: 17px; margin-top: 6px; }
.filters button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 500;
}
.filters button:hover { color: var(--text); }
.filters button[aria-pressed=true] { border-bottom-color: var(--red); color: var(--text); }
.filters .icon { width: 15px; height: 15px; }
.filters button[aria-pressed=true] .icon { color: var(--red-soft); }
.list-status, .pagination {
  color: var(--muted);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}
.list-status { margin: 0; padding: 10px clamp(15px, 1.6vw, 28px); border-bottom: 1px solid var(--line); }
.list-status:empty { display: none; }
.message-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.message-row {
  position: relative;
  display: flex;
  align-items: stretch;
  min-width: 0;
  border-bottom: 1px solid var(--line);
}
.message-row:hover, .message-row.is-active { background: var(--input); }
.message-open {
  display: grid;
  align-content: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  min-height: 75px;
  padding: 12px 0 13px clamp(15px, 1.6vw, 28px);
  border: 0;
  border-radius: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
}
.message-first { display: flex; align-items: baseline; justify-content: space-between; gap: 7px; min-width: 0; }
.message-sender, .message-subject, .message-date, .message-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-sender { font-size: .9rem; font-weight: 470; color: var(--muted); }
.message-date { flex: none; color: var(--muted); font-size: .76rem; font-variant-numeric: tabular-nums; }
.message-subject { font-size: .98rem; line-height: 1.35; }
.message-preview { color: var(--muted); font-size: .84rem; line-height: 1.4; }
.is-unread .message-sender, .is-unread .message-subject { color: var(--text); font-weight: 680; }
.is-unread .message-sender::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 6px;
  vertical-align: .14em;
  background: var(--red);
}
.message-star {
  display: grid;
  place-items: center;
  flex: none;
  width: 37px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}
.message-star .icon { width: 16px; height: 16px; }
.message-star:hover, .message-star[aria-pressed=true], #reader-star[aria-pressed=true] { color: var(--red-soft); }
.message-star[aria-pressed=true] .icon, #reader-star[aria-pressed=true] .icon { fill: currentColor; }
.list-state { padding: 22px clamp(15px, 1.6vw, 28px); color: var(--muted); font-size: .93rem; line-height: 1.5; }
.list-state p { margin: 0; }
.list-state button { margin-top: 10px; padding: 7px 0; border: 0; background: transparent; color: var(--text); text-decoration: underline; text-underline-offset: 4px; }
.pagination { display: flex; align-items: center; gap: 2px; min-height: 48px; padding: 3px 8px 3px clamp(15px, 1.6vw, 28px); border-top: 1px solid var(--line); }
#page-info { margin-right: auto; }

/* Reading view */
#reader { min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 20px;
  text-align: center;
}
.reader-empty h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(1.5rem, 2.2vw, 2.45rem);
  font-weight: 550;
  letter-spacing: -.035em;
}
.reader-tools {
  display: flex;
  align-items: center;
  min-height: 57px;
  padding: 7px clamp(16px, 2.4vw, 42px);
  border-bottom: 1px solid var(--line);
}
.reader-flags { display: flex; align-items: center; margin-left: auto; }
.reader-content { max-width: 850px; margin-inline: auto; padding: clamp(26px, 3.2vw, 60px) clamp(20px, 3.1vw, 58px) 48px; }
#reader-title {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  font-size: clamp(1.95rem, 3.25vw, 3.9rem);
  line-height: 1.07;
  letter-spacing: -.038em;
  overflow-wrap: anywhere;
}
.reader-meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 16px;
  margin: 24px 0;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  font-size: .91rem;
  line-height: 1.5;
}
.reader-meta dt { color: var(--muted); }
.reader-meta dd { margin: 0; overflow-wrap: anywhere; }
#reader-date { font-variant-numeric: tabular-nums; }
#reader-body { color: var(--text); font-size: 1rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments { display: flex; align-items: flex-start; flex-direction: column; gap: 5px; }
.attachments:not(:empty) { margin-top: 20px; }
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 34px;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.5;
}
a.attachment { color: var(--text); text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 4px; }
a.attachment:hover { text-decoration-color: var(--red); }
.remove-attachment { padding: 4px 8px; border: 0; color: var(--muted); background: var(--input); }
.remove-attachment:hover { color: var(--text); }
.reader-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 31px; padding-top: 16px; border-top: 1px solid var(--line); }
.secondary, .attach-input {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 41px;
  padding: 7px 11px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: .91rem;
  font-weight: 540;
}
.reader-actions .secondary:first-child { margin-left: -10px; }
.secondary .icon, .attach-input .icon, .compose-footer .primary .icon { width: 17px; height: 17px; }

/* Composer */
#compose-dialog {
  width: min(660px, calc(100vw - 36px));
  max-width: 100%;
  max-height: calc(100vh - 42px);
  max-height: calc(100dvh - 42px);
  padding: 0;
  border: 1px solid var(--line);
  border-top: 3px solid var(--red);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}
#compose-dialog::backdrop { background: #070604b8; }
#compose-form { display: flex; flex-direction: column; }
.compose-header, .compose-footer {
  display: flex;
  flex: none;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 16px clamp(18px, 3vw, 32px);
}
.compose-header { border-bottom: 1px solid var(--line); }
.compose-header h2 { margin: 0; font-family: var(--sans); font-size: clamp(1.6rem, 3.4vw, 2.2rem); font-weight: 550; line-height: 1.15; letter-spacing: -.03em; }
.compose-fields { padding: 4px clamp(18px, 3vw, 32px) 16px; }
.compose-line { display: flex; align-items: center; gap: 12px; min-height: 45px; border-bottom: 1px solid var(--line); }
.compose-line > span { flex: none; min-width: 3.25rem; color: var(--muted); font-size: .9rem; }
.compose-line input, #compose-body {
  width: 100%;
  min-width: 0;
  padding: 7px 3px;
  border: 0;
  border-radius: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
}
.compose-line input { min-height: 40px; }
.compose-line input::placeholder, #compose-body::placeholder, .search-control input::placeholder { opacity: 1; color: var(--muted); }
.copy-fields summary { display: inline-flex; align-items: center; min-height: 35px; color: var(--muted); font-size: .83rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.copy-fields summary:hover { color: var(--text); }
#compose-body { display: block; min-height: 150px; margin-top: 10px; line-height: 1.65; resize: vertical; }
#compose-error:not([hidden]) { margin-top: 10px; }
.compose-footer { border-top: 1px solid var(--line); }
.compose-footer .primary { min-height: 43px; }
.attach-input { position: relative; margin-left: -10px; overflow: hidden; cursor: pointer; }
.attach-input input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.attach-input:focus-within { outline: 2px solid var(--red-soft); outline-offset: 2px; }
.toast {
  position: fixed;
  z-index: 20;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(460px, calc(100% - 32px));
  padding: 13px 17px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  background: var(--input);
  font-size: .94rem;
  line-height: 1.5;
}
.toast:empty { display: none; }
#app-view :is(button,input):focus-visible, #compose-dialog :is(button,input,textarea,summary):focus-visible {
  outline: 2px solid var(--red-soft);
  outline-offset: -2px;
}

@media (max-width: 940px) {
  .app-header { gap: 10px; min-height: 58px; padding: 6px 14px; }
  .mobile-nav { display: inline-grid; }
  .mail-layout { position: relative; grid-template-columns: minmax(255px, .78fr) minmax(320px, 1fr); }
  .mail-nav {
    display: none;
    position: absolute;
    z-index: 6;
    inset: 0 auto 0 0;
    width: min(288px, 83%);
    padding: 12px 17px;
  }
  .mobile-drawer-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 14px; }
  .mobile-drawer-head b { font-family: var(--sans); font-size: 1.4rem; font-weight: 550; }
  .folders-scrim { position: absolute; z-index: 5; inset: 0; padding: 0; border: 0; background: #090806b3; }
  #app-view[data-mobile-pane=folders] .mail-nav, #app-view[data-mobile-pane=folders] .folders-scrim { display: block; }
}
@media (max-width: 710px) {
  .app-header { gap: 7px; padding-inline: 8px; }
  .app-header .brand { font-size: 1.75rem; }
  .account { gap: 0; font-size: .8rem; }
  .account .icon { display: none; }
  .mail-layout { display: block; }
  .list-pane, #reader { height: 100%; }
  .list-pane { border-right: 0; }
  .list-header { padding: 15px 17px 0; }
  .section-title { margin-bottom: 10px; }
  .message-open { min-height: 77px; padding-left: 17px; }
  .message-star, .icon-button { width: 44px; }
  .filters button { min-height: 43px; }
  .folder-item { min-height: 43px; }
  #reader { display: none; }
  #app-view[data-mobile-pane=reader] #reader { display: block; }
  #app-view[data-mobile-pane=reader] .list-pane { display: none; }
  .reader-tools { min-height: 49px; padding: 3px 9px; }
  .reader-content { padding: 24px 20px 36px; }
  .reader-meta { margin-block: 18px; padding-bottom: 18px; }
  #compose-dialog { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
  .compose-header, .compose-footer { padding-block: 11px; }
}
@media (prefers-reduced-motion: no-preference) {
  #compose-dialog[open], .toast:not(:empty) { animation: mail-appear .14s ease-out; }
  @keyframes mail-appear { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
}
