/* Simple Office: External Email (office/extmail.js). A three-pane desktop mail client that folds to one pane on
   phones. Colours come from app.css design tokens, so light and dark themes follow automatically. */
:root { --xm: #5145cd; --xm-soft: #eceaf9; }
:root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --xm: #a79bf5; --xm-soft: rgba(129, 112, 243, .15); } }
:root[data-theme="dark"] { --xm: #a79bf5; --xm-soft: rgba(129, 112, 243, .15); }

.xm-root { color: var(--text); }
.xm-tone { background: var(--xm-soft); color: var(--xm); }
.xm-loading { display: flex; align-items: center; justify-content: center; min-height: 160px; height: 100%; }

/* ---------------------------------------------------------------- welcome */
.xm-welcome { display: flex; align-items: center; justify-content: center; min-height: calc(100dvh - var(--header-h) - 120px); padding: 24px 0; }
.xm-welcome-card { max-width: 560px; text-align: center; padding: 40px 32px; }
.xm-welcome-icon { width: 76px; height: 76px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center; font-size: 36px;
  background: linear-gradient(135deg, var(--xm), #7c6ef0); color: #fff; margin-bottom: 18px; box-shadow: 0 12px 28px -10px rgba(81, 69, 205, .6); }
.xm-provider-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 26px; }
.xm-provider-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- shell */
.xm { display: grid; grid-template-columns: 248px 360px minmax(0, 1fr); gap: 0; height: calc(100vh - var(--header-h) - 32px - var(--bottom-h));
  height: calc(100dvh - var(--header-h) - 32px - var(--bottom-h)); min-height: 460px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.xm-rail, .xm-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.xm-rail { background: var(--surface-2); padding: 14px 12px; gap: 12px; }
.xm-compose { border-radius: 12px; font-weight: 600; box-shadow: 0 6px 16px -8px rgba(81, 69, 205, .7); }
/* folders rail hidden by the toggle in the message-list header; phones keep the sliding overlay instead */
/* the hidden rail is display:none, so it stops being a grid item: drop its track rather than zeroing it,
   otherwise the list slides into the 0-wide first column and disappears along with this toggle */
.xm.rail-hidden { grid-template-columns: 360px minmax(0, 1fr); }
.xm.rail-hidden .xm-rail { display: none; }
/* Compose lives on the rail, so stand it in on the header while the rail is away */
.xm-compose-mini { display: none; }
.xm.rail-hidden .xm-compose-mini { display: inline-flex; }

/* accounts */
.xm-accounts { display: flex; flex-direction: column; gap: 4px; }
.xm-acc { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 1px solid transparent; background: transparent;
  border-radius: 12px; padding: 8px 10px; cursor: pointer; transition: background .12s, border-color .12s; }
.xm-acc:hover { background: var(--surface); }
.xm-acc.active { background: var(--surface); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.xm-acc-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.xm-acc-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.xm-acc-text b { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-acc-text small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-acc-badge { margin-inline-start: auto; }
.xm-acc-add { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; color: var(--muted); font-size: 13px; font-weight: 500;
  border: 1px dashed var(--line-strong); }
.xm-acc-add:hover { color: var(--xm); border-color: var(--xm); background: var(--xm-soft); }

/* folders */
.xm-folders { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 4px; }
.xm-folder { display: flex; align-items: center; gap: 10px; width: 100%; text-align: start; border: 0; background: transparent; border-radius: 10px;
  padding: 8px 12px; cursor: pointer; color: var(--text); font-size: 14px; }
.xm-folder:hover { background: var(--surface); }
.xm-folder.active { background: var(--xm-soft); color: var(--xm); font-weight: 600; }
.xm-folder i { font-size: 16px; width: 18px; text-align: center; opacity: .9; }
.xm-folder-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-folder .nav-badge { margin-inline-start: auto; }
.xm-manage { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); margin: 0 -12px -14px; color: var(--muted); font-size: 13px; }
.xm-manage:hover { color: var(--xm); background: var(--surface); }

/* message list */
.xm-list { background: var(--surface); }
.xm-list-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); min-height: 56px; }
.xm-folder-name { font-weight: 700; font-size: 15px; white-space: nowrap; }
.xm-search { flex: 1; min-width: 0; position: relative; }
.xm-search i { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.xm-search input { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 7px 12px 7px 30px; font-size: 13px; color: var(--text); }
.xm-search input:focus { outline: none; border-color: var(--xm); background: var(--surface); }
.xm-bulk { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--xm-soft); flex-wrap: wrap; }
.xm-bulk-n { font-size: 13px; font-weight: 600; color: var(--xm); margin-inline-end: 4px; }
.xm-msgs { flex: 1; overflow-y: auto; }

.xm-msg { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.xm-msg:hover { background: var(--surface-2); }
.xm-msg.active { background: var(--xm-soft); }
.xm-msg.selected { background: color-mix(in srgb, var(--xm-soft) 70%, var(--surface)); }
.xm-msg.active::before { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px; background: var(--xm); }
.xm-check { position: relative; flex: none; width: 18px; height: 18px; margin-top: 3px; display: inline-flex; }
.xm-check input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.xm-check span { width: 18px; height: 18px; border: 1.5px solid var(--line-strong); border-radius: 5px; display: inline-block; transition: .12s; }
.xm-check input:checked + span { background: var(--xm); border-color: var(--xm); }
.xm-check input:checked + span::after { content: "\2713"; color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; height: 100%; }
.xm-msg .avatar { flex: none; }
.xm-msg-main { flex: 1; min-width: 0; }
.xm-msg-row1 { display: flex; align-items: baseline; gap: 8px; }
.xm-msg-from { font-size: 14px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-msg-date { font-size: 12px; color: var(--muted); flex: none; }
.xm-msg-row2 { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.xm-msg-subject { font-size: 13px; color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-msg.unread .xm-msg-from { font-weight: 700; }
.xm-msg.unread .xm-msg-subject { color: var(--text); font-weight: 500; }
.xm-msg.unread::after { content: ""; position: absolute; inset-inline-start: 4px; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--xm); transform: translateY(-50%); }
.xm-star { font-size: 14px; color: var(--muted); flex: none; cursor: pointer; opacity: .55; }
.xm-star:hover { opacity: 1; }
.xm-star.on { color: #f0a500; opacity: 1; }

.xm-pager { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.xm-pager-btns { display: flex; gap: 4px; }

/* reader */
.xm-reader { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.xm-reader-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 10px; }
.xm-reader-empty i { font-size: 46px; opacity: .4; }
.xm-reader-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 56px; }
.xm-reader-acts { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.xm-reader-scroll { flex: 1; overflow-y: auto; padding: 20px 24px 40px; }
.xm-subject { font-size: 21px; font-weight: 700; line-height: 1.3; margin: 0 0 16px; }
.xm-msg-head { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.xm-msg-head-main { flex: 1; min-width: 0; }
.xm-msg-head-from { font-size: 15px; }
.xm-msg-head-date { white-space: nowrap; }
.xm-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.xm-att { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  color: var(--text); font-size: 13px; max-width: 240px; }
.xm-att:hover { border-color: var(--xm); background: var(--xm-soft); color: var(--text); }
.xm-att i { font-size: 18px; color: var(--xm); flex: none; }
.xm-att-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-att small { color: var(--muted); flex: none; }
.xm-remote-bar { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-radius: 10px; background: var(--polls-soft); color: var(--text);
  font-size: 13px; margin-bottom: 14px; }
.xm-body { min-height: 80px; }
.xm-frame { width: 100%; border: 0; min-height: 120px; background: #fff; border-radius: 8px; }

/* ---------------------------------------------------------------- compose */
.xm-compose-form, .xm-form { display: flex; flex-direction: column; gap: 12px; }
.xm-field { display: flex; flex-direction: column; gap: 5px; margin: 0; position: relative; }
.xm-field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.xm-field-row { margin-top: 8px; }
.xm-cc-toggle { position: absolute; inset-inline-end: 0; top: 0; font-size: 12px; padding: 0; }
.xm-quill-wrap .ql-container { min-height: 200px; font-size: 15px; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; }
.xm-quill-wrap .ql-toolbar { border-top-left-radius: 10px; border-top-right-radius: 10px; }
.xm-quill-wrap .ql-editor { min-height: 200px; }
.xm-quote { color: var(--muted); border-inline-start: 3px solid var(--line-strong); padding-inline-start: 12px; }
.xm-compose-atts { display: flex; flex-wrap: wrap; gap: 6px; }
.xm-compose-att { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; }
.btn-close-sm { font-size: 9px; padding: 2px; }
/* an attachment taken from the Files page, rather than uploaded from the device */
.xm-att-stored { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); }
.xm-att-total { flex-basis: 100%; font-size: 12px; }

/* account form */
.xm-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.xm-form-grid3 { display: grid; grid-template-columns: 2fr 1fr 1.2fr; gap: 10px; }
.xm-provider-note { font-size: 13px; padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-text); }
.xm-advanced { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; background: var(--surface-2); }
.xm-advanced > summary { cursor: pointer; font-weight: 600; font-size: 13.5px; padding: 8px 0; color: var(--text); }
.xm-server-block { margin: 10px 0; }
.xm-server-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.xm-check-field { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--muted); margin: 8px 0 4px; cursor: pointer; }
.xm-check-field input { margin-top: 3px; }

/* settings page */
.xm-settings { max-width: 760px; margin: 0 auto; }
.xm-settings-back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.xm-settings-back:hover { color: var(--xm); }
.xm-settings-panel { padding: 22px 22px 10px; }
.xm-acc-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.xm-acc-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.xm-acc-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.xm-acc-avatar { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; flex: none; }
.xm-acc-card-main { flex: 1; min-width: 0; }
.xm-acc-card-meta { margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xm-acc-card-acts { display: flex; gap: 4px; flex: none; }

/* ---------------------------------------------------------------- responsive (phones & tablets) */
.xm .xm-back { display: none; }
@media (max-width: 991.98px) {
  .xm { grid-template-columns: 300px minmax(0, 1fr); }
  .xm.rail-hidden { grid-template-columns: minmax(0, 1fr); }
  .xm-reader { grid-column: 1 / -1; }
  .xm[data-pane="list"] .xm-reader, .xm[data-pane="folders"] .xm-reader { display: none; }
  .xm[data-pane="reader"] .xm-rail, .xm[data-pane="reader"] .xm-list { display: none; }
  .xm[data-pane="reader"] .xm-reader { grid-column: 1 / -1; }
  .xm .xm-reader-bar .xm-back { display: inline-flex; }
}
@media (max-width: 767.98px) {
  .xm { grid-template-columns: 1fr; margin: 0 -16px; border-radius: 0; border-left: 0; border-right: 0;
    height: calc(100dvh - var(--header-h) - 4px - var(--bottom-h)); }
  /* the rail is a sliding overlay here, driven by data-pane: the desktop collapse must not apply */
  .xm.rail-hidden { grid-template-columns: 1fr; }
  .xm.rail-hidden .xm-rail { display: flex; }
  .xm-rail-toggle, .xm.rail-hidden .xm-compose-mini { display: none !important; }
  .xm-rail { position: absolute; z-index: 5; width: 82%; max-width: 300px; height: 100%; box-shadow: var(--shadow); transition: transform .2s; }
  .xm[data-pane="list"] .xm-rail, .xm[data-pane="reader"] .xm-rail { transform: translateX(-105%); }
  html[dir="rtl"] .xm[data-pane="list"] .xm-rail, html[dir="rtl"] .xm[data-pane="reader"] .xm-rail { transform: translateX(105%); }
  .xm[data-pane="folders"] .xm-rail { transform: none; }
  .xm[data-pane="folders"] .xm-list { visibility: hidden; }
  .xm-list { grid-column: 1; }
  .xm[data-pane="reader"] .xm-list { display: none; }
  .xm-list-head .xm-back { display: inline-flex !important; }
  .xm-form-grid, .xm-form-grid3 { grid-template-columns: 1fr; }
  .xm-reader-scroll { padding: 16px; }
  .xm-subject { font-size: 18px; }
}
