/* =====================================================================
   Cloudflare Single Email Viewer — styles
   Premium dark glassmorphism. Accent color is injected at runtime via
   the --accent CSS variable (from NEXT_PUBLIC_THEME_COLOR).
   ===================================================================== */

:root {
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.18);
  --accent-glow: rgba(139, 92, 246, 0.55);
  --bg-0: #07040d;
  --bg-1: #0b0613;
  --text: #f4f1fb;
  --text-dim: #b7afce;
  --text-faint: #7d7596;
  --glass-bg: rgba(22, 16, 38, 0.45);
  --glass-border: rgba(255, 255, 255, 0.12);
  --radius: 22px;
  --radius-sm: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(
      1200px 800px at 50% -10%,
      #150a26 0%,
      var(--bg-1) 45%,
      var(--bg-0) 100%
    );
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Background layers ---------- */
#bg-canvas,
#bg-fallback {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  display: block;
}

#bg-fallback {
  z-index: -3;
  background:
    radial-gradient(40% 50% at 20% 20%, var(--accent-soft), transparent 70%),
    radial-gradient(45% 55% at 85% 30%, rgba(56, 189, 248, 0.16), transparent 70%),
    radial-gradient(50% 60% at 50% 95%, rgba(236, 72, 153, 0.14), transparent 70%);
  background-color: var(--bg-1);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  0% { filter: hue-rotate(0deg); transform: scale(1); }
  100% { filter: hue-rotate(25deg); transform: scale(1.08); }
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    120% 120% at 50% 40%,
    transparent 55%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

/* ---------- Stage / layout ---------- */
.stage {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.hero,
.inbox {
  width: min(560px, 100%);
  text-align: center;
}

/* ---------- Hero ---------- */
.eyebrow {
  margin: 0 0 14px;
  font-size: 12px;
  letter-spacing: 0.42em;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
}

.title {
  margin: 0 0 14px;
  font-size: clamp(38px, 8vw, 76px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #ffffff 0%, #d6cdf0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 60px var(--accent-glow);
  filter: drop-shadow(0 8px 40px var(--accent-soft));
}

.subtitle {
  margin: 0 auto 34px;
  max-width: 30ch;
  color: var(--text-dim);
  font-size: clamp(14px, 2.4vw, 17px);
  line-height: 1.6;
}

.subtitle strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- Glass cards ---------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.input-card {
  padding: 26px 24px 24px;
  text-align: left;
}

.field-label {
  display: block;
  margin: 0 0 10px 2px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.field-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field-icon {
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
  opacity: 0.9;
}

#email-input {
  flex: 1;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  padding: 16px 0;
  letter-spacing: 0.01em;
}

#email-input::placeholder {
  color: var(--text-faint);
}

/* ---------- Buttons ---------- */
.btn-primary {
  position: relative;
  margin-top: 18px;
  width: 100%;
  border: 0;
  cursor: pointer;
  padding: 15px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(
    135deg,
    var(--accent) 0%,
    color-mix(in srgb, var(--accent) 55%, #3b82f6) 100%
  );
  box-shadow: 0 10px 30px var(--accent-soft), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
  transition: transform 0.18s var(--ease), box-shadow 0.25s var(--ease),
    filter 0.2s var(--ease);
  overflow: hidden;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  cursor: progress;
  filter: saturate(0.7) brightness(0.9);
}

.btn-spinner {
  display: none;
  width: 18px;
  height: 18px;
  margin-left: 10px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: -3px;
  animation: spin 0.7s linear infinite;
}

.is-loading .btn-spinner {
  display: inline-block;
}

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

.form-error {
  margin: 14px 2px 0;
  color: #ff9aa6;
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Email panel ---------- */
.email-card {
  padding: 26px 24px;
  text-align: left;
}

.email-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.avatar {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(
    135deg,
    var(--accent),
    color-mix(in srgb, var(--accent) 40%, #ec4899)
  );
  box-shadow: 0 6px 18px var(--accent-soft);
  text-transform: uppercase;
}

.email-head-main {
  flex: 1;
  min-width: 0;
}

.email-from {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-address {
  color: var(--text-faint);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-time {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 12px;
  text-align: right;
  max-width: 40%;
}

.email-subject {
  margin: 18px 0 14px;
  font-size: clamp(18px, 3.5vw, 23px);
  font-weight: 700;
  line-height: 1.3;
  word-break: break-word;
}

.email-body {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.7;
  max-height: 46vh;
  overflow: auto;
  border-radius: 12px;
}

.email-body pre.text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}

.email-body iframe {
  width: 100%;
  border: 0;
  border-radius: 12px;
  background: #fff;
  min-height: 200px;
}

.email-empty {
  text-align: center;
  padding: 30px 10px;
  color: var(--text-faint);
}

.email-empty-icon {
  font-size: 42px;
  margin-bottom: 8px;
}

/* ---------- Inbox actions ---------- */
.inbox-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.btn-ghost {
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 14px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.05);
}

.btn-refresh {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.18s var(--ease), box-shadow 0.25s var(--ease),
    background 0.2s;
}

.btn-refresh:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px var(--accent-soft);
}

.btn-refresh:disabled {
  cursor: progress;
  opacity: 0.75;
}

.refresh-icon {
  display: inline-block;
  font-size: 18px;
  line-height: 1;
}

.is-refreshing .refresh-icon {
  animation: spin 0.7s linear infinite;
}

.checked-for {
  margin: 14px 0 0;
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  word-break: break-all;
}

/* ---------- Transitions between phases ---------- */
.fade-scale-out {
  animation: fadeScaleOut 0.55s var(--ease) forwards;
  pointer-events: none;
}

@keyframes fadeScaleOut {
  to { opacity: 0; transform: scale(0.85) translateY(-8px); filter: blur(6px); }
}

.fade-scale-in {
  animation: fadeScaleIn 0.6s var(--ease) both;
}

@keyframes fadeScaleIn {
  from { opacity: 0; transform: scale(0.94) translateY(14px); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.crossfade {
  animation: crossfade 0.45s var(--ease) both;
}

@keyframes crossfade {
  from { opacity: 0.25; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 14, 34, 0.9);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}

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

/* ---------- Footer credit ---------- */
.credit {
  position: fixed;
  bottom: 12px;
  right: 16px;
  font-size: 11px;
  color: var(--text-faint);
  opacity: 0.6;
  z-index: 5;
  pointer-events: none;
}

/* ---------- Accessibility / motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #bg-fallback { animation: none; }
}

@media (max-width: 480px) {
  .inbox-actions { flex-direction: column-reverse; }
  .btn-ghost,
  .btn-refresh { width: 100%; justify-content: center; }
}
