:root {
  --mail-teal: #3f7d8c;
  --mail-teal-deep: #0b3037;
  --mail-teal-soft: #eaf2f2;
  --mail-amber: #d99429;
  --mail-page: #f7f8f6;
  --mail-card: #ffffff;
  --mail-text: #14262b;
  --mail-muted: #6d7e82;
  --mail-line: #e4eae8;
  --mail-cta: #123c43;
  --mail-cta-text: #ffffff;
  --mail-shadow: 0 24px 70px rgba(17, 47, 53, .14);
  --mail-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mail-page: #0b1215;
    --mail-card: #111b1e;
    --mail-text: #e7f0ef;
    --mail-muted: #91a5a8;
    --mail-line: #28383b;
    --mail-teal: #76bdc7;
    --mail-teal-soft: #152c31;
    --mail-cta: #9bd8de;
    --mail-cta-text: #092326;
    --mail-shadow: 0 28px 80px rgba(0, 0, 0, .42);
  }
}

body.mail-login-body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  color: var(--mail-text);
  background: var(--mail-page);
  font-family: var(--mail-font);
  -webkit-font-smoothing: antialiased;
}

.mail-login-shell {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
}

/* The SSO image is a full-page, centered backdrop. The form panel overlays it. */
.mail-visual {
  position: absolute;
  inset: 0;
  z-index: 0;
  min-height: 100svh;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--mail-page);
}

.mail-visual picture {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.mail-visual img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
}

.mail-visual::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(0deg, rgba(4, 24, 28, .14) 0%, transparent 26%);
}

.mail-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: .1;
  background-image: radial-gradient(rgba(255,255,255,.7) .7px, transparent .7px);
  background-size: 7px 7px;
  mix-blend-mode: soft-light;
}

.mail-visual-caption {
  position: absolute;
  right: clamp(18px, 2.8vw, 34px);
  bottom: 23px;
  z-index: 3;
  color: rgba(255,255,255,.72);
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: .2em;
  text-shadow: 0 1px 8px rgba(0,0,0,.35);
}

.mail-form-panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  width: min(620px, 46vw);
  min-height: 100svh;
  padding: clamp(28px, 5vw, 58px);
  background: var(--mail-card);
}

/* Soft edge from the white panel into the centered photo. */
.mail-form-panel::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: clamp(64px, 8vw, 140px);
  pointer-events: none;
  background: linear-gradient(90deg, var(--mail-card) 0%, color-mix(in srgb, var(--mail-card) 62%, transparent) 48%, transparent 100%);
}

.mail-brand {
  position: absolute;
  top: clamp(28px, 5vw, 58px);
  left: clamp(28px, 5vw, 58px);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--mail-text);
  text-decoration: none;
  z-index: 3;
}

.mail-brand img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 4px 14px rgba(15, 43, 48, .14);
}

.mail-brand-name {
  font-size: 14px;
  font-weight: 750;
  letter-spacing: -.025em;
}

.mail-form-main {
  width: min(420px, 100%);
  margin: auto;
  padding: 38px 0;
}

.mail-login-intro {
  margin-bottom: 28px;
}

.mail-kicker {
  margin: 0 0 13px;
  color: var(--mail-teal);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .18em;
}

.mail-login-intro h1 {
  margin: 0;
  color: var(--mail-text);
  font-size: clamp(27px, 2.8vw, 35px);
  line-height: 1.16;
  font-weight: 700;
  letter-spacing: -.045em;
  white-space: nowrap;
}

.mail-intro-sub {
  margin: 11px 0 0;
  color: var(--mail-muted);
  font-size: 13px;
  line-height: 1.7;
}

.mail-sso-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--mail-cta);
  color: var(--mail-cta-text);
  font-size: 13.5px;
  font-weight: 650;
  text-decoration: none;
  transition: background .18s ease, transform .18s ease, box-shadow .18s ease;
}

.mail-sso-btn:hover {
  background: var(--mail-teal-deep);
  color: #fff;
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(11, 48, 55, .18);
}

.mail-sso-icon {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 8px;
  background: rgba(255,255,255,.13);
}

.mail-sso-arrow {
  margin-left: auto;
  color: color-mix(in srgb, var(--mail-cta-text) 62%, transparent);
  font-size: 17px;
}

.mail-sso-note {
  margin: 11px 0 0;
  color: var(--mail-muted);
  font-size: 11px;
  text-align: center;
}

