/* STR Mail — built on the Industry design system (/_ds/…/styles.css): steel accent on a light
   technical ground, Barlow over Barlow Condensed, square hairline frames. Tokens only. */

:root {
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --rail-w: 232px;
  --list-w: 400px;
  --muted: color-mix(in srgb, var(--color-text) 58%, transparent);
  --faint: color-mix(in srgb, var(--color-text) 8%, transparent);
  --hover: color-mix(in srgb, var(--color-text) 5%, transparent);
  --paper: #fff;
}

html, body, #app { height: 100%; }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.boot { display: grid; place-items: center; height: 100%; font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

.mono-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--color-accent-700); }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }

.btn { white-space: nowrap; }
.btn.btn-primary.blueprint > .corner { color: color-mix(in srgb, var(--color-text) 55%, transparent); }
.btn-icon { color: var(--color-text); border-color: transparent; }
.btn-icon:hover { background: var(--hover); }
.btn-icon:active { background: var(--faint); }
.btn-icon[aria-pressed="true"] { color: var(--color-accent-700); }
.btn-quiet { border-color: transparent; color: var(--color-accent-700); font-family: var(--font-body); font-weight: 500; }
.btn-quiet:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }
.btn-danger { color: #8f2d2d; }

/* ───────────────────────────────────────────────────────────── sign in */

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow: auto; }
.login-card { width: min(380px, 100%); padding: 32px 28px 28px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 34px; margin: 4px 0 0; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; }
.login-card .btn-primary { margin-top: 6px; padding-block: 10px; font-size: 15px; }
.form-error { color: #8f2d2d; font-size: 13px; min-height: 1.2em; margin: 0; }

/* ──────────────────────────────────────────────────────────── layout */

.app { display: grid; grid-template-columns: var(--rail-w) var(--list-w) minmax(0, 1fr); height: var(--app-height, 100dvh); box-sizing: border-box; }
.mobile-nav, .mobile-identity, .mobile-install, .drawer-close { display: none; }
.installed [data-install-mail] { display: none; }
.install-btn { white-space: normal; }
.install-dialog { width: min(380px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--color-divider); background: var(--color-bg); color: var(--color-text); }
.install-dialog::backdrop { background: #0006; }
.install-dialog h2 { margin: 0 0 16px; }
.install-dialog p { font-size: 16px; line-height: 1.6; }
.install-dialog button { min-height: 44px; width: 100%; }
#connection-status { position: fixed; z-index: 60; top: 0; left: 0; right: 0; padding: 12px max(16px, env(safe-area-inset-left)); background: var(--color-accent-900); color: white; font-size: 14px; text-align: center; }

.rail { display: flex; flex-direction: column; gap: 18px; padding: 18px 14px 14px; border-right: 1px solid var(--color-divider); min-height: 0; }
.brand { display: flex; align-items: baseline; gap: 8px; padding: 0 6px; }
.brand b { font-family: var(--font-heading); font-weight: 600; font-size: 20px; letter-spacing: 0.04em; }
.brand span { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-accent-700); }
.business-host { margin: -10px 6px 0; font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.compose-btn { margin: 4px 6px 0; padding-block: 10px; font-size: 15px; }

.folders { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }
.folder { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; cursor: pointer; text-align: left; font-size: 15px; border-left: 2px solid transparent; }
.folder:hover { background: var(--hover); }
.folder[aria-current="true"] { background: var(--color-accent-100); border-left-color: var(--color-accent); color: var(--color-accent-800); font-weight: 500; }
.folder .count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--color-accent-700); }
.folder .count.zero { visibility: hidden; }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px 6px 0; border-top: 1px solid var(--color-divider); }
.whoami { font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.whoami b { display: block; font-weight: 500; }
.whoami span { color: var(--muted); }
.rail-actions { display: flex; gap: 6px; }

/* ─────────────────────────────────────────────────────────────── list */

.list-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--color-divider); }
.list-head { display: flex; flex-direction: column; gap: 10px; padding: 16px 16px 12px; border-bottom: 1px solid var(--color-divider); }
.list-title { display: flex; align-items: center; gap: 8px; }
.list-title h2 { font-size: 26px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 34px; background: var(--paper); }

