/* ==========================================================================
   mail.jarin.dev — single-user webmail stylesheet
   House system: MALearn launchpad tokens x MAFinance v2 stamps x jarin.dev,
   worn on a Gmail skeleton. Flat print-shop: 1.5px ink borders, hard offset
   shadows, zero gradients, zero blur, zero decorative motion.
   ========================================================================== */

/* ---------- Fonts (local files only — no CDN, no external requests) ------- */
@font-face {
  font-family: 'Archivo';
  src: url('fonts/Archivo-400.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto';
  src: url('fonts/Roboto-0.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Roboto Mono';
  src: url('fonts/RobotoMono-0.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens -------------------------------------------------------- */
:root {
  --paper: #F8F9FA;
  --card: #FFFFFF;
  --ink: #202124;
  --grey: #5F6368;
  --line: #DADCE0;
  --line2: #E8EAED;
  --blue: #1A73E8;
  --blue-d: #174EA6;
  --blue-t: #E8F0FE;
  --red: #D93025;
  --yellow: #F9AB00;

  --font-ui: 'Roboto', system-ui, sans-serif;
  --font-disp: 'Archivo', system-ui, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, monospace;

  --b: 1.5px;          /* the one border weight of the house */
  --r: 10px;           /* card / surface radius */
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --row-hover: #F1F3F4;
}

/* ---------- Reset / base -------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--blue); }

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

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

textarea { resize: vertical; }

svg { display: block; flex: none; }

input::placeholder,
textarea::placeholder { color: var(--grey); opacity: 1; }

/* The one focus language, everywhere. */
:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

::selection { background: var(--blue-t); color: var(--ink); }

/* Views carry `hidden` managed by JS *and* are gated by html[data-boot] —
   the two mechanisms coexist, so nothing may out-specify this guard. */
[hidden] { display: none !important; }

/* ---------- Micro-type utilities ----------------------------------------- */
.mono {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .08em;
}

.field-label,
.nav-heading,
.nav-count,
.list-count,
.thread-chip,
.live-pill,
.reply-head,
.toast {
  text-transform: uppercase;
  letter-spacing: .12em;
}

/* ---------- Stamp buttons ------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  border: var(--b) solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 4px 4px 0 var(--ink);
}
.btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}
.btn:disabled,
.btn[aria-busy="true"] {
  opacity: .6;
  cursor: default;
  transform: none;
  box-shadow: 3px 3px 0 var(--ink);
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-block { width: 100%; }

/* ---------- Icon buttons -------------------------------------------------- */
.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: inherit;
  transition: background-color .12s ease;
}
.icon-btn:hover { background: var(--line2); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Auth view (pre-session hero) --------------------------------- */
.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--paper);
}

.auth-card {
  width: min(400px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
  box-shadow: 6px 6px 0 var(--ink);
}

.auth-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
}

.auth-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--font-disp);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -.02em;
}
.auth-domain { color: var(--grey); font-weight: 500; }
.auth-sub { color: var(--grey); font-size: 13px; margin-top: -6px; }

.auth-field { display: block; margin-top: 6px; }
.auth-field input {
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-bottom: var(--b) solid var(--line);
  background: none;
}
.auth-field input:focus { border-bottom-color: var(--blue); }
.auth-field:focus-within .field-label { color: var(--blue); }

.auth-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
}

/* ---------- App shell / topbar -------------------------------------------- */
.app-view { display: block; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-inline: calc(12px + env(safe-area-inset-left)) calc(12px + env(safe-area-inset-right));
  background: var(--card);
  border-bottom: var(--b) solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 4px;
  color: var(--ink);
  text-decoration: none;
  flex: none;
}
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
}
.brand-name {
  font-family: var(--font-disp);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -.02em;
}

