/* Sparkle effect for embed trigger button only (single star at top-right) */
.sparkle-btn {
    position: relative;
    padding: 12px 28px;
    font-size: 18px;
    font-weight: bold;
    color: #fff; /* JS sets button text to white when primary color override is on */
    border: none;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
}

/* Big 4-point sparkle (concave sides), top-right */
.sparkle-btn::after {
    content: "";
    position: absolute;
    top: 0.35em;   /* scale with font for theme consistency */
    right: 0.40em;
    width: 0.5em;
    height: 0.5em;
    background: #fff;
    clip-path: polygon(
      50% 0%, 58% 26%, 100% 50%, 58% 74%, 50% 100%, 42% 74%, 0% 50%, 42% 26%
    );
    opacity: 0.95;
    filter: drop-shadow(0 0 4px rgba(255,255,255,0.9));
    animation: sparkle-top-right 2.2s ease-in-out infinite;
    animation-delay: 0s; /* big first */
}

/* Smaller sparkle slightly inward; alternates with big */
.sparkle-btn::before {
    content: none !important; /* ensure only one sparkle star is rendered */
}
@keyframes sparkle-top-right {
    0%, 100% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.15); opacity: 1; }
}



/* Chatbot Overlay */
.saber-chat-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    /* backdrop-filter: blur(8px); REMOVED */
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Floating action button (optional) */
.saber-chat-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    padding: 12px 18px;
    border-radius: 12px;
    display: none;
}

.saber-chat-overlay.is-open {
    display: block;
    opacity: 1;
}

/* Chat window - Centered Modal */
.saber-chat-window {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    width: 90vw;
    max-width: 1040px;
    height: 77vh;
    max-height: 630px;
    background-color: rgba(255, 255, 255, 0.75); /* 75% transparent */
    color: #333333;
    font-family: 'Karla', sans-serif;
    font-size: 14px; /* ensure readable base size independent of theme */
    line-height: 1.0; /* consistent readability across themes */
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border-radius: 12px;
    border: 1px solid rgba(234, 234, 234, 0.5);
    flex-direction: column;
    overflow: auto;          /* required for native resize handle */
    resize: both;            /* native browser resize */
    min-width: 360px;        /* keep layout usable */
    min-height: 360px;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease, top 0.3s ease;
    z-index: 1000;
    padding: 0;
}

.saber-chat-window.is-open {
    display: flex;
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Close Button */
.saber-chat-close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 5px;
    opacity: 0.7;
    transition: opacity 0.2s, transform 0.2s;
    /* Add flex centering for the character inside */
    display: flex;
    align-items: center;
    justify-content: center;
}
.saber-chat-close-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Messages area */
.saber-chat-messages {
    flex: 1 1 auto; /* occupy remaining space */
    min-height: 0;  /* allow scrolling area to shrink within flex container */
    overflow-y: auto;
    padding: 6px 12px; /* Reduced by 50% */
    background-color: transparent;
}

.saber-chat-message {
    margin-bottom: 16px;
    display: flex;
    max-width: 95%;
}

.saber-chat-message p {
    margin: 0;
    padding: 0;
    line-height: 1.3;
    word-wrap: break-word;
}

.saber-chat-message.user {
    flex-direction: column;
    align-items: flex-end;
    width: 100%;
}

.saber-chat-message.user p {
    font-size: 1.44em; /* 20% bigger */
    font-weight: 700; 
    font-family: 'EB Garamond', serif;
    background-color: rgba(238, 227, 217, 0.9);
    color: #333333;
    padding: 10px 14px;
    border-radius: 12px;
    border: none;
}

.saber-chat-message.bot {
    flex-direction: column;
    align-items: flex-start;
}

.saber-chat-message.bot p {
    background-color: rgba(248, 245, 242, 0.75);
    color: #333333;
    padding: 10px 14px; /* 30% smaller */
    border-radius: 12px;
    border: none;
}

/* AI Response Typography */
.saber-chat-message.bot h1,
.saber-chat-message.bot h2,
.saber-chat-message.bot h3 {
    font-family: 'Lora', serif;
    font-size: 1.3em; 
    font-weight: 600;
    margin-bottom: 10px;
}

.saber-chat-message.bot ul {
    padding-left: 0;
    margin: 10px 0 0 0;
    list-style: none;
}

.saber-chat-message.bot li {
    position: relative;
    padding-left: 20px;
    margin-bottom: 4px;
    line-height: 1.3;
}

.saber-chat-message.bot li::before {
    content: '•';
    position: absolute;
    left: 0;
    top: 0;
    color: #D4A373;
    font-size: 1.2em;
}

.saber-chat-message.loading p {
    display: flex;
    align-items: center;
}

.saber-chat-message.loading .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out both;
}

