/* memoratu-mail webmail — one stylesheet, no framework, no build step.
 *
 * Light and dark both, because a mailbox is read at both ends of the day and a
 * forced theme is the kind of small wrongness that makes a tool feel borrowed.
 */

:root {
  --bg: #ffffff;
  --bg-sunk: #f5f6f8;
  --bg-raised: #ffffff;
  --fg: #16181d;
  --fg-muted: #656b76;
  --line: #e2e5ea;
  --accent: #2b5fd9;
  --accent-fg: #ffffff;
  --warn-bg: #fff6e5;
  --warn-line: #e0a93a;
  --error: #b4231f;
  --danger: #b4231f;
  --radius: 8px;
  --rail-w: 15rem;
  --list-w: 24rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --bg-sunk: #0f1115;
    --bg-raised: #1c1f26;
    --fg: #e7e9ee;
    --fg-muted: #9aa1ad;
    --line: #2b2f38;
    --accent: #6f95ef;
    --accent-fg: #0f1115;
    --warn-bg: #2e2515;
    --warn-line: #a9802c;
    --error: #ff8a84;
    --danger: #ff8a84;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.muted { color: var(--fg-muted); }
.small { font-size: 0.85em; }
.pad { padding: 1rem; }
.spacer { flex: 1 1 auto; }
.error { color: var(--error); }

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

button {
  font: inherit;
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[disabled] { opacity: 0.55; cursor: not-allowed; }

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

.icon-button {
  border: none;
  background: none;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.3rem 0.5rem;
}

input, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

label {
  display: block;
  margin: 0.75rem 0 0.2rem;
  font-size: 0.85em;
  color: var(--fg-muted);
}

/* ------------------------------ sign in ----------------------------- */

#signin-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sunk);
  padding: 1rem;
}

.card {
  width: 100%;
  max-width: 22rem;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
}
.card h1 { margin: 0; font-size: 1.25rem; }
.card button[type="submit"] { width: 100%; margin-top: 1.1rem; }
.card .small { margin-bottom: 0; }

/* ------------------------------ layout ------------------------------ */

#main-screen { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
  flex: 0 0 auto;
}
.brand { font-size: 0.95rem; }
#menu-button { display: none; }

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
  min-height: 0;
}

.rail {
  border-right: 1px solid var(--line);
  background: var(--bg-sunk);
  padding: 0.6rem;
  overflow-y: auto;
}
.rail-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem;
  text-align: left;
}
.rail-item:hover { background: var(--bg-raised); }
.rail-item.is-active { background: var(--accent); color: var(--accent-fg); }
.rail-label { flex: 1 1 auto; }
.rail-count { font-size: 0.8em; opacity: 0.8; font-variant-numeric: tabular-nums; }
.rail-sep { height: 1px; background: var(--line); margin: 0.6rem 0.3rem; }
.rail-attention .rail-label { color: var(--warn-line); }
.rail-attention.is-active .rail-label { color: var(--accent-fg); }
.rail-note { margin: 1rem 0.3rem 0; }

.list-pane, .reader-pane {
  min-height: 0;
  overflow-y: auto;
}
.list-pane { border-right: 1px solid var(--line); }

.pane-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.pane-head h2 { margin: 0; font-size: 1rem; flex: 1 1 auto; }

/* --------------------------- message list --------------------------- */

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

.message-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 0.6rem 0.9rem;
}
.message-row:hover { background: var(--bg-sunk); }
.message-row.is-selected { background: var(--bg-sunk); box-shadow: inset 3px 0 0 var(--accent); }

.row-top { display: flex; gap: 0.5rem; align-items: baseline; }
.row-from { font-weight: 600; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-when { font-size: 0.8em; color: var(--fg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-to { font-size: 0.8em; color: var(--fg-muted); }
.row-badges { display: flex; gap: 0.35rem; margin-top: 0.15rem; }

.badge {
  font-size: 0.7em;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  color: var(--fg-muted);
}
.badge-warn { border-color: var(--warn-line); color: var(--warn-line); }

.more { display: block; width: calc(100% - 1.8rem); margin: 0.9rem; }

/* ------------------------------ reader ------------------------------ */

.reader-head { padding: 1rem 1.1rem 0; }
.reader-head h2 { margin: 0 0 0.6rem; font-size: 1.15rem; overflow-wrap: anywhere; }

.reader-meta { font-size: 0.9em; display: grid; gap: 0.15rem; }
.reader-meta .k { color: var(--fg-muted); display: inline-block; min-width: 4.5rem; }
.reader-meta span { overflow-wrap: anywhere; }

.reader-actions { display: flex; gap: 0.5rem; margin: 0.9rem 0; }

.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin: 0.9rem 0;
}
.warn ul { margin: 0.35rem 0 0.35rem 1.1rem; padding: 0; }
.warn p { margin: 0.35rem 0 0; }

.body {
  margin: 0;
  padding: 1rem 1.1rem 1.5rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
}

.attachments { padding: 0 1.1rem 1.5rem; }
.attachments h3 { font-size: 0.9rem; margin: 0 0 0.4rem; }
.attachments ul { list-style: none; margin: 0; padding: 0; }
.attachments li { padding: 0.3rem 0; border-top: 1px solid var(--line); }
.attachments a { color: var(--accent); overflow-wrap: anywhere; }

/* ------------------------------ compose ----------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.compose {
  position: fixed;
  z-index: 11;
  right: 1.5rem;
  bottom: 0;
  width: min(42rem, calc(100vw - 3rem));
  max-height: min(90vh, 46rem);
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
}

.compose-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.compose-head h2 { margin: 0; font-size: 0.95rem; }

.compose-body { padding: 0.2rem 0.9rem 0.9rem; overflow-y: auto; flex: 1 1 auto; }

.compose-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--line);
}
.compose-foot .error { flex: 1 1 100%; margin: 0; }

/* ------------------------------ narrow ------------------------------ */
/* One breakpoint, because a mailbox is read on a phone and three columns are
 * not a phone layout. The rail slides over; the reader covers the list. */

@media (max-width: 60rem) {
  #menu-button { display: block; }

  .layout { grid-template-columns: 1fr; }

  .rail {
    position: fixed;
    z-index: 9;
    top: 3rem;
    bottom: 0;
    left: 0;
    width: var(--rail-w);
    transform: translateX(-100%);
    transition: transform 0.15s ease-out;
  }
  .rail.is-open { transform: translateX(0); }

  .list-pane { border-right: none; }
  .list-pane.is-hidden-narrow { display: none; }

  .reader-pane { display: none; }
  .reader-pane.is-open-narrow { display: block; }

  .compose {
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }
}

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