:root {
  --cream: #fff9ee;
  --paper: #fffefb;
  --ink: #312a3c;
  --muted: #746a7d;
  --pink: #ff78a5;
  --pink-soft: #ffd7e6;
  --yellow: #ffd45c;
  --coral: #ff7166;
  --blue: #6ea8ff;
  --blue-soft: #dceaff;
  --mint: #79d8b0;
  --line: 2px solid var(--ink);
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--cream); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  border-right: var(--line);
  background: var(--pink-soft);
}

.mail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font: 700 1.4rem "Fredoka", sans-serif;
  text-decoration: none;
}

.mail-brand span {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border: var(--line);
  border-radius: 15px;
  background: var(--pink);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-5deg);
}

.compose-button,
.send-button {
  min-height: 48px;
  padding: 0 18px;
  border: var(--line);
  border-radius: 16px;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 900;
}

.compose-button:active,
.send-button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }

.sidebar nav { display: grid; gap: 7px; }
.folder-button,
.admin-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 13px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  font-weight: 800;
}

.folder-button.active { border: var(--line); background: var(--paper); box-shadow: 3px 3px 0 var(--ink); }
.folder-button b { margin-left: auto; }
.admin-button { margin-top: auto; }
.admin-button:hover, .folder-button:not(.active):hover { background: rgba(255,255,255,.55); }

.account-chip {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 2px solid rgba(49,42,60,.18);
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: var(--line);
  border-radius: 50%;
  background: var(--blue);
  font: 700 1.1rem "Fredoka", sans-serif;
}
.account-chip strong, .account-chip small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-chip small { margin-top: 2px; color: var(--muted); font-size: .7rem; }

.mail-main { min-width: 0; padding: 28px; }
.mail-header { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.tiny-label { color: #c43b72; font-size: .72rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.mail-header h1 { margin: 2px 0 0; font: 700 clamp(2rem, 4vw, 3.4rem) "Fredoka", sans-serif; }
.search-box { width: min(340px, 45%); min-height: 46px; display: flex; align-items: center; gap: 9px; padding: 0 15px; border: var(--line); border-radius: 16px; background: var(--paper); box-shadow: 3px 3px 0 var(--ink); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; }

.mail-layout {
  height: calc(100vh - 135px);
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(290px, 390px) minmax(0, 1fr);
  overflow: hidden;
  border: var(--line);
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 7px 8px 0 var(--ink);
}

.message-list { overflow-y: auto; border-right: var(--line); background: #fffdf8; }
.message-row { width: 100%; display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 10px; padding: 17px 16px; border: 0; border-bottom: 1px solid #ded6e2; background: transparent; text-align: left; }
.message-row:hover, .message-row.active { background: var(--blue-soft); }
.message-row.unread { background: #fff3c8; }
.message-row.unread.active { background: var(--blue-soft); }
.sender-dot { width: 38px; height: 38px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 13px; background: var(--pink); font-weight: 900; }
.message-copy { min-width: 0; }
.message-topline { display: flex; justify-content: space-between; gap: 8px; }
.message-topline strong, .message-subject, .message-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-time { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.message-subject { margin-top: 3px; font-weight: 800; }
.message-preview { margin-top: 2px; color: var(--muted); font-size: .82rem; }
.unread-pip { width: 9px; height: 9px; margin-top: 5px; border: 1px solid var(--ink); border-radius: 50%; background: var(--coral); }
.message-list-empty { padding: 70px 20px; color: var(--muted); text-align: center; }

.reader { overflow-y: auto; padding: clamp(24px, 4vw, 52px); }
.reader.empty { display: grid; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.empty-cat { font-size: 4rem; color: var(--pink); }
.reader-header { padding-bottom: 24px; border-bottom: 2px solid #ece4ec; }
.reader-header h2 { margin: 10px 0 16px; font: 700 clamp(1.8rem, 3.5vw, 3rem)/1.05 "Fredoka", sans-serif; }
.reader-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: .88rem; }
.reader-meta strong { color: var(--ink); }
.reader-body { padding: 30px 0; white-space: pre-wrap; line-height: 1.72; overflow-wrap: anywhere; }
.reply-button { min-height: 43px; padding: 0 17px; border: var(--line); border-radius: 14px; background: var(--pink-soft); box-shadow: 3px 3px 0 var(--ink); font-weight: 900; }

.modal { width: min(620px, calc(100% - 28px)); padding: 0; border: var(--line); border-radius: 26px; background: var(--paper); box-shadow: 9px 10px 0 var(--ink); }
.modal::backdrop { background: rgba(49,42,60,.38); backdrop-filter: blur(3px); }
.modal form { display: grid; gap: 16px; padding: 24px; }
.modal header, .modal footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.modal h2 { margin: 0; font: 700 2rem "Fredoka", sans-serif; }
.icon-button { width: 39px; height: 39px; border: var(--line); border-radius: 13px; background: var(--pink-soft); font-size: 1.5rem; }
.modal label { display: grid; gap: 6px; color: var(--muted); font-size: .76rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.modal input, .modal textarea { width: 100%; border: var(--line); border-radius: 13px; background: #fffdfa; padding: 11px 13px; outline: none; text-transform: none; }
.modal input:focus, .modal textarea:focus { box-shadow: 0 0 0 3px var(--blue-soft); }
.body-field textarea { min-height: 230px; resize: vertical; }
.form-status { color: #b22d62; font-size: .84rem; font-weight: 800; }
.send-button { margin-left: auto; }
.user-list { max-height: 190px; overflow-y: auto; display: grid; gap: 8px; padding-top: 12px; border-top: 2px solid #ece4ec; }
.user-row { display: flex; justify-content: space-between; gap: 15px; padding: 10px 12px; border-radius: 12px; background: var(--blue-soft); }
.user-row small { display: block; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 10; padding: 11px 17px; border: var(--line); border-radius: 999px; background: var(--ink); color: white; font-weight: 900; opacity: 0; pointer-events: none; transform: translate(-50%, 18px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 850px) {
  .app-shell { grid-template-columns: 78px minmax(0, 1fr); }
  .sidebar { padding: 18px 12px; align-items: center; }
  .mail-brand strong, .compose-button, .folder-button:not(.active) span + *, .account-chip > span:last-child, .admin-button { font-size: 0; }
  .compose-button { width: 50px; padding: 0; font-size: 0; }
  .compose-button::before { content: "+"; font-size: 1.7rem; }
  .folder-button { width: 50px; justify-content: center; padding: 0; font-size: 0; }
  .folder-button span { font-size: 1.1rem; }
  .account-chip { grid-template-columns: 42px; }
  .mail-main { padding: 18px; }
}

@media (max-width: 650px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: auto 10px 10px; z-index: 5; width: auto; height: 68px; flex-direction: row; justify-content: center; padding: 8px 12px; border: var(--line); border-radius: 22px; box-shadow: 5px 5px 0 var(--ink); }
  .mail-brand, .account-chip, .admin-button { display: none !important; }
  .sidebar nav { display: flex; }
  .compose-button, .folder-button { width: 48px; min-height: 48px; }
  .mail-main { padding: 16px 12px 98px; }
  .mail-header { align-items: stretch; flex-direction: column; gap: 12px; }
  .search-box { width: 100%; }
  .mail-layout { height: auto; min-height: 70vh; grid-template-columns: 1fr; }
  .message-list { border-right: 0; }
  .reader { display: none; position: fixed; inset: 0; z-index: 7; background: var(--paper); }
  .reader.mobile-open { display: block; }
}
