/* ══════════════════════════════════════════════════════════
   MAIL — Material Design 3  ·  bsod4ik.ru
   ══════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────── */
:root {
  --md-primary:        #1a73e8;
  --md-primary-cont:   #d3e3fd;
  --md-on-primary:     #fff;
  --md-secondary:      #5f6368;
  --md-surface:        #fff;
  --md-surface-1:      #f0f4ff;
  --md-surface-2:      #e8eaed;
  --md-surface-var:    #f8f9fa;
  --md-on-surface:     #202124;
  --md-on-surface-var: #5f6368;
  --md-outline:        #dadce0;
  --md-outline-var:    #e8eaed;
  --md-error:          #d93025;
  --md-scrim:          rgba(32,33,36,.45);
  --md-shadow:         0 1px 3px rgba(60,64,67,.3), 0 4px 8px rgba(60,64,67,.15);
  --md-shadow-sm:      0 1px 2px rgba(60,64,67,.3);
  --radius-xs:  4px;
  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-full:9999px;
  --nav-w: 256px;
  --topbar-h: 64px;
  --font: 'Google Sans', 'Roboto', system-ui, sans-serif;
  --trans: .2s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --md-primary:        #8ab4f8;
  --md-primary-cont:   #1a3050;
  --md-on-primary:     #0d2040;
  --md-secondary:      #9aa0a6;
  --md-surface:        #202124;
  --md-surface-1:      #2d2e31;
  --md-surface-2:      #35363a;
  --md-surface-var:    #292a2d;
  --md-on-surface:     #e8eaed;
  --md-on-surface-var: #9aa0a6;
  --md-outline:        #3c4043;
  --md-outline-var:    #35363a;
  --md-error:          #f28b82;
  --md-scrim:          rgba(0,0,0,.6);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
* { -webkit-tap-highlight-color: transparent; tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--md-surface);
  color: var(--md-on-surface);
  min-height: 100vh;
  transition: background var(--trans), color var(--trans);
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; }
a { color: var(--md-primary); }
iframe { border: none; }

/* ── Material Symbols ────────────────────────────────────── */
.material-symbols-rounded {
  font-size: 22px;
  line-height: 1;
  vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  user-select: none;
}
.icon-filled { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--md-outline); border-radius: 99px; }

/* ══════════════════════════════════════════════════════════
   LOGIN PAGE
   ══════════════════════════════════════════════════════════ */
.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--md-surface);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--md-surface-1);
  border-radius: var(--radius-xl);
  padding: 40px 36px 36px;
  box-shadow: var(--md-shadow);
  animation: fadeUp .35s cubic-bezier(.4,0,.2,1);
}

@keyframes fadeUp {
  from { opacity:0; transform:translateY(20px); }
  to   { opacity:1; transform:translateY(0); }
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.logo-icon {
  font-size: 52px !important;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 48;
  color: var(--md-primary);
}

.login-title {
  text-align: center;
  font-size: 28px;
  font-weight: 500;
  margin-bottom: 4px;
  letter-spacing: -.5px;
}
.login-sub {
  text-align: center;
  color: var(--md-on-surface-var);
  font-size: 15px;
  margin-bottom: 28px;
}

.login-error {
  background: #fce8e6;
  color: var(--md-error);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
[data-theme="dark"] .login-error { background: #3b1f1d; }

/* MD3 outlined text field */
.field-wrap { margin-bottom: 16px; }
.field-wrap:has(.field-hint) { margin-bottom: 8px; }
.md-field {
  position: relative;
  border: 2px solid var(--md-outline);
  border-radius: var(--radius-sm);
  transition: border-color var(--trans);
}
.md-field:focus-within {
  border-color: var(--md-primary);
}
.md-field input {
  width: 100%;
  padding: 18px 44px 6px 16px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--md-on-surface);
  line-height: 1.2;
}
.md-field label {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--md-on-surface-var);
  font-size: 16px;
  pointer-events: none;
  transition: var(--trans);
  background: var(--md-surface-1);
  padding: 0 2px;
}
.md-field input:not(:placeholder-shown) ~ label,
.md-field input:focus ~ label {
  top: 0;
  font-size: 12px;
  color: var(--md-primary);
}
.eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--md-on-surface-var);
  padding: 4px;
  border-radius: 50%;
  transition: background var(--trans);
}
.eye-btn:hover { background: var(--md-surface-2); }

