:root {
  --bg: #0d0f12;
  --panel: #14171c;
  --panel-2: #1a1e24;
  --line: #222831;
  --text: #e8ebf1;
  --muted: #8b93a1;
  --accent: #4ade80;
  --accent-soft: rgba(74, 222, 128, .12);
  --accent-line: rgba(74, 222, 128, .35);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(900px 500px at 50% -220px, rgba(74, 222, 128, .06), transparent 70%), var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 18px 40px; }

/* brand */
.brand {
  font-weight: 700; font-size: 21px; letter-spacing: -.03em;
  display: inline-flex; align-items: center; gap: 6px; user-select: none;
}
.brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  margin-top: 4px;
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px var(--accent-soft); }
  50% { box-shadow: 0 0 0 7px rgba(74, 222, 128, .05); }
}

header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.spacer { flex: 1; }
.chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.chip span { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* controls */
select, button, input, textarea { font: inherit; color: var(--text); }
select, button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .06s ease, opacity .16s ease;
}
select:hover, button:hover:not(:disabled) { border-color: #323945; background: var(--panel-2); }
button:active:not(:disabled) { transform: translateY(1px); }
select:focus-visible, button:focus-visible, input:focus-visible {
  outline: none; border-color: var(--accent-line);
}
button.primary {
  background: var(--accent-soft); border-color: var(--accent-line); color: #b9f7cf;
}
button.primary:hover:not(:disabled) {
  background: rgba(74, 222, 128, .2); border-color: var(--accent); color: #d6ffe4;
}
button.danger { background: var(--danger-soft); border-color: rgba(248, 113, 113, .35); color: #ffd6d6; }
button.danger:hover:not(:disabled) { background: rgba(248, 113, 113, .2); border-color: var(--danger); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--text); background: var(--panel); }
button:disabled { opacity: .38; cursor: not-allowed; }
button.block { width: 100%; }
.muted { color: var(--muted); }

input, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  transition: border-color .18s ease, background .18s ease;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent-line); background: var(--panel); }

