/* The email composer (public/mail_composer.js) and the email choices on Send for review and Members. The lab's own look:
   Inter, the warm page, white cards under soft shadows, one blue for what is chosen. A full-screen editing step: the
   template and its two variants on the left, the email as a recipient gets it on the right; on a phone, Edit and Preview
   tabs with the formatting bar held above the actions. */

/* ---- ProseMirror's own needs (prosemirror-view/style/prosemirror.css), scoped ---- */
.mail-composer .ProseMirror { position: relative; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; font-variant-ligatures: none; font-feature-settings: "liga" 0; }
.mail-composer .ProseMirror li { position: relative; }
.mail-composer .ProseMirror-hideselection *::selection { background: transparent; }
.mail-composer .ProseMirror-hideselection { caret-color: transparent; }
.mail-composer .ProseMirror [draggable][contenteditable=false] { user-select: text; }

/* ---- the frame ---- */
body.mail-composing .workspace-feedback-button { display: none; }
.mail-composer { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); }
.mail-composer.as-page { position: relative; inset: auto; z-index: auto; height: 100vh; height: 100dvh; background: transparent; margin: -38px -40px -110px; }
.mc-head { display: flex; align-items: center; gap: 16px; padding: 14px 24px; background: var(--surface); box-shadow: 0 1px 0 var(--line); position: relative; z-index: 3; }
.mc-title h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.mc-title .small { margin-top: 1px; }
.mc-close { width: 36px; height: 36px; padding: 0; border-radius: 10px; flex: none; }
.mc-pick { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.mc-pick-label { white-space: nowrap; }
.mc-picker { width: auto; min-width: 220px; max-width: 340px; }
.mc-state { flex: none; }
.mc-tabs { display: none; }
.mc-loading { margin-left: auto; }
.mc-main { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 0.9fr); gap: 24px; align-items: start;
  padding: 26px max(28px, calc((100% - 1400px) / 2)) 40px; }
.mc-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 22px 24px 24px; min-width: 0; }
.mc-error { max-width: 560px; margin: 48px auto; }
.mc-banner { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; background: var(--accent-soft); color: var(--accent-ink); border-radius: 10px; padding: 9px 12px; margin-bottom: 16px; font-size: 13px; }
.mc-banner[hidden] { display: none; }
.mc-activation { margin: 0 0 16px; padding: 9px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; line-height: 1.45; }

