:root {
  --bg: #f6f7f9;
  --panel: #fff;
  --text: #1c2024;
  --muted: #5f6873;
  --line: #dde1e6;
  --accent: #2457d6;
  --danger: #b42318;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181c; --panel: #1d2126; --text: #e6e8eb; --muted: #9aa3ad; --line: #30363d; --accent: #7aa2ff; --danger: #ff7b72; }
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.15rem; margin: 0 0 .6rem; }
button, input, select { font: inherit; color: inherit; }
button {
  padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.danger { color: var(--danger); }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
input, select { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); min-width: 0; }

header { padding: 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.address-row, .custom-row, .view-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
#address {
  flex: 1 1 16rem; padding: .45rem .6rem; border: 1px dashed var(--line); border-radius: 6px;
  font-size: 1.05rem; overflow-wrap: anywhere; user-select: all;
}
.custom-row { margin-top: .6rem; }
.custom-row label { color: var(--muted); }
.custom-row input { flex: 1 1 8rem; }
.status { margin: .6rem 0 0; color: var(--muted); font-size: .9rem; }
.live.on { color: #1a7f37; }
.error { margin: .5rem 0 0; color: var(--danger); }

main { display: grid; grid-template-columns: minmax(16rem, 22rem) 1fr; min-height: calc(100vh - 11rem); }
.list-pane { border-right: 1px solid var(--line); overflow-y: auto; }
#messages { list-style: none; margin: 0; padding: 0; }
.msg {
  display: grid; grid-template-columns: 1fr auto; gap: .1rem .5rem; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .7rem 1rem; background: transparent;
}
#messages li.active .msg { background: var(--panel); box-shadow: inset 3px 0 var(--accent); }
.from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { color: var(--muted); font-size: .85rem; }
.subject { grid-column: 1 / -1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip { font-size: .85rem; }
.empty { padding: 1rem; color: var(--muted); }

.view-pane { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.view-head { padding: 1rem; border-bottom: 1px solid var(--line); }
.view-head h2 { margin: 0 0 .5rem; font-size: 1.1rem; overflow-wrap: anywhere; }
.back { display: none; margin-bottom: .6rem; }
dl { display: grid; grid-template-columns: auto 1fr; gap: .15rem .75rem; margin: 0 0 .75rem; font-size: .9rem; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
.attachments { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-wrap: wrap; gap: .4rem; }
button.link { color: var(--accent); }
#v-html { flex: 1; width: 100%; min-height: 60vh; border: 0; background: #fff; }
#v-text { flex: 1; margin: 0; padding: 1rem; white-space: pre-wrap; overflow-wrap: anywhere; font: .9rem/1.5 ui-monospace, monospace; }
[hidden] { display: none !important; }

@media (max-width: 720px) {
  main { grid-template-columns: 1fr; min-height: 0; }
  .list-pane { border-right: 0; }
  body.viewing .list-pane { display: none; }
  .back { display: inline-block; }
}
