:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --hover: #eef1f6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --card: #1d2027;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --border: #2d313a;
    --accent: #5c7cfa;
    --danger: #ff6b6b;
    --hover: #262a33;
  }
}

* { box-sizing: border-box; }

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

.page { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; }
.head h1 { margin: 0 0 4px; font-size: 26px; }
.lead, .muted { color: var(--muted); }
.lead { margin: 0 0 24px; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }

.address-row, .meta-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.meta-row { justify-content: space-between; margin-top: 14px; color: var(--muted); }
.meta-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 8px; }
.address {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  overflow-wrap: anywhere;
  user-select: all;
}

.status { color: var(--danger); }

.inbox h2 { font-size: 18px; margin: 24px 0 8px; }
.messages { list-style: none; margin: 0; padding: 0; }
.messages li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.messages li:hover { background: var(--hover); }
.msg-top { display: flex; justify-content: space-between; gap: 12px; }
.msg-from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subject, .msg-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-preview { color: var(--muted); font-size: 14px; }

.reader-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.reader-subject { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.reader-html { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.reader-text { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.attachments { margin: 12px 0 0; padding-left: 18px; color: var(--muted); }

.progress-head { display: flex; gap: 10px; align-items: center; }
.elapsed { margin-left: auto; font-variant-numeric: tabular-nums; }
.spinner, .steps li.active .step-icon {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.bar { height: 6px; margin: 16px 0; border-radius: 3px; background: var(--hover); overflow: hidden; }
.bar-fill {
  height: 100%;
  width: 5%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 40%, #91a7ff 50%, var(--accent) 60%, var(--accent) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  transition: width .6s ease;
}

.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0; color: var(--muted); transition: color .3s; }
.steps li b { display: block; font-weight: 500; }
.step-note { display: block; font-size: 13px; }
.step-icon {
  width: 16px;
  height: 16px;
  flex: none;
  margin-top: 3px;
  border: 2px solid var(--border);
  border-radius: 50%;
}
.steps li.active { color: var(--text); }
.steps li.active b { font-weight: 600; }
.steps li.active .step-icon { margin-top: 3px; }
.steps li.done { color: var(--text); }
.steps li.done .step-icon { border-color: var(--accent); background: var(--accent); position: relative; }
.steps li.done .step-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-text);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  .spinner, .steps li.active .step-icon, .bar-fill { animation: none; }
}
