:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --pane: #ffffff;
  --pane-alt: #f8fafb;
  --ink: #202427;
  --muted: #68747d;
  --line: #d9e0e5;
  --accent: #0f6cbd;
  --accent-2: #0a5ca8;
  --green: #157347;
  --amber: #a85d00;
  --shadow: 0 16px 38px rgba(18, 31, 43, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.mail-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.folder-pane {
  min-height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #eef3f7;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.muted,
.message-preview,
.message-time,
.message-meta,
.sender-row span,
label,
.account-card span,
.account-card small,
.dialog-subtitle,
.shared-address-strip span,
.sent-summary span,
.mailbox-note p {
  color: var(--muted);
}

.compose-button,
.primary,
.secondary,
.icon-button,
.segment,
.folder,
select {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--pane);
  color: var(--ink);
}

.compose-button {
  width: 100%;
  margin-bottom: 12px;
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 800;
}

.account-card {
  display: grid;
  gap: 3px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.account-card span,
.account-card small,
.dialog-subtitle {
  font-size: 0.84rem;
}

.account-card strong {
  line-height: 1.2;
}

.folders {
  display: grid;
  gap: 6px;
}

.folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  text-align: left;
}

.folder.active,
.folder:hover {
  border-color: #b6cce0;
  background: #dcecfb;
}

.folder strong {
  min-width: 26px;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--accent-2);
  background: #ffffff;
  text-align: center;
  font-size: 0.82rem;
}

.mailbox-note {
  margin-top: 22px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
}

.mailbox-note p {
  margin: 8px 0 0;
  line-height: 1.45;
}

.mail-main {
  min-width: 0;
  padding: 20px;
}

.mail-header,
.mail-toolbar,
.message-top,
.sender-row,
.control-row,
.reply-actions,
.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.12;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
}

.search-box {
  width: min(420px, 46vw);
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.mail-toolbar {
  margin: 18px 0 12px;
}

.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane);
}

.segment {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  background: transparent;
}

.segment.active {
  color: #ffffff;
  background: var(--accent);
}

select {
  padding: 0 12px;
}

.mail-layout {
  height: calc(100vh - 136px);
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 14px;
}

.message-list,
.reading-pane {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane);
  box-shadow: var(--shadow);
}

.message-list {
  display: grid;
  align-content: start;
}

.message-card {
  width: 100%;
  display: grid;
  gap: 7px;
  padding: 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--pane);
  color: var(--ink);
  text-align: left;
}

.message-card:hover,
.message-card.active {
  background: #eef6ff;
}

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

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

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

.message-meta {
  font-size: 0.84rem;
}

.reading-pane {
  padding: 22px;
}

.message-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 40px;
  flex: 0 0 40px;
  font-size: 1.1rem;
}

.icon-button.flagged {
  color: #ffffff;
  border-color: var(--amber);
  background: var(--amber);
}

.sender-row {
  margin: 16px 0;
  align-items: flex-start;
}

.sender-row strong,
.sender-row span {
  display: block;
}

.control-row,
.sent-summary {
  align-items: end;
  flex-wrap: wrap;
  padding: 14px;
  border-radius: 8px;
  background: var(--pane-alt);
}

.sent-summary {
  display: grid;
  gap: 4px;
  align-items: start;
}

.shared-address-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #c6d8ea;
  border-radius: 8px;
  background: #eef6ff;
}

.shared-address-strip span {
  text-align: right;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.control-row label {
  flex: 1 1 160px;
}

.primary,
.secondary {
  padding: 0 16px;
  font-weight: 800;
}

.primary {
  color: #ffffff;
  border-color: var(--green);
  background: var(--green);
}

.email-body {
  margin: 20px 0;
  line-height: 1.6;
  max-width: 780px;
}

.email-body p {
  margin: 0 0 12px;
}

.thread-history {
  display: grid;
  gap: 12px;
  margin: 20px 0;
}

.thread-message {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.thread-message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.thread-message > span,
.thread-message-head span {
  color: var(--muted);
  font-size: 0.9rem;
}

.thread-message .email-body {
  margin-bottom: 0;
}

.notes {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.note {
  padding: 12px;
  border-radius: 8px;
  background: #eef3f7;
}

.note p {
  margin: 0 0 8px;
}

.note span {
  color: var(--muted);
  font-size: 0.86rem;
}

.reply-box {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.thread-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.7fr);
  gap: 14px;
  margin-top: 16px;
}

.thread-actions .reply-box {
  margin-top: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane-alt);
}

input,
textarea,
label select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.empty-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.compose-dialog {
  width: min(620px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.22);
}

.compose-dialog::backdrop {
  background: rgba(20, 28, 35, 0.32);
}

.compose-dialog form {
  padding: 18px;
}

.dialog-actions {
  margin-top: 16px;
}

.dialog-subtitle {
  margin: 4px 0 0;
}

@media (max-width: 980px) {
  .mail-shell {
    grid-template-columns: 1fr;
  }

  .folder-pane {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .folders {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .mailbox-note {
    display: none;
  }

  .mail-header,
  .mail-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }

  .mail-layout {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .message-list,
  .reading-pane {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .mail-main {
    padding: 14px;
  }

  .folders {
    grid-template-columns: 1fr 1fr;
  }

  .segmented {
    overflow-x: auto;
  }

  .sender-row,
  .shared-address-strip,
  .thread-actions,
  .reply-actions,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .thread-actions {
    display: flex;
  }

  .shared-address-strip span {
    text-align: left;
  }
}
