/* The webmail's whole appearance.
 *
 * Served as its own file rather than inlined into the page, which is what lets
 * the Content-Security-Policy drop 'unsafe-inline' for styles: a policy that
 * permits inline style to make our own page work also permits any inline style
 * an injection manages to place. See handleApp.
 *
 * Three things govern everything below:
 *
 *   1. This is read on a phone as often as on a desktop. The three panes
 *      collapse to one, and every target is at least 40px.
 *   2. It is read for hours. Long sessions are why the density control and the
 *      dark theme exist, and why nothing animates for longer than 150ms.
 *   3. The customer is comparing it, consciously or not, against Gmail. It does
 *      not have to look like Gmail, but it cannot look like less care was taken.
 */

/* ---------------------------------------------------------------- tokens -- */

:root {
  --bg:            #f2f5f9;
  --bg-sunk:       #e8edf5;
  --panel:         #ffffff;
  --panel-2:       #f7f9fc;
  --fg:            #16202e;
  --fg-soft:       #4a5768;
  --muted:         #6b7a8d;
  --line:          #dfe6f0;
  --line-soft:     #eaeff6;
  --accent:        #2563eb;
  --accent-fg:     #ffffff;
  --accent-soft:   #e3ecff;
  --accent-line:   #b9d0ff;
  --star:          #f0a202;
  --bad:           #d02f2f;
  --bad-soft:      #fdecec;
  --ok:            #16794a;
  --ok-soft:       #e6f5ee;
  --warn:          #a35b00;
  --warn-soft:     #fdf1e0;
  --shadow-1:      0 1px 2px rgba(16,32,54,.06), 0 1px 3px rgba(16,32,54,.05);
  --shadow-2:      0 10px 24px rgba(16,32,54,.10), 0 2px 6px rgba(16,32,54,.06);
  --shadow-3:      0 24px 60px rgba(16,32,54,.20);
  --radius:        10px;
  --radius-lg:     16px;

  /* Density. Changed by [data-density] below; every list measurement is
   * derived from these two so one switch moves the whole list together. */
  --row-y:         .62rem;
  --row-gap:       .22rem;

  --rail-w:        16rem;
  --list-w:        24rem;
  --gutter:        1px;

  color-scheme: light;
}

/* The dark palette is written twice, and it has to be. The theme has three
 * states — light, dark, and "whatever the system says" — and only the first two
 * put an attribute on the root element. So the media query covers the system
 * default while excluding anyone who explicitly chose light, and the attribute
 * rule covers an explicit dark choice on a machine set to light. Defining the
 * colours only inside the media query would leave the toggle unable to turn
 * dark ON, and only inside the attribute rule would leave a system-dark machine
 * showing a white screen at midnight. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0b1017;
    --bg-sunk:     #070b11;
    --panel:       #121a25;
    --panel-2:     #0e1621;
    --fg:          #e6ecf5;
    --fg-soft:     #b3c0d1;
    --muted:       #8595aa;
    --line:        #23303f;
    --line-soft:   #1a2531;
    --accent:      #6f9dff;
    --accent-fg:   #06101f;
    --accent-soft: #17263e;
    --accent-line: #2c4468;
    --star:        #ffc046;
    --bad:         #ff6b6b;
    --bad-soft:    #2a1518;
    --ok:          #4ecf9a;
    --ok-soft:     #10241c;
    --warn:        #ffb257;
    --warn-soft:   #2a1f10;
    --shadow-1:    0 1px 2px rgba(0,0,0,.4);
    --shadow-2:    0 12px 28px rgba(0,0,0,.5);
    --shadow-3:    0 24px 60px rgba(0,0,0,.65);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:          #0b1017;
  --bg-sunk:     #070b11;
  --panel:       #121a25;
  --panel-2:     #0e1621;
  --fg:          #e6ecf5;
  --fg-soft:     #b3c0d1;
  --muted:       #8595aa;
  --line:        #23303f;
  --line-soft:   #1a2531;
  --accent:      #6f9dff;
  --accent-fg:   #06101f;
  --accent-soft: #17263e;
  --accent-line: #2c4468;
  --star:        #ffc046;
  --bad:         #ff6b6b;
  --bad-soft:    #2a1518;
  --ok:          #4ecf9a;
  --ok-soft:     #10241c;
  --warn:        #ffb257;
  --warn-soft:   #2a1f10;
  --shadow-1:    0 1px 2px rgba(0,0,0,.4);
  --shadow-2:    0 12px 28px rgba(0,0,0,.5);
  --shadow-3:    0 24px 60px rgba(0,0,0,.65);
  color-scheme: dark;
}

:root[data-density="compact"] { --row-y: .42rem; --row-gap: .1rem; }
:root[data-density="roomy"]   { --row-y: .85rem; --row-gap: .35rem; }

/* ------------------------------------------------------------------ base -- */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* One visible focus ring everywhere. Removing it is how a page becomes
 * unusable without a mouse, and this one is used heavily from the keyboard. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
