/* Batch selection is independent from the email open in the reading pane.

   The bar (.batch-export-bar) sits in the results header row. With nothing selected it is only the
   page checkbox, so the export controls cost the results no row; while emails are selected it takes
   the saved searches' place. The card (.batch-export) is rendered only when there is something to
   report, and takes its own line under that row. */
.email-results-header { flex-wrap: wrap; row-gap: .5rem; }
.batch-export-bar { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; min-width: 0; }
/* The page checkbox lines up with the row checkboxes below it: same 44px column, same left edge. */
.batch-export-bar .mud-input-control { flex: 0 0 44px; width: 44px; margin: 0; }
.batch-export-bar .mud-checkbox { margin: 0; }
.batch-export-bar .mud-icon-button { width: 44px; height: 44px; }
/* 30rem is what the count, Clear and the two export buttons need on one line. Where the layout
   switch leaves that much, the bar shares its line (no jump when a row is ticked); where it does
   not, the bar takes the whole line and the switch moves under it. */
.batch-export-bar.is-active { flex: 1 1 30rem; flex-wrap: wrap; }
/* The header's own gap is 1.5rem above 768px; the checkbox and "Saved:" belong closer together. */
@media (min-width: 769px) {
    .email-results-header > .batch-export-bar + .saved-searches { margin-left: -1rem; }
}
.batch-export__count { font-size: .875rem; font-weight: 600; white-space: nowrap; }
.batch-export__actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .5rem .75rem; margin-left: auto; }
/* The "Up to N per export" hint is shown only where it fits on the bar's one line; going over the
   limit is explained in the status card at every width. */
.batch-export__limit { display: none; font-size: .8125rem; color: var(--color-text-secondary); white-space: nowrap; }
@media (min-width: 1280px) { .batch-export__limit { display: inline; } }
.batch-export__actions .mud-button-root, .batch-export__job .mud-button-root {
    min-height: 44px; border-radius: 999px; text-transform: none; white-space: nowrap;
}
.batch-export__clear { min-height: 44px; text-transform: none; }

.batch-export {
    flex: 0 0 100%; order: 10; box-sizing: border-box;
    padding: 1rem 1.25rem;
    border: 1px solid color-mix(in srgb, var(--color-brand-primary) 24%, var(--color-border));
    border-radius: 18px;
    background: color-mix(in srgb, var(--color-brand-primary) 3%, var(--color-surface));
    color: var(--color-text-primary);
}
.batch-export > * { margin: .75rem 0 0; }
.batch-export > :first-child { margin-top: 0; }
.batch-export__job { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.batch-export__details { color: var(--color-text-secondary); font-size: .8125rem; line-height: 1.5; }
.batch-export__job { padding: 1rem; border: 1px solid var(--color-border); border-radius: 12px; justify-content: space-between; background: var(--color-surface); }
.batch-export__job--ready { background: color-mix(in srgb, var(--color-brand-accent) 7%, var(--color-surface)); }
.batch-export__job-copy { display: flex; align-items: center; gap: .75rem; min-width: 0; flex: 1 1 240px; }
.batch-export__job-copy > div { min-width: 0; }
.batch-export__job-copy strong { display: block; font-size: .875rem; }
.batch-export__job-copy span { display: block; color: var(--color-text-secondary); font-size: .8125rem; margin-top: .25rem; overflow-wrap: anywhere; }
.batch-export__error { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; color: var(--color-danger, var(--color-text-primary)); font-size: .875rem; }
#emails-page .email-select-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: start; }
#emails-page .email-select-row__check { padding-top: .5rem; }
#emails-page .email-select-row__check .mud-checkbox { margin: 0; }
#emails-page .email-select-row__check .mud-icon-button { width: 44px; height: 44px; }
#emails-page .email-select-row .email-card { min-width: 0; margin: 0; }
@media (max-width: 600px) {
    /* Saved searches keep their own line; the page checkbox shares the next one with the layout switch. */
    .email-results-header > .saved-searches { order: 1; }
    .email-results-header > .batch-export-bar { order: 2; }
    .email-results-header > .email-layout { order: 3; }
    .email-results-header > .batch-export-bar.is-active { flex: 1 1 100%; flex-wrap: wrap; }
    .batch-export { padding: .75rem; }
    .batch-export__actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-left: 0; }
    .batch-export__actions .mud-button-root { padding: .5rem; font-size: .8125rem; }
    .batch-export__count { font-size: .8125rem; }
    .batch-export__clear { min-width: 44px; padding: 0 .5rem; font-size: .8125rem; }
    .batch-export__job { padding: .75rem; }
    .batch-export__job .mud-button-root { width: 100%; }
    #emails-page .email-select-row .email-card { gap: .4rem .6rem !important; }
    #emails-page .email-select-row .email-card > .avatar { grid-column: 1; grid-row: 1; }
    #emails-page .email-select-row .email-card > .body { display: contents; }
    #emails-page .email-select-row .email-card .row1 { grid-column: 2; grid-row: 1; min-width: 0; }
    #emails-page .email-select-row .email-card .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #emails-page .email-select-row .email-card .to { display: none; }
    #emails-page .email-select-row .email-card > .right { grid-column: 3; grid-row: 1; }
    #emails-page .email-select-row .email-card .subject { grid-column: 1 / -1; grid-row: 2; overflow-wrap: anywhere; }
    #emails-page .email-select-row .email-card .snippet { grid-column: 1 / -1; grid-row: 3; }
}
