/* ==========================================================================
   CrankUp — Live AI Demo Widget
   Namespaced .cu-demo-* so it can't collide with site styles.
   Consumes existing :root tokens (--gold, --bg, --surface, --border, fonts).
   WhatsApp green is used ONLY inside the chat surface as a deliberate, authentic
   WhatsApp homage; gold remains the section/CTA accent.
   ========================================================================== */

/* Section wrapper used by every embed (homepage, service, industry pages) */
.cu-demo-section {
  padding: 100px 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
@media (max-width: 768px) {
  .cu-demo-section { padding: 64px 0; }
}

.cu-demo {
  /* WhatsApp dark-mode palette — scoped to the widget only */
  --wa-app: #0b141a;       /* chat wallpaper */
  --wa-header: #1f2c33;    /* top bar */
  --wa-in: #202c33;        /* received bubble */
  --wa-out: #005c4b;       /* sent bubble (green) */
  --wa-text: #e9edef;      /* bubble text */
  --wa-meta: #8696a0;      /* timestamps / muted */
  --wa-online: #25d366;    /* online dot */
  --wa-tick: #53bdeb;      /* read ticks */

  max-width: 384px;
  margin: 0 auto;
  font-family: var(--font-body);
}

/* On the standalone /demo/ page and homepage we allow it a touch wider via phone frame */

/* ---------- Sector selector ---------- */
.cu-demo-selector {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.cu-demo-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: none;
  padding: 22px 24px;
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font-body);
  overflow: hidden;
  transition: background 0.25s ease;
}
.cu-demo-card:hover,
.cu-demo-card:focus-visible { background: var(--surface-hi); outline: none; }
.cu-demo-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 2px;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.cu-demo-card:hover::after,
.cu-demo-card:focus-visible::after { transform: scaleX(1); }
.cu-demo-card-icon {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: var(--gold-glow);
  border: 1px solid var(--gold-border);
  color: var(--gold);
  font-size: 18px;
}
.cu-demo-card-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cu-demo-card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.cu-demo-card-sub { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.cu-demo-card-go {
  margin-left: auto;
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 14px;
  transition: color 0.2s ease, transform 0.2s ease;
}
.cu-demo-card:hover .cu-demo-card-go { color: var(--gold); transform: translateX(3px); }

/* ---------- Phone frame (desktop only) ---------- */
.cu-demo-phone {
  position: relative;
  background: #0a0a0a;
  border: 10px solid #161616;
  border-radius: 38px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
/* ---------- Chat shell ---------- */
.cu-demo-chat {
  display: flex;
  flex-direction: column;
  height: 720px;
  background: var(--wa-app);
  border-radius: 28px;
  overflow: hidden;
}

/* Phone status bar (time + island + icons) — only inside the desktop phone frame */
.cu-demo-statusbar {
  position: relative;
  flex: 0 0 auto;
  height: 36px;
  background: var(--wa-header);
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  color: var(--wa-text);
  font-size: 12px;
  font-weight: 600;
}
.cu-demo-phone .cu-demo-statusbar { display: flex; }
.cu-demo-statusbar::before { /* dynamic island */
  content: '';
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  width: 84px; height: 20px;
  background: #000;
  border-radius: 12px;
}
.cu-demo-sb-icons { display: inline-flex; gap: 6px; font-size: 11px; }
.cu-demo-phone .cu-demo-chat { border-radius: 0; }
/* When shown without a phone frame (mobile / inline fallback) */
.cu-demo-chat.is-bare {
  border: 1px solid var(--border);
  border-radius: 12px;
  height: 540px;
}

/* Header */
.cu-demo-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--wa-header);
  border-bottom: 1px solid rgba(0, 0, 0, 0.3);
  flex: 0 0 auto;
}
.cu-demo-back {
  background: none; border: none; cursor: pointer;
  color: var(--wa-meta); font-size: 18px; padding: 2px 4px;
  display: none;
}
.cu-demo-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--gold-gradient, linear-gradient(135deg, #F0D880, #C9A84C));
  color: #1a1400;
  font-size: 18px;
  flex: 0 0 auto;
}
.cu-demo-head-info { display: flex; flex-direction: column; min-width: 0; }
.cu-demo-head-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--wa-text);
  letter-spacing: -0.01em;
}
.cu-demo-head-status {
  font-size: 12px;
  color: var(--wa-meta);
  display: flex; align-items: center; gap: 6px;
}
.cu-demo-online-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--wa-online);
  display: inline-block;
}
.cu-demo-head-switch {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: var(--wa-meta); font-size: 16px; padding: 6px;
  transition: color 0.2s ease;
}
.cu-demo-head-switch:hover { color: var(--gold); }

