:root {
  --bg: #0f1115;
  --card: #171a21;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8b92a5;
  --accent: #4f7cff;
  --accent-hover: #3d6af5;
  --ok: #2fbf71;
  --warn: #e0a429;
  --err: #e5484d;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
code { background: #0b0d11; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- layout ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.container {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 20px;
  display: grid;
  gap: 18px;
}

.card {
  min-width: 0; /* grid item: let .table-wrap scroll instead of widening the page */
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- form ---------- */
.add-row { display: flex; gap: 10px; }
.add-row input {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b0d11;
  color: var(--text);
  outline: none;
}
.add-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,124,255,.2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #20242e;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: #272c38; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: #ff8a8a; border-color: rgba(255,106,106,.45); }
.btn-danger:hover { background: rgba(255,106,106,.12); border-color: #ff6a6a; }
.btn.is-busy { opacity: .7; pointer-events: none; }

.alert {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid;
  font-size: 14px;
}
.alert-error { border-color: rgba(229,72,77,.5); background: rgba(229,72,77,.1); color: #ffb4b6; }

.pill {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.pill-warn { border-color: var(--warn); color: var(--warn); font-weight: 600; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.domains { width: 100%; border-collapse: collapse; font-size: 14px; }
table.domains th, table.domains td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.domains th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table.domains tr:last-child td { border-bottom: none; }
td.domain { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.message { color: #c9cdd8; max-width: 520px; }
td.time { color: var(--muted); white-space: nowrap; font-size: 13px; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-purchased { background: rgba(47,191,113,.15); color: #6fe3a3; border-color: rgba(47,191,113,.4); }
.badge-purchased_forward_failed { background: rgba(224,164,41,.15); color: #ffd47a; border-color: rgba(224,164,41,.4); }
.badge-failed { background: rgba(229,72,77,.15); color: #ff9b9e; border-color: rgba(229,72,77,.4); }
.badge-pending {
  background: rgba(79,124,255,.15); color: #9db5ff; border-color: rgba(79,124,255,.4);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- login ---------- */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 16px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login-card input[type=password] {
  width: 100%;
  font-size: 16px;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b0d11;
  color: var(--text);
  margin-bottom: 14px;
}
.login-card input:focus { border-color: var(--accent); outline: none; }
.login-card .btn { width: 100%; }

/* ---------- live inbox ---------- */
.inbox-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.inbox-head h2 { margin: 0 0 2px; font-size: 16px; }
.inbox-tools { display: flex; align-items: center; gap: 10px; }
.inbox-status { white-space: nowrap; }
.mail-modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.mail-item { position: relative; }
.mail-del {
  position: absolute; top: 8px; right: 10px;
  padding: 2px 8px; font-size: 12px; line-height: 1.4;
  opacity: 0; transition: opacity .15s;
}
.mail-item:hover .mail-del, .mail-del:focus { opacity: 1; }
.mail-item .mail-row1 { padding-right: 70px; }
.mail-item.removing { opacity: .4; pointer-events: none; }
@media (hover: none) { .mail-del { opacity: 1; } }
.mail-list { list-style: none; margin: 12px 0 0; padding: 0; }
.mail-empty { padding: 14px 4px; }
.mail-item {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  background: #12151c;
  transition: border-color .12s ease, background .12s ease;
}
.mail-item:hover { border-color: var(--accent); background: #151925; }
.mail-item.unread { border-left: 3px solid var(--accent); }
.mail-item.just-in { animation: flashin 1.4s ease; }
@keyframes flashin {
  0% { background: rgba(79,124,255,.25); }
  100% { background: #12151c; }
}
.mail-row1 { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.mail-from { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-date { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mail-subject { margin-top: 2px; font-size: 14px; color: #dfe3ec; }
.mail-item.unread .mail-subject { font-weight: 600; }
.mail-snippet { margin-top: 2px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* message modal */
.mail-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.mail-modal[hidden] { display: none; }
.mail-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.mail-modal-box {
  position: relative;
  width: 100%;
  max-width: 760px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.mail-modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.mail-modal-subject { font-size: 16px; font-weight: 600; }
.mail-modal-body { padding: 0; overflow: auto; background: #0b0d11; }
.mail-text { margin: 0; padding: 16px 18px; white-space: pre-wrap; word-break: break-word; font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace; color: #d7dbe4; }
.mail-html { width: 100%; min-height: 60vh; border: 0; background: #fff; }

/* ---------- CSV page ---------- */
.topbar h1 a.plain { color: inherit; }
.topbar h1 a.plain:hover { color: var(--accent); }
.container-wide { max-width: none; margin: 14px auto; padding: 0 16px; }
.csv-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.csv-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.csv-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.csv-filter {
  padding: 6px 10px; font-size: 13px; border-radius: 8px;
  border: 1px solid var(--border); background: #0b0d11; color: var(--text); outline: none; min-width: 180px;
}
.csv-filter:focus { border-color: var(--accent); }
.csv-status-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.csv-saved { color: var(--ok); }
.csv-info { color: var(--warn); }
.csv-err { color: var(--err); }
.csv-help { margin: 0 0 10px; }
.csv-card { padding: 14px; }
.csv-wrap { max-height: calc(100vh - 210px); overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.csv-table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13.5px; table-layout: auto; }
.csv-table th, .csv-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); vertical-align: top; }
.csv-table thead th { position: sticky; top: 0; z-index: 2; background: #1d2129; text-align: left; font-weight: 600; }
.csv-table .csv-num {
  position: sticky; left: 0; z-index: 1; background: #1d2129; color: var(--muted);
  text-align: right; padding: 7px 10px; font-variant-numeric: tabular-nums; user-select: none; min-width: 44px; white-space: nowrap;
}
.csv-table thead .csv-num { z-index: 3; }
td.csv-cell {
  min-width: 120px; max-width: 460px;
  padding: 7px 10px; outline: none; white-space: pre-wrap; word-break: break-word; cursor: text;
}
th.csv-head { position: relative; }
.csv-head-text {
  display: block; min-width: 100px; max-width: 460px;
  padding: 7px 26px 7px 10px; outline: none; white-space: pre-wrap; word-break: break-word; cursor: text;
}
td.csv-cell.editing, .csv-head.editing .csv-head-text { box-shadow: inset 0 0 0 2px var(--accent); background: #0f1320; }
td.csv-cell.saving { background: rgba(224,164,41,.12); }
td.csv-cell.saved { background: rgba(47,191,113,.18); transition: background .6s; }
td.csv-cell.error { box-shadow: inset 0 0 0 2px var(--err); }
.csv-act { width: 34px; min-width: 34px; text-align: center; vertical-align: middle !important; }
.csv-del {
  border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1;
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity .12s;
}
.csv-table tr:hover .csv-del, .csv-del:focus { opacity: 1; }
.csv-del:hover { background: rgba(229,72,77,.18); color: #ff8a8a; }
.csv-del-col { position: absolute; top: 5px; right: 4px; }
th.csv-head:hover .csv-del-col { opacity: 1; }
.csv-table.flash { animation: flashin 1.2s ease; }
.csv-table .empty-row td, .csv-table .no-match td { padding: 16px 12px; border: 0; }
@media (hover: none) { .csv-del { opacity: 1; } }

@media (max-width: 640px) {
  .add-row { flex-direction: column; }
  td.message { max-width: none; }
  .mail-from { max-width: 55%; }
}