:focus:not(:focus-visible) { outline: none; }

.muted { color: var(--muted); }
.grow  { flex: 1 1 auto; min-width: 0; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Visible only to a screen reader. Used for the live region that announces
 * what just happened, which sighted users read from the toast instead. */
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  min-height: 2.25rem; padding: .4rem .7rem;
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--accent-line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.icon { padding: .4rem; min-width: 2.25rem; justify-content: center; }
.btn.plain { background: none; border-color: transparent; }
.btn.plain:hover:not(:disabled) { background: var(--panel-2); border-color: var(--line); }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); border-color: var(--accent); }
/* Long labels in a narrow sidebar. Without this the close-account button
 * rendered as "ose my account and delete everythin" — clipped at both ends,
 * which is how a destructive control ends up unreadable. */
.btn.wrap {
  white-space: normal; text-align: left; line-height: 1.35;
  height: auto; min-height: 2.25rem; padding: .5rem .7rem;
}
.btn.tiny { min-height: 1.8rem; padding: .25rem .45rem; font-size: .8rem; }
.tiny { font-size: .78rem; line-height: 1.45; }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
.btn[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent);
  font-weight: 600;
}

.field {
  width: 100%; padding: .6rem .75rem;
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* ----------------------------------------------------------------- login -- */

#login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(1100px 520px at 12% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  overflow: auto;
}
#login[hidden] { display: none; }