/* Message stream */
.cu-demo-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--wa-app);
  /* subtle texture without an external asset */
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 22px 22px;
  scrollbar-width: thin;
  scrollbar-color: #2a3942 transparent;
}
.cu-demo-body::-webkit-scrollbar { width: 6px; }
.cu-demo-body::-webkit-scrollbar-thumb { background: #2a3942; border-radius: 3px; }

.cu-msg {
  max-width: 80%;
  padding: 7px 11px 6px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--wa-text);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.cu-msg.in {
  align-self: flex-start;
  background: var(--wa-in);
  border-top-left-radius: 3px;
}
.cu-msg.out {
  align-self: flex-end;
  background: var(--wa-out);
  border-top-right-radius: 3px;
}
.cu-msg-time {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: var(--wa-meta);
  margin-top: 2px;
  line-height: 1;
}
.cu-msg.out .cu-msg-time { color: rgba(233, 237, 239, 0.6); }
.cu-msg.out .cu-msg-time::after {
  content: ' \2713\2713';
  color: var(--wa-tick);
}

/* Typing indicator */
.cu-demo-typing {
  align-self: flex-start;
  background: var(--wa-in);
  border-radius: 10px;
  border-top-left-radius: 3px;
  padding: 11px 14px;
  display: inline-flex;
  gap: 4px;
}
.cu-demo-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--wa-meta);
  display: inline-block;
}

/* System / error notice line */
.cu-demo-notice {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 12.5px;
  color: var(--wa-meta);
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  line-height: 1.5;
}
.cu-demo-notice a { color: var(--wa-online); text-decoration: none; font-weight: 600; }

/* Footer / input */
.cu-demo-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--wa-header);
  border-top: 1px solid rgba(0, 0, 0, 0.3);
}
.cu-demo-input {
  flex: 1 1 auto;
  min-width: 0; /* allow shrink-to-fit on narrow phones (flex item default min-width is auto) */
  resize: none;
  max-height: 96px;
  min-height: 22px;
  background: #2a3942;
  border: none;
  border-radius: 18px;
  padding: 10px 14px;
  color: var(--wa-text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.4;
  outline: none;
}
.cu-demo-input::placeholder { color: var(--wa-meta); }
.cu-demo-input:disabled { opacity: 0.6; }
.cu-demo-send {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: #000;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.cu-demo-send:hover { opacity: 0.9; }
.cu-demo-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Inline email capture */
.cu-demo-email {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--wa-header);
  border-top: 1px solid rgba(0, 0, 0, 0.3);
}
.cu-demo-email input {
  flex: 1 1 auto;
  min-width: 0; /* allow shrink-to-fit on narrow phones */
  background: #2a3942;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--wa-text);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}
.cu-demo-email input::placeholder { color: var(--wa-meta); }
.cu-demo-email input:focus { border-color: var(--gold); }
.cu-demo-email input.is-invalid { border-color: #e0584a; }
.cu-demo-email button {
  flex: 0 0 auto;
  background: var(--gold);
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s ease;
}
.cu-demo-email button:hover { opacity: 0.9; }
.cu-demo-email button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Disclaimer under widget */
.cu-demo-disclaimer {
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ---------- Animations (reduced-motion safe) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .cu-msg, .cu-demo-typing, .cu-demo-notice {
    animation: cuMsgIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  @keyframes cuMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .cu-demo-typing span { animation: cuTyping 1.2s infinite ease-in-out; }
  .cu-demo-typing span:nth-child(2) { animation-delay: 0.18s; }
  .cu-demo-typing span:nth-child(3) { animation-delay: 0.36s; }
  @keyframes cuTyping {
    0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .cu-demo { max-width: 100%; }
  .cu-demo-phone {
    border: none;
    border-radius: 12px;
    box-shadow: none;
    background: transparent;
    padding: 0;
  }
  .cu-demo-statusbar { display: none !important; }
  .cu-demo-chat {
    border-radius: 12px;
    border: 1px solid var(--border);
    height: 70vh;
    min-height: 460px;
    max-height: 620px;
  }
  .cu-demo-phone .cu-demo-chat { border-radius: 12px; }
}
