html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(var(--brand-rgb), .6);
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}
/* ---------- message view (Email/View) ---------- */
.mail-view { max-width: 960px; }

/* Wraps onto a second row rather than pushing buttons off screen. */
.mail-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin-bottom: .75rem;
}
.mail-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .375rem;
  margin-left: auto;
}
.mail-toolbar-actions form { margin: 0; }
/* Comfortable tap targets on phones. */
@media (max-width: 767.98px) {
  .mail-toolbar .btn { min-width: 2.5rem; min-height: 2.25rem; }
}

.mail-subject {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 .875rem;
  overflow-wrap: anywhere;
}
@media (min-width: 768px) {
  .mail-subject { font-size: 1.6rem; }
}

.mail-meta {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding-bottom: .875rem;
  margin-bottom: .875rem;
  border-bottom: 1px solid var(--bs-border-color);
}
.mail-avatar {
  flex: 0 0 2.5rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  background: var(--bs-primary-bg-subtle);
  color: var(--bs-primary-text-emphasis);
}
.mail-meta-text { flex: 1 1 auto; min-width: 0; }
.mail-meta-line { display: flex; align-items: baseline; gap: .5rem; }
.mail-sender {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-date {
  margin-left: auto;
  flex-shrink: 0;
  font-size: .8125rem;
  color: var(--bs-secondary-color);
}
.mail-address {
  font-size: .8125rem;
  color: var(--bs-secondary-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-attachments { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .875rem; }
.mail-attachment {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  max-width: 100%;
  padding: .375rem .625rem;
  border: 1px solid var(--bs-border-color);
  border-radius: .5rem;
  color: var(--bs-body-color);
  text-decoration: none;
  font-size: .875rem;
}
.mail-attachment:hover { background: var(--bs-tertiary-bg); }
.mail-attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* HTML mail is authored for a white page — keep it on one in dark mode too. */
.mail-html {
  background: #fff;
  border-radius: .5rem;
  padding: .75rem;
  overflow: hidden;
}
.mail-html iframe { display: block; width: 100%; min-height: 200px; border: 0; }
@media (max-width: 575.98px) {
  .mail-html { padding: .5rem; border-radius: .375rem; }
}

.mail-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  font-size: 1rem;
  margin: 0;
}

.mail-footer-actions { display: flex; gap: .5rem; margin: 1.25rem 0 0; }
@media (max-width: 575.98px) {
  .mail-footer-actions .btn { flex: 1 1 0; }
}

.mail-thread { margin-top: 1.5rem; }

/* ---------- folder lists on phones (Inbox, Sent, Spam, Drafts, Search) ----------
   The desktop table becomes a two-line mail-app list: sender + date, then subject +
   delete. The whole row opens the message; the folder sidebar becomes a swipeable strip. */
@media (max-width: 767.98px) {
  .mail-folders {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: .375rem;
    overflow-x: auto;
    margin-bottom: .75rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .mail-folders::-webkit-scrollbar { display: none; }
  .mail-folders .list-group-item {
    flex: 0 0 auto;
    width: auto !important; /* list-group-item-action forces 100% */
    display: flex;
    align-items: center;
    gap: .375rem;
    white-space: nowrap;
    padding: .375rem .875rem;
    border-width: 1px !important;
    border-radius: 999px !important;
    margin: 0 !important;
  }

  .mail-list thead { display: none; }
  .mail-list, .mail-list tbody { display: block; width: 100%; }
  .mail-list tr {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: .75rem;
    row-gap: .125rem;
    align-items: center;
    padding: .625rem .75rem;
    border-bottom: 1px solid var(--bs-border-color);
  }
  .mail-list td {
    display: block;
    width: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    min-width: 0;
  }
  /* sender */
  .mail-list td:nth-child(1) { grid-column: 1; grid-row: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* date */
  .mail-list td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; font-size: .75rem; white-space: nowrap; }
  /* subject */
  .mail-list td:nth-child(2) { grid-column: 1; grid-row: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--bs-secondary-color); }
  .mail-list tr.fw-semibold td:nth-child(2) { color: var(--bs-body-color); }
  /* actions: the row itself opens the message, so only delete stays */
  .mail-list td:nth-child(4) { grid-column: 2; grid-row: 2; text-align: right; position: relative; z-index: 1; }
  .mail-list td:nth-child(4) a.btn { display: none; }
  .mail-list td:nth-child(4) .btn { padding: .125rem .4rem; font-size: .8rem; }
  /* Stretch the subject link over the whole row as the tap target. */
  .mail-list td:nth-child(2) a::after { content: ""; position: absolute; inset: 0; }
}

/* ---------- email signature (Signature/Index, Compose) ---------- */
.signature-layouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.signature-layouts .btn { font-size: .8125rem; padding: .625rem .25rem; }
.signature-thumb {
  flex: 0 0 auto;
  width: 4.5rem;
  height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .25rem;
  background: #fff;
  border: 1px solid var(--bs-border-color);
  border-radius: .5rem;
}
.signature-thumb img { max-width: 100%; max-height: 100%; }
/* Sized to its content by signature.js; .mail-html iframe's min-height is for messages. */
.mail-html iframe.signature-frame { display: block; width: 100%; height: 0; min-height: 0; border: 0; }
.signature-preview-sample { margin: 0 0 .75rem; color: #1f2937; font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
.signature-preview-empty { margin: 0; color: #6b7280; }
@media (min-width: 992px) {
  .signature-preview-sticky { position: sticky; top: 1rem; }
}

/* ---------- attachments: image thumbnails, scan states, image viewer (Email/View, Compose) ---------- */
.btn-close-sm { width: .5rem; height: .5rem; padding: .25rem; background-size: .5rem; }
.mail-image-attachments { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .875rem; }
.mail-image-thumb { margin: 0; width: 9rem; border: 1px solid var(--bs-border-color); border-radius: .5rem; overflow: hidden; }
.mail-image-open { display: block; width: 100%; height: 6.5rem; padding: 0; border: 0; background: var(--bs-tertiary-bg); cursor: zoom-in; }
.mail-image-open img { width: 100%; height: 100%; object-fit: cover; }
.mail-image-thumb figcaption { display: flex; align-items: center; gap: .375rem; padding: .25rem .5rem; font-size: .8125rem; }
.mail-image-thumb figcaption .mail-attachment-name { flex: 1 1 auto; }
.mail-image-thumb figcaption a { color: var(--bs-secondary-color); }
.mail-attachment-blocked { color: var(--bs-danger-text-emphasis); background: var(--bs-danger-bg-subtle); border-color: var(--bs-danger-border-subtle); cursor: not-allowed; }
.mail-attachment-danger { border-color: var(--bs-danger-border-subtle); }
.mail-scan-notes { margin: -.375rem 0 .875rem; padding-left: 1.25rem; font-size: .8125rem; color: var(--bs-secondary-color); }

.image-viewer .modal-content { background: #000; color: #fff; }
.image-viewer .modal-header { border-color: rgba(255, 255, 255, .15); gap: .25rem; }
.image-viewer .modal-body { position: relative; display: flex; align-items: center; justify-content: center; padding: .5rem; }
.image-viewer .modal-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.image-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 1.25rem;
}
.image-viewer-nav:hover { background: rgba(255, 255, 255, .3); }
.image-viewer-nav.prev { left: .75rem; }
.image-viewer-nav.next { right: .75rem; }
