/* ============================================================
   Сброс и переменные
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f7fb;
  --surface:   #ffffff;
  --surface-2: #f0f2f7;
  --border:    #e3e7ef;
  --border-2:  #d5dae6;
  --text:      #1a2233;
  --text-2:    #5a6478;
  --text-3:    #8d97ac;
  --primary:   #4a6cf7;
  --primary-h: #3a5ce6;
  --danger:    #e5484d;
  --success:   #14a44d;
  --sidebar:   #1e2740;
  --sidebar-2: #2a3453;
  --shadow-sm: 0 1px 2px rgba(20,30,60,.06);
  --shadow:    0 4px 16px rgba(20,30,60,.08);
  --shadow-lg: 0 20px 60px rgba(20,30,60,.25);
  --radius:    10px;
  --radius-lg: 16px;
  --sidebar-w: 260px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ============================================================
   Экран входа
   ============================================================ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
 /* background: radial-gradient(circle at 20% 20%, #4a6cf7 0%, #2a3e9e 60%, #1a2233 100%); */
  padding: 20px;
}

.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 15px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  font-size: 42px;
  width: 72px; height: 72px;
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4a6cf7, #6b8cff);
  color: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(74,108,247,.4);
}

.login-card h1 {
  font-size: 26px; font-weight: 700;
  color: var(--text);
  margin-bottom: 26px;
}

.login-sub {
  color: var(--text-3);
  margin-bottom: 28px;
  font-size: 13px;
}

.field {
  display: flex;
  text-align: left;
  margin: 0px;
}

.field span {
  align-items: center;
  display: flex;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  margin-right: 0px;
  letter-spacing: .04em;
  min-width: 45px;
}

.field input,
.field textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(74,108,247,.12);
}

.field textarea {
  resize: vertical;
  font-family: inherit;
  line-height: 1.5;
}

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  width: 100%;
  transition: background .15s, transform .05s;
}

.btn-primary:hover { background: var(--primary-h); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.login-error {
  margin-top: 0px;
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

/* ============================================================
   Приложение
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Сайдбар ---------- */
.sidebar {
  background: var(--sidebar);
  color: #e8ecf5;
  display: flex;
  flex-direction: column;
  padding: 6px 6px;
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}


.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 6px 4px;
  font-size: 18px; font-weight: 700;
}

.brand-logo {
  width: 32px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4a6cf7, #6b8cff);
  font-size: 16px;
}

.compose-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(74,108,247,.35);
  transition: background .15s, transform .05s;
}

.compose-btn:hover { background: var(--primary-h); }
.compose-btn:active { transform: translateY(1px); }
.compose-btn span { font-size: 16px; }

.folder-list {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.folder-item {
  display: flex; align-items: center; gap: 10px;
  padding: 3px 12px;
  background: transparent;
  border: none;
  color: #c5cde0;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  transition: background .12s, color .12s;
  width: 100%;
}

.folder-item:hover { background: var(--sidebar-2); color: #fff; }

.folder-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.folder-icon { font-size: 16px; width: 20px; text-align: center; }
.folder-name { flex: 1; }

.folder-badge {
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}

.folder-item.active .folder-badge {
  background: rgba(255,255,255,.25);
}

/* ---------- Футер сайдбара ---------- */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}

.user-block {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0;
}

.avatar {
  width: 36px; height: 36px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #6b8cff, #a06bff);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff;
  text-transform: uppercase;
}

.user-info { min-width: 0; }
.user-name {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-domain { font-size: 12px; color: #8d97ac; }

.logout-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,.15);
  color: #c5cde0;
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 16px;
  transition: background .15s;
}
.logout-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ============================================================
   Основная область
   ============================================================ */
.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

/* ---------- Верхняя панель ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  display: flex; align-items: center; gap: 20px;
  flex-wrap: wrap;
}

.topbar-title {
  display: flex; align-items: baseline; gap: 10px;
  flex-shrink: 0;
}

.topbar-title h1 {
  font-size: 20px; font-weight: 700;
}

.counter {
  color: var(--text-3);
  font-size: 13px;
}

.topbar-actions {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
  flex: 1;
  max-width: 620px;
}

.search-box {
  flex: 1;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px; top: 44%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 16px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 4px 14px 4px 36px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius);
  outline: none;
  background: var(--surface-2);
  transition: border-color .15s, background .15s;
}

.search-box input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(74,108,247,.12);
}

.filter-select {
  padding: 3px 12px;
  border: 1.5px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--surface-2);
  outline: none;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.filter-select:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.icon-btn {
  width: 28px; height: 29px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 18px;
  transition: background .15s, color .15s, transform .3s;
}
.icon-btn:hover { background: var(--surface); color: var(--primary); }
.icon-btn:active { transform: rotate(180deg); }

/* ---------- Список писем ---------- */
.mail-list-wrap {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 6px;
  position: relative;
}

.mail-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 1px;
}

