:root {
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e3e8ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, #ffe9f3 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e5e8f0;
  --text: #121826;
  --muted: #667085;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef0ff;
  --primary-text: #ffffff;
  --success: #12b76a;
  --success-soft: #e7f8ef;
  --warning: #f79009;
  --warning-soft: #fff4e5;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --otp-bg: #f2f3ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .14);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #1b1f4a 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, #3a1430 0%, transparent 55%);
    --surface: #121826;
    --surface-2: #0f1420;
    --border: #232b3d;
    --text: #eef1f8;
    --muted: #98a2b3;
    --primary: #8b84ff;
    --primary-2: #b18cff;
    --primary-soft: #1d2147;
    --primary-text: #0b0f19;
    --success: #32d583;
    --success-soft: #0f2a1d;
    --warning: #fdb022;
    --warning-soft: #2e2210;
    --danger: #f97066;
    --danger-soft: #2f1414;
    --otp-bg: #181d3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }
.container.wide { max-width: 1100px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar .container { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 40%, transparent);
}
.logo svg.i { width: 18px; height: 18px; }
main { padding: 24px 0 64px; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-title { margin: 0 0 4px; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.card-sub { margin: 0 0 16px; color: var(--muted); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: transform .08s, background .15s, border-color .15s, box-shadow .15s; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .input:focus-visible, .switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-soft { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 34px; }
.btn-lg { height: 50px; padding: 0 22px; font-size: 15px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn.is-done { background: var(--success-soft); color: var(--success); border-color: transparent; box-shadow: none; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.input:focus { border-color: var(--primary); background: var(--surface); outline: none; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.form-error { color: var(--danger); font-size: 13.5px; min-height: 20px; margin: 4px 0 10px; }

.code-input {
  width: 100%; height: 64px; text-align: center; font-family: var(--mono); font-size: 28px; font-weight: 700;
  letter-spacing: .45em; text-transform: uppercase; padding-left: .45em; border-radius: 14px; border: 2px solid var(--border); background: var(--surface-2);
}
.code-input:focus { border-color: var(--primary); outline: none; background: var(--surface); }
.code-input.is-ok { border-color: var(--success); background: var(--success-soft); }
.code-input.is-bad { border-color: var(--danger); animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Pills / badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.pill.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.brand { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- Inbox header ---------- */
.hero { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.hero p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.alias-box { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--border); }
.alias-box .addr { flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alias-list { display: flex; flex-direction: column; gap: 8px; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls .spacer { flex: 1; }

.ring { --p: 0; width: 22px; height: 22px; border-radius: 50%; background: conic-gradient(currentColor calc(var(--p) * 1%), color-mix(in srgb, currentColor 20%, transparent) 0); -webkit-mask: radial-gradient(circle 7px, transparent 98%, #000 100%); mask: radial-gradient(circle 7px, transparent 98%, #000 100%); transition: --p .2s; }
.refresh-btn .label-count { font-variant-numeric: tabular-nums; }
.spin svg.i { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 14px; font-weight: 500; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 40px; height: 24px; border-radius: 999px; background: var(--border); position: relative; transition: background .2s; flex: none; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ---------- Messages ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 2px 12px; gap: 10px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.msg-list { display: flex; flex-direction: column; gap: 12px; }
.msg { padding: 18px; position: relative; overflow: hidden; }
.msg.is-new { animation: arrive .6s ease-out; }
.msg.is-latest { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 10%, transparent), var(--shadow); }
@keyframes arrive { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
.msg-head { display: flex; gap: 12px; align-items: flex-start; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 16px; }
.av0 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.av1 { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.av2 { background: linear-gradient(135deg, #f59e0b, #f97316); }
.av3 { background: linear-gradient(135deg, #10b981, #14b8a6); }
.av4 { background: linear-gradient(135deg, #0ea5e9, #3b82f6); }
.av5 { background: linear-gradient(135deg, #a855f7, #d946ef); }
.av6 { background: linear-gradient(135deg, #64748b, #475569); }
.av7 { background: linear-gradient(135deg, #ef4444, #f97316); }
.msg-meta { flex: 1; min-width: 0; }
.msg-from { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.msg-from .addr { font-weight: 400; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.msg-subject { margin-top: 2px; color: var(--text); font-size: 14px; word-break: break-word; }
.msg-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; text-align: right; }
.msg-to { margin-top: 6px; font-size: 12.5px; color: var(--muted); word-break: break-all; }

.otp-box { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 14px 18px; border-radius: 14px; background: var(--otp-bg); border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent); flex-wrap: wrap; }
.otp-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--primary); }
.otp-code { font-family: var(--mono); font-size: 30px; font-weight: 700; letter-spacing: .18em; line-height: 1.2; color: var(--text); cursor: pointer; word-break: break-all; }
.otp-alt { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); align-items: center; }
.otp-alt button { font-family: var(--mono); }
.link-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.link-btn { height: auto; min-height: 46px; padding: 8px 16px; max-width: 100%; justify-content: flex-start; text-align: left; }
.link-btn:hover { text-decoration: none; }
.link-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.link-label, .link-host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-host { font-size: 12px; font-weight: 500; opacity: .8; }
.link-actions .link-btn:first-child { flex: 1 1 260px; }
details.body pre a { word-break: break-all; }
.no-otp { margin-top: 12px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

details.body { margin-top: 12px; }
details.body summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); list-style: none; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
details.body summary::-webkit-details-marker { display: none; }
details.body summary svg.i { width: 15px; height: 15px; transition: transform .2s; }
details.body[open] summary svg.i { transform: rotate(90deg); }
details.body pre { margin: 10px 0 0; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; font-family: var(--font); font-size: 13.5px; max-height: 360px; overflow: auto; }

.expire-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); opacity: .5; transition: width 1s linear; }

/* ---------- Empty / state ---------- */
.state { text-align: center; padding: 48px 24px; }
.state .icon-wrap { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 22px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.state .icon-wrap svg.i { width: 32px; height: 32px; }
.state.bad .icon-wrap { background: var(--danger-soft); color: var(--danger); }
.state h3 { margin: 0 0 6px; font-size: 18px; }
.state p { margin: 0 auto; color: var(--muted); max-width: 420px; font-size: 14px; }
.state .btn { margin-top: 20px; }
.mb-0 { margin-bottom: 0 !important; }
.mt-16 { margin-top: 16px; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: 13.5px; margin-bottom: 16px; }
.banner.warn { background: var(--warning-soft); color: var(--warning); }
.banner.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- Toast ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); animation: toastIn .25s ease-out; }
.toast.out { animation: toastOut .2s ease-in forwards; }
.toast .ok { color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

/* ---------- Landing / auth ---------- */
.center-wrap { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; padding: 32px 28px; text-align: center; }
.auth-card .logo { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 18px; }
.auth-card .logo svg.i { width: 28px; height: 28px; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; }
.auth-card > p { margin: 0 0 24px; color: var(--muted); }
.auth-card form { text-align: left; }
.steps { margin-top: 24px; display: grid; gap: 10px; text-align: left; }
.step { display: flex; gap: 12px; align-items: flex-start; font-size: 13.5px; color: var(--muted); }
.step b { width: 24px; height: 24px; border-radius: 8px; flex: none; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-size: 12px; }

/* ---------- Admin ---------- */
.tabs { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); gap: 4px; }
.tab { height: 36px; padding: 0 14px; border-radius: 9px; border: 0; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab .count { font-size: 12px; padding: 0 7px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 800px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { padding: 16px; }
.stat .k { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .v.small { font-size: 14px; font-weight: 600; margin-top: 8px; }
.acc-line { display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-line + .acc-line { margin-top: 4px; }
.acc-line span:last-child { overflow: hidden; text-overflow: ellipsis; }
.acc-line.ok .dot { color: var(--success); }
.acc-line.bad .dot { color: var(--danger); }
.admin-grid { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
@media (max-width: 920px) { .admin-grid { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 80px; }
@media (max-width: 920px) { .sticky { position: static; } }

.result-box { margin-top: 16px; padding: 16px; border-radius: 14px; background: var(--success-soft); border: 1px solid color-mix(in srgb, var(--success) 25%, transparent); }
.result-box .t { font-size: 13px; font-weight: 700; color: var(--success); display: flex; align-items: center; gap: 6px; }
.result-box .link { margin: 10px 0 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface); font-family: var(--mono); font-size: 14px; word-break: break-all; border: 1px solid var(--border); }
.result-box .row { display: flex; gap: 8px; flex-wrap: wrap; }

.list-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.list-tools .input { height: 42px; }
.list-tools select.input { width: auto; flex: none; background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; }
.search { position: relative; flex: 1; min-width: 180px; }
.search svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search .input { padding-left: 36px; }

.code-item { padding: 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; }
.code-item + .code-item { margin-top: 10px; }
.code-badge { font-family: var(--mono); font-weight: 700; font-size: 17px; letter-spacing: .12em; padding: 8px 12px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); }
.code-item.off .code-badge { background: var(--surface-2); color: var(--muted); }
.code-info { min-width: 0; }
.code-info .name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-info .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; word-break: break-word; }
.code-actions { display: flex; gap: 6px; align-items: center; }
@media (max-width: 640px) {
  .code-item { grid-template-columns: auto 1fr; }
  .code-actions { grid-column: 1 / -1; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 12px; }
}

.modal-back { position: fixed; inset: 0; background: rgba(10, 14, 25, .5); display: grid; place-items: center; z-index: 50; padding: 16px; animation: toastIn .15s; }
.modal { width: 100%; max-width: 440px; padding: 24px; }
.modal h3 { margin: 0 0 6px; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

footer.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px 16px 32px; }

@media (max-width: 480px) {
  .hero { padding: 18px; }
  .hero h1 { font-size: 20px; }
  .otp-code { font-size: 26px; letter-spacing: .14em; }
  .msg { padding: 16px; }
  .controls .btn { flex: 1; }
  .controls .spacer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
