/* === Email UX upgrades (theme, filters, avatars, star, search) === */
#email-root .email-mailboxes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#email-root .email-mailboxes-header .email-search {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  padding: 10px;
}

#mailSearchInput {
  width: 100%;
  height: 25px;
  padding: 6px 9px;
  border-radius: 999px;
  border: var(--line);
  color: var(--text);
  outline: none;
}

#mailSearchInput::placeholder {
  color: var(--text-muted);
}

#mailSearchInput:focus {
  box-shadow: var(--ring);
}

/* Active mailbox filter */
#email-root .chip.is-active {
  border: 2px solid var(--primary);
}

#email-root .chip[disabled] {
  opacity: .6;
  pointer-events: none;
}

/* Thread row enhancements */
#emailList .inbox-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 5px;
}

#emailList .inbox-item.is-open {
  box-shadow: var(--ring);
}

/* Star button pinned bottom-right */
#emailList .thread-star {
  position: absolute;
  right: 2px;
  bottom: 1px;
  width: 17px;
  height: 17px;
  padding: 2px;
  font-size: 11px;
  background: transparent;
  display: grid;
  align-content: center;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
}

#emailList .thread-star:hover {
  background: var(--muted);
  color: var(--text);
}

#emailList .thread-star.is-starred {
  color: var(--primary);
}

/* Avatar with image + fallback initial */
#email-root .email-avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: var(--line);
  overflow: hidden;
  background: var(--muted);
}

#email-root .email-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  contain: content;
}

#email-root .email-avatar.has-img img {
  display: block;
}

#email-root .email-avatar .avatar-fallback {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
}

/* Load more button loading bars */
#emailLoadMore {
  position: relative;
}

#emailLoadMore .bars {
  display: none;
  gap: 3px;
  align-items: flex-end;
  justify-content: center;
  margin-left: 8px;
}

#emailLoadMore .bars i {
  display: block;
  width: 3px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
  opacity: .8;
  animation: emailBars 900ms infinite ease-in-out;
}

#emailLoadMore .bars i:nth-child(2) {
  animation-delay: 120ms;
  height: 14px;
}

#emailLoadMore .bars i:nth-child(3) {
  animation-delay: 240ms;
  height: 8px;
}

#emailLoadMore.is-loading .bars {
  display: inline-flex;
}

#emailLoadMore.is-loading .label {
  opacity: .7;
}

@keyframes emailBars {

  0%,
  100% {
    transform: scaleY(.55);
  }

  50% {
    transform: scaleY(1.1);
  }
}

/* Email account manager modal */
.email-accounts-modal .account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
  cursor: pointer;
}

.email-accounts-modal .account-row:hover {
  box-shadow: var(--ring);
}

.email-accounts-modal .account-row.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, .25), 0 0 18px rgba(79, 70, 229, .25);
}

.email-accounts-modal .account-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.email-accounts-modal .account-left .email-avatar {
  width: 30px;
  height: 30px;
  background: var(--dots);
  border-radius: 10px;
  overflow: hidden;
  display: inline-grid;
  align-items: center;
  justify-items: center;
  align-content: center;
}

.email-accounts-modal .account-meta {
  min-width: 0;
}

.email-accounts-modal .account-email {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
}

.email-accounts-modal .account-provider {
  font-size: 12px;
  color: var(--text-muted);
}

.email-accounts-modal .account-unlink {
  width: 25px;
  height: 25px;
  border-radius: 999px;
  border: var(--line);
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.email-accounts-modal .account-unlink:hover {
  background: rgba(239, 68, 68, .12);
  color: rgba(239, 68, 68, 1);
}

.email-accounts-modal .provider-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.email-accounts-modal .provider-pill {
  width: 74px;
  height: 74px;
  border-radius: 999px;
  border: var(--line);
  background: rgba(255, 255, 255, .03);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.email-accounts-modal .provider-pill:hover {
  box-shadow: var(--ring);
}

.email-accounts-modal .provider-label {
  text-align: center;
  font-size: 12px;
  margin-top: 6px;
  color: var(--text-muted);
}

/* Prevent accidental double-taps while loading */
#email-root.is-loading-threads #emailList {
  opacity: .85;
}

/* Thread list loading indicator (uses same 3-bar animation as Load More) */
#emailList .email-loading-list {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#emailList .email-loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
}

