/* Open mail and write (Clear desk): the reading pane, its action bar and menus, the composer and the sending bar.
   Desktop (900 px and up): the pane sits right of the list with its actions as a toolbar on top. Phone: the pane is a
   full-screen layer over the list and the tab bar, "‹ Mail" and the more menu on top, the five actions pinned at the
   bottom. Every base rule comes first; the phone overrides are in one block at the end. */

/* the pane */
.pane { position: sticky; top: 0; height: 100vh; height: 100dvh; overflow: auto; min-width: 0; border-left: 1px solid var(--line); background: var(--bg); animation: pane-in .32s cubic-bezier(.2, .8, .2, 1); }
@keyframes pane-in { from { opacity: 0; transform: translateX(18px); } }
.pane-bar { position: sticky; top: 0; z-index: 3; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 20px; background: var(--bg); border-bottom: 1px solid var(--line); }
.pane-bar .spacer { flex: 1; }
.pane-bar .back { display: none; }
.pane-bar .icon-btn { flex: none; }
.phone-only { display: none; }

/* Reply · Forward · Done · Snooze · Bin: a toolbar of icon + word buttons, Reply the violet one */
.pane-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.act {
  min-height: 40px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 14px var(--sans); color: var(--text);
  background: var(--weak); border: 0; border-radius: var(--radius);
  cursor: pointer; transition: background .15s;
}
.act:hover { background: color-mix(in srgb, var(--text) 7%, var(--weak)); }
.act.primary { background: var(--primary); color: var(--on-primary); }
.act.primary:hover { background: color-mix(in srgb, var(--primary) 86%, var(--text)); }
.act:disabled { opacity: .45; cursor: not-allowed; }
.act[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary); }
.act-wrap { position: relative; display: inline-flex; }
/* The more menu hangs from the bar, not the button: it opens at the pane's right edge and never runs out of the pane. */
.more-wrap { display: inline-flex; }
.more-btn[aria-expanded="true"] { background: var(--weak); color: var(--text); }