.searchwrap {
  position: relative;
  flex: 1 1 auto;
  max-width: 640px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 0 8px 0 12px;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: 999px;
}
.search-icon { color: var(--grey); }
.searchwrap input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  background: none;
}
.searchwrap input:focus-visible { outline: none; }
/* The field itself is the focus indicator for the search pill. */
.searchwrap:focus-within {
  border-color: var(--blue);
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.searchwrap input::-webkit-search-cancel-button,
.searchwrap input::-webkit-search-decoration { display: none; }

.search-clear {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  color: var(--grey);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex: none;
}

.live-pill {
  padding: 2px 8px;
  border: var(--b) solid var(--line);
  border-radius: 999px;
  color: var(--grey);
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

/* ---------- Layout skeleton ---------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: 256px minmax(340px, 420px) 1fr;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow: hidden;
}
.layout > * { min-width: 0; }

/* ---------- Sidebar ------------------------------------------------------ */
.sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  background: var(--card);
  border-right: var(--b) solid var(--ink);
}

.btn-compose {
  width: 100%;
  justify-content: center;
  margin-bottom: 16px;
  background: var(--blue);
  color: #fff;
}

.nav-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.nav-section + .nav-section { margin-top: 18px; }

.nav-heading {
  padding: 0 10px;
  margin-bottom: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--grey);
}

.nav-list > li + li { margin-top: 2px; }

.nav-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  transition: background-color .12s ease;
}
.nav-row:hover { background: var(--line2); }
.nav-row:focus-visible { outline-offset: -2px; }
.nav-row.active,
.nav-row[aria-current="true"] {
  background: var(--blue-t);
  color: var(--blue-d);
  font-weight: 700;
}

.nav-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--tone, var(--blue));
}

.nav-glyph { width: 16px; height: 16px; flex: none; }

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  flex: none;
}
.nav-row.active .nav-count { background: var(--blue-d); }

/* Addresses on a project whose domain isn't routable yet (e.g. waiting on a
   Resend slot): dimmed, with the count badge echoing the muted tone. */
.nav-row.pending { opacity: .55; }
.nav-row.pending .nav-count { background: var(--grey); }

.nav-note {
  padding: 12px 10px 4px;
  color: var(--grey);
  font-size: 11px;
  font-style: italic;
}

/* ---------- List pane ---------------------------------------------------- */
.list-pane {
  overflow-y: auto;
  background: var(--card);
  border-right: var(--b) solid var(--ink);
}

.list-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: var(--b) solid var(--line);
}
.list-title {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.01em;
}
.list-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey);
}

.mail-list { list-style: none; }

.mail-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line2);
  cursor: pointer;
}
.mail-row:hover { background: var(--row-hover); }
.mail-row:focus-visible { outline-offset: -2px; }
.mail-row.active,
.mail-row.active:hover { background: var(--blue-t); }

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r);
  border: var(--b) solid var(--tone, var(--ink));
  color: var(--tone, var(--ink));
  background: var(--line2);
  background: color-mix(in srgb, var(--tone, var(--blue)) 14%, white);
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  text-transform: uppercase;
}

.row-main {
  display: block;
  min-width: 0;
}

.row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.row-from {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.row-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.row-date {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--grey);
  white-space: nowrap;
}

.thread-chip {
  padding: 0 6px;
  border: var(--b) solid var(--ink);
  border-radius: 999px;
  font-size: 10px;
  line-height: 1.5;
}

.row-subject,
.row-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-subject { margin-top: 1px; font-size: 14px; }
.row-preview { margin-top: 1px; font-size: 13px; color: var(--grey); }

.mail-row.unread .row-from,
.mail-row.unread .row-subject { font-weight: 700; }

.unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--blue);
  vertical-align: middle;
}

.row-actions {
  display: none;
  align-items: center;
  align-self: center;
  gap: 2px;
}
.mail-row:hover .row-actions,
.mail-row:focus-within .row-actions { display: flex; }
/* Gmail behaviour: the action strip replaces the date while hovering. */
.mail-row:hover .row-date,
.mail-row:focus-within .row-date { display: none; }

