:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #667085;
  --line: #e3e6ea;
  --accent: #2459d6;
  --accent-dark: #1b46ad;
  --danger: #c4372f;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

main { max-width: 1040px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 16px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two .card { margin-bottom: 16px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid rgba(36, 89, 214, 0.25); border-color: var(--accent); }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: 0.55; cursor: progress; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
.ghost { background: transparent; }
.ghost:hover:not(:disabled) { background: #eef1f5; }
.danger { color: var(--danger); }
.tab { border: 0; background: transparent; color: var(--muted); }
.tab.active { color: var(--accent); background: #eaf0fd; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.row input[type="email"] { flex: 1; min-width: 220px; }

.file { position: relative; flex-direction: row; align-items: center; cursor: pointer; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file span {
  display: inline-block;
  padding: 9px 14px;
  border: 1px dashed #b8c0cc;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}

.notice {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  background: #fff8e6;
  border: 1px solid #f1d58a;
}

.list { display: flex; flex-direction: column; }
.item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.item:first-child { border-top: 0; }
.item:hover { background: #fafbfc; }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  align-self: flex-start;
  background: #eef1f5;
  color: var(--muted);
}
.badge.Processing { background: #fff4e0; color: var(--warn); }
.badge.Ready { background: #eaf0fd; color: var(--accent); }
.badge.Sent { background: #e6f5ec; color: var(--ok); }
.badge.Failed { background: #fdeceb; color: var(--danger); }

.meta { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 12px 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }

.pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  max-height: 520px;
  overflow: auto;
}
.pre.short { max-height: 220px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.err-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #fdeceb;
  color: #8a1f19;
  white-space: pre-wrap;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #1c1f24;
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
  white-space: pre-wrap;
}
.toast.bad { background: var(--danger); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 760px) {
  .two, .grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  main { padding: 12px; }
  .meta { grid-template-columns: 1fr; }
}
