/* 메일 페이지 — 페이지 전체는 뷰포트에 고정하고 목록만 스크롤 */
@media (min-width: 768px) {
  /* 상단 네비바(고정) 높이만큼만 빼서 content-wrapper를 뷰포트에 맞춘다.
     content-header 높이는 아래 flex 체인이 자동으로 처리하므로 별도 계산 불필요. */
  .content-wrapper.mail-shell {
    height: calc(100vh - 3.5rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  /* sysadmin 역할 미리보기 바(.wrapper padding-bottom:38px)만큼 추가로 뺀다 */
  body.role-debug-active .content-wrapper.mail-shell {
    height: calc(100vh - 3.5rem - 38px);
  }
  .content-wrapper.mail-shell > .content-header {
    flex: 0 0 auto;
  }
  .content-wrapper.mail-shell > .content {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
  }
  .content-wrapper.mail-shell > .content > .container-fluid {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .content-wrapper.mail-shell .mail-page-row {
    flex: 1 1 auto;
    min-height: 0;
  }
  /* 프레임을 스크롤 컨테이너로: 목록은 카드가 100%라 스크롤 없음,
     상세(PJAX로 교체 시)는 내용이 길면 프레임 안에서만 스크롤된다. */
  .content-wrapper.mail-shell .mail-main-col,
  .content-wrapper.mail-shell .mail-sidebar-col {
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
  }
}

.mail-list-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 320px;
  margin-bottom: 0;
}
.mail-list-card > .card-header,
.mail-list-card > .card-footer {
  flex: 0 0 auto;
}
.mail-list-card > #mail-bulk-form.mail-list-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
}
.mail-list-card .mail-list-body > .mail-bulk-bar {
  flex: 0 0 auto;
  margin: 0.75rem 1rem;
}
.mail-list-card .mail-list-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.mail-list-table tbody tr.unread td { font-weight: 700; }
.mail-list-table tbody tr { cursor: pointer; }
/* 목록 헤더 고정 */
.mail-list-scroll .mail-list-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.mail-bulk-bar {
  background: var(--app-surface-muted, #f4f6f9);
  border: 1px solid var(--app-border, #e2e8f0);
  border-radius: 8px;
  padding: 8px 12px;
}
/* 드롭다운 항목 텍스트가 파랗게 선택(하이라이트)되어 보이는 문제 방지 */
.mail-bulk-bar .dropdown-menu { user-select: none; -webkit-user-select: none; }
.mail-bulk-bar .dropdown-item { color: var(--app-text, #1f2d3d); cursor: pointer; }
.mail-bulk-bar .dropdown-item:hover,
.mail-bulk-bar .dropdown-item:focus { background-color: var(--app-row-hover, #eef3fa); color: var(--app-text, #1f2d3d); }
.mail-bulk-bar .dropdown-item:active { background-color: var(--app-border, #e2e8f0); color: var(--app-text, #1f2d3d); }
.mail-bulk-bar .dropdown-item[disabled],
.mail-bulk-bar .dropdown-item:disabled { color: var(--app-text-muted, #6c7a90); cursor: default; }

@media (max-width: 767.98px) {
  .mail-list-card { height: auto; min-height: 0; }
  .mail-list-card .mail-list-scroll { overflow-y: visible; }
}

/* 폴더명 — 목록 카드 헤더 / 상세 공통 */
.mail-folder-caption {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--app-text, #1f2d3d);
  margin: 0 0 0.65rem;
}

/* 다우형 메일 상세 — 목록과 동일한 mail-shell 래퍼 안에서 표시 */
.mail-shell .mail-detail-card,
.mail-view-page .mail-detail-card {
  border: 1px solid var(--app-border, #e2e8f0);
  border-radius: 10px;
  overflow: hidden;
  background: var(--app-surface, #fff);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  margin-bottom: 0;
}

/* 상세도 목록 카드와 같이 프레임 안에서만 스크롤 */
@media (min-width: 768px) {
  .mail-shell.mail-view-page .mail-detail-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
}

.mail-view-toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--app-border, #e2e8f0);
  background: var(--app-surface-muted, #f4f6f9);
}

/* mainStyle.css 의 form{width:100%} 때문에 버튼이 세로로 쌓이던 문제 보정 */
.mail-view-toolbar > form,
.mail-view-toolbar > a.btn,
.mail-view-toolbar > .btn-group {
  width: auto !important;
  max-width: 100%;
  margin: 0;
  flex: 0 0 auto;
}

.mail-view-toolbar > form {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.mail-view-toolbar .btn {
  border-radius: 6px;
  font-size: 0.82rem;
  padding: 0.28rem 0.55rem;
  line-height: 1.35;
  white-space: nowrap;
  /* 목록 툴바와 동일하게 outline-secondary 톤 유지 */
  color: var(--app-text-muted, #6c7a90);
  border-color: var(--app-border, #e2e8f0);
  background-color: var(--app-surface, #fff);
}

.mail-view-toolbar .btn:hover,
.mail-view-toolbar .btn:focus,
.mail-view-toolbar .btn:active,
.mail-view-toolbar .btn.active,
.mail-view-toolbar .show > .btn.dropdown-toggle {
  color: #fff;
  background-color: #6c757d;
  border-color: #6c757d;
  box-shadow: none;
}

.mail-view-toolbar .btn i {
  margin-right: 0.28rem;
}

.mail-view-toolbar .dropdown-menu {
  font-size: 0.85rem;
  min-width: 11rem;
  user-select: none;
  -webkit-user-select: none;
}

.mail-view-toolbar .dropdown-menu form {
  width: 100%;
  margin: 0;
}

.mail-view-toolbar .dropdown-item {
  color: var(--app-text, #1f2d3d);
  cursor: pointer;
}

.mail-view-toolbar .dropdown-item:hover,
.mail-view-toolbar .dropdown-item:focus {
  background-color: var(--app-row-hover, #eef3fa);
  color: var(--app-text, #1f2d3d);
}

.mail-view-toolbar .dropdown-item:active {
  background-color: var(--app-border, #e2e8f0);
  color: var(--app-text, #1f2d3d);
}

.mail-view-toolbar .dropdown-item[disabled],
.mail-view-toolbar .dropdown-item:disabled {
  color: var(--app-text-muted, #6c7a90);
  cursor: default;
}

.mail-view-header {
  padding: 1.05rem 1.15rem 0.85rem;
}

.mail-view-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.mail-view-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--app-text, #1f2d3d);
  line-height: 1.35;
  margin: 0;
  word-break: break-word;
}

.mail-view-title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-shrink: 0;
}

.mail-view-title-actions .btn {
  font-size: 0.78rem;
  padding: 0.15rem 0.45rem;
}

.mail-view-meta {
  display: grid;
  gap: 0.28rem;
}

.mail-view-meta-row {
  display: grid;
  grid-template-columns: 4.8rem minmax(0, 1fr);
  gap: 0.45rem;
  align-items: start;
  font-size: 0.88rem;
}

.mail-view-meta-label {
  color: var(--app-text-muted, #6c7a90);
  padding-top: 0.18rem;
}

.mail-view-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.mail-view-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  background: var(--app-surface-muted, #f4f6f9);
  color: var(--app-text, #1f2d3d);
  border: 1px solid var(--app-border, #e2e8f0);
  font-size: 0.82rem;
  line-height: 1.3;
  word-break: break-all;
}

.mail-view-meta-date {
  color: var(--app-text-muted, #6c7a90);
  padding-top: 0.18rem;
}

.mail-view-attach-bar {
  margin: 0.35rem 1.15rem 0;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  background: var(--app-surface-muted, #f4f6f9);
  border: 1px solid var(--app-border, #e2e8f0);
  color: var(--app-text-muted, #6c7a90);
  font-size: 0.86rem;
}

.mail-view-attach-bar.has-files {
  background: var(--app-accent-soft, #d9e4f5);
  border-color: var(--app-border, #e2e8f0);
  color: var(--app-accent, #214789);
}

.mail-view-attach-list {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
}

.mail-view-attach-list li + li {
  margin-top: 0.25rem;
}

.mail-view-attach-list a {
  color: inherit;
}

.mail-view-body-wrap {
  padding: 1.1rem 1.15rem 1.35rem;
  border-top: 1px solid var(--app-border, #e2e8f0);
  margin-top: 0.85rem;
}

.mail-view-body-wrap .mail-view-body,
.mail-view-body-wrap .mail-view-body-plain {
  font-size: 14px;
  line-height: 1.55;
  color: var(--app-text, #1f2d3d);
  word-break: break-word;
}

.mail-view-body-plain {
  white-space: pre-wrap;
  font-family: inherit;
  margin: 0;
}

@media (max-width: 767.98px) {
  .mail-view-meta-row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
  .mail-view-title {
    font-size: 1.15rem;
  }
  .mail-view-toolbar {
    padding: 0.55rem 0.7rem;
  }
  .mail-view-header,
  .mail-view-body-wrap {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }
  .mail-view-attach-bar {
    margin-left: 0.85rem;
    margin-right: 0.85rem;
  }
}

@media print {
  .main-sidebar,
  .main-header,
  .content-header,
  .mail-sidebar-col,
  .mail-view-toolbar,
  .mail-view-title-actions,
  .mail-view-page .content-wrapper > .content > .container-fluid > .row > .col-auto {
    display: none !important;
  }
  .mail-view-page .mail-main-col,
  .mail-view-page .content-wrapper,
  .mail-view-page .content {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
  }
  .mail-view-page .mail-detail-card {
    border: none;
    box-shadow: none;
  }
}
