/* ==========================================================
   SEHL MAIL — MOBILE COMPOSER UX V2
   Phone/tablet only. Desktop remains untouched.
   ========================================================== */

:root {
  --sehl-composer-safe-bottom: env(safe-area-inset-bottom, 0px);
  --sehl-composer-safe-left: env(safe-area-inset-left, 0px);
  --sehl-composer-safe-right: env(safe-area-inset-right, 0px);
  --sehl-keyboard-inset: 0px;
  --sehl-compactbar-h: 58px;

  /* SEHL-MAIL-THEME-SEMANTIC-V1

     Mobile Composer consumes the canonical light/dark theme. */

  --sehl-cmp-bg: var(--bg);
  --sehl-cmp-panel: var(--surface);
  --sehl-cmp-panel-2: var(--surface-2);
  --sehl-cmp-border: var(--line);
  --sehl-cmp-border-strong: color-mix(in srgb,var(--gold) 42%,var(--line));
  --sehl-cmp-text: var(--ink);
  --sehl-cmp-muted: var(--ink-soft);
  --sehl-cmp-accent: var(--gold-deep);
  --sehl-cmp-shadow: var(--sh-3);
  --sehl-cmp-radius: 18px;
}

@media (max-width: 900px), ((max-width: 1100px) and (pointer: coarse)) {

  /* ----- Composer root ----- */

  .sehl-mobile-composer-v2 {
    --sehl-composer-inline:
      max(12px, var(--sehl-composer-safe-left));
    position: relative;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .sehl-mobile-composer-v2.sehl-cmp-keyboard {
    height: var(--sehl-vvh, 100dvh) !important;
    max-height: var(--sehl-vvh, 100dvh) !important;
  }

  /* Native-feeling touch sizing, but do not inflate editor controls. */
  .sehl-mobile-composer-v2 button,
  .sehl-mobile-composer-v2 [role="button"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  /* ----- Recipient suggestions ----- */

  .sehl-mobile-composer-v2 [role="listbox"],
  .sehl-mobile-composer-v2 [class*="suggest" i],
  .sehl-mobile-composer-v2 [id*="suggest" i],
  .sehl-mobile-composer-v2 [class*="autocomplete" i],
  .sehl-mobile-composer-v2 [id*="autocomplete" i],
  .sehl-mobile-composer-v2 [class*="people" i][class*="list" i],
  .sehl-mobile-composer-v2 [class*="recipient" i][class*="list" i] {
    max-height: min(176px, 25vh) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sehl-mobile-composer-v2 [role="listbox"]::-webkit-scrollbar,
  .sehl-mobile-composer-v2 [class*="suggest" i]::-webkit-scrollbar,
  .sehl-mobile-composer-v2 [class*="autocomplete" i]::-webkit-scrollbar {
    display: none;
  }

  /* Suggestions should never grow into a full-screen panel. */
  .sehl-mobile-composer-v2.sehl-cmp-focus-to [role="listbox"],
  .sehl-mobile-composer-v2.sehl-cmp-focus-to [class*="suggest" i],
  .sehl-mobile-composer-v2.sehl-cmp-focus-to [id*="suggest" i],
  .sehl-mobile-composer-v2.sehl-cmp-focus-to [class*="autocomplete" i] {
    max-height: 168px !important;
  }

  /* ----- Full formatting toolbar ----- */

  .sehl-mobile-composer-v2 #fmtBar {
    transition:
      opacity .16s ease,
      transform .20s cubic-bezier(.22,.8,.22,1),
      visibility .16s ease;
  }

  /* Recipient and Subject typing: formatter must stay out of the way. */
  .sehl-mobile-composer-v2.sehl-cmp-focus-to #fmtBar,
  .sehl-mobile-composer-v2.sehl-cmp-focus-subject #fmtBar {
    display: none !important;
  }

  /*
   * In mobile body editing the original formatter becomes a bottom sheet.
   * It is CLOSED unless .sehl-format-sheet-open is present.
   */
  .sehl-mobile-composer-v2.sehl-cmp-focus-body #fmtBar:not(.sehl-format-sheet-open),
  .sehl-mobile-composer-v2.sehl-cmp-keyboard #fmtBar:not(.sehl-format-sheet-open) {
    display: none !important;
  }

  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open {
    position: fixed !important;
    z-index: 10030 !important;
    left: max(10px, var(--sehl-composer-safe-left)) !important;
    right: max(10px, var(--sehl-composer-safe-right)) !important;
    bottom:
      calc(
        var(--sehl-keyboard-inset, 0px) +
        var(--sehl-compactbar-h) +
        8px
      ) !important;

    display: flex !important;
    flex-wrap: wrap !important;
    align-content: flex-start;
    gap: 8px !important;

    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: min(38vh, 310px) !important;

    padding: 12px !important;
    margin: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;

    border: 1px solid var(--sehl-cmp-border) !important;
    border-radius: var(--sehl-cmp-radius) !important;
    background: color-mix(in srgb,var(--sehl-cmp-panel) 97%,transparent) !important;
    box-shadow: var(--sehl-cmp-shadow) !important;

    -webkit-backdrop-filter: blur(20px) saturate(145%);
    backdrop-filter: blur(20px) saturate(145%);
  }

  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open > * {
    flex: 0 0 auto;
  }

  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open select,
  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open input,
  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open button,
  .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open [role="button"] {
    min-height: 42px;
  }

  /* ----- Editor body ----- */

  .sehl-mobile-composer-v2 #cBody {
    min-height: 110px !important;
    max-height:
      calc(
        var(--sehl-vvh, 100dvh) -
        var(--sehl-keyboard-inset, 0px) -
        290px
      ) !important;

    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--sehl-compactbar-h) + 18px) !important;
    scroll-padding-bottom: calc(var(--sehl-compactbar-h) + 26px);
  }

  /* ----- Custom SEHL compact toolbar ----- */

  #sehlComposerCompactBar {
    position: fixed;
    z-index: 10020;

    left: max(12px, var(--sehl-composer-safe-left));
    right: max(12px, var(--sehl-composer-safe-right));
    bottom:
      calc(
        var(--sehl-keyboard-inset, 0px) +
        max(8px, var(--sehl-composer-safe-bottom))
      );

    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 6px;

    min-height: var(--sehl-compactbar-h);
    padding: 6px 8px;

    border: 1px solid var(--sehl-cmp-border);
    border-radius: 22px;
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb,var(--sehl-cmp-panel-2) 98%,transparent),
        color-mix(in srgb,var(--sehl-cmp-panel) 98%,transparent)
      );

    box-shadow:
      0 12px 34px rgba(0,0,0,.34),
      inset 0 1px 0 color-mix(in srgb,var(--ink) 4%,transparent);

    -webkit-backdrop-filter: blur(18px) saturate(140%);
    backdrop-filter: blur(18px) saturate(140%);
  }

  .sehl-mobile-composer-v2.sehl-cmp-focus-body #sehlComposerCompactBar,
  .sehl-mobile-composer-v2.sehl-cmp-keyboard.sehl-cmp-focus-body #sehlComposerCompactBar {
    display: flex;
  }

  /*
   * When recipient or subject is active, do NOT waste vertical space
   * with a composer toolbar.
   */
  .sehl-mobile-composer-v2.sehl-cmp-focus-to #sehlComposerCompactBar,
  .sehl-mobile-composer-v2.sehl-cmp-focus-subject #sehlComposerCompactBar {
    display: none !important;
  }

  #sehlComposerCompactBar .sehl-cmp-left,
  #sehlComposerCompactBar .sehl-cmp-right {
    display: flex;
    align-items: center;
    gap: 3px;
  }

  #sehlComposerCompactBar .sehl-cmp-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;

    padding: 0;
    margin: 0;

    border: 0;
    border-radius: 14px;
    background: transparent;
    color: var(--sehl-cmp-muted);

    appearance: none;
    -webkit-appearance: none;

    transition:
      background .13s ease,
      color .13s ease,
      transform .10s ease;
  }

  #sehlComposerCompactBar .sehl-cmp-icon:active {
    transform: scale(.94);
    background: color-mix(in srgb,var(--ink) 6%,transparent);
  }

  #sehlComposerCompactBar .sehl-cmp-icon[aria-pressed="true"] {
    color: var(--sehl-cmp-accent);
    background: color-mix(in srgb,var(--gold) 10%,transparent);
  }

  #sehlComposerCompactBar .sehl-cmp-icon svg {
    width: 22px;
    height: 22px;
    overflow: visible;

    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;

    pointer-events: none;
  }

  /* Slightly different geometry for the SEHL "A" icon. */
  #sehlComposerCompactBar .sehl-cmp-format svg {
    width: 23px;
    height: 23px;
  }

  #sehlComposerCompactBar .sehl-cmp-send {
    width: 48px;
    min-width: 48px;
    border: 1px solid var(--sehl-cmp-border-strong);
    background:
      linear-gradient(
        180deg,
        color-mix(in srgb,var(--gold) 18%,transparent),
        color-mix(in srgb,var(--gold) 9%,transparent)
      );
    color: var(--gold-deep);
  }

  #sehlComposerCompactBar .sehl-cmp-send:active {
    background: color-mix(in srgb,var(--gold) 19%,transparent);
  }

  #sehlComposerCompactBar .sehl-cmp-divider {
    width: 1px;
    height: 26px;
    margin: 0 3px;
    background: var(--sehl-cmp-border);
  }

  #sehlComposerCompactBar .sehl-cmp-icon:focus-visible {
    outline: 2px solid color-mix(in srgb,var(--gold) 55%,transparent);
    outline-offset: 2px;
  }

  /* Small status chip used only when an action has no direct core hook. */
  #sehlComposerToast {
    position: fixed;
    z-index: 10060;
    left: 50%;
    bottom:
      calc(
        var(--sehl-keyboard-inset, 0px) +
        var(--sehl-compactbar-h) +
        24px
      );
    transform: translateX(-50%) translateY(8px);

    max-width: min(82vw, 340px);
    padding: 9px 13px;

    border: 1px solid var(--sehl-cmp-border);
    border-radius: 999px;
    background: color-mix(in srgb,var(--sehl-cmp-panel) 96%,transparent);
    color: var(--sehl-cmp-text);
    box-shadow: 0 12px 34px rgba(0,0,0,.35);

    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
  }

  #sehlComposerToast.sehl-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  /* ----- Full formatter dim layer ----- */

  #sehlComposerFormatBackdrop {
    position: fixed;
    z-index: 10025;
    inset: 0;

    display: none;
    background: rgba(0,0,0,.22);
    -webkit-backdrop-filter: blur(1px);
    backdrop-filter: blur(1px);
  }

  .sehl-mobile-composer-v2.sehl-cmp-format-open #sehlComposerFormatBackdrop {
    display: block;
  }

  /* ----- Phone tuning ----- */

  @media (max-width: 560px) {
    :root {
      --sehl-compactbar-h: 56px;
    }

    #sehlComposerCompactBar {
      border-radius: 20px;
      padding-inline: 6px;
    }

    #sehlComposerCompactBar .sehl-cmp-icon {
      width: 42px;
      min-width: 42px;
      height: 42px;
      min-height: 42px;
      border-radius: 13px;
    }

    #sehlComposerCompactBar .sehl-cmp-send {
      width: 46px;
      min-width: 46px;
    }

    .sehl-mobile-composer-v2 #fmtBar.sehl-format-sheet-open {
      left: 8px !important;
      right: 8px !important;
      border-radius: 17px !important;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  #sehlComposerCompactBar *,
  #sehlComposerToast,
  .sehl-mobile-composer-v2 #fmtBar {
    transition-duration: .001ms !important;
    animation-duration: .001ms !important;
  }
}