.btn-filled {
  width: 100%;
  padding: 14px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  border-radius: var(--radius-full);
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background var(--trans), box-shadow var(--trans), transform var(--trans);
  margin-top: 8px;
  min-height: 48px;
  letter-spacing: .3px;
}
.btn-filled:hover { background: #1557b0; box-shadow: var(--md-shadow-sm); }
.btn-filled:active { transform: scale(.98); }
.btn-filled:disabled { opacity: .6; pointer-events: none; }

.btn-spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 14px;
  color: var(--md-on-surface-var);
}
.auth-switch a { color: var(--md-primary); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }
.field-hint {
  font-size: 13px;
  color: var(--md-primary);
  margin-top: 6px;
  margin-bottom: 0;
  padding-left: 4px;
  min-height: 18px;
  line-height: 1.3;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── NAV RAIL ─────────────────────────────────────────────── */
.nav-rail {
  width: var(--nav-w);
  height: 100vh;
  background: var(--md-surface-1);
  border-right: 1px solid var(--md-outline-var);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform var(--trans), background var(--trans);
  z-index: 200;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 8px;
  color: var(--md-primary);
}
.nav-brand-icon {
  font-size: 28px !important;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
.nav-brand-text {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
}

.compose-btn {
  margin: 12px 16px;
  padding: 14px 20px;
  background: var(--md-primary-cont);
  color: var(--md-primary);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: background var(--trans), box-shadow var(--trans);
  box-shadow: var(--md-shadow-sm);
}
.compose-btn:hover {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-shadow);
}
.compose-btn .material-symbols-rounded { font-size: 20px !important; }

.nav-folders { flex: 1; padding: 4px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  height: 52px;
  border-radius: var(--radius-full);
  margin: 1px 8px;
  cursor: pointer;
  color: var(--md-on-surface-var);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--trans), color var(--trans);
  user-select: none;
  position: relative;
}
.nav-item:hover { background: var(--md-surface-2); color: var(--md-on-surface); }
.nav-item.active {
  background: var(--md-primary-cont);
  color: var(--md-primary);
}
.nav-item .material-symbols-rounded { font-size: 20px !important; flex-shrink: 0; }
.nav-item-label { flex: 1; }
.nav-item-badge {
  background: var(--md-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}

.nav-bottom {
  border-top: 1px solid var(--md-outline-var);
  padding: 12px 8px;
  position: relative;
}
.nav-avatar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--trans);
}
.nav-avatar:hover { background: var(--md-surface-2); }
.avatar-circle {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--md-primary);
  color: var(--md-on-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
  flex-shrink: 0;
}
.nav-account-info { overflow: hidden; }
.nav-email {
  font-size: 13px;
  color: var(--md-on-surface-var);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 170px;
}

.user-menu {
  position: absolute;
  bottom: 100%;
  left: 8px; right: 8px;
  background: var(--md-surface);
  border: 1px solid var(--md-outline-var);
  border-radius: var(--radius-md);
  box-shadow: var(--md-shadow);
  overflow: hidden;
  animation: fadeIn .15s ease;
}
.user-menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--md-on-surface);
  transition: background var(--trans);
}
.user-menu button:hover { background: var(--md-surface-1); }

/* ── TOPBAR (mobile) ──────────────────────────────────────── */
.topbar {
  display: none;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 8px;
  gap: 4px;
  background: var(--md-surface);
  border-bottom: 1px solid var(--md-outline-var);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-full);
  background: var(--md-surface-var);
  cursor: text;
  color: var(--md-on-surface-var);
  font-size: 15px;
  margin: 0 4px;
}

/* ── ICON BUTTON ──────────────────────────────────────────── */
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--md-on-surface-var);
  transition: background var(--trans), color var(--trans);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--md-surface-2); color: var(--md-on-surface); }

/* ── MAIN AREA ────────────────────────────────────────────── */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--md-surface);
}