/* the more menu and the snooze choices */
.pop-menu { position: absolute; top: calc(100% + 6px); right: 8px; z-index: 6; min-width: 240px; max-height: 70vh; overflow-y: auto; display: grid; gap: 2px; padding: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: 0 12px 40px var(--scrim); }
.pop-menu[hidden] { display: none; }
.snooze-menu { left: 0; right: auto; min-width: 170px; }
.pop-menu > button, .pop-menu .categories button {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 40px; padding: 0 10px;
  background: none; border: 0; border-radius: 8px;
  color: var(--text); font: 500 15px var(--sans); text-align: left; cursor: pointer;
}
.pop-menu > button:hover, .pop-menu .categories button:hover, .pop-menu .categories button[aria-selected="true"] { background: var(--weak); }
.pop-menu > button:disabled { opacity: .45; cursor: not-allowed; }
.pop-menu > button[aria-expanded="true"] { color: var(--primary); }
.pop-menu .categories { display: grid; gap: 2px; margin: 0 0 0 10px; padding-left: 8px; border-left: 2px solid var(--line); }
.pop-menu .always { display: flex; gap: 8px; align-items: center; padding: 8px 10px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.pop-menu .always input { accent-color: var(--primary); width: 18px; height: 18px; flex: none; }
/* Inside the bar, under the menus: a click anywhere else lands on it and closes the menu. */
.menu-scrim { position: fixed; inset: 0; z-index: 1; }

/* the mail */
.reading { padding: 20px 20px 40px; max-width: 920px; }
.reading .subject { font: 700 21px/1.25 var(--sans); margin: 0 0 12px; overflow-wrap: anywhere; }
/* focused by code when a mail opens, never by Tab: no ring around a heading */
.reading .subject:focus { outline: none; }
.keys { margin-top: 18px; font-size: 12px; color: var(--muted); }
.draft-note { margin-bottom: 12px; color: var(--warn); background: var(--warn-soft); }

/* The grey box: Needs you and the TL;DR first, then where it was filed and by what. */
.ai-box { display: grid; gap: 6px; margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; background: var(--weak); font-size: 15px; }
.ai-box .what { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ai-box .k { font: 600 12px var(--sans); color: var(--primary); }
.ai-box .summary { color: var(--text); }
.ai-box .reason { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.ai-box .how { font-size: 12px; color: var(--muted); }
.ai-box .stage { font: 500 12px var(--sans); color: var(--muted); }
.ai-box .conf.low { color: var(--warn); }

.thread { display: grid; }
.earlier { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: baseline; width: 100%; min-height: 44px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.earlier:hover { background: var(--weak); }
.earlier b { font-weight: 600; color: var(--text); }
.earlier span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); }
.earlier time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.earlier.more { display: block; text-align: center; font-size: 13px; }

.message { padding: 14px 0; border-bottom: 1px solid var(--line); }
.message:last-child { border-bottom: 0; }
.message-head { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 2px 10px; align-items: start; margin-bottom: 14px; }
.message-head .avatar { grid-row: span 2; background: color-mix(in srgb, var(--acc, var(--primary)) 16%, var(--bg)); color: color-mix(in srgb, var(--acc, var(--primary)) 80%, var(--text)); }
.message-head .who { min-width: 0; overflow-wrap: anywhere; }
.message-head .who b { font-weight: 600; }
.message-head .who small { display: block; font-size: 13px; color: var(--muted); }
.message-head time { font-variant-numeric: tabular-nums; }
.message-head .to { grid-column: 2; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.message-head .to b { font-weight: 500; color: var(--muted); }
.message-head .tag { min-width: 0; padding: 0 5px; font-size: 11px; }
.sent-mark { margin-left: 8px; padding: 0 6px; border-radius: 99px; background: var(--weak); font: 600 12px var(--sans); color: var(--muted); }
.message-state { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 16px 0; color: var(--muted); }
.message-state.failed { color: var(--danger); }
.message .icon, .image-bar .icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.attachments { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments a { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: var(--radius); background: var(--weak); font-size: 14px; text-decoration: none; color: var(--text); }
.attachments a:hover { background: color-mix(in srgb, var(--text) 7%, var(--weak)); }
.attachments .name { overflow-wrap: anywhere; }
.attachments .size { font-size: 12px; color: var(--muted); }
.image-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 12px; border-radius: var(--radius); background: var(--warn-soft); font-size: 14px; color: var(--text); }
.image-bar .icon { color: var(--warn); }
.image-bar .spacer { flex: 1; }
/* Mail is written for white paper and the sanitizer gives it a white page, so the frame is paper in both themes:
   painting it the dark ground would flash dark to white as the body loads. */
.mail-frame { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--paper); }
.mail-body { display: block; width: 100%; height: 240px; border: 0; background: var(--paper); }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.6; }
.mail-text a { color: var(--primary); }

/* what the grey box leads to: block confirm, a rule to approve, the bill strip (F8.1) */
.suggest-line { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--primary-soft); font-size: 14px; }
.suggest-line .q { font-weight: 600; }
.suggest-line .ev { color: var(--text); flex: 1 1 240px; }
.suggest-line .acts { display: flex; gap: 6px; }
.block-confirm { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius); background: var(--danger-soft); font-size: 14px; }
.block-confirm .q { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.block-confirm .acts { display: flex; gap: 6px; }
.bill-strip { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; align-items: center; margin: 0 0 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--bg); }
.bill-strip .what { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.bill-strip .what b { color: var(--text); }
.reading > .toast-region > .toast { margin: 0 0 12px; }

/* write: under the mail it answers, or the whole pane for a new mail */
.composer { margin-top: 16px; display: grid; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--bg); animation: composer-in .24s ease-out; }
@keyframes composer-in { from { opacity: 0; transform: translateY(8px); } }
/* The page's own bar and heading around a new mail give way to the composer's bar. */
.pane:not(.reading-pane):has(> .reading > .composer) > .pane-bar { display: none; }
.pane:not(.reading-pane) > .reading:has(> .composer) > h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.pane:not(.reading-pane) > .reading > .composer { margin-top: 0; border: 0; border-radius: 0; }
.pane:not(.reading-pane) > .reading:has(> .composer) { padding-top: 0; }
.composer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg); border-radius: var(--radius-card) var(--radius-card) 0 0; }
.pane:not(.reading-pane) > .reading > .composer > .composer-bar { position: sticky; top: 0; z-index: 2; padding: 12px 0; border-radius: 0; }
.composer-bar .spacer { flex: 1; }
.composer-bar .send { order: 1; }
.composer-bar .attach { order: 2; cursor: pointer; }
.composer-bar .spacer { order: 3; }
.composer-bar .discard { order: 4; }
.composer-bar .cancel { order: 5; width: 40px; padding: 0; }
.composer-bar .cancel .word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.composer-bar .attach:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.composer-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; min-height: 48px; padding: 4px 12px; border-bottom: 1px solid var(--line); font-size: 15px; }
.pane:not(.reading-pane) > .reading > .composer .composer-row { padding: 4px 0; }
.composer-row > label { font-size: 15px; color: var(--muted); }
.bare { min-width: 0; width: 100%; background: none; border: 0; outline: none; font: 15px var(--sans); color: var(--text); padding: 6px 0; }
.bare::placeholder { color: var(--muted); }
.from-pick { display: inline-flex; align-items: center; gap: 8px; justify-self: start; max-width: 100%; padding: 0 10px; border-radius: var(--radius); background: var(--weak); }
.from-pick select { min-width: 0; max-width: 100%; min-height: 36px; background: none; border: 0; outline: none; font: 15px var(--sans); color: var(--text); }
.from-pick option { background: var(--bg); color: var(--text); }
/* Composer fields are borderless: the From picker gets a ring round its box, a text row and the body an inset one.
   :focus-visible keeps a mouse click on the picker quiet; text fields always show it, as they should. */
