/* Mail web UI. Mobile-first, dark, Geist Sans. */
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #000;
  --surface: #0a0a0a;
  --raised: #141414;
  --hover: #171717;
  --border: #1f1f1f;
  --border-strong: #2e2e2e;
  --text: #ededed;
  --text-2: #a1a1a1;
  --text-3: #6b6b6b;
  --accent: #7aa7ff;
  --danger: #ff6b6b;
  --danger-bg: #2a1212;
  --radius: 12px;
  --gutter: 16px;
  --top: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Geist, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: 'ss01';
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.noscript { color: var(--text-2); text-align: center; padding: 40px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--text-2);
  display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--raised); color: var(--text);
  font-weight: 500; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--text); color: #000; border-color: var(--text); }
.btn.primary:hover { background: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--text); background: var(--raised); }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--raised); color: var(--text); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; }

.field {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  outline: none;
}
.field::placeholder { color: var(--text-3); }
.field:focus { border-color: #4a4a4a; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.login-card { width: 100%; max-width: 360px; }
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: -.01em; }
.wordmark .mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--border-strong); color: var(--text-2);
}
.wordmark .mark svg { width: 15px; height: 15px; }
.login h1 { font-size: 26px; font-weight: 600; letter-spacing: -.025em; margin: 40px 0 8px; }
.login p { color: var(--text-2); margin: 0 0 28px; }
.login form { display: grid; gap: 12px; }
.login .btn { height: 44px; }
.login .em { color: var(--text); }
.login .fine { color: var(--text-3); font-size: 13px; margin-top: 20px; }
.check-icon {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--border-strong); color: var(--text); margin-top: 40px;
}
.check-icon svg { width: 20px; height: 20px; }
.login .check-icon + h1 { margin-top: 20px; }

