:root {
  --ink: #1b2233;
  --ink-2: #3a4258;
  --muted: #687089;
  --faint: #9aa1b5;
  --paper: #f3f5fa;
  --panel: #ffffff;
  --line: #e2e6f0;
  --line-strong: #cfd5e3;
  --accent: #2f3fc8;
  --accent-ink: #ffffff;
  --accent-soft: #eaedfd;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --ok: #23824f;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Fraunces', Georgia, serif;
  --sidebar: 256px;
  --list: 400px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel); color: var(--ink); font-weight: 500; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--paper); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #2533b0; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-icon { width: 36px; padding: 0; border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-icon:hover { background: var(--paper); }
.btn-icon.on { color: #c88a00; }
.btn-link { border: 0; background: none; padding: 0; height: auto; color: var(--accent); font-weight: 500; cursor: pointer; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel);
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.error-text { color: var(--danger); font-size: 13.5px; margin: 0 0 12px; }
.muted { color: var(--muted); }

/* ---------- Sign-in / setup ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 380px; }
.gate .wordmark { margin-bottom: 28px; }
.gate h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; margin: 0 0 8px; }
.gate p.lead { color: var(--muted); margin: 0 0 24px; }
.gate .btn-primary { width: 100%; height: 42px; margin-top: 6px; }

.wordmark { display: flex; align-items: center; gap: 10px; font-family: var(--sans); font-weight: 600; font-size: 23px; letter-spacing: -.02em; color: var(--ink); }
.logo-mark { display: block; flex: none; }

/* ---------- App frame ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) var(--list) minmax(0, 1fr); grid-template-rows: 100dvh; height: 100dvh; overflow: hidden; }
.scrim { display: none; }

.sidebar { display: flex; flex-direction: column; min-height: 0; padding: 18px 0 12px; background: var(--paper); }
.sidebar .wordmark { padding: 0 20px 18px; }
.sidebar .compose-btn { margin: 0 16px 16px; height: 42px; }
.nav { display: flex; flex-direction: column; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 16px 0 20px; margin-right: 10px;
  border: 0; border-radius: 0 8px 8px 0; background: none; text-align: left; cursor: pointer;
  color: var(--ink-2); font-size: 14.5px;
}
.nav-item:hover { background: rgba(47, 63, 200, .06); }
.nav-item.active { background: var(--panel); color: var(--ink); font-weight: 600; }
.nav-item .count { margin-left: auto; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item.active .count { color: var(--ink); }
.nav-sep { height: 1px; background: var(--line); margin: 12px 20px; }
.nav-heading { display: flex; align-items: center; justify-content: space-between; padding: 4px 16px 6px 20px; font-size: 13px; color: var(--muted); }

/* The account tabs: a colored divider tab sticking out of the left edge */
.accounts-nav { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px; }
.acct-item { padding-left: 24px; }
.acct-item .tab {
  position: absolute; left: 0; top: 7px; bottom: 7px; width: 8px;
  border-radius: 0 4px 4px 0; background: var(--c);
  transition: width .15s ease;
}
.acct-item:hover .tab, .acct-item.active .tab { width: 12px; }
.acct-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.acct-item .warn { color: var(--danger); display: inline-flex; }
.acct-item.has-unread .name { font-weight: 600; color: var(--ink); }
.sidebar-foot { display: flex; flex-direction: column; padding: 8px 0 0; border-top: 1px solid var(--line); margin-top: 4px; }
.sidebar-foot .nav-item { height: 34px; font-size: 14px; }
.whoami { padding: 8px 20px 0; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Message list ---------- */
.list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.list-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 11px; color: var(--faint); }
.search input { padding-left: 36px; background: var(--paper); border-color: transparent; }
.list-title { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.list-title h2 { font-size: 16px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-title .sub { font-size: 13px; color: var(--muted); white-space: nowrap; }
.list-title .spacer { flex: 1; }
.menu-btn { display: none; }
.kind-tabs { display: flex; gap: 2px; margin: 10px 0 -2px -4px; }
.kind-tab { height: 30px; padding: 0 11px; border: 0; border-radius: 7px; background: none; color: var(--muted); font-size: 13.5px; font-weight: 500; cursor: pointer; }
.kind-tab:hover { background: var(--paper); color: var(--ink); }
.kind-tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.list-body { flex: 1; overflow-y: auto; }
.list-notice { padding: 10px 16px; font-size: 13px; color: var(--danger); background: var(--danger-soft); border-bottom: 1px solid var(--line); }

.row {
  position: relative; display: block; width: 100%;
  padding: 11px 16px 12px 22px;
  border: 0; border-bottom: 1px solid var(--line); background: var(--panel);
  text-align: left; cursor: pointer;
}
.row::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--c); opacity: .3;
}
.row.unread::before { opacity: 1; }
.row:hover { background: #f8f9fc; }
.row.selected { background: var(--accent-soft); }
.row-top { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; }
.row-acct { color: var(--c-ink, var(--muted)); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-date { margin-left: auto; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-from { font-size: 14.5px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.row.unread .row-from { font-weight: 600; color: var(--ink); }
.row-line { display: flex; gap: 6px; align-items: center; font-size: 13.5px; margin-top: 1px; }
.row-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--muted); }
.row-text b { font-weight: 500; color: var(--ink-2); }
.row.unread .row-text b { color: var(--ink); font-weight: 600; }
.row-icons { display: inline-flex; gap: 4px; margin-left: auto; color: var(--faint); }
.row-icons svg.i { width: 15px; height: 15px; }
.row-icons .star { color: #c88a00; fill: #f5c542; }
.list-more { padding: 14px 16px 24px; text-align: center; }

.empty { padding: 48px 28px; text-align: center; color: var(--muted); }
.empty h3 { font-family: var(--serif); font-weight: 600; font-size: 20px; color: var(--ink); margin: 0 0 6px; }
.empty p { margin: 0 0 16px; }
.loading { padding: 32px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Reading pane ---------- */
.reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.reader-bar { display: flex; align-items: center; gap: 2px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.reader-bar .spacer { flex: 1; }
.reader-bar .back { display: none; }
.reader-scroll { flex: 1; overflow-y: auto; }
.reader-inner { max-width: 860px; padding: 26px 36px 48px; }
.subject { font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 1.2; letter-spacing: -.01em; margin: 0 0 18px; overflow-wrap: anywhere; }
.acct-chip {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 16px; margin-bottom: 16px;
  border-radius: 6px; background: var(--paper); font-size: 13px; color: var(--ink-2);
}
.acct-chip::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: 6px 0 0 6px; background: var(--c); }
.meta { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 14px; align-items: baseline; margin-bottom: 18px; font-size: 14px; }
.meta .from { font-weight: 600; }
.meta .addr { color: var(--muted); font-weight: 400; }
.meta .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.meta .to { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.images-note { display: flex; gap: 10px; align-items: center; padding: 9px 12px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--muted); }
.mail-frame { width: 100%; border: 0; display: block; min-height: 120px; }
.mail-wrap { overflow-x: auto; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.att { display: inline-flex; align-items: center; gap: 8px; max-width: 260px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-size: 13px; }
.att:hover { background: var(--paper); }
.att .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .s { color: var(--muted); white-space: nowrap; }
.reply-row { display: flex; gap: 8px; margin-top: 26px; }
.reader-empty { flex: 1; display: grid; place-items: center; color: var(--faint); text-align: center; padding: 24px; }
.reader-empty .rack { display: flex; justify-content: center; margin-bottom: 14px; opacity: .85; }

/* ---------- Admin pages ---------- */
.page { grid-column: 2 / -1; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); }
.page-scroll { flex: 1; overflow-y: auto; }
.page-inner { max-width: 820px; padding: 28px 36px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.page-head h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; margin: 0; }
.page-head .spacer { flex: 1; }
.page-lead { color: var(--muted); margin: 0 0 24px; max-width: 60ch; }
.table { border-top: 1px solid var(--line); }
.trow { position: relative; display: flex; align-items: center; gap: 14px; padding: 14px 4px 14px 20px; border-bottom: 1px solid var(--line); }
.trow .swatch { position: absolute; left: 0; top: 12px; bottom: 12px; width: 6px; border-radius: 0 3px 3px 0; background: var(--c); }
.trow .main { flex: 1; min-width: 0; }
.trow .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow .t2 { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.trow .t2.err { color: var(--danger); }
.trow .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.ok-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 6px; vertical-align: 1px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; margin-left: 6px; vertical-align: 1px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(27, 34, 51, .38); }
.modal { width: 100%; max-width: 520px; max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--panel); border-radius: 14px; box-shadow: 0 24px 60px rgba(27, 34, 51, .25); }
.modal-head { display: flex; align-items: center; padding: 18px 20px 4px 24px; }
.modal-head h2 { font-family: var(--serif); font-weight: 600; font-size: 21px; margin: 0; flex: 1; }
.modal-body { padding: 12px 24px 8px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 24px 22px; }
.steps { margin: 0 0 16px; padding: 12px 14px 12px 34px; background: var(--paper); border-radius: 10px; font-size: 13.5px; color: var(--ink-2); }
.steps li { margin: 3px 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches label { position: relative; cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 28px; height: 28px; border-radius: 7px; background: var(--c); border: 2px solid transparent; box-shadow: inset 0 0 0 2px #fff; }
.swatches input:checked + span { border-color: var(--ink); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.checklist { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 0; }
.checklist label { position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 20px; font-size: 14px; cursor: pointer; }
.checklist label::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; width: 6px; border-radius: 0 3px 3px 0; background: var(--c); }
.radio-row { display: flex; gap: 18px; }
.radio-row label { display: flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.secret { display: flex; gap: 8px; align-items: center; padding: 12px 14px; margin: 6px 0 12px; background: var(--paper); border-radius: 10px; font-size: 18px; font-weight: 600; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.secret code { flex: 1; font-family: var(--sans); }

/* ---------- Compose ---------- */
.compose {
  position: fixed; right: 24px; bottom: 0; z-index: 40;
  width: 580px; max-width: calc(100vw - 48px); height: min(640px, calc(100dvh - 40px));
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 12px 12px 0 0; box-shadow: 0 18px 50px rgba(27, 34, 51, .22);
}
.compose-head { display: flex; align-items: center; padding: 10px 10px 10px 18px; border-bottom: 1px solid var(--line); }
.compose-head h2 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; }
.compose-fields { border-bottom: 1px solid var(--line); }
.cf { position: relative; display: flex; align-items: center; gap: 10px; padding: 0 16px 0 18px; border-bottom: 1px solid var(--line); min-height: 42px; }
.cf:last-child { border-bottom: 0; }
.cf > span { font-size: 13px; color: var(--muted); width: 52px; flex: none; }
.cf input, .cf select { flex: 1; min-width: 0; height: 40px; border: 0; background: transparent; }
.cf input:focus, .cf select:focus { outline: none; }
.cf:focus-within { background: #fafbfe; }
.cf.from::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 6px; border-radius: 0 3px 3px 0; background: var(--c); }
.compose textarea { flex: 1; width: 100%; border: 0; resize: none; padding: 14px 18px; line-height: 1.55; }
.compose textarea:focus { outline: none; }
.compose-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 6px; background: var(--paper); font-size: 12.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; }
.compose-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.compose-foot .spacer { flex: 1; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); }

/* ---------- Small screens ---------- */
@media (max-width: 1180px) {
  :root { --list: 340px; --sidebar: 232px; }
  .reader-inner { padding: 22px 26px 40px; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .input, .cf input, .cf select, .compose textarea { font-size: 16px; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; width: 286px; max-width: 86vw;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(27, 34, 51, .2);
  }
  .app.drawer-open .sidebar { transform: none; }
  .scrim { display: none; position: fixed; inset: 0; z-index: 29; background: rgba(27, 34, 51, .3); }
  .app.drawer-open .scrim { display: block; }
  .menu-btn { display: inline-flex; margin-left: -8px; }
  .list-pane { border: 0; height: 100dvh; }
  .reader { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .2s ease; }
  .app.show-reader .reader { transform: none; }
  .reader-bar .back { display: inline-flex; }
  .reader-inner { padding: 18px 18px 40px; }
  .subject { font-size: 22px; }
  .page { grid-column: 1; border: 0; height: 100dvh; }
  .page-inner { padding: 18px 18px 40px; }
  .page-head .menu-btn { display: inline-flex; }
  .trow { flex-wrap: wrap; }
  .trow .actions { width: 100%; justify-content: flex-start; }
  .compose { right: 0; width: 100vw; max-width: 100vw; height: 100dvh; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Google sign-in box on the Gmail accounts page */
.google-box { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin: 0 0 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.google-box .main { flex: 1; min-width: 0; }
.google-box .t1 { font-weight: 600; }
.google-box .t2 { font-size: 13px; color: var(--muted); }
a.btn { text-decoration: none; }
.google-box { flex-wrap: wrap; }

/* Groups of Gmail accounts in the sidebar */
.grp { margin-bottom: 4px; }
.grp-head { position: relative; display: flex; align-items: center; height: 32px; padding: 0 10px 0 8px; margin-right: 10px; border-radius: 0 8px 8px 0; }
.grp-head:hover { background: rgba(47, 63, 200, .06); }
.grp-head.active { background: var(--panel); }
.grp-head[draggable="true"] { cursor: grab; }
.grp-toggle { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; flex: none; }
.grp-toggle svg.i { width: 15px; height: 15px; transition: transform .15s ease; }
.grp.collapsed .grp-toggle svg.i { transform: rotate(-90deg); }
.grp-name { flex: 1; min-width: 0; height: 32px; padding: 0 4px; border: 0; background: none; text-align: left; font-size: 13.5px; font-weight: 600; color: var(--ink-2); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-head .count { font-size: 12.5px; color: var(--muted); margin-right: 2px; }
.grp-menu { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; opacity: 0; flex: none; }
.grp-head:hover .grp-menu, .grp-menu:focus-visible { opacity: 1; }
.grp-menu:hover { background: var(--paper); color: var(--ink); }
.grp.collapsed .grp-body { display: none; }
.grp .acct-item { padding-left: 38px; }
.grp-loose .acct-item { padding-left: 24px; }
.grp-head-loose { padding-left: 20px; }
.grp-loose-label { font-size: 12.5px; color: var(--muted); }
.grp-empty { margin: 2px 10px 4px 38px; padding: 6px 8px; border: 1px dashed var(--line-strong); border-radius: 8px; font-size: 12.5px; color: var(--faint); }
.acct-item[draggable="true"] { cursor: grab; }
.dragging { opacity: .4; }
.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.drop-into { background: var(--accent-soft) !important; box-shadow: inset 0 0 0 1px var(--accent); }
@media (hover: none) { .grp-menu { opacity: 1; } }
