:root {
  color-scheme: light dark;
  --border: light-dark(#d8d8dc, #3a3a3f);
  --muted: light-dark(#66666e, #9a9aa2);
  --bg-subtle: light-dark(#f5f5f7, #1c1c1f);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: light-dark(#111, #eee);
  background: light-dark(#fff, #111);
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

#logout-button {
  margin-left: auto;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

#login {
  max-width: 24rem;
  margin: 4rem auto;
  text-align: center;
}

button {
  font: inherit;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg-subtle);
  cursor: pointer;
}

button:hover {
  filter: brightness(0.97);
}

#generate {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

#generated-address {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.375rem;
  background: var(--bg-subtle);
}

#filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

#filters input {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
}

#filters label {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(18rem, 26rem) 1fr;
  flex: 1;
  min-height: 0;
}

#results {
  list-style: none;
  margin: 0;
  padding: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#results li {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

.result-line1 {
  display: flex;
  gap: 0.5rem;
  overflow: hidden;
}

.result-date {
  flex: none;
  color: var(--muted);
  font-size: 0.8rem;
}

.result-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-line2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
}

#results li:hover {
  background: var(--bg-subtle);
}

#results li.selected {
  background: var(--bg-subtle);
  font-weight: 600;
}

#detail {
  padding: 1rem 1.5rem;
  overflow-y: auto;
}

#detail dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 1rem;
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

#detail dt {
  color: var(--muted);
}

#detail dd {
  margin: 0;
  word-break: break-word;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  margin-left: 0.35rem;
  vertical-align: middle;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: var(--bg-subtle);
  color: inherit;
}

#detail iframe {
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: #fff;
}

#detail pre {
  white-space: pre-wrap;
  word-break: break-word;
}

.hint {
  color: var(--muted);
}

.truncated-warning {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem;
  border: 1px solid light-dark(#e8b339, #7a5c14);
  border-radius: 0.375rem;
  background: light-dark(#fdf3d8, #3a2e0d);
  color: light-dark(#6b4e00, #f0d896);
  font-size: 0.85rem;
}

.modal {
  position: relative;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  max-width: 40rem;
  width: calc(100% - 2rem);
  color: inherit;
  background: light-dark(#fff, #111);
}

.modal.modal-lg {
  max-width: 60rem;
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.4);
}

.modal-close-button {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  padding: 0.15rem 0.5rem;
  line-height: 1;
}

.modal h2 {
  font-size: 1rem;
  margin: 0 0 1rem;
}

.modal pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-subtle);
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.85rem;
}

#headers-content {
  max-height: 70vh;
  overflow-y: auto;
}

#usage h3 {
  font-size: 0.9rem;
  margin: 1.25rem 0 0.4rem;
}

#usage code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg-subtle);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
}

#usage button:not(.icon-button) {
  margin-left: 0.5rem;
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}
