/* ─── Веб-почта ───────────────────────────────────────────────── */
:root {
  --bg: #edeef0;
  --panel: #ffffff;
  --accent: #2688eb;
  --accent-dark: #1a6fc4;
  --accent-soft: #e5f0fb;
  --text: #000000;
  --text-2: #414141;
  --muted: #818c99;
  --line: #e7e8ea;
  --hover: #f0f2f5;
  --danger: #e64646;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ─── Вход ──────────────────────────────────────────────────── */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 16px; padding: 40px 36px; }
.login-logo { font-size: 40px; color: var(--accent); }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; font-weight: 600; }
.login-sub { margin: 0 0 24px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input { width: 100%; padding: 11px 13px; border: 1px solid #d3d9de; border-radius: 8px; background: #fff; outline: none; }
.field input:focus { border-color: var(--accent); }
.login-error { color: var(--danger); margin-bottom: 12px; font-size: 13px; }

.btn-primary { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 10px 22px; font-weight: 500; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-outline { background: var(--hover); color: var(--text-2); border: none; border-radius: 8px; padding: 10px 18px; font-weight: 500; }
.btn-outline:hover { background: #e3e6ea; }

/* ─── Каркас ────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100vh; }
.layout { display: flex; flex: 1; min-height: 0; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); flex: none; }
.brand { display: flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 600; color: var(--accent); margin-right: 12px; }
.brand span { color: var(--text); }
.icon-btn {
  background: none; border: none; border-radius: 8px;
  width: 36px; height: 36px; font-size: 16px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text-2); }
.icon-btn:disabled { opacity: .4; cursor: default; background: none; }
.search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 8px; background: var(--hover); border-radius: 10px; padding: 0 8px 0 12px; height: 38px; }
.search:focus-within { background: #fff; box-shadow: 0 0 0 1px var(--accent); }
.search input { flex: 1; border: none; background: none; outline: none; height: 100%; }
.search-icon { color: var(--muted); font-size: 13px; }
.search-clear { background: none; border: none; color: var(--muted); border-radius: 6px; width: 28px; height: 28px; }
.search-clear:hover { background: #e3e6ea; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.acc-email { color: var(--muted); font-size: 13px; }

/* аватары */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 500; text-transform: uppercase;
  background: var(--accent);
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.av0{background:#5181b8}.av1{background:#e64646}.av2{background:#4bb34b}.av3{background:#792ec0}
.av4{background:#e39e2b}.av5{background:#3f8ae0}.av6{background:#c74b8b}.av7{background:#1c8e8e}

/* ─── Сайдбар ───────────────────────────────────────────────── */
.sidebar { width: 224px; flex: none; padding: 12px 8px 16px 12px; overflow-y: auto; display: flex; flex-direction: column; }
.compose-btn {
  background: var(--panel); color: var(--text); border: none;
  border-radius: 10px; padding: 12px 16px; font-weight: 500; text-align: center;
  margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.compose-btn:hover { background: #fafbfc; }
.folders { display: flex; flex-direction: column; gap: 1px; }
.folder, .side-link {
  display: flex; align-items: center; gap: 10px;
  border: none; background: none; border-radius: 8px;
  padding: 8px 10px; text-align: left; color: var(--text-2);
  white-space: nowrap; overflow: hidden; width: 100%;
}
.folder:hover, .side-link:hover { background: rgba(0,0,0,.05); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.folder .f-icon, .side-link .f-icon { width: 18px; text-align: center; flex: none; font-size: 14px; }
.folder .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.folder .f-count { font-size: 12px; color: var(--muted); }
.folder .f-count.has { color: var(--accent); font-weight: 600; }
.folder.active .f-count { color: var(--accent); }
.side-link { margin-top: 4px; }

/* ─── Панель контента ───────────────────────────────────────── */
.main { flex: 1; min-width: 0; padding: 0 12px 12px 0; display: flex; flex-direction: column; }
#list-view, #msg-view, #contacts-view {
  background: var(--panel); border-radius: var(--radius);
  flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
}
.list-toolbar, .msg-toolbar {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 8px 12px; border-bottom: 1px solid var(--line); flex: none;
}
.list-title { font-weight: 600; font-size: 15px; margin-left: 4px; }
.pager { font-size: 12px; color: var(--muted); margin-right: 4px; }
.tool-btn {
  background: none; border: none; border-radius: 8px;
  padding: 7px 10px; color: var(--text-2); white-space: nowrap;
}
.tool-btn:hover { background: var(--hover); }
.move-select { border: none; background: none; border-radius: 8px; padding: 7px 6px; color: var(--text-2); max-width: 150px; }
.move-select:hover { background: var(--hover); }
.state { padding: 44px 24px; text-align: center; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%; margin: 0 auto;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ─── Список писем ──────────────────────────────────────────── */
.msg-list { overflow-y: auto; flex: 1; }
.day-head {
  padding: 14px 20px 6px; font-size: 13px; font-weight: 600; color: var(--muted);
  position: sticky; top: 0; background: var(--panel); z-index: 2;
}
.msg-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 8px; cursor: pointer; position: relative;
  border-radius: 8px; margin: 0 6px;
}
.msg-row:hover { background: var(--hover); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.msg-row.unread .dot { background: var(--accent); }
.m-from { width: 190px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.msg-row.unread .m-from { font-weight: 600; color: var(--text); }
.m-text { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: baseline; }
.m-subj { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.msg-row.unread .m-subj { font-weight: 600; color: var(--text); }
.m-snip { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.m-right { display: flex; align-items: center; gap: 8px; flex: none; }
.m-clip { color: var(--muted); font-size: 13px; }
.m-date { font-size: 12px; color: var(--muted); width: 46px; text-align: right; }
.msg-row.unread .m-date { color: var(--text-2); font-weight: 500; }
.m-acts { display: none; gap: 2px; }
.msg-row:hover .m-acts { display: flex; }
.msg-row:hover .m-date { display: none; }
.m-act { background: none; border: none; border-radius: 6px; width: 28px; height: 28px; color: var(--muted); font-size: 14px; }
.m-act:hover { background: #e3e6ea; color: var(--text-2); }
.m-act.on { color: #e39e2b; }

/* ─── Чтение письма ─────────────────────────────────────────── */
.msg-card { overflow-y: auto; flex: 1; padding: 12px 24px 24px; }
.msg-subject { font-size: 20px; font-weight: 600; margin: 8px 0 18px; }
.msg-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.msg-meta { min-width: 0; flex: 1; }
.msg-from { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.add-contact { background: none; border: none; color: var(--accent); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.add-contact:hover { background: var(--accent-soft); }
.msg-date { flex: none; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.att-card {
  display: flex; align-items: center; gap: 10px; width: 230px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  text-decoration: none; color: var(--text); background: #fbfcfd;
}
.att-card:hover { background: var(--hover); }
.att-ico { font-size: 20px; flex: none; }
.att-info { min-width: 0; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.att-size { color: var(--muted); font-size: 12px; }
.msg-body { border-top: 1px solid var(--line); padding-top: 18px; }
.msg-body iframe { width: 100%; border: none; display: block; }
.msg-body pre.plain { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
.msg-actions { display: flex; gap: 8px; margin-top: 26px; }

/* ─── Контакты ──────────────────────────────────────────────── */
.contacts { overflow-y: auto; flex: 1; padding: 6px; }
.contact-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; }
.contact-row:hover { background: var(--hover); }
.contact-main { flex: 1; min-width: 0; }
.contact-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-acts { display: flex; gap: 4px; flex: none; }

/* ─── Модальные окна ────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.compose, .cdlg {
  position: fixed; z-index: 50; background: var(--panel);
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.3);
  display: flex; flex-direction: column;
}
.compose { width: 720px; max-width: calc(100vw - 24px); height: 74vh; min-height: 440px; }
.compose-header { display: flex; align-items: center; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); font-weight: 600; flex: none; }
.compose-fields { flex: none; padding: 0 20px; }
.compose-row { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.compose-row label { color: var(--muted); font-size: 13px; flex: none; width: 54px; }
.compose-row input { flex: 1; border: none; outline: none; padding: 11px 0; background: none; }
.cc-toggle { background: none; border: none; color: var(--accent); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.cc-toggle:hover { background: var(--accent-soft); }
.compose-body { flex: 1; border: none; outline: none; resize: none; padding: 14px 20px; background: none; }
.compose-atts { flex: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 6px; }
.c-att { display: inline-flex; align-items: center; gap: 6px; background: var(--hover); border-radius: 8px; padding: 5px 10px; font-size: 12px; max-width: 240px; }
.c-att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-att button { background: none; border: none; color: var(--muted); padding: 0 2px; }
.c-att button:hover { color: var(--danger); }
.compose-footer { flex: none; display: flex; align-items: center; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.attach-btn { color: var(--text-2); background: none; border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px; }
.attach-btn:hover { background: var(--hover); }
.compose-error { color: var(--danger); font-size: 12px; }

.cdlg { width: 420px; max-width: calc(100vw - 24px); padding: 22px 24px 20px; }
.cdlg h3 { margin: 0 0 16px; font-size: 17px; }
.cdlg-err { color: var(--danger); font-size: 13px; min-height: 18px; }
.cdlg-actions { display: flex; gap: 8px; margin-top: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 60; background: #2c2d2e; color: #fff; border-radius: 10px; padding: 12px 22px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }

/* ─── Мобильный ─────────────────────────────────────────────── */
#menu-btn { display: none; }
@media (max-width: 880px) {
  #menu-btn { display: inline-flex; }
  .brand span, .acc-email { display: none; }
  .layout { position: relative; }
  .sidebar {
    position: absolute; z-index: 30; top: 0; bottom: 0; left: 0;
    background: var(--bg); transform: translateX(-105%);
    transition: transform .2s ease; box-shadow: 4px 0 16px rgba(0,0,0,.14);
  }
  .sidebar.open { transform: none; }
  .main { padding: 0 8px 8px; }
  .m-from { width: 120px; }
  .m-snip { display: none; }
  .m-subj { max-width: 100%; }
  .msg-card { padding: 10px 14px 20px; }
  .compose { width: 100%; max-width: 100%; height: 100%; border-radius: 0; top: 0; left: 0; transform: none; }
  .att-card { width: 100%; }
  .tool-btn { padding: 7px 8px; font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }