/* WholeTwilight Portal by SK — one stylesheet for the inbox page (index.html),
   the admin page (admin.html) and the email viewer built by common.js.
   Follows the device's light or dark setting. */

:root {
  --bg: #f5f6fb;
  --bg-glow: rgba(99, 102, 241, 0.10);
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef0f6;
  --border: #e3e6ef;
  --border-strong: #cfd4e2;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;
  --primary-text: #4338ca;
  --on-primary: #ffffff;
  --accent: #7c3aed;
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning-soft: #fffbeb;
  --warning-text: #92400e;
  --code-bg: #f1f3f9;
  --ring: 0 0 0 4px rgba(79, 70, 229, 0.16);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px -12px rgba(15, 23, 42, 0.14);
  --shadow-lg: 0 24px 64px -24px rgba(15, 23, 42, 0.35);
  --scrim: rgba(15, 23, 42, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --font: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 64px;
  --bottom-nav-h: 0px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --bg-glow: rgba(99, 102, 241, 0.16);
    --surface: #121a2d;
    --surface-2: #0f1627;
    --surface-3: #1a2440;
    --border: #232d47;
    --border-strong: #33405f;
    --text: #e8ebf4;
    --text-2: #c3cadb;
    --muted: #8f99b3;
    --primary: #6d6af5;
    --primary-hover: #8380ff;
    --primary-soft: rgba(109, 106, 245, 0.16);
    --primary-text: #a5a8ff;
    --accent: #a78bfa;
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --warning-soft: rgba(251, 191, 36, 0.12);
    --warning-text: #fcd34d;
    --code-bg: #1a2440;
    --ring: 0 0 0 4px rgba(109, 106, 245, 0.28);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 64px -24px rgba(0, 0, 0, 0.8);
    --scrim: rgba(3, 6, 15, 0.66);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 15px/1.55 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 520px at 50% -180px, var(--bg-glow), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.no-scroll {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

a {
  color: var(--primary-text);
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.6;
}

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.12em 0.42em;
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--text-2);
}

.i {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.mono {
  font-family: var(--mono);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

/* ---------- brand ---------- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  box-shadow: 0 8px 20px -8px rgba(79, 70, 229, 0.65);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-by {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.brand-small {
  gap: 10px;
}

.brand-small .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  box-shadow: none;
}

.brand-small .brand-name {
  font-size: 15px;
}

.brand-small .brand-by {
  font-size: 10.5px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--muted);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn .i {
  width: 18px;
  height: 18px;
}

.btn-primary {
  border-color: transparent;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12), 0 6px 16px -8px rgba(79, 70, 229, 0.7);
}

.btn-primary:hover:not(:disabled) {
  border-color: transparent;
  background: var(--primary-hover);
}

.btn-block {
  width: 100%;
  min-height: 48px;
  font-size: 15px;
}

.btn-small {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.btn-danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.btn-danger:hover:not(:disabled) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.icon-btn.small {
  width: 32px;
  height: 32px;
}

.icon-btn.small .i {
  width: 17px;
  height: 17px;
}

.icon-btn.danger {
  color: var(--danger);
}

.icon-btn.danger:hover {
  background: var(--danger-soft);
}

/* ---------- form fields ---------- */

.field-label {
  display: block;
  margin: 16px 0 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 6px 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field:focus-within {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.field input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15.5px;
}

.field input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.field input:focus-visible {
  box-shadow: none;
}

.field .suffix {
  flex: none;
  padding-right: 8px;
  color: var(--muted);
  font-size: 15px;
}

.field-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}

.field-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.field-btn[aria-pressed="true"] {
  color: var(--primary-text);
}

.field-search {
  min-height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.field-search input {
  height: 40px;
  font-size: 14.5px;
}

.field-search input::-webkit-search-cancel-button {
  cursor: pointer;
}

.text-input {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

textarea.text-input {
  resize: vertical;
  min-height: 160px;
  line-height: 1.5;
}

.form-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

.form-error:empty {
  display: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 4px;
  font-size: 14.5px;
  cursor: pointer;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.key-row {
  display: flex;
  gap: 8px;
}

.key-row .text-input {
  flex: 1;
  min-width: 0;
}

/* ---------- sign-in page ---------- */

.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(40px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  width: 100%;
  max-width: 440px;
  margin: auto 0;
}

.auth-card {
  width: 100%;
  padding: 30px 28px 26px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-lead {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14.5px;
}

.auth-card .btn-block {
  margin-top: 20px;
}

.auth-card .form-error + .btn-block {
  margin-top: 14px;
}

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.recent {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.recent > p {
  flex-basis: 100%;
  margin-bottom: 2px;
  font-size: 13px;
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary-text);
  background: var(--primary-soft);
}

.auth-points {
  display: grid;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 0 6px;
  list-style: none;
  color: var(--muted);
  font-size: 13.5px;
}

.auth-points li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-points .i {
  width: 18px;
  height: 18px;
  color: var(--primary-text);
}

.foot {
  margin-top: 28px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

.foot:empty {
  display: none;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 880px;
  min-height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
}

.topbar-wide {
  max-width: 1080px;
  justify-content: space-between;
}

.address-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 40px;
  margin-left: auto;
  padding: 0 12px 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.address-pill:hover {
  border-color: var(--primary);
}

.address-pill .i {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.address-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.status-dot.is-down {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.actions-nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
}

.nav-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav-btn .i {
  width: 18px;
  height: 18px;
}

.nav-btn.busy .i {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- inbox page ---------- */

.portal-main {
  display: grid;
  gap: 18px;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px calc(40px + var(--bottom-nav-h) + env(safe-area-inset-bottom));
}

.code-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  overflow: hidden;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 62%, #a21caf 100%);
  color: #fff;
  box-shadow: 0 18px 40px -22px rgba(79, 70, 229, 0.9);
}

.code-card::after {
  content: "";
  position: absolute;
  inset: -40% -10% auto auto;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18), transparent 65%);
  pointer-events: none;
}

.code-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.code-label {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.code-value {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.code-value-link {
  font-family: var(--font);
  font-size: 22px;
  letter-spacing: -0.01em;
}

.code-meta {
  font-size: 13.5px;
  opacity: 0.85;
}

.code-card.is-empty {
  background: var(--surface);
  color: var(--text);
  border: 1px dashed var(--border-strong);
  box-shadow: none;
}

.code-card.is-empty::after {
  display: none;
}

.code-card.is-empty .code-label,
.code-card.is-empty .code-meta {
  color: var(--muted);
  opacity: 1;
}

.code-card.is-empty .code-value {
  color: var(--border-strong);
  font-size: 26px;
}

.code-card .btn-primary {
  position: relative;
  z-index: 1;
  min-height: 46px;
  padding: 0 18px;
  background: #fff;
  color: #3730a3;
  box-shadow: 0 6px 18px -8px rgba(0, 0, 0, 0.45);
}

.code-card .btn-primary:hover:not(:disabled) {
  background: #eef0ff;
}

.inbox-card {
  padding: 18px 18px 8px;
}

.inbox-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin: 2px 2px 14px;
}

.inbox-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.count {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 12.5px;
  font-weight: 700;
}

.inbox-card .field-search {
  margin-bottom: 6px;
}

/* ---------- email list (common.js) ---------- */

.mail-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mail-list li + li {
  border-top: 1px solid var(--border);
}

.mail-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  grid-template-areas:
    "avatar from time"
    "avatar subject chip";
  align-items: center;
  column-gap: 14px;
  row-gap: 2px;
  width: 100%;
  padding: 14px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  transition: background-color 0.12s;
}

.mail-item:hover {
  background: var(--surface-2);
}

.avatar {
  grid-area: avatar;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
}

.mail-from {
  grid-area: from;
  overflow: hidden;
  font-size: 15px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-time {
  grid-area: time;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  text-align: right;
}

.mail-subject {
  grid-area: subject;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-chip {
  grid-area: chip;
  justify-self: end;
  padding: 2px 9px;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.mail-chip-link {
  font-family: var(--font);
  letter-spacing: 0;
}

.mail-item.is-new {
  background: var(--primary-soft);
}

.mail-item.is-new .mail-from::after {
  content: "New";
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 11px;
  font-weight: 700;
  vertical-align: 2px;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 44px 16px 40px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 10px;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary-text);
}

.empty-icon .i {
  width: 26px;
  height: 26px;
}

.empty-title {
  font-size: 16px;
  font-weight: 650;
}

/* ---------- email viewer and dialogs ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--scrim);
  animation: fade-in 0.15s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.viewer-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  height: min(88vh, 900px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from {
    transform: translateY(12px);
    opacity: 0.6;
  }
}

.dialog-card {
  max-width: 520px;
  height: auto;
  max-height: 88vh;
}

.dialog-wide {
  max-width: 720px;
  height: min(80vh, 760px);
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 60px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border);
}

.viewer-bar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0 6px;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 26px;
}

#viewer-subject {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 14px;
  margin: 16px 0 18px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 14px;
}

.meta dt {
  color: var(--muted);
  font-weight: 600;
}

.meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: 12px;
  background: var(--primary-soft);
}

.action-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.action-label {
  color: var(--primary-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.action-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.12em;
  overflow-wrap: anywhere;
}

.action-link {
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-2);
}

.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--warning-soft);
  color: var(--warning-text);
  font-size: 14px;
}

.notice-ok {
  background: var(--success-soft);
  color: var(--success);
}

.notice-info {
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.viewer-body iframe {
  display: block;
  width: 100%;
  min-height: 60vh;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.mail-text {
  margin: 0;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-2);
  font: 14px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13.5px;
  text-decoration: none;
}

.file:hover {
  border-color: var(--primary);
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-body .field-label {
  margin: 6px 0 -4px;
}

.dialog-body .check-row {
  margin: 4px 0;
}

.skip-list {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 13.5px;
}

/* ---------- toast (common.js) ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--bottom-nav-h) + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(92vw, 440px);
  padding: 11px 18px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-color-scheme: dark) {
  .toast {
    background: #e8ebf4;
    color: #0b1020;
  }
}

/* ---------- admin page ---------- */

.admin-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.admin-login {
  max-width: 420px;
  margin: 8vh auto 0;
}

.admin-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.tag-accent {
  margin-left: 4px;
  background: var(--primary-soft);
  color: var(--primary-text);
}

.tag-off {
  background: var(--danger-soft);
  color: var(--danger);
}

.page-head {
  margin-bottom: 18px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat strong {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat span {
  color: var(--muted);
  font-size: 13.5px;
}

.list-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.list-tools .field-search {
  flex: 1;
  background: var(--surface);
}

.addr-list {
  margin: 0;
  padding: 4px 0;
  list-style: none;
}

.addr-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
}

.addr-row + .addr-row {
  border-top: 1px solid var(--border);
}

.addr-row.is-off .addr-text {
  opacity: 0.6;
}

.addr-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--success);
}

.is-off .dot {
  background: var(--border-strong);
}

.addr-text {
  min-width: 0;
}

.addr-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
  font-size: 15px;
}

.addr-name .muted {
  margin-left: -8px;
}

.addr-key {
  display: flex;
  align-items: center;
  gap: 2px;
}

.key {
  font-size: 13.5px;
}

.addr-actions {
  display: flex;
  gap: 6px;
}

.wide-only {
  display: inline;
}

.narrow-only {
  display: none;
}

/* ---------- phones ---------- */

@media (max-width: 720px) {
  :root {
    --bottom-nav-h: 64px;
    --topbar-h: 58px;
  }

  /* A blurred top bar would trap the fixed bottom bar inside it. */
  .topbar {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--surface);
  }

  .topbar-inner {
    gap: 12px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
  }

  .portal .brand-small .brand-text {
    display: none;
  }

  .address-pill {
    flex: 1;
    margin-left: 0;
    justify-content: center;
  }

  .actions-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    justify-content: space-around;
    gap: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
  }

  .nav-btn {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    max-width: 120px;
    min-height: 52px;
    padding: 0;
    font-size: 12px;
  }

  .nav-btn .i {
    width: 22px;
    height: 22px;
  }

  .portal-main {
    gap: 14px;
    padding: 16px 12px calc(28px + var(--bottom-nav-h) + env(safe-area-inset-bottom));
  }

  .code-card {
    flex-direction: column;
    align-items: stretch;
    padding: 20px;
  }

  .code-value {
    font-size: 30px;
  }

  .code-card .btn-primary {
    width: 100%;
  }

  .inbox-card {
    padding: 14px 10px 4px;
  }

  .inbox-head {
    margin: 2px 6px 12px;
  }

  .mail-item {
    column-gap: 12px;
    padding: 12px 6px;
  }

  .auth {
    padding-top: max(28px, env(safe-area-inset-top));
  }

  .auth-card {
    padding: 24px 20px 22px;
  }

  .field .suffix {
    font-size: 14px;
  }

  .viewer {
    padding: 0;
  }

  .viewer-card,
  .dialog-card,
  .dialog-wide {
    max-width: none;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .dialog-card:not(.dialog-wide) {
    height: auto;
    max-height: 92vh;
    margin-top: auto;
    border-radius: 20px 20px 0 0;
  }

  .viewer:has(.dialog-card:not(.dialog-wide)) {
    place-items: end stretch;
  }

  .viewer-scroll {
    padding: 18px 16px 24px;
  }

  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-main {
    padding: 20px 12px 40px;
  }

  .stats {
    gap: 8px;
  }

  .stat {
    padding: 12px 14px;
  }

  .stat strong {
    font-size: 22px;
  }

  .list-tools {
    flex-wrap: wrap;
  }

  .list-tools .field-search {
    flex-basis: 100%;
  }

  .list-tools .btn {
    flex: 1;
  }

  .addr-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px;
    padding: 14px;
  }

  .addr-actions {
    grid-column: 1 / -1;
  }

  .addr-actions .btn {
    flex: 1;
  }

  .wide-only {
    display: none;
  }

  .narrow-only {
    display: inline;
  }
}

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