:root {
  color-scheme: light dark;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #f0f3f7;
  --border: #d8dee8;
  --border-strong: #b7c2d0;
  --text: #17202e;
  --muted: #647084;
  --blue: #2563eb;
  --blue-soft: #e8f0ff;
  --green: #059669;
  --green-soft: #dff8ef;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1118;
    --surface: #151a23;
    --surface-soft: #1c2330;
    --border: #293241;
    --border-strong: #3a4658;
    --text: #e7ecf4;
    --muted: #9aa6b8;
    --blue: #60a5fa;
    --blue-soft: rgba(96, 165, 250, 0.14);
    --green: #34d399;
    --green-soft: rgba(52, 211, 153, 0.14);
    --red: #f87171;
    --red-soft: rgba(248, 113, 113, 0.14);
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
}

.brand h1,
.topbar h2,
.reader h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.topbar p,
.reader p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.alias-form {
  display: grid;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 11px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.alias-row {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 8px;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: 140ms ease;
}

.primary-btn {
  min-height: 40px;
  background: var(--blue);
  border-color: var(--blue);
  color: white;
  font-weight: 700;
}

.secondary-btn,
.icon-btn {
  min-height: 38px;
  background: var(--surface);
  color: var(--text);
}

.danger-btn {
  min-height: 38px;
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red);
  font-weight: 700;
}

.icon-btn {
  width: 40px;
  padding: 0;
}

.primary-btn:hover,
.secondary-btn:hover,
.danger-btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.section-title {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.alias-list {
  display: grid;
  gap: 8px;
}

.alias-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
}

.alias-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.alias-address {
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 13px;
}

.alias-label {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.alias-actions {
  display: flex;
  gap: 6px;
}

.danger-icon {
  color: var(--red);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.topbar h2 {
  font-size: 24px;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.setup-warning,
.setup-card,
.status-line {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
}

.setup-warning {
  margin-bottom: 12px;
  color: var(--red);
}

.setup-card {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 520px);
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

.setup-card h3 {
  margin: 0;
  font-size: 15px;
}

.setup-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.setup-form {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.status-dot.error {
  background: var(--red);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  min-height: 650px;
}

.message-list-wrap,
.reader {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.message-table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

tr.message-row {
  cursor: pointer;
}

tr.message-row:hover {
  background: var(--blue-soft);
}

.code-pill {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  padding: 42px;
  color: var(--muted);
  text-align: center;
}

.reader {
  display: flex;
  flex-direction: column;
}

.reader-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.reader-code {
  margin: 16px 16px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.reader-body {
  margin: 0;
  padding: 16px;
  white-space: pre-wrap;
  overflow: auto;
  color: var(--text);
  line-height: 1.55;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 11px 13px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 1000px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .setup-card,
  .setup-form,
  .form-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main,
  .sidebar {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    flex: 1;
  }

  th:nth-child(1),
  td:nth-child(1),
  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }
}