.from-pick:has(select:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }
.composer-row:has(.bare:focus-visible), .composer-body:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); }
.auto-note { font-size: 13px; color: var(--ok); }
.recipient-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; padding: 4px 0; }
.recipient-chips .bare { flex: 1; min-width: 140px; width: auto; }
/* The address suggestions come from a datalist; its arrow only adds noise to a To line. */
.recipient-chips .bare::-webkit-calendar-picker-indicator { display: none; }
.recipient { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 2px 2px 10px; border-radius: 99px; background: var(--weak); font-size: 14px; overflow-wrap: anywhere; }
.recipient small { font-size: 12px; color: var(--muted); }
.recipient button { width: 28px; height: 28px; border: 0; border-radius: 99px; background: none; color: var(--muted); cursor: pointer; font: inherit; }
.recipient button:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, var(--weak)); }
.recipient.invalid { color: var(--danger); background: var(--danger-soft); }
.link-btn { min-height: 36px; border: 0; background: none; cursor: pointer; font: 500 14px var(--sans); color: var(--muted); }
.link-btn:hover { color: var(--text); }
.composer-body { min-height: 240px; resize: vertical; border: 0; outline: none; background: transparent; padding: 14px 12px; font: 16px/1.6 var(--sans); color: var(--text); }
.pane:not(.reading-pane) > .reading > .composer .composer-body { padding: 14px 0; }
.quote-toggle { justify-self: start; min-height: 32px; margin: 0 12px 10px; padding: 0 10px; border: 0; border-radius: 99px; background: var(--weak); cursor: pointer; font: 600 13px var(--sans); color: var(--muted); }
.quote-toggle:hover, .quote-toggle[aria-expanded="true"] { color: var(--text); }
.composer-quote { margin: 0 12px 12px; padding-left: 12px; border-left: 2px solid var(--line); color: var(--muted); font: 14px/1.5 var(--sans); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; }
.composer-files { list-style: none; margin: 0; padding: 0 12px 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.composer-files li { display: inline-flex; align-items: center; gap: 8px; padding: 2px 2px 2px 12px; border-radius: var(--radius); background: var(--weak); font-size: 14px; }
.composer-files small { font-size: 12px; color: var(--muted); }
.composer-note { margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--warn-soft); color: var(--text); font-size: 14px; }
.composer-alert { margin: 10px 12px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
div.composer-alert { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
div.composer-alert p { margin: 0; flex: 1 1 16rem; }
.composer-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); }
.composer-status { font-size: 13px; color: var(--muted); }
.composer-foot .discard { margin-left: auto; }