.mail-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 6px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .08s;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
}

.mail-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.mail-item.unread {
  background: linear-gradient(to right, #f4f7ff, var(--surface) 30%);
  border-left: 3px solid var(--primary);
}

.mail-item.unread .mail-from,
.mail-item.unread .mail-subject {
  font-weight: 700;
  color: var(--text);
}

.mail-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,108,247,.15);
}

/* Аватар-инициал */
.mail-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff;
  font-size: 15px;
  flex-shrink: 0;
  text-transform: uppercase;
  margin: auto;
  position: relative;
  cursor: pointer;
  transition: transform .1s;
}
.mail-avatar:hover {
  transform: scale(1.05);
}

.mail-avatar .mail-avatar-check {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(74,108,247,.85);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  border-radius: inherit;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.mail-avatar.selected .mail-avatar-letter {
  opacity: 0;
}

.mail-avatar.selected .mail-avatar-check {
  opacity: 1;
}

.mail-avatar.selected {
  box-shadow: 0 0 0 3px rgba(74,108,247,.4);
}

/* Сетка элемента — убираем колонку чекбокса */
.mail-item {
  grid-template-columns: auto 1fr auto;
}

.mail-body { min-width: 0; }

.mail-row1 {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 2px;
}

.mail-from {
  font-size: 14px;
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.mail-subject {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.mail-preview {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-side {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  flex-shrink: 0;
}

.mail-date {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

.mail-tags { display: flex; gap: 6px; }

.tag {
  display: inline-flex; align-items: center;
  font-size: 14px;
  padding: 0px;
  border-radius: 8px;
  font-weight: 600;
}

.tag-attach {
  background: rgb(255 255 255 / 0%);
  color: #4a6cf7;
}

.tag-flag {
  color: #f5a623;
  font-size: 14px;
  padding: 0;
}

/* Пустое состояние */
.mail-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-3);
}

.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: .5; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty-sub { font-size: 13px; }

/* ---------- Пагинация ---------- */
.pager {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 4px 24px;
  display: flex; align-items: center; justify-content: center; gap: 16px;
}

.pager-btn {
  padding: 4px 8px;
  border: 0px solid var(--border-2);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.pager-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.pager-btn:disabled { opacity: .4; cursor: not-allowed; }

.page-info { color: var(--text); font-size: 13px; }

/* ============================================================
   Модальное окно (перетаскиваемое)
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,20,40,.4);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow: auto;
}

.modal-window {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; width:600px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 80px);
  overflow: hidden;
  /* Для перетаскивания: position управляется из JS */
  position: relative;
 resize: both;
  min-width: 640px;
 /* min-height: 400px; */
}

.modal-window.dragging {
  user-select: none;
  box-shadow: 0 30px 80px rgba(15,20,40,.4);
}

.modal-header {
  padding: 3px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  cursor: grab;
  background: var(--surface);
  flex-shrink: 0;
}

.modal-header:active { cursor: grabbing; }

.modal-subject {
  display: flex;
  justify-content: center;
  flex: 1;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 44px;
}

.modal-close {
  width: 32px; height: 32px;
  border: none;
  background: var(--surface);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 14px;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--danger); color: #fff; }

.modal-meta {
  padding: 14px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  flex-shrink: 0;
}

.meta-row {
  display: flex; gap: 8px;
  font-size: 13px;
}

.meta-label {
  color: var(--text-3);
  width: 52px;
  flex-shrink: 0;
}

.meta-value {
  color: var(--text);
  word-break: break-word;
}

.modal-body {
  overflow-y: auto;
  flex: 1;
  line-height: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-body p{
  padding: 10px;
}

.modal-body iframe {
  width: 100%;
  border: 0;
  min-height: 400px;
  height: calc(100% - 2px);
}

.modal-attachments {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.attach-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}

.attach-list { display: flex; flex-wrap: wrap; gap: 8px; }

.attach-item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  transition: border-color .15s, color .15s;
  max-width: 100%;
}

.attach-item:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.attach-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.attach-size { color: var(--text-3); font-size: 11px; }

.modal-actions {
  padding: 3px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px;
  background: var(--surface);
  flex-shrink: 0;
  justify-content: center;
}

.action-btn {
  padding: 6px 16px;
  border: 1.5px solid var(--border-2);
  background: var(--surface);
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); }

.action-btn.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ============================================================
   Окно написания
   ============================================================ */
.compose-window { max-width: 640px; }

.compose-form {
  padding: 10px;
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
}

.compose-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 8px;
}

.compose-actions .btn-primary { width: auto; padding: 11px 24px; }

/* ============================================================
   Уведомления
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  z-index: 200;
  animation: toast-in .25s ease-out;
  max-width: 90vw;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================================================
   Скроллбары
   ============================================================ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }

/* ============================================================
   Адаптив
   ============================================================ */
@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
  .topbar { padding: 12px 16px; }
  .mail-list-wrap { padding: 12px 16px; }
}

