:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eaeef1;
  --hover: #e4e9ec;
  --border: #dde3e7;
  --text: #1c2326;
  --muted: #5f6b70;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d3ebe8;
  --accent-text: #0b5a54;
  --danger: #b42318;
  --star: #d99a00;
  --unread-bg: #ffffff;
  --read-bg: #f3f6f8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 2px 6px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 28px rgba(16, 24, 40, .2);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101315;
    --surface: #191e21;
    --surface-2: #232a2e;
    --hover: #2a3236;
    --border: #2f383d;
    --text: #e5eaec;
    --muted: #98a4a9;
    --accent: #5fb9ae;
    --accent-ink: #062320;
    --accent-soft: #1e3d39;
    --accent-text: #93d8cf;
    --danger: #f97066;
    --star: #f2c14e;
    --unread-bg: #20272a;
    --read-bg: #191e21;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
.muted { color: var(--muted); }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 9px 24px;
  font-weight: 600;
  background: var(--surface-2);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: var(--shadow); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.outline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: transparent;
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn.outline:hover { background: var(--hover); }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  text-decoration: none;
  flex: none;
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small .icon { width: 18px; height: 18px; }

.link { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; }
.link:hover { color: var(--text); text-decoration: underline; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  white-space: nowrap;
}
.brand .brand-mark { width: 34px; height: 34px; font-size: 19px; border-radius: 10px; }
.brand b { font-weight: 700; }
.brand > span:not(.brand-mark) { color: var(--muted); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  flex: none;
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar.lg { width: 40px; height: 40px; font-size: 17px; }
.avatar.xl { width: 76px; height: 76px; font-size: 32px; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 8px;
}
.topbar .spacer { flex: 1; }

.account { position: relative; }
.account > button {
  border: 0;
  background: transparent;
  padding: 4px;
  border-radius: 50%;
  display: grid;
}
.account > button:hover { background: var(--hover); }
.menu {
  position: absolute;
  right: 0;
  top: 48px;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 18px 20px 22px;
  text-align: center;
  z-index: 50;
}
.menu .email { color: var(--muted); margin-bottom: 16px; font-weight: 500; }
.menu .name { font-size: 20px; margin: 12px 0 4px; }
.menu .btn { margin-top: 16px; width: 100%; justify-content: center; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 448px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 40px 36px 32px;
}
.login-card h1 { font-size: 28px; font-weight: 500; margin: 22px 0 6px; }
.login-card .subtitle { margin: 0 0 28px; color: var(--muted); }
.field { position: relative; display: block; margin-bottom: 12px; }
.field input {
  width: 100%;
  height: 56px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  padding: 20px 14px 6px;
  outline: none;
  font-size: 16px;
}
.field.with-suffix input { padding-right: 150px; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.field span {
  position: absolute;
  left: 15px;
  top: 17px;
  color: var(--muted);
  pointer-events: none;
  font-size: 16px;
  transition: top .15s, font-size .15s, color .15s;
}
.field input:focus + span,
.field input:not(:placeholder-shown) + span { top: 6px; font-size: 12px; }
.field input:focus + span { color: var(--accent-text); }
.field .suffix {
  position: absolute;
  right: 14px;
  top: 25px;
  color: var(--muted);
  font-style: normal;
  font-size: 16px;
  pointer-events: none;
}
.check {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  user-select: none;
  margin-top: 4px;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 14px 3px 3px;
  background: transparent;
  margin: -12px 0 24px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover { background: var(--hover); }
.error {
  color: var(--danger);
  margin: 8px 0 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.error .icon { width: 18px; height: 18px; }
.login-actions { display: flex; justify-content: flex-end; margin-top: 32px; }

.home { min-height: 100%; display: flex; flex-direction: column; }
.launcher {
  width: 100%;
  max-width: 760px;
  margin: 8vh auto 40px;
  padding: 0 20px;
  text-align: center;
}
.launcher h1 { font-size: 34px; font-weight: 500; margin: 0 0 8px; }
.apps {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-top: 44px;
}
.app {
  position: relative;
  width: 168px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 12px 22px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: transform .12s, box-shadow .12s;
}
.app:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.app-icon {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff;
}
.app-icon .icon { width: 30px; height: 30px; }
.app .badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
}
.app small { color: var(--muted); font-weight: 400; margin-top: -8px; }

.mail-app { overflow: hidden; }
.mail-app .brand { min-width: 216px; margin-left: 4px; }
.search {
  flex: 1;
  min-width: 0;
  max-width: 720px;
  height: 48px;
  background: var(--surface-2);
  border-radius: 999px;
  display: flex;
  align-items: center;
  padding: 0 4px;
  transition: background .15s, box-shadow .15s;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 16px;
  padding: 0 6px;
}
.search input::-webkit-search-cancel-button { display: none; }

.layout { display: flex; height: calc(100% - 64px); }
.sidebar {
  width: 256px;
  flex: none;
  padding: 8px 12px 16px 0;
  overflow-y: auto;
}
.compose-btn {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  height: 56px;
  padding: 0 26px 0 18px;
  margin: 0 0 16px 8px;
  border: 0;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
  transition: box-shadow .15s;
}
.compose-btn:hover { box-shadow: var(--shadow); }
.folders { list-style: none; margin: 0; padding: 0; }
.folder {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 34px;
  padding: 0 14px 0 26px;
  border-radius: 0 999px 999px 0;
  color: var(--text);
  text-decoration: none;
}
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.folder span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder b { font-size: 12px; font-weight: 700; }
.nav-collapsed .sidebar { width: 80px; }
.nav-collapsed .compose-btn { padding: 0 16px; }
.nav-collapsed .compose-btn span,
.nav-collapsed .folder span,
.nav-collapsed .folder b { display: none; }
.nav-collapsed .folder { padding-left: 30px; }

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  margin-right: 16px;
  overflow: hidden;
}
.toolbar {
  height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
}
.toolbar .spacer { flex: 1; }
.toolbar .count { color: var(--muted); font-size: 12px; margin-right: 6px; white-space: nowrap; }
.toolbar .view-label { font-weight: 600; margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list-wrap { flex: 1; overflow-y: auto; }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 16px 0 10px;
  border-bottom: 1px solid var(--border);
  background: var(--read-bg);
  cursor: pointer;
}
.row.unread { background: var(--unread-bg); font-weight: 700; }
.row:hover { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 1px 4px rgba(16, 24, 40, .18); z-index: 1; }
.star {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 0;
  flex: none;
}
.star:hover { background: var(--hover); }
.star.on { color: var(--star); }
.star.on .icon { fill: currentColor; }
.row .sender { width: 200px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .snippet { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .preview { color: var(--muted); font-weight: 400; }
.row .clip { color: var(--muted); display: grid; }
.row .clip .icon { width: 16px; height: 16px; }
.row time { flex: none; min-width: 56px; text-align: right; font-size: 12px; }
.row:not(.unread) time { color: var(--muted); }
.row-actions {
  position: absolute;
  right: 10px;
  display: none;
  gap: 2px;
  padding-left: 8px;
  background: inherit;
}
.row:hover .row-actions { display: flex; }
.row:hover time { visibility: hidden; }

.empty, .loading { list-style: none; text-align: center; color: var(--muted); padding: 72px 16px; }
.empty .icon { width: 48px; height: 48px; stroke-width: 1.2; margin-bottom: 10px; }

.reader { flex: 1; overflow-y: auto; padding: 20px 28px 48px 76px; }
.reader h1 { font-size: 22px; font-weight: 400; margin: 4px 0 22px; overflow-wrap: anywhere; }
.msg-head { display: flex; gap: 14px; align-items: flex-start; margin-left: -56px; }
.msg-head .who { flex: 1; min-width: 0; }
.msg-head .who strong { font-weight: 700; }
.msg-head .addr { color: var(--muted); font-size: 12px; }
.msg-head .to { font-size: 12px; padding: 0; text-align: left; overflow-wrap: anywhere; }
.msg-head .meta { display: flex; align-items: center; gap: 2px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 14px;
  margin-top: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.details dt { text-align: right; }
.details dd { margin: 0; color: var(--text); }
.msg-body { margin-top: 22px; }
.message-frame {
  display: block;
  width: 100%;
  min-height: 80px;
  border: 0;
  border-radius: 8px;
  background: #fff;
}
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.attachment {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 280px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.attachment:hover { background: var(--hover); }
.attachment div { min-width: 0; }
.attachment span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment small { color: var(--muted); }
.reply-bar { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }

.compose {
  position: fixed;
  right: 24px;
  bottom: 0;
  z-index: 40;
  width: 560px;
  max-width: calc(100vw - 16px);
  height: min(600px, calc(100vh - 80px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.compose.min { width: 300px; height: 44px; }
.compose.min .compose-body,
.compose.min footer { display: none; }
.compose-head {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 0 16px;
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
}
.compose-head .icon-btn { width: 32px; height: 32px; }
.compose-head .icon-btn .icon { width: 18px; height: 18px; }
.compose-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 16px; }
.cfield { display: flex; align-items: center; gap: 8px; min-height: 40px; border-bottom: 1px solid var(--border); }
.cfield > label { color: var(--muted); }
.cfield input { flex: 1; min-width: 0; height: 38px; border: 0; outline: none; background: transparent; }
.compose textarea {
  flex: 1;
  min-height: 120px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  padding: 12px 0;
  line-height: 1.5;
}
.files {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 130px;
  overflow-y: auto;
}
.files li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 3px 3px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 13px;
}
.files li .icon { width: 16px; height: 16px; color: var(--muted); }
.files li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files li small { color: var(--muted); }
.compose footer { display: flex; align-items: center; gap: 6px; padding: 10px 14px 14px 16px; flex: none; }
.compose footer .spacer { flex: 1; }
.compose footer label.icon-btn { cursor: pointer; }

.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 48px);
  padding: 12px 12px 12px 20px;
  border-radius: 8px;
  background: #283034;
  color: #eef2f3;
  box-shadow: var(--shadow-lg);
}
.toast button { border: 0; background: transparent; color: #8fd6cc; font-weight: 700; padding: 4px 8px; }

.scrim { display: none; }

@media (max-width: 860px) {
  .mail-app .brand,
  .mail-app .topbar .spacer { display: none; }
  .mail-app .topbar { gap: 4px; padding-right: 8px; }
  .sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 30;
    background: var(--bg);
    box-shadow: var(--shadow-lg);
    transform: translateX(-105%);
    transition: transform .2s;
  }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 64px 0 0; z-index: 25; background: rgba(0, 0, 0, .35); }
  .content { margin: 0; border-radius: 0; }
  .row {
    height: auto;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 2px;
    padding: 10px 12px 10px 6px;
  }
  .row .sender { width: auto; flex: 1; }
  .row .snippet {
    order: 3;
    flex-basis: 100%;
    padding-left: 42px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .row:hover .row-actions { display: none; }
  .row:hover time { visibility: visible; }
  .reader { padding: 16px 16px 40px; }
  .msg-head { margin-left: 0; }
  .compose { right: 0; width: 100%; max-width: 100%; height: calc(100% - 56px); border-radius: 14px 14px 0 0; }
  .toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
}
