/* Mailroom app shell. Phone first; three panes from 900px. No inline styles anywhere (CSP). */
:root {
  color-scheme: light dark;
  --bg: #f5f4ed;
  --surface: #fffdf7;
  --surface-2: #eeede4;
  --ink: #132824;
  --muted: #5d6b66;
  --line: #dddbcf;
  --accent: #d4eb8d;
  --accent-ink: #132824;
  --bar: #132824;
  --bar-ink: #f5f4ed;
  --bar-muted: #a9b7b1;
  --mine: #2f7d4f;
  --archive: #5d6b66;
  --danger: #a8322d;
  --focus: #6a8f1f;
  --shadow: 0 6px 24px rgb(19 40 36 / 0.18);
  --bar-h: 56px;
  --tab-h: 64px;
  --radius: 12px;
  --font:
    system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1412;
    --surface: #121e1b;
    --surface-2: #1b2a26;
    --ink: #e6ede5;
    --muted: #9caba4;
    --line: #26362f;
    --accent: #c5e07a;
    --accent-ink: #0e1a17;
    --bar: #0e1a17;
    --bar-ink: #e6ede5;
    --bar-muted: #8fa199;
    --mine: #57b27b;
    --archive: #7f8f88;
    --danger: #e0756e;
    --focus: #c5e07a;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.5);
  }
}
[hidden] {
  display: none !important;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
/* The page itself never scrolls or bounces: only the list, message and sheets scroll inside. */
html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
/* 16px inputs: mobile browsers do not zoom into the field. */
input,
select,
textarea {
  font-size: 16px;
}
button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 14px;
  min-height: 40px;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  font-weight: 600;
}
button.plain {
  border-color: transparent;
  background: transparent;
}
button.secondary {
  background: transparent;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
input:not([type='checkbox']),
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
}
label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  font-size: 14px;
  color: var(--muted);
}
label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}
h3 {
  margin: 28px 0 8px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.footnote {
  font-size: 13px;
  color: var(--muted);
}
#signature {
  white-space: pre-line;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
svg .dot {
  fill: currentColor;
  stroke: none;
}

/* App chrome: fixed bars, no double-tap zoom delay. */
#appbar,
#tabbar,
#action-bar,
.fab,
.sheet-head {
  touch-action: manipulation;
  user-select: none;
}
#appbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0
    max(6px, env(safe-area-inset-left));
  background: var(--bar);
  color: var(--bar-ink);
  z-index: 5;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: inherit;
  flex: none;
}
#title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-left: 10px;
}
#desk-title {
  font-size: 20px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#title-count {
  font-size: 13px;
  color: var(--bar-muted);
  white-space: nowrap;
}
#search-form {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 6px;
}
#search {
  background: rgb(255 255 255 / 0.12);
  border-color: transparent;
  color: var(--bar-ink);
  height: 40px;
}
#search::placeholder {
  color: var(--bar-muted);
}
#appbar.searching #title-wrap,
#appbar.searching #search-toggle {
  display: none;
}
#banner {
  flex: none;
  padding: 6px 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}
#tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 5;
}
#tabbar button {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  min-height: var(--tab-h);
  padding: 4px 0;
}
#tabbar button[aria-current='page'] {
  color: var(--ink);
}
#tabbar button[aria-current='page'] svg {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 14px;
  width: 52px;
  padding: 0 14px;
}
.tab-label {
  font-size: 12px;
  font-weight: 600;
}
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
#tabbar .badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 8px);
}

/* Workspace: list underneath, message panel slides over it on narrow screens. */
#workspace,
#signin {
  flex: 1;
  min-height: 0;
}
#workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
#sidebar {
  display: none;
}
#list-pane,
#detail-body,
#signin,
.sheet-body,
#more-sheet,
#menu {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#list-pane {
  min-height: 0;
  background: var(--surface);
  padding-bottom: 96px;
}
#more {
  display: block;
  margin: 12px auto;
}
.row {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  touch-action: pan-y;
}
.swipe {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  font-weight: 700;
  color: #fff;
  visibility: hidden;
}
.row[data-swipe] .swipe {
  visibility: visible;
}
.row[data-swipe='right'] .swipe {
  background: var(--mine);
}
.row[data-swipe='left'] .swipe {
  background: var(--archive);
}
.row[data-swipe='right'] .swipe-archive,
.row[data-swipe='left'] .swipe-mine {
  visibility: hidden;
}
.message {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px 10px;
  width: 100%;
  min-height: 0;
  padding: 12px 16px 12px 26px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  text-align: left;
  transition: transform 0.18s ease;
}
.message.dragging {
  transition: none;
}
.message.active {
  background: var(--surface-2);
}
.message.unread::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 20px;
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--mine);
}
.message .sender,
.message .subject,
.message .snippet {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.message .sender {
  font-weight: 500;
}
.message.unread .sender,
.message.unread .subject {
  font-weight: 700;
}
.message .date {
  font-size: 13px;
  color: var(--muted);
}
.message .subject,
.message .snippet {
  grid-column: 1 / -1;
}
.message .snippet {
  font-size: 14px;
  color: var(--muted);
}
.chip {
  justify-self: start;
  grid-column: 1 / -1;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}
.skeleton {
  padding: 14px 16px 14px 26px;
  border-bottom: 1px solid var(--line);
}
.skeleton span {
  display: block;
  height: 12px;
  margin: 7px 0;
  border-radius: 6px;
  background: var(--surface-2);
  animation: pulse 1.2s ease-in-out infinite;
}
.skeleton span:nth-child(1) {
  width: 40%;
}
.skeleton span:nth-child(2) {
  width: 75%;
}
.skeleton span:nth-child(3) {
  width: 90%;
}
@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}
.empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 72px 24px;
  text-align: center;
  color: var(--muted);
}
.empty svg {
  width: 48px;
  height: 48px;
  stroke-width: 1.4;
}
.empty h2 {
  font-size: 18px;
  color: var(--ink);
}

