/* ============================================================
   TG Mail — тёмная тема с акцентом
   Поверхности слоями, один акцентный градиент для главных
   действий, цветные аватары для быстрого различения.
   ============================================================ */
:root {
  --bg:         #0b0e14;
  --surface:    #131824;
  --surface-2:  #1a2130;
  --surface-3:  #212a3a;
  --border:     rgba(255, 255, 255, .07);
  --border-2:   rgba(255, 255, 255, .13);

  --text:       #eef1f7;
  --text-2:     #a3adc2;
  --text-3:     #6b7688;

  --accent:     #5b7cfa;
  --accent-2:   #8b5cf6;
  --accent-soft: rgba(91, 124, 250, .14);
  --accent-glow: rgba(91, 124, 250, .32);

  --ok:         #3ddc97;
  --warn:       #f5a524;
  --danger:     #f2555a;
  --danger-soft: rgba(242, 85, 90, .13);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow-2: 0 10px 30px rgba(0, 0, 0, .5);

  --r:    14px;
  --r-sm: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  background:
    radial-gradient(130% 55% at 50% -12%, rgba(91, 124, 250, .13), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: rgba(11, 14, 20, .82);
  backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.tabs {
  display: flex; gap: 3px; flex: 0 1 auto; min-width: 0;
  padding: 3px; border-radius: 12px;
  background: rgba(255, 255, 255, .04);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: 7px 13px; border: none; border-radius: 9px; cursor: pointer;
  background: none; color: var(--text-2);
  font-size: 13px; font-weight: 500; font-family: inherit; white-space: nowrap;
  transition: color .16s, background .16s, box-shadow .16s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 2px 10px var(--accent-glow);
}
.topbar-side { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; margin-left: auto; }
#ver {
  font-size: 10px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); white-space: nowrap;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto;
  border: none; border-radius: 10px; background: none; cursor: pointer;
  color: var(--text-2); font-size: 16px; line-height: 1; font-family: inherit;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.icon-btn:active { background: rgba(255, 255, 255, .11); }

main { padding: 14px; padding-bottom: 48px; max-width: 720px; }

/* ---------- карточки ---------- */
.card {
  background: linear-gradient(180deg, #161c29, #121722);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-1);
}
.card h3 {
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  margin-bottom: 3px; word-break: break-all;
}
.card .meta { color: var(--text-2); font-size: 12.5px; word-break: break-word; }
.card .meta + .meta { margin-top: 4px; }
.meta.err { color: #ff8a8e; }

.card-top { display: flex; align-items: center; gap: 12px; }
.card-top .card-main { flex: 1 1 auto; min-width: 0; }

.avatar {
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; flex: 0 0 auto;
  border-radius: 13px;
  color: #fff; font-size: 17px; font-weight: 600;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35);
  user-select: none;
}
.avatar.sm { width: 36px; height: 36px; border-radius: 11px; font-size: 14px; }

.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 23px; height: 23px; padding: 0 8px; flex: 0 0 auto;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 12px; font-weight: 600;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ---------- статистика ---------- */
.stats { display: flex; gap: 8px; margin: 4px 0 14px; }
.stat {
  flex: 1 1 0; min-width: 0;
  padding: 9px 11px;
  background: rgba(255, 255, 255, .035);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  text-align: center;
}
.stat b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -.02em; }
.stat span { display: block; font-size: 10.5px; color: var(--text-3); margin-top: 1px; }
.stat.warn b { color: var(--warn); }
.stat.ok b { color: var(--ok); }

.empty {
  color: var(--text-3); text-align: center; padding: 64px 20px;
  font-size: 14px; line-height: 1.7; white-space: pre-line;
}

/* ---------- кнопки ---------- */
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.row.tight { margin-top: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
  font-size: 13.5px; font-weight: 500; font-family: inherit;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, filter .15s, opacity .15s, transform .06s;
}
.btn:hover { background: var(--surface-3); border-color: rgba(255, 255, 255, .18); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn.primary, .btn.ok {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn.primary:hover, .btn.ok:hover { filter: brightness(1.1); border-color: transparent; }

.btn.gray { background: none; border-color: transparent; color: var(--text-2); }
.btn.gray:hover { background: rgba(255, 255, 255, .06); color: var(--text); border-color: transparent; }

.btn.danger { background: var(--danger-soft); border-color: rgba(242, 85, 90, .28); color: #ff8a8e; }
.btn.danger:hover { background: rgba(242, 85, 90, .2); border-color: rgba(242, 85, 90, .45); }

.btn.small { height: 31px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }

/* ---------- поля ввода ---------- */
textarea, input, select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-2); border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .28); color: var(--text);
  font-size: 14px; font-family: inherit;
  margin-bottom: 10px;
  transition: border-color .15s, box-shadow .15s;
}
textarea:focus, input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea {
  min-height: 118px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; line-height: 1.6;
}
select { appearance: none; -webkit-appearance: none; }
label { display: block; color: var(--text-2); font-size: 12.5px; margin-bottom: 5px; }

/* ---------- переключатель ---------- */
.switch {
  display: flex; align-items: center; gap: 11px;
  margin-top: 11px; cursor: pointer; font-size: 13.5px; color: var(--text);
}
.switch input {
  appearance: none; -webkit-appearance: none;
  width: 38px; height: 22px; flex: 0 0 auto;
  margin: 0; padding: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .1); border: none;
  position: relative; cursor: pointer;
  transition: background .2s, box-shadow .2s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; opacity: .75;
  transition: transform .2s, opacity .2s;
}
.switch input:checked {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.switch input:checked::after { transform: translateX(16px); opacity: 1; }

/* ---------- список писем ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; margin-bottom: 6px;
  background: linear-gradient(180deg, #151b27, #121722);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color .15s, transform .06s, background .15s;
}
.list-item:hover { border-color: var(--border-2); background: linear-gradient(180deg, #1a2130, #151b27); }
.list-item:active { transform: scale(.995); }
.list-item .li-main { flex: 1 1 auto; min-width: 0; }
.list-item .li-title {
  font-size: 14px; font-weight: 500; letter-spacing: -.01em;
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .li-title.unseen { color: var(--text); font-weight: 600; }
.list-item .li-sub {
  color: var(--text-3); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .li-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  flex: 0 0 auto;
}
.list-item .li-date {
  color: var(--text-3); font-size: 11.5px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------- шапка раздела ---------- */
.back-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.back-row h2 {
  flex: 1 1 auto; min-width: 0;
  font-size: 16px; font-weight: 600; letter-spacing: -.015em;
  word-break: break-all;
}
.search-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search-row input.search-input { flex: 1 1 auto; margin-bottom: 0; }
.search-row .btn { flex: 0 0 auto; }

/* ---------- код и вложения ---------- */
.code-chip {
  padding: 3px 8px; border-radius: 7px;
  border: 1px solid rgba(91, 124, 250, .35);
  background: var(--accent-soft); color: #a9bcff;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
  transition: background .15s, border-color .15s;
}
.code-chip:hover { background: rgba(91, 124, 250, .22); border-color: rgba(91, 124, 250, .55); }

.code-row {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 0; padding: 12px 14px;
  border: 1px solid rgba(91, 124, 250, .28);
  border-radius: var(--r);
  background: linear-gradient(135deg, rgba(91, 124, 250, .12), rgba(139, 92, 246, .08));
}
.code-big {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 22px; font-weight: 600; letter-spacing: .14em;
  font-variant-numeric: tabular-nums; color: #c3cfff;
}
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.attach-row .meta { flex: 1 0 100%; }

/* ---------- письмо ---------- */
.bodybar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0 8px; }
.bodytabs {
  display: inline-flex; padding: 3px; gap: 3px;
  border-radius: 11px; background: rgba(255, 255, 255, .05);
}
.mini {
  height: 30px; padding: 0 14px;
  border: none; border-radius: 8px; background: none; cursor: pointer;
  color: var(--text-2); font-size: 13px; font-weight: 500; font-family: inherit;
  transition: background .15s, color .15s;
}
.mini:hover { color: var(--text); }
.mini.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; box-shadow: 0 2px 10px var(--accent-glow);
}
.theme-btn { border: 1px solid var(--border-2); border-radius: 9px; }
.theme-btn.active { border-color: transparent; }