/* SEHL MAIL RECOVERY DIALOG V1 */

.sehl-recovery-overlay {
  position: fixed;
  z-index: 20000;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  padding:
    max(24px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));

  background: rgba(4, 7, 11, .54);

  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);

  opacity: 0;
  transition: opacity .18s ease;
}

.sehl-recovery-overlay.sehl-recovery-visible {
  opacity: 1;
}

.sehl-recovery-card {
  width: min(100%, 430px);

  padding: 22px;

  border: 1px solid rgba(190, 173, 128, .22);
  border-radius: 24px;

  background:
    radial-gradient(
      circle at 10% 0%,
      rgba(215, 194, 143, .07),
      transparent 34%
    ),
    linear-gradient(
      180deg,
      rgba(30, 36, 46, .99),
      rgba(18, 23, 31, .99)
    );

  box-shadow:
    0 30px 90px rgba(0, 0, 0, .52),
    inset 0 1px 0 color-mix(in srgb,var(--ink) 4%,transparent);

  color: var(--ink);
}

.sehl-recovery-icon {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 48px;
  height: 48px;
  margin-bottom: 18px;

  border: 1px solid rgba(215, 194, 143, .28);
  border-radius: 16px;

  color: var(--gold);

  background:
    linear-gradient(
      180deg,
      rgba(215,194,143,.12),
      rgba(215,194,143,.045)
    );
}