.card {
  width: min(26rem, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 1.75rem;
}
.card h1 { margin: 0 0 .3rem; font-size: 1.5rem; letter-spacing: -.02em; }
.card .sub { margin: 0 0 1.4rem; color: var(--muted); font-size: .9rem; }
.card label { display: block; margin-bottom: .9rem; }
.card label > span {
  display: block; margin-bottom: .35rem;
  font-size: .78rem; font-weight: 600; color: var(--fg-soft);
}
/* The password field and its reveal button. The padding on the input keeps
 * the text clear of the button rather than running underneath it. */
.pwwrap { position: relative; }
.pwwrap .field { padding-right: 2.9rem; }
.pweye {
  position: absolute; right: .35rem; top: 50%; transform: translateY(-50%);
  border: none; background: none; cursor: pointer;
  padding: .35rem .45rem; border-radius: 8px; font-size: 1rem; line-height: 1;
}
.pweye:hover { background: var(--line-soft); }

.card .btn.primary { width: 100%; justify-content: center; }
.card .foot { margin: 1.1rem 0 0; font-size: .82rem; color: var(--muted); }

.alert {
  margin-top: .9rem; padding: .6rem .75rem;
  border-radius: var(--radius); font-size: .87rem;
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
}

/* ------------------------------------------------------------------ app --- */

#app { display: none; height: 100%; grid-template-rows: auto 1fr; }
#app.on { display: grid; }

/* --- top bar --- */

.topbar {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem .75rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; letter-spacing: -.02em; font-size: 1.05rem;
  padding-right: .4rem;
}
.brand .mark {
  display: grid; place-items: center; width: 1.85rem; height: 1.85rem;
  border-radius: 9px; background: var(--accent); color: var(--accent-fg);
  font-size: .95rem; font-weight: 800;
}

.searchwrap { position: relative; flex: 1 1 auto; max-width: 46rem; }
.searchwrap .field { padding-left: 2.35rem; padding-right: 2.2rem; background: var(--panel-2); }
.searchwrap .glass, .searchwrap .clear {
  position: absolute; top: 50%; transform: translateY(-50%);
  color: var(--muted); line-height: 1;
}
.searchwrap .glass { left: .7rem; pointer-events: none; }
.searchwrap .clear { right: .35rem; border: none; background: none; padding: .3rem; border-radius: 6px; }
.searchwrap .clear:hover { background: var(--line-soft); color: var(--fg); }

.who { font-size: .82rem; color: var(--muted); max-width: 15rem; }

/* --- panes --- */

/* Three panes and two draggable gutters between them.
 *
 * The widths are custom properties rather than fixed values so one drag moves
 * the whole grid, and so the choice can be remembered. A mail client where the
 * reading pane cannot be made bigger is a mail client somebody stops using:
 * what is comfortable depends on the screen, the message and the person. */
.panes {
  display: grid;
  grid-template-columns: var(--rail-w) var(--gutter) var(--list-w) var(--gutter) minmax(0, 1fr);
  min-height: 0;
}
.pane { min-height: 0; display: flex; flex-direction: column; }

.gutter {
  position: relative;
  background: var(--line);
  cursor: col-resize;
  transition: background .12s ease;
}
/* The visible line is 1px but the grab target is not — a 1px target is a test
 * of aim rather than a control. This widens the hit area without moving the
 * layout, which is why it is a pseudo-element rather than padding. */
.gutter::after {
  content: ""; position: absolute; top: 0; bottom: 0;
  left: -4px; right: -4px; z-index: 3;
}
.gutter:hover, .gutter:focus-visible, .gutter.dragging { background: var(--accent); }
.gutter:focus-visible { outline: none; }
/* While dragging, the pointer must not turn into a text cursor over the panes
 * and a stray selection must not be made. */
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe { pointer-events: none; }

/* --- folder rail --- */

#rail { background: var(--panel-2); overflow-y: auto; padding: .7rem .55rem 1.5rem; }
#compose { width: 100%; justify-content: center; margin-bottom: .8rem; min-height: 2.6rem; }

.railhead {
  margin: 1.1rem .55rem .35rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}

/* The "Folders" label and the New folder button share a row, so the button
 * does not need a heading of its own or a second row of vertical space. The
 * row carries the vertical rhythm .railhead normally carries on its own —
 * .railhead itself is reset to margin:0 here so it centers against the
 * button instead of sitting on its own baseline. */
.railrow { display: flex; align-items: center; justify-content: space-between; margin: 1.1rem .55rem .35rem; }
.railrow .railhead { margin: 0; }
.railrow .btn.icon { min-height: 1.7rem; min-width: 1.7rem; padding: .25rem; }
.railrow .btn.icon .svgi { width: .95rem; height: .95rem; }

/* Each row is a container, not a button, so a rename/delete icon can sit
 * beside the folder button itself rather than nested inside it — a <button>
 * cannot legally contain another <button>, and the click for "open this
 * folder" must not fire when the click was really for "rename it". */
.fold {
  display: flex; align-items: center;
  border-radius: 999px; margin-bottom: 1px;
}
.fold:hover, .fold:focus-within { background: var(--line-soft); }
/* .cur, not [aria-current] — aria-current belongs on .foldmain, the actual
 * treeitem, and duplicating it on this plain wrapper div would be a stray
 * ARIA attribute with no element role to attach it to. */
.fold.cur { background: var(--accent-soft); }

.fold .foldmain {
  display: flex; align-items: center; gap: .55rem; flex: 1 1 auto; min-width: 0;
  text-align: left; padding: .45rem .6rem;
  background: none; border: none; border-radius: 999px;
  color: var(--fg-soft); font: inherit; font-size: .9rem;
}
.fold.cur .foldmain { color: var(--accent); font-weight: 700; }
.fold .ico { flex: 0 0 auto; width: 1.15rem; text-align: center; opacity: .85; }
.fold .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold .n { flex: 0 0 auto; font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.fold .n.unread { color: var(--accent); font-weight: 700; }
/* The total, shown beside the unread count when they differ. Lighter and
 * smaller so the eye reads "3 unread of 57" rather than two rival numbers. */
.fold .n.total { opacity: .65; font-size: .7rem; }
.fold .n.unread + .n.total::before { content: "/"; margin: 0 .15rem; opacity: .5; }
.fold.cur .n { color: var(--accent); }
.fold.drop { outline: 1px solid var(--accent); background: var(--accent-soft); }

/* Rename and delete: small, and out of the way until the row is hovered or
 * one of them has keyboard focus — a folder list is not the place for two
 * extra icons on every single row all the time. Kept in the layout rather
 * than display:none so Tab still reaches them for a keyboard user who is
 * not hovering anything. */
.fold .foldact {
  flex: 0 0 auto; width: 1.6rem; height: 1.6rem; margin-right: .3rem;
  padding: .2rem; border: none; background: none; border-radius: 6px;
  color: var(--muted); opacity: 0; transition: opacity .12s ease;
}
.fold:hover .foldact, .fold:focus-within .foldact { opacity: 1; }
.fold .foldact:hover { background: var(--panel); color: var(--fg); }
.fold .foldact.danger:hover { background: var(--bad-soft); color: var(--bad); }
.fold .foldact .svgi { width: .9rem; height: .9rem; }

/* Touch devices have no hover, so the icons above would never appear —
 * leaving a freshly created folder with no visible way to rename or
 * delete it. Show them plainly wherever there is no hover to reveal
 * them; real pointer/desktop keeps the hover-reveal behavior above. */
@media (hover: none) {
  .fold .foldact { opacity: 1; }
}

#yourdata { margin: 1.2rem .3rem 0; padding: .9rem .55rem; border-top: 1px solid var(--line); }
#yourdata p { margin: 0 0 .7rem; font-size: .8rem; color: var(--muted); line-height: 1.45; }
#yourdata .btn { width: 100%; justify-content: center; margin-bottom: .4rem; }
#yourdata .field { margin-bottom: .45rem; }
.status { font-size: .8rem; margin-top: .5rem; color: var(--muted); }
.status.bad { color: var(--bad); }
.status.ok  { color: var(--ok); }

/* --- message list --- */

#listpane { background: var(--panel); }

/* flex: 0 0 auto on both bars below is load-bearing, not tidying.
 *
 * #listpane is a flex column and #list is flex:1, so with the default
 * flex-shrink:1 a long message list SQUASHES the bars above it — the filter
 * chips end up sliced in half horizontally, which is exactly how this shipped
 * and what the first screenshot of it showed. min-height does not save you:
 * flex-shrink overrides it. */
.toolbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: .35rem;
  padding: .45rem .55rem;
  border-bottom: 1px solid var(--line);
  min-height: 3rem;
}
.toolbar .sep { width: 1px; height: 1.4rem; background: var(--line); margin: 0 .2rem; }
.toolbar .count { font-size: .78rem; color: var(--muted); margin-left: auto; padding-right: .3rem;
                  font-variant-numeric: tabular-nums; }

/* Wrapping rather than scrolling sideways. The list column is 24rem, which is
 * not wide enough for five chips in a row, and a horizontal scroll hides
 * controls behind a gesture nobody thinks to make — the "Empty folder" button
 * was off the right-hand edge and invisible. */
/* The action bar. Appears only with a selection, wraps rather than scrolling,
 * and every control is a word rather than a glyph — the icon-only version was
 * genuinely undecodable, and two of the icons meant nearly opposite things. */
.actionbar {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: .35rem;
  padding: .45rem .55rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
}
.actionbar[hidden] { display: none; }
.actionbar .btn { min-height: 2rem; font-size: .84rem; }

.chips {
  flex: 0 0 auto;
  display: flex; flex-wrap: wrap; gap: .3rem;
  padding: .4rem .55rem; border-bottom: 1px solid var(--line-soft);
}
.chip {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--fg-soft);
  border-radius: 999px; padding: .25rem .7rem; font-size: .8rem; white-space: nowrap;
}
/* "Empty folder" is not a view filter — it moves every message in the folder to
 * Trash. It sits at the end of this row because there is nowhere better in a
 * column this narrow, so it is coloured to say it is a different kind of thing.
 * It still demands the folder's name be typed before it does anything. */