/* the sending bar: "Sending to Jonas… Undo", dark on the light theme and light on the dark one */
.outbox { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 36; display: grid; gap: 8px; width: min(520px, calc(100% - 32px)); }
.outbox-bar { position: relative; overflow: hidden; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; min-height: 48px; padding: 6px 8px 6px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; box-shadow: 0 10px 40px var(--scrim); }
.outbox-bar .what { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; }
.outbox-bar b { font-weight: 600; }
.outbox-bar .count { font: 600 13px var(--sans); font-variant-numeric: tabular-nums; }
.outbox-bar .undo { display: inline-flex; align-items: center; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--radius); background: none; color: var(--primary-soft); font: 700 14px var(--sans); text-decoration: none; cursor: pointer; }
.outbox-bar .undo:hover { text-decoration: underline; }
.outbox-bar .dismiss { width: 40px; height: 40px; border: 0; border-radius: var(--radius); background: none; color: inherit; font: 18px var(--sans); cursor: pointer; }
.outbox-bar .meter { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--primary); transition: width .5s linear; }
.outbox-bar.sent { background: var(--ok-soft); color: var(--text); box-shadow: none; }
.outbox-bar.failed { background: var(--danger-soft); color: var(--text); box-shadow: none; }
.outbox-bar.failed .undo { color: var(--danger); }


/* Phone and small tablet: the open mail and the composer fill the screen. */
@media (max-width: 899px) {
  .pane { position: fixed; inset: 0; z-index: 35; height: auto; border-left: 0; display: flex; flex-direction: column; overflow: hidden; animation-name: pane-in-phone; }
  @keyframes pane-in-phone { from { opacity: 0; transform: translateX(40%); } }
  .pane-bar { position: relative; flex: none; flex-wrap: nowrap; gap: 4px; padding: calc(4px + env(safe-area-inset-top, 0px)) 8px 4px; border-bottom: 0; }
  .pane-bar .back { display: inline-flex; padding: 0 8px 0 2px; color: var(--primary); font: 500 16px var(--sans); }
  .pane-bar .back:hover { background: none; color: var(--primary); }
  .desk-only { display: none; }
  .phone-only { display: flex; }
  .reading { flex: 1; min-height: 0; overflow-y: auto; max-width: none; padding: 4px 16px calc(100px + env(safe-area-inset-bottom, 0px)); }
  .pane-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; flex-wrap: nowrap; gap: 6px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-top: 1px solid var(--line); }
  .pane-actions > .act, .pane-actions > .act-wrap { flex: 1 1 0; min-width: 0; }
  .act { flex-direction: column; gap: 3px; width: 100%; min-height: 56px; padding: 8px 0; font: 600 12px var(--sans); }
  .snooze-menu { top: auto; bottom: calc(100% + 8px); }
  .pop-menu { max-height: 60vh; }
  /* While Tim answers, the composer's Send is the action: the bar steps aside. */
  .pane:has(.composer) .pane-actions { display: none; }
  .pane:has(.composer) .reading { padding-bottom: 32px; }
  .keys { display: none; }
  .reading .subject { font-size: 21px; }
  .pane:not(.reading-pane) > .reading:has(> .composer) { padding-top: env(safe-area-inset-top, 0px); }
  .composer-bar .cancel { order: 1; width: auto; padding: 0 8px; color: var(--primary); font: 500 16px var(--sans); }
  .composer-bar .cancel .word { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .composer-bar .cancel .ic { display: none; }
  .composer-bar .spacer { order: 2; }
  .composer-bar .attach { order: 3; width: 40px; padding: 0; background: none; color: var(--muted); }
  .composer-bar .attach .word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .composer-bar .send { order: 4; }
  .composer-bar .discard { display: none; }
  .composer-foot .discard { display: inline-flex; }
  .composer-row > .auto-note { grid-column: 2 / -1; }
  .recipient:has(small) { font-weight: 500; }
  .recipient small { display: none; }
  .bill-strip { grid-template-columns: minmax(0, 1fr); }
  /* Above the tab bar, and above the open mail's action bar when a reply was just sent from it. */
  .outbox { bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
}

/* Desktop with a narrow pane (the list beside it is wide): the toolbar keeps to one row. Reply keeps its word; the
   other four show their icon, named by the hidden word and the tooltip. */
@media (min-width: 900px) {
  .reading-pane { container: pane / inline-size; }
}
@container pane (max-width: 660px) {
  .pane-actions .act:not(.primary) { padding: 0 11px; }
  .pane-actions .act:not(.primary) span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
