:root {
  --bg: #f5f2ed;
  --panel: #fffaf2;
  --surface: #ffffff;
  --ink: #151515;
  --muted: #706a63;
  --line: rgba(20, 20, 20, .1);
  --accent: #245f63;
  --danger: #9a3158;
  --shadow: 0 20px 54px rgba(20, 24, 28, .12);
  --sidebar: 280px;
  --list: 390px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html.sidebar-collapsed { --sidebar: 0px; }
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.login-page {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 26px;
  padding: 24px;
}
.login-logo {
  width: 132px;
  height: 132px;
  justify-self: center;
  border-radius: 32px;
  box-shadow: 0 18px 46px rgba(0,0,0,.16);
}
.login-card {
  width: min(420px, calc(100vw - 40px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.88);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 {
  margin: 0 0 22px;
  font-size: 30px;
}
.login-card label {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  font-weight: 750;
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  padding: 12px 14px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, textarea:focus {
  border-color: rgba(36, 95, 99, .56);
  box-shadow: 0 0 0 4px rgba(36, 95, 99, .12);
}
.login-card button,
.compose-button,
.composer > button {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  padding: 13px 16px;
  font-weight: 850;
  transition: background .16s ease, transform .16s ease;
}
.login-card button:hover,
.compose-button:hover,
.composer > button:hover {
  background: #000;
  transform: translateY(-1px);
}
.mail-app {
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) var(--list) minmax(0, 1fr);
  overflow: hidden;
  transition: grid-template-columns .24s ease;
}
.mobile-topbar,
.drawer-backdrop,
.drawer-close,
.back-link { display: none; }
.sidebar-toggle {
  position: fixed;
  top: 50%;
  left: max(8px, calc(var(--sidebar) - 14px));
  z-index: 20;
  width: 28px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(0,0,0,.14);
  color: var(--ink);
  font-size: 23px;
  line-height: 1;
  transform: translateY(-50%) rotate(180deg);
  transition: left .24s ease, transform .24s ease;
}
html.sidebar-collapsed .sidebar-toggle {
  left: 8px;
  transform: translateY(-50%);
}
.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: hidden auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 22px;
  transition: opacity .18s ease, transform .24s ease, padding .24s ease;
}
html.sidebar-collapsed .sidebar {
  opacity: 0;
  padding-left: 0;
  padding-right: 0;
  pointer-events: none;
  transform: translateX(-100%);
}
.brand {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  position: relative;
}
.brand strong {
  font-size: 20px;
  line-height: 1.1;
}
.brand > img,
.mobile-topbar img {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  object-fit: cover;
}
.brand span {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu {
  position: relative;
}
.account-menu-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: rgba(0,0,0,.05);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  transition: background .16s ease, transform .16s ease;
}
.account-menu-button:hover,
.account-menu-button:active {
  background: rgba(0,0,0,.09);
  transform: scale(.98);
}
.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 70;
  width: 168px;
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 44px rgba(0,0,0,.16);
  padding: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px) scale(.98);
  transform-origin: top right;
  transition: opacity .16s ease, transform .16s ease;
}
body.account-menu-open .account-dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.account-dropdown button {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 0 10px;
  text-align: left;
  font-weight: 650;
}
.account-dropdown button:hover,
.account-dropdown button:active {
  background: rgba(0,0,0,.06);
}
.account-dropdown form {
  margin: 0;
}
.folders {
  display: grid;
  gap: 2px;
}
.folders a,
.logout button {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  padding: 0 14px;
  text-decoration: none;
  transition: background .16s ease, color .16s ease;
}
.folders a:hover,
.logout button:hover { background: rgba(0,0,0,.06); }
.folders a.active {
  background: var(--ink);
  color: #fff;
}
.folder-count {
  min-width: 34px;
  border-radius: 999px;
  background: rgba(0,0,0,.055);
  color: var(--muted);
  padding: 3px 7px;
  text-align: center;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.2;
}
.folders a.active .folder-count {
  background: rgba(255,255,255,.18);
  color: #fff;
}
.logout { margin-top: auto; }
.logout button {
  width: 100%;
  color: var(--muted);
}
.mail-list {
  min-width: 0;
  overflow: hidden auto;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,.58);
}
.list-head {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(12px);
  padding: 24px;
}
.list-title {
  margin-bottom: 16px;
}
.list-title h1 {
  margin: 0 0 5px;
  font-size: 34px;
  line-height: 1;
}
.list-title span {
  display: inline-flex;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.search input { height: 46px; }
.mail-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 14px;
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  text-decoration: none;
  transition: background .16s ease;
}
.mail-row:hover { background: var(--surface); }
.mail-row time,
.mail-row .from {
  color: var(--muted);
  font-size: 13px;
}
.mail-row .from,
.mail-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-row strong {
  grid-column: 1 / -1;
  font-size: 15px;
}
.mail-row.unread .from,
.mail-row.unread strong {
  color: var(--ink);
  font-weight: 850;
}
.reader {
  min-width: 0;
  overflow: hidden auto;
  background: var(--panel);
}
.reader-head {
  border-bottom: 1px solid var(--line);
  background: rgba(255,250,242,.92);
  padding: 30px 36px 24px;
}
.reader-head h2 {
  margin: 0;
  max-width: 900px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.08;
}
.reader-head p {
  margin: 16px 0 18px;
  color: var(--muted);
}
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.message-actions form { margin: 0; }
.message-actions button,
.composer-head button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  transition: background .16s ease;
}
.message-actions button:hover,
.composer-head button:hover { background: rgba(0,0,0,.06); }
.message-actions .danger { color: var(--danger); }
.message-body {
  width: min(860px, calc(100% - 56px));
  margin: 36px auto;
  border: 1px solid rgba(0,0,0,.04);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 16px 44px rgba(20,24,28,.08);
  padding: 34px;
  line-height: 1.72;
}
.message-body pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}
.attachments a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  text-decoration: none;
}
.empty-reader,
.empty-list {
  display: grid;
  place-items: center;
  min-height: 220px;
  color: var(--muted);
  text-align: center;
}
.empty-reader { min-height: 100%; }
.alert {
  margin: 16px 24px;
  border-radius: 12px;
  padding: 12px 14px;
}
.login-card .alert { margin: 0 0 14px; }
.notice {
  background: rgba(36,95,99,.12);
  color: var(--accent);
}
.error {
  background: rgba(154,49,88,.12);
  color: var(--danger);
}
.composer {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  width: min(620px, calc(100vw - 32px));
  display: none;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
  padding: 16px;
}
body.compose-open .composer { display: grid; }
.composer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.composer textarea {
  min-height: 220px;
  resize: vertical;
}
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --sidebar: 220px;
    --list: minmax(0, 1fr);
  }
  .mail-app {
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
  }
  .mail-list { border-right: 0; }
  .reader { display: none; }
  body.has-message .mail-list { display: none; }
  body.has-message .reader { display: block; }
  .back-link {
    display: inline-flex;
    width: fit-content;
    margin-bottom: 14px;
    color: var(--accent);
    font-weight: 850;
    text-decoration: none;
  }
}
@media (max-width: 767px) {
  body { background: #faf7f1; }
  .login-page {
    align-content: start;
    padding-top: 13vh;
  }
  .login-logo {
    width: 116px;
    height: 116px;
    border-radius: 28px;
  }
  .login-card { padding: 22px; }
  .mail-app {
    display: block;
    min-height: 100vh;
    height: auto;
    overflow: visible;
    padding-top: calc(58px + var(--safe-top));
  }
  .sidebar-toggle { display: none; }
  .mobile-topbar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 40;
    min-height: calc(58px + var(--safe-top));
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 42px;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,250,242,.96);
    backdrop-filter: blur(14px);
    padding: var(--safe-top) 12px 0;
  }
  .mobile-topbar button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--ink);
    font-size: 27px;
    line-height: 1;
    transition: background .16s ease, transform .16s ease, opacity .16s ease;
  }
  .mobile-topbar button:active {
    background: rgba(0,0,0,.06);
    transform: scale(.97);
  }
  .mobile-topbar strong,
  .mobile-topbar span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-topbar strong {
    display: flex;
    align-items: center;
    gap: 8px;
    transition: opacity .18s ease, transform .18s ease;
  }
  .mobile-topbar img {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }
  .mobile-topbar span {
    max-width: 112px;
    color: var(--muted);
    font-size: 13px;
  }
  .search-trigger {
    position: relative;
    justify-self: end;
    font-size: 0 !important;
  }
  .search-trigger::before,
  .search-trigger::after {
    content: "";
    position: absolute;
    display: block;
  }
  .search-trigger::before {
    width: 13px;
    height: 13px;
    left: 10px;
    top: 10px;
    border: 2px solid currentColor;
    border-radius: 50%;
  }
  .search-trigger::after {
    width: 10px;
    height: 2px;
    left: 23px;
    top: 24px;
    border-radius: 999px;
    background: currentColor;
    transform: rotate(45deg);
    transform-origin: left center;
  }
  .mobile-search {
    position: absolute;
    top: calc(var(--safe-top) + 8px);
    right: 12px;
    left: 58px;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(18px) scaleX(.88);
    transform-origin: right center;
    transition: opacity .2s ease, transform .2s ease;
  }
  .mobile-search input {
    height: 42px;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(0,0,0,.08);
    padding: 0 13px;
  }
  .mobile-search .search-close {
    background: var(--ink);
    color: #fff;
  }
  body.search-open .mobile-search {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0) scaleX(1);
  }
  body.search-open .mobile-topbar strong {
    opacity: 0;
    transform: translateX(-8px);
  }
  body.search-open .search-trigger {
    opacity: 0;
    pointer-events: none;
  }
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(0,0,0,.38);
  }
  body.menu-open .drawer-backdrop { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(84vw, 320px);
    padding: calc(16px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
    box-shadow: 20px 0 70px rgba(0,0,0,.22);
    transform: translateX(-105%);
    transition: transform .22s ease;
  }
  html.sidebar-collapsed .sidebar {
    opacity: 1;
    padding: calc(16px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
    pointer-events: auto;
    transform: translateX(-105%);
  }
  body.menu-open .sidebar,
  html.sidebar-collapsed body.menu-open .sidebar {
    transform: translateX(0);
  }
  .drawer-close {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    align-self: end;
    border: 0;
    border-radius: 9px;
    background: rgba(0,0,0,.06);
    color: var(--ink);
    font-size: 28px;
    line-height: 1;
  }
  .brand {
    margin-top: -38px;
    padding-right: 44px;
  }
  .compose-button {
    margin-top: 2px;
  }
  .folders a {
    min-height: 38px;
    padding: 0 12px;
  }
  .list-head {
    padding: 22px 18px 16px;
  }
  .list-title {
    margin-bottom: 14px;
  }
  .list-head .search {
    display: none;
  }
  .list-title h1 {
    margin-bottom: 5px;
    font-size: 32px;
  }
  .mail-row { padding: 15px 18px; }
  body.has-message .mail-list { display: none; }
  .reader {
    display: none;
    min-height: calc(100vh - 58px - var(--safe-top));
  }
  body.has-message .reader { display: block; }
  .back-link {
    display: inline-flex;
    width: fit-content;
    margin-bottom: 14px;
    color: var(--accent);
    font-weight: 850;
    text-decoration: none;
  }
  .reader-head { padding: 18px; }
  .reader-head h2 { font-size: 28px; }
  .message-body {
    width: auto;
    margin: 14px;
    padding: 22px;
  }
  .composer {
    inset: auto 10px calc(10px + var(--safe-bottom));
    width: auto;
    max-height: calc(100vh - 78px - var(--safe-top) - var(--safe-bottom));
    overflow: auto;
  }
}