.content-area {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── EMAIL LIST PANE ──────────────────────────────────────── */
.email-list-pane {
  width: 360px;
  flex-shrink: 0;
  border-right: 1px solid var(--md-outline-var);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--md-surface);
  transition: width var(--trans);
}

.list-toolbar {
  display: flex;
  align-items: center;
  padding: 16px 20px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--md-outline-var);
}
.folder-title {
  flex: 1;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.3px;
}
.toolbar-actions { display: flex; gap: 4px; }

.email-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.list-loading {
  display: flex; align-items: center; justify-content: center;
  padding: 60px;
}

/* spinner */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--md-outline);
  border-top-color: var(--md-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.email-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--md-outline-var);
  transition: background var(--trans);
  position: relative;
}
.email-item:hover { background: var(--md-surface-var); }
.email-item.active { background: var(--md-primary-cont); }
.email-item.unread .email-from { font-weight: 700; color: var(--md-on-surface); }
.email-item.unread .email-subject { font-weight: 600; color: var(--md-on-surface); }
.email-item.unread::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--md-primary);
  border-radius: 0 2px 2px 0;
}

.email-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--md-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600;
  color: var(--md-on-surface-var);
  flex-shrink: 0;
  margin-top: 1px;
}

.email-info { flex: 1; min-width: 0; }
.email-row1 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.email-from {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.email-date {
  font-size: 12px;
  color: var(--md-on-surface-var);
  white-space: nowrap;
  flex-shrink: 0;
}
.email-subject {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--md-outline-var);
}
.page-btn {
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--md-primary);
  background: var(--md-surface-1);
  border: 1px solid var(--md-outline);
  transition: background var(--trans);
}
.page-btn:hover { background: var(--md-primary-cont); }
.page-btn:disabled { opacity: .4; pointer-events: none; }
.page-info { font-size: 13px; color: var(--md-on-surface-var); }

/* ── EMAIL READER ─────────────────────────────────────────── */
.email-reader-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--md-surface);
}

.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--md-on-surface-var);
}
.empty-icon {
  font-size: 72px !important;
  opacity: .25;
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 48;
}
.reader-empty p { font-size: 16px; }

.reader-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.reader-toolbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-outline-var);
  gap: 8px;
}
.reader-actions { display: flex; gap: 4px; margin-left: auto; }

.reader-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--md-outline-var);
}
.reader-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--md-primary);
  color: var(--md-on-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 600;
  flex-shrink: 0;
}
.reader-meta { flex: 1; min-width: 0; }
.reader-subject {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.3px;
  margin-bottom: 8px;
  line-height: 1.3;
}
.reader-from {
  font-size: 14px;
  margin-bottom: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.reader-from-email {
  color: var(--md-on-surface-var);
  font-size: 13px;
}
.reader-date { font-size: 13px; color: var(--md-on-surface-var); }

.reader-body-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.reader-iframe {
  flex: 1;
  width: 100%;
  background: var(--md-surface);
}
.reader-text {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 1.7;
  color: var(--md-on-surface);
  white-space: pre-wrap;
}

/* ── DRAWER OVERLAY ───────────────────────────────────────── */
.drawer-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--md-scrim);
  z-index: 150;
  pointer-events: none;
}
.drawer-overlay.open {
  pointer-events: auto;
}
.drawer-overlay.closing {
  display: block;
  pointer-events: auto;
}

/* ── COMPOSE ──────────────────────────────────────────────── */
.compose-overlay {
  position: fixed; inset: 0;
  display: flex;
  align-items: flex-end; justify-content: flex-end;
  padding: 24px;
  z-index: 500;
  background: rgba(0,0,0,0.3);
}
.compose-card {
  width: 540px;
  max-width: 100%;
  background: var(--md-surface);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(0,0,0,.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp .25s cubic-bezier(.4,0,.2,1);
  max-height: 90vh;
}
@keyframes slideUp {
  from { opacity:0; transform:translateY(40px); }
  to   { opacity:1; transform:translateY(0); }
}

.compose-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  background: var(--md-surface-1);
  border-bottom: 1px solid var(--md-outline-var);
  gap: 12px;
}
.compose-title { flex: 1; font-size: 16px; font-weight: 600; }

