:root {
  --ink: #1f2a37;
  --paper: #f4f5f7;
  --card: #ffffff;
  --line: #d9dee5;
  --muted: #5d6b7a;
  --accent: #b45309;
  --accent-dark: #92400e;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

input[type=text], input[type=email], input[type=password], input[type=search] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
}

select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 8px;
  font: inherit;
  color: inherit;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.primary {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  font-weight: 600;
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: 0.6; cursor: default; }

.ghost {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  padding: 6px 12px;
}

.danger {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  padding: 4px 8px;
}
.danger:hover { border-color: var(--danger); }

.link {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  text-decoration: underline;
}

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
}

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h2 .muted { font-weight: 400; font-size: 14px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login form { width: min(360px, 100%); display: grid; gap: 12px; }
.login label { color: var(--ink); font-size: 14px; }
.login-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.login-head h1 { margin: 0; }
.account-part select { justify-self: start; min-width: 200px; }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--ink);
  color: #f3f4f6;
}
.brand { display: flex; gap: 10px; align-items: baseline; }
.brand strong { font-size: 18px; }
.brand span { color: #c3cad3; font-size: 13px; }

.tabs { display: flex; gap: 4px; margin-right: auto; }
.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #c3cad3;
  padding: 6px 12px;
}
.tab:hover { color: #fff; }
.tab.current { background: #374151; color: #fff; font-weight: 600; }

.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid #4b5563;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: #f3f4f6;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  display: grid;
  min-width: 200px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 8px 24px rgb(0 0 0 / 15%);
}
.menu-items button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 8px 10px;
  text-align: left;
}
.menu-items button:hover { background: var(--paper); }

.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: grid;
  gap: 16px;
}

.note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
  line-height: 1.45;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.list-head h2 { margin: 0; }
.tools { display: flex; gap: 8px; align-items: center; flex: 1; justify-content: flex-end; }
.tools input { width: min(360px, 100%); }
.tools button { white-space: nowrap; }

.sort { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-bottom: 8px; }
.sort label { display: flex; gap: 6px; align-items: center; }
.sort select { padding: 4px 6px; font-size: 13px; }
.sort .ghost { padding: 3px 10px; }

.address {
  border: 0;
  background: none;
  padding: 0;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
}
.address:hover { text-decoration: underline; }
.address.big { font-size: 16px; }
.mono { font-family: var(--mono); overflow-wrap: anywhere; }
.small { font-size: 12px; margin: 0; }

/* Compact rows of addresses and messages; details open in a dialog. */
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { display: flex; gap: 8px; align-items: center; min-width: 0; }
.row-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-stat { font-size: 12px; white-space: nowrap; display: grid; gap: 1px; justify-items: end; }
.row .ghost { padding: 4px 10px; font-size: 13px; }
.alias.off .address { color: var(--muted); text-decoration: line-through; }

.row.message { display: block; padding: 0; }
.row-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 4px;
  text-align: left;
}
.row-button:hover { background: var(--paper); }
.dir {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
}
.dir.in { background: var(--ok-bg); color: var(--ok); }
.dir.out { background: var(--warn-bg); color: var(--warn); }

.relay {
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--paper);
  font-size: 14px;
}
.relay p { margin: 0 0 4px; }
.relay .ghost { margin-top: 4px; }

.chips { margin: 0 0 8px; }
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 2px 10px;
  font-size: 13px;
}
.chip .link { text-decoration: none; font-size: 15px; }

.more { display: flex; justify-content: center; padding-top: 12px; }

.switch { display: flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; color: var(--muted); }
.switch input { margin: 0; width: 16px; height: 16px; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* Dialogs */
.modal {
  width: min(680px, calc(100% - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}
.modal::backdrop { background: rgb(17 24 39 / 45%); }
.modal-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.modal-head h2 { margin: 0; overflow-wrap: anywhere; }
.modal-head .close { padding: 2px 10px; font-size: 18px; line-height: 1; }
.modal-body { display: grid; gap: 14px; padding: 16px 18px 18px; }
.modal-actions { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.alias-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.fields .wide { grid-column: 1 / -1; }
.local-domain { display: flex; gap: 6px; align-items: center; color: var(--ink); }
.local-domain input { flex: 1; min-width: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

.facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 14px;
  margin: 0;
  font-size: 14px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.attachments { font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.mail-text {
  margin: 0;
  max-height: 50vh;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: var(--paper);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.account-part { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.account-part h3 { margin: 0; }
.account-part p { margin: 0; }
.pair { display: grid; gap: 10px; }
.qr { justify-self: start; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }
.secret { font-size: 13px; letter-spacing: 0.05em; }
.token-form { display: flex; gap: 8px; align-items: end; }
.token-form label { flex: 1; }
.account-part .note { display: grid; gap: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  z-index: 10;
}
.toast.hidden { display: none; }

@media (max-width: 640px) {
  .fields { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; padding: 10px 14px; }
  .brand span { display: none; }
  .who { display: inline-block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
  .tools { flex-wrap: wrap; }
  .row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .row .row-stat { grid-column: 2 / -1; grid-row: 2; justify-items: start; grid-auto-flow: column; justify-content: start; gap: 10px; }
}
