/* Sh.M Mail — تمیز، سریع، شبیه جیمیل */
:root {
  --bg: #f6f8fc;
  --panel: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #e0e3e7;
  --accent: #0b57d0;
  --accent-soft: #d3e3fd;
  --sidebar: #f6f8fc;
  --danger: #c5221f;
  --ok: #137333;
  --hover: #eef1f6;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);
  --r: 12px;
}
[data-theme="dark"] {
  --bg: #111418;
  --panel: #1a1d23;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #2d323a;
  --accent: #8ab4f8;
  --accent-soft: #1e3a5f;
  --sidebar: #15181d;
  --danger: #f28b82;
  --ok: #81c995;
  --hover: #23262e;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

.app { display: flex; height: 100%; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--sidebar);
  border-left: 1px solid var(--line);
  padding: 12px 10px 16px;
  display: flex; flex-direction: column;
  transition: transform .2s ease;
}
.brand {
  font-weight: 700; font-size: 20px; color: var(--accent);
  margin: 8px 12px 14px;
}
.btn {
  border: 0; border-radius: 20px; padding: 10px 16px;
  cursor: pointer; font-size: 14px; font-weight: 600;
  background: var(--line); color: var(--text);
  transition: background .15s, box-shadow .15s, transform .12s;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: var(--accent); color: #fff;
}
.btn.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
}
.btn.compose {
  width: calc(100% - 8px); margin: 0 4px 14px;
  background: var(--accent-soft); color: var(--accent);
  box-shadow: var(--shadow); padding: 12px 16px;
}
.btn.compose:hover { box-shadow: 0 2px 8px rgba(11,87,208,.2); }

nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; }
nav button {
  display: block; width: 100%; text-align: right;
  border: 0; background: none; cursor: pointer;
  padding: 10px 14px; border-radius: 0 20px 20px 0;
  color: var(--text); font-size: 14px;
  transition: background .12s;
}
nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav button:hover:not(.on) { background: var(--hover); }

.side-foot {
  margin-top: auto; padding-top: 12px;
  border-top: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.who {
  direction: ltr; text-align: right; word-break: break-all;
  margin-bottom: 8px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.link {
  background: none; border: 0; color: var(--accent); cursor: pointer;
  font-size: 13px; padding: 4px 0; margin-left: 10px;
}

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
}
.top input {
  flex: 1; border: 0; background: var(--panel);
  border-radius: 24px; padding: 12px 18px; color: var(--text);
  box-shadow: var(--shadow); font-size: 14px;
  transition: box-shadow .15s;
}
.top input:focus {
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent), var(--shadow);
}
.icon, .burger, .icon-close {
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 18px;
  display: grid; place-items: center;
  transition: background .12s;
}
.icon:hover, .burger:hover, .icon-close:hover { background: var(--hover); color: var(--text); }
.burger { display: none; }

.split {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(280px, 360px) 1fr;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.list { overflow: auto; border-left: 1px solid var(--line); }
.item {
  display: grid; grid-template-columns: 40px 1fr; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background .1s;
}
.item:hover { background: var(--hover); }
.item.unread { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); font-weight: 600; }
.item.on { background: var(--accent-soft); }
.item .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
.item .from { font-size: 14px; margin-bottom: 2px; }
.item .subj { font-size: 13px; font-weight: 500; }
.item .snip {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400;
}

.read { overflow: auto; padding: 24px 28px; }
.read h2 { margin: 0 0 10px; font-size: 20px; font-weight: 600; }
.read .meta { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 14px; }
.read .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.read .body {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px; line-height: 1.7;
  animation: fadeIn .2s ease;
}
.empty { color: var(--muted); text-align: center; padding: 48px 20px; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* Auth */
.auth-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: min(400px, 94vw); background: var(--panel);
  border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: slideUp .25s ease;
}
.logo { font-size: 26px; font-weight: 800; color: var(--accent); }
.muted { color: var(--muted); margin: 6px 0 0; font-size: 13px; }
.tabs {
  display: flex; gap: 6px; margin: 18px 0 12px;
  background: var(--bg); padding: 4px; border-radius: 10px;
}
.tab {
  flex: 1; border: 0; border-radius: 8px; padding: 9px; cursor: pointer;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 14px;
  transition: background .15s, color .15s;
}
.tab.on { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.auth-card label { display: block; margin-top: 12px; font-size: 13px; color: var(--muted); }
.auth-card input {
  width: 100%; margin-top: 6px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px;
}
.auth-card input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
}
.auth-card .btn.primary { width: 100%; margin-top: 16px; padding: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; }
.suffix { color: var(--muted); font-size: 12px; white-space: nowrap; }
.err { color: var(--danger); margin-top: 10px; font-size: 13px; min-height: 1.2em; }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(0,0,0,.4); padding: 16px;
  animation: fadeIn .15s ease;
}
.sheet {
  width: min(640px, 100%); max-height: 90vh;
  background: var(--panel); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  animation: slideUp .2s ease;
}
.sheet.small { width: min(400px, 100%); padding: 16px; }
.compose-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.compose-head strong { font-size: 15px; }
.field { padding: 8px 16px 0; display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1; min-height: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field textarea, .sheet.small input, .sheet.small textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px;
}
.field input:focus, .editor:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}
.editor {
  min-height: 150px; max-height: 280px; overflow: auto;
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  background: var(--bg); line-height: 1.6;
}
.editor:empty:before { content: attr(data-placeholder); color: var(--muted); }
.compose-status { margin: 8px 16px 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }
.compose-status.ok { color: var(--ok); }
.compose-status.err { color: var(--danger); }
.compose-foot {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--line); margin-top: 10px;
}
.turnstile-box { margin: 12px 0; min-height: 65px; display: flex; justify-content: center; }

.mobile-nav { display: none; }
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 56px; z-index: 20;
    transform: translateX(105%); width: 260px;
    background: var(--panel); box-shadow: -4px 0 20px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: none; }
  .overlay.show { display: block; }
  .burger { display: grid; }
  .split { grid-template-columns: 1fr; }
  .list { border-left: 0; }
  .read { display: none; padding: 16px; }
  .read.show {
    display: block; position: fixed; inset: 56px 0 56px 0; z-index: 10;
    background: var(--panel); overflow: auto;
  }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 12;
    background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav button {
    flex: 1; border: 0; background: none; padding: 12px 4px;
    color: var(--muted); font-size: 12px; font-weight: 600;
  }
  .mobile-nav button:active { color: var(--accent); }
  .top { padding: 8px 12px; }
  .item { padding: 12px; }
}
