
/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #5865F2;
  --accent-dark: #4752C4;
  --bg: #ffffff;
  --bg2: #F4F4F5;
  --bg3: #E4E4E7;
  --text: #18181B;
  --text2: #71717A;
  --border: #E4E4E7;
  --radius: 14px;
  --nav-h: 64px;
  --top-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18181B;
    --bg2: #27272A;
    --bg3: #3F3F46;
    --text: #FAFAFA;
    --text2: #A1A1AA;
    --border: #3F3F46;
  }
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; }

/* ===== АНИМАЦИИ ===== */
@keyframes fadeUp   { from { opacity:0; transform:translateY(12px) } to { opacity:1; transform:translateY(0) } }
@keyframes fadeIn   { from { opacity:0 } to { opacity:1 } }
@keyframes spin     { to { transform: rotate(360deg) } }
@keyframes pulse    { 0%,100%{opacity:1} 50%{opacity:.4} }
@keyframes slideDown{ from { opacity:0; transform:translateY(-8px) } to { opacity:1; transform:translateY(0) } }
@keyframes toastIn  { from { opacity:0; transform:translateX(-50%) translateY(12px) } to { opacity:1; transform:translateX(-50%) translateY(0) } }

/* ===== ЭКРАНЫ ===== */
.screen {
  position: fixed; inset: 0; bottom: var(--nav-h);
  display: none; flex-direction: column;
  background: var(--bg); overflow: hidden;
}
.screen.active { display: flex; animation: fadeIn .2s ease; }

/* ===== TOPBAR ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; height: var(--top-h); flex-shrink: 0;
  background: var(--accent); color: #fff;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 4px; }
.topbar-title { font-size: 17px; font-weight: 500; flex: 1; padding: 0 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.15); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .15s;
}
.icon-btn:hover  { background: rgba(255,255,255,.25); }
.icon-btn:active { transform: scale(.9); }
.back-btn { background: rgba(255,255,255,.15); }

/* ===== АККАУНТЫ ПАНЕЛЬ ===== */
.accounts-panel {
  background: var(--bg); border-bottom: 1px solid var(--border);
  animation: slideDown .2s ease; overflow: hidden;
}
.accounts-panel.hidden { display: none; }
.account-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; transition: background .15s;
}
.account-row:hover { background: var(--bg2); }
.account-row.active { background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.account-dot {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 500; color: #fff; flex-shrink: 0;
}
.account-info { flex: 1; }
.account-email { font-size: 14px; font-weight: 500; color: var(--text); }
.account-provider { font-size: 12px; color: var(--text2); }
.account-unread { background: var(--accent); color: #fff; font-size: 11px; border-radius: 10px; padding: 2px 7px; }
.add-account-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; width: 100%; border: none; background: none;
  color: var(--accent); font-size: 14px; cursor: pointer; font-weight: 500;
  border-top: 1px solid var(--border);
}
.avatar-sm { width: 22px; height: 22px; border-radius: 6px; background: rgba(255,255,255,.3); display: block; }

/* ===== ПАПКИ ===== */
.folders-row {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
}
.folders-row::-webkit-scrollbar { display: none; }
.folder-tab {
  flex-shrink: 0; padding: 10px 14px; font-size: 13px;
  color: var(--text2); background: none; border: none;
  border-bottom: 2px solid transparent; cursor: pointer;
  transition: color .2s, border-color .2s; white-space: nowrap;
}
.folder-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 17px; border-radius: 10px;
  background: #E24B4A; color: #fff; font-size: 10px;
  font-weight: 600; padding: 0 4px; margin-left: 4px;
}
.badge:empty { display: none; }