/* login */
.card {
  max-width: 420px; margin: 10vh auto 0;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 16px; padding: 28px;
  animation: rise .28s ease both;
}
.card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.03em; }
.card p { margin: 0 0 18px; font-size: 14px; }
#loginForm { display: grid; gap: 10px; }
#loginForm input { width: 100%; }
#loginForm button { padding: 11px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* layout */
.layout { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
.side {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  padding: 12px; position: sticky; top: 18px;
}
.side-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 4px 6px 10px;
}
.addr-list { display: grid; gap: 2px; margin-bottom: 10px; max-height: 46vh; overflow: auto; }
.side-empty { padding: 10px 6px; font-size: 13px; }
.addr-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  gap: 2px 8px; text-align: left; background: none; border: 1px solid transparent;
  border-radius: 10px; padding: 9px 10px;
}
.addr-item:hover { background: var(--panel-2); border-color: transparent; }
.addr-item.active { background: var(--accent-soft); border-color: var(--accent-line); }
.addr-name { font-weight: 550; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.addr-domain { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.addr-item.active .addr-domain { color: #9ce7b7; }
.badge {
  grid-row: 1; grid-column: 2; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
}
.new-addr { display: grid; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.new-addr input, .new-addr select { width: 100%; }

.content { min-height: 60vh; }
.cur { display: flex; gap: 8px; margin-bottom: 10px; }
.cur input {
  flex: 1; font: 500 15px ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel); cursor: default;
}

/* bar + tabs */
.bar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.bar input { flex: 1; background: transparent; }
#count { white-space: nowrap; font-size: 13px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 10px 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; font-weight: 500;
}
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.pill {
  font-size: 12px; line-height: 1; padding: 4px 7px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.tab.active .pill { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

/* bulk */
.bulk {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.bulk-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.check { display: inline-flex; align-items: center; cursor: pointer; }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 17px; height: 17px; border-radius: 5px;
  border: 1px solid #333b47; background: var(--bg);
  display: inline-block; position: relative;
  transition: background .15s ease, border-color .15s ease;
}
.check input:checked + .box { background: var(--accent); border-color: var(--accent); }
.check input:checked + .box::after {
  content: ""; position: absolute; left: 5px; top: 2px;
  width: 4px; height: 8px; border: solid #06130b; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* list */
.list { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.row {
  display: grid; grid-template-columns: 26px 190px 1fr auto;
  gap: 12px; padding: 13px 16px; align-items: center;
  border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background .14s ease;
  animation: rowin .2s ease both;
}
@keyframes rowin { from { opacity: 0; } to { opacity: 1; } }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel-2); }
.row.selected { background: linear-gradient(90deg, var(--accent-soft), transparent 60%); }
.row .from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .subject { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { color: var(--muted); font-size: 12px; white-space: nowrap; text-align: right; }
.expire { color: var(--accent); font-size: 12px; white-space: nowrap; }
.empty { padding: 46px 18px; text-align: center; color: var(--muted); }

/* view */
.view {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  overflow: hidden; animation: rise .18s ease both;
}
.view .head { padding: 18px; border-bottom: 1px solid var(--line); }
.view .head h2 { margin: 0 0 8px; font-size: 17px; font-weight: 600; }
.view .meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.view .toolbar { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.view iframe { width: 100%; height: 65vh; border: 0; background: #fff; }
.view pre {
  margin: 0; padding: 18px; white-space: pre-wrap; word-break: break-word;
  font: 13px/1.65 ui-monospace, Menlo, monospace;
}

.hidden { display: none !important; }

/* admin */
.admin-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.admin-head h1 { margin: 0; font-size: 22px; letter-spacing: -.03em; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); padding: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.row-form input { flex: 1 1 150px; }
.table { display: grid; gap: 6px; }
.table-row {
  display: grid; grid-template-columns: 1fr auto auto auto auto;
  gap: 8px; align-items: center; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.table-row .email { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.table-row select, .table-row button { padding: 6px 9px; font-size: 12px; }
.status { font-size: 12px; }
.status.on { color: var(--accent); }
.status.off { color: var(--danger); }
.groups { display: grid; gap: 10px; }
.group { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); }
.group-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.group-head button { padding: 5px 9px; font-size: 12px; }
.group-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 8px 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 8px; }
.check-line { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }

/* footer */
.foot { margin-top: 32px; text-align: center; }
.small-brand { font-size: 14px; font-weight: 650; opacity: .9; }
.small-brand .dot { width: 6px; height: 6px; margin-top: 3px; }

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(5, 7, 9, .68);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 20; animation: fade .16s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: 100%; max-width: 520px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: pop .2s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-card h2 { margin: 0 0 10px; font-size: 18px; }
.modal-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-actions button { width: 100%; text-align: left; padding: 12px 14px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(14px);
  background: #1b2027; border: 1px solid var(--line); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: opacity .18s ease, transform .18s ease;
  pointer-events: none; z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .addr-list { max-height: none; }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .row { grid-template-columns: 24px 1fr auto; }
  .row .subject { grid-column: 2 / -1; }
  .row .from { padding-right: 8px; }
  .bulk-actions { margin-left: 0; width: 100%; }
  .bulk-actions button { flex: 1 1 auto; }
  .table-row { grid-template-columns: 1fr auto; }
  .table-row .email { grid-column: 1 / -1; }
}

/* mfa */
#mfaForm { display: grid; gap: 10px; margin-top: 14px; }
#mfaForm input { text-align: center; letter-spacing: .3em; font: 600 18px ui-monospace, Menlo, monospace; }
.secret {
  display: grid; gap: 6px; margin-bottom: 6px;
  border: 1px dashed var(--line); border-radius: 12px; padding: 12px;
  background: var(--bg);
}
.secret code {
  display: block; font: 13px/1.5 ui-monospace, Menlo, monospace;
  color: var(--accent); word-break: break-all;
}
.secret .uri { color: var(--muted); font-size: 11px; }
.secret button { justify-self: start; padding: 6px 10px; font-size: 12px; margin-top: 4px; }

/* admin tables */
.table-row { grid-template-columns: 1fr auto auto auto auto auto auto; }
.panel-audit { margin-top: 18px; }
.audit { display: grid; gap: 4px; max-height: 420px; overflow: auto; }
.audit-row {
  display: grid;
  grid-template-columns: 130px 170px 1fr 1fr 110px;
  gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted); align-items: center;
}
.audit-row:last-child { border-bottom: 0; }
.audit-action { color: var(--text); font-weight: 500; }
.audit-actor { color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-target { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-ip { text-align: right; }

@media (max-width: 680px) {
  .audit-row { grid-template-columns: 1fr 1fr; }
  .audit-target, .audit-ip { display: none; }
}
