/* The authenticated shell. The existing card editor and dialogs retain their own controls. */
:root {
  --line: #e3e5e8;
  --muted: #666c77;
  --mail-sub: #515762;
  --mail-pale: #f2f3f4;
}
body { background: white; font: 400 15px/1.5 var(--sans); }
.mail-app {
  display: grid; height: 100vh; height: 100dvh; overflow: hidden;
  grid-template: 56px minmax(0,1fr) / 84px minmax(0,1fr);
}
.mail-bar { position: relative; z-index: 3; grid-column: 1/-1; display:flex; align-items:center; justify-content:space-between; padding:0 22px; border-bottom:1px solid var(--line); }
.mail-app :where(.mail-brand, .mail-rail button, .workspace-menu summary, .mail-filters button, .reader-tools button) {
  display:inline-flex; align-items:center; justify-content:center; border:0; background:transparent; color:inherit; padding:0; border-radius:6px;
}
.mail-brand { gap:9px; min-height:44px; font:650 17px/1 var(--display); letter-spacing:-.025em; }
.mail-rail { grid-area:2/1; background:#fafafa; border-right:1px solid var(--line); padding:14px 6px; display:flex; flex-direction:column; gap:5px; }
.mail-rail button { flex-direction:column; gap:4px; min-height:56px; font-size:12px; color:var(--mail-sub); }
.mail-rail button[aria-current] { background:#e9ebed; color:var(--ink); font-weight:620; }
.mail-rail .icon { width:18px; height:18px; }
.mail-app .icon { stroke-width:1.65; }
.mail-bar button:hover, .mail-rail button:hover, .workspace-menu summary:hover, .mail-filters button:hover, .reader-tools button:not(:disabled):hover { background:#f3f4f5; }
.workspace-menu summary { list-style:none; width:44px; min-height:44px; cursor:pointer; }
.workspace-menu summary::-webkit-details-marker { display:none; }
.workspace-menu summary .icon { width:20px; height:20px; }
.workspace-menu-panel { position:absolute; right:14px; top:calc(100% - 3px); z-index:3; display:grid; gap:2px; width:min(310px,calc(100vw - 24px)); padding:8px; max-height:calc(100dvh - 68px); overflow:auto; border:1px solid var(--line); border-radius:10px; box-shadow:0 8px 24px #17191d18; background:white; }
.workspace-menu-panel > .btn { justify-content:flex-start; min-height:38px; }
.menu-settings { display:grid; gap:10px; margin:5px 4px; padding:12px 2px; border-block:1px solid var(--line); }
.menu-settings .project-switcher { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--mail-sub); }
.menu-settings .project-select-wrap { flex:1; min-width:0; }
.menu-settings .project-select-wrap select { width:100%; max-width:100%; }
.menu-settings .filter-chips { flex-wrap:wrap; }
.menu-settings .search { width:100%; max-width:none; }
.mail-main { grid-area:2/2; min-width:0; min-height:0; overflow:auto; }
.mail-app:has(.mail-rail[hidden]) .mail-main { grid-column:1/-1; }
#workspace, .mail-inbox { height:100%; }
.view-page { width:min(100%,940px); margin-inline:auto; padding:24px clamp(20px,5vw,72px) 48px; }
.view-page > h1, .queue-heading h1 { font:620 17px/1.25 var(--display); letter-spacing:-.025em; }
.view-page > h1 { margin-bottom:20px; }
.mail-main .doc-sheet { margin:0; border:0; border-radius:0; box-shadow:none; }
.mail-inbox { display:grid; grid-template-columns:clamp(310px,31vw,410px) minmax(0,1fr); }
.mail-queue,.mail-reader { min-height:0; min-width:0; display:flex; flex-direction:column; }
.mail-queue { border-right:1px solid var(--line); }
.queue-heading { display:flex; align-items:center; justify-content:space-between; gap:8px; min-height:65px; padding:8px 22px; border-bottom:1px solid var(--line); }
.mail-filters { display:flex; gap:2px; }
.mail-filters button { min-height:40px; padding:0 12px; font-size:13px; color:var(--muted); }
.mail-filters button[aria-pressed=true] { background:var(--mail-pale); font-weight:620; color:var(--ink); }
.queue-scroll,.reader-scroll { flex:1; overflow:auto; overscroll-behavior:contain; scrollbar-width:thin; }
#mail-list { list-style:none; margin:0; padding:0; }
#pull-indicator { display:none; }
@media(max-width:819px) {
  /* Safari's 100vh body can be taller than the visible 100dvh shell. While
     the Inbox list is showing, only its queue may scroll, not the page/tabs. */
  :is(html, body, .mail-main):has(#workspace:not([hidden]) > #inbox-view:not([hidden], .show-letter)) {
    overflow:hidden;
    overscroll-behavior-y:none;
  }
  body:has(#workspace:not([hidden]) > #inbox-view:not([hidden], .show-letter)) {
    position:fixed;
    inset:0;
    min-height:0;
  }
  #inbox-scroll { min-height:0; overscroll-behavior-y:none; }
  /* No native vertical pan to hand off to Safari for an empty/short queue.
     Keep taps, horizontal gestures, pinch zoom and our pull-to-refresh. */
  #inbox-scroll[data-fits] { touch-action:pan-x pinch-zoom; }
  #pull-indicator { display:grid; place-items:center; flex:none; height:var(--pull-height,0px); overflow:hidden; pointer-events:none; }
  #pull-indicator .pull-dots { width:24px; height:24px; transform:rotate(var(--pull-angle,0deg)); }
  /* Track the finger directly. Only ease the list back after release. */
  #pull-indicator:is([data-phase="refreshing"],[data-phase="idle"]) { transition:height .24s cubic-bezier(.2,.75,.3,1); }
  #pull-indicator[data-phase="idle"] .pull-dots { opacity:0; transition:opacity .14s ease-out; }
  #pull-indicator[data-phase="pulling"] .pull-dots { opacity:.72; }
  #pull-indicator[data-phase="refreshing"] .pull-dots { animation:glamp-pull-orbit .9s linear infinite; }
}
@keyframes glamp-pull-orbit {
  from { transform:rotate(var(--pull-angle,0deg)); }
  to { transform:rotate(calc(var(--pull-angle,0deg) + 1turn)); }
}
@media(prefers-reduced-motion:reduce) {
  #pull-indicator .pull-dots, #pull-indicator[data-phase="refreshing"] .pull-dots { animation:none; transform:none; }
}
.mail-message { display:block; width:100%; text-align:left; padding:15px 22px; border:0; border-bottom:1px solid var(--line); background:transparent; overflow-wrap:anywhere; text-decoration:none; color:inherit; }
.mail-message:focus-visible { outline-offset:-3px; }
.mail-message:hover,.mail-message[aria-current] { background:#f5f6f7; }
.mail-sender-row,.mail-ident,.mail-meta,.reader-tools,.mail-stepper,.mail-byline,.mail-actions { display:flex; align-items:center; }
.mail-sender-row { justify-content:space-between; gap:8px; }
.mail-ident { gap:7px; font-size:13px; color:var(--mail-sub); }
.mail-message .unread-dot { width:6px; height:6px; flex:none; border-radius:50%; background:#3a66a0; box-shadow:none; }
.mail-message time { flex:none; color:var(--muted); font-size:12px; }
.mail-subject { display:block; margin:4px 0; font-size:16px; font-weight:490; line-height:1.35; letter-spacing:-.015em; }
.mail-message.unread .mail-subject { font-weight:620; }
.mail-meta { gap:7px; font-size:12px; line-height:1.35; color:var(--muted); flex-wrap:wrap; }
.mail-meta span + span::before { content:'·'; margin-right:7px; color:#9398a0; }
.mail-done { color:#486454; }
.mail-review,.mail-due-today { color:#845323; }
.mail-placeholder { padding:20px 22px; font-size:14px; color:var(--muted); }
.reader-tools { justify-content:flex-end; gap:12px; min-height:65px; padding:0 clamp(18px,4vw,60px); }
.mail-stepper { gap:4px; }
.reader-tools button { min-height:40px; min-width:40px; font-size:13px; }
.reader-tools button:disabled { opacity:.4; cursor:default; }
.reader-tools button .icon { width:15px; height:15px; }
#mail-back { display:none; }
.mail-letter { max-width:800px; margin:auto; padding:12px clamp(22px,4.2vw,65px) 44px; overflow-wrap:anywhere; }
.mail-letter h2#letter-title { font:620 clamp(22px,2.1vw,32px)/1.18 var(--display); letter-spacing:-.035em; text-wrap:balance; margin:10px 0; }
.mail-byline { flex-wrap:wrap; gap:8px; color:var(--muted); font-size:13px; }
.mail-byline strong { color:#303238; font-weight:560; }
.mail-byline time::before { content:'·'; margin-right:8px; }
.mail-letter .md-body { margin-top:20px; padding:0; color:#303238; line-height:1.65; font-size:15px; }
.mail-letter .md-body p:first-child { margin-top:0; }
.mail-letter figure { margin:16px 0; }
.mail-letter figure img { display:block; max-width:100%; height:auto; border-radius:4px; }
.mail-letter figcaption { margin-top:4px; font-size:12px; color:var(--muted); }
.mail-actions { gap:8px; flex-wrap:wrap; margin-top:24px; }
.mail-actions button { display:inline-flex; align-items:center; justify-content:center; gap:7px; min-height:40px; padding:8px 14px; font-size:13px; font-weight:560; border-radius:6px; border:1px solid var(--line); background:white; }
.mail-actions button:hover { background:var(--mail-pale); }
.mail-actions .mail-primary { background:var(--ink); color:white; border-color:var(--ink); }
.mail-actions .mail-primary:hover { background:#36393e; }
.mail-actions .icon { width:15px; height:15px; }
.mail-intro { color:var(--muted); font-size:14px; }
@media(max-width:819px) {
  .mail-app { grid-template:minmax(56px,auto) minmax(0,1fr) auto / minmax(0,1fr); }
  .mail-bar { grid-area:1/1; padding:0 18px; }
  .mail-main { grid-area:2/1; }
  .mail-rail { grid-area:3/1; display:flex; flex-direction:row; padding:3px 6px calc(3px + env(safe-area-inset-bottom,0px)); gap:4px; border:0; border-top:1px solid var(--line); background:white; }
  .mail-rail button { flex:1; position:relative; min-height:47px; flex-direction:row; gap:7px; font-size:13px; }
  .mail-rail button[aria-current] { background:none; }
  .mail-rail button[aria-current]::before { content:''; position:absolute; top:-4px; left:24%; right:24%; height:2px; background:var(--ink); }
  .mail-rail .icon { width:16px; height:16px; }
  .view-page { padding:20px 18px 38px; }
  .mail-inbox { display:block; }
  .mail-reader { display:none; height:100%; }
  .mail-queue { border:0; height:100%; }
  .mail-inbox.show-letter .mail-reader { display:flex; }
  .mail-inbox.show-letter .mail-queue { display:none; }
  .queue-heading { min-height:57px; padding:5px 18px; }
  .mail-filters button { min-height:44px; }
  .mail-message { padding:14px 18px; }
  .mail-message[aria-current] { background:white; }
  .reader-tools { justify-content:space-between; padding:0 12px; min-height:48px; }
  .reader-tools button { min-height:44px; min-width:44px; }
  #mail-back { display:flex; align-items:center; gap:3px; padding:0 6px; color:var(--mail-sub); }
  .mail-letter { padding:16px 20px 32px; max-width:680px; }
  .mail-letter h2#letter-title { font-size:24px; }
  .notice { bottom:calc(68px + env(safe-area-inset-bottom,0px)); }
}

.mail-gallery .image-zoom { width:fit-content; max-width:100%; }
/* Only the open image stage takes over pinch/pan; normal page zoom and
   scrolling stay native everywhere else, including the gallery thumbnails. */
#photo-viewer {
  position:fixed; inset:0; margin:0; width:100%; max-width:none; height:100vh; height:100dvh; max-height:none;
  padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px);
  background:#141517; color:#f4f5f6; border:0; border-radius:0; overflow:hidden; box-shadow:none;
}
#photo-viewer[open] { display:grid; grid-template-rows:auto minmax(0,1fr) auto; }
#photo-viewer::backdrop { background:#141517; }
.photo-bar,.photo-tools { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:4px 12px; min-width:0; }
#photo-caption { font-size:14px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
#photo-viewer button { min-width:44px; min-height:44px; flex:none; padding:0 10px; border:0; border-radius:8px; background:transparent; color:inherit; font:inherit; touch-action:manipulation; }
#photo-viewer button:enabled:hover { background:#303135; }
#photo-viewer button:disabled { color:#999; }
#photo-viewer button:focus-visible { outline:2px solid white; outline-offset:-3px; }
#photo-stage { position:relative; min-height:0; overflow:hidden; touch-action:none; overscroll-behavior:none; user-select:none; -webkit-user-select:none; background:#0b0c0d; }
#photo-stage.magnified { cursor:grab; }
#photo-stage.magnified:active { cursor:grabbing; }
#photo-full { position:absolute; left:50%; top:50%; max-width:none; max-height:none; pointer-events:none; -webkit-touch-callout:none; }
#photo-status:not(:empty) { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); text-align:center; font-size:14px; }
#photo-hint { font-size:12px; color:#c6c8cc; }
.photo-tools [role=group] { display:flex; flex:none; align-items:center; }
#photo-viewer :is(#photo-plus,#photo-minus) { font-size:20px; }
