/*
 * The whole stylesheet. External, never inline: `style-src 'self'` with no
 * exceptions is what lets the CSP live in a static CloudFront Response Headers
 * Policy. docs/05-recipient-app.md#content-security-policy
 *
 * No @import, no remote font, no tracking pixel dressed as a background image.
 * `img-src 'self' data:` would block them anyway.
 */

:root {
  --text: #14181d;
  --muted: #5b6672;
  --bg: #ffffff;
  --surface: #f4f6f8;
  --rule: #dde3e9;
  --accent: #1a56db;
  --accent-text: #ffffff;
  --focus: #1a56db;
  --error: #b42318;
  --badge: #b54708;
  --badge-bg: #fff4e5;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e7ebef;
    --muted: #9aa6b2;
    --bg: #12161a;
    --surface: #1a2027;
    --rule: #2a323a;
    --accent: #7aa2f7;
    --accent-text: #0b1020;
    --focus: #7aa2f7;
    --error: #f97066;
    --badge: #fdb022;
    --badge-bg: #2a2010;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: relative;
  max-width: 46rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 6rem;
}

/* The `hidden` attribute must win over any display rule below. */
[hidden] {
  display: none !important;
}

/* Visible focus rings, never `outline: none`. docs/05-recipient-app.md#accessibility */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- site header ------------------------------------------------------------ */

.site {
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
}

.site h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ---- type ------------------------------------------------------------------------- */

h2 {
  font-size: 1.15rem;
  margin: 2rem 0 0.75rem;
}

h3 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.5rem;
}

h4,
h5 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

p {
  margin: 0 0 1rem;
}

.lede {
  font-size: 1.1rem;
}

.muted,
.help {
  color: var(--muted);
}

.error {
  color: var(--error);
}

a {
  color: var(--accent);
}

/* ---- controls ---------------------------------------------------------------------- */

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.375rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--muted);
}

button:disabled {
  cursor: default;
  opacity: 0.6;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0;
}

.field {
  margin: 1rem 0;
}

.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.field-row input {
  flex: 1 1 16rem;
}

input[type="text"],
input[type="password"],
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  width: 100%;
  max-width: 100%;
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

input[type="file"] {
  font: inherit;
  max-width: 100%;
}

/* ---- conversation header ------------------------------------------------------------ */

.conversation-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.5rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
}

.conversation-header p {
  margin: 0;
}

.conversation-header .sent {
  color: var(--muted);
}

.conversation-header .header-actions {
  margin-left: auto;
}

/* ---- rendered markdown ------------------------------------------------------------- */

.body,
.message-body {
  overflow-wrap: anywhere;
}

.body pre,
.message-body pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
}

.body code,
.message-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.body p code,
.body li code,
.message-body p code,
.message-body li code {
  background: var(--surface);
  border-radius: 0.25rem;
  padding: 0.1em 0.3em;
}

.body blockquote,
.message-body blockquote {
  margin: 1rem 0;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
}

.body hr,
.message-body hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2rem 0;
}

.body table,
.message-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  display: block;
  overflow-x: auto;
}

.body th,
.body td,
.message-body th,
.message-body td {
  border: 1px solid var(--rule);
  padding: 0.375rem 0.625rem;
  text-align: left;
  vertical-align: top;
}

.body th,
.message-body th {
  background: var(--surface);
}

.align-left {
  text-align: left;
}

.align-center {
  text-align: center;
}

.align-right {
  text-align: right;
}

figure {
  margin: 1.5rem 0;
}

figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

figure.video video {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  border-radius: 0.375rem;
}

figure.image img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.375rem;
}

.video-notice {
  margin: 0.5rem 0 0;
  color: var(--error);
}

/* ---- roster, thread ------------------------------------------------------------------- */

.roster ul {
  margin: 0;
  padding-left: 1.25rem;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
}

.message-me {
  background: var(--surface);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.message-meta .author {
  color: var(--text);
  font-weight: 600;
}

.message-body > :last-child {
  margin-bottom: 0;
}

.reply-text {
  white-space: pre-wrap;
}

/* ---- attachments drawer ----------------------------------------------------------------- */

.drawer {
  margin-top: 2rem;
  border: 1px solid var(--rule);
  border-radius: 0.5rem;
}

.drawer-toggle {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-weight: 600;
}

.drawer-toggle[aria-expanded="true"] {
  border-bottom: 1px solid var(--rule);
  border-radius: 0.5rem 0.5rem 0 0;
}

.drawer-panel {
  padding: 0.75rem 1rem;
}

.attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.attachment {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule);
}

.attachment:last-child {
  border-bottom: 0;
}

.attachment-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.attachment-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.attachment-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.badge {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.1rem 0.5rem;
  border-radius: 1rem;
  background: var(--badge-bg);
  color: var(--badge);
}

/* ---- composer ------------------------------------------------------------------------------ */

.composer {
  margin-top: 2rem;
}

.composer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.file-label {
  color: var(--accent);
  cursor: pointer;
}

.notice {
  min-height: 1.6em;
  margin: 0.5rem 0 0;
}

.frozen {
  margin-top: 2rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 0.375rem;
  color: var(--muted);
}

/* ---- watermark ------------------------------------------------------------------------------ */

/* Tiles the recipient address and session timestamp diagonally across the
   viewport. Fixed to the viewport, above the content, and `pointer-events:
   none` so it never intercepts a click. Rotation is on a class, never an
   inline style. This is deterrence, not enforcement. */
.watermark {
  position: fixed;
  inset: -20vh -20vw;
  z-index: 10;
  pointer-events: none;
  user-select: none;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 12vh;
  align-items: center;
  justify-items: center;
  opacity: 0.09;
}

.watermark-tile {
  transform: rotate(-30deg);
  font-size: 0.8rem;
  white-space: nowrap;
  color: var(--text);
}

@media print {
  .watermark {
    opacity: 0.2;
  }
}
