:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1d21;
  --muted: #6b7280;
  --border: #e3e5e9;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #e8eaed;
    --muted: #9aa0a9;
    --border: #2a2e36;
    --accent: #4f8cff;
    --accent-soft: #1d2a44;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.ghost { border-color: transparent; color: var(--accent); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  max-width: 900px;
  margin: 0 auto;
}
.brand { font-weight: 700; font-size: 18px; }
.logo { color: var(--accent); }

.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.status[data-state="live"] .dot { background: var(--ok); }

.container { max-width: 900px; margin: 0 auto; padding: 0 16px; display: grid; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.label { margin: 0 0 8px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }

.address-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.address {
  flex: 1 1 260px;
  min-width: 0;
  font: 600 20px/1.3 ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 10px 14px;
  overflow-wrap: anywhere;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); margin: 12px 0 0; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.section-head h2 { margin: 0; font-size: 18px; }

.message-list { list-style: none; margin: 0; padding: 0; }
.message-list li { border-top: 1px solid var(--border); }
.message-list li:first-child { border-top: 0; }
.message-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  padding: 12px 10px;
  background: transparent;
}
.message-item:hover { background: var(--accent-soft); }
.message-item .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-item .time { color: var(--muted); font-size: 13px; }
.message-item .subject, .message-item .preview {
  grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-item .preview { color: var(--muted); font-size: 14px; }
.message-item.unread .subject { font-weight: 700; }
.message-item.unread .from::before { content: "● "; color: var(--accent); }
.message-item.fresh { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.empty { text-align: center; padding: 32px 0 16px; }
.empty p { margin: 4px 0; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 12px;
  border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.reader-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.reader-toolbar .spacer { flex: 1; }
.reader-subject { margin: 0 0 8px; font-size: 20px; overflow-wrap: anywhere; }
.reader-meta { margin: 0 0 16px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.reader-frame {
  width: 100%;
  height: 65vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.attachments { margin-top: 16px; }
.attachments h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); }
.attachments a {
  display: inline-block; margin: 0 8px 8px 0; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; color: var(--accent); text-decoration: none;
}

.footer { text-align: center; padding: 24px 16px; }

@media (max-width: 600px) {
  .address { font-size: 16px; }
  .card { padding: 16px; }
  .reader-frame { height: 60vh; }
}