.chip.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.chip.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.chip:hover { border-color: var(--accent-line); color: var(--fg); }
.chip[aria-pressed="true"] {
  background: var(--accent-soft); border-color: var(--accent-line);
  color: var(--accent); font-weight: 600;
}

#list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }

.row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: start;
  gap: 0 .5rem;
  width: 100%; text-align: left;
  padding: var(--row-y) .6rem;
  background: none; border: none;
  border-bottom: 1px solid var(--line-soft);
  border-left: 3px solid transparent;
  color: inherit;
}
/* touch-action: pan-y hands vertical scrolling to the browser and leaves
 * horizontal movement to the swipe handler. Without it the two contest every
 * gesture and the list stutters. */
.row { position: relative; touch-action: pan-y; }

/* The action revealed behind the row while it is being dragged. Painted with a
 * pseudo-element on the row itself, so there is no extra wrapper per row in a
 * list that may hold thousands. */
.row.swiping { user-select: none; z-index: 1; }
.row.swiping::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  display: flex; align-items: center;
  font-size: 1.2rem; color: #fff;
  padding: 0 1.1rem;
}
.row.swipe-star::before { content: "★"; background: var(--star); justify-content: flex-start; }
.row.swipe-del::before  { content: "🗑"; background: var(--bad);  justify-content: flex-end; }
/* Past the commitment point. Until this lights up, letting go springs back. */
.row.swipe-armed::before { filter: brightness(1.08); font-size: 1.45rem; }

.row:hover { background: var(--panel-2); }

/* Selected and open are two different states and looked identical — both a
 * flat blue — so a row you had merely opened was indistinguishable from one
 * you had ticked for a bulk delete. Selected is the tint; open is the bar down
 * the left edge and a lighter wash. */
.row.sel { background: var(--accent-soft); }
.row[aria-current="true"] {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--panel));
}
.row.sel[aria-current="true"] { background: var(--accent-soft); }
.row.cursor { box-shadow: inset 0 0 0 2px var(--accent-line); }
.row.unread { background: var(--panel); }
.row.unread .from, .row.unread .subj { font-weight: 700; color: var(--fg); }
.row.unread .dot { background: var(--accent); }