/* ---- edit card ---- */
.mc-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.mc-label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.mc-label-row .mc-label { margin: 0; }
.mc-namebar { margin-bottom: 16px; }
.mc-name { font-size: 15px; font-weight: 500; }
.mc-rows { display: grid; gap: 6px; padding: 12px 14px; border-radius: 12px; background: #fafaf8; box-shadow: inset 0 0 0 1px var(--line-soft); font-size: 13.5px; }
.mc-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.mc-row .k { color: var(--ink-3); font-size: 12.5px; }
.mc-row.who-gets { color: var(--ink-2); }
.mc-variants { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 20px 0 6px; }
.mc-variant { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; padding: 11px 14px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--field); color: var(--ink-2); font: 500 13.5px/1.3 var(--sans); transition: background 0.12s, color 0.12s; }
.mc-variant:hover { color: var(--ink); background: #f0f0ed; }
.mc-variant.on { background: var(--ink); color: #fff; }
.mc-variant:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mc-variant-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.mc-variant.has-problem .mc-variant-dot { background: var(--danger); }
.mc-variant-hint { margin: 0 0 18px; min-height: 1.4em; }
.mc-field { margin-top: 18px; }
.mc-subject-field { margin-top: 0; }
.mc-subject[hidden], .mc-body[hidden] { display: none; }

/* subject: one line, chips inline */
.mail-subject { min-height: 42px; padding: 9px 12px; border-radius: 10px; background: var(--field); font: 500 15px/1.5 var(--sans); outline: none; white-space: pre-wrap; overflow-wrap: anywhere; transition: background 0.12s, box-shadow 0.12s; }
.mail-subject:focus { background: var(--surface); box-shadow: 0 0 0 1.5px rgba(59, 130, 246, 0.55), 0 0 0 4px rgba(59, 130, 246, 0.14); }

/* body: a writing surface with the bar on top */
.mc-editor { display: flex; flex-direction: column; border-radius: 14px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-2); transition: box-shadow 0.12s; }
.mc-editor:focus-within { box-shadow: inset 0 0 0 1.5px rgba(59, 130, 246, 0.55), 0 0 0 4px rgba(59, 130, 246, 0.12); }
.mc-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(6px); border-radius: 14px 14px 0 0; }
.mc-tool { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; transition: background 0.1s, color 0.1s; }
.mc-tool:hover { background: var(--hover); color: var(--ink); }
.mc-tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.mc-tool:disabled { opacity: 0.32; cursor: default; background: transparent; }
.mc-tool:focus-visible, .mc-style:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
summary.mc-tool { width: auto; padding: 0 10px; list-style: none; font: 500 13px var(--sans); }
summary.mc-tool::-webkit-details-marker, .mc-varmenu summary::-webkit-details-marker { display: none; }
.mc-varmenu { position: relative; }
.mc-varmenu summary { list-style: none; }
.mc-varbtn.small-btn { display: inline-flex; gap: 5px; padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.mc-style { width: auto; height: 34px; padding: 4px 30px 4px 10px; font-size: 13px; font-weight: 500; background-color: transparent; border-radius: 8px; }
.mc-style:hover { background-color: var(--hover); }
.mc-sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 5px; flex: none; }
.mc-varlist { width: min(320px, 86vw); right: 0; left: auto !important; max-height: 360px; overflow: auto; gap: 2px; }
.mc-subject-field .mc-varlist { right: 0; }
.mc-varitem { display: grid !important; gap: 4px; width: 100%; padding: 9px 10px !important; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; border-radius: 9px; }
.mc-varitem:hover, .mc-varitem:focus-visible { background: var(--hover); outline: none; }
.mc-varitem-top { display: flex; align-items: center; gap: 8px; }
.mc-varitem-hint { font-size: 12px; line-height: 1.4; color: var(--ink-2); }
.mc-linkbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafaf8; }
.mc-linkbar[hidden] { display: none; }
.mc-linkbar input { flex: 1 1 240px; width: auto; min-width: 0; height: 34px; }
.small-btn { padding: 6px 11px; font-size: 13px; }

.mail-body { min-height: 360px; padding: 20px 24px 26px; outline: none; font: 16px/1.65 var(--sans); color: var(--ink); }
.mail-body p { margin: 0 0 14px; }
.mail-body h2 { font-size: 21px; line-height: 1.3; letter-spacing: -0.012em; margin: 22px 0 10px; }
.mail-body h3 { font-size: 17px; line-height: 1.35; color: var(--ink); margin: 18px 0 8px; }
.mail-body > :first-child { margin-top: 0; }
.mail-body ul, .mail-body ol { margin: 0 0 14px; padding-left: 26px; }
.mail-body li { margin: 0 0 4px; }
.mail-body li > p { margin: 0; }
.mail-body blockquote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid #d9d9de; color: var(--ink-2); }
.mail-body a, .mail-subject a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.mail-empty::before { content: attr(data-placeholder); position: absolute; color: var(--ink-3); pointer-events: none; }
.mail-body.mail-empty::before { top: 20px; left: 24px; }
.mail-subject.mail-empty::before { top: 9px; left: 12px; font-weight: 400; }

/* variables: chips, never raw tokens or addresses */
.mail-chip { display: inline-block; padding: 0 7px; margin: 0 1px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-ink);
  font: 500 0.86em/1.6 var(--sans); white-space: nowrap; vertical-align: 0.04em; cursor: default; user-select: none; }
.mail-chip.link { text-decoration: underline; text-underline-offset: 2px; }
.mail-chip.link::before { content: "↗ "; text-decoration: none; display: inline-block; margin-right: 1px; }
.mail-composer .ProseMirror-selectednode.mail-chip, .mail-chip.ProseMirror-selectednode { box-shadow: 0 0 0 2px var(--accent); }
strong .mail-chip { font-weight: 700; }
em .mail-chip { font-style: italic; }

