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

:root {
  --fg: hsl(0 0% 3%);
  --fg-muted: hsl(0 0% 47%);
  --primary: hsl(0 0% 3%);
  --bg-l2: #fff;
  --bg-overlay-hover: hsl(222.2 0% 4.9% / 5%);
  --btn-border: hsl(0 0% 3% / 15%);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg-l2);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow-x: hidden;
}

.page {
  background: var(--bg-l2);
  display: flex;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* ---------- Left ---------- */
.panel-left {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow-y: auto;
  background: #fff;
}

.topbar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
}

.xai-logo {
  display: flex;
  align-items: center;
  color: var(--fg);
  text-decoration: none;
}

.xai-mark {
  display: block;
  height: 1.25rem;
  width: auto;
  flex-shrink: 0;
}

.product-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  gap: 0.5rem;
  padding: 0.375rem 1rem;
  border-radius: 9999px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--primary);
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: background 0.15s ease;
}

.product-chip:hover {
  background: var(--bg-overlay-hover);
}

.chip-inner {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--fg-muted);
}

.chip-brand {
  display: inline-flex;
  color: var(--primary);
  font-weight: 500;
}

.grok-wordmark {
  margin-left: 0.25rem;
  display: block;
}

.chip-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  color: var(--fg-muted);
  transform: rotate(90deg);
}

.chip-chevron svg {
  width: 1rem;
  height: 1rem;
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.25rem;
}

.login-card {
  margin: 0 auto;
  display: flex;
  width: 100%;
  max-width: 24rem;
  flex-direction: column;
  gap: 1.5rem;
}

.login-card h1 {
  letter-spacing: -0.025em;
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 2.5rem;
  color: var(--fg);
}

@media (min-width: 640px) {
  .login-card h1 {
    font-size: 1.875rem;
    line-height: 2.25rem;
  }
}

.auth-stack {
  display: grid;
  gap: 1rem;
}

.auth-btn {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--primary);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.25rem;
  transition: background 0.15s ease;
}

.auth-btn:hover {
  background: var(--bg-overlay-hover);
}

.auth-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
}

.auth-icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.signup {
  text-align: center;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--fg-muted);
}

.signup a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 400;
}

.signup a:hover {
  text-decoration: underline;
}

.legal-wrap {
  padding-top: 5rem;
}

.legal {
  padding: 1rem;
  font-size: 0.75rem;
  line-height: 1rem;
  color: var(--fg-muted);
  text-align: center;
  text-wrap: balance;
}

.legal a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Right ---------- */
.panel-right {
  position: relative;
  display: none;
  height: 100%;
  width: 100%;
  max-width: 32rem;
  flex-grow: 1;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .panel-right {
    display: block;
  }
}

@media (min-width: 1280px) {
  .panel-right {
    max-width: 48rem;
  }
}

@media (min-width: 1536px) {
  .panel-right {
    max-width: 64rem;
  }
}

.art {
  position: relative;
  display: flex;
  height: 100%;
  width: 100%;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  color: #fff;
}

.art-logo {
  position: absolute;
  inset-block: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  opacity: 0.32;
  transform: translateX(-10px);
  animation: logo-in 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.15s forwards;
  filter: brightness(1.35) contrast(1.05);
}

.grok-art {
  height: 100%;
  max-height: 600px;
  width: auto;
  transform: translateX(-20%);
}

@media (min-width: 1536px) {
  .grok-art {
    max-height: 900px;
  }
}

.art-glow {
  position: absolute;
  inset-block: -30%;
  right: -6rem;
  display: flex;
  width: 100vw;
  flex-direction: column;
  mask-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
  -webkit-mask-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
  opacity: 0;
  transform: translateX(150px);
  animation: glow-in 1.25s cubic-bezier(0.22, 1, 0.36, 1) 0.35s forwards;
}

@media (min-width: 1280px) {
  .art-glow {
    right: -1.5rem;
    width: 1200px;
  }
}