/* ===== ПОИСК ===== */
.search-bar { padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-bar.hidden { display: none; }
.search-inner {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border-radius: 12px; padding: 8px 12px;
  border: 1px solid transparent; transition: border-color .2s;
}
.search-inner:focus-within { border-color: var(--accent); }
.search-inner svg { color: var(--text2); flex-shrink: 0; }
.search-inner input { flex: 1; border: none; background: none; font-size: 14px; color: var(--text); outline: none; }
.search-inner .icon-btn { background: none; color: var(--text2); width: 24px; height: 24px; font-size: 13px; }

/* ===== СПИСОК ПИСЕМ ===== */
.email-list { flex: 1; overflow-y: auto; }
.email-item {
  display: flex; gap: 11px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .15s; animation: fadeUp .3s ease both;
}
.email-item:hover  { background: var(--bg2); }
.email-item:active { background: var(--bg3); }
.email-avatar {
  width: 42px; height: 42px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 500; flex-shrink: 0; color: #fff;
}
.email-body { flex: 1; min-width: 0; }
.email-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.email-sender { font-size: 14px; color: var(--text); }
.email-sender.bold { font-weight: 600; }
.email-time { font-size: 11px; color: var(--text2); flex-shrink: 0; margin-left: 8px; }
.email-subject { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-subject.bold { font-weight: 500; }
.email-preview { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.unread-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  flex-shrink: 0; margin-top: 6px; animation: pulse 2s ease-in-out infinite;
}

.loader { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 20px; color: var(--text2); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--text2); }
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ===== ЧТЕНИЕ ПИСЬМА ===== */
.email-content { flex: 1; overflow-y: auto; padding: 16px; }
.email-header { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.email-header h1 { font-size: 18px; font-weight: 600; margin-bottom: 12px; line-height: 1.3; }
.email-meta { display: flex; align-items: center; gap: 10px; }
.email-meta-avatar { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 500; color: #fff; flex-shrink: 0; }
.email-meta-info .from { font-size: 14px; font-weight: 500; }
.email-meta-info .date { font-size: 12px; color: var(--text2); margin-top: 2px; }
.email-body-text { font-size: 14px; line-height: 1.7; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.email-body-html { font-size: 14px; line-height: 1.6; }
.reply-bar { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); flex-shrink: 0; }
.reply-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px; border-radius: 12px; font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; transition: all .2s;
  background: var(--accent); color: #fff;
}
.reply-btn:hover  { background: var(--accent-dark); transform: translateY(-1px); }
.reply-btn:active { transform: scale(.97); }
.reply-btn.secondary { background: var(--bg2); color: var(--text); }
.reply-btn.secondary:hover { background: var(--bg3); }

/* ===== НАПИСАТЬ ПИСЬМО ===== */
.compose-form { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.compose-field { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.compose-field label { font-size: 13px; color: var(--text2); width: 50px; flex-shrink: 0; }
.compose-field input, .compose-field select {
  flex: 1; border: none; background: none; font-size: 15px; color: var(--text);
  outline: none; padding: 0 4px;
}
.compose-divider { height: 1px; background: var(--border); }
#compose-body { flex: 1; padding: 16px; font-size: 15px; color: var(--text); border: none; background: none; outline: none; resize: none; line-height: 1.6; min-height: 200px; }
.send-btn {
  padding: 8px 16px; background: rgba(255,255,255,.2); color: #fff;
  border: none; border-radius: 20px; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .2s;
}
.send-btn:hover  { background: rgba(255,255,255,.3); }
.send-btn:active { transform: scale(.95); }

/* ===== ДОБАВИТЬ ЯЩИК ===== */
.add-account-screen { flex: 1; overflow-y: auto; padding: 16px; }
.add-account-hint { font-size: 13px; color: var(--text2); margin-bottom: 12px; padding: 0 4px; }
.provider-list { display: flex; flex-direction: column; gap: 8px; }
.provider-btn {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--bg2); border-radius: var(--radius); border: 1px solid var(--border);
  cursor: pointer; text-align: left; transition: all .2s; width: 100%;
}
.provider-btn:hover  { border-color: var(--accent); transform: translateY(-1px); }
.provider-btn:active { transform: scale(.98); }
.provider-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.provider-name { font-size: 14px; font-weight: 500; color: var(--text); }
.provider-sub  { font-size: 12px; color: var(--text2); margin-top: 2px; }
.chevron { color: var(--text2); margin-left: auto; }
.imap-form { margin-top: 16px; padding: 16px; background: var(--bg2); border-radius: var(--radius); border: 1px solid var(--border); }
.imap-form.hidden { display: none; }
.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; font-weight: 500; }
.form-field input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg);
  font-size: 14px; color: var(--text); outline: none; transition: border-color .2s;
}
.form-field input:focus { border-color: var(--accent); }
.form-error { background: #FEE2E2; color: #991B1B; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.form-error.hidden { display: none; }
.submit-btn {
  width: 100%; padding: 13px; background: var(--accent); color: #fff;
  border: none; border-radius: 12px; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.submit-btn:hover  { background: var(--accent-dark); transform: translateY(-1px); }
.submit-btn:active { transform: scale(.97); }
.submit-btn:disabled { opacity: .6; pointer-events: none; }
.imap-extra-fields { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
#imap-extra.hidden { display: none; }

/* ===== НИЖНЯЯ НАВИГАЦИЯ ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h); display: flex;
  background: var(--bg); border-top: 1px solid var(--border);
  z-index: 100;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; border: none; background: none;
  color: var(--text2); cursor: pointer; font-size: 10px;
  transition: color .15s; padding: 6px 0;
}
.nav-btn svg { transition: transform .2s; }
.nav-btn:hover svg { transform: scale(1.1); }
.nav-btn:active svg { transform: scale(.9); }
.nav-btn.active { color: var(--accent); }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%;
  transform: translateX(-50%); background: #18181B; color: #fff;
  padding: 10px 20px; border-radius: 20px; font-size: 14px;
  z-index: 200; white-space: nowrap;
  animation: toastIn .3s ease;
}
.toast.hidden { display: none; }
