/*
 * Promtek Mail — quiet resize-safe sorting and semantic unread dots v5
 *
 * Sorting is delegated to Roundcube's own set_list_options() method. The
 * status-icon slot remains aligned, but its plain circle is visible only on
 * unread messages; replied, forwarded, thread, and deleted states stay intact.
 */

html:not(.iframe) body.task-mail .promtek-message-filters {
  position: relative;
  box-sizing: border-box;
  gap: 2px;
  min-width: 0;
  overflow: visible;
  padding-right: 7px;
  padding-left: 7px;
}

html:not(.iframe) body.task-mail .promtek-message-filter {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0 !important;
  padding-right: 7px;
  padding-left: 7px;
  overflow: hidden;
  text-overflow: ellipsis;
}

html:not(.iframe) body.task-mail .promtek-message-sort {
  position: relative;
  z-index: 20;
  flex: 0 1 88px;
  min-width: 38px;
  max-width: 88px;
  margin-left: auto;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 28px;
  margin: 0;
  padding: 0 6px;
  color: var(--promtek-muted);
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  box-shadow: none;
  font: inherit;
  font-size: 12px;
  line-height: 26px;
  white-space: nowrap;
  cursor: pointer;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle::before {
  content: "\f160";
  flex: 0 0 auto;
  width: 1em;
  color: var(--promtek-muted);
  font-family: "Icons";
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle.is-ascending::before {
  content: "\f161";
}

/*
 * Roundcube returns focus to the toggle after a menu choice. Remove the
 * inherited mouse/programmatic focus outline, while keeping the dedicated
 * :focus-visible ring below for keyboard navigation.
 */
html:not(.iframe) body.task-mail .promtek-message-sort-toggle:focus {
  outline: none;
}

html:not(.iframe) body.task-mail
  .promtek-message-sort-toggle:focus:not(:focus-visible) {
  border: 1px solid transparent;
  box-shadow: none;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle:hover,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle:focus-visible,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle.is-open {
  color: var(--promtek-text);
  background-color: var(--promtek-selection-hover);
  border-color: transparent;
  outline: none;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle:hover::before,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle:focus-visible::before,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle.is-open::before {
  color: var(--promtek-text);
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle:hover
  .promtek-message-sort-caret,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle:focus-visible
  .promtek-message-sort-caret,
html:not(.iframe) body.task-mail .promtek-message-sort-toggle.is-open
  .promtek-message-sort-caret {
  border-top-color: var(--promtek-text);
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle:focus-visible {
  box-shadow: 0 0 0 3px var(--promtek-focus-ring);
}

html:not(.iframe) body.task-mail .promtek-message-sort-label {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
}

html:not(.iframe) body.task-mail .promtek-message-sort-caret {
  width: 0;
  height: 0;
  border-top: 5px solid var(--promtek-muted);
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
}

html:not(.iframe) body.task-mail .promtek-message-sort-toggle.is-open .promtek-message-sort-caret {
  transform: rotate(180deg);
}

html:not(.iframe) body.task-mail .promtek-message-sort.is-icon-only {
  flex: 0 0 36px;
  width: 36px;
  min-width: 36px;
  max-width: 36px;
}

html:not(.iframe) body.task-mail .promtek-message-sort.is-icon-only
  .promtek-message-sort-toggle {
  gap: 0;
  padding: 0;
}

html:not(.iframe) body.task-mail .promtek-message-sort.is-icon-only
  .promtek-message-sort-label,
html:not(.iframe) body.task-mail .promtek-message-sort.is-icon-only
  .promtek-message-sort-caret {
  display: none;
}

html:not(.iframe) body.task-mail .promtek-message-sort-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  box-sizing: border-box;
  width: 214px;
  padding: 6px;
  color: var(--promtek-text);
  background-color: var(--promtek-header);
  border: 1px solid var(--promtek-border);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(31, 22, 13, 0.16);
}

html.dark-mode:not(.iframe) body.task-mail .promtek-message-sort-menu {
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
}

html:not(.iframe) body.task-mail .promtek-message-sort-menu[hidden] {
  display: none !important;
}

html:not(.iframe) body.task-mail .promtek-message-sort-heading {
  padding: 7px 10px 5px 30px;
  color: var(--promtek-faint);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

html:not(.iframe) body.task-mail .promtek-message-sort-option {
  position: relative;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 34px;
  margin: 0;
  padding: 6px 10px 6px 30px;
  color: var(--promtek-text);
  background-color: transparent;
  border: 0;
  border-radius: 6px;
  box-shadow: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}

html:not(.iframe) body.task-mail .promtek-message-sort-option:hover,
html:not(.iframe) body.task-mail .promtek-message-sort-option:focus-visible {
  color: var(--promtek-text);
  background-color: var(--promtek-selection-hover);
  outline: none;
}

html:not(.iframe) body.task-mail .promtek-message-sort-option.is-active {
  color: var(--promtek-selection-ink);
  background-color: var(--promtek-selection);
}

html:not(.iframe) body.task-mail .promtek-message-sort-option.is-active::before {
  content: "\f00c";
  position: absolute;
  left: 10px;
  color: var(--promtek-accent);
  font-family: "Icons";
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

html:not(.iframe) body.task-mail .promtek-message-sort-option:disabled {
  color: var(--promtek-faint);
  background-color: transparent;
  cursor: default;
}

html:not(.iframe) body.task-mail .promtek-message-sort-divider {
  height: 1px;
  margin: 6px -6px;
  background-color: var(--promtek-border);
}

/* Preserve the status slot for alignment, but hide its decorative read dot. */
html:not(.iframe) body.task-mail .messagelist tbody tr:not(.unread):not(.deleted)
  td.subject span.msgicon.status:not(.replied):not(.forwarded):not(.unreadchildren)::before {
  color: transparent !important;
}

html:not(.iframe) body.task-mail .messagelist tbody tr.unread
  td.subject span.msgicon.status::before {
  color: var(--promtek-accent) !important;
}