.row-actions .icon-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--grey);
}
.row-actions .icon-btn svg { width: 16px; height: 16px; }

.icon-btn.starred svg { fill: var(--yellow); }

/* ---------- Empty states ------------------------------------------------- */
.empty-state,
.reader-empty {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2px;
  padding: 48px 24px;
  text-align: center;
  color: var(--grey);
}
.empty-state { min-height: 50vh; }

.empty-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  border: var(--b) solid var(--line);
  border-radius: 12px;
  color: var(--grey);
  font-size: 24px;
  line-height: 1;
}
.empty-title {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}
.empty-sub { font-size: 13px; }

/* ---------- Reader pane -------------------------------------------------- */
.reader-pane {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0 24px 32px;
  background: var(--paper);
}

.reader-empty {
  flex: 1 1 auto;
  padding: 40px 0;
}

/* Never shrink below content: the pane is the scroller, not this box. */
.reader-body {
  flex: 1 0 auto;
  min-width: 0;
}

.reader-topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 0 12px;
  margin-bottom: 16px;
  background: var(--paper);
  border-bottom: var(--b) solid var(--ink);
}

.reader-back { display: none; flex: none; }

.reader-subject {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-disp);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -.015em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: anywhere;
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.thread-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  padding: 14px 16px;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
}
.msg-out {
  background: var(--blue-t);
  border-color: var(--blue-d);
}

.msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.msg-who {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.msg-from {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-to {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-date {
  margin-left: auto;
  flex: none;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--grey);
  white-space: nowrap;
}

.msg-body {
  margin: 12px 0 0;
  max-width: 68ch;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
}
.msg-body a { color: var(--blue-d); }

/* ---------- Reply box ---------------------------------------------------- */
.reply-box {
  margin-top: 16px;
  padding: 12px 16px 14px;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
}

.reply-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey);
}
/* Addresses are not shouted, even inside an uppercase micro-label row. */
.reply-identity {
  text-transform: none;
  letter-spacing: .02em;
  color: var(--ink);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-box textarea {
  width: 100%;
  min-height: 96px;
  padding: 10px;
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
  background: var(--card);
}
.reply-box textarea:focus { border-color: var(--blue); }

.reply-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.reply-status,
.compose-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--grey);
}
.reply-status[data-state="error"],
.compose-status[data-state="error"] { color: var(--red); }

/* ---------- Compose dialog ---------------------------------------------- */
.compose {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
.compose::backdrop { background: rgba(32, 33, 36, .45); }

.compose-form {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  overflow: hidden;
  background: var(--card);
  border: var(--b) solid var(--ink);
  border-radius: var(--r);
}

.compose-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: var(--b) solid var(--ink);
}
.compose-title {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.01em;
}

.compose-fields {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 16px 12px;
}

.compose-field { display: block; padding: 12px 0; }
.compose-field input {
  width: 100%;
  padding: 6px 0 4px;
  border: 0;
  border-bottom: var(--b) solid var(--line);
  background: none;
}
.compose-field input:focus { border-bottom-color: var(--blue); }
.compose-field:focus-within .field-label { color: var(--blue); }

/* The one control that keeps a box: the sending-address select. */
.compose-field select {
  width: 100%;
  padding: 6px 32px 6px 12px;
  border: var(--b) solid var(--line);
  border-radius: 999px;
  background-color: var(--card);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16'><path fill='%23202124' d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  appearance: none;
  -webkit-appearance: none;
}
.compose-field select:focus { border-color: var(--blue); }

.compose-fields textarea {
  width: 100%;
  min-height: 180px;
  padding: 10px 0 14px;
  border: 0;
  background: none;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
}

.compose-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