.saber-chat-message.loading .dot:nth-child(1) { animation-delay: -0.32s; }
.saber-chat-message.loading .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Input area */
.saber-chat-input-form {
    display: flex;
    align-items: center;
    padding: 6px 24px 10px;
    border-top: 1px solid rgba(234, 234, 234, 0.5);
    background-color: transparent;
    cursor: auto;
}

.saber-chat-input-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    border: 1px solid #EAEAEA;
    border-radius: 8px;
    padding: 4px;
    background-color: #fff; /* Keep input wrapper solid */
    overflow: hidden; /* prevent inner controls from spilling outside when focused */
}

.saber-chat-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    color: #333333;
    padding: 8px 12px;
    font-size: 1em;
    font-family: 'Karla', sans-serif;
}
.saber-chat-input:focus {
    outline: none;
}

.saber-chat-send-btn {
    border-radius: 6px;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 700;
    font-family: 'Karla', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, opacity 0.2s;
}

/* Remove unwanted theme borders on buttons in the chat UI */
.saber-chat-send-btn.button,
.saber-chat-fab.button,
.saber-chat-trigger-btn.button {
    border: none;
    box-shadow: none;
    outline: none;
    background-clip: padding-box;
}

/* Be extra explicit for themes that style .button--primary */
.saber-chat-send-btn,
.saber-chat-send-btn.button--primary,
.saber-chat-fab,
.saber-chat-fab.button--primary,
.saber-chat-trigger-btn,
.saber-chat-trigger-btn.button--primary {
    border: none;
    border-color: transparent;
    box-shadow: none;
    background-image: none;
    -webkit-appearance: none;
    appearance: none;
}

/* Kill borders/rings in all interaction states */
.saber-chat-send-btn:focus,
.saber-chat-send-btn:active,
.saber-chat-send-btn:focus-visible,
.saber-chat-fab:focus,
.saber-chat-fab:active,
.saber-chat-fab:focus-visible,
.saber-chat-trigger-btn:focus,
.saber-chat-trigger-btn:active,
.saber-chat-trigger-btn:focus-visible {
    outline: none;
    box-shadow: none;
    border: none;
}

/* Some themes draw borders via pseudo elements */
.saber-chat-fab::before,
.saber-chat-fab::after,
.saber-chat-trigger-btn::before,
.saber-chat-trigger-btn::after,
.saber-chat-send-btn::before,
.saber-chat-send-btn::after {
    box-shadow: none;
    border: none;
}

/* Header */
.saber-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: transparent;
    border-bottom: 1px solid rgba(234, 234, 234, 0.5);
    cursor: grab;
}

.saber-chat-header-text {
    display: flex;
    align-items: center; /* Use center alignment for better vertical consistency */
    line-height: 1.2;
}

.saber-chat-header-title {
    font-weight: bold;
    font-size: 0.9em;
    color: #333;
}

/* Footer */
.saber-chat-footer {
    text-align: center;
    padding: 8px 12px;
    font-size: 0.75em;
    color: #777777;
    background-color: transparent;
    border-top: 1px solid rgba(234, 234, 234, 0.5);
    cursor: auto;
}
.saber-chat-footer a {
    color: #333333;
    font-weight: 600;
    text-decoration: none;
}

/* Hide Powered by footer */
.saber-powered-by { display: none !important; }

/* New Trigger Form Styles - hidden by default; shown by JS after status check */
.saber-chat-trigger {
    display: none;
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    margin: 0;
    background-color: #fff;
    box-sizing: border-box;
    min-height: 48px;
}
.saber-chat-trigger-input {
    flex: 1;
    border: none;
    background: transparent;
    color: #374151;
    padding: 12px 16px;
    font-size: 1em;
    font-family: 'Karla', sans-serif;
    min-width: 0;
}
.saber-chat-trigger-input::placeholder {
    color: #9ca3af;
}
.saber-chat-trigger-input:focus {
    outline: none;
}

.saber-chat-trigger-btn {
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 700;
    font-family: 'Karla', sans-serif;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    white-space: nowrap;
    align-self: stretch;
    height: 100%;
    min-height: 48px;
    margin: 0;
    border: none;
    border-radius: 0;
    flex-shrink: 0;
    width: auto;
}
.saber-chat-trigger-btn:hover { opacity: 0.96; }
.saber-chat-trigger-btn .saber-chat-eye-icon {
    margin-right: 8px;
}

/* Hide custom handle when native resize is used */
.saber-chat-resize-handle { display: none; }

/* Mobile: anchor to edges with safe-area padding, remove transforms to avoid horizontal overflow */
@media (max-width: 768px) {
  .saber-chat-window {
    left: 0 !important;
    right: 0 !important;
    top: 8vh !important;
    bottom: 8vh !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    resize: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
  }
  .saber-chat-window .saber-chat-input,
  .saber-chat-trigger-input {
    font-size: 16px !important; /* prevent iOS focus zoom */
  }
  .saber-chat-window.is-open {
    transform: none !important;
  }
}