.mail-form-foot {
  position: absolute;
  right: clamp(28px, 5vw, 58px);
  bottom: 22px;
  display: flex;
  gap: 18px;
  color: var(--mail-muted);
  font-size: 9.5px;
  letter-spacing: .02em;
  z-index: 3;
}

.mail-form-foot span:first-child {
  display: none;
}

.mail-admin-fallback {
  position: absolute;
  left: clamp(28px, 5vw, 58px);
  bottom: 20px;
  z-index: 5;
  width: min(330px, calc(100vw - 56px));
}

.mail-admin-fallback summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 0;
  color: var(--mail-muted);
  font-size: 10px;
  letter-spacing: .03em;
  cursor: pointer;
  user-select: none;
  list-style: none;
  opacity: .78;
}

.mail-admin-fallback summary::-webkit-details-marker { display: none; }
.mail-admin-fallback summary::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}
.mail-admin-fallback summary:hover { color: var(--mail-teal); opacity: 1; }
.mail-admin-fallback[open] summary { color: var(--mail-teal); opacity: 1; }

.mail-admin-form {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--mail-line);
  border-radius: 13px;
  background: var(--mail-card);
  box-shadow: var(--mail-shadow);
}

.mail-field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--mail-text);
  font-size: 10.5px;
  font-weight: 650;
}

.mail-password-wrap { position: relative; }

.mail-password-wrap input {
  width: 100%;
  min-height: 40px;
  padding: 0 55px 0 11px;
  border: 1px solid var(--mail-line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--mail-card) 90%, var(--mail-teal-soft));
  color: var(--mail-text);
  font: inherit;
  font-size: 12.5px;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.mail-password-wrap input::placeholder { color: color-mix(in srgb, var(--mail-muted) 70%, transparent); }
.mail-password-wrap input:focus {
  outline: none;
  border-color: var(--mail-teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mail-teal) 15%, transparent);
}

.mail-password-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
  padding: 4px 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--mail-muted);
  font: inherit;
  font-size: 10px;
  cursor: pointer;
}

.mail-password-toggle:hover,
.mail-password-toggle:focus-visible {
  color: var(--mail-teal);
  background: var(--mail-teal-soft);
  outline: none;
}

.mail-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 38px;
  margin-top: 9px;
  border: 1px solid var(--mail-teal);
  border-radius: 9px;
  background: var(--mail-teal);
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}

.mail-submit:hover { background: var(--mail-teal-deep); border-color: var(--mail-teal-deep); }
.mail-submit:disabled { cursor: wait; opacity: .7; }
.mail-submit.is-loading .mail-submit-arrow {
  width: 10px;
  height: 10px;
  border: 1.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  font-size: 0;
  animation: mail-spin .7s linear infinite;
}
.mail-submit-arrow { font-size: 13px; line-height: 1; }

.mail-flash {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: -8px 0 20px;
  padding: 10px 12px;
  border: 1px solid var(--mail-line);
  border-radius: 10px;
  color: var(--mail-text);
  background: var(--mail-teal-soft);
  font-size: 11.5px;
  line-height: 1.55;
}

.mail-flash-dot {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--mail-teal);
}

