/* ============================================================
 * Trina Solar AI Assistant - chat widget styles (replaces the iframe)
 * Companion to js/ai-assistant.js; container .trina-ai[data-assistant-chat]
 *
 * Ported from Child-CN/css/moudle/ai-assistant.css. The entry point and modal
 * shell that live in Child-CN/css/moudle/main.css are appended at the bottom of
 * this file, so the whole feature ships in one stylesheet.
 * ============================================================ */

.trina-ai {
    --trina-ai-primary: #005ea8;
    --trina-ai-primary-dark: #004a87;
    --trina-ai-ink: #34566e;
    --trina-ai-ink-light: #7a94a6;
    --trina-ai-bg: #f4f9fd;
    --trina-ai-bubble-user: linear-gradient(135deg, #0a78c2, #005ea8);
    --trina-ai-border: #e3edf5;
    --trina-ai-radius: 14px;

    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: #fff;
    font-family: inherit;
    color: var(--trina-ai-ink);
    font-size: 15px;
    line-height: 1.65;
}

/* ---------------- header ---------------- */

.trina-ai__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 52px 14px 20px; /* right padding leaves room for the modal close button */
    background: var(--trina-ai-primary);
    color: #fff;
    flex: none;
}

.trina-ai__header-id {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.trina-ai__header-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 33, 61, 0.25);
}

.trina-ai__header-avatar img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.trina-ai__header-name {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.trina-ai__newchat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: background 160ms ease;
    flex: none;
}

.trina-ai__newchat:hover:not(:disabled),
.trina-ai__newchat:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    outline: none;
}

.trina-ai__newchat:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.trina-ai__newchat svg {
    width: 13px;
    height: 13px;
}

/* ---------------- message area ---------------- */

.trina-ai__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 12px;
    background: var(--trina-ai-bg);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #c6d8e6 transparent;
}

.trina-ai__messages::-webkit-scrollbar {
    width: 5px;
}

.trina-ai__messages::-webkit-scrollbar-thumb {
    background: #c6d8e6;
    border-radius: 3px;
}

/* welcome screen */

.trina-ai__welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 46px 12px 20px;
}

.trina-ai__welcome-icon {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 94, 168, 0.18);
    margin-bottom: 18px;
}

.trina-ai__welcome-icon img {
    width: 46px;
    height: 46px;
    object-fit: contain;
}

.trina-ai__welcome-title {
    margin: 0 0 8px;
    font-size: 19px;
    font-weight: 600;
    color: var(--trina-ai-ink);
}

.trina-ai__welcome-text {
    margin: 0 0 26px;
    font-size: 14px;
    color: var(--trina-ai-ink-light);
}

.trina-ai__welcome-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

/* suggested-question chips */

.trina-ai__chip {
    padding: 8px 14px;
    border: 1px solid var(--trina-ai-border);
    border-radius: 999px;
    background: #fff;
    color: var(--trina-ai-primary);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color 160ms ease, background 160ms ease;
    max-width: 100%;
    text-align: left;
}

.trina-ai__chip:hover,
.trina-ai__chip:focus-visible {
    border-color: var(--trina-ai-primary);
    background: #fff;
    outline: none;
}

/* message bubbles */

.trina-ai__msg {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
}

.trina-ai__msg--user {
    justify-content: flex-end;
}

.trina-ai__msg-avatar {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid var(--trina-ai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-top: 2px;
}

.trina-ai__msg-avatar img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.trina-ai__msg-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 86%;
}

.trina-ai__bubble {
    padding: 10px 14px;
    border-radius: var(--trina-ai-radius);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.trina-ai__msg--user .trina-ai__bubble {
    background: var(--trina-ai-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: normal;
}

.trina-ai__msg--assistant .trina-ai__bubble {
    background: #fff;
    border: 1px solid var(--trina-ai-border);
    border-bottom-left-radius: 4px;
}

/* thinking animation */

.trina-ai__thinking {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.trina-ai__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--trina-ai-primary);
    opacity: 0.35;
    animation: trinaAiDot 1.2s infinite ease-in-out;
}

.trina-ai__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.trina-ai__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes trinaAiDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* streaming stage hint (Searching the knowledge base…) */

.trina-ai__stage-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--trina-ai-ink-light);
}

.trina-ai__stage-text::before {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid var(--trina-ai-border);
    border-top-color: var(--trina-ai-primary);
    border-radius: 50%;
    animation: trinaAiSpin 0.8s linear infinite;
    flex: none;
}

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

/* typewriter caret */

.trina-ai__caret {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: -0.15em;
    background: var(--trina-ai-primary);
    animation: trinaAiBlink 0.9s step-end infinite;
}

@keyframes trinaAiBlink {
    50% { opacity: 0; }
}

/* stopped / error / retry */

.trina-ai__stopped {
    margin-top: 6px;
    font-size: 12px;
    color: var(--trina-ai-ink-light);
}