/* ---------- Shell ---------- */
.shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.panes { flex: 1; min-height: 0; display: flex; }
.pane-list, .pane-detail { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-list { flex: 1; }
.pane-detail { flex: 1; background: var(--bg); }
.shell[data-view="list"] .pane-detail { display: none; }
.shell[data-view="detail"] .pane-list { display: none; }

.topbar {
  height: var(--top); flex: none; display: flex; align-items: center; gap: 4px;
  padding: 0 calc(var(--gutter) - 8px); padding-top: env(safe-area-inset-top);
  box-sizing: content-box; border-bottom: 1px solid var(--border);
}
.topbar .grow { flex: 1; min-width: 0; }
.switcher {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%;
  height: 40px; padding: 0 10px 0 8px; border: 0; border-radius: 10px; background: transparent; text-align: left;
}
.switcher:hover { background: var(--raised); }
.switcher .label { font-weight: 600; font-size: 15px; flex: none; }
.switcher .addr { color: var(--text-2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher .chev { color: var(--text-3); flex: none; width: 14px; height: 14px; }

.searchbar { padding: 12px var(--gutter); flex: none; }
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-3); pointer-events: none; }
.search .field { padding-left: 38px; padding-right: 38px; height: 40px; background: var(--surface); border-color: var(--border); }
.search .clear { position: absolute; right: 2px; top: 0; height: 40px; width: 36px; }

/* ---------- Thread list ---------- */
.list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.list-head { padding: 4px var(--gutter) 8px; color: var(--text-3); font-size: 12px; letter-spacing: .02em; }
.row {
  display: grid; grid-template-columns: 10px 1fr auto; column-gap: 10px; row-gap: 2px;
  padding: 14px var(--gutter) 14px calc(var(--gutter) - 4px); text-decoration: none; color: inherit;
  border-bottom: 1px solid var(--border);
}
.row:hover { background: var(--surface); }
.row[aria-current="true"] { background: var(--raised); }
.row .dot { grid-row: 1; align-self: center; width: 6px; height: 6px; border-radius: 50%; justify-self: center; }
.row.unread .dot { background: var(--accent); }
.row .from { grid-column: 2; font-size: 15px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .from { color: var(--text); font-weight: 600; }
.row .count { color: var(--text-3); font-weight: 400; margin-left: 6px; font-size: 13px; }
.row .time { grid-column: 3; font-size: 12px; color: var(--text-3); align-self: center; font-variant-numeric: tabular-nums; }
.row.unread .time { color: var(--text-2); }
.row .subject { grid-column: 2 / 4; font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .subject { color: var(--text); font-weight: 500; }
.row .snippet { grid-column: 2 / 4; font-size: 13px; color: var(--text-3); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.45; }
.row .clip { width: 12px; height: 12px; color: var(--text-3); vertical-align: -1px; margin-left: 6px; }

.state { padding: 64px 32px; text-align: center; color: var(--text-3); }
.state .title { color: var(--text-2); font-weight: 500; margin-bottom: 4px; }
.state .btn { margin-top: 16px; }
.state.error .title { color: var(--text); }
.more { padding: 20px; display: flex; justify-content: center; color: var(--text-3); font-size: 13px; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 5;
  height: 52px; padding: 0 20px 0 18px; border-radius: 16px; border: 0;
  background: var(--text); color: #000; font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.6); text-decoration: none;
}
.fab svg { width: 18px; height: 18px; }
.shell[data-view="detail"] .fab { display: none; }

/* ---------- Detail: thread ---------- */
.detail-top { justify-content: space-between; }
.detail-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.thread { max-width: 820px; margin: 0 auto; padding: 20px var(--gutter) 40px; }
.thread h1 { font-size: 22px; line-height: 1.3; font-weight: 600; letter-spacing: -.02em; margin: 4px 0 6px; word-break: break-word; }
.thread .meta { color: var(--text-3); font-size: 13px; margin-bottom: 20px; }
.msg { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.msg-head {
  width: 100%; display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center;
  padding: 14px; border: 0; background: transparent; text-align: left; color: inherit;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--border-strong); color: var(--text-2);
  font-size: 13px; font-weight: 600; text-transform: uppercase;
}
.msg.out .avatar { background: #1c1c1c; color: var(--text); }
.msg-who { min-width: 0; }
.msg-who .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who .name .email { font-weight: 400; color: var(--text-3); margin-left: 6px; }
.msg-who .sub { color: var(--text-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { color: var(--text-3); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.msg-body { padding: 0 14px 16px; }
.msg-text { font-family: inherit; white-space: pre-wrap; word-break: break-word; color: var(--text); font-size: 15px; line-height: 1.6; margin: 0; padding-top: 2px; }
.msg-text .quote { color: var(--text-3); }
.msg-frame { width: 100%; height: 520px; border: 0; border-radius: 10px; background: #fff; display: block; }
.msg-tools { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.msg-tools .btn { height: 32px; padding: 0 12px; font-size: 13px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); margin-top: 10px; }
.status.failed { color: var(--danger); }
.atts { display: grid; gap: 8px; margin-top: 14px; }
.att {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--raised); text-decoration: none; min-width: 0;
}
.att:hover { border-color: #444; }
.att svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.att .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.att .sz { color: var(--text-3); font-size: 12px; flex: none; }

.reply-bar { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- Composer ---------- */
.composer { max-width: 820px; margin: 0 auto; padding: 8px var(--gutter) 32px; }
.composer.inline { padding: 0; margin-top: 16px; }
.composer .card { border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.composer .line { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border); min-height: 48px; }
.composer .line label { color: var(--text-3); font-size: 14px; width: 56px; flex: none; }
.composer .line input, .composer .line select {
  flex: 1; min-width: 0; height: 46px; border: 0; background: transparent; outline: none; color: var(--text); font-size: 15px;
}
.composer .line select { appearance: none; -webkit-appearance: none; cursor: pointer; }
.composer .line .toggle { flex: none; height: 30px; padding: 0 8px; font-size: 13px; }
.composer textarea {
  display: block; width: 100%; min-height: 260px; padding: 14px; border: 0; background: transparent;
  outline: none; resize: vertical; color: var(--text); font-size: 15px; line-height: 1.6;
}
.composer.inline textarea { min-height: 160px; }
.composer .actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.composer .actions .grow { flex: 1; }
.composer .hint { color: var(--text-3); font-size: 12px; }
.composer h2 { font-size: 20px; font-weight: 600; letter-spacing: -.02em; margin: 12px 0 16px; }

.banner {
  border: 1px solid #4a1f1f; background: var(--danger-bg); color: #ffd6d6;
  border-radius: 10px; padding: 12px 14px; margin-top: 12px; font-size: 14px;
}
.banner strong { color: #fff; font-weight: 600; display: block; margin-bottom: 2px; }
.banner.ok { border-color: var(--border-strong); background: var(--raised); color: var(--text-2); }

.placeholder { flex: 1; display: grid; place-items: center; color: var(--text-3); text-align: center; padding: 32px; }
.placeholder svg { width: 28px; height: 28px; margin-bottom: 10px; color: #3a3a3a; }

/* ---------- Mailbox sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; animation: fade .15s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 80vh; overflow-y: auto;
  background: var(--surface); border-top: 1px solid var(--border-strong); border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(12px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 12px 8px; font-size: 12px; color: var(--text-3); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.mb {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border: 0; border-radius: 10px;
  background: transparent; text-align: left; color: var(--text);
}
.mb:hover { background: var(--raised); }
.mb[aria-current="true"] { background: var(--raised); }
.mb .a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.mb .n { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.mb .off { color: var(--text-3); font-size: 12px; }
.mb .tick { width: 16px; height: 16px; color: var(--text); flex: none; }
.mb .tick.none { visibility: hidden; }
.sheet h3.gap { margin-top: 14px; }
.sheet .sep { height: 1px; background: var(--border); margin: 8px 4px; }
.sheet .who { padding: 8px 12px; color: var(--text-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: #000; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.6); animation: fade .15s;
}

/* ---------- Desktop: two panes ---------- */
@media (min-width: 900px) {
  :root { --gutter: 20px; }
  .shell[data-view] .pane-list, .shell[data-view] .pane-detail { display: flex; }
  .pane-list { flex: none; width: 400px; border-right: 1px solid var(--border); }
  .detail-top .back { display: none; }
  .fab { position: static; height: 36px; padding: 0 14px; border-radius: 10px; font-size: 14px; box-shadow: none; }
  .shell[data-view="detail"] .fab { display: inline-flex; }
  .fab svg { width: 16px; height: 16px; }
  .list { padding-bottom: 24px; }
  .thread { padding: 32px 40px 56px; }
  .thread h1 { font-size: 24px; }
  .composer { padding: 16px 40px 40px; }
  .sheet {
    left: 12px; right: auto; bottom: auto; top: calc(var(--top) + 4px); width: 360px; max-height: 70vh;
    border: 1px solid var(--border-strong); border-radius: 14px; padding: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.7);
    animation: fade .12s ease-out;
  }
  .sheet .grab { display: none; }
  .scrim { background: transparent; }
}
@media (min-width: 1280px) { .pane-list { width: 440px; } }