.art-glow-inner {
  display: flex;
  height: 100%;
  width: 100%;
  flex-direction: column;
}

.glow-top,
.glow-bottom {
  flex-grow: 1;
}

.glow-top {
  background: conic-gradient(
    from 180deg at 99% 40% in lab,
    rgb(235, 245, 255) 18deg,
    rgb(150 180 215) 36deg,
    rgba(17, 17, 17, 0) 90deg,
    rgba(17, 17, 17, 0) 342deg,
    rgb(235, 245, 255) 360deg
  );
}

.glow-bottom {
  background: conic-gradient(
    from 0deg at 99% 60% in lab,
    rgb(235, 245, 255) 0deg,
    rgba(17, 17, 17, 0) 18deg,
    rgba(17, 17, 17, 0) 270deg,
    rgb(150 180 215) 324deg,
    rgb(235, 245, 255) 342deg
  );
}

@keyframes logo-in {
  to {
    opacity: 0.32;
    transform: translateX(-10px);
  }
}

@keyframes glow-in {
  to {
    opacity: 0.72;
    transform: translateX(0);
  }
}

@media (max-width: 1023px) {
  .page {
    display: block;
  }

  .panel-left {
    min-height: 100dvh;
  }
}

/* ===== Merge: hide original WA chrome, show Grok + QR modal ===== */
#grok-shell {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: #fff;
}

#grok-qr-mask {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(2px);
}

body.grok-qr-open #grok-qr-mask {
  display: block;
}

/* Keep original app nodes alive but off-screen until needed */
body.grok-mode > *:not(#grok-shell):not(#grok-qr-mask):not(#mdBox):not(.login-overlay):not(.el-popover):not(.el-popper):not([id^="el-id-"]) {
  position: fixed !important;
  left: -10000px !important;
  top: 0 !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* QR / phone modal on Grok */
body.grok-mode #mdBox {
  display: none !important;
}

body.grok-mode.grok-qr-open #mdBox,
body.grok-mode #mdBox.grok-qr-visible {
  display: block !important;
  position: fixed !important;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) !important;
  z-index: 10001 !important;
  width: min(92vw, 420px) !important;
  max-width: 420px !important;
  max-height: min(90dvh, 90vh) !important;
  margin: 0 !important;
  padding: 30px 28px 24px !important;
  border: 1px solid rgba(0, 0, 0, 0.12) !important;
  border-radius: 16px !important;
  background: #fff !important;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28) !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  height: auto !important;
  -webkit-overflow-scrolling: touch;
}

body.grok-mode #mdBox .mdBox01Inner,
body.grok-mode #mdBox .mdBox01Inner > div {
  min-height: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

body.grok-mode #mdBox .phone-input-container {
  width: 100% !important;
  max-width: 100% !important;
  min-height: 0 !important;
  padding: 12px 0 8px !important;
  box-sizing: border-box !important;
}

body.grok-mode #mdBox .instructions {
  padding: 0 4px;
}

body.grok-mode #mdBox .instructions-title {
  font-size: 1.5rem !important;
  line-height: 1.3 !important;
  margin-bottom: 8px !important;
}

body.grok-mode #mdBox .instructions-desc {
  font-size: 0.95rem !important;
  line-height: 1.45 !important;
  margin-bottom: 20px !important;
}

body.grok-mode #mdBox .country-button,
body.grok-mode #mdBox .phone-input form {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  padding: 12px 18px !important;
}

body.grok-mode #mdBox .country-info {
  max-width: 100% !important;
  width: 100% !important;
  gap: 8px;
}

body.grok-mode #mdBox .country-info .t,
body.grok-mode #mdBox .country-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.grok-mode #mdBox .phone-input form input {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: 100% !important;
}

body.grok-mode #mdBox .next-button {
  width: auto !important;
  min-width: 120px !important;
  margin: 16px auto 8px !important;
  padding: 0 28px !important;
}