.bodybox { border-radius: var(--r); }
.mailframe {
  display: block; width: 100%; height: 60vh;
  border: 1px solid var(--border); border-radius: var(--r);
  background: #fff;
}
.modal-body pre {
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 13.5px; line-height: 1.6; color: var(--text-2);
}

/* ---------- заметки к ящику ---------- */
.pw-static {
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .22); color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pw-row { display: flex; gap: 8px; align-items: center; }
.pw-row input.pw-input {
  flex: 1 1 auto; margin-bottom: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px; letter-spacing: .04em;
}
.pw-row .btn { flex: 0 0 auto; padding: 0 13px; }
.pw-opts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 10px 0 14px; }
.pw-len {
  width: 64px; margin-bottom: 0; padding: 6px 8px;
  text-align: center; font-size: 13px;
}
.chip {
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-2); background: none; color: var(--text-3);
  font-size: 12px; font-family: inherit;
  transition: background .15s, border-color .15s, color .15s;
}
.chip.active {
  background: var(--accent-soft); border-color: rgba(91, 124, 250, .45); color: #a9bcff;
}

.note-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.note-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  background: rgba(0, 0, 0, .22);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.note-label { flex: 0 0 60px; color: var(--text-3); font-size: 12px; }
.note-value {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; color: var(--text);
}
.note-value.secret { color: var(--text-2); letter-spacing: .1em; cursor: pointer; }
.note-value.secret.shown { color: var(--text); letter-spacing: normal; }
.note-text { margin-top: 10px; white-space: pre-line; }
.copy-btn { flex: 0 0 auto; }

/* ---------- модальное окно ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 7, 11, .72);
  padding: 14px;
  backdrop-filter: blur(4px);
}
.modal-box {
  display: flex; flex-direction: column;
  width: 100%; max-width: 560px; max-height: 88vh;
  background: linear-gradient(180deg, #171d2a, #121722);
  border: 1px solid var(--border-2);
  border-radius: 18px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14.5px; font-weight: 600; letter-spacing: -.01em;
}
.modal-head > span:first-child { flex: 1 1 auto; min-width: 0; word-break: break-word; }
.modal-body { padding: 16px; overflow-y: auto; }

.hidden { display: none !important; }

/* ---------- уведомление ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  max-width: 90%;
  padding: 11px 18px;
  background: linear-gradient(180deg, #232c3d, #1b2331);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  color: var(--text); font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-2);
  z-index: 100;
}
