/* Marlpost. Marl is chalky grey-green clay: the palette is that chalk, a wet-clay green for structure and one
   deep lagoon ink for anything you can press. Mail is read in a serif, the interface speaks in a sans. */
:root {
  --chalk: #f4f7f3;
  --paper: #ffffff;
  --clay: #dfe6df;
  --marl: #5f7368;
  --ink: #16211d;
  --lagoon: #0e5a63;
  --lagoon-press: #0a444b;
  --postmark: #a8321f;
  --ui: "Avenir Next", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --letter: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --chalk: #141b18;
    --paper: #1b2420;
    --clay: #2c3833;
    --marl: #9db0a5;
    --ink: #e9efea;
    --lagoon: #6cc3cc;
    --lagoon-press: #8fd5dc;
    --postmark: #f08a73;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--chalk); color: var(--ink); font: 15px/1.45 var(--ui); }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 0.95rem; font-weight: 600; margin-top: 1.4rem; }

.wordmark { font: 600 1.35rem/1 var(--letter); letter-spacing: 0.01em; color: var(--lagoon); }

button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--clay); background: var(--paper); border-radius: 6px; padding: 0.45rem 0.85rem; cursor: pointer;
}
button:hover { border-color: var(--marl); }
button.primary { background: var(--lagoon); border-color: var(--lagoon); color: var(--chalk); font-weight: 600; }
button.primary:hover { background: var(--lagoon-press); border-color: var(--lagoon-press); }
button.link { border: 0; background: none; padding: 0; color: var(--lagoon); text-decoration: underline; text-underline-offset: 2px; }
button.icon { border: 0; background: none; padding: 0.2rem 0.5rem; font-size: 1.2rem; }
button:disabled { opacity: 0.55; cursor: progress; }
:focus-visible { outline: 2px solid var(--lagoon); outline-offset: 2px; }

label { display: block; margin: 0.9rem 0 0.3rem; font-size: 0.85rem; color: var(--marl); }
input:not([type="file"]), textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--clay); border-radius: 6px; background: var(--paper);
}
textarea { font-family: var(--letter); font-size: 1rem; line-height: 1.55; resize: vertical; }
.form-error { color: var(--postmark); min-height: 1.4em; margin-top: 0.7rem; font-size: 0.9rem; }

/* Signed out */
#gate { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.gate-card { width: min(26rem, 100%); }
.gate-card h1 { font: 500 1.9rem/1.15 var(--letter); margin: 2.2rem 0 1.2rem; }
.address-field { display: flex; align-items: center; border: 1px solid var(--clay); border-radius: 6px; background: var(--paper); }
.address-field:focus-within { outline: 2px solid var(--lagoon); outline-offset: 2px; }
.address-field input { border: 0; background: none; outline: none; flex: 1; min-width: 0; }
.address-field span { padding-right: 0.7rem; color: var(--marl); }
#gate-form .primary { width: 100%; margin-top: 0.4rem; padding: 0.65rem; }
.gate-switch { margin-top: 1.4rem; color: var(--marl); }

/* Signed in: rail, list, reader */
#app { height: 100%; display: grid; grid-template-columns: 15rem minmax(18rem, 24rem) 1fr; }
.rail { display: flex; flex-direction: column; gap: 1.2rem; padding: 1.4rem 1.1rem; border-right: 1px solid var(--clay); }
.folders { list-style: none; margin: 0; padding: 0; }
.folders button { width: 100%; text-align: left; border: 0; background: none; padding: 0.5rem 0.6rem; display: flex; justify-content: space-between; }
.folders button[aria-current="true"] { background: var(--clay); font-weight: 600; }
.count { color: var(--postmark); font-weight: 600; font-variant-numeric: tabular-nums; }
.me { margin-top: auto; display: grid; gap: 0.35rem; justify-items: start; }
.me-address { font: 500 1rem/1.3 var(--letter); overflow-wrap: anywhere; }
.me-usage { color: var(--marl); font-size: 0.82rem; }

.list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--clay); background: var(--paper); }
.list-head { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem 0.4rem; align-items: center; padding: 1.2rem 1rem 0.8rem; }
.list-head #search { grid-column: 1 / -1; }
#messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#messages button {
  display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.6rem; width: 100%; text-align: left;
  border: 0; border-top: 1px solid var(--clay); border-left: 3px solid transparent; border-radius: 0; padding: 0.7rem 1rem 0.75rem 0.8rem;
}
#messages button[aria-current="true"] { background: var(--chalk); }
/* The postmark edge is the one unread signal: no dots, no bold-everything. */
#messages button.unread { border-left-color: var(--postmark); }
#messages .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#messages .unread .who, #messages .unread .subject { font-weight: 600; }
#messages .when { color: var(--marl); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
#messages .subject, #messages .snippet { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#messages .snippet { color: var(--marl); font-size: 0.88rem; }
.empty { color: var(--marl); padding: 2rem 1rem; }
.more { margin: 0.8rem 1rem 1.2rem; align-self: start; }

.reader { min-width: 0; overflow-y: auto; padding: 1.4rem clamp(1rem, 4vw, 3rem) 3rem; }
.reader-head { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: start; }
.reader-head h2 { flex: 1 1 16rem; font: 500 1.6rem/1.2 var(--letter); overflow-wrap: anywhere; }
.reader-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.envelope { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.9rem; margin: 1.1rem 0 1.3rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--clay); font-size: 0.92rem; }
.envelope dt { color: var(--marl); }
.envelope dd { margin: 0; overflow-wrap: anywhere; }
.notice { background: var(--clay); border-radius: 6px; padding: 0.5rem 0.75rem; margin-bottom: 1rem; font-size: 0.9rem; }
#r-text { font: 1.05rem/1.6 var(--letter); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch; margin: 0; }
#r-html { width: 100%; height: 60vh; border: 1px solid var(--clay); border-radius: 6px; background: #fff; }
.attachments { list-style: none; padding: 0; margin: 1.6rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.attachments small { color: var(--marl); margin-left: 0.4rem; }

.back { display: none; }

dialog { border: 1px solid var(--clay); border-radius: 10px; background: var(--chalk); color: var(--ink); width: min(40rem, calc(100vw - 2rem)); padding: 1.5rem; }
dialog::backdrop { background: rgb(22 33 29 / 0.45); }
.dialog-actions { display: flex; justify-content: end; gap: 0.5rem; margin-top: 1rem; }
#s-token { display: block; margin-top: 0.7rem; font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; overflow-wrap: anywhere; user-select: all; }
#settings p { color: var(--marl); margin: 0.3rem 0 0.7rem; }
#s-save-name { margin-top: 0.6rem; }

#toast { position: fixed; left: 50%; bottom: 1.5rem; translate: -50% 0; background: var(--ink); color: var(--chalk); padding: 0.6rem 1rem; border-radius: 6px; max-width: calc(100vw - 2rem); }

/* Narrow screens: one pane at a time. */
@media (max-width: 62rem) {
  #app { grid-template-columns: 1fr; }
  .rail, .reader { display: none; }
  .back { display: inline-block; }
  #app.show-rail .rail { display: flex; position: fixed; inset: 0 20% 0 0; z-index: 2; background: var(--chalk); box-shadow: 0 0 0 100vmax rgb(22 33 29 / 0.45); }
  #app.show-reader .list { display: none; }
  #app.show-reader .reader { display: block; }
}
