/* postbox — mobile-first, two breakpoints, no framework. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #14171a;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c2129;
    --text: #e6edf3;
    --muted: #8b949e;
    --border: #262c36;
    --accent: #58a6ff;
    --accent-soft: #17233b;
    --warn: #e3a008;
    --warn-soft: #2a2113;
    --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1rem env(safe-area-inset-bottom);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 44rem; margin: 0 auto; padding-bottom: 3rem; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.25rem; margin: 0 0 .35rem; line-height: 1.3; }
code { font-family: var(--mono); font-size: .8125rem; }
.muted { color: var(--muted); }
.small { font-size: .8125rem; }

/* ---- top bar & tabs ---- */

.topbar {
  max-width: 44rem;
  margin: 0 auto;
  padding: .875rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand { display: flex; align-items: center; gap: .625rem; color: inherit; min-width: 0; }
.brand-text { font-weight: 650; letter-spacing: -.01em; min-width: 0; }
.brand-text em {
  display: block;
  font: 400 .75rem/1.2 var(--mono);
  font-style: normal;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  flex: none;
  width: 2rem; height: 2rem;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .9375rem;
}
.brand-mark.big { width: 3rem; height: 3rem; font-size: 1.375rem; border-radius: 14px; }

.back { font-size: .9375rem; font-weight: 550; }

.logout button {
  background: none; border: 0; padding: .25rem;
  color: var(--muted); font: inherit; font-size: .875rem; cursor: pointer;
}
.logout button:hover { color: var(--text); }

.tabs {
  max-width: 44rem;
  margin: 0 auto .875rem;
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid var(--border);
}
.tabs a {
  padding: .5rem .75rem;
  color: var(--muted);
  font-size: .9375rem;
  font-weight: 550;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs b {
  font-weight: 600; font-size: .75rem;
  padding: .0625rem .3125rem; border-radius: 999px;
  background: var(--border); color: var(--muted);
}
.tabs b.warn { background: var(--warn-soft); color: var(--warn); }

/* ---- forms ---- */

.new, .search { margin-bottom: .875rem; }

.new {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem;
  box-shadow: var(--shadow);
}
.new-row { display: grid; gap: .625rem; }

.field { display: block; min-width: 0; }
.field > span {
  display: block;
  font-size: .75rem; font-weight: 600;
  color: var(--muted);
  margin-bottom: .25rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input[type=text], input[type=search], input[type=password], .field input {
  width: 100%;
  padding: .5rem .625rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: .9375rem;
}
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* The @domain suffix sits inside the field so the address reads as one unit. */
.addr-input { display: flex; align-items: stretch; }
.addr-input input {
  border-radius: 9px 0 0 9px;
  border-right: 0;
  font-family: var(--mono);
  font-size: .875rem;
  min-width: 0;
}
.addr-input em {
  display: flex; align-items: center;
  padding: 0 .625rem;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 9px 9px 0;
  background: var(--border);
  color: var(--muted);
  font: 400 .8125rem var(--mono);
  font-style: normal;
  white-space: nowrap;
}

button[type=submit], .addr-actions button {
  padding: .5rem .875rem;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font: inherit; font-size: .9375rem; font-weight: 550;
  cursor: pointer;
}
button[type=submit]:hover { filter: brightness(1.08); }

.addr-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .875rem 0; }
.addr-actions button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}
.addr-actions button:hover { background: var(--surface-2); }
button.danger { color: var(--danger); }

.search input { box-shadow: var(--shadow); }

/* ---- address pill (copy target) ---- */

.addr-pill {
  display: inline-block;
  max-width: 100%;
  padding: .375rem .625rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 500 .875rem var(--mono);
  cursor: pointer;
  overflow-wrap: anywhere;
  text-align: left;
}
.addr-pill:hover { border-style: solid; }
.addr-pill.copied { color: #fff; background: var(--accent); border-color: var(--accent); }

.created {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: .875rem;
  margin-bottom: .875rem;
}
.created p { margin: 0 0 .5rem; font-size: .875rem; font-weight: 550; }

/* ---- address list ---- */

.addresses, .messages, .attachments { list-style: none; margin: 0; padding: 0; }

.addresses li { margin-bottom: .5rem; }
.addresses a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  box-shadow: var(--shadow);
}
.addresses a:hover { border-color: var(--accent); }

.avatar {
  flex: none;
  width: 2.25rem; height: 2.25rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-size: .9375rem;
}
.avatar.big { width: 3rem; height: 3rem; font-size: 1.25rem; }

.who { flex: 1; min-width: 0; }
.who b { display: block; font-weight: 600; font-size: .9375rem; }
.who code, .who .note {
  display: block;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.who .note { font-size: .8125rem; font-style: italic; }

.meta {
  flex: none;
  display: flex; flex-direction: column; align-items: flex-end;
  gap: .125rem;
  font-size: .75rem;
  color: var(--muted);
  text-align: right;
}
.badge {
  min-width: 1.25rem;
  padding: .0625rem .3125rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  text-align: center;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: .9375rem;
}
.stats { text-align: center; font-size: .75rem; color: var(--muted); margin-top: 1.5rem; }

/* ---- address detail ---- */

.addr-head { display: flex; gap: .875rem; align-items: flex-start; margin-bottom: .875rem; }
.addr-head > div { min-width: 0; flex: 1; }
.addr-head p { margin: .5rem 0 0; font-size: .8125rem; }

.warn-banner {
  margin-top: .625rem !important;
  padding: .5rem .625rem;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: .8125rem;
}

.editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem .875rem;
  box-shadow: var(--shadow);
}
.editor summary { cursor: pointer; font-size: .875rem; font-weight: 550; color: var(--muted); }
.editor form { display: grid; gap: .625rem; margin-top: .75rem; }
.editor button { justify-self: start; }

/* ---- message list & reader ---- */

.messages li { margin-bottom: .375rem; }
.messages a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .125rem .75rem;
  padding: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: inherit;
  box-shadow: var(--shadow);
}
.messages a:hover { border-color: var(--accent); }
.messages .from { font-size: .8125rem; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages .subject { grid-column: 1 / -1; font-size: .9375rem; }
.messages .when { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.messages .unseen .subject, .messages li.unseen .subject { font-weight: 650; }
.messages li.unseen a { border-left: 3px solid var(--accent); }

.msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.msg h1 { font-size: 1.125rem; overflow-wrap: anywhere; }
.msg-meta {
  display: flex; flex-wrap: wrap; gap: .25rem .625rem;
  margin: 0 0 1rem;
  padding-bottom: .875rem;
  border-bottom: 1px solid var(--border);
  font-size: .8125rem;
  color: var(--muted);
}
.msg-meta b { color: var(--text); }
.msg-meta code { overflow-wrap: anywhere; }

.attachments li {
  padding: .5rem .625rem;
  margin-bottom: .375rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  overflow-wrap: anywhere;
}

.body-tools {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .625rem;
  margin-bottom: .625rem;
  font-size: .8125rem;
}

.body-frame {
  width: 100%;
  min-height: 12rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.body-text, .plain pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: .875rem/1.6 var(--mono);
  margin: 0;
  padding: .875rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.plain { margin-top: .875rem; }
.plain summary { cursor: pointer; font-size: .875rem; color: var(--muted); margin-bottom: .5rem; }

.expired {
  padding: .875rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: .875rem;
}

.msg-delete { margin-top: 1.25rem; padding-top: .875rem; border-top: 1px solid var(--border); }
.msg-delete button {
  background: none; border: 1px solid var(--border); border-radius: 9px;
  padding: .4375rem .75rem; font: inherit; font-size: .875rem; cursor: pointer;
}

/* ---- login ---- */

.login { display: grid; place-items: center; min-height: 100svh; }
.login-card {
  width: min(22rem, 100%);
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin: .875rem 0 .125rem; font-size: 1.375rem; }
.login-card p { margin: 0 0 1.25rem; font-size: .8125rem; font-family: var(--mono); }
.login-card form { display: grid; gap: .625rem; }
.login-card .brand-mark { margin: 0 auto; }
.error {
  padding: .5rem;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--danger);
  font-size: .8125rem !important;
  font-family: system-ui, sans-serif !important;
}

/* ---- wider screens ---- */

@media (min-width: 40rem) {
  body { padding-inline: 1.5rem; }
  h1 { font-size: 1.5rem; }
  .new-row { grid-template-columns: 1fr 1.4fr auto; align-items: end; gap: .75rem; }
  .new-row button { height: 2.375rem; }
  .messages a { grid-template-columns: 12rem 1fr auto; align-items: baseline; }
  .messages .subject { grid-column: 2; }
  .msg { padding: 1.5rem; }
}