@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .topbar-actions { flex-wrap: wrap; }
  .search-box { min-width: 100%; }
  .modal { padding: 16px; }
  .modal-window { max-height: calc(100vh - 32px); }
}

/* ============================================================
   Панель массовых операций
   ============================================================ */
.bulk-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 0px 13px;
  background: #eef2ff;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-wrap: wrap;
}

.bulk-check {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.bulk-check input { width: 12px; height: 12px; cursor: pointer; display: none}

.bulk-count { color: var(--text-3); }

.bulk-actions {
  display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto;
}

.action-btn.sm { padding: 6px 12px; font-size: 13px; }
.action-btn.primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.action-btn.primary:hover { background: var(--primary-h); border-color: var(--primary-h); }

/* Чекбокс в элементе письма */
.mail-checkbox {
  width: 12px; height: 12px;
  cursor: pointer;
  flex-shrink: 0;
  margin: auto;
}

/* ============================================================
   Инструменты сайдбара
   ============================================================ */
.sidebar-tools {
  display: flex; gap: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.tool-btn {
  flex: 1;
  padding: 8px 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: #c5cde0;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.tool-btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* Кнопка удаления папки */
.folder-item .folder-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  transition: opacity .15s;
}
.folder-item:hover .folder-del { opacity: .7; }
.folder-item .folder-del:hover { opacity: 1; }

/* ============================================================
   Модалки: маленькая / широкая
   ============================================================ */
.modal-window.small { max-width: 420px; }
.modal-window.wide  { max-width: 900px; }

/* ============================================================
   Область вложений при написании
   ============================================================ */
.attach-area {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.attach-list-edit {
  display: flex; flex-direction: column; gap: 6px;
}

.attach-edit-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: 13px;
}

.attach-edit-name {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.attach-edit-size { color: var(--text-3); font-size: 12px; }

.attach-edit-remove {
  background: transparent; border: none;
  color: var(--text-3); cursor: pointer;
  font-size: 16px; padding: 0 4px;
}
.attach-edit-remove:hover { color: var(--danger); }

/* ============================================================
   Фильтры
   ============================================================ */
.filters-body { padding: 20px; overflow-y: auto; max-height: 70vh; }

.filters-list {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 16px;
}

.filter-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.filter-toggle {
  width: 18px; height: 18px;
  cursor: pointer;
}

.filter-info { font-size: 13px; line-height: 1.5; }
.filter-info b { color: var(--text); }
.filter-info .filter-arrow { color: var(--primary); margin: 0 4px; }
.filter-info .filter-folder {
  display: inline-block;
  background: var(--primary); color: #fff;
  padding: 2px 8px; border-radius: 6px; font-size: 12px;
}

.filter-actions { display: flex; gap: 6px; }

/* Форма фильтра */
.filter-form {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 2px solid var(--primary);
}

.filter-form-row {
  display: flex; gap: 10px;
}

.filter-form-row select,
.filter-form-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border-2);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
}

.filter-form-row select:focus,
.filter-form-row input:focus { border-color: var(--primary); }

.filter-form-actions {
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ============================================================
   Список папок в диалоге "переместить"
   ============================================================ */
.move-list {
  padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 60vh; overflow-y: auto;
}

.move-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background .12s, border-color .12s;
}
.move-item:hover {
  background: var(--surface);
  border-color: var(--primary);
}

/* ============================================================
   Кнопка удаления папки в сайдбаре
   ============================================================ */
.folder-item .folder-del-btn {
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.folder-item:hover .folder-del-btn { opacity: .6; }
.folder-item .folder-del-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }

.ws-status {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #8d97ac;
  margin-left: auto; margin-right: 6px;
  transition: background .2s;
}
.ws-status.online {
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}
/* ============================================================
   Вложения в письме
   ============================================================ */
.attach-item {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  transition: border-color .15s, color .15s, background .15s;
  max-width: 100%;
}

.attach-item-audio {
  display: flow; align-items: center; gap: 10px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  transition: border-color .15s, color .15s, background .15s;
  max-width: 100%;
}

.attach-item:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #f6f8ff;
}