.mc-required { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.mc-req { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; padding: 3px 10px 3px 8px; border-radius: 999px; }
.mc-req.ok { background: #eef7f0; color: #2f6b3f; }
.mc-req.missing { background: var(--danger-soft); color: var(--danger); }
.mc-problems { display: grid; gap: 6px; margin-top: 10px; }
.mc-problems:empty { display: none; }
.mc-problem { text-align: left; font: 13px/1.45 var(--sans); color: var(--danger); background: var(--danger-soft); border: 0; border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.mc-problem:hover { text-decoration: underline; }

/* ---- preview card ---- */
.mc-preview { position: sticky; top: 0; }
.mc-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.mc-preview-head h2 { margin: 0; }
.mc-preview-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.mc-preview-controls .seg { display: inline-flex; align-items: center; gap: 5px; }
.mc-pv-variant { margin-bottom: 8px; }
.mc-recipient { margin: 0 0 12px; }
.mc-stage { position: relative; display: flex; justify-content: center; background: #f2f2ef; border-radius: 14px; padding: 20px; min-height: 440px; }
.mc-stale { position: absolute; left: 20px; right: 20px; bottom: 20px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 500; box-shadow: var(--ring); }
.mc-stale[hidden] { display: none; }
.mc-check { margin: 12px 0 0; display: flex; align-items: center; gap: 6px; }
.ok-text { color: #2f6b3f; display: inline-flex; align-items: center; gap: 6px; }
.warn-text { color: var(--warn); }

.mail-device { width: 100%; max-width: 660px; background: #fff; border-radius: 12px; box-shadow: 0 1px 2px rgba(17, 17, 17, 0.06), 0 8px 24px -10px rgba(17, 17, 17, 0.2); overflow: hidden; align-self: flex-start; }
.mail-device.phone { max-width: 390px; border-radius: 34px; box-shadow: 0 0 0 9px #1d1d1f, 0 18px 40px -12px rgba(17, 17, 17, 0.45); margin: 10px 0; }
.mail-envelope { padding: 16px 22px 13px; border-bottom: 1px solid var(--line); }
.mail-device.phone .mail-envelope { padding: 26px 18px 12px; }
.mail-subject-line { font: 600 17px/1.35 var(--sans); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.mail-meta { display: grid; gap: 1px; margin-top: 7px; font-size: 12.5px; color: var(--ink-2); overflow-wrap: anywhere; }
.mail-meta .k { color: var(--ink-3); }
.mail-body-frame { padding: 22px 22px 26px; }
.mail-device.phone .mail-body-frame { padding: 16px 18px 30px; }
.mail-note { padding: 0 22px 16px; font-size: 12px; color: var(--ink-3); }

/* ---- footer: always in reach ---- */
.mc-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; background: var(--surface); box-shadow: 0 -1px 0 var(--line); position: relative; z-index: 3; }
.mc-foot-left, .mc-foot-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mc-foot-note { overflow: hidden; text-overflow: ellipsis; max-width: 460px; }
.mc-why { color: var(--warn); text-align: right; }
.mc-primary { min-width: 150px; }

/* ---- Send for review: the email step; Members: the invitation line ---- */
.mail-choice { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 18px; align-items: start; padding: 16px 18px; border-radius: 14px; background: #fafaf8; box-shadow: inset 0 0 0 1px var(--line-soft); }
.mail-choice-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.mail-choice-subjects { display: grid; gap: 3px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.mail-choice-subjects .k { color: var(--ink-3); margin-right: 6px; }
.mail-choice-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.mail-choice-warn { grid-column: 1 / -1; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.mail-final { margin-top: 12px; }
.mail-final > summary { cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.mail-final-body { display: grid; gap: 10px; margin-top: 10px; }
.mail-final-body .mc-stage { min-height: 0; padding: 14px; }
.req-email { display: inline-block; margin-top: 4px; }
.mail-pinned .sheet-card { width: min(760px, 100%); background: var(--surface); padding: 18px 22px 24px; }
.mail-pinned-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.mail-pinned-head h2 { margin: 0 0 2px; }
.mail-pinned-body { display: grid; gap: 12px; }
.mail-pinned-body .mail-choice-name { margin: 0; }
.mail-pinned-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.mail-pinned .mc-stage { min-height: 0; padding: 14px; }
.invite-choice { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: #fafaf8; box-shadow: inset 0 0 0 1px var(--line-soft); margin-top: 6px; }

/* ---- phones ---- */
@media (max-width: 760px) {
  /* On a phone the library page takes the whole screen, like the editing step. */
  .mail-composer.as-page { position: fixed; inset: 0; z-index: 70; height: auto; margin: 0; background: var(--bg); }
  .mc-head { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px 10px; }
  .mc-title { min-width: 0; }
  .mc-title h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mc-title .small { display: none; }
  .mc-tabs { display: inline-flex; margin-left: auto; }
  .mc-tabs .seg { padding: 7px 14px; }
  .mc-pick { order: 3; width: 100%; margin: 0; }
  .mc-pick-label { display: none; }
  .mc-picker { flex: 1; min-width: 0; max-width: none; }
  .mc-main { grid-template-columns: minmax(0, 1fr); padding: 12px 10px 16px; gap: 12px; }
  .mc-main[data-tab="edit"] .mc-preview, .mc-main[data-tab="preview"] .mc-edit { display: none; }
  .mc-card { padding: 16px 14px 18px; border-radius: 14px; }
  .mc-preview { position: static; }
  .mc-row { grid-template-columns: 72px minmax(0, 1fr); }
  .mc-variants { margin-top: 16px; }
  .mc-variant { padding: 11px 12px; font-size: 13px; min-height: 44px; }
  .mail-subject { font-size: 16px; min-height: 46px; }
  .mail-body { min-height: 300px; padding: 16px 16px 22px; font-size: 16px; }
  .mail-body.mail-empty::before { top: 16px; left: 16px; }
  /* The formatting bar sits under the text, above the actions, in reach of a thumb; it scrolls sideways. */
  .mc-toolbar { order: 3; position: sticky; top: auto; bottom: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; border-bottom: 0; border-top: 1px solid var(--line); border-radius: 0 0 14px 14px; padding: 4px;
    backdrop-filter: none; background: var(--surface); box-shadow: 0 -6px 14px -10px rgba(17, 17, 17, 0.25); }
  .mc-toolbar::-webkit-scrollbar { display: none; }
  .mc-linkbar { order: 2; border-bottom: 0; border-top: 1px solid var(--line); }
  .mc-tool { width: 44px; height: 44px; }
  .mc-varbtn.small-btn { min-height: 44px; padding: 0 14px; }
  summary.mc-tool { padding: 0 12px; }
  .mc-style { height: 44px; }
  /* The variable menu opens as a sheet over the page: the bar scrolls sideways and would clip it. */
  .mc-varmenu .menu-list { position: fixed !important; left: 10px !important; right: 10px !important; bottom: 128px; top: auto; width: auto; max-height: 52vh; z-index: 90; box-shadow: 0 0 0 1px var(--line), var(--shadow-lg); }
  .mc-stage { padding: 10px; min-height: 0; }
  .mail-device.phone { box-shadow: 0 0 0 6px #1d1d1f, 0 12px 28px -12px rgba(17, 17, 17, 0.4); margin: 6px; }
  .mc-preview-controls .seg span { display: none; }
  .mc-preview-controls .seg { padding: 6px 10px; }
  /* Actions in two rows at most: restore (an icon), check and save; then the one action this step is for. */
  .mc-foot { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .mc-foot-left, .mc-foot-right { display: contents; }
  .mc-foot-note { display: none; }
  .mc-restore { width: 44px; min-height: 44px; padding: 0; }
  .mc-restore span { display: none; }
  .mc-foot .ghost { min-height: 44px; }
  .mc-foot .mc-why { grid-column: 1 / -1; order: 4; text-align: left; }
  .mc-foot .mc-why:empty { display: none; }
  .mc-foot .mc-primary { grid-column: 1 / -1; order: 5; min-height: 46px; }
  .mail-choice { grid-template-columns: minmax(0, 1fr); }
  .mail-choice-actions { justify-content: flex-start; }
}