#detail {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform 0.22s ease,
    visibility 0s linear 0.22s;
}
#detail.open {
  transform: none;
  visibility: visible;
  transition: transform 0.22s ease;
}
#detail-body {
  flex: 1;
  min-height: 0;
  padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}
#detail-body h2 {
  font-size: 21px;
  margin: 8px 0 6px;
  overflow-wrap: anywhere;
}
.meta {
  font-size: 13px;
  color: var(--muted);
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}
.button-row input {
  width: auto;
  flex: 1 1 180px;
}
#detail iframe {
  display: block;
  width: 100%;
  height: 70dvh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.attachment {
  display: block;
  margin: 8px 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.code {
  display: grid;
  gap: 4px;
  margin: 12px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
}
.code button {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: transparent;
  border-color: var(--accent-ink);
  color: var(--accent-ink);
}
#action-bar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
#action-bar button {
  padding: 6px 2px;
  font-size: 13px;
  font-weight: 600;
  min-height: 44px;
}
#action-bar .hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  text-align: center;
  color: var(--muted);
}
/* Reading on a phone: the action bar replaces the tab bar. */
body.reading #tabbar,
body.reading .fab {
  display: none;
}
.fab {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: 16px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}

#signin {
  padding: 32px max(20px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}
.signin-inner {
  max-width: 440px;
  margin: 0 auto;
}
.hero {
  font-size: 40px;
  line-height: 1.05;
  margin: 8px 0 12px;
}
.lede {
  color: var(--muted);
}
.notice {
  font-weight: 650;
}
#signin form button.primary {
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
}
#signin .secondary {
  width: 100%;
  margin-top: 16px;
}
#pin,
#new-pin {
  letter-spacing: 0.3em;
}

/* Toasts sit above the bars and never move the layout. */
#status,
#update {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#status {
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
}
#status button {
  min-height: 32px;
  padding: 4px 10px;
  background: transparent;
  border-color: var(--bg);
  color: var(--bg);
}
#update {
  top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px);
}
#update button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  font-weight: 650;
}

/* Sheets and popovers (native <dialog>; Android back closes them via history). */
dialog {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgb(0 0 0 / 0.4);
}
dialog.sheet[open] {
  display: flex;
  flex-direction: column;
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
}
.sheet-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0
    max(8px, env(safe-area-inset-left));
  background: var(--bar);
  color: var(--bar-ink);
}
.sheet-head h2 {
  flex: 1;
  font-size: 18px;
}
.sheet-head .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.sheet-body {
  flex: 1;
  min-height: 0;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}
.sheet-body article {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.sheet-body details {
  flex-basis: 100%;
}
.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.toggles label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  color: var(--ink);
}
#audit {
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#menu {
  margin: calc(var(--bar-h) + env(safe-area-inset-top) - 4px) max(8px, env(safe-area-inset-right))
    auto auto;
  width: min(300px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--bar-h) - 24px);
  padding: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  text-align: left;
}
button.menu-item:hover,
.menu-item:focus-within {
  background: var(--surface-2);
}
.menu-item select {
  width: auto;
  max-width: 60%;
  padding: 6px 8px;
}
#more-sheet {
  margin: auto 0 0;
  width: 100vw;
  max-width: 100vw;
  max-height: 80dvh;
  padding: 6px max(8px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  border-radius: 18px 18px 0 0;
}
.grabber {
  width: 40px;
  height: 4px;
  margin: 6px auto 10px;
  border-radius: 2px;
  background: var(--line);
}
.menu-item .badge {
  flex: none;
}

/* Wide: Fold inner screen in landscape, tablets, desktop. Sidebar + list + reading pane. */
@media (min-width: 900px) {
  #workspace {
    grid-template-columns: 232px minmax(320px, 400px) minmax(0, 1fr);
  }
  #sidebar {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 10px;
    border-right: 1px solid var(--line);
    background: var(--bg);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #compose-wide {
    margin-bottom: 12px;
  }
  #admin-wide {
    margin-top: auto;
  }
  #list-pane {
    border-right: 1px solid var(--line);
    padding-bottom: 24px;
  }
  #detail,
  #detail.open {
    position: static;
    transform: none;
    visibility: visible;
    transition: none;
  }
  #tabbar,
  .fab,
  #back {
    display: none !important;
  }
  #status {
    bottom: 24px;
  }
  dialog.sheet[open] {
    width: min(760px, calc(100vw - 48px));
    height: auto;
    max-height: calc(100dvh - 48px);
    margin: auto;
    border-radius: 16px;
    overflow: hidden;
  }
  #more-sheet {
    width: 360px;
    margin: auto;
    border-radius: 16px;
  }
}
.side-desk {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  text-align: left;
  font-weight: 550;
}
.side-desk[aria-current='page'] {
  background: var(--accent);
  color: var(--accent-ink);
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