.mail-flash--error {
  color: #b23b2b;
  border-color: color-mix(in srgb, #c0492f 25%, var(--mail-line));
  background: color-mix(in srgb, #c0492f 7%, var(--mail-card));
}
.mail-flash--error .mail-flash-dot { background: #c0492f; }

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

@media (max-width: 900px) {
  .mail-login-shell {
    display: flex;
    flex-direction: column;
    min-height: 100svh;
    overflow: visible;
  }

  .mail-visual {
    position: relative;
    inset: auto;
    order: -1;
    height: 34svh;
    min-height: 230px;
  }

  .mail-visual img { object-position: center 38%; }

  .mail-visual::before {
    background:
      linear-gradient(0deg, var(--mail-card) 0%, color-mix(in srgb, var(--mail-card) 58%, transparent) 18%, transparent 52%),
      linear-gradient(180deg, rgba(5,27,31,.15), transparent 30%);
  }

  .mail-visual-caption { right: 18px; bottom: 16px; }

  .mail-form-panel {
    width: 100%;
    min-height: 0;
    padding: 26px 24px 24px;
  }

  .mail-form-panel::after { display: none; }

  .mail-brand {
    position: static;
    margin: 0 auto 26px;
    max-width: 480px;
  }

  .mail-form-main {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0;
  }

  .mail-login-intro { margin-bottom: 22px; }
  .mail-login-intro h1 { font-size: 27px; white-space: normal; }

  .mail-admin-fallback {
    position: static;
    width: 100%;
    max-width: 480px;
    margin: 28px auto 0;
  }

  .mail-admin-form {
    position: static;
    margin-top: 10px;
  }

  .mail-form-foot {
    position: static;
    justify-content: center;
    margin-top: 22px;
    padding-bottom: 2px;
  }

  .mail-form-foot span:first-child { display: inline; }
}

@media (max-width: 460px) {
  .mail-visual { height: 29svh; min-height: 200px; }
  .mail-form-panel { padding: 22px 18px 20px; }
  .mail-brand { margin-bottom: 22px; }
  .mail-login-intro h1 { font-size: 24px; }
  .mail-intro-sub { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .mail-login-body *,
  .mail-login-body *::before,
  .mail-login-body *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---- explicit theme, neutral dark palette ---- */
:root {
  --mail-action-bg: var(--mail-teal);
  --mail-action-text: #ffffff;
  --mail-action-hover: var(--mail-teal-deep);
}

:root[data-theme="light"] {
  --mail-teal: #3f7d8c;
  --mail-teal-deep: #0b3037;
  --mail-teal-soft: #eaf2f2;
  --mail-amber: #d99429;
  --mail-page: #f7f8f6;
  --mail-card: #ffffff;
  --mail-text: #14262b;
  --mail-muted: #6d7e82;
  --mail-line: #e4eae8;
  --mail-cta: #123c43;
  --mail-cta-text: #ffffff;
  --mail-action-bg: #123c43;
  --mail-action-text: #ffffff;
  --mail-action-hover: #0b3037;
}

:root[data-theme="dark"] {
  --mail-teal: #c8cfd2;
  --mail-teal-deep: #343b40;
  --mail-teal-soft: #1b2023;
  --mail-amber: #b8a174;
  --mail-page: #0b0f12;
  --mail-card: #12171a;
  --mail-text: #e7ecee;
  --mail-muted: #8d999e;
  --mail-line: #283136;
  --mail-cta: #242a2e;
  --mail-cta-text: #f1f4f5;
  --mail-shadow: 0 28px 80px rgba(0, 0, 0, .42);
  --mail-action-bg: #242a2e;
  --mail-action-text: #f1f4f5;
  --mail-action-hover: #343b40;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mail-teal: #c8cfd2;
    --mail-teal-deep: #343b40;
    --mail-teal-soft: #1b2023;
    --mail-amber: #b8a174;
    --mail-page: #0b0f12;
    --mail-card: #12171a;
    --mail-text: #e7ecee;
    --mail-muted: #8d999e;
    --mail-line: #283136;
    --mail-cta: #242a2e;
    --mail-cta-text: #f1f4f5;
    --mail-shadow: 0 28px 80px rgba(0, 0, 0, .42);
    --mail-action-bg: #242a2e;
    --mail-action-text: #f1f4f5;
    --mail-action-hover: #343b40;
  }
}

.mail-submit {
  background: var(--mail-action-bg);
  border-color: var(--mail-action-bg);
  color: var(--mail-action-text);
}
.mail-submit:hover {
  background: var(--mail-action-hover);
  border-color: var(--mail-action-hover);
}
.mail-submit.is-loading .mail-submit-arrow {
  border-color: color-mix(in srgb, var(--mail-action-text) 38%, transparent);
  border-top-color: var(--mail-action-text);
}
.mail-sso-btn:hover {
  background: var(--mail-action-hover);
  border-color: var(--mail-action-hover);
}

/* theme toggle (login, top-right of the form panel) */
.mail-theme-toggle {
  position: absolute;
  top: clamp(28px, 5vw, 58px);
  right: clamp(28px, 5vw, 58px);
  z-index: 4;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--mail-line);
  border-radius: 11px;
  background: var(--mail-card);
  color: var(--mail-muted);
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease, background .18s ease;
}
.mail-theme-toggle:hover {
  color: var(--mail-text);
  border-color: var(--mail-text);
  background: var(--mail-teal-soft);
}
.mail-theme-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--mail-teal) 36%, transparent);
  outline-offset: 2px;
}

.theme-icon-sun { display: none; }
.theme-icon-moon { display: block; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-icon-moon { display: none; }
}

@media (max-width: 900px) {
  .mail-theme-toggle {
    top: 22px;
    right: 22px;
    width: 32px;
    height: 32px;
  }
}