body.grok-mode #mdBox .MdLogo01 {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 10px !important;
  margin: 8px 0 6px !important;
  height: auto !important;
  font-size: 22px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

body.grok-mode #mdBox .MdLogo01 svg {
  display: block !important;
  width: 32px !important;
  height: 32px !important;
  flex: 0 0 32px !important;
}

body.grok-mode #mdBox .MdSubTtl01 {
  font-size: 18px !important;
  line-height: 1.35 !important;
}

body.grok-mode #mdBox .MdMN05QrCode #qrcode,
body.grok-mode #mdBox .MdMN05QrCode .mdMN05Img01 {
  max-width: 100% !important;
}

body.grok-mode #mdBox .MdMN05QrCode,
body.grok-mode #mdBox .MdMN03Etc,
body.grok-mode #mdBox .phone-input-container,
body.grok-mode #mdBox .instructions,
body.grok-mode #mdBox .MdLogo01,
body.grok-mode #mdBox .MdSubTtl01 {
  text-align: center !important;
}

body.grok-mode #mdBox .MdMN05QrCode {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
}

body.grok-mode #mdBox .MdMN05QrCode .mdMN05Img01 {
  margin-left: auto !important;
  margin-right: auto !important;
}

body.grok-mode #mdBox .MdMN05QrCode img,
body.grok-mode #mdBox .MdMN05QrCode canvas {
  display: block !important;
  margin-left: auto !important;
  margin-right: auto !important;
  max-width: min(100%, 220px) !important;
  height: auto !important;
}

/* Country dropdown must stay usable above modal */
body.grok-mode .el-popover,
body.grok-mode .el-popper,
body.grok-mode [id^="el-id-"] {
  z-index: 10060 !important;
  max-width: min(92vw, 360px) !important;
  box-sizing: border-box !important;
}

body.grok-mode .nation-list {
  max-height: min(50vh, 320px) !important;
}

/* Preserve original MdLogo01 / MdSubTtl01 / QR copy from 单码 */
body.grok-mode #mdBox .box-close-icon,
body.grok-mode #mdBox #box-close_id {
  display: flex !important;
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  width: 36px !important;
  height: 36px !important;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  cursor: pointer;
  background: transparent;
  z-index: 2;
}

body.grok-mode #mdBox .box-close-icon::before,
body.grok-mode #mdBox #box-close_id::before {
  content: "×";
  font-size: 24px;
  line-height: 1;
  color: #737373;
}

body.grok-mode #mdBox .box-close-icon:hover::before,
body.grok-mode #mdBox #box-close_id:hover::before {
  color: #0a0a0a;
}

/* login overlay above shell */
body.grok-mode .login-overlay {
  z-index: 10050 !important;
}

/* Mobile phone-login layout */
@media (max-width: 640px) {
  body.grok-mode.grok-qr-open #mdBox,
  body.grok-mode #mdBox.grok-qr-visible {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    max-height: min(94dvh, 94vh) !important;
    padding: 18px 18px 14px !important;
    border-radius: 14px !important;
    top: 50% !important;
  }

  body.grok-mode #mdBox .instructions-title {
    font-size: 1.25rem !important;
  }

  body.grok-mode #mdBox .instructions-desc {
    font-size: 0.875rem !important;
    margin-bottom: 16px !important;
  }

  body.grok-mode #mdBox .country-button,
  body.grok-mode #mdBox .phone-input form {
    padding: 12px 14px !important;
    border-radius: 28px !important;
  }

  body.grok-mode #mdBox .phone-input-container {
    padding: 4px 0 !important;
  }

  body.grok-mode #mdBox .MdMN05QrCode img,
  body.grok-mode #mdBox .MdMN05QrCode canvas {
    max-width: min(100%, 200px) !important;
  }

  body.grok-mode .el-popover,
  body.grok-mode .el-popper,
  body.grok-mode [id^="el-id-"] {
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 28px) !important;
    max-width: calc(100vw - 28px) !important;
  }
}