#emailList .email-loading-row .email-avatar {
  opacity: .7;
}

#emailList .email-loading-row .email-loading-lines {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

#emailList .email-loading-row .bars {
  display: inline-flex;
  gap: 3px;
  align-items: flex-end;
  justify-content: center;
  color: var(--text-muted);
}

#emailList .email-loading-row .bars i {
  display: block;
  width: 3px;
  height: 10px;
  border-radius: 2px;
  background: currentColor;
  opacity: .65;
  animation: emailBars 900ms infinite ease-in-out;
}

#emailList .email-loading-row .bars i:nth-child(2) {
  animation-delay: 120ms;
  height: 14px;
}

#emailList .email-loading-row .bars i:nth-child(3) {
  animation-delay: 240ms;
  height: 8px;
}

/* Drag/drop affordance for composer */
#email-root [contenteditable].is-drop-target {
  box-shadow: var(--ring);
  outline: 2px dashed rgba(79, 70, 229, .55);
  outline-offset: 2px;
  background: rgba(79, 70, 229, .08);
}

/* ===== Email Compose Enhancements ===== */
.email-send-as-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0 10px;
}

#email-root input {
  background: var(--bg)
}

#emailReplyBody {
  background: var(--bg);
  border-radius: 5px;
}

.rte-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.email-send-as-row .label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.email-send-as-row .email-send-as-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: var(--line);
  border-radius: 999px;
}

.email-send-as-row .email-send-as-btn .txt {
  font-weight: 600;
  font-size: 13px;
}

.email-send-as-row .email-send-as-btn .caret {
  opacity: 0.7;
  font-size: 12px;
}

.email-quote-box {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.email-quote-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.email-quote-content {
  max-height: 20vh;
  overflow: hidden;
  position: relative;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  padding: 8px;
  padding-bottom: 38px; /* space for expand button overlay */
  border-radius: 10px;
  background: var(--strans);
}

.email-quote-box.is-expanded .email-quote-content {
  max-height: none;
}

.email-quote-box.is-collapsed .email-quote-content::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), var(--surface));
  pointer-events: none;
}

.email-quote-toggle {
  position: absolute;
  right: 10px;
  bottom: 10px;
}

.email-quote-toggle .ic {
  font-size: 12px;
}

.email-quote-iframe {
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: transparent;
}

/* ------------------------------
   Email: Details side panel
   ------------------------------ */

.email-details-pane #emailDetails{
  padding: 12px;
  overflow: auto;
}

.email-details-pane #emailDetails .details-title{
  font-weight: 800;
  font-size: 14px;
  margin: 0 0 8px 0;
  word-break: break-word;
}

.email-details-pane #emailDetails .details-sub{
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.email-details-pane #emailDetails .details-actions{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* Override overly restrictive global styles */
.email-details-pane #emailDetails .code{
  width: 100% !important;
  height: auto !important;
  max-height: 55vh;
  font-size: 12px !important;
  letter-spacing: normal !important;
  scrollbar-width: thin !important;
}

.email-details-pane #emailDetails details summary{
  cursor: pointer;
}

.email-details-pane #emailDetails .email-details-attachments{
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.email-details-pane #emailDetails .email-details-attachment{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: var(--line);
  border-radius: 10px;
  background: var(--primary-faded);
}

.email-details-pane #emailDetails .email-details-attachment .name{
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-details-pane #emailDetails .email-details-attachment .meta{
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ────────────────────────────────────────────────────────────
   Email link mini-window (in-app)
   ──────────────────────────────────────────────────────────── */
dialog.email-miniwin {
  width: min(1040px, 92vw);
  height: min(760px, 86vh);
  padding: 0;
  border: none;
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
  overflow: hidden;
}

dialog.email-miniwin::backdrop {
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(8px);
}

.email-miniwin-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.email-miniwin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: var(--line);
  background: rgba(0,0,0,.12);
}

.email-miniwin-title {
  font-weight: 700;
  font-size: 13px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 72vw;
}

.email-miniwin-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.email-miniwin-body {
  flex: 1;
  background: var(--bg);
}

.email-miniwin-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