/* Theme-controlled SSO backdrop images (explicit toggle + system fallback). */
.mail-bg-img--dark { display: none; }
:root[data-theme="dark"] .mail-bg-img--dark { display: block; }
:root[data-theme="dark"] .mail-bg-img--light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mail-bg-img--dark { display: block; }
  :root:not([data-theme="light"]) .mail-bg-img--light { display: none; }
}

/* Higher-specificity display switch (beats .mail-visual img { display:block }). */
.mail-visual img.mail-bg-img--light { display: block; }
.mail-visual img.mail-bg-img--dark { display: none; }
:root[data-theme="dark"] .mail-visual img.mail-bg-img--light { display: none; }
:root[data-theme="dark"] .mail-visual img.mail-bg-img--dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mail-visual img.mail-bg-img--light { display: none; }
  :root:not([data-theme="light"]) .mail-visual img.mail-bg-img--dark { display: block; }
}

/* Dark theme: strictly neutral grays, no cyan/blue cast. */
:root[data-theme="dark"] {
  --mail-teal: #c9c9c9;
  --mail-teal-deep: #333333;
  --mail-teal-soft: #1a1a1a;
  --mail-amber: #b9b9b9;
  --mail-page: #0b0b0b;
  --mail-card: #121212;
  --mail-text: #e8e8e8;
  --mail-muted: #8f8f8f;
  --mail-line: #2a2a2a;
  --mail-cta: #242424;
  --mail-cta-text: #f2f2f2;
  --mail-action-bg: #242424;
  --mail-action-text: #f2f2f2;
  --mail-action-hover: #333333;
  --mail-shadow: 0 28px 80px rgba(0, 0, 0, .42);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mail-teal: #c9c9c9;
    --mail-teal-deep: #333333;
    --mail-teal-soft: #1a1a1a;
    --mail-amber: #b9b9b9;
    --mail-page: #0b0b0b;
    --mail-card: #121212;
    --mail-text: #e8e8e8;
    --mail-muted: #8f8f8f;
    --mail-line: #2a2a2a;
    --mail-cta: #242424;
    --mail-cta-text: #f2f2f2;
    --mail-action-bg: #242424;
    --mail-action-text: #f2f2f2;
    --mail-action-hover: #333333;
    --mail-shadow: 0 28px 80px rgba(0, 0, 0, .42);
  }
}

/* Neutralize remaining dark-only overlays that had a blue-green tint. */
:root[data-theme="dark"] .mail-visual::before,
:root[data-theme="dark"] .mail-visual::after {
  background-color: transparent;
}
:root[data-theme="dark"] .mail-visual::before {
  background: linear-gradient(0deg, rgba(0, 0, 0, .18) 0%, transparent 26%);
}
:root[data-theme="dark"] .mail-visual::after {
  background-image: radial-gradient(rgba(255,255,255,.7) .7px, transparent .7px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mail-visual::before {
    background: linear-gradient(0deg, rgba(0, 0, 0, .18) 0%, transparent 26%);
  }
}

/* Dark theme: neutral surfaces, cyan restored on theme-color accents. */
:root[data-theme="dark"] {
  --mail-teal: #7cc8d2;
  --mail-teal-deep: #5aaab5;
  --mail-teal-soft: #13282c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mail-teal: #7cc8d2;
    --mail-teal-deep: #5aaab5;
    --mail-teal-soft: #13282c;
  }
}
.mail-sso-icon {
  color: var(--mail-teal);
}

/* Match light mode's theme-color usage: CTA, submit, accent text/icons/focus. */
:root[data-theme="dark"] {
  --mail-teal: #7cc8d2;
  --mail-teal-deep: #a5e0e6;
  --mail-teal-soft: #13282c;
  --mail-cta: #7cc8d2;
  --mail-cta-text: #07191c;
  --mail-action-bg: #7cc8d2;
  --mail-action-text: #07191c;
  --mail-action-hover: #a5e0e6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mail-teal: #7cc8d2;
    --mail-teal-deep: #a5e0e6;
    --mail-teal-soft: #13282c;
    --mail-cta: #7cc8d2;
    --mail-cta-text: #07191c;
    --mail-action-bg: #7cc8d2;
    --mail-action-text: #07191c;
    --mail-action-hover: #a5e0e6;
  }
}
.mail-sso-icon {
  color: var(--mail-cta-text);
}
.mail-sso-btn:hover {
  color: var(--mail-cta-text);
}
