@postalsys/ee-client 1.8.2 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +2 -0
  2. package/index.d.ts +15 -6
  3. package/index.js +650 -196
  4. package/package.json +16 -9
package/index.js CHANGED
@@ -65,6 +65,31 @@ const MESSAGE_BODY_STYLES = `
65
65
  }
66
66
  `;
67
67
 
68
+ // Inline SVG icons (24x24 grid, stroked with currentColor so they follow the button's text
69
+ // colour in both themes). Static markup only, nothing here is built from message data.
70
+ const ICON_PATHS = {
71
+ back: '<path d="m15 18-6-6 6-6"/>',
72
+ next: '<path d="m9 18 6-6-6-6"/>',
73
+ chevronDown: '<path d="m6 9 6 6 6-6"/>',
74
+ mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
75
+ mailOpen:
76
+ '<path d="M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z"/><path d="m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10"/>',
77
+ trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
78
+ move: '<path d="M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1"/><path d="M2 13h10"/><path d="m9 16 3-3-3-3"/>',
79
+ download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/><path d="M12 15V3"/>',
80
+ send: '<path d="m22 2-7 20-4-9-9-4Z"/><path d="M22 2 11 13"/>',
81
+ compose: '<path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/>'
82
+ };
83
+
84
+ // Below this container width the UI shows one pane at a time and the compose button
85
+ // drops its label. Shared by the stylesheet's container query and the compose button
86
+ // sizing, which cannot use the query because the button is not inside .ee-client.
87
+ const NARROW_WIDTH = 700;
88
+
89
+ function icon(name, size = 16) {
90
+ return `<svg class="ee-icon" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${ICON_PATHS[name]}</svg>`;
91
+ }
92
+
68
93
  export class EmailEngineClient {
69
94
  constructor(options = {}) {
70
95
  this.apiUrl = options.apiUrl || 'http://127.0.0.1:3000';
@@ -79,16 +104,11 @@ export class EmailEngineClient {
79
104
  // A containerId that matches nothing is almost always a typo; warn
80
105
  // rather than silently degrading to a UI-less, API-only client.
81
106
  if (!this.container) {
82
- console.warn(
83
- `EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`
84
- );
107
+ console.warn(`EmailEngineClient: no element found for containerId "${options.containerId}"; UI rendering disabled`);
85
108
  }
86
109
  }
87
- this.confirmMethod =
88
- options.confirmMethod ||
89
- ((message, _title = 'Confirm', _cancelText = 'Cancel', _okText = 'OK') => confirm(message));
90
- this.alertMethod =
91
- options.alertMethod || ((message, _title = 'Notice', _cancelText = null, _okText = 'OK') => alert(message));
110
+ this.confirmMethod = options.confirmMethod || ((message, _title = 'Confirm', _cancelText = 'Cancel', _okText = 'OK') => confirm(message));
111
+ this.alertMethod = options.alertMethod || ((message, _title = 'Notice', _cancelText = null, _okText = 'OK') => alert(message));
92
112
 
93
113
  this.currentFolder = null;
94
114
  this.currentMessage = null;
@@ -124,8 +144,7 @@ export class EmailEngineClient {
124
144
  this.styleNonce = typeof options.styleNonce === 'string' && options.styleNonce ? options.styleNonce : null;
125
145
 
126
146
  // Get page size from localStorage or options or default
127
- const savedPageSize =
128
- typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
147
+ const savedPageSize = typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
129
148
  const requestedPageSize = savedPageSize ? parseInt(savedPageSize, 10) : parseInt(options.pageSize, 10);
130
149
  this.pageSize = requestedPageSize > 0 ? requestedPageSize : 20;
131
150
 
@@ -151,16 +170,14 @@ export class EmailEngineClient {
151
170
  try {
152
171
  const nodeFetch = await import('node-fetch');
153
172
  fetchFn = nodeFetch.default;
154
- } catch (err) {
173
+ } catch {
155
174
  // node-fetch is not installed; the guard below reports it
156
175
  }
157
176
  }
158
177
 
159
178
  if (!fetchFn) {
160
179
  // Either node-fetch is missing or it exposed no callable default export
161
- throw new Error(
162
- 'fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch'
163
- );
180
+ throw new Error('fetch is not available. In Node.js environments, please install node-fetch: npm install node-fetch');
164
181
  }
165
182
 
166
183
  try {
@@ -183,7 +200,7 @@ export class EmailEngineClient {
183
200
  let details;
184
201
  try {
185
202
  details = await response.json();
186
- } catch (parseError) {
203
+ } catch {
187
204
  // Not a JSON body - the status line is all there is to go on
188
205
  details = { message: response.statusText };
189
206
  }
@@ -196,7 +213,7 @@ export class EmailEngineClient {
196
213
 
197
214
  async apiRequest(method, endpoint, data = null) {
198
215
  const options = {
199
- method: method,
216
+ method,
200
217
  headers: {
201
218
  'Content-Type': 'application/json',
202
219
  ...this._authHeaders()
@@ -250,10 +267,11 @@ export class EmailEngineClient {
250
267
  }
251
268
 
252
269
  async loadMessages(path, cursor = null) {
253
- this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
270
+ this._setView('list');
271
+ this._setPaneHtml('.ee-message-list', `${this._messageListHeader(path)}<div class="ee-loading">Loading messages...</div>`);
254
272
 
255
273
  try {
256
- const params = new URLSearchParams({ path: path, pageSize: this.pageSize });
274
+ const params = new URLSearchParams({ path, pageSize: this.pageSize });
257
275
  if (cursor) {
258
276
  params.set('cursor', cursor);
259
277
  }
@@ -280,15 +298,20 @@ export class EmailEngineClient {
280
298
  };
281
299
  } catch (error) {
282
300
  console.error('Failed to load messages:', error);
283
- this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () =>
284
- this._fireAndForget(this.loadMessages(path, cursor))
301
+ this._renderPaneError(
302
+ '.ee-message-list',
303
+ 'Messages unavailable',
304
+ error,
305
+ () => this._fireAndForget(this.loadMessages(path, cursor)),
306
+ this._messageListHeader(path)
285
307
  );
286
308
  throw error;
287
309
  }
288
310
  }
289
311
 
290
312
  async loadMessage(messageId) {
291
- this._setPaneHtml('.ee-message-viewer', '<div class="ee-loading">Loading message...</div>');
313
+ this._setView('message');
314
+ this._setPaneHtml('.ee-message-viewer', `${this._messageToolbar()}<div class="ee-loading">Loading message...</div>`);
292
315
 
293
316
  try {
294
317
  const params = new URLSearchParams({
@@ -324,8 +347,12 @@ export class EmailEngineClient {
324
347
  return this.currentMessage;
325
348
  } catch (error) {
326
349
  console.error('Failed to load message:', error);
327
- this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () =>
328
- this._fireAndForget(this.loadMessage(messageId))
350
+ this._renderPaneError(
351
+ '.ee-message-viewer',
352
+ 'Message unavailable',
353
+ error,
354
+ () => this._fireAndForget(this.loadMessage(messageId)),
355
+ this._messageToolbar()
329
356
  );
330
357
  throw error;
331
358
  }
@@ -408,9 +435,7 @@ export class EmailEngineClient {
408
435
  }
409
436
 
410
437
  _normalizeRecipients(to) {
411
- return Array.isArray(to)
412
- ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr))
413
- : [typeof to === 'string' ? { address: to } : to];
438
+ return Array.isArray(to) ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr)) : [typeof to === 'string' ? { address: to } : to];
414
439
  }
415
440
 
416
441
  // Account details (name, email address) fetched once and cached for the lifetime
@@ -426,8 +451,8 @@ export class EmailEngineClient {
426
451
  try {
427
452
  const messageData = {
428
453
  to: this._normalizeRecipients(to),
429
- subject: subject,
430
- text: text
454
+ subject,
455
+ text
431
456
  };
432
457
 
433
458
  const response = await this.apiRequest('POST', `${this._accountPath()}/submit`, messageData);
@@ -451,8 +476,8 @@ export class EmailEngineClient {
451
476
  const messageData = {
452
477
  path: draftsFolder.path,
453
478
  flags: ['\\Draft'],
454
- subject: subject,
455
- text: text
479
+ subject,
480
+ text
456
481
  };
457
482
 
458
483
  const recipients = to ? this._normalizeRecipients(to) : [];
@@ -467,7 +492,7 @@ export class EmailEngineClient {
467
492
  if (accountInfo && accountInfo.email) {
468
493
  messageData.from = { name: accountInfo.name || '', address: accountInfo.email };
469
494
  }
470
- } catch (err) {
495
+ } catch {
471
496
  // Non-fatal: the draft is saved without a From header
472
497
  }
473
498
 
@@ -570,11 +595,12 @@ export class EmailEngineClient {
570
595
  // missing, optionally with a Retry button. Without this a failed request
571
596
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
572
597
  // only trace of the failure in the developer console.
573
- _renderPaneError(selector, title, error, retry = null) {
598
+ _renderPaneError(selector, title, error, retry = null, header = '') {
574
599
  const detail = this._errorMessage(error, '');
575
600
  const pane = this._setPaneHtml(
576
601
  selector,
577
602
  `
603
+ ${header}
578
604
  <div class="ee-error">
579
605
  <div class="ee-error-title">${this.escapeHtml(title)}</div>
580
606
  ${detail ? `<div class="ee-error-detail">${this.escapeHtml(detail)}</div>` : ''}
@@ -618,14 +644,54 @@ export class EmailEngineClient {
618
644
  // The message list before any folder is opened. Shared with createLayout so the
619
645
  // pane header markup lives in one place.
620
646
  _messageListPlaceholder() {
647
+ return `${this._messageListHeader(null)}<div class="ee-empty-state">Select a folder</div>`;
648
+ }
649
+
650
+ // Header for every state of the message list pane, titled with the folder
651
+ // being shown. In the single-pane layout its back button leads to the folders.
652
+ _messageListHeader(path, controls = '') {
653
+ const folder = path && this.folders.find(f => f.path === path);
621
654
  return `
622
655
  <div class="ee-pane-header">
623
- <span class="ee-pane-title">Messages</span>
656
+ <div class="ee-pane-heading">
657
+ ${this._iconButton('show-folders', 'back', 'Folders', 'ee-nav-button')}
658
+ <span class="ee-pane-title">${this.escapeHtml(folder ? folder.name : 'Messages')}</span>
659
+ </div>
660
+ ${controls}
624
661
  </div>
625
- <div class="ee-empty-state">Select a folder</div>
626
662
  `;
627
663
  }
628
664
 
665
+ // The viewer's toolbar row. It stays up in the loading, empty and error states
666
+ // too, so the header band runs unbroken across the panes and the single-pane
667
+ // layout always has its way back to the list.
668
+ _messageToolbar(actions = '') {
669
+ return `
670
+ <div class="ee-message-actions">
671
+ ${this._iconButton('back-to-list', 'back', 'Back to messages', 'ee-nav-button')}
672
+ ${actions}
673
+ </div>
674
+ `;
675
+ }
676
+
677
+ _messageViewerPlaceholder() {
678
+ return `${this._messageToolbar()}<div class="ee-empty-state">Select a message to view</div>`;
679
+ }
680
+
681
+ // Which pane the single-pane (narrow) layout shows: folders, list or message.
682
+ // Wider layouts show all three and ignore it.
683
+ _getView() {
684
+ const client = this.container && this.container.querySelector('.ee-client');
685
+ return client ? client.dataset.view : null;
686
+ }
687
+
688
+ _setView(view) {
689
+ const client = this.container && this.container.querySelector('.ee-client');
690
+ if (client) {
691
+ client.dataset.view = view;
692
+ }
693
+ }
694
+
629
695
  formatDate(dateStr) {
630
696
  const date = new Date(dateStr);
631
697
  const now = new Date();
@@ -649,6 +715,84 @@ export class EmailEngineClient {
649
715
  return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
650
716
  }
651
717
 
718
+ /**
719
+ * Markup for the "Code requested" box of a message that carries a one-time passcode
720
+ * (EmailEngine's `otp` field, from the OTP-Token header). The site the code is for is named
721
+ * only when EmailEngine reports the origin as authenticated: the header itself is not, and
722
+ * anyone can send a message claiming a code for any site.
723
+ *
724
+ * @param {{code: string, origin: string, authenticated?: boolean}} [otp]
725
+ * @returns {string} HTML, or an empty string when there is no passcode
726
+ */
727
+ renderOtpBox(otp) {
728
+ if (!otp || typeof otp.code !== 'string' || !otp.code) {
729
+ return '';
730
+ }
731
+
732
+ // one tile per character for a code a person reads off and types, as Gmail does
733
+ const code = /^[A-Za-z0-9]{1,10}$/.test(otp.code)
734
+ ? Array.from(otp.code, ch => `<span class="ee-otp-char">${this.escapeHtml(ch)}</span>`).join('')
735
+ : `<span class="ee-otp-text">${this.escapeHtml(otp.code)}</span>`;
736
+
737
+ let site = '';
738
+ if (otp.authenticated) {
739
+ try {
740
+ site = new URL(otp.origin).host;
741
+ } catch {
742
+ // leave the site out rather than show a value that does not parse
743
+ }
744
+ }
745
+
746
+ return `
747
+ <div class="ee-otp" role="region" aria-label="Code requested">
748
+ <div class="ee-otp-title">Code requested${site ? ` for <span class="ee-otp-site">${this.escapeHtml(site)}</span>` : ''}</div>
749
+ <div class="ee-otp-code" aria-label="${this.escapeHtml(otp.code)}">${code}</div>
750
+ <div class="ee-otp-actions">
751
+ <button type="button" class="ee-button ee-otp-copy" data-action="copy-otp">Copy code</button>
752
+ <span class="ee-otp-status" aria-live="polite"></span>
753
+ </div>
754
+ ${site ? '' : '<div class="ee-otp-note">The sender of this code could not be verified</div>'}
755
+ </div>
756
+ `;
757
+ }
758
+
759
+ /**
760
+ * Copies text to the clipboard. The Clipboard API needs a secure context, so a page served
761
+ * over plain http falls back to a selected textarea and execCommand
762
+ *
763
+ * @param {string} text
764
+ * @returns {Promise<boolean>} Whether the text was copied
765
+ */
766
+ async copyText(text) {
767
+ if (typeof navigator !== 'undefined' && navigator.clipboard && typeof window !== 'undefined' && window.isSecureContext) {
768
+ try {
769
+ await navigator.clipboard.writeText(text);
770
+ return true;
771
+ } catch {
772
+ // fall through to the legacy path
773
+ }
774
+ }
775
+
776
+ if (typeof document === 'undefined') {
777
+ return false;
778
+ }
779
+
780
+ const textarea = document.createElement('textarea');
781
+ textarea.value = text;
782
+ textarea.setAttribute('readonly', '');
783
+ textarea.style.position = 'fixed';
784
+ textarea.style.top = '-1000px';
785
+ document.body.appendChild(textarea);
786
+ textarea.select();
787
+ try {
788
+ return document.execCommand('copy');
789
+ } catch {
790
+ return false;
791
+ } finally {
792
+ textarea.remove();
793
+ }
794
+ }
795
+
652
796
  escapeHtml(value) {
653
797
  if (value === null || value === undefined) {
654
798
  return '';
@@ -660,7 +804,7 @@ export class EmailEngineClient {
660
804
  _authHeaders() {
661
805
  const headers = {};
662
806
  if (this.accessToken) {
663
- headers['Authorization'] = `Bearer ${this.accessToken}`;
807
+ headers.Authorization = `Bearer ${this.accessToken}`;
664
808
  }
665
809
  return headers;
666
810
  }
@@ -712,12 +856,7 @@ export class EmailEngineClient {
712
856
  this._saveBlob(blob, filename);
713
857
  } catch (error) {
714
858
  console.error('Failed to download attachment:', error);
715
- this.alertMethod(
716
- this._errorMessage(error, 'Failed to download attachment. Please try again.'),
717
- 'Download Error',
718
- null,
719
- 'OK'
720
- );
859
+ this.alertMethod(this._errorMessage(error, 'Failed to download attachment. Please try again.'), 'Download Error', null, 'OK');
721
860
  }
722
861
  }
723
862
 
@@ -737,12 +876,7 @@ export class EmailEngineClient {
737
876
  this._saveBlob(blob, filename);
738
877
  } catch (error) {
739
878
  console.error('Failed to download original message:', error);
740
- this.alertMethod(
741
- this._errorMessage(error, 'Failed to download original message. Please try again.'),
742
- 'Download Error',
743
- null,
744
- 'OK'
745
- );
879
+ this.alertMethod(this._errorMessage(error, 'Failed to download original message. Please try again.'), 'Download Error', null, 'OK');
746
880
  }
747
881
  }
748
882
 
@@ -776,6 +910,9 @@ export class EmailEngineClient {
776
910
  background: #fff;
777
911
  border: 1px solid #ddd;
778
912
  position: relative;
913
+ /* Layout breakpoints follow the widget's own width, not the viewport:
914
+ hosts embed it in pages of any shape */
915
+ container: ee-client / inline-size;
779
916
  }
780
917
 
781
918
  .ee-client * {
@@ -783,7 +920,8 @@ export class EmailEngineClient {
783
920
  }
784
921
 
785
922
  .ee-sidebar {
786
- width: 200px;
923
+ width: clamp(160px, 18%, 220px);
924
+ flex-shrink: 0;
787
925
  background: #ffffff;
788
926
  border-right: 1px solid #ddd;
789
927
  display: flex;
@@ -863,7 +1001,8 @@ export class EmailEngineClient {
863
1001
  }
864
1002
 
865
1003
  .ee-message-list {
866
- width: 350px;
1004
+ width: clamp(260px, 32%, 380px);
1005
+ flex-shrink: 0;
867
1006
  border-right: 1px solid #ddd;
868
1007
  background: #ffffff;
869
1008
  display: flex;
@@ -944,45 +1083,117 @@ export class EmailEngineClient {
944
1083
 
945
1084
  .ee-message-viewer {
946
1085
  flex: 1;
1086
+ min-width: 0;
947
1087
  display: flex;
948
1088
  flex-direction: column;
949
1089
  overflow: hidden;
1090
+ container: ee-viewer / inline-size;
950
1091
  }
951
1092
 
952
1093
  .ee-message-actions {
953
- padding: 10px 16px;
1094
+ padding: 0 12px;
954
1095
  background: #e9ecef;
955
1096
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
956
1097
  border-bottom: 2px solid #dee2e6;
957
1098
  display: flex;
958
- gap: 8px;
1099
+ gap: 6px;
959
1100
  height: 44px;
960
1101
  align-items: center;
961
1102
  flex-shrink: 0;
962
1103
  box-sizing: border-box;
963
1104
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1105
+ overflow-x: auto;
1106
+ scrollbar-width: none;
964
1107
  }
965
1108
 
966
1109
  .ee-button {
967
- padding: 4px 10px;
968
- border: 1px solid #ddd;
1110
+ display: inline-flex;
1111
+ align-items: center;
1112
+ justify-content: center;
1113
+ gap: 6px;
1114
+ flex-shrink: 0;
1115
+ padding: 0 10px;
1116
+ border: 1px solid #d0d4d9;
969
1117
  background: white;
970
- border-radius: 4px;
1118
+ color: #333;
1119
+ border-radius: 6px;
971
1120
  cursor: pointer;
972
- font-size: 12px;
973
- height: 24px;
1121
+ font-family: inherit;
1122
+ font-size: 13px;
1123
+ font-weight: 500;
1124
+ height: 30px;
974
1125
  line-height: 1;
1126
+ white-space: nowrap;
975
1127
  box-sizing: border-box;
976
1128
  }
977
1129
 
978
- select.ee-button {
979
- padding: 3px 10px;
980
- height: 24px;
981
- }
982
-
983
1130
  .ee-button:hover:not(:disabled) {
984
1131
  background: #f0f0f0;
985
1132
  }
1133
+
1134
+ .ee-button:focus-visible,
1135
+ .ee-move-button:focus-within,
1136
+ .ee-compose-button:focus-visible {
1137
+ outline: 2px solid #4d9fff;
1138
+ outline-offset: 1px;
1139
+ }
1140
+
1141
+ .ee-icon {
1142
+ flex-shrink: 0;
1143
+ }
1144
+
1145
+ .ee-icon-button {
1146
+ width: 30px;
1147
+ padding: 0;
1148
+ }
1149
+
1150
+ .ee-nav-button {
1151
+ display: none;
1152
+ }
1153
+
1154
+ /* Borderless, so a back arrow beside the title does not read as one
1155
+ of the pagination arrows */
1156
+ .ee-client .ee-button.ee-nav-button {
1157
+ background: transparent;
1158
+ border-color: transparent;
1159
+ margin-left: -6px;
1160
+ }
1161
+
1162
+ .ee-toolbar-spacer {
1163
+ flex: 1;
1164
+ }
1165
+
1166
+ .ee-button-primary {
1167
+ background: #007bff;
1168
+ border-color: #007bff;
1169
+ color: white;
1170
+ }
1171
+
1172
+ .ee-button-primary:hover:not(:disabled) {
1173
+ background: #0069d9;
1174
+ }
1175
+
1176
+ .ee-button-danger:hover:not(:disabled) {
1177
+ background: #fdecea;
1178
+ border-color: #f1b0ab;
1179
+ color: #c62828;
1180
+ }
1181
+
1182
+ .ee-move-button {
1183
+ position: relative;
1184
+ }
1185
+
1186
+ /* The native select covers the whole button, invisibly, so a click
1187
+ anywhere on it opens the platform folder picker */
1188
+ .ee-move-select {
1189
+ position: absolute;
1190
+ inset: 0;
1191
+ width: 100%;
1192
+ height: 100%;
1193
+ opacity: 0;
1194
+ cursor: pointer;
1195
+ font-size: 14px;
1196
+ }
986
1197
 
987
1198
  .ee-button:disabled {
988
1199
  background: #e9ecef;
@@ -993,23 +1204,114 @@ export class EmailEngineClient {
993
1204
 
994
1205
  .ee-message-content {
995
1206
  flex: 1;
996
- padding: 16px;
1207
+ /* The bottom padding lets the end of the message scroll clear of
1208
+ the floating compose button */
1209
+ padding: 20px 20px 88px;
997
1210
  overflow-y: auto;
998
1211
  }
1212
+
1213
+ .ee-message-title {
1214
+ margin: 0 0 12px;
1215
+ font-size: 20px;
1216
+ font-weight: 600;
1217
+ line-height: 1.3;
1218
+ overflow-wrap: anywhere;
1219
+ }
999
1220
 
1000
1221
  .ee-message-meta {
1222
+ display: grid;
1223
+ grid-template-columns: auto minmax(0, 1fr);
1224
+ gap: 2px 12px;
1001
1225
  margin-bottom: 16px;
1002
1226
  padding-bottom: 16px;
1003
1227
  border-bottom: 1px solid #e0e0e0;
1004
1228
  }
1005
1229
 
1006
1230
  .ee-message-meta-row {
1007
- margin-bottom: 4px;
1231
+ display: contents;
1232
+ }
1233
+
1234
+ .ee-message-meta-value {
1235
+ overflow-wrap: anywhere;
1236
+ }
1237
+
1238
+ .ee-otp {
1239
+ margin-bottom: 16px;
1240
+ padding: 14px 16px;
1241
+ background: #eef3fb;
1242
+ border-radius: 8px;
1243
+ }
1244
+
1245
+ .ee-otp-title {
1246
+ font-size: 13px;
1247
+ color: #444;
1248
+ margin-bottom: 10px;
1249
+ overflow-wrap: anywhere;
1250
+ }
1251
+
1252
+ .ee-otp-site {
1253
+ font-weight: 600;
1254
+ }
1255
+
1256
+ .ee-otp-code {
1257
+ display: flex;
1258
+ flex-wrap: wrap;
1259
+ gap: 6px;
1260
+ margin-bottom: 12px;
1261
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
1262
+ font-size: 22px;
1263
+ }
1264
+
1265
+ .ee-otp-char {
1266
+ display: inline-flex;
1267
+ align-items: center;
1268
+ justify-content: center;
1269
+ min-width: 32px;
1270
+ height: 40px;
1271
+ background: white;
1272
+ border-radius: 6px;
1273
+ }
1274
+
1275
+ .ee-otp-text {
1276
+ padding: 6px 10px;
1277
+ background: white;
1278
+ border-radius: 6px;
1279
+ font-size: 16px;
1280
+ overflow-wrap: anywhere;
1281
+ user-select: all;
1282
+ }
1283
+
1284
+ .ee-otp-actions {
1285
+ display: flex;
1286
+ align-items: center;
1287
+ gap: 10px;
1288
+ }
1289
+
1290
+ .ee-otp .ee-otp-copy {
1291
+ height: 32px;
1292
+ padding: 0 16px;
1293
+ font-size: 13px;
1294
+ background: #007bff;
1295
+ border-color: #007bff;
1296
+ color: white;
1297
+ border-radius: 16px;
1298
+ }
1299
+
1300
+ .ee-otp .ee-otp-copy:hover:not(:disabled) {
1301
+ background: #0069d9;
1302
+ }
1303
+
1304
+ .ee-otp-status,
1305
+ .ee-otp-note {
1306
+ font-size: 12px;
1307
+ color: #666;
1308
+ }
1309
+
1310
+ .ee-otp-note {
1311
+ margin-top: 10px;
1008
1312
  }
1009
1313
 
1010
1314
  .ee-message-meta-label {
1011
- display: inline-block;
1012
- width: 60px;
1013
1315
  color: #666;
1014
1316
  font-weight: 500;
1015
1317
  }
@@ -1119,7 +1421,8 @@ export class EmailEngineClient {
1119
1421
  }
1120
1422
 
1121
1423
  .ee-pane-header {
1122
- padding: 10px 16px;
1424
+ gap: 8px;
1425
+ padding: 0 12px 0 16px;
1123
1426
  background: #e9ecef;
1124
1427
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
1125
1428
  border-bottom: 2px solid #dee2e6;
@@ -1132,10 +1435,20 @@ export class EmailEngineClient {
1132
1435
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1133
1436
  }
1134
1437
 
1438
+ .ee-pane-heading {
1439
+ display: flex;
1440
+ align-items: center;
1441
+ gap: 6px;
1442
+ min-width: 0;
1443
+ }
1444
+
1135
1445
  .ee-pane-title {
1136
- font-weight: 500;
1446
+ font-weight: 600;
1137
1447
  font-size: 14px;
1138
1448
  color: #333;
1449
+ overflow: hidden;
1450
+ text-overflow: ellipsis;
1451
+ white-space: nowrap;
1139
1452
  }
1140
1453
 
1141
1454
  .ee-folder-tree {
@@ -1145,15 +1458,16 @@ export class EmailEngineClient {
1145
1458
 
1146
1459
  .ee-pagination-controls {
1147
1460
  display: flex;
1148
- gap: 8px;
1461
+ gap: 6px;
1149
1462
  align-items: center;
1463
+ flex-shrink: 0;
1150
1464
  }
1151
1465
 
1152
1466
  .ee-page-size-selector {
1153
1467
  display: flex;
1154
- gap: 4px;
1468
+ gap: 6px;
1155
1469
  align-items: center;
1156
- margin-left: auto;
1470
+ margin-left: 4px;
1157
1471
  }
1158
1472
 
1159
1473
  .ee-page-size-label {
@@ -1162,49 +1476,100 @@ export class EmailEngineClient {
1162
1476
  }
1163
1477
 
1164
1478
  .ee-page-size-select {
1165
- font-size: 11px;
1166
- padding: 2px 4px;
1167
- border: 1px solid #ddd;
1168
- border-radius: 3px;
1169
- background: white;
1170
- cursor: pointer;
1171
- height: 22px;
1172
- }
1173
-
1174
- .ee-pagination-btn {
1175
- font-size: 11px;
1176
- padding: 3px 8px;
1177
- height: 22px;
1178
- line-height: 1;
1479
+ padding: 0 4px;
1179
1480
  }
1180
1481
 
1181
1482
  .ee-message-items {
1182
1483
  flex: 1;
1183
1484
  overflow-y: auto;
1485
+ padding-bottom: 88px;
1184
1486
  }
1185
1487
 
1186
1488
  .ee-compose-button {
1187
1489
  position: fixed;
1188
1490
  bottom: 20px;
1189
1491
  right: 20px;
1190
- width: 56px;
1191
- height: 56px;
1492
+ display: inline-flex;
1493
+ align-items: center;
1494
+ gap: 10px;
1495
+ height: 52px;
1496
+ padding: 0 22px 0 18px;
1192
1497
  background: #007bff;
1193
1498
  border: none;
1194
- border-radius: 50%;
1499
+ border-radius: 16px;
1195
1500
  color: white;
1196
- font-size: 24px;
1501
+ font-family: var(--ee-font, inherit);
1502
+ font-size: 15px;
1503
+ font-weight: 600;
1197
1504
  cursor: pointer;
1198
1505
  box-shadow: 0 4px 12px rgba(0,123,255,0.3);
1199
1506
  z-index: 1000;
1200
- transition: all 0.2s ease;
1507
+ transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1201
1508
  }
1202
1509
 
1203
1510
  .ee-compose-button:hover {
1204
1511
  background: #0056b3;
1205
- transform: scale(1.05);
1512
+ transform: translateY(-1px);
1206
1513
  box-shadow: 0 6px 16px rgba(0,123,255,0.4);
1207
1514
  }
1515
+
1516
+ .ee-compose-button.ee-compose-compact {
1517
+ width: 56px;
1518
+ height: 56px;
1519
+ padding: 0;
1520
+ justify-content: center;
1521
+ border-radius: 50%;
1522
+ }
1523
+
1524
+ .ee-compose-compact .ee-compose-button-label {
1525
+ display: none;
1526
+ }
1527
+
1528
+ /* Medium widths: the viewer is too narrow for labelled buttons, so the
1529
+ toolbar goes icon-only, as webmail toolbars usually are */
1530
+ @container ee-viewer (max-width: 559px) {
1531
+ .ee-message-actions .ee-button:not(.ee-keep-label) .ee-button-label {
1532
+ display: none;
1533
+ }
1534
+
1535
+ .ee-message-actions .ee-button:not(.ee-keep-label) {
1536
+ width: 30px;
1537
+ padding: 0;
1538
+ }
1539
+
1540
+ .ee-message-actions .ee-move-button {
1541
+ width: 44px;
1542
+ gap: 2px;
1543
+ }
1544
+ }
1545
+
1546
+ /* Narrow widths: one pane at a time, in the order a phone mail app uses
1547
+ (folders, list, message), with back buttons in the pane headers. The
1548
+ shown pane follows data-view on .ee-client. */
1549
+ @container ee-client (max-width: ${NARROW_WIDTH - 1}px) {
1550
+ .ee-sidebar,
1551
+ .ee-message-list,
1552
+ .ee-message-viewer {
1553
+ display: none;
1554
+ width: 100%;
1555
+ flex: 1;
1556
+ border-right: 0;
1557
+ }
1558
+
1559
+ .ee-client[data-view="folders"] .ee-sidebar,
1560
+ .ee-client[data-view="list"] .ee-message-list,
1561
+ .ee-client[data-view="message"] .ee-message-viewer {
1562
+ display: flex;
1563
+ }
1564
+
1565
+ .ee-nav-button {
1566
+ display: inline-flex;
1567
+ }
1568
+
1569
+ .ee-message-content {
1570
+ padding: 16px 16px 88px;
1571
+ }
1572
+ }
1208
1573
 
1209
1574
  .ee-compose-modal {
1210
1575
  display: none;
@@ -1385,24 +1750,21 @@ export class EmailEngineClient {
1385
1750
  opacity: 0.6;
1386
1751
  }
1387
1752
 
1388
- /* Dark mode toggle button */
1753
+ /* Dark mode toggle button, in the Folders pane header */
1389
1754
  .ee-dark-mode-toggle {
1390
- position: absolute;
1391
- top: 8px;
1392
- right: 16px;
1393
1755
  background: #f8f9fa;
1394
1756
  border: 1px solid #dee2e6;
1395
- border-radius: 3px;
1396
- padding: 6px 10px;
1397
- font-size: 12px;
1757
+ border-radius: 6px;
1758
+ padding: 0;
1759
+ width: 30px;
1760
+ height: 30px;
1761
+ flex-shrink: 0;
1398
1762
  cursor: pointer;
1399
- z-index: 100;
1400
1763
  transition: all 0.2s ease;
1401
1764
  display: flex;
1402
1765
  align-items: center;
1403
1766
  justify-content: center;
1404
1767
  color: #495057;
1405
- font-weight: 500;
1406
1768
  }
1407
1769
 
1408
1770
  .ee-dark-mode-toggle:hover {
@@ -1515,6 +1877,27 @@ export class EmailEngineClient {
1515
1877
  border-color: #555;
1516
1878
  }
1517
1879
 
1880
+ .ee-dark-mode .ee-button-primary,
1881
+ .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
1882
+ background: #0056b3;
1883
+ border-color: #0056b3;
1884
+ color: white;
1885
+ }
1886
+
1887
+ .ee-dark-mode .ee-button-danger:hover:not(:disabled) {
1888
+ background: #4a2323;
1889
+ border-color: #7a3434;
1890
+ color: #f0a5a5;
1891
+ }
1892
+
1893
+ .ee-dark-mode .ee-message-meta {
1894
+ border-color: #333;
1895
+ }
1896
+
1897
+ .ee-dark-mode .ee-message-meta-label {
1898
+ color: #999;
1899
+ }
1900
+
1518
1901
  .ee-dark-mode .ee-button:disabled {
1519
1902
  background: #222;
1520
1903
  color: #666;
@@ -1532,10 +1915,18 @@ export class EmailEngineClient {
1532
1915
  }
1533
1916
 
1534
1917
  .ee-dark-mode .ee-attachments {
1535
- background: #252525;
1536
1918
  border-color: #333;
1537
1919
  }
1538
1920
 
1921
+ .ee-dark-mode .ee-attachments-title,
1922
+ .ee-dark-mode .ee-attachment-name {
1923
+ color: #e0e0e0;
1924
+ }
1925
+
1926
+ .ee-dark-mode .ee-attachment-size {
1927
+ color: #999;
1928
+ }
1929
+
1539
1930
  .ee-dark-mode .ee-attachment-item {
1540
1931
  background: #2a2a2a;
1541
1932
  border-color: #333;
@@ -1556,24 +1947,60 @@ export class EmailEngineClient {
1556
1947
  color: #f0a5a5;
1557
1948
  }
1558
1949
 
1950
+ .ee-dark-mode .ee-otp {
1951
+ background: #23303f;
1952
+ }
1953
+
1954
+ .ee-dark-mode .ee-otp-title {
1955
+ color: #ccc;
1956
+ }
1957
+
1958
+ .ee-dark-mode .ee-otp-char,
1959
+ .ee-dark-mode .ee-otp-text {
1960
+ background: #1a1a1a;
1961
+ color: #e0e0e0;
1962
+ }
1963
+
1964
+ .ee-dark-mode .ee-otp .ee-otp-copy {
1965
+ background: #0056b3;
1966
+ border-color: #0056b3;
1967
+ color: white;
1968
+ }
1969
+
1970
+ .ee-dark-mode .ee-otp-status,
1971
+ .ee-dark-mode .ee-otp-note {
1972
+ color: #999;
1973
+ }
1974
+
1559
1975
  .ee-dark-mode .ee-pagination {
1560
1976
  background: #252525;
1561
1977
  border-color: #333;
1562
1978
  }
1563
1979
 
1564
- .ee-dark-mode .ee-compose-button {
1980
+ /* The compose button and modal sit beside .ee-client, not inside it, so
1981
+ setDarkMode puts the ee-dark-mode class on them directly */
1982
+ .ee-compose-button.ee-dark-mode {
1565
1983
  background: #0056b3;
1984
+ color: white;
1566
1985
  }
1567
1986
 
1568
- .ee-dark-mode .ee-compose-modal {
1987
+ .ee-compose-button.ee-dark-mode:hover {
1988
+ background: #004a99;
1989
+ }
1990
+
1991
+ .ee-compose-modal.ee-dark-mode {
1569
1992
  background: rgba(0, 0, 0, 0.7);
1570
1993
  }
1571
1994
 
1572
- .ee-dark-mode .ee-compose-content {
1995
+ .ee-dark-mode .ee-compose-dialog {
1573
1996
  background: #202020;
1574
1997
  color: #e0e0e0;
1575
1998
  }
1576
1999
 
2000
+ .ee-dark-mode .ee-compose-label {
2001
+ color: #ccc;
2002
+ }
2003
+
1577
2004
  .ee-dark-mode .ee-compose-header {
1578
2005
  background: linear-gradient(to bottom, #2a2a2a, #252525);
1579
2006
  border-color: #333;
@@ -1765,41 +2192,39 @@ export class EmailEngineClient {
1765
2192
  }
1766
2193
 
1767
2194
  if (!this.messages.length) {
1768
- messageList.innerHTML = `
1769
- <div class="ee-pane-header">
1770
- <span class="ee-pane-title">Messages</span>
1771
- </div>
1772
- <div class="ee-empty-state">No messages</div>
1773
- `;
2195
+ messageList.innerHTML = `${this._messageListHeader(this.currentFolder)}<div class="ee-empty-state">No messages</div>`;
1774
2196
  return;
1775
2197
  }
1776
2198
 
1777
2199
  const hasPagination = this.nextPageCursor || this.prevPageCursor;
1778
2200
 
1779
- const html = `
1780
- <div class="ee-pane-header">
1781
- <span class="ee-pane-title">Messages</span>
2201
+ // Both arrows stay in place once there is more than one page, the unavailable
2202
+ // one disabled, so the controls do not shift under the pointer between pages
2203
+ const controls = `
1782
2204
  <div class="ee-pagination-controls">
1783
2205
  ${
1784
2206
  hasPagination
1785
2207
  ? `
1786
- ${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
1787
- ${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
2208
+ ${this._iconButton('prev-page', 'back', 'Previous page', '', !this.prevPageCursor)}
2209
+ ${this._iconButton('next-page', 'next', 'Next page', '', !this.nextPageCursor)}
1788
2210
  `
1789
2211
  : ''
1790
2212
  }
1791
- <div class="ee-page-size-selector">
1792
- <span class="ee-page-size-label">Show:</span>
1793
- <select class="ee-page-size-select" data-action="page-size">
2213
+ <label class="ee-page-size-selector" title="Messages per page">
2214
+ <span class="ee-page-size-label">Show</span>
2215
+ <select class="ee-button ee-page-size-select" data-action="page-size">
1794
2216
  <option value="10" ${this.pageSize === 10 ? 'selected' : ''}>10</option>
1795
2217
  <option value="20" ${this.pageSize === 20 ? 'selected' : ''}>20</option>
1796
2218
  <option value="30" ${this.pageSize === 30 ? 'selected' : ''}>30</option>
1797
2219
  <option value="50" ${this.pageSize === 50 ? 'selected' : ''}>50</option>
1798
2220
  <option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100</option>
1799
2221
  </select>
1800
- </div>
2222
+ </label>
1801
2223
  </div>
1802
- </div>
2224
+ `;
2225
+
2226
+ const html = `
2227
+ ${this._messageListHeader(this.currentFolder, controls)}
1803
2228
  <div class="ee-message-items">
1804
2229
  ${this.messages
1805
2230
  .map(
@@ -1844,7 +2269,7 @@ export class EmailEngineClient {
1844
2269
  const pageSizeSelect = messageList.querySelector('[data-action="page-size"]');
1845
2270
  if (pageSizeSelect) {
1846
2271
  pageSizeSelect.addEventListener('change', e => {
1847
- this.pageSize = parseInt(e.target.value);
2272
+ this.pageSize = parseInt(e.target.value, 10);
1848
2273
  // Save to localStorage
1849
2274
  if (typeof window !== 'undefined' && window.localStorage) {
1850
2275
  localStorage.setItem('ee-client-page-size', this.pageSize.toString());
@@ -1865,59 +2290,71 @@ export class EmailEngineClient {
1865
2290
  }
1866
2291
 
1867
2292
  if (!this.currentMessage) {
1868
- viewer.innerHTML = '<div class="ee-empty-state">Select a message to view</div>';
2293
+ viewer.innerHTML = this._messageViewerPlaceholder();
2294
+ // Nothing left to show in the single-pane layout (the message was deleted
2295
+ // or moved), so return to the list it came from
2296
+ if (this._getView() === 'message') {
2297
+ this._setView('list');
2298
+ }
1869
2299
  return;
1870
2300
  }
1871
2301
 
1872
2302
  const msg = this.currentMessage;
1873
2303
  const isUnseen = msg.unseen;
1874
2304
  const isDraft = this._isDraftMessage(msg);
2305
+ // Labels drop to icons when the viewer is narrow (see the ee-viewer container
2306
+ // query); aria-label and title carry the full name either way. The move control
2307
+ // is a native select laid invisibly over a button so it looks like the rest of
2308
+ // the toolbar while keeping the platform's own folder picker.
2309
+ const actions = `
2310
+ ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : ''}
2311
+ ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
2312
+ <span class="ee-button ee-move-button" title="Move to folder">
2313
+ ${icon('move')}<span class="ee-button-label">Move</span>${icon('chevronDown', 12)}
2314
+ <select class="ee-move-select" data-action="move" aria-label="Move to folder">
2315
+ <option value="">Move to...</option>
2316
+ ${this.buildFolderTree()
2317
+ .map(({ folder, depth }) => {
2318
+ const indent = ' '.repeat(depth);
2319
+ const prefix = depth > 0 ? '└ ' : '';
2320
+ return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
2321
+ })
2322
+ .join('')}
2323
+ </select>
2324
+ </span>
2325
+ ${this._toolbarButton('delete', 'trash', 'Delete', 'Delete', 'ee-button-danger')}
2326
+ <span class="ee-toolbar-spacer"></span>
2327
+ ${this._toolbarButton('download-original', 'download', 'Download', 'Download the original message (.eml)')}
2328
+ `;
1875
2329
  const html = `
1876
- <div class="ee-message-actions">
1877
- ${isDraft ? '<button class="ee-button" data-action="send-draft">Send Draft</button>' : ''}
1878
- <button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
1879
- <button class="ee-button" data-action="delete">Delete</button>
1880
- <button class="ee-button" data-action="download-original">Download Original</button>
1881
- <select class="ee-button" data-action="move">
1882
- <option value="">Move to...</option>
1883
- ${this.buildFolderTree()
1884
- .map(({ folder, depth }) => {
1885
- const indent = ' '.repeat(depth);
1886
- const prefix = depth > 0 ? '└ ' : '';
1887
- return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
1888
- })
1889
- .join('')}
1890
- </select>
1891
- </div>
2330
+ ${this._messageToolbar(actions)}
1892
2331
  <div class="ee-message-content">
2332
+ <h2 class="ee-message-title">${this.escapeHtml(msg.subject || '(no subject)')}</h2>
1893
2333
  <div class="ee-message-meta">
1894
2334
  <div class="ee-message-meta-row">
1895
- <span class="ee-message-meta-label">From:</span>
1896
- ${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}
2335
+ <span class="ee-message-meta-label">From</span>
2336
+ <span class="ee-message-meta-value">${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}</span>
1897
2337
  </div>
1898
2338
  <div class="ee-message-meta-row">
1899
- <span class="ee-message-meta-label">To:</span>
1900
- ${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}
2339
+ <span class="ee-message-meta-label">To</span>
2340
+ <span class="ee-message-meta-value">${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}</span>
1901
2341
  </div>
1902
2342
  ${
1903
2343
  msg.cc && msg.cc.length
1904
2344
  ? `
1905
2345
  <div class="ee-message-meta-row">
1906
- <span class="ee-message-meta-label">Cc:</span>
1907
- ${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}
2346
+ <span class="ee-message-meta-label">Cc</span>
2347
+ <span class="ee-message-meta-value">${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}</span>
1908
2348
  </div>
1909
2349
  `
1910
2350
  : ''
1911
2351
  }
1912
2352
  <div class="ee-message-meta-row">
1913
- <span class="ee-message-meta-label">Date:</span>
1914
- ${new Date(msg.date).toLocaleString()}
1915
- </div>
1916
- <div class="ee-message-meta-row">
1917
- <span class="ee-message-meta-label">Subject:</span>
1918
- ${this.escapeHtml(msg.subject || '(no subject)')}
2353
+ <span class="ee-message-meta-label">Date</span>
2354
+ <span class="ee-message-meta-value">${this.escapeHtml(new Date(msg.date).toLocaleString())}</span>
1919
2355
  </div>
1920
2356
  </div>
2357
+ ${this.renderOtpBox(msg.otp)}
1921
2358
  <div class="ee-message-body"></div>
1922
2359
  ${
1923
2360
  msg.attachments && msg.attachments.length > 0
@@ -1961,9 +2398,11 @@ export class EmailEngineClient {
1961
2398
  return;
1962
2399
  }
1963
2400
 
1964
- const originalText = sendDraftButton.textContent;
2401
+ // Only the label changes, the icon stays
2402
+ const label = sendDraftButton.querySelector('.ee-button-label');
2403
+ const originalText = label.textContent;
1965
2404
  sendDraftButton.disabled = true;
1966
- sendDraftButton.textContent = 'Sending...';
2405
+ label.textContent = 'Sending...';
1967
2406
 
1968
2407
  try {
1969
2408
  await this.submitDraft(msg.id);
@@ -1978,16 +2417,14 @@ export class EmailEngineClient {
1978
2417
  const errorMessage = this._formatSendError(error);
1979
2418
  await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
1980
2419
  sendDraftButton.disabled = false;
1981
- sendDraftButton.textContent = originalText;
2420
+ label.textContent = originalText;
1982
2421
  }
1983
2422
  });
1984
2423
  }
1985
2424
 
1986
2425
  viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
1987
2426
  const currentlyUnseen = msg.unseen;
1988
- this.markAsRead(msg.id, currentlyUnseen).catch(error =>
1989
- this._alertActionFailed(error, 'Failed to update the message flags')
1990
- );
2427
+ this.markAsRead(msg.id, currentlyUnseen).catch(error => this._alertActionFailed(error, 'Failed to update the message flags'));
1991
2428
  });
1992
2429
 
1993
2430
  viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
@@ -1998,9 +2435,7 @@ export class EmailEngineClient {
1998
2435
  'Delete'
1999
2436
  );
2000
2437
  if (result) {
2001
- this.deleteMessage(msg.id).catch(error =>
2002
- this._alertActionFailed(error, 'Failed to delete the message')
2003
- );
2438
+ this.deleteMessage(msg.id).catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
2004
2439
  }
2005
2440
  });
2006
2441
 
@@ -2029,9 +2464,34 @@ export class EmailEngineClient {
2029
2464
  });
2030
2465
  });
2031
2466
 
2467
+ const copyOtpButton = viewer.querySelector('[data-action="copy-otp"]');
2468
+ if (copyOtpButton) {
2469
+ const status = viewer.querySelector('.ee-otp-status');
2470
+ copyOtpButton.addEventListener('click', async () => {
2471
+ const copied = await this.copyText(msg.otp.code);
2472
+ copyOtpButton.textContent = copied ? 'Copied' : 'Copy code';
2473
+ status.textContent = copied ? 'Code copied to the clipboard' : 'Could not copy, select the code and copy it by hand';
2474
+ clearTimeout(this._otpCopyTimer);
2475
+ this._otpCopyTimer = setTimeout(() => {
2476
+ copyOtpButton.textContent = 'Copy code';
2477
+ status.textContent = '';
2478
+ }, 2500);
2479
+ });
2480
+ }
2481
+
2032
2482
  // Message content scrolling is now handled in loadMessage method
2033
2483
  }
2034
2484
 
2485
+ // An icon-only button. Static arguments only, never message data.
2486
+ _iconButton(action, iconName, label, extraClass = '', disabled = false) {
2487
+ return `<button type="button" class="ee-button ee-icon-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${label}"${disabled ? ' disabled' : ''}>${icon(iconName)}</button>`;
2488
+ }
2489
+
2490
+ // A message toolbar button. Static arguments only, never message data.
2491
+ _toolbarButton(action, iconName, label, title, extraClass = '') {
2492
+ return `<button type="button" class="ee-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${title}">${icon(iconName)}<span class="ee-button-label">${label}</span></button>`;
2493
+ }
2494
+
2035
2495
  // The message body goes into a shadow root on its container. Sanitised message HTML still
2036
2496
  // carries class and id attributes, and in the host document those would pick up the host's
2037
2497
  // own stylesheet (a utility class like "fixed inset-0" could cover the whole page) or collide
@@ -2081,27 +2541,25 @@ export class EmailEngineClient {
2081
2541
  }
2082
2542
 
2083
2543
  this.container.innerHTML = `
2084
- <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
2085
- ${
2086
- this.showDarkModeToggle
2087
- ? `<button class="ee-dark-mode-toggle" title="Toggle dark mode">
2088
- <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
2089
- </button>`
2090
- : ''
2091
- }
2544
+ <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}" data-view="list">
2092
2545
  <div class="ee-sidebar">
2093
2546
  <div class="ee-pane-header">
2094
2547
  <span class="ee-pane-title">Folders</span>
2548
+ ${
2549
+ this.showDarkModeToggle
2550
+ ? `<button type="button" class="ee-dark-mode-toggle" title="Toggle dark mode" aria-label="Toggle dark mode">
2551
+ <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
2552
+ </button>`
2553
+ : ''
2554
+ }
2095
2555
  </div>
2096
2556
  <div class="ee-folder-tree"></div>
2097
2557
  </div>
2098
2558
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2099
- <div class="ee-message-viewer">
2100
- <div class="ee-empty-state">Select a message to view</div>
2101
- </div>
2559
+ <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2102
2560
  </div>
2103
- <button class="ee-compose-button" title="Compose Email">✉</button>
2104
- <div class="ee-compose-modal">
2561
+ <button type="button" class="ee-compose-button${this.darkMode ? ' ee-dark-mode' : ''}" title="Compose email" aria-label="Compose">${icon('compose', 22)}<span class="ee-compose-button-label">Compose</span></button>
2562
+ <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2105
2563
  <div class="ee-compose-dialog">
2106
2564
  <div class="ee-compose-header">
2107
2565
  <h3 class="ee-compose-title">Compose Email</h3>
@@ -2130,6 +2588,15 @@ export class EmailEngineClient {
2130
2588
  </div>
2131
2589
  `;
2132
2590
 
2591
+ // Pane navigation in the single-pane layout, delegated because the panes
2592
+ // re-render their headers on every load
2593
+ this.container.querySelector('.ee-client').addEventListener('click', e => {
2594
+ const nav = e.target.closest('[data-action="show-folders"], [data-action="back-to-list"]');
2595
+ if (nav) {
2596
+ this._setView(nav.dataset.action === 'show-folders' ? 'folders' : 'list');
2597
+ }
2598
+ });
2599
+
2133
2600
  // Wire up compose modal events
2134
2601
  this.setupComposeModal();
2135
2602
 
@@ -2191,12 +2658,7 @@ export class EmailEngineClient {
2191
2658
 
2192
2659
  if (!to && !subject && !message) {
2193
2660
  modal.classList.remove('show');
2194
- await this.alertMethod(
2195
- 'Nothing to save - fill in at least one field first.',
2196
- 'Validation Error',
2197
- null,
2198
- 'OK'
2199
- );
2661
+ await this.alertMethod('Nothing to save - fill in at least one field first.', 'Validation Error', null, 'OK');
2200
2662
  modal.classList.add('show');
2201
2663
  setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
2202
2664
  return;
@@ -2238,17 +2700,10 @@ export class EmailEngineClient {
2238
2700
  if (!to || !message) {
2239
2701
  // Close modal temporarily to show alert, then reopen
2240
2702
  modal.classList.remove('show');
2241
- await this.alertMethod(
2242
- 'Please fill in the recipient and message fields.',
2243
- 'Validation Error',
2244
- null,
2245
- 'OK'
2246
- );
2703
+ await this.alertMethod('Please fill in the recipient and message fields.', 'Validation Error', null, 'OK');
2247
2704
  modal.classList.add('show');
2248
2705
  // Re-focus the appropriate field
2249
- const fieldToFocus = !to
2250
- ? form.querySelector('input[name="to"]')
2251
- : form.querySelector('textarea[name="message"]');
2706
+ const fieldToFocus = !to ? form.querySelector('input[name="to"]') : form.querySelector('textarea[name="message"]');
2252
2707
  setTimeout(() => fieldToFocus.focus(), 100);
2253
2708
  return;
2254
2709
  }
@@ -2303,7 +2758,6 @@ export class EmailEngineClient {
2303
2758
 
2304
2759
  const updateButtonPosition = () => {
2305
2760
  const containerRect = this.container.getBoundingClientRect();
2306
- const buttonSize = 56; // Button width/height
2307
2761
  const margin = 20; // Desired margin from edges
2308
2762
 
2309
2763
  // A hidden container (display: none) reports a zero-size rect; positioning
@@ -2317,6 +2771,11 @@ export class EmailEngineClient {
2317
2771
  }
2318
2772
  composeButton.style.display = '';
2319
2773
 
2774
+ // A labelled pill on roomy layouts, a round icon button where width is
2775
+ // short and the button would cover too much of the single pane
2776
+ composeButton.classList.toggle('ee-compose-compact', containerRect.width < NARROW_WIDTH);
2777
+ const buttonSize = composeButton.offsetWidth || 56;
2778
+
2320
2779
  // Calculate the ideal position (bottom-right of container with margin)
2321
2780
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
2322
2781
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -2372,6 +2831,7 @@ export class EmailEngineClient {
2372
2831
  let inThrottle;
2373
2832
  return function () {
2374
2833
  const args = arguments;
2834
+ // eslint-disable-next-line no-invalid-this -- the wrapper forwards whatever this its caller bound
2375
2835
  const context = this;
2376
2836
  if (!inThrottle) {
2377
2837
  func.apply(context, args);
@@ -2478,15 +2938,9 @@ export class EmailEngineClient {
2478
2938
  return;
2479
2939
  }
2480
2940
 
2481
- // Update UI
2482
- const client = this.container.querySelector('.ee-client');
2483
- if (client) {
2484
- if (this.darkMode) {
2485
- client.classList.add('ee-dark-mode');
2486
- } else {
2487
- client.classList.remove('ee-dark-mode');
2488
- }
2489
- }
2941
+ // Update UI. The compose button and modal are siblings of .ee-client, so
2942
+ // they carry the class themselves.
2943
+ this.container.querySelectorAll('.ee-client, .ee-compose-button, .ee-compose-modal').forEach(el => el.classList.toggle('ee-dark-mode', this.darkMode));
2490
2944
 
2491
2945
  // Update toggle button icon
2492
2946
  const icon = this.container.querySelector('.ee-dark-mode-icon');