:root {
  --bg: #f6f7fb;
  --pane: #ffffff;
  --pane2: #fbfbfe;
  --text: #171a21;
  --muted: #79808f;
  --line: #e8eaf1;
  --accent: #4f63ff;
  --accent-2: #8e5bff;
  --accent-soft: #eef0ff;
  --danger: #e5484d;
  --warn: #d9822b;
  --ok: #2f9e64;
  --shadow: 0 10px 34px rgba(23, 28, 60, .13);
  --shadow-s: 0 2px 10px rgba(23, 28, 60, .07);
  --r: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1016;
    --pane: #161923;
    --pane2: #121520;
    --text: #e9ebf3;
    --muted: #8990a6;
    --line: #242939;
    --accent: #6c7dff;
    --accent-2: #a07dff;
    --accent-soft: #1e2440;
    --shadow: 0 10px 34px rgba(0, 0, 0, .55);
    --shadow-s: 0 2px 10px rgba(0, 0, 0, .35);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea {
  font: inherit; color: var(--text); background: var(--pane2);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px;
  outline: none; width: 100%; transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
::placeholder { color: var(--muted); }

/* иконки */
.ic { width: 20px; height: 20px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.ic-s { width: 17px; height: 17px; }
.ic-xl { width: 44px; height: 44px; stroke-width: 1.4; opacity: .5; }

/* аватары */
.ava {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px; overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  user-select: none;
}
.ava { position: relative; }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 2; }
.ava.s { width: 34px; height: 34px; font-size: 14px; }

/* ---------- ВХОД ---------- */
#login-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--sat));
  background:
    radial-gradient(60% 40% at 20% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent),
    var(--bg);
}
#login-form {
  width: 100%; max-width: 370px; background: var(--pane);
  border-radius: 24px; padding: 38px 30px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 13px; text-align: center;
  border: 1px solid var(--line);
}
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 6px; border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
}
.login-logo .ic { width: 30px; height: 30px; }
#login-form h1 { font-size: 22px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
#login-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: 12px; padding: 13px; font-weight: 600; margin-top: 4px;
  transition: opacity .15s, transform .1s;
}
#login-btn:active { transform: scale(.98); }
#login-btn:disabled { opacity: .6; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- КАРКАС ---------- */
#app { display: flex; height: 100dvh; }

#sidebar {
  width: 250px; flex-shrink: 0; background: var(--pane2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: calc(12px + var(--sat)) 12px calc(12px + var(--sab));
}
.side-profile {
  display: flex; align-items: center; gap: 11px; text-align: left;
  padding: 9px 10px; border-radius: var(--r); margin-bottom: 12px;
  transition: background .15s;
}
.side-profile:hover { background: var(--accent-soft); }
.side-me { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.side-name { font-weight: 650; font-size: 14.5px; }
.side-mail { font-size: 12px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.side-chevron { color: var(--muted); }
.compose-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: 12px; padding: 12px; font-weight: 600; margin-bottom: 14px;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .1s;
}
.compose-btn:active { transform: scale(.98); }
#folder-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border-radius: 11px; font-size: 14.5px; text-align: left;
  color: var(--muted); transition: background .15s, color .15s;
}
.folder-item .ic { width: 18px; height: 18px; }
.folder-item .f-name { flex: 1; color: var(--text); }
.folder-item .f-count {
  font-size: 11.5px; background: var(--accent); color: #fff;
  border-radius: 20px; padding: 1.5px 7.5px; font-weight: 700; min-width: 21px;
  text-align: center;
}
.folder-item.active { background: var(--accent-soft); color: var(--accent); }
.folder-item.active .f-name { color: var(--accent); font-weight: 650; }
.side-foot { display: flex; flex-direction: column; gap: 2px; padding-top: 10px;
  border-top: 1px solid var(--line); }
.ghost-btn {
  display: flex; align-items: center; gap: 10px;
  text-align: left; padding: 10px 12px; border-radius: 11px;
  color: var(--muted); font-size: 13.5px; transition: background .15s, color .15s;
}
.ghost-btn:hover { background: var(--accent-soft); color: var(--accent); }
.ghost-btn.on { color: var(--accent); font-weight: 600; }

/* ---------- СПИСОК ---------- */
#list-pane {
  width: 396px; flex-shrink: 0; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; background: var(--pane);
  position: relative;
}
.pane-head {
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + var(--sat)) 12px 8px;
  border-bottom: 1px solid var(--line); min-height: 56px;
  background: color-mix(in srgb, var(--pane) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  z-index: 2;
}
.pane-head h2 { font-size: 18px; flex: 1; letter-spacing: -.01em; padding-left: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); flex-shrink: 0; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
#menu-btn { display: none; }