.trina-ai__error {
    color: #c0392b;
    font-size: 14px;
}

.trina-ai__retry {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding: 2px 10px;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: transparent;
    color: inherit;
    font-size: 12.5px;
    cursor: pointer;
}

.trina-ai__retry:hover {
    opacity: 0.75;
}

/* feedback buttons */

.trina-ai__msg-tools {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-left: 2px;
}

.trina-ai__fb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--trina-ai-ink-light);
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

.trina-ai__fb:hover,
.trina-ai__fb:focus-visible {
    background: #e8f2fa;
    color: var(--trina-ai-primary);
    outline: none;
}

.trina-ai__fb.is-active {
    color: var(--trina-ai-primary);
    background: #e8f2fa;
}

/* ---------------- suggestion bar above the input ---------------- */

.trina-ai__suggested {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 10px 18px 0;
    background: var(--trina-ai-bg);
}

.trina-ai__suggested-label {
    flex: none;
    font-size: 12.5px;
    color: var(--trina-ai-ink-light);
}

/* welcome-screen link bar - anchors reuse the chip look */
a.trina-ai__chip {
    display: inline-block;
    text-decoration: none;
    box-sizing: border-box;
}

a.trina-ai__chip:hover,
a.trina-ai__chip:focus-visible {
    text-decoration: none;
    color: var(--trina-ai-primary);
}

/* ---------------- input area ---------------- */

.trina-ai__footer {
    display: block;
    flex: none;
    padding: 12px 18px;
    background: #fff;
    border-top: 1px solid var(--trina-ai-border);
    box-sizing: border-box;
}

.trina-ai__inputwrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 8px 8px 8px 14px;
    border: 1px solid var(--trina-ai-border);
    border-radius: 22px;
    background: #fff;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.trina-ai__inputwrap:focus-within {
    border-color: var(--trina-ai-primary);
    box-shadow: 0 0 0 3px rgba(0, 94, 168, 0.12);
}

.trina-ai__input {
    flex: 1;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    font: inherit;
    color: var(--trina-ai-ink);
    line-height: 1.5;
    max-height: 120px;
    padding: 4px 0;
}

.trina-ai__input::placeholder {
    color: #a4b8c6;
}

.trina-ai__input:disabled {
    opacity: 0.6;
}

.trina-ai__send {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: var(--trina-ai-primary);
    color: #fff;
    cursor: pointer;
    transition: background 160ms ease, transform 120ms ease;
}

.trina-ai__send:hover:not(:disabled) {
    background: var(--trina-ai-primary-dark);
    transform: translateY(-1px);
}

.trina-ai__send:focus-visible {
    outline: 2px solid var(--trina-ai-primary-dark);
    outline-offset: 2px;
}

.trina-ai__send.is-stop {
    background: #fff;
    color: var(--trina-ai-primary);
    border: 1px solid var(--trina-ai-primary);
}

.trina-ai__send svg {
    display: block;
}

.trina-ai__disclaimer {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 2px 12px;
    margin: 8px 4px 0;
    font-size: 12px;
}

/* English copy is longer than the CN original, so the row is allowed to wrap
   and the links get an explicit style instead of inheriting the theme anchor look. */
.trina-ai__disclaimer a {
    color: var(--trina-ai-primary);
    text-decoration: none;
    font-weight: 600;
}

.trina-ai__disclaimer a:hover,
.trina-ai__disclaimer a:focus-visible {
    text-decoration: underline;
    text-underline-offset: 2px;
    outline: none;
}

/* Selector was ".ai__disclaimer .tip" upstream (missing the trina- prefix), so it never matched. */
.trina-ai__disclaimer .tip {
    font-size: 11.5px;
    color: #a4b8c6;
}

/* ---------------- Markdown elements ---------------- */

.trina-ai__md .trina-ai__md-p {
    margin: 0 0 8px;
}

.trina-ai__md .trina-ai__md-p:last-child {
    margin-bottom: 0;
}

.trina-ai__md .trina-ai__md-h {
    margin: 10px 0 6px;
    font-weight: 600;
    color: var(--trina-ai-ink);
    line-height: 1.4;
}

.trina-ai__md h3.trina-ai__md-h { font-size: 16px; }
.trina-ai__md h4.trina-ai__md-h,
.trina-ai__md h5.trina-ai__md-h { font-size: 15px; }

.trina-ai__md .trina-ai__md-list {
    margin: 0 0 8px;
    padding-left: 20px;
}

.trina-ai__md .trina-ai__md-list li {
    margin: 2px 0;
}

.trina-ai__md .trina-ai__md-code {
    margin: 8px 0;
    padding: 10px 12px;
    background: #0f2b46;
    color: #dcebf7;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.55;
    font-family: Menlo, Consolas, monospace;
}

