:root {
  --blue: #0f6cbd; --blue-dark: #115ea3; --bg: #f5f5f5; --pane: #fff; --line: #e1e1e1;
  --text: #242424; --muted: #616161; --unread: #0f6cbd; --sel: #cfe4fa; --hover: #f0f6fc; --danger: #c50f1f;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid #d1d1d1; background: #fff; border-radius: 4px; padding: 6px 12px; }
button:hover { background: #f5f5f5; }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: var(--blue-dark); }
button.link { border: none; background: none; color: inherit; text-decoration: underline; padding: 4px; }
button.icon { border: none; background: none; font-size: 18px; padding: 4px 8px; color: inherit; }
input, textarea, select { font: inherit; border: 1px solid #d1d1d1; border-radius: 4px; padding: 6px 8px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
.topbar .search input:focus { outline: 2px solid #fff8; }
label { display: block; margin: 8px 0; color: var(--muted); }
label input, label textarea { margin-top: 4px; color: var(--text); }
.error { color: var(--danger); min-height: 1em; }
.note { color: var(--muted); min-height: 1em; }

/* Sign-in */
#login { display: flex; height: 100%; align-items: center; justify-content: center; }
.card { background: var(--pane); padding: 32px; border-radius: 8px; width: min(380px, 92vw); box-shadow: 0 2px 12px #0002; }
.card h1 { margin-top: 0; font-weight: 600; }
.card .primary { width: 100%; padding: 10px; margin-top: 8px; }
.join-addr { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.join-addr input { margin: 0; flex: 1; }
#join-domain { color: var(--text); white-space: nowrap; }
.brand-box { display: flex; align-items: center; gap: 10px; margin: -6px 0 14px; font-weight: 600; font-size: 17px; }
.brand-box img { max-height: 40px; max-width: 160px; }
.tcount { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 9px; background: #e8e8e8; color: var(--muted); font-size: 11.5px; font-weight: 600; vertical-align: 1px; }
.thread-strip { margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.thread-strip:empty { display: none; }
.thread-strip .th-head { padding: 6px 10px; background: #fafafa; color: var(--muted); font-size: 12.5px; }
.thread-strip button { display: flex; gap: 10px; width: 100%; text-align: left; border: none; border-top: 1px solid #f0f0f0; border-radius: 0; background: #fff; padding: 7px 10px; font-size: 13px; }
.thread-strip button:hover { background: var(--hover); }
.thread-strip .th-who { font-weight: 600; flex: 0 0 auto; max-width: 35%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-strip .th-prev { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-strip .th-when { color: var(--muted); white-space: nowrap; }
.chip.pv { cursor: zoom-in; }
dialog.pv-dlg { width: min(1100px, 96vw); height: 92vh; padding: 0; overflow: hidden; }
.pv-dlg form { display: flex; flex-direction: column; height: 100%; }
.pv-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pv-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-head .spacer { flex: 1; }
.pv-body { flex: 1; min-height: 0; background: #2b2b2b; display: flex; align-items: center; justify-content: center; }
.pv-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pv-body iframe { width: 100%; height: 100%; border: none; background: #fff; }
.passkey-btn { width: 100%; padding: 10px; margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* Layout */
#app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; background: var(--blue); color: #fff; padding: 6px 12px; }
.topbar .brand { font-weight: 600; font-size: 16px; }
.topbar .search { flex: 1; max-width: 520px; }
.topbar .search input { border: none; }
.topbar .primary { background: #fff; color: var(--blue); }
/* Stays white on hover (the general hover colour is the top bar's own colour). */
.topbar .primary:hover { background: #fff; color: var(--blue-dark); box-shadow: 0 0 0 3px #ffffff59, 0 2px 8px #0003; }
.topbar .me { opacity: .9; font-size: 13px; }
#menu-btn { display: none; }
.panes { flex: 1; display: grid; grid-template-columns: 220px 380px 1fr; min-height: 0; }
.folders { background: var(--bg); overflow-y: auto; padding: 8px 0; border-right: 1px solid var(--line); min-width: 0; }
.drawer-head, .drawer-foot, .m-title, #search-btn, .scrim { display: none; }
.list-pane, .reader { min-width: 0; }
.ic { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.topbar .icon .ic { width: 20px; height: 20px; }
.toolbar button .ic { margin-right: 4px; }
.reader .toolbar > button, .extras > button { padding: 5px 9px; }
.toolbar .more-btn { display: none; }
.extras { display: contents; }
/* Desktop order: Reply, Reply all, Forward, Delete, then the rest (on phones Delete sits in the top bar). */
.toolbar .del { order: 2; }
.extras > :nth-child(n+3) { order: 3; }
.toolbar .dmore, .toolbar .tb-sep { display: none; }
/* Desktop reader toolbar: Reply / Reply all / Forward with words, the rest as quiet icons, extras under ⋯ */
@media (min-width: 801px) {
  .reader .toolbar { gap: 2px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .reader .toolbar > button:not(.back):not(.more-btn), .reader .extras > button { border: 1px solid transparent; background: none; border-radius: 6px; padding: 5px 10px; color: var(--text); display: inline-flex; align-items: center; }
  .reader .toolbar > button:not(.back):not(.more-btn):hover, .reader .extras > button:hover { background: var(--hover); border-color: var(--line); }
  .toolbar .ico-only { padding: 6px 8px !important; }
  .toolbar .ico-only .lbl { display: none; }
  .toolbar .ico-only .ic { margin-right: 0; }
  .toolbar .ico-only.on { color: #c50f1f; }
  .toolbar .ovf { display: none !important; }
  .toolbar .tb-sep { display: block; order: 2; width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
  .toolbar .del { order: 2; }
  .toolbar .dmore { display: inline-flex; order: 4; margin-left: auto; border: none; background: none; border-radius: 6px; padding: 6px 8px; }
  .toolbar .dmore:hover { background: var(--hover); }
  .reader .toolbar select { order: 3; border: 1px solid transparent; background: none; color: var(--muted); padding: 4px 6px; font-size: 13px; }
  .reader .toolbar select:hover { border-color: var(--line); }
}
.avatar { display: none; }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.dlg-head h2 { flex: 1; margin: 0; }
.dlg-head .icon, .dlg-head .primary, .dlg-head > span { display: none; }
.to-row { position: relative; }
.to-row #c-ccbcc { position: absolute; right: 6px; bottom: 5px; padding: 2px 6px; color: var(--blue); text-decoration: none; font-size: 13px; }
.to-row input { padding-right: 70px; }
.folder { display: flex; justify-content: space-between; padding: 7px 16px; cursor: pointer; border-left: 3px solid transparent; }
.folder:hover { background: #ebebeb; }
.folder.active { background: var(--sel); border-left-color: var(--blue); font-weight: 600; }
.folder .count { color: var(--blue); font-weight: 600; }
.folder-head { margin: 14px 0 4px; padding: 6px 16px 2px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #777; border-top: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-head + .folder-head { border-top: none; margin-top: 0; }
#compose select { width: 100%; }
.list-pane { background: var(--pane); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.live { width: 9px; height: 9px; border-radius: 50%; background: #bbb; }
.live.on { background: #13a10e; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item { padding: 10px 14px 10px 11px; border-bottom: 1px solid #f0f0f0; border-left: 3px solid transparent; cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--sel); }
.item.unread { border-left-color: var(--unread); }
.item.unread .who, .item.unread .subj { font-weight: 600; }
.item.unread .subj { color: var(--unread); }
.item .top { display: flex; justify-content: space-between; gap: 8px; }
.item .who { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj, .item .prev { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item .prev { color: var(--muted); font-size: 13px; }
.item .marks { color: var(--muted); }
.more { margin: 8px auto; }

/* ---------- Selecting several messages ---------- */
.lh-right { display: flex; align-items: center; gap: 10px; }
.sel-btn { border: none; background: none; padding: 2px; color: var(--muted); display: inline-flex; border-radius: 4px; }
.sel-btn:hover { background: #ebebeb; color: var(--text); }
.ck { display: none; }
.list.selecting .item { position: relative; padding-left: 42px; }
.list.selecting .ck { display: flex; position: absolute; left: 13px; top: 12px; width: 18px; height: 18px; border: 1.5px solid #8a8a8a; border-radius: 4px; background: #fff; align-items: center; justify-content: center; }
.list.selecting .ck .ic { width: 13px; height: 13px; stroke-width: 3; color: #fff; visibility: hidden; }
.item.selected { background: var(--sel); }
.item.selected .ck { background: var(--blue); border-color: var(--blue); }
.item.selected .ck .ic { visibility: visible; }
.selbar { display: flex; align-items: center; gap: 2px; padding: 7px 8px; border-bottom: 1px solid var(--line); background: var(--pane); }
.selbar[hidden] { display: none; }
.list-pane.selecting .list-head { display: none; }
.selbar button { border: none; background: none; width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; color: inherit; }
.selbar button:hover { background: var(--hover); }
.selbar button:disabled { opacity: .35; pointer-events: none; }
.selbar button[hidden] { display: none; }
.sel-count { flex: 1; font-weight: 600; padding: 0 6px; white-space: nowrap; }
.sel-more-wrap { position: relative; }
.sel-menu { position: absolute; right: 0; top: 40px; z-index: 30; min-width: 210px; max-height: 60vh; overflow-y: auto; background: var(--pane); color: var(--text); border-radius: 8px; box-shadow: 0 8px 28px #0004; padding: 6px 0; }
.sel-menu[hidden] { display: none; }
.sel-menu button { display: flex; width: 100%; height: auto; justify-content: flex-start; gap: 12px; padding: 9px 16px; border-radius: 0; text-align: left; }
.sel-menu .sel-menu-h { padding: 8px 16px 4px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }
.flash { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; background: #323130; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 16px #0004; max-width: 90vw; }
.flash button { margin-left: 16px; border: none; background: none; color: #9cd0ff; font-weight: 600; padding: 0; min-height: 0; }
.flash button:hover { background: none; text-decoration: underline; }
/* Small pop-up menus (send later, snooze, templates) */
.pop { position: fixed; top: 0; left: 0; right: auto; width: max-content; min-width: 240px; max-width: min(380px, 92vw); }
.pop button { border: none; background: none; color: inherit; min-height: 0; align-items: center; }
.pop button:hover { background: var(--hover); }
.pop .sel-menu-h:empty { padding: 0; margin: 4px 0; }
.pop .sel-menu-sub { color: var(--muted); font-size: 12.5px; margin-left: auto; padding-left: 12px; white-space: nowrap; }
.note-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #fff4ce; border: 1px solid #f1dc95; border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; }
.note-bar button { padding: 4px 10px; }
.ext-bar { background: #eef3fb; border-color: #cbd9ef; color: #2d3f5e; font-size: 13px; }
.ext-bar.danger { background: #fde7e7; border-color: #f1b2b2; color: #8a1f1f; font-size: 13.5px; }
.ext-bar svg { flex: 0 0 auto; width: 18px; height: 18px; }
.ext-bar span { flex: 1; min-width: 0; }
.c-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.c-tools .attach { flex: 1; }
.c-tpl { color: var(--blue); text-decoration: none !important; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.chip.big { border-style: dashed; }
.inline-sel { width: auto !important; display: inline-block; margin: 4px 4px 0; }
.apps li .acts { display: flex; gap: 6px; flex: none; }
.apps li > span:first-child { min-width: 0; overflow-wrap: anywhere; padding-right: 8px; }
dialog.small { width: min(380px, 92vw); }
.avatar .av-c { display: none; }
.empty { color: var(--muted); text-align: center; margin-top: 40%; }

/* Reader */
.reader { background: var(--pane); overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; min-height: 0; }
.reader h1 { font-size: 20px; font-weight: 600; margin: 4px 0 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.toolbar select { width: auto; }
.toolbar .back { display: none; }
.meta { color: var(--muted); margin-bottom: 4px; line-height: 1.5; }
.meta b { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; background: #fafafa; color: inherit; text-decoration: none; }
.chip button { border: none; background: none; padding: 0 0 0 6px; }
.body-text { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; margin: 12px 0; }
.body-frame { border: none; width: 100%; flex: 1; min-height: 400px; margin-top: 8px; }

/* Dialogs */
dialog { border: none; border-radius: 8px; padding: 20px 24px; width: min(680px, 96vw); box-shadow: 0 8px 30px #0004; }
dialog::backdrop { background: #0005; }
dialog h2 { margin-top: 0; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
#compose textarea { margin-top: 8px; resize: vertical; }
/* The message editor */
.ed-bar { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; margin-top: 8px; padding: 3px; border: 1px solid #d1d1d1; border-bottom: none; border-radius: 4px 4px 0 0; background: #fafafa; }
.ed-b { border: none; background: none; padding: 3px 8px; min-height: 0; border-radius: 4px; font-size: 13px; color: var(--text); }
.ed-b:hover { background: #e8e8e8; }
.ed-b.b { font-weight: 700; } .ed-b.i { font-style: italic; font-family: Georgia, serif; } .ed-b.u { text-decoration: underline; }
.ed-sep { width: 1px; height: 18px; background: #d1d1d1; margin: 0 4px; }
.editor { border: 1px solid #d1d1d1; border-radius: 0 0 4px 4px; padding: 8px 10px; min-height: 260px; max-height: 52vh; overflow-y: auto; line-height: 1.45; outline: none; word-wrap: break-word; background: #fff; }
.editor:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.editor blockquote { margin: 6px 0 6px 4px; padding-left: 10px; border-left: 3px solid #c8c8c8; color: #555; }
.editor img { max-width: 100%; height: auto; }
.editor .mk-quote { color: #444; margin-top: 10px; }
.editor p { margin: 0 0 8px; }
.sig-ed { min-height: 90px; max-height: 240px; }
.c-right { display: inline-flex; align-items: center; gap: 12px; }
.c-saved { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.c-discard { margin-left: auto; }
dialog .actions .c-discard { margin-left: 0; }
.ac .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac button.on { background: var(--hover); }
/* Contacts */
.ct-top { gap: 8px; }
.ct-top input { flex: 1; }
.ct-list { list-style: none; margin: 0; padding: 0; max-height: 56vh; overflow-y: auto; }
.ct-list li { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.ct-list li:hover { background: var(--hover); }
.ct-list li.empty { cursor: default; display: block; margin: 20px 0; }
.ct-list .avatar { display: flex; width: 36px; height: 36px; border-radius: 50%; align-items: center; justify-content: center; color: #fff; font-weight: 600; flex: none; }
.ct-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ct-main > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-main .muted { color: var(--muted); font-size: 13px; }
.ct-write { border: none; background: none; padding: 6px; border-radius: 50%; color: var(--blue); }
.danger-link { color: var(--danger) !important; text-decoration: none !important; }
/* Original source, shortcuts */
pre.src { background: #f6f6f6; border: 1px solid var(--line); border-radius: 4px; padding: 10px; font-size: 12px; max-height: 40vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.btn-like { display: inline-flex; align-items: center; border: 1px solid #d1d1d1; border-radius: 4px; padding: 6px 12px; color: inherit; text-decoration: none; background: #fff; }
table.keys td { padding: 4px 10px 4px 0; vertical-align: top; }
kbd { display: inline-block; border: 1px solid #ccc; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font: 12px Consolas, monospace; background: #fafafa; }
/* Dragging onto folders, mailbox space */
.folder.drop { background: var(--sel); outline: 2px dashed var(--blue); outline-offset: -2px; }
.drag-tag { position: fixed; top: -100px; left: 0; background: var(--blue); color: #fff; padding: 4px 10px; border-radius: 12px; font-size: 13px; }
.quota { padding: 10px 16px 12px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.quota .q-bar { height: 5px; background: #e1e1e1; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.quota .q-bar i { display: block; height: 100%; background: var(--blue); }
.quota.warn .q-bar i { background: #c19c00; }
.quota.bad .q-bar i { background: var(--danger); }
.quota.bad .q-text { color: var(--danger); }
.v-when { gap: 12px; flex-wrap: wrap; }
.v-when label { flex: 1 1 200px; }
.sig-form { border: 1px dashed var(--line); border-radius: 6px; padding: 4px 10px 10px; margin: 6px 0; }
.forgot { display: block; margin: 12px auto 0; color: var(--blue) !important; text-decoration: none !important; font-size: 13px; }
#login-ok { color: #107c10; }
/* Calendar */
.cal-entry { font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.cal-entry .ic { vertical-align: -3px; }
.tasks-entry { margin-top: -4px; }
.tasks { max-width: 760px; }
.task-add { display: flex; gap: 8px; margin: 10px 0 16px; flex-wrap: wrap; }
.task-add input:first-child { flex: 1 1 260px; width: auto; }
.task-add .task-due-in { flex: 0 0 160px; width: auto; }
.task-add .primary { display: inline-flex; align-items: center; gap: 6px; }
.task-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; background: var(--pane); }
.task { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid #f0f0f0; }
.task:last-child { border-bottom: none; }
.task input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--blue); }
.task-main { flex: 1; min-width: 0; border: none; background: none; text-align: left; padding: 2px 0; display: flex; flex-direction: column; }
.task-main:hover { background: none; }
.task-title { overflow-wrap: anywhere; }
.task-notes { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.task-when.today { color: var(--blue); font-weight: 600; }
.task-when.late { color: var(--danger); font-weight: 600; }
.task-del { opacity: .5; }
.task-del:hover { opacity: 1; }
.task-del svg { width: 16px; height: 16px; }
.task-done { margin-top: 16px; }
.task-done summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
body.cal-mode .list-pane, body.cal-mode .reader { display: none; }
.calendar { grid-column: 2 / -1; background: var(--pane); overflow-y: auto; padding: 12px 18px; min-height: 0; display: flex; flex-direction: column; }
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.cal-head h2 { margin: 0 6px; font-size: 20px; font-weight: 600; }
.cal-head .spacer { flex: 1; }
.cal-head .primary { display: inline-flex; align-items: center; gap: 6px; }
.cal-nav { padding: 5px 8px; display: inline-flex; }
.cal-nav.next .ic { transform: scaleX(-1); }
.cal-seg { display: inline-flex; border: 1px solid #d1d1d1; border-radius: 4px; overflow: hidden; }
.cal-seg button { border: none; border-radius: 0; }
.cal-seg button.on { background: var(--sel); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(96px, 1fr); flex: 1; border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.cal-dow { grid-row: 1; padding: 4px 6px; font-size: 12px; color: var(--muted); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 0; }
.cal-grid { grid-template-rows: auto; }
.cal-day { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 4px; min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.cal-day:hover { background: var(--hover); }
.cal-day.other { background: #fafafa; color: #999; }
.cal-n { font-size: 12.5px; padding: 1px 4px; align-self: flex-start; border-radius: 10px; }
.cal-day.today .cal-n { background: var(--blue); color: #fff; font-weight: 600; }
.ev { display: block; width: 100%; text-align: left; border: none; border-left: 3px solid var(--evc, var(--blue)); background: #eef4fb; border-radius: 3px; padding: 1px 5px; font-size: 12px; min-height: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.ev.allday { background: var(--evc, var(--blue)); color: #fff; }
.ev.more { background: none; border: none; color: var(--muted); padding-left: 4px; }
.ev-t { color: var(--muted); margin-right: 4px; }
.agenda { max-width: 760px; }
.ag-day h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }
.ag-ev { display: grid; grid-template-columns: 130px 1fr; gap: 2px 12px; width: 100%; text-align: left; background: none; border: none; border-left: 4px solid var(--evc, var(--blue));
  border-radius: 0; padding: 8px 10px; margin: 2px 0; }
.ag-ev:hover { background: var(--hover); }
.ag-time { color: var(--muted); font-size: 13px; }
.ag-title { font-weight: 600; }
.ag-loc { grid-column: 2; color: var(--muted); font-size: 13px; }
.ev-when { gap: 10px; }
.ev-att { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.ev-att:empty { display: none; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 12px; background: #f0f0f0; font-size: 12.5px; }
.att i { font-style: normal; font-weight: 700; }
.att.ACCEPTED { background: #dff6dd; color: #0e700e; } .att.DECLINED { background: #fde7e9; color: #a4262c; text-decoration: line-through; }
.att.TENTATIVE { background: #fff4ce; color: #8a5a00; }
.ev-rsvp { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; margin: 8px 0; border-radius: 8px; background: #eef3fb; border: 1px solid #cbd9ef; }
.ev-rsvp-btns { display: inline-flex; gap: 6px; margin-left: auto; }
.ev-rsvp-btns button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.ev-avail { margin: 6px 0 4px; font-size: 12px; }
.av-head, .av-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 8px; }
.av-row { margin: 3px 0; }
.av-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.av-bar { position: relative; height: 16px; background: #f3f3f3; border-radius: 3px; }
.av-busy { position: absolute; top: 0; bottom: 0; background: #9aa0a6; border-radius: 2px; }
.av-slot { position: absolute; top: -3px; bottom: -3px; border: 2px solid var(--blue); border-radius: 4px; background: #0f6cbd1a; pointer-events: none; }
.av-slot.clash { border-color: var(--danger); background: #c50f1f1a; }
.av-ticks { position: relative; height: 14px; color: var(--muted); }
.av-ticks span { position: absolute; transform: translateX(-50%); font-size: 10.5px; }
.av-note { margin: 4px 0 0; color: var(--muted); }
.av-note.clash { color: var(--danger); }
.share-cal { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
.share-cal h3 { margin: 0 0 6px; font-size: 14px; }
.share-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid #f0f0f0; }
.share-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.share-row select { width: auto; }
.share-add { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.share-add input { flex: 1 1 200px; width: auto; }
.share-add select { width: auto; }
.inv-btns { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.ev-when label { flex: 1 1 160px; }
.ev-when .ev-time { flex: 0 1 140px; }
.attach input { border: none; padding: 4px 0; }
.c-receipt { margin: 0; gap: 6px; font-size: 13px; }
.c-receipt input { width: auto; }
/* Settings: tabs on the left, one section at a time */
dialog.s-dlg { width: min(980px, 96vw); height: min(720px, 92vh); padding: 0; overflow: hidden; }
.s-dlg .settings { display: flex; flex-direction: column; height: 100%; position: relative; }
.s-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; margin: 0; border-bottom: 1px solid var(--line); }
.s-head h2 { flex: 0 0 auto; font-size: 20px; }
.s-head .s-who { display: block; flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-head .primary { display: inline-flex; border-radius: 6px; padding: 6px 18px; }
.s-head > span:first-child { display: none; }
.s-body { flex: 1; display: flex; min-height: 0; }
.s-nav { flex: 0 0 210px; display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; background: #fafafa; border-right: 1px solid var(--line); overflow-y: auto; }
.s-tab { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: none; border-radius: 6px; padding: 9px 12px; color: var(--text); position: relative; }
.s-tab:hover { background: #eef1f5; }
.s-tab svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); }
.s-tab span { flex: 1; }
.s-tab.on { background: var(--sel); font-weight: 600; }
.s-tab.on svg { color: var(--blue); }
.s-tab.on::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--blue); }
.s-badge { font-style: normal; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: #dff6dd; color: #0e700e; }
.s-badge:empty { display: none; }
.s-badge.warn { background: #fff4ce; color: #8a5a00; }
.s-panes { flex: 1; overflow-y: auto; padding: 22px 28px 70px; background: var(--bg); }
.s-pane-head h2 { margin: 0; font-size: 20px; }
.s-pane-head p { margin: 4px 0 18px; color: var(--muted); }
.s-card { background: var(--pane); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin: 0 0 14px; box-shadow: 0 1px 2px #0000000a; }
.s-card h3 { margin: 0 0 4px; font-size: 15px; }
.s-card .hint:first-of-type { margin-top: 2px; }
.s-card label { margin: 10px 0; }
.s-card > button[id$="-save"], .s-card .row > button[id$="-save"], .s-card > button#p-save, .s-card > button#sig-new, .s-card > button#fetch-add { background: var(--blue); color: #fff; border-color: var(--blue); }
.s-card > button[id$="-save"]:hover, .s-card .row > button[id$="-save"]:hover, .s-card > button#p-save:hover { background: var(--blue-dark); }
.s-card > button { margin-top: 4px; }
.s-card.off > label:not(.row), .s-card.off > .v-when { display: none; }
.s-card .row label { flex: 1; }
/* Switches for on/off choices */
.settings input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 36px !important; height: 20px; border-radius: 10px; background: #c8c8c8; border: none; padding: 0; margin: 0; position: relative; flex: 0 0 auto; cursor: pointer; transition: background .15s; }
.settings input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #0003; transition: left .15s; }
.settings input[type=checkbox]:checked { background: var(--blue); }
.settings input[type=checkbox]:checked::after { left: 18px; }
.settings label.row { color: var(--text); gap: 10px; }
.s-toast { position: absolute; left: 50%; bottom: 18px; transform: translate(-50%, 20px); margin: 0; max-width: min(560px, 90%); background: #242424; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px #0004; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 5; }
.s-toast.show { opacity: 1; transform: translate(-50%, 0); }
.s-toast.err { background: var(--danger); }
.row { display: flex; align-items: center; gap: 8px; }
.row input[type=checkbox] { width: auto; }
.narrow { width: 70px !important; display: inline-block; }
.apps { list-style: none; padding: 0; margin: 6px 0; }
.apps li { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; border-bottom: 1px solid #f0f0f0; }
.newpw { background: #dff6dd; padding: 10px; border-radius: 4px; font-family: Consolas, monospace; font-size: 16px; }
.hint { color: var(--muted); }

/* ---------- Phones: one screen at a time, app-style ---------- */
@media (max-width: 800px) {
  :root { font-size: 15px; }
  input, textarea, select { font-size: 16px; } /* no zoom-in on focus (iOS) */
  button { min-height: 40px; }
  .topbar { height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0; gap: 2px; position: relative; z-index: 6; }
  .topbar .brand, .topbar .me, #logout-btn, #notify-btn, #settings-btn { display: none; }
  .topbar .icon { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
  .topbar .icon:active { background: #ffffff26; }
  #menu-btn, #search-btn { display: inline-flex; }
  .m-title { display: block; flex: 1; font-size: 18px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding-left: 4px; }
  .topbar .search { display: none; }
  body.searching .topbar .search { display: block; flex: 1; max-width: none; }
  body.searching .m-title { display: none; }
  .topbar .search input { height: 40px; border-radius: 20px; padding: 0 14px; }

  /* Compose: a round button in the corner */
  #compose-btn { position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 4; width: 58px; height: 58px; border-radius: 18px;
    padding: 0; display: flex; align-items: center; justify-content: center; background: var(--blue); color: #fff; border: none; box-shadow: 0 4px 14px #0f6cbd66, 0 2px 4px #0003; }
  #compose-btn .lbl { display: none; }
  #compose-btn .ic { width: 24px; height: 24px; }
  body.reading #compose-btn { display: none; }

  .panes { grid-template-columns: 1fr; }
  /* Folders: a drawer over a dimmed page */
  .folders { position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); z-index: 20; display: flex; flex-direction: column; padding: 0;
    background: var(--pane); transform: translateX(-105%); transition: transform .22s ease; border: none; }
  body.show-folders .folders { transform: none; box-shadow: 4px 0 24px #0004; }
  .scrim { display: block; position: fixed; inset: 0; background: #0006; z-index: 15; opacity: 0; pointer-events: none; transition: opacity .22s; }
  body.show-folders .scrim { opacity: 1; pointer-events: auto; }
  .drawer-head { display: flex; flex-direction: column; gap: 2px; padding: calc(18px + env(safe-area-inset-top)) 20px 14px; background: var(--blue); color: #fff; }
  .drawer-head .brand { font-size: 18px; font-weight: 600; }
  .d-me { opacity: .9; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  #folders { flex: 1; overflow-y: auto; padding: 8px 0; }
  .folder { padding: 12px 20px; min-height: 46px; align-items: center; border-left: none; border-radius: 0 24px 24px 0; margin-right: 10px; }
  .folder.active { background: var(--sel); }
  .drawer-foot { display: flex; flex-direction: column; border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
  .drawer-foot button { border: none; background: none; text-align: left; padding: 12px 20px; display: flex; align-items: center; gap: 14px; border-radius: 0; }
  .drawer-foot button:active { background: var(--hover); }

  /* The list */
  .list-head { display: none; }
  .list { padding-bottom: 90px; }
  .item { display: grid; grid-template-columns: 40px 1fr; column-gap: 12px; padding: 12px 14px; border-left: none; position: relative; }
  .item.unread::before { content: ""; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--unread); }
  .item > :not(.avatar):not(.ck) { grid-column: 2; min-width: 0; }
  .avatar { display: flex; grid-row: span 3; width: 40px; height: 40px; border-radius: 50%; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 16px; align-self: start; margin-top: 2px; }
  .item .who { font-size: 15px; }
  /* Selecting on a phone: the round initial becomes the tick; the action bar covers the top bar. */
  .item { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  .list.selecting .item { padding-left: 14px; }
  .list.selecting .ck { display: none; }
  .item.selected .avatar { background: var(--blue) !important; }
  .item.selected .avatar .av-l { display: none; }
  .item.selected .avatar .av-c { display: block; width: 22px; height: 22px; stroke-width: 3; }
  .selbar { position: fixed; top: 0; left: 0; right: 0; z-index: 8; height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 4px 0; gap: 0;
    background: var(--blue); color: #fff; border: none; box-shadow: 0 2px 6px #0003; }
  .selbar button { width: 44px; height: 44px; border-radius: 50%; }
  .selbar button:hover, .selbar button:active { background: #ffffff26; }
  .selbar .ic { width: 22px; height: 22px; }
  .sel-count { font-size: 18px; }
  .sel-menu { top: 48px; }
  body.selecting #compose-btn { display: none; }
  .flash { bottom: calc(24px + env(safe-area-inset-bottom)); }
  .item .subj { font-size: 14px; }
  .empty { margin-top: 30%; padding: 0 24px; }

  /* Reading: one screen, with a compact action bar */
  body.reading .list-pane { display: none; }
  body:not(.reading) .reader { display: none; }
  .reader { padding: 0 16px 24px; }
  .reader .toolbar { position: sticky; top: 0; z-index: 3; margin: 0 -16px 8px; padding: 4px 6px; background: var(--pane); border-bottom: 1px solid var(--line); flex-wrap: nowrap; gap: 0; align-items: center; }
  .reader .toolbar > button, .reader .toolbar .more-btn { border: none; background: none; min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center; }
  .reader .toolbar > button:active, .reader .toolbar .more-btn:active { background: var(--hover); }
  .reader .toolbar > button .lbl { display: none; }
  .reader .toolbar > button .ic, .reader .toolbar .more-btn .ic { width: 22px; height: 22px; margin: 0; }
  .toolbar .back { display: inline-flex; margin-right: auto; }
  .toolbar .more-btn { display: inline-flex; order: 4; }
  .extras { display: none; position: absolute; right: 8px; top: 50px; flex-direction: column; min-width: 200px; background: var(--pane); border-radius: 10px; box-shadow: 0 8px 28px #0004; padding: 6px 0; }
  .toolbar.open .extras { display: flex; }
  .extras button { border: none; background: none; text-align: left; padding: 11px 18px; display: flex; align-items: center; gap: 12px; border-radius: 0; }
  .extras button:active { background: var(--hover); }
  .extras select { margin: 6px 14px; width: auto; }
  .reader h1 { font-size: 21px; margin: 10px 0; overflow-wrap: anywhere; }
  .meta { font-size: 14px; overflow-wrap: anywhere; }
  .body-frame { min-height: 60vh; }

  /* Writing and settings: full screen, actions at the top */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }
  dialog form { min-height: 100%; display: flex; flex-direction: column; }
  .dlg-head { position: sticky; top: 0; z-index: 2; background: var(--pane); margin: 0 -16px 6px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line); }
  .dlg-head h2 { font-size: 18px; text-align: left; }
  .dlg-head .icon, .dlg-head .primary, .dlg-head > span { display: inline-flex; align-items: center; justify-content: center; }
  .dlg-head .icon { min-width: 44px; min-height: 44px; font-size: 22px; }
  .dlg-head .primary { padding: 8px 18px; border-radius: 20px; }
  .dlg-head > span { width: 8px; }
  dialog .actions { display: none; }
  #compose label { margin: 6px 0; }
  #compose textarea { flex: 1; min-height: 40vh; }
  #compose .editor { flex: 1; min-height: 38vh; max-height: none; }
  .ed-bar { flex-wrap: nowrap; overflow-x: auto; }
  .ed-b { min-height: 34px; padding: 4px 10px; white-space: nowrap; }
  .c-tools { flex-wrap: wrap; }
  .ct-list { max-height: none; }
  .quota { padding: 10px 20px; }
  .calendar { padding: 8px 12px 90px; }
  body.cal-mode #compose-btn { display: none; }
  .cal-head h2 { font-size: 17px; flex-basis: 100%; order: -1; margin: 0 0 4px; }
  .cal-head .lbl { display: none; }
  .cal-grid { grid-auto-rows: minmax(64px, 1fr); }
  .ev .ev-t { display: none; }
  .ev { font-size: 10.5px; padding: 0 3px; }
  .ag-ev { grid-template-columns: 1fr; }
  .ag-loc { grid-column: 1; }
  /* Settings on phones: tabs become a scrolling strip under the title */
  dialog.s-dlg { width: 100vw; height: 100dvh; max-height: 100dvh; padding: 0; }
  .s-head { margin: 0; padding: calc(6px + env(safe-area-inset-top)) 10px 6px 16px; }
  .s-head .s-who { display: none; }
  .s-head h2 { flex: 1; }
  .s-body { flex-direction: column; }
  .s-nav { flex: 0 0 auto; flex-direction: row; overflow-x: auto; padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--line); gap: 6px; scrollbar-width: none; }
  .s-tab { width: auto; flex: 0 0 auto; padding: 7px 12px; border-radius: 18px; border: 1px solid var(--line); background: #fff; white-space: nowrap; }
  .s-tab.on { border-color: var(--blue); }
  .s-tab.on::before { display: none; }
  .s-panes { padding: 14px 12px 80px; }
  .s-pane-head h2 { font-size: 18px; }
  .s-card { padding: 14px; }
  .s-toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
  dialog.small { width: min(380px, 92vw); height: auto; max-height: 90dvh; margin: auto; border-radius: 10px; padding: 18px 20px; }
  dialog.small form { min-height: 0; }
  dialog.small .actions { display: flex; }
  .apps li { flex-wrap: wrap; gap: 6px; }
  .row { flex-wrap: wrap; }
}
.qr svg { display: block; margin: 6px 0 10px; border-radius: 6px; }
#tfa-code { width: 110px !important; }
#notify-btn.on { color: #2563eb; }