.row .pick, .row .starbtn {
  grid-row: 1 / span 3; align-self: center;
  border: none; background: none; padding: .2rem; border-radius: 6px; line-height: 1;
}
.row .pick { color: var(--muted); font-size: .95rem; width: 1.6rem; }
.row .pick:hover { background: var(--line-soft); color: var(--fg); }
.row .pick[aria-checked="true"] { color: var(--accent); }
.row .starbtn { color: var(--line); font-size: 1.05rem; width: 1.6rem; }
.row .starbtn:hover { color: var(--star); }
.row .starbtn.on { color: var(--star); }

.row .line1 { display: flex; align-items: baseline; gap: .4rem; min-width: 0; }
.row .from { flex: 1 1 auto; min-width: 0; font-size: .89rem; color: var(--fg-soft);
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tcount {
  flex: 0 0 auto; font-size: .72rem; color: var(--muted);
  background: var(--line-soft); border-radius: 999px; padding: 0 .38rem;
}
.row .when { grid-row: 1; grid-column: 4; font-size: .74rem; color: var(--muted);
             white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: .3rem; }
.row .subj { grid-column: 3 / span 2; font-size: .88rem; margin-top: .05rem;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .snip { grid-column: 3 / span 2; font-size: .82rem; color: var(--muted);
             margin-top: var(--row-gap);
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .tags { grid-column: 3 / span 2; display: flex; gap: .35rem; margin-top: .3rem; flex-wrap: wrap; }
.tag {
  font-size: .68rem; padding: .05rem .4rem; border-radius: 5px;
  background: var(--line-soft); color: var(--muted); white-space: nowrap;
}
.tag.warn { background: var(--warn-soft); color: var(--warn); }

:root[data-density="compact"] .row .snip { display: none; }

.loadmore { display: grid; place-items: center; padding: 1rem; }

.empty {
  display: grid; place-items: center; gap: .5rem;
  padding: 3rem 1.5rem; text-align: center; color: var(--muted);
}
.empty .big { font-size: 2rem; opacity: .5; }
.empty h3 { margin: 0; font-size: 1rem; color: var(--fg-soft); font-weight: 600; }
.empty p { margin: 0; font-size: .87rem; max-width: 26rem; }

/* skeleton rows while a folder loads, so the pane does not flash empty */
.skel { padding: var(--row-y) .6rem; border-bottom: 1px solid var(--line-soft); }
.skel span {
  display: block; height: .62rem; border-radius: 4px; margin-bottom: .45rem;
  background: linear-gradient(90deg, var(--line-soft), var(--line), var(--line-soft));
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
.skel span:nth-child(1) { width: 38%; }
.skel span:nth-child(2) { width: 72%; }
.skel span:nth-child(3) { width: 55%; margin-bottom: 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- reader --- */

/* The reader is a flex column with ONE scroll region: the body frame.
 *
 * A message body renders inside a sandboxed iframe with no same-origin
 * privileges, which means this page cannot measure how tall its content is —
 * that would need a script inside the frame, and no script runs inside that
 * frame on purpose. So the frame cannot grow to fit. The choice is between two
 * nested scrollbars and one, and one is right: the header, attachments and
 * conversation strip stay put where they can be seen, and the body scrolls
 * inside its own box the way a document does. */
#readerpane { background: var(--panel-2); }
#reader {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  padding: 1.1rem 1.3rem 1.1rem;
  overflow: hidden;
}
#reader > div:first-child { overflow-y: auto; max-height: 55%; padding-right: .2rem; }

.msghead { display: flex; align-items: flex-start; gap: .8rem; margin-bottom: .9rem; }
/* The ✕ that closes the message: top right of the header, on every screen size.
 * Owner feedback 24 Aug: it existed (1.1.0) but "took some time to find" —
 * `.btn.plain` has no background or border until hovered, so it read as
 * stray text rather than a button. A permanent soft circular chip fixes
 * that without a new icon, handler, or code path. */
.msghead .closebtn {
  flex: 0 0 auto; margin-left: auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 50%;
}
.msghead .closebtn:hover:not(:disabled) {
  background: var(--line-soft); border-color: var(--accent-line); color: var(--accent);
}
.avatar {
  flex: 0 0 auto; display: grid; place-items: center;
  width: 2.6rem; height: 2.6rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: 1rem; text-transform: uppercase;
}
#reader h2 { margin: 0 0 .55rem; font-size: 1.3rem; line-height: 1.3; letter-spacing: -.015em; }
.meta { font-size: .85rem; color: var(--muted); }
.meta .name { color: var(--fg); font-weight: 600; }
.meta + .meta { margin-top: .1rem; }

.bodyframe {
  flex: 1 1 auto; width: 100%; min-height: 14rem; margin-top: 1rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff;
}
pre.plain {
  white-space: pre-wrap; overflow-wrap: anywhere; font: inherit;
  margin-top: 1rem; padding: 1rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}

.note {
  margin-top: 1rem; padding: .65rem .8rem;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: .86rem; color: var(--fg-soft);
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
}
.note.bad  { border-left-color: var(--bad);  color: var(--bad); background: var(--bad-soft); }
.note.warn { border-left-color: var(--warn); color: var(--warn); background: var(--warn-soft); }

.attachbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.att {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem .7rem; max-width: 18rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); color: inherit; text-decoration: none;
}
.att:hover { border-color: var(--accent); }
.att .ico { font-size: 1.1rem; }
.att .nm { font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .sz { font-size: .74rem; color: var(--muted); margin-left: auto; }

/* conversation strip inside the reader */
.thread { margin: 1.2rem 0 0; border-top: 1px solid var(--line); padding-top: .8rem; }
.thread h4 {
  margin: 0 0 .5rem; font-size: .7rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.threadhead { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.threadhead h4 { margin: 0; }
.threadactions {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  padding: .45rem .55rem; margin-bottom: .4rem;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  border-radius: var(--radius);
}

/* A row in the conversation is now a checkbox and a button, not one button —
 * ticking a message and opening it are different intentions. */
.tmsg {
  display: flex; align-items: center; gap: .3rem; width: 100%;
  border: 1px solid transparent; border-radius: var(--radius);
}
.tmsg:hover { background: var(--panel); border-color: var(--line); }
.tmsg[aria-current="true"] { background: var(--accent-soft); border-color: var(--accent-line); }
.tpick {
  flex: 0 0 auto; border: none; background: none; color: var(--muted);
  padding: .35rem .3rem; border-radius: 6px; font-size: .95rem;
}
.tpick:hover { color: var(--fg); background: var(--line-soft); }
.tpick[aria-checked="true"] { color: var(--accent); }
.topen {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: baseline; gap: .6rem; text-align: left;
  padding: .45rem .5rem .45rem .2rem; border: none;
  background: none; color: inherit; font-size: .85rem;
}
.topen .star { color: var(--star); }
.tmsg .who { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
             white-space: nowrap; color: var(--fg); }
.tmsg.unread .who { font-weight: 700; }
.tmsg .when { color: var(--muted); font-size: .76rem; white-space: nowrap; }

/* --- composer --- */

/* Docked, not modal. Writing a message nearly always means checking something
 * in another one — an address, a figure, what was actually said — and a modal
 * makes that impossible without abandoning the draft. Gmail learned this in
 * 2013 and every client has copied it since. */
.composer {
  position: fixed; right: 1.1rem; bottom: 0;
  width: min(42rem, calc(100vw - 2rem));
  max-height: min(38rem, calc(100vh - 4rem));
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-3);
  z-index: 60;
}
.composer[hidden] { display: none; }
/* height is !important because the resize grip writes an inline height, and
 * inline beats a class — without this, minimising a window somebody had made
 * taller would leave a tall empty bar. */
.composer.mini { max-height: none; height: auto !important; }
/* Set by the drag handler once the window has been moved: the panel stops
 * being anchored to the bottom-right and starts being positioned outright. */
.composer.floating { right: auto; bottom: auto; border-bottom: 1px solid var(--line);
                     border-radius: var(--radius-lg); }
.composer.full {
  right: 2vw; bottom: 2vh; left: 2vw; top: 2vh;
  width: auto; height: auto; max-height: none;
  border-radius: var(--radius-lg); border-bottom: 1px solid var(--line);
}
.chead { cursor: grab; }
.chead:active { cursor: grabbing; }
/* The resize grip. Top-left because the panel grows up and to the left from
 * its anchor in the bottom-right corner, so that is the edge that moves. */
.cgrip {
  position: absolute; top: 0; left: 0; width: 16px; height: 16px;
  cursor: nwse-resize; z-index: 4;
}
.composer.full .cgrip, .composer.mini .cgrip { display: none; }
.composer.mini .cbody, .composer.mini .cfoot { display: none; }

.chead {
  display: flex; align-items: center; gap: .3rem;
  padding: .5rem .5rem .5rem .9rem;
  background: var(--fg); color: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.chead .ctitle { font-size: .88rem; font-weight: 600; overflow: hidden;
                 text-overflow: ellipsis; white-space: nowrap; }
.chead .btn { color: inherit; }
.chead .btn:hover:not(:disabled) { background: rgba(255,255,255,.14); border-color: transparent; }

.cbody { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 0 .9rem; }

.crow { display: flex; align-items: center; gap: .6rem; border-bottom: 1px solid var(--line-soft); }
.crow label { flex: 0 0 3.2rem; font-size: .82rem; color: var(--muted); padding: .55rem 0; }
.cfield {
  flex: 1 1 auto; min-width: 0; border: none; background: none;
  padding: .55rem 0; font-size: .9rem; color: var(--fg);
}
.cfield:focus { outline: none; }
.crow:focus-within { border-bottom-color: var(--accent); }
.ccopy { font-size: .78rem; color: var(--muted); }

.ctools { display: flex; align-items: center; gap: .1rem; padding: .4rem 0;
          border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.ctools .sep { width: 1px; height: 1.2rem; background: var(--line); margin: 0 .3rem; }
.ctools .btn { min-height: 1.9rem; min-width: 1.9rem; padding: .2rem .35rem; }

.cwrite {
  flex: 1 1 auto; min-height: 8rem; overflow-y: auto;
  padding: .8rem 0; font-size: .92rem; line-height: 1.55;
  outline: none;
}
.cwrite:empty::before {
  content: attr(data-placeholder); color: var(--muted);
}
.cwrite blockquote {
  margin: .8em 0; padding-left: .9em;
  border-left: 3px solid var(--line); color: var(--muted);
}
.cwrite a { color: var(--accent); }

.cattach { display: flex; flex-wrap: wrap; gap: .4rem; padding-bottom: .6rem; }
.cattach .file {
  display: flex; align-items: center; gap: .45rem;
  padding: .3rem .55rem; font-size: .8rem;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.cattach .file button { border: none; background: none; color: var(--muted); padding: 0 .1rem; }
.cattach .file button:hover { color: var(--bad); }

.cfoot {
  display: flex; align-items: center; gap: .5rem;
  padding: .7rem .9rem; border-top: 1px solid var(--line); background: var(--panel-2);
  border-radius: 0;
}
.cfoot .btn { min-height: 2.3rem; }
#cattachbtn { display: inline-flex; align-items: center; }
.cstatus { font-size: .8rem; color: var(--muted); }
.cstatus.bad { color: var(--bad); }

@media (max-width: 62rem) {
  .composer { right: 0; left: 0; width: 100%; max-height: 100vh; height: 100vh;
              border-radius: 0; border: none; }
  .chead { border-radius: 0; }
}

/* --- misc spacing helpers, so no markup carries an inline style --- */

.gap { height: .9rem; }
.gap.lg { height: 1.2rem; }
.railhead.flush { margin-left: .25rem; }
.setnote { font-size: .82rem; margin-top: .4rem; }

/* --- toast --- */

#toasts {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .5rem; align-items: center;
  z-index: 90; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: .9rem;
  padding: .6rem .75rem .6rem 1rem;
  background: var(--fg); color: var(--bg);
  border-radius: var(--radius); box-shadow: var(--shadow-2);
  font-size: .87rem; pointer-events: auto;
  animation: rise .15s ease;
  max-width: min(32rem, calc(100vw - 2rem));
}
.toast.bad { background: var(--bad); color: #fff; }
.toast button {
  border: none; background: none; color: inherit;
  font-weight: 700; text-decoration: underline; padding: .2rem .3rem; border-radius: 6px;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* --- dialogs --- */

dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--panel); color: var(--fg);
  box-shadow: var(--shadow-3);
  padding: 0; width: min(34rem, calc(100vw - 2rem)); max-height: 86vh;
}
dialog::backdrop { background: rgba(9,14,22,.45); backdrop-filter: blur(2px); }
dialog .dhead {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line);
}
dialog .dhead h3 { margin: 0; font-size: 1.02rem; }
dialog .dbody { padding: 1.1rem; overflow-y: auto; max-height: 60vh; }
dialog .dfoot {
  display: flex; justify-content: flex-end; gap: .5rem;
  padding: .8rem 1.1rem; border-top: 1px solid var(--line); background: var(--panel-2);
}
dialog p { margin: 0 0 .8rem; font-size: .9rem; color: var(--fg-soft); line-height: 1.55; }
dialog label, dialog .seglabel { display: block; margin-bottom: 1rem; }
dialog label > span, dialog .seglabel > span { display: block; margin-bottom: .35rem; font-size: .8rem;
                      font-weight: 600; color: var(--fg-soft); }

.pickfolder { display: flex; flex-direction: column; gap: 2px; }
.pickfolder button {
  display: flex; align-items: center; gap: .5rem; text-align: left;
  padding: .5rem .65rem; border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: inherit; font-size: .9rem;
}
.pickfolder button:hover { background: var(--accent-soft); border-color: var(--accent-line); }

.kbd {
  display: inline-block; min-width: 1.5rem; text-align: center;
  padding: .1rem .35rem; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; background: var(--panel-2);
  font: 600 .76rem ui-monospace, SFMono-Regular, Menlo, monospace;
}
.keys { display: grid; grid-template-columns: auto 1fr; gap: .5rem .9rem; align-items: center;
        font-size: .87rem; }
.keys .grouphead { grid-column: 1 / -1; margin: .7rem 0 .1rem; font-size: .7rem;
                   letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* Same small-caps label the shortcuts list uses for its section headers
   (.keys .grouphead above), but for a single label outside that grid — the
   About dialog's "What's new". */
.abouteyebrow { display: block; margin: 0 0 .3rem; font-size: .7rem;
                letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#aboutversion { font-size: 1rem; font-weight: 650; color: var(--fg); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: none; background: var(--panel); padding: .4rem .75rem; font-size: .85rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* --- mail rules (Settings > Mail rules, and the add/edit dialog) --- */

#ruleslist { display: flex; flex-direction: column; gap: 2px; margin-bottom: .6rem; }

.ruleitem {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .55rem; border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 4px; background: var(--panel);
}
.ruleitem.off { opacity: .55; }
.ruleitem .ruleinfo { flex: 1 1 auto; min-width: 0; }
.ruleitem .rulename { font-size: .88rem; font-weight: 600; display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ruleitem .rulesummary { font-size: .76rem; color: var(--muted); display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ruleitem .ruleact {
  flex: 0 0 auto; width: 1.7rem; height: 1.7rem; padding: .25rem;
  border: none; background: none; border-radius: 6px; color: var(--muted);
}
.ruleitem .ruleact:hover { background: var(--panel-2); color: var(--fg); }
.ruleitem .ruleact.danger:hover { background: var(--bad-soft); color: var(--bad); }
.ruleitem .ruleact .svgi { width: .9rem; height: .9rem; }
.ruleitem .ruletoggle { flex: 0 0 auto; }

#ruleconditions { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.condrow { display: flex; gap: .4rem; align-items: center; }
.condrow select { flex: 0 0 auto; width: auto; }
.condrow input.field { flex: 1 1 auto; margin: 0; }
.condrow .ruleact { flex: 0 0 auto; width: 1.7rem; height: 1.7rem; padding: .25rem;
  border: none; background: none; border-radius: 6px; color: var(--muted); }
.condrow .ruleact:hover { background: var(--bad-soft); color: var(--bad); }
.condrow .ruleact .svgi { width: .9rem; height: .9rem; }

.rulecheck { display: flex; align-items: center; gap: .5rem; font-size: .88rem;
  font-weight: 400; color: var(--fg); margin-bottom: .55rem; cursor: pointer; }
.rulecheck input { margin: 0; }
#actfolder { margin: -.25rem 0 .55rem 1.6rem; width: calc(100% - 1.6rem); }
#actfolder:disabled { opacity: .5; }

/* --- responsive --- */

@media (max-width: 78rem) { :root { --list-w: 21rem; --rail-w: 14rem; } }

@media (max-width: 62rem) {
  .panes { grid-template-columns: 1fr; }
  .pane + .pane { border-left: none; }
  .pane, .gutter { display: none; }
  #app[data-view="rail"]   #rail       { display: flex; }
  #app[data-view="list"]   #listpane   { display: flex; }
  #app[data-view="read"]   #readerpane { display: flex; }
  .backbtn { display: inline-flex !important; }
  .who { display: none; }
  #reader { padding: .9rem .8rem 3rem; }
}

.backbtn { display: none; }

@media print {
  .topbar, #rail, #listpane, #toasts, .attachbar, .thread { display: none !important; }
  .panes { grid-template-columns: 1fr; }
  body { overflow: visible; background: #fff; }
  #reader { overflow: visible; }
}

/* ------------------------------------- 1.2.0: SVG icons, toolbar polish -- */

/* Inline icons: they size with the text, inherit currentColor (which is what
 * makes them follow dark mode), and never shrink in a flex row. */
.svgi { width: 1.1em; height: 1.1em; flex: 0 0 auto; vertical-align: -0.2em; }
.btn .svgi, .pweye .svgi, .glass .svgi { vertical-align: initial; }
.row .pick .svgi, .row .starbtn .svgi, .tpick .svgi { width: 1.05rem; height: 1.05rem; }

/* The same quiet hover and visible focus on every toolbar button. pick,
 * starbtn, tpick and pweye had hover rules of their own or none at all; this
 * rounds them off without moving anything. */
.btn.plain:focus-visible,
.row .pick:focus-visible, .row .starbtn:focus-visible,
.tpick:focus-visible, .pweye:focus-visible { background: var(--panel-2); }
.btn.plain:active:not(:disabled) { background: var(--line-soft); }

/* Prev / Next in the reader header. */
.msghead .navbtns { display: inline-flex; gap: .15rem; flex: 0 0 auto; }
