/* ==========================================================================
   Email History
   ========================================================================== */
.eh-page {
  --eh-ok: #15803d;
  --eh-bad: #b91c1c;
  --eh-soft: color-mix(in srgb, var(--text-primary) 4%, var(--bg-surface));
  max-width: 1000px;
  margin: 0 auto;
  padding-bottom: 3rem;
}

.theme-dark .eh-page { --eh-ok: #4ade80; --eh-bad: #f87171; }
.eh-page [hidden] { display: none !important; }

.eh-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.25rem 0 1.25rem;
}

.eh-head h2 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text-primary); }
.eh-head p { color: var(--text-secondary); font-size: 0.92rem; margin-top: 0.3rem; }

.eh-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.eh-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.eh-stat-label { font-size: 0.76rem; color: var(--text-secondary); }
.eh-stat-value { font-size: 1.45rem; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.eh-stat-sub { font-size: 0.74rem; color: var(--text-muted); }

.eh-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.eh-filters {
  display: inline-flex;
  background: var(--eh-soft);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.eh-filters button {
  border: none;
  background: transparent;
  padding: 0.38rem 0.9rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.eh-filters button.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

.eh-search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.eh-search i { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.85rem; }
.eh-search .form-control { padding-left: 2.1rem; }

.eh-day {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 1.1rem 0 0.45rem;
}

.eh-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.eh-row + .eh-row { border-top: 1px solid var(--border-color); }

.eh-row-btn {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.eh-row-btn:hover, .eh-row.is-open .eh-row-btn { background: var(--eh-soft); }
.eh-row-btn:focus-visible { outline: 2px solid var(--text-primary); outline-offset: -2px; }

.eh-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  color: #fff;
  background: var(--eh-ok);
}

.eh-row.is-failed .eh-dot { background: var(--eh-bad); }

.eh-main { min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.eh-title { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eh-sub { font-weight: 400; color: var(--text-secondary); font-size: 0.8rem; margin-left: 0.45rem; }
.eh-subject { font-size: 0.82rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eh-row.is-failed .eh-subject { color: var(--eh-bad); }

.eh-meta { display: flex; align-items: center; gap: 0.75rem; font-size: 0.78rem; color: var(--text-secondary); white-space: nowrap; }
.eh-source { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.eh-time { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; }
.eh-chevron { transition: transform 0.18s ease; color: var(--text-muted); }
.eh-row.is-open .eh-chevron { transform: rotate(180deg); }

.eh-panel {
  padding: 0.25rem 1rem 1rem calc(28px + 1.85rem);
  background: var(--eh-soft);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.eh-email {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.86rem;
  line-height: 1.55;
}

.eh-email-subject { font-weight: 650; margin-bottom: 0.5rem; color: var(--text-primary); }
.eh-email-body { white-space: pre-wrap; word-break: break-word; color: var(--text-secondary); max-height: 420px; overflow: auto; }
.eh-email-body.is-muted { font-style: italic; }

.eh-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  font-size: 0.8rem;
  margin: 0;
}

.eh-facts dt { color: var(--text-secondary); }
.eh-facts dd { margin: 0; color: var(--text-primary); overflow-wrap: anywhere; }

.eh-error {
  font-size: 0.82rem;
  color: var(--eh-bad);
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
}

.eh-loading { font-size: 0.82rem; color: var(--text-secondary); padding-top: 0.5rem; }

.eh-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  background: var(--bg-surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.eh-more { display: flex; justify-content: center; margin-top: 1rem; }

@media (max-width: 720px) {
  .eh-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .eh-source { display: none; }
  .eh-panel { padding-left: 1rem; }
  .eh-sub { display: block; margin-left: 0; }
}