.compose-fields { border-bottom: 1px solid var(--md-outline-var); }
.compose-field {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--md-outline-var);
}
.compose-field:last-child { border-bottom: none; }
.compose-field label { font-size: 14px; color: var(--md-on-surface-var); min-width: 40px; }
.compose-field input {
  flex: 1;
  border: none; outline: none;
  background: transparent;
  font-size: 15px;
  color: var(--md-on-surface);
}
.compose-field input:-webkit-autofill,
.compose-field input:-webkit-autofill:hover,
.compose-field input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--md-surface) inset !important;
  -webkit-text-fill-color: var(--md-on-surface) !important;
  transition: background-color 9999s ease-in-out 0s;
}

.compose-body {
  flex: 1;
  min-height: 200px;
  padding: 16px 20px;
  border: none; outline: none;
  background: transparent;
  color: var(--md-on-surface);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
}

.compose-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--md-outline-var);
}
.compose-send {
  width: auto;
  padding: 10px 24px;
  font-size: 14px;
}
.compose-send .material-symbols-rounded { font-size: 18px !important; }

.mobile-compose-fab {
  display: none;
}

/* ── TOAST ────────────────────────────────────────────────── */
/* ── CONFIRM DIALOG ──────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: var(--md-scrim);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}
.confirm-card {
  background: var(--md-surface);
  border-radius: var(--radius-xl);
  padding: 28px 24px 20px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: var(--md-shadow);
  animation: fadeUp .2s cubic-bezier(.4,0,.2,1);
}
.confirm-icon {
  font-size: 40px !important;
  color: var(--md-error);
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 40;
  margin-bottom: 12px;
  display: block;
}
.confirm-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--md-on-surface);
  margin-bottom: 24px;
  line-height: 1.4;
}
.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.confirm-btn-cancel {
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  color: var(--md-on-surface-var);
  background: transparent;
  transition: background var(--trans);
}
.confirm-btn-cancel:hover { background: var(--md-surface-2); }
.confirm-btn-ok {
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--md-error);
  transition: background var(--trans);
}
.confirm-btn-ok:hover { background: #b0261e; }

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--md-on-surface);
  color: var(--md-surface);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: transform .3s cubic-bezier(.4,0,.2,1), opacity .3s;
  white-space: nowrap;
  box-shadow: var(--md-shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── EMPTY STATE ──────────────────────────────────────────── */
.empty-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 24px;
  color: var(--md-on-surface-var);
  text-align: center;
}
.empty-list .material-symbols-rounded {
  font-size: 56px !important;
  opacity: .3;
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 48;
}
.empty-list p { font-size: 15px; }

