.webmail-header-wrapper {
  align-items: center;
  display: flex;
  position: relative;
  z-index: 1050;
}

.webmail-layout {
  align-items: flex-start;
  display: grid;
  gap: 1.25rem;
  grid-template-columns: 190px minmax(0, 1fr);
}

.webmail-main {
  min-width: 0;
  width: 100%;
}

.webmail-bulk-toolbar {
  align-items: center;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  padding: 0.65rem 1rem;
}

.webmail-bulk-toolbar .form-check {
  margin: 0;
}

.webmail-select-row {
  align-items: stretch;
  display: flex;
}

.webmail-select-row-check {
  align-items: center;
  display: flex;
  flex: 0 0 46px;
  justify-content: center;
}

.webmail-select-row .list-group-item {
  border-left: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.webmail-mailbox-nav {
  background: #fff;
  border: 1px solid #e9ecef;
  border-radius: 1rem;
  padding: 0.75rem;
  position: sticky;
  top: 1rem;
}

.webmail-mailbox-nav-title {
  align-items: center;
  color: #212529;
  display: flex;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.75rem;
}

.webmail-compose-button {
  align-items: center;
  background: #d90073;
  border: 1px solid #d90073;
  border-radius: 0.7rem;
  color: #fff;
  display: flex;
  font-size: 0.92rem;
  font-weight: 700;
  gap: 0.55rem;
  justify-content: center;
  margin-bottom: 0.65rem;
  min-height: 44px;
  padding: 0.6rem 0.8rem;
  text-decoration: none;
}

.webmail-compose-button:hover,
.webmail-compose-button:focus-visible,
.webmail-compose-button.active {
  background: #b80062;
  border-color: #b80062;
  color: #fff;
}

.webmail-folder-links {
  display: grid;
  gap: 0.15rem;
}

.webmail-mailbox-nav-link {
  align-items: center;
  border-radius: 0.6rem;
  color: #495057;
  display: flex;
  font-size: 0.88rem;
  font-weight: 500;
  gap: 0.65rem;
  min-height: 38px;
  padding: 0.5rem 0.65rem;
  text-decoration: none;
}

.webmail-mailbox-nav-link i {
  font-size: 1rem;
  text-align: center;
  width: 1.1rem;
}

.webmail-mailbox-nav-link:hover,
.webmail-mailbox-nav-link:focus-visible {
  background: #fff5fa;
  color: #9b145d;
}

.webmail-mailbox-nav-link.active {
  background: #fde8f2;
  color: #9b145d;
  font-weight: 700;
}

.webmail-nav-divider {
  border-top: 1px solid #edf0f3;
  margin: 0.65rem 0;
}

.webmail-contact-autocomplete {
  position: relative;
}

.webmail-contact-suggestions {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.65rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
  left: 0;
  margin-top: 0.3rem;
  max-height: 250px;
  overflow-y: auto;
  position: absolute;
  right: 0;
  z-index: 1060;
}

.webmail-contact-suggestion {
  align-items: center;
  background: #fff;
  border: 0;
  border-bottom: 1px solid #f1f3f5;
  color: #212529;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  text-align: left;
  width: 100%;
}

.webmail-contact-suggestion:last-child {
  border-bottom: 0;
}

.webmail-contact-suggestion small {
  color: #6c757d;
  display: block;
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.webmail-contact-suggestion-email {
  color: #6c757d;
  font-size: 0.8rem;
  text-align: right;
}

.webmail-contact-suggestion:hover,
.webmail-contact-suggestion:focus-visible,
.webmail-contact-suggestion.active {
  background: #fde8f2;
  outline: none;
}

.webmail-contact-suggestion.active {
  box-shadow: inset 3px 0 #d90073;
}

.webmail-address-book-dialog {
  border: 0;
  border-radius: 1rem;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
  max-height: min(720px, calc(100vh - 2rem));
  max-width: min(680px, calc(100vw - 2rem));
  padding: 0;
  width: 100%;
}

.webmail-address-book-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.webmail-address-book-header,
.webmail-address-book-footer {
  align-items: center;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 1rem 1.25rem;
}

.webmail-address-book-header {
  border-bottom: 1px solid #edf0f3;
}

.webmail-address-book-search {
  padding: 1rem 1.25rem 0.75rem;
}

.webmail-address-book-list {
  max-height: min(420px, calc(100vh - 250px));
  min-height: 160px;
  overflow-y: auto;
  padding: 0 1.25rem 1rem;
}

.webmail-address-book-item {
  align-items: center;
  border: 1px solid #e9ecef;
  border-radius: 0.75rem;
  cursor: pointer;
  display: flex;
  gap: 0.8rem;
  margin-bottom: 0.55rem;
  padding: 0.75rem 0.85rem;
}

.webmail-address-book-item:hover {
  background: #fff7fb;
  border-color: #f3c8dc;
}

.webmail-address-book-item-info {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
}

.webmail-address-book-item-info small {
  color: #6c757d;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.webmail-address-book-empty {
  color: #6c757d;
  margin: 0;
  padding: 2rem 1rem;
  text-align: center;
}

.webmail-address-book-footer {
  background: #f8f9fa;
  border-top: 1px solid #edf0f3;
}

.webmail-header-button {
  align-items: center;
  background: #fff5fa;
  border: 1px solid #f3c8dc;
  border-radius: 999px;
  color: #9b145d;
  display: inline-flex;
  font-size: 0.9rem;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.45rem 0.85rem;
}

.webmail-header-button:hover,
.webmail-header-button:focus-visible {
  background: #fde8f2;
}

.webmail-header-badge {
  align-items: center;
  background: #dc3545;
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 700;
  justify-content: center;
  min-width: 1.35rem;
  padding: 0.1rem 0.35rem;
}

.webmail-header-popup {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.85rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  left: auto;
  margin-top: 0;
  max-height: calc(100dvh - 90px);
  overflow: hidden;
  position: absolute;
  right: 0;
  top: calc(100% + 0.55rem);
  transform: none;
  width: min(360px, calc(100vw - 24px));
}

.webmail-header-popup-title {
  align-items: center;
  border-bottom: 1px solid #edf0f3;
  display: flex;
  font-weight: 700;
  justify-content: space-between;
  padding: 0.9rem 1rem;
}

.webmail-header-popup-title > div {
  display: grid;
  gap: 0.1rem;
}

.webmail-header-popup-title small {
  color: #868e96;
  font-size: 0.7rem;
  font-weight: 500;
}

.webmail-header-popup-close {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: #6c757d;
  display: inline-flex;
  flex: 0 0 auto;
  height: 32px;
  justify-content: center;
  margin: -0.4rem -0.45rem -0.4rem 0;
  width: 32px;
}

.webmail-header-popup-close:hover,
.webmail-header-popup-close:focus-visible {
  background: #fde8f2;
  color: #9b145d;
  outline: none;
}

.webmail-header-popup-body {
  max-height: 320px;
  overflow-y: auto;
}

.webmail-header-item {
  border-bottom: 1px solid #f1f3f5;
  color: #212529;
  display: block;
  padding: 0.8rem 1rem;
  text-decoration: none;
}

.webmail-header-item:hover {
  background: #fff7fb;
}

.webmail-header-item.unread .webmail-header-item-subject {
  font-weight: 700;
}

.webmail-header-item-sender,
.webmail-header-item-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.webmail-header-item-sender {
  color: #6c757d;
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.webmail-header-empty {
  color: #6c757d;
  padding: 1.5rem 1rem;
  text-align: center;
}

.webmail-header-popup-actions {
  align-items: center;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
}

.webmail-header-popup-actions a,
.webmail-header-refresh,
.webmail-header-external-link {
  background: transparent;
  border: 0;
  color: #9b145d;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0;
  text-decoration: none;
}

.webmail-header-refresh:hover,
.webmail-header-refresh:focus-visible,
.webmail-header-popup-actions a:hover,
.webmail-header-popup-actions a:focus-visible,
.webmail-header-external-link:hover,
.webmail-header-external-link:focus-visible {
  color: #d90073;
  text-decoration: underline;
}

.webmail-header-external-link {
  display: block;
  margin: 0 1rem 0.9rem;
  text-align: center;
}

.webmail-sync-status {
  color: #6c757d;
  font-size: 0.76rem;
}

@media (max-width: 767.98px) {
  .webmail-layout {
    display: block;
  }

  .webmail-mailbox-nav {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding: 0.45rem;
    position: static;
    scrollbar-width: thin;
  }

  .webmail-mailbox-nav-title,
  .webmail-nav-divider {
    display: none;
  }

  .webmail-compose-button,
  .webmail-mailbox-nav-link {
    flex: 0 0 auto;
    font-size: 0.8rem;
    margin: 0;
    min-height: 38px;
    padding: 0.45rem 0.7rem;
  }

  .webmail-folder-links {
    display: flex;
    gap: 0.35rem;
  }

  .webmail-header-button {
    padding-inline: 0.7rem;
  }

  .webmail-header-popup {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    top: 66px;
    margin-top: 0;
    max-height: calc(100dvh - 78px);
    position: fixed;
    transform: none;
    width: auto;
  }

  .webmail-header-popup-body {
    max-height: calc(100dvh - 178px);
    overscroll-behavior: contain;
  }

  .webmail-bulk-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .webmail-address-book-header,
  .webmail-address-book-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .webmail-address-book-header .btn-close {
    position: absolute;
    right: 1rem;
    top: 1rem;
  }

  .webmail-address-book-footer .d-flex {
    width: 100%;
  }

  .webmail-address-book-footer .btn {
    flex: 1 1 0;
  }
}

/* 휴대폰 가로 모드처럼 화면 높이가 낮을 때도 팝업 상단과 닫기 버튼을 고정 노출한다. */
@media (max-height: 520px) {
  .webmail-header-popup {
    left: 50%;
    right: auto;
    top: calc(54px + env(safe-area-inset-top));
    margin-top: 0;
    max-height: calc(100dvh - 66px - env(safe-area-inset-top));
    position: fixed;
    transform: translateX(-50%);
    width: min(360px, calc(100vw - 20px));
  }

  .webmail-header-popup-body {
    max-height: calc(100dvh - 166px - env(safe-area-inset-top));
    overscroll-behavior: contain;
  }
}