.sehl-recovery-icon svg {
  width: 26px;
  height: 26px;

  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sehl-recovery-copy {
  margin-bottom: 24px;
}

.sehl-recovery-eyebrow {
  margin-bottom: 7px;

  color: var(--gold);

  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
}

.sehl-recovery-card h2 {
  margin: 0 0 8px;

  color: var(--ink);

  font-size: 23px;
  font-weight: 680;
  line-height: 1.15;
}

.sehl-recovery-card p {
  margin: 0;

  color: var(--ink-soft);

  font-size: 15px;
  line-height: 1.5;
}

.sehl-recovery-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sehl-recovery-btn {
  min-height: 48px;
  padding: 0 18px;

  border-radius: 15px;

  font: inherit;
  font-size: 15px;
  font-weight: 650;

  appearance: none;
  -webkit-appearance: none;

  cursor: pointer;
  touch-action: manipulation;
}

.sehl-recovery-discard {
  border: 1px solid rgba(159, 172, 194, .16);
  background: color-mix(in srgb,var(--ink) 3%,transparent);
  color: var(--ink-soft);
}

.sehl-recovery-restore {
  border: 1px solid rgba(215, 194, 143, .38);

  background:
    linear-gradient(
      180deg,
      rgba(215,194,143,.20),
      rgba(215,194,143,.09)
    );

  color: var(--gold-deep);
}

.sehl-recovery-btn:active {
  transform: scale(.98);
}

.sehl-recovery-btn:focus-visible {
  outline: 2px solid rgba(215, 194, 143, .62);
  outline-offset: 2px;
}

@media (max-width: 560px) {
  .sehl-recovery-card {
    padding: 20px;
    border-radius: 22px;
  }

  .sehl-recovery-card h2 {
    font-size: 22px;
  }

  .sehl-recovery-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sehl-recovery-overlay,
  .sehl-recovery-btn {
    transition: none !important;
  }
}


/* SEHL-MAIL-PROSEMIRROR-WEBKIT-STABILITY-V1 */
#cBody .sehl-prosemirror{
  color:var(--ink)!important;
  background:var(--surface)!important;
  caret-color:var(--ink);
  -webkit-user-select:text;
  user-select:text;
  -webkit-touch-callout:default;
}
#cBody .sehl-prosemirror::selection{
  background:color-mix(in srgb,var(--gold) 28%,transparent);
}