.bulk { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--color-divider); background: var(--color-accent-100); }
.bulk .mono-label { margin: 0 auto 0 6px; }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.row { position: relative; display: grid; grid-template-columns: 22px minmax(0, 1fr) 28px; gap: 4px 8px; align-items: start; padding: 11px 10px 11px 12px; border-bottom: 1px solid var(--faint); cursor: pointer; border-left: 2px solid transparent; }
.row:hover { background: var(--hover); }
.row[aria-selected="true"] { background: var(--color-accent-100); border-left-color: var(--color-accent); }
.row.checked { background: color-mix(in srgb, var(--color-accent) 8%, transparent); }
.row-check { margin: 3px 0 0; width: 15px; height: 15px; accent-color: var(--color-accent); cursor: pointer; }
.row-main { min-width: 0; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-from { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.row-date { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.row-subject { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-snippet { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-marks { display: inline-flex; gap: 4px; color: var(--muted); align-self: center; }
.row.unread .row-from, .row.unread .row-subject { font-weight: 700; }
.row.unread::before { content: ""; position: absolute; left: 4px; top: 17px; width: 5px; height: 5px; background: var(--color-accent); }
.row .star { width: 28px; height: 28px; border: 0; background: none; padding: 0; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.row .star:hover { color: var(--color-accent-700); }
.row .star.on { color: var(--color-accent-700); }
.star.on .icon { fill: currentColor; }
.list-empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 14px; }
.list-more { display: flex; justify-content: center; padding: 14px; }

/* ───────────────────────────────────────────────────────────── reader */

.reader-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.reader-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.reader-empty .blueprint { padding: 28px 34px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--color-divider); flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar .sep { width: 1px; height: 22px; background: var(--color-divider); margin: 0 6px; }
.back-btn { display: none; }

.reader-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.reader { max-width: 940px; margin: 0 auto; padding: 22px clamp(16px, 3vw, 36px) 48px; }
.reader h1 { font-size: 30px; margin: 0 0 16px; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 2px 12px; align-items: start; margin-bottom: 18px; }
.avatar { grid-row: span 3; width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--color-divider); font-family: var(--font-heading); font-weight: 600; font-size: 18px; color: var(--color-accent-700); background: var(--color-accent-100); }
.meta-from { font-size: 15px; overflow-wrap: anywhere; }
.meta-from b { font-weight: 600; }
.meta-from span { color: var(--muted); }
.meta-date { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; text-align: right; }
.meta-to { grid-column: 2 / 4; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.meta-to b { font-weight: 500; color: var(--color-text); }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 14px; font-size: 13px; border: 1px solid var(--color-divider); background: var(--paper); }
.notice .icon { margin-top: 1px; color: var(--color-accent-700); }
.notice.warn { border-color: color-mix(in srgb, #8f2d2d 35%, transparent); background: color-mix(in srgb, #8f2d2d 5%, var(--paper)); }
.notice.warn .icon { color: #8f2d2d; }
.notice p { margin: 0; }
.notice .btn { margin-left: auto; padding: 3px 10px; font-size: 13px; }

.body-frame { width: 100%; border: 1px solid var(--color-divider); background: var(--paper); display: block; min-height: 120px; }
.text-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.6; padding: 18px 20px; border: 1px solid var(--color-divider); background: var(--paper); }
.text-body .quote { color: var(--muted); }

.attachments { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.attachment { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--color-divider); background: var(--paper); color: inherit; text-decoration: none; max-width: 100%; font-size: 13px; }
.attachment:hover { border-color: var(--color-accent); }
.attachment .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.attachment .size { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.quick-reply { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }

/* ──────────────────────────────────────────────────────────── compose */

.compose { position: fixed; right: 24px; bottom: 0; width: min(620px, calc(100vw - 48px)); height: min(640px, calc(100dvh - 48px)); display: flex; flex-direction: column; background: var(--color-bg); border: 1px solid var(--color-divider); box-shadow: var(--shadow-lg); z-index: 20; }
.compose-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--color-divider); background: var(--color-accent-900); color: var(--color-bg); }
.compose-head .mono-label { color: var(--color-accent-200); flex: 1; }
.compose-head .btn-icon { color: var(--color-bg); }
.compose-head .btn-icon:hover { background: color-mix(in srgb, #fff 12%, transparent); }
.compose-fields { display: flex; flex-direction: column; border-bottom: 1px solid var(--color-divider); }
.compose-body { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.compose-body textarea { min-height: 140px; flex-shrink: 0; }
.cfield { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--faint); }
.cfield:last-child { border-bottom: 0; }
.cfield label { font-size: 13px; color: var(--muted); width: 52px; flex: none; }
.cfield input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 15px; padding: 10px 0; color: var(--color-text); outline: none; }
.cfield .btn-quiet { padding: 3px 6px; font-size: 13px; }
.compose textarea { flex: 1; resize: none; border: 0; padding: 14px 16px; font: inherit; font-size: 15px; line-height: 1.6; background: var(--paper); color: var(--color-text); outline: none; }
.compose-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; }
.compose-atts:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border: 1px solid var(--color-divider); font-size: 13px; background: var(--paper); max-width: 100%; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip .size { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.chip button { border: 0; background: none; width: 22px; height: 22px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.chip button:hover { color: var(--color-text); background: var(--hover); }
.compose-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.compose-foot .form-error { flex: 1; min-width: 0; }
.compose-send { padding: 8px 20px; font-size: 15px; }

.suggest { position: absolute; left: 76px; right: 12px; top: 100%; z-index: 5; margin: 0; padding: 4px 0; list-style: none; background: var(--color-bg); border: 1px solid var(--color-divider); box-shadow: var(--shadow-md); }
.suggest li { padding: 7px 12px; font-size: 14px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li span { color: var(--muted); }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--color-accent-100); }

/* ─────────────────────────────────────────────────────────── addresses */

.addresses { display: flex; flex-direction: column; gap: 4px; min-height: 0; overflow-y: auto; }
.rail-label { padding: 0 10px 2px; }
.folder.address { font-size: 13px; padding-block: 6px; }
.address-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-filter { display: flex; align-items: center; gap: 8px; margin-top: -2px; }
.list-filter .filter-address { font-size: 14px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-filter .btn-icon { width: 28px; height: 28px; }
.row-via { display: inline-block; max-width: 55%; margin-right: 8px; padding: 0 6px; vertical-align: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 10px; line-height: 17px; letter-spacing: 0.02em; color: var(--color-accent-800); background: var(--color-accent-100); }
.cfield select { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 15px; padding: 10px 0; color: var(--color-text); outline: none; cursor: pointer; }
.cfield select:focus-visible { outline: 2px solid var(--color-accent); outline-offset: -2px; }

.settings { display: flex; flex-direction: column; gap: 14px; }
.identity { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.identity-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; overflow-wrap: anywhere; }
.identity-head b { font-weight: 600; }

/* ───────────────────────────────────────────────────────────── dialogs */

.dialog-backdrop { z-index: 30; }
.dialog.sheet { background: var(--color-bg); width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; }
.dialog.sheet.wide { width: min(900px, 100%); }
.dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog h3 { font-size: 15px; margin: 8px 0 0; letter-spacing: 0.02em; }
.source { margin: 0; max-height: 65vh; overflow: auto; padding: 12px; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--paper); border: 1px solid var(--color-divider); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 0; }
.keys dt { font-family: var(--font-mono); font-size: 12px; color: var(--color-accent-700); }
.keys dd { margin: 0; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; background: var(--color-accent-900); color: var(--color-bg); font-size: 14px; box-shadow: var(--shadow-lg); pointer-events: auto; max-width: calc(100vw - 32px); }
.toast button { border: 0; background: none; color: var(--color-accent-200); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer; padding: 2px 4px; }

/* ──────────────────────────────────────────────────────────── narrow */

@media (max-width: 1180px) {
  :root { --rail-w: 208px; --list-w: 340px; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .login { height: var(--app-height, 100dvh); min-height: 0; box-sizing: border-box; padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  input, textarea, select, .input, .cfield input, .cfield select, .compose textarea { font-size: 16px; }
  button, .btn { touch-action: manipulation; }
  .btn-icon { min-width: 44px; min-height: 44px; }
  .folder, .folder.address { min-height: 48px; }
  .list-filter .btn-icon { width: 44px; height: 44px; }
  .mobile-identity { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; min-width: 0; padding: 0 4px; }
  .mobile-identity b { font-family: var(--font-heading); font-size: 18px; font-weight: 600; }
  .mobile-install { display: inline-flex; min-height: 44px; padding: 8px 12px; font-size: 14px; }
  .mobile-identity span { font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); position: fixed; inset: auto 0 0; z-index: 22; padding: 4px max(8px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: var(--color-bg); border-top: 1px solid var(--color-divider); }
  .mobile-nav button { min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
  .mobile-nav button[aria-current="page"] { color: var(--color-accent-800); background: var(--color-accent-100); }
  .mobile-nav .mobile-compose { color: var(--color-accent-800); font-weight: 600; }
  .mobile-nav .icon { width: 22px; height: 22px; }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(280px, 84vw); z-index: 25; background: var(--color-bg); transform: translateX(-102%); transition: transform 0.18s ease, visibility 0.18s; visibility: hidden; }
  .rail { padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); padding-left: max(14px, env(safe-area-inset-left)); box-sizing: border-box; overflow-y: auto; }
  .brand { justify-content: space-between; }
  .drawer-close { display: inline-flex; }
  .app.drawer .rail { transform: none; visibility: visible; box-shadow: var(--shadow-lg); }
  .scrim { position: fixed; inset: 0; z-index: 24; background: color-mix(in srgb, var(--color-neutral-900) 40%, transparent); }
  .menu-btn, .back-btn { display: inline-flex; }
  .list-pane { border-right: 0; }
  .app.reading .list-pane { display: none; }
  .app:not(.reading) .reader-pane { display: none; }
  .list-head { padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .list-title h2 { font-size: 28px; }
  .row { padding: 12px 8px; min-height: 88px; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 4px; }
  .row-select { display: flex; align-items: flex-start; justify-content: center; width: 44px; min-height: 44px; padding-top: 8px; cursor: pointer; }
  .row .star { width: 44px; height: 44px; }
  .row-subject { font-size: 16px; }
  .row-snippet { line-height: 1.5; }
  .row input[type="checkbox"] { width: 20px; height: 20px; }
  .reader { padding: 18px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
  .reader-scroll { overflow-x: hidden; }
  .text-body { padding: 16px; font-size: 16px; }
  .reader h1 { font-size: 25px; }
  .compose { top: var(--app-top, 0px); left: 0; right: 0; bottom: auto; width: 100%; height: var(--app-height, 100dvh); border: 0; z-index: 35; }
  .compose-head { padding-top: max(8px, env(safe-area-inset-top)); flex-shrink: 0; }
  .compose-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); flex-shrink: 0; flex-wrap: wrap; }
  .compose-foot .form-error:not(:empty) { flex-basis: 100%; order: -1; }
  .compose-send { min-height: 44px; }
  .cfield { min-height: 48px; flex-shrink: 0; }
  .cfield .btn-quiet { min-width: 44px; min-height: 44px; }
  .compose-fields { flex-shrink: 0; }
  .compose textarea { min-height: 140px; }
  .toolbar { padding: max(6px, env(safe-area-inset-top)) 8px 6px; }
  .toolbar .sep, .toolbar .source-btn { display: none; }
  .meta { grid-template-columns: 40px minmax(0, 1fr); }
  .meta-date { grid-column: 2; grid-row: 2; text-align: left; }
  .meta-to { grid-column: 2; }
  .avatar { grid-row: span 3; }
  .quick-reply .btn { min-height: 44px; }
  .dialog-backdrop { z-index: 40; padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom)); }
  .dialog.sheet { max-height: calc(var(--app-height, 100dvh) - 32px); }
  #toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .offline .list-head { padding-top: calc(48px + env(safe-area-inset-top)); }
  .offline .compose-head { padding-top: calc(48px + env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  .rail { transition: none; }
}