/* ---------- Mobile tab bar ---------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: var(--b) solid var(--ink);
}

.tabbar-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--ink);
  transition: background-color .12s ease;
}
.tabbar-btn:hover { background: var(--line2); }

.tabbar-fab {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: var(--b) solid var(--ink);
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(-50%, -50%);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tabbar-fab:hover {
  transform: translate(calc(-50% - 1px), calc(-50% - 1px));
  box-shadow: 4px 4px 0 var(--ink);
}
.tabbar-fab:active {
  transform: translate(calc(-50% + 2px), calc(-50% + 2px));
  box-shadow: none;
}

/* ---------- Scrim / toast ------------------------------------------------ */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(32, 33, 36, .35);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 100;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  max-width: calc(100vw - 32px);
  text-align: center;
  animation: toast-rise .16s ease-out;
}
@keyframes toast-rise {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Pre-JS view gating ------------------------------------------
   The inline boot script writes html[data-boot]; the views also carry the
   hidden attribute once JS takes over. Both must hold. */
html:not([data-boot]) .app-view { display: none; }
html[data-boot="app"] .auth-view { display: none; }
html[data-boot="auth"] .app-view { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */

/* ---------- <=1100px: rail goes off-canvas, panes switch ------------- */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 240px 1fr;
  }
  /* The rail is fixed here, so track 1 would otherwise be a dead 240px gutter:
     the panes span the grid and own the full width. */
  .list-pane { grid-column: 1 / -1; }
  .reader-pane {
    display: none;
    grid-column: 1 / -1;
  }

  /* One pane at a time; data-pane picks it. */
  .layout[data-pane="reader"] .list-pane { display: none; }
  .layout[data-pane="reader"] .reader-pane { display: flex; }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    z-index: 40;
    width: 280px;
    padding-left: calc(12px + env(safe-area-inset-left));
    transform: translateX(-105%);
    transition: transform .2s ease;
    border-right: var(--b) solid var(--ink);
  }
  .sidebar.open { transform: translateX(0); }

  .nav-toggle { display: grid; }
  .reader-back { display: grid; }
}

/* ---------- <=680px: single pane, bottom bar -------------------------- */
@media (max-width: 680px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    height: calc(100vh - var(--topbar-h) - var(--tabbar-h) - env(safe-area-inset-bottom));
    height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - env(safe-area-inset-bottom));
  }

  .topbar { gap: 4px; }
  .searchwrap { display: none; }
  .topbar.search-open .searchwrap {
    display: flex;
    position: fixed;
    inset: 8px 8px auto;
    max-width: none;
    z-index: 30;
  }

  .list-pane { border-right: 0; }
  .reader-pane { padding: 0 16px 32px; }

  .tabbar { display: flex; }

  .compose {
    width: calc(100vw - 16px);
    inset: auto 8px 8px;
    margin: 0;
    max-height: calc(100dvh - 24px - env(safe-area-inset-bottom));
  }

  .toast { bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); }

  .nav-note { display: none; }

  .mail-row { padding-right: 8px; }
  .row-actions .icon-btn { width: 28px; height: 28px; }
}

/* ---------- >=1101px: static three-pane --------------------------------- */
@media (min-width: 1101px) {
  .sidebar {
    position: static;
    transform: none;
    width: auto;
    border-right: var(--b) solid var(--ink);
  }
  .nav-toggle { display: grid; }
  .reader-back { display: none; }
  .tabbar { display: none; }
}

/* ---------- Print -------------------------------------------------------- */
@media print {
  @page { margin: 12mm; }

  body { background: #fff; }

  .topbar,
  .sidebar,
  .scrim,
  .tabbar,
  .toast,
  .list-pane,
  .reply-box,
  .compose,
  .reader-back,
  .reader-actions { display: none !important; }

  .layout {
    display: block;
    height: auto;
    overflow: visible;
  }

  .reader-pane {
    display: block;
    padding: 0;
    background: #fff;
    overflow: visible;
  }

  .reader-topbar {
    position: static;
    margin-bottom: 12px;
    border-bottom: 0;
  }

  .msg {
    break-inside: avoid;
    border-color: #202124;
    background: #fff;
  }

  .empty-mark { border-color: #DADCE0; }
}

/* ---------- Reduced motion ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