/* SEHL-MOBILE-COMPOSER-CONTRACT-V3 START */

/*
 * iPhone / mobile composer contract:
 *
 * - visualViewport is the geometry authority
 * - header and footer stay inside the visible viewport
 * - cw-body is the scrolling surface
 * - editor never exceeds viewport width
 * - no second keyboard subtraction
 * - editable text is >=16px to prevent iOS focus zoom
 */

@media (max-width:900px),
       ((max-width:1100px) and (pointer:coarse)) {

  #cw.sehl-mobile-composer-v2,
  #cw.sehl-mobile-composer-v2.max {
    position: fixed !important;

    top: var(--sehl-vv-top, 0px) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;

    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;

    height: var(--sehl-vvh, 100dvh) !important;
    min-height: 0 !important;
    max-height: var(--sehl-vvh, 100dvh) !important;

    margin: 0 !important;
    box-sizing: border-box !important;

    display: flex !important;
    flex-direction: column !important;

    overflow: hidden !important;

    transform: none !important;
  }


  /* ---------- HEADER ---------- */

  #cw.sehl-mobile-composer-v2 .cw-head {
    position: relative !important;

    flex: 0 0 auto !important;

    width: 100% !important;
    min-width: 0 !important;

    box-sizing: border-box !important;
  }


  /* ---------- SCROLLING CONTENT ---------- */

  #cw.sehl-mobile-composer-v2 .cw-body {
    position: relative !important;

    flex: 1 1 auto !important;

    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;

    min-height: 0 !important;

    box-sizing: border-box !important;

    overflow-x: hidden !important;
    overflow-y: auto !important;

    overscroll-behavior: contain;

    -webkit-overflow-scrolling: touch;

    padding-bottom:
      calc(
        var(--sehl-compactbar-h, 54px) +
        28px +
        max(
          8px,
          var(--sehl-composer-safe-bottom)
        )
      ) !important;
  }


  /* ---------- FIELD ROWS ---------- */

  #cw.sehl-mobile-composer-v2 .cw-row {
    width: 100% !important;

    min-width: 0 !important;
    max-width: 100% !important;

    grid-template-columns:
      46px minmax(0,1fr) auto !important;

    box-sizing: border-box !important;
  }

  #cw.sehl-mobile-composer-v2 .cw-row > * {
    min-width: 0 !important;
    max-width: 100%;
  }

  #cw.sehl-mobile-composer-v2 .cw-row input {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;

    box-sizing: border-box !important;
  }


  /*
   * Critical for iOS:
   * 16px prevents Safari/WebKit from zooming the viewport
   * when an editable control receives focus.
   */

  #cw.sehl-mobile-composer-v2 input,
  #cw.sehl-mobile-composer-v2 textarea,
  #cw.sehl-mobile-composer-v2 [contenteditable="true"],
  #cw.sehl-mobile-composer-v2 #cBody,
  #cw.sehl-mobile-composer-v2 #cBody .sehl-prosemirror {
    font-size: 16px !important;

    -webkit-text-size-adjust: 100%;
  }


  /* ---------- EDITOR ---------- */

  #cw.sehl-mobile-composer-v2 #cBody {
    width: 100% !important;

    min-width: 0 !important;
    max-width: 100% !important;

    min-height: 180px !important;
    max-height: none !important;

    box-sizing: border-box !important;

    overflow: visible !important;

    padding-bottom: 18px !important;
  }

  #cw.sehl-mobile-composer-v2
  #cBody .sehl-prosemirror {
    position: relative !important;

    width: 100% !important;

    min-width: 0 !important;
    max-width: 100% !important;

    min-height: 180px !important;

    box-sizing: border-box !important;

    overflow-wrap: anywhere !important;
    word-break: break-word;

    color: var(--ink) !important;
    caret-color: var(--ink) !important;
  }


  /*
   * The visible viewport already excludes the keyboard.
   * Do not subtract keyboardInset again from the editor.
   */

  #cw.sehl-mobile-composer-v2.sehl-cmp-keyboard {
    height: var(--sehl-vvh, 100dvh) !important;
    max-height: var(--sehl-vvh, 100dvh) !important;
  }


  /* ---------- MOBILE TOOLBAR ---------- */

  #cw.sehl-mobile-composer-v2
  #sehlComposerCompactBar {
    position: absolute !important;

    left:
      max(
        12px,
        var(--sehl-composer-safe-left)
      ) !important;

    right:
      max(
        12px,
        var(--sehl-composer-safe-right)
      ) !important;

    bottom:
      max(
        8px,
        var(--sehl-composer-safe-bottom)
      ) !important;

    max-width: none !important;

    box-sizing: border-box !important;
  }


  /* ---------- FOOTER ---------- */

  #cw.sehl-mobile-composer-v2 .cw-foot {
    position: relative !important;

    flex: 0 0 auto !important;

    width: 100% !important;
    min-width: 0 !important;

    box-sizing: border-box !important;
  }
}

/* SEHL-MOBILE-COMPOSER-CONTRACT-V3 END */