/* ── ANIMATIONS ───────────────────────────────────────────── */
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes mdFadeScale {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes mdSlideInLeft {
  from { transform: translateX(-105%); }
  to { transform: translateX(0); }
}
@keyframes mdSheetUp {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes mdReaderIn {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes mdReaderOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(22px); }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  (≤ 768px)
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root {
    --topbar-h: 72px;
    --mobile-gutter: 12px;
    --mobile-bottom-safe: max(16px, env(safe-area-inset-bottom));
  }

  html,
  body {
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    background: var(--md-surface-var);
    overscroll-behavior: none;
  }

  .app {
    height: auto;
    min-height: 100dvh;
    background: var(--md-surface-var);
    max-width: 100vw;
    overflow-x: hidden;
    overflow-y: auto;
  }
  html::-webkit-scrollbar:horizontal,
  body::-webkit-scrollbar:horizontal,
  .app::-webkit-scrollbar:horizontal,
  .main-area::-webkit-scrollbar:horizontal,
  .content-area::-webkit-scrollbar:horizontal,
  .email-list-pane::-webkit-scrollbar:horizontal,
  .email-list::-webkit-scrollbar:horizontal {
    width: 0;
    height: 0;
    display: none;
  }

  .nav-rail {
    position: fixed;
    left: 0;
    top: 0;
    width: min(86vw, 328px);
    max-width: 328px;
    height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) 10px var(--mobile-bottom-safe);
    background: var(--md-surface);
    border-right: none;
    border-radius: 0 28px 28px 0;
    transform: translateX(-100%);
    box-shadow: 0 16px 44px rgba(60,64,67,.28);
    transition: transform .36s cubic-bezier(.2,0,0,1), box-shadow var(--trans);
    z-index: 220;
  }
  .nav-rail.open {
    transform: translateX(0);
  }
  .drawer-overlay.open {
    display: block;
  }
  .drawer-overlay.closing {
    display: block;
    background: transparent;
  }

  .nav-brand {
    padding: 14px 14px 8px;
  }
  .nav-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--md-primary-cont);
    color: var(--md-primary);
  }
  .nav-brand-text {
    font-size: 24px;
  }
  .compose-btn {
    margin: 12px 6px 14px;
    height: 56px;
    border-radius: 18px;
    justify-content: center;
    box-shadow: none;
  }
  .nav-folders {
    padding: 4px 0;
  }
  .nav-item {
    height: 50px;
    margin: 3px 0;
    padding: 0 14px;
    border-radius: 25px;
    font-size: 15px;
  }
  .nav-item .material-symbols-rounded {
    font-size: 23px !important;
    font-variation-settings: 'FILL' 0, 'wght' 450, 'GRAD' 0, 'opsz' 24;
  }
  .nav-item.active .material-symbols-rounded {
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24;
  }
  .nav-bottom {
    padding: 12px 4px 0;
  }
  .nav-avatar {
    min-height: 56px;
    padding: 10px 12px;
    border-radius: 18px;
    background: var(--md-surface-var);
  }
  .avatar-circle {
    width: 40px;
    height: 40px;
  }
  .user-menu {
    left: 4px;
    right: 4px;
    border-radius: 18px;
  }

  .topbar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--topbar-h);
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    gap: 8px;
    background: color-mix(in srgb, var(--md-surface) 92%, transparent);
    border-bottom: none;
    box-shadow: 0 1px 0 var(--md-outline-var);
    backdrop-filter: blur(18px);
  }
  .topbar .icon-btn {
    width: 48px;
    height: 48px;
    color: var(--md-on-surface);
  }
  .topbar .icon-btn .material-symbols-rounded,
  .reader-toolbar .icon-btn .material-symbols-rounded,
  .compose-header .icon-btn .material-symbols-rounded,
  .compose-footer .icon-btn .material-symbols-rounded {
    font-size: 24px !important;
    font-variation-settings: 'FILL' 0, 'wght' 450, 'GRAD' 0, 'opsz' 24;
  }
  .topbar-search {
    min-width: 0;
    height: 48px;
    padding: 0 8px 0 16px;
    margin: 0;
    gap: 10px;
    border-radius: 24px;
    background: var(--md-surface);
    color: var(--md-on-surface);
    box-shadow: inset 0 0 0 1px var(--md-outline-var);
    font-size: 16px;
    font-weight: 500;
    cursor: text;
    transition: background var(--trans), box-shadow var(--trans), transform var(--trans);
  }
  .topbar-search:focus-within {
    background: color-mix(in srgb, var(--md-primary-cont) 28%, var(--md-surface));
    box-shadow: inset 0 0 0 2px var(--md-primary);
  }
  .topbar-search .material-symbols-rounded {
    color: var(--md-on-surface-var);
    flex-shrink: 0;
  }
  .topbar-search input {
    width: 100%;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--md-on-surface);
    font: inherit;
    font-weight: 500;
    caret-color: var(--md-primary);
    -webkit-appearance: none;
    appearance: none;
  }
  .topbar-search input::placeholder {
    color: var(--md-on-surface-var);
    opacity: 1;
    font-weight: 500;
  }
  .topbar-search input::-webkit-search-cancel-button {
    display: none;
  }
  .search-clear {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--md-on-surface-var);
    flex-shrink: 0;
  }
  .search-clear .material-symbols-rounded {
    font-size: 20px !important;
  }
  .topbar-search.has-value .search-clear {
    display: inline-flex;
  }
  .search-clear:active {
    background: color-mix(in srgb, var(--md-on-surface) 10%, transparent);
  }
  #topbarTitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: none;
  }

  .main-area {
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--md-surface-var);
    scrollbar-width: none;
    padding-top: 0;
  }
  .main-area::-webkit-scrollbar { display: none; }
  *::-webkit-scrollbar:horizontal {
    height: 0 !important;
    display: none !important;
  }

  .content-area {
    flex-direction: column;
    min-height: calc(100dvh - var(--topbar-h));
    height: auto;
    padding-top: 0;
    padding-left: var(--mobile-gutter);
    padding-right: var(--mobile-gutter);
    padding-bottom: calc(88px + var(--mobile-bottom-safe));
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .email-list-pane {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: calc(100dvh - var(--topbar-h));
    border-right: none;
    border-bottom: none;
    background: transparent;
    overflow-x: hidden;
  }
  .list-toolbar {
    padding: 14px 2px 10px;
    padding-top: calc(var(--topbar-h) + 14px);
    border-bottom: none;
  }
  .folder-title {
    font-size: 28px;
    line-height: 1.15;
    letter-spacing: 0;
  }
  .toolbar-actions .icon-btn {
    width: 44px;
    height: 44px;
    background: var(--md-surface);
    box-shadow: inset 0 0 0 1px var(--md-outline-var);
  }
  .email-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 12px;
    overflow: visible;
  }
  .email-item {
    align-items: center;
    min-height: 76px;
    padding: 14px;
    border-bottom: none;
    border-radius: 20px;
    background: var(--md-surface);
    box-shadow: inset 0 0 0 1px var(--md-outline-var);
    transition: transform .18s cubic-bezier(.2,0,0,1), background var(--trans), box-shadow var(--trans);
    animation: mdFadeScale .24s cubic-bezier(.2,0,0,1);
  }
  .email-item:hover {
    background: var(--md-surface);
  }
  .email-item:active {
    transform: scale(.985);
  }
  .email-item.active {
    background: var(--md-primary-cont);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-primary) 24%, transparent);
  }
  .email-item.unread {
    background: color-mix(in srgb, var(--md-primary-cont) 34%, var(--md-surface));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--md-primary) 18%, var(--md-outline-var));
  }
  .email-item.unread::before {
    left: auto;
    right: 14px;
    top: 18px;
    bottom: auto;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--md-primary);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--md-primary) 12%, transparent);
  }
  .email-item.unread .email-date {
    padding-right: 18px;
    color: var(--md-primary);
    font-weight: 600;
  }
  .email-avatar {
    width: 44px;
    height: 44px;
    font-size: 16px;
    margin-left: 2px;
  }
  .email-row1 {
    align-items: center;
    margin-bottom: 5px;
  }
  .email-from {
    font-size: 15px;
  }
  .email-date {
    font-size: 12px;
  }
  .email-subject {
    font-size: 14px;
    color: var(--md-on-surface-var);
  }
  .list-pagination:not(:empty) {
    margin: 8px 0 0;
    padding: 10px;
    border-top: none;
    border-radius: 18px;
    background: var(--md-surface);
  }
  .page-btn {
    min-height: 40px;
    padding: 8px 16px;
  }

  .email-reader-pane {
    position: fixed;
    inset: 0;
    z-index: 320;
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: var(--md-surface);
  }
  .email-reader-pane.open {
    display: flex;
    animation: mdReaderIn .26s cubic-bezier(.2,0,0,1);
  }
  .email-reader-pane.closing {
    display: flex;
    pointer-events: none;
    animation: mdReaderOut .22s cubic-bezier(.4,0,1,1) forwards;
  }
  .reader-content {
    background: var(--md-surface);
  }
  .reader-toolbar {
    min-height: 64px;
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
    border-bottom: none;
    background: color-mix(in srgb, var(--md-surface) 94%, transparent);
    box-shadow: 0 1px 0 var(--md-outline-var);
    backdrop-filter: blur(18px);
  }
  .reader-toolbar .icon-btn {
    width: 44px;
    height: 44px;
  }
  .reader-actions {
    gap: 2px;
  }
  .reader-header {
    padding: 18px 16px 16px;
    gap: 12px;
    border-bottom: 1px solid var(--md-outline-var);
  }
  .reader-avatar {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  .reader-subject {
    font-size: 20px;
    line-height: 1.25;
    letter-spacing: 0;
    margin-bottom: 10px;
  }
  .reader-from {
    font-size: 14px;
    line-height: 1.35;
  }
  .reader-from-email,
  .reader-date {
    font-size: 12px;
  }
  .reader-text {
    padding: 20px 16px calc(24px + var(--mobile-bottom-safe));
    font-size: 16px;
    line-height: 1.65;
  }
  .reader-iframe {
    min-height: 100%;
  }

  .compose-overlay {
    padding: 0;
    align-items: flex-end;
    background: rgba(32,33,36,.42);
    animation: fadeIn .18s ease;
  }
  .compose-card {
    width: 100%;
    max-height: min(86dvh, 720px);
    border-radius: 28px 28px 0 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 36px rgba(0,0,0,.24);
    animation: mdSheetUp .32s cubic-bezier(.2,0,0,1);
  }
  .compose-header {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-shrink: 0;
    min-height: 64px;
    padding: 22px 18px 14px;
    background: var(--md-surface);
    border-bottom: 1px solid var(--md-outline-var);
  }
  .compose-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    width: 40px;
    height: 4px;
    border-radius: 99px;
    background: var(--md-outline);
    transform: translateX(-50%);
  }
  .compose-title {
    font-size: 18px;
    letter-spacing: 0;
  }
  .compose-fields {
    border-bottom: 1px solid var(--md-outline-var);
    background: var(--md-surface);
  }
  .compose-field {
    padding: 14px 18px;
    gap: 12px;
  }
  .compose-field label {
    min-width: 48px;
    font-size: 13px;
  }
  .compose-field input {
    font-size: 16px;
    min-width: 0;
  }
  .compose-body {
    min-height: 180px;
    padding: 18px;
    font-size: 16px;
    line-height: 1.55;
  }
  .compose-footer {
    position: sticky;
    bottom: 0;
    flex-shrink: 0;
    padding: 12px 16px calc(12px + var(--mobile-bottom-safe));
    background: var(--md-surface);
    border-top: 1px solid var(--md-outline-var);
  }
  .compose-send {
    min-width: 136px;
    min-height: 48px;
    border-radius: 24px;
    padding: 12px 22px;
  }
  .compose-footer .icon-btn {
    width: 48px;
    height: 48px;
    margin-left: auto;
    background: var(--md-surface-var);
  }

  .mobile-compose-fab {
    position: fixed;
    right: 18px;
    bottom: calc(18px + var(--mobile-bottom-safe));
    z-index: 140;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background: var(--md-primary-cont);
    color: var(--md-primary);
    box-shadow: 0 8px 20px rgba(60,64,67,.24), 0 2px 6px rgba(60,64,67,.16);
    transition: transform .18s cubic-bezier(.2,0,0,1), box-shadow var(--trans), background var(--trans);
  }
  .mobile-compose-fab .material-symbols-rounded {
    font-size: 28px !important;
    font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 28;
  }
  .mobile-compose-fab:active {
    transform: scale(.94);
    box-shadow: 0 4px 12px rgba(60,64,67,.2);
  }

  #backBtn { display: flex; }

  .toast {
    bottom: calc(88px + var(--mobile-bottom-safe));
    max-width: calc(100vw - 32px);
    white-space: normal;
    text-align: center;
    border-radius: 18px;
  }

  .empty-list {
    min-height: 52dvh;
    margin: 8px 0;
    border-radius: 24px;
    background: var(--md-surface);
  }
}

@media (max-width: 420px) {
  .folder-title {
    font-size: 25px;
  }
  .topbar {
    padding-left: 8px;
    padding-right: 8px;
  }
  .topbar-search {
    padding: 0 12px;
    font-size: 15px;
  }
  .content-area {
    padding-left: 8px;
    padding-right: 8px;
  }
  .email-item {
    border-radius: 18px;
    padding: 12px;
    gap: 10px;
  }
  .email-avatar {
    width: 40px;
    height: 40px;
  }
  .reader-subject {
    font-size: 18px;
  }
  .mobile-compose-fab {
    right: 14px;
    width: 60px;
    height: 60px;
  }
}

@media (min-width: 769px) {
  #backBtn { display: none; }
  .email-reader-pane { display: flex !important; }
}

/* ── TABLET ─────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1100px) {
  :root { --nav-w: 220px; }
  .email-list-pane { width: 300px; }
}