.trina-ai__md-code-inline {
    padding: 1px 6px;
    background: #e8f2fa;
    border-radius: 4px;
    font-size: 0.92em;
    font-family: Menlo, Consolas, monospace;
    color: #0a5d9f;
}

.trina-ai__md .trina-ai__md-quote {
    margin: 8px 0;
    padding: 6px 12px;
    border-left: 3px solid var(--trina-ai-primary);
    background: #eef6fc;
    color: #4d6b80;
    border-radius: 0 8px 8px 0;
}

.trina-ai__md .trina-ai__md-hr {
    border: 0;
    border-top: 1px solid var(--trina-ai-border);
    margin: 10px 0;
}

.trina-ai__md-table-wrap {
    margin: 8px 0;
    overflow-x: auto;
    border: 1px solid var(--trina-ai-border);
    border-radius: 8px;
}

.trina-ai__md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.trina-ai__md-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--trina-ai-border);
}

.trina-ai__md-table tr:last-child td {
    border-bottom: 0;
}

.trina-ai__md a {
    color: var(--trina-ai-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.trina-ai__md strong {
    color: #234;
    font-weight: 600;
}

/* ---------------- mobile ---------------- */

@media screen and (max-width: 980px) {
    .trina-ai {
        font-size: 14.5px;
    }

    .trina-ai__header {
        padding: 12px 48px 12px 14px;
    }

    .trina-ai__header-name {
        font-size: 16px;
    }

    .trina-ai__newchat span {
        display: none;
    }

    .trina-ai__messages {
        padding: 14px 12px 8px;
    }

    .trina-ai__msg-body {
        max-width: 90%;
    }

    .trina-ai__footer {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .trina-ai__welcome {
        padding-top: 30px;
    }
}

/* honour the OS reduced-motion preference */

@media (prefers-reduced-motion: reduce) {
    .trina-ai__dot,
    .trina-ai__caret,
    .trina-ai__stage-text::before {
        animation: none;
    }
}

/* ============================================================
 * Entry point (floating mascot) + slide-in modal shell
 *
 * Ported from Child-CN/css/moudle/main.css (~line 6370). Two deliberate
 * differences from the CN version:
 *
 * 1. The hidden .floating-assistant__menu / __item rules are not carried over.
 *    Nothing ever reveals them in CN either (visibility: hidden with no hover or
 *    .is-open rule), and the global site already exposes both links elsewhere.
 *
 * 2. Position. The global site has two bottom-right floats already:
 *      .rightTipNew        (contact icon, footer.css)  bottom  30px, 45x45
 *      .trina-survey-float (mu-plugin, all non-CN)     bottom  86px, 45x45
 *    so the AI trigger stacks above them at bottom 139px rather than taking the
 *    corner. If either float moves, this offset has to move with it.
 * ============================================================ */

.floating-assistant {
  position: fixed;
  z-index: 9999;
  right: 26px;           /* centres the 52px trigger over the 45px icon column at right: 30px */
  bottom: 139px;         /* 86px survey float + 45px height + 8px gap */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.floating-assistant__trigger {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 160ms ease;
}

.floating-assistant__trigger:hover {
  transform: translateY(-2px);
}

.floating-assistant__trigger:focus-visible {
  outline: 3px solid #005ea8;
  outline-offset: 3px;
}

.floating-assistant__trigger img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* body class toggled while the panel is open */
.assistant-chat-open {
  overflow: hidden;
}

.assistant-chat-modal {
  position: fixed;
  z-index: 10000;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

.assistant-chat-modal.is-open {
  visibility: visible;
  pointer-events: auto;
}

.assistant-chat-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 33, 61, 0.45);
  opacity: 0;
  transition: opacity 200ms ease;
}

.assistant-chat-modal.is-open .assistant-chat-modal__backdrop {
  opacity: 1;
}

.assistant-chat-modal__panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100%;
  background: #fff;
  box-shadow: -12px 0 32px rgba(0, 33, 61, 0.22);
  transform: translateX(100%);
  transition: transform 240ms ease;
}

.assistant-chat-modal.is-open .assistant-chat-modal__panel {
  transform: translateX(0);
}

.assistant-chat-modal__close {
  position: absolute;
  z-index: 1;
  top: 18px;
  right: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #34566e;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.assistant-chat-modal__close:hover,
.assistant-chat-modal__close:focus-visible {
  background: #eaf6fd;
  color: #005ea8;
  outline: none;
}

.assistant-chat-modal__content {
  height: 100%;
  overflow: hidden;
}

@media screen and (max-width: 980px) {
  .floating-assistant {
    right: 0;
    bottom: 2.16rem;     /* 1.34rem survey float + 0.72rem height + 0.1rem gap */
  }

  .floating-assistant__trigger {
    width: 0.72rem;
    height: 0.72rem;
  }

  .assistant-chat-modal__panel {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .floating-assistant__trigger,
  .assistant-chat-modal__backdrop,
  .assistant-chat-modal__panel {
    transition: none;
  }
}
