:root {
  --ink: #17211b;
  --muted: #68756d;
  --line: #dce4de;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --accent: #176b45;
  --accent-soft: #e2f1e8;
  --warning: #a34d18;
  --warning-soft: #fff0e5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, #dceee2 0, transparent 34%),
    radial-gradient(circle at 85% 82%, #eee7d8 0, transparent 36%),
    var(--paper);
}

.login-card {
  width: min(420px, 100%);
  padding: 40px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 24px 70px rgb(32 52 40 / 12%);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}

h1, h2, h3 { margin-top: 0; }
.login-card h1 { margin-bottom: 8px; font-size: 34px; }
.muted { color: var(--muted); line-height: 1.6; }
label { display: block; margin: 24px 0 8px; font-size: 14px; font-weight: 700; }

input, select {
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid #bdc9c1;
  border-radius: 10px;
  color: var(--ink);
  background: white;
}

input:focus, select:focus, button:focus-visible {
  outline: 3px solid rgb(23 107 69 / 20%);
  outline-offset: 2px;
}

.login-card input { width: 100%; }
.login-card button, .search button {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  color: white;
  background: var(--accent);
  font-weight: 750;
}
.login-card button { width: 100%; margin-top: 14px; }
.error { min-height: 20px; color: #a42a2a; font-size: 14px; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: 12px 16px 16px;
  overflow: hidden;
}
.topbar {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 12px;
}
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.quiet {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: var(--panel);
}

.account-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 12px 2px;
}
.account-tab {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: max-content;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-align: left;
  background: var(--panel);
}
.account-tab span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.account-tab.selected {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 -2px var(--accent);
}

.metrics {
  display: flex;
  align-items: center;
  margin: 10px 12px;
  overflow-x: auto;
}
.metric {
  display: flex;
  flex: 0 0 auto;
  align-items: baseline;
  gap: 6px;
  padding: 0 16px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.metric:first-child { padding-left: 0; }
.metric:last-child { border-right: 0; }
.metric strong { font-size: 18px; line-height: 1.3; }
.metric span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.metric.warning { border-color: var(--line); background: transparent; }
.metric.warning strong { color: var(--warning); }

.toolbar {
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
}
.search {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 190px) auto;
  gap: 8px;
}
.search input { min-width: 0; width: 100%; }
.sync-state {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: clamp(440px, 38vw, 720px) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel);
}
.mail-column {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.mail-list-panel {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.mail-list { display: flex; flex-direction: column; }
.mail-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  padding: 16px 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  color: inherit;
  background: white;
}
.mail-row:hover, .mail-row.selected { background: #f0f6f2; }
.mail-row.selected { box-shadow: inset 4px 0 var(--accent); }
.mail-row-head, .mail-row-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.mail-row-head time, .mail-row-foot { color: var(--muted); font-size: 12px; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row-foot { justify-content: flex-start; }

.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  color: #526159;
  background: #edf1ee;
}
.status-sent { color: var(--accent); background: var(--accent-soft); }
.status-failed, .status-uncertain, .status-oversized {
  color: var(--warning);
  background: var(--warning-soft);
}
.load-more { display: block; margin: 14px auto; }
.empty-list { padding: 30px; color: var(--muted); text-align: center; }

.detail {
  min-width: 0;
  min-height: 0;
  padding: 28px 32px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.detail.empty, .detail.loading {
  display: grid;
  place-items: center;
  color: var(--muted);
}
.detail h2 { margin-bottom: 18px; font-size: 26px; line-height: 1.35; }
.detail-meta { display: grid; gap: 6px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-meta p { display: grid; grid-template-columns: 80px 1fr; gap: 12px; margin: 0; }
.detail-meta span { color: var(--muted); }
.message-body {
  margin: 24px 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-body.rich-text {
  white-space: normal;
}
.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text p { margin: 0 0 1em; }
.rich-text blockquote {
  margin: 1em 0;
  padding-inline-start: 16px;
  border-inline-start: 1px solid var(--line);
  color: var(--muted);
}
.rich-text pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
}
.rich-text a { color: var(--accent); overflow-wrap: anywhere; }
.rich-text table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
}
.rich-text th, .rich-text td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
}
.email-image-alt {
  color: var(--muted);
  font-size: 13px;
}
.attachments { display: grid; gap: 8px; padding-top: 18px; border-top: 1px solid var(--line); }
.attachments h3 { margin-bottom: 4px; }
.attachments a { color: var(--accent); }

@media (max-width: 900px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 18px;
    overflow: visible;
  }
  .topbar { margin-bottom: 12px; }
  .sync-state { white-space: normal; }
  .metrics {
    display: flex;
    flex-wrap: wrap;
    row-gap: 6px;
    margin: 10px 0;
  }
  .metric {
    align-items: baseline;
    flex-direction: row;
    gap: 5px;
    padding: 0 10px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
  }
  .metric:first-child { padding-left: 0; }
  .metric:last-child { border-right: 0; }
  .metric.warning { border-color: var(--line); background: transparent; }
  .account-tab { min-width: max-content; }
  .search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: stretch;
  }
  .search input { grid-column: 1 / -1; width: 100%; }
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  .mail-column { border-right: 0; }
  .mail-list-panel {
    overflow-y: visible;
    scrollbar-gutter: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .detail { min-height: 440px; padding: 22px; }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .workspace { grid-template-columns: clamp(400px, 43vw, 500px) minmax(0, 1fr); }
  .search { grid-template-columns: minmax(0, 1fr) auto; }
  .search input { grid-column: 1 / -1; }
}

@media (min-width: 901px) and (max-height: 760px) {
  .app-shell { padding-block: 8px 12px; }
  .account-tabs { padding-top: 8px; }
  .metrics { margin-block: 7px; }
  .toolbar { padding-bottom: 8px; }
}