.attach-icon { font-size: 18px; }

.attach-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  color: var(--text);
  font-weight: 500;
}

.attach-size { color: var(--text-3); font-size: 11px; }

.attach-actions { display: flex; gap: 4px; margin-left: 4px; }

.attach-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
}

.attach-action:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ============================================================
   Модалка просмотра
   ============================================================ */
.viewer-window {
  max-width: 1000px;
  width: 50vw;
  height: 45vh;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.viewer-toolbar { display: flex; gap: 6px; }

.viewer-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.viewer-content iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 6px;
  background: #fff;
}

.viewer-content pre {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #fff;
  padding: 16px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.viewer-fallback {
  text-align: center;
  color: var(--text-2);
  padding: 40px;
}

.viewer-fallback .icon { font-size: 64px; margin-bottom: 16px; opacity: .6; }
.viewer-fallback .name { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.viewer-fallback .hint { font-size: 13px; color: var(--text-3); margin-bottom: 20px; }
.viewer-fallback .btn-primary { display: inline-flex; padding: 10px 20px; width: auto; }

.viewer-loading {
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

#login-form {
    display: grid;
    gap: 10px;
}

/* ============================================================
   Маленькая кнопка прикрепления файла
   ============================================================ */
.attach-mini-btn {
  flex-shrink: 0;
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: 25px;
  cursor: pointer;
}

.attach-mini-btn:hover {
  color: var(--text-2);
}

/* Поле "Письмо" — флекс-строка: label, кнопка, textarea */
.compose-form textarea {
  display: flex;
  align-items: flex-start;
  gap: 8px;
    width: 100%;
    padding: 6px 10px;
    border: 1.5px solid var(--border-2);
    border-radius: var(--radius);
    background: var(--surface);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

/* Вложения-аудио inline */
.attach-item.attach-inline {
  display: flex;
  flex-direction: column;
  width: 100%;
  align-items: stretch;
  padding: 10px 12px;
  gap: 8px;
}

.attach-inline-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.attach-inline-head .attach-name { flex: 1; }

.attach-audio {
  width: 100%;
  height: 22px;
}

.attach-edit-item.attach-error {
  border-color: var(--danger);
  background: #fff5f5;
}

.attach-total {
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
  margin-top: 4px;
}

.attach-total.attach-error {
  color: var(--danger);
  font-weight: 600;
}

.attach-edit-item.attach-uploading { background: #f5f8ff; }

.attach-progress {
  flex: 1;
  height: 6px;
  background: var(--border-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 0 8px;
}

.attach-progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width .15s ease;
}

.attach-total {
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
  margin-top: 4px;
}

.attach-total.attach-error { color: var(--danger); font-weight: 600; }

/* ============================================================
   Мобильная версия
   ============================================================ */

/* Бургер скрыт на десктопе */
.menu-btn { display: none; }

@media (max-width: 768px) {
  :root { --sidebar-w: 280px; }

  .app {
    grid-template-columns: 1fr;
    position: relative;
    overflow: hidden;
  }

  /* Сайдбар выезжает слева */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
    display: flex !important;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Затемнение под сайдбаром */
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 55;
    opacity: 0;
    transition: opacity .25s ease;
  }

  .sidebar-backdrop.visible {
    display: block;
    opacity: 1;
  }

  /* Контент на всю ширину */
  .content {
    width: 100%;
    height: 100vh;
  }

  /* Топбар — 2 строки: сверху бургер + название, снизу поиск + фильтр */
  .topbar {
    padding: 8px 10px;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
  }

  .menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .menu-btn:hover { background: var(--surface-2); }

  .topbar-title {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar-title h1 {
    font-size: 17px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .search-box {
    flex: 1;
    min-width: 0;
  }

  .search-box input {
    padding: 8px 10px 8px 32px;
    font-size: 14px;
    width: 100%;
  }

  .search-icon {
    left: 10px;
    font-size: 14px;
  }

  .filter-select {
    padding: 8px;
    font-size: 13px;
    max-width: 110px;
    flex-shrink: 0;
  }

  .icon-btn {
    width: 36px; height: 36px;
    font-size: 16px;
    flex-shrink: 0;
   display: none;
  }

  /* Список писем */
  .mail-list-wrap {
    padding: 8px 10px;
  }

  .mail-item {
    padding: 12px 12px;
    gap: 10px;
    grid-template-columns: auto 1fr auto;
  }

  .mail-avatar {
    width: 36px; height: 36px;
    font-size: 14px;
  }

  .mail-from,
  .mail-subject {
    font-size: 13px;
    max-width: 100%;
  }

  .mail-preview { font-size: 12px; }
  .mail-date { font-size: 11px; }

  /* Bulk bar — переносим кнопки */
  .bulk-bar {
    padding: 8px 12px;
    gap: 8px;
  }
  .bulk-actions {
    margin-left: 0;
    width: 100%;
    justify-content: center;
  }
  .action-btn.sm {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Пагинация */
  .pager {
    padding: 8px 12px;
    gap: 10px;
  }
  .pager-btn { padding: 6px 12px; font-size: 13px; }

  /* ============ МОДАЛКИ — компактные, на весь экран ============ */
  .modal {
    padding: 0;
    align-items: center;
  }

  .modal-window {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto;
    max-height: 100vh;
    resize: none;
    margin: 0;
    height: 85vh;
  }

  /* Маленькие модалки (папка, переместить) */
  .modal-window.small {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto;
    max-height: 90vh;
    border-radius: 0;
  }

  /* Широкие модалки (фильтры) */
  .modal-window.wide {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto;
    max-height: 100vh;
    border-radius: 0;
  }

  /* Compose — на весь экран */
  .compose-window {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 85vh;
    max-height: 100vh;
  }

  /* Viewer — 80vh, чтобы видеть контекст */
  .viewer-window {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 85vh;
    max-height: 85vh;
  }

  .viewer-content iframe { height: 100%; }

  .modal-header { cursor: default; }
  .modal-header:active { cursor: default; }

  .modal-subject {
    margin-left: 0;
    font-size: 15px;
  }

  .modal-meta {
    padding: 4px 12px;
    gap: 4px;
  }

  .meta-row { font-size: 13px; }
  .meta-label { width: 44px; }

  .modal-body {
    padding: 1px;
    line-height: 1.4;
  }

  .modal-body p { padding: 6px; }

  .modal-body iframe {
    min-height: 200px;
    height: calc(100% - 4px);
  }

  .modal-attachments {
    padding: 10px 14px;
  }

  .modal-actions {
    padding: 5px 0px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .action-btn {
    padding: 6px 5px;
    font-size: 13px;
  }

  /* Формы */
  .compose-form { padding: 8px; gap: 6px; }

  .field span { min-width: 60px; font-size: 13px; }
  .field input,
  .field textarea { font-size: 14px; }

  .compose-actions {
    flex-direction: column-reverse;
    gap: 6px;
  }
  .compose-actions .btn-primary,
  .compose-actions .action-btn {
    width: 100%;
    padding: 10px;
  }

  /* Вложения */
  .attach-inline-head { flex-wrap: wrap; }
  .attach-audio { width: 100%; }

  .attach-edit-item {
    flex-wrap: wrap;
    gap: 6px;
  }
  .attach-edit-name { font-size: 13px; }

  /* Фильтры */
  .filters-body { padding: 12px; max-height: calc(100vh - 60px); }

  .filter-form-row { flex-wrap: wrap; }
  .filter-form-row select,
  .filter-form-row input {
    min-width: 0;
    padding: 8px 10px;
    font-size: 13px;
  }

  .filter-item {
    grid-template-columns: auto 1fr;
    padding: 10px;
  }
  .filter-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* Затемнение под сайдбаром */
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 55;
    opacity: 0;
    transition: opacity .25s ease;
  }

  .sidebar-backdrop.visible {
    display: block;
    opacity: 1;
  }
}


/*---------------------*/

/* ============================================================
   Dropdown мультиаккаунта
   ============================================================ */
.avatar {
  cursor: pointer;
  transition: transform .1s;
}
.avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 0 0 2px rgba(255,255,255,.3);
}

.accounts-dropdown {
  position: fixed;
  z-index: 300;
  min-width: 220px;
  max-width: 320px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: dd-in .15s ease-out;
}

@keyframes dd-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.accounts-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
  color: var(--text);
  font-size: 14px;
}

.accounts-item:hover { background: var(--surface-2); }
.accounts-item.active { background: #eef2ff; cursor: default; }

.accounts-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  font-size: 13px;
  flex-shrink: 0;
}

.accounts-name { flex: 1; min-width: 0; }

.accounts-user {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accounts-status {
  font-size: 11px;
  color: var(--text-3);
}

.accounts-check {
  color: var(--primary);
  font-weight: 700;
  font-size: 16px;
}

.accounts-remove {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.accounts-remove:hover {
  background: var(--danger);
  color: #fff;
}

.accounts-add {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 10px;
  color: var(--primary);
  font-weight: 600;
}

.accounts-plus {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--primary);
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .accounts-dropdown {
    position: fixed !important;
    left: 10px !important;
    bottom: auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-height: 70vh;
    overflow-y: auto;
    padding: 8px;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,.4);
    animation: dd-in-mobile .2s ease-out;
  }

  @keyframes dd-in-mobile {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .accounts-item {
    padding: 12px 12px;
    gap: 12px;
    font-size: 15px;
    border-radius: 10px;
  }

  .accounts-avatar {
    width: 40px; height: 40px;
    font-size: 15px;
  }

  .accounts-user { font-size: 15px; }
  .accounts-status { font-size: 12px; }
  .accounts-check { font-size: 18px; }

  .accounts-remove {
    font-size: 16px;
    padding: 6px 10px;
    border-radius: 6px;
  }

  .accounts-add {
    padding: 12px;
    font-size: 15px;
  }

  .accounts-plus {
    width: 40px; height: 40px;
    font-size: 22px;
  }
}