.msg-list { flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; padding: 6px 8px calc(6px + var(--sab)); }
.msg-item {
  display: flex; gap: 11px; width: 100%; text-align: left; align-items: flex-start;
  padding: 11px 12px; border-radius: 13px; position: relative;
  transition: background .12s;
}
.msg-item:hover { background: var(--pane2); }
.msg-item.active { background: var(--accent-soft); }
.msg-item .m-body { flex: 1; min-width: 0; }
.msg-item .m-top { display: flex; gap: 8px; align-items: baseline; }
.msg-item .m-from { font-weight: 600; font-size: 14.5px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item .m-date { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.msg-item .m-subj { display: block; font-size: 13.5px; color: var(--muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.msg-item.unread .m-subj { color: var(--text); }
.msg-item.unread .m-from::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 7px; vertical-align: 1px;
}
.more-btn { padding: 13px; color: var(--accent); font-weight: 600; }
.list-empty {
  padding: 60px 16px; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 12px; font-size: 14px;
}

.fab {
  display: none; position: absolute; right: 18px; bottom: calc(24px + var(--sab));
  width: 58px; height: 58px; border-radius: 18px;
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--accent) 50%, transparent); z-index: 5;
  transition: transform .1s;
}
.fab:active { transform: scale(.94); }
.fab .ic { width: 23px; height: 23px; }

/* ---------- ЧТЕНИЕ ---------- */
.read-pane { flex: 1; display: flex; flex-direction: column; background: var(--pane2); min-width: 0; }
.read-actions { display: flex; gap: 2px; margin-left: auto; }
#back-btn { display: none; }
.read-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--sab); }
.read-placeholder {
  padding: 90px 20px; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.read-head { padding: 22px 24px 16px; border-bottom: 1px solid var(--line); background: var(--pane); }
.read-subj { font-size: 20px; font-weight: 700; margin-bottom: 12px;
  overflow-wrap: anywhere; letter-spacing: -.015em; }
.read-meta { display: flex; gap: 12px; align-items: center; }
.read-who { min-width: 0; flex: 1; }
.read-from { font-weight: 650; font-size: 14.5px; }
.read-addr, .read-date { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.spam-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  border-radius: 20px; padding: 3px 10px; margin-top: 8px;
}
.spam-chip .ic { width: 13px; height: 13px; }
.spam-chip.low { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.spam-chip.high { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.read-content { padding: 20px 24px; }
.read-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; }
.read-frame { width: 100%; border: 0; background: #fff; border-radius: 12px;
  min-height: 200px; box-shadow: var(--shadow-s); }
.read-atts { padding: 0 24px 24px; display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip {
  display: inline-flex; gap: 8px; align-items: center; text-decoration: none;
  background: var(--pane); color: var(--text); border: 1px solid var(--line);
  border-radius: 11px; padding: 9px 13px; font-size: 13.5px; transition: border-color .15s;
}
.att-chip:hover { border-color: var(--accent); }
.att-chip .ic { width: 15px; height: 15px; color: var(--muted); }
.att-size { color: var(--muted); font-size: 12px; }

/* ---------- МОДАЛКИ ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(8, 10, 18, .5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: 100%; max-width: 640px; background: var(--pane);
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + var(--sab));
  display: flex; flex-direction: column; gap: 11px;
  max-height: 92dvh; box-shadow: var(--shadow);
  animation: rise .22s cubic-bezier(.3,1.2,.4,1);
}
@keyframes rise { from { transform: translateY(40px); opacity: .6; } }
.modal-head { display: flex; align-items: center; }
.modal-head h3 { flex: 1; font-size: 17.5px; letter-spacing: -.01em; }
#c-body { min-height: 32dvh; resize: vertical; }
.modal-foot { display: flex; align-items: center; gap: 12px; }
#c-status { flex: 1; font-size: 13px; color: var(--muted); }
.send-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  border-radius: 12px; padding: 12px 24px; font-weight: 600; transition: transform .1s;
}
.send-btn:active { transform: scale(.97); }
.send-btn:disabled { opacity: .6; }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 22px; }
}

/* переключатель аккаунтов */
.sheet { max-width: 420px; }
.account-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.account-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 12px; border-radius: 13px; text-align: left; transition: background .13s;
}
.account-item:hover { background: var(--accent-soft); }
.account-item .a-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.account-item .a-name { font-weight: 600; font-size: 14.5px; }
.account-item .a-mail { font-size: 12.5px; color: var(--muted); }
.account-item .f-count {
  font-size: 11.5px; background: var(--accent); color: #fff;
  border-radius: 20px; padding: 1.5px 7.5px; font-weight: 700;
}
.account-item .a-check { color: var(--accent); }

/* ---------- LIVE ---------- */
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); opacity: .45; margin-left: 9px; vertical-align: 2px;
  transition: background .3s, opacity .3s;
}
.live-dot.on {
  background: var(--ok); opacity: 1;
  animation: live-pulse 2.2s ease-out infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.msg-item.new { animation: msg-in .38s cubic-bezier(.3,1.1,.4,1), msg-flash 2.4s ease .1s; }
@keyframes msg-in { from { opacity: 0; transform: translateY(-12px) scale(.98); } }
@keyframes msg-flash {
  0% { background: var(--accent-soft); }
  100% { background: transparent; }
}
.f-count.bump { animation: bump .35s cubic-bezier(.3,1.6,.5,1); }
@keyframes bump { 40% { transform: scale(1.35); } }

/* ---------- ВЛОЖЕНИЯ В КОМПОЗЕРЕ ---------- */
.c-atts { display: flex; flex-wrap: wrap; gap: 8px; }
.c-att {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--pane2); border: 1px solid var(--line); border-radius: 11px;
  padding: 6px 8px 6px 6px; font-size: 13px; max-width: 100%;
  animation: rise .18s ease;
}
.c-att .thumb {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: var(--accent-soft);
}
.c-att .thumb-ico {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.c-att .thumb-ico .ic { width: 16px; height: 16px; }
.c-att .a-nm { max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-att .a-sz { color: var(--muted); font-size: 11.5px; }
.c-att .a-x {
  width: 24px; height: 24px; border-radius: 8px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.c-att .a-x:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.c-att .a-x .ic { width: 13px; height: 13px; }
.modal-card.drop { outline: 2.5px dashed var(--accent); outline-offset: -8px; }
.progress {
  height: 4px; border-radius: 3px; background: var(--line); overflow: hidden; flex: 1;
}
.progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .2s ease; border-radius: 3px;
}

/* ---------- НИЖНЯЯ НАВИГАЦИЯ ---------- */
#bottom-nav { display: none; }
.sheet-actions {
  border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px;
  display: flex; flex-direction: column; gap: 2px;
}

/* ---------- ТОСТ ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(26px + var(--sab)); background: var(--text); color: var(--bg);
  padding: 12px 22px; border-radius: 14px; font-size: 14px; z-index: 99;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
  animation: rise .2s ease;
}

/* ---------- МОБИЛЬНАЯ ВЁРСТКА ---------- */
@media (max-width: 900px) {
  #sidebar { display: none; }   /* на мобилке всё в нижней панели */
  #menu-btn { display: none; }
  #list-pane { width: 100%; border-right: 0; }
  .fab { display: none; }        /* «написать» теперь в нижней панели */
  .compose-btn { display: none; }
  .msg-list { padding: 4px 6px calc(78px + var(--sab)); }
  .msg-item { padding: 12px 10px; }

  #bottom-nav {
    display: flex; align-items: flex-end;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--pane) 90%, transparent);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    padding: 8px 6px calc(8px + var(--sab));
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--muted); font-size: 10.5px; padding: 3px 0; position: relative;
    transition: color .15s;
  }
  .bn-item .ic { width: 23px; height: 23px; }
  .bn-item.active { color: var(--accent); }
  .bn-label { line-height: 1; }
  .bn-badge {
    position: absolute; top: -3px; left: calc(50% + 4px);
    background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
    border-radius: 10px; padding: 1.5px 5px; min-width: 17px; text-align: center;
  }
  .bn-compose {
    flex: 0 0 58px; width: 54px; height: 54px; border-radius: 50%;
    margin: 0 2px; align-self: center; transform: translateY(-8px);
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
    box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 45%, transparent);
    transition: transform .1s;
  }
  .bn-compose:active { transform: translateY(-8px) scale(.94); }
  .bn-compose .ic { width: 24px; height: 24px; }

  .read-pane {
    position: fixed; inset: 0; z-index: 30; transform: translateX(100%);
    transition: transform .24s cubic-bezier(.3,1,.4,1); background: var(--pane2);
  }
  .read-pane.open { transform: none; }
  #back-btn { display: inline-flex; }
  .read-placeholder { display: none; }
  .read-head { padding: 16px 18px 14px; }
  .read-content { padding: 16px 18px; }
  .read-atts { padding: 0 18px 18px; }
}
