/**
 * HISTORA AI Floating Widget Styles
 * Modern glassmorphism design consistent with Pendidikan Sejarah theme
 */

/* ================================
   CSS Variables (inherits theme vars)
   ================================ */
.histora-floating-widget {
    --hw-primary: var(--primary-color, #c9302c);
    --hw-secondary: var(--secondary-color, #f39c12);
    --hw-accent: var(--accent-color, #27ae60);
    --hw-text: var(--text-primary, #2c3e50);
    --hw-text-light: var(--text-secondary, #5a6c7d);
    --hw-bg: var(--bg-primary, #ffffff);
    --hw-bg-secondary: var(--bg-secondary, #f8f9fa);
    --hw-border: var(--border-color, #dee2e6);
    --hw-gradient: var(--gradient-primary, linear-gradient(135deg, #c9302c 0%, #f39c12 100%));
    --hw-gradient-dark: var(--gradient-secondary, linear-gradient(135deg, #bc0909 0%, #370909 100%));
    --hw-shadow: 0 8px 32px rgba(201, 48, 44, 0.18);
    --hw-shadow-hover: 0 12px 40px rgba(201, 48, 44, 0.28);
    --hw-radius: 20px;
    --hw-font: var(--font-primary, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    --hw-font-heading: var(--font-heading, 'Montserrat', sans-serif);
    --hw-transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --hw-transition-bounce: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Dark mode overrides */
[data-theme="dark"] .histora-floating-widget {
    --hw-primary: var(--primary-color, #e74c3c);
    --hw-secondary: var(--secondary-color, #f1c40f);
    --hw-bg: var(--bg-primary, #1a1a2e);
    --hw-bg-secondary: var(--bg-secondary, #16213e);
    --hw-text: var(--text-primary, #ecf0f1);
    --hw-text-light: var(--text-secondary, #bdc3c7);
    --hw-border: var(--border-color, #2c3e50);
    --hw-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --hw-shadow-hover: 0 12px 40px rgba(231, 76, 60, 0.3);
}

/* ================================
   Animations
   ================================ */
@keyframes hw-scaleIn {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

    60% {
        transform: scale(1.1) rotate(10deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes hw-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes hw-slideDown {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

@keyframes hw-popupOpen {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.85);
    }

    50% {
        transform: translateY(-5px) scale(1.02);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes hw-popupClose {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(30px) scale(0.85);
    }
}

@keyframes hw-pulse-ring {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

@keyframes hw-float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

@keyframes hw-shimmer {
    0% {
        background-position: -200% center;
    }

    100% {
        background-position: 200% center;
    }
}

@keyframes hw-typing-dot {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes hw-fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes hw-gradient-shift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes hw-notification-bounce {

    0%,
    100% {
        transform: scale(1);
    }

    30% {
        transform: scale(1.3);
    }

    60% {
        transform: scale(0.9);
    }
}

/* ================================
   Widget Container
   ================================ */
.histora-floating-widget {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9990;
    font-family: var(--hw-font);
    transition: transform var(--hw-transition), right var(--hw-transition);
}

/* Shift when scroll-to-top is visible (on the same side) */
.histora-floating-widget.hw-shifted {
    right: 90px;
}

/* ================================
   Toggle Button (FAB)
   ================================ */
.hw-toggle-btn {
    position: relative;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: var(--hw-gradient);
    background-size: 200% 200%;
    animation: hw-gradient-shift 4s ease infinite;
    color: #fff;
    cursor: pointer;
    box-shadow: var(--hw-shadow);
    transition: all var(--hw-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    overflow: visible;
}

.hw-toggle-btn::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--hw-gradient);
    opacity: 0;
    z-index: -1;
    transition: opacity 0.3s ease;
    animation: hw-pulse-ring 2s ease-out infinite;
}

.hw-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: var(--hw-shadow-hover);
}

.hw-toggle-btn:hover::before {
    opacity: 0.4;
}

.hw-toggle-btn:active {
    transform: scale(0.95);
}

/* Icon inside toggle */
.hw-toggle-btn .hw-icon {
    width: 28px;
    height: 28px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.hw-toggle-btn .hw-icon-chat {
    display: block;
}

.hw-toggle-btn .hw-icon-close {
    display: none;
}

.histora-floating-widget.hw-open .hw-toggle-btn .hw-icon-chat {
    display: none;
}

.histora-floating-widget.hw-open .hw-toggle-btn .hw-icon-close {
    display: block;
}

.histora-floating-widget.hw-open .hw-toggle-btn {
    background: var(--hw-gradient-dark);
    animation: none;
}

.histora-floating-widget.hw-open .hw-toggle-btn::before {
    animation: none;
    opacity: 0;
}

/* Notification badge */
.hw-notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: var(--hw-accent);
    border-radius: 50%;
    border: 2.5px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    animation: hw-notification-bounce 0.6s ease;
    transition: all 0.3s ease;
}

.hw-notification-badge.hw-hidden {
    transform: scale(0);
    opacity: 0;
}

/* ================================
   Tooltip label on hover
   ================================ */
.hw-toggle-label {
    position: absolute;
    right: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--hw-bg);
    color: var(--hw-text);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    padding: 8px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    border: 1px solid var(--hw-border);
}

.hw-toggle-label::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: var(--hw-bg);
    border-right: 1px solid var(--hw-border);
    border-bottom: 1px solid var(--hw-border);
}

.hw-toggle-btn:hover+.hw-toggle-label,
.hw-toggle-label:hover {
    opacity: 1;
    pointer-events: auto;
}

.histora-floating-widget.hw-open .hw-toggle-label {
    display: none;
}

/* ================================
   Popup Chat Window
   ================================ */
.hw-popup {
    position: absolute;
    bottom: calc(100% + 16px);
    right: 0;
    width: 400px;
    height: 560px;
    background: var(--hw-bg);
    border-radius: var(--hw-radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(30px) scale(0.85);
    transition: none;
}

[data-theme="dark"] .hw-popup {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.hw-popup.hw-popup-opening {
    animation: hw-popupOpen 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    pointer-events: auto;
}

.hw-popup.hw-popup-closing {
    animation: hw-popupClose 0.3s ease forwards;
    pointer-events: none;
}

.hw-popup.hw-popup-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ================================
   Popup Header
   ================================ */
.hw-popup-header {
    background: var(--hw-gradient);
    background-size: 200% 200%;
    animation: hw-gradient-shift 6s ease infinite;
    padding: 18px 20px;
    min-height: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-sizing: border-box;
}

.hw-popup-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 30%, rgba(255, 255, 255, 0.08) 50%, transparent 70%);
    background-size: 200% 100%;
    animation: hw-shimmer 3s ease-in-out infinite;
}

.hw-popup-header-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.hw-popup-header-avatar svg {
    width: 24px;
    height: 24px;
    fill: #fff;
}

.hw-popup-header-info {
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.hw-popup-header-title {
    font-family: var(--hw-font-heading);
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.03em;
    line-height: 1.2;
}

.hw-popup-header-subtitle {
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hw-popup-header-subtitle .hw-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
    animation: hw-float 2s ease-in-out infinite;
}

.hw-popup-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.hw-header-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 10px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.hw-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.08);
}

.hw-header-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ================================
   Quick Actions Bar
   ================================ */
.hw-quick-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    min-height: 52px;
    background: var(--hw-bg-secondary);
    border-bottom: 1px solid var(--hw-border);
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
    box-sizing: border-box;
}

.hw-quick-actions::-webkit-scrollbar {
    display: none;
}

.hw-quick-action-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--hw-border);
    background: var(--hw-bg);
    color: var(--hw-text-light);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    font-family: var(--hw-font);
}

.hw-quick-action-btn:hover {
    border-color: var(--hw-primary);
    color: var(--hw-primary);
    background: rgba(201, 48, 44, 0.05);
    transform: translateY(-1px);
}

.hw-quick-action-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.hw-quick-action-btn.hw-action-fullpage {
    background: var(--hw-gradient);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}

.hw-quick-action-btn.hw-action-fullpage:hover {
    box-shadow: 0 4px 16px rgba(201, 48, 44, 0.3);
    color: #fff;
    transform: translateY(-2px);
}

/* ================================
   Chat Messages Area
   ================================ */
.hw-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0;
}

/* Custom scrollbar */
.hw-messages::-webkit-scrollbar {
    width: 5px;
}

.hw-messages::-webkit-scrollbar-track {
    background: transparent;
}

.hw-messages::-webkit-scrollbar-thumb {
    background: var(--hw-border);
    border-radius: 10px;
}

.hw-messages::-webkit-scrollbar-thumb:hover {
    background: var(--hw-text-light);
}

/* Message bubbles */
.hw-message {
    display: flex;
    gap: 10px;
    animation: hw-fadeIn 0.35s ease;
    max-width: 88%;
}

.hw-message.hw-msg-bot {
    align-self: flex-start;
}

.hw-message.hw-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.hw-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.hw-msg-bot .hw-msg-avatar {
    background: var(--hw-gradient);
}

.hw-msg-bot .hw-msg-avatar svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.hw-msg-user .hw-msg-avatar {
    background: var(--hw-bg-secondary);
    border: 1px solid var(--hw-border);
    color: var(--hw-text-light);
    font-weight: 600;
    font-size: 12px;
}

.hw-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.hw-msg-bot .hw-msg-bubble {
    background: var(--hw-bg-secondary);
    color: var(--hw-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--hw-border);
}

.hw-msg-user .hw-msg-bubble {
    background: var(--hw-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.hw-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}

.hw-typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--hw-primary);
    opacity: 0.4;
    animation: hw-typing-dot 1.4s ease-in-out infinite;
}

.hw-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.hw-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Welcome card */
.hw-welcome-card {
    text-align: center;
    padding: 20px 16px;
    animation: hw-fadeIn 0.5s ease;
}

.hw-welcome-emoji {
    font-size: 36px;
    margin-bottom: 10px;
    animation: hw-float 3s ease-in-out infinite;
}

.hw-welcome-title {
    font-family: var(--hw-font-heading);
    font-size: 16px;
    font-weight: 700;
    color: var(--hw-text);
    margin-bottom: 4px;
}

.hw-welcome-text {
    font-size: 13px;
    color: var(--hw-text-light);
    line-height: 1.5;
}

/* Suggestions chips */
.hw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 12px;
}

.hw-suggestion-chip {
    font-family: var(--hw-font);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--hw-border);
    background: var(--hw-bg);
    color: var(--hw-text-light);
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.hw-suggestion-chip:hover {
    border-color: var(--hw-primary);
    color: var(--hw-primary);
    background: rgba(201, 48, 44, 0.04);
}

/* ================================
   Input Area
   ================================ */
.hw-input-area {
    padding: 12px 16px 14px;
    min-height: 70px;
    border-top: 1px solid var(--hw-border);
    background: var(--hw-bg);
    flex-shrink: 0;
    box-sizing: border-box;
}

.hw-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--hw-bg-secondary);
    border-radius: 16px;
    border: 1.5px solid var(--hw-border);
    padding: 4px 4px 4px 14px;
    transition: all 0.25s ease;
}

.hw-input-wrapper:focus-within {
    border-color: var(--hw-primary);
    box-shadow: 0 0 0 3px rgba(201, 48, 44, 0.08);
}

.hw-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--hw-text);
    font-family: var(--hw-font);
    font-size: 13.5px;
    line-height: 1.5;
    padding: 8px 0;
    resize: none;
    outline: none;
    max-height: 80px;
    min-height: 20px;
}

.hw-input-wrapper textarea::placeholder {
    color: var(--hw-text-light);
    opacity: 0.6;
}

.hw-send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    border-radius: 12px;
    border: none;
    background: var(--hw-gradient);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s ease;
}

.hw-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(201, 48, 44, 0.3);
}

.hw-send-btn:active {
    transform: scale(0.95);
}

.hw-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.hw-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ================================
   Popup Footer
   ================================ */
.hw-popup-footer {
    padding: 10px 16px;
    min-height: 40px;
    text-align: center;
    border-top: 1px solid var(--hw-border);
    background: var(--hw-bg-secondary);
    flex-shrink: 0;
    box-sizing: border-box;
}

.hw-popup-footer-text {
    font-size: 11px;
    color: var(--hw-text-light);
    opacity: 0.7;
}

.hw-popup-footer-text strong {
    color: var(--hw-primary);
    font-weight: 600;
}

/* ================================
   Fullpage Shortcut Button
   ================================ */
.hw-fullpage-shortcut {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--hw-bg);
    border: 1px solid var(--hw-border);
    border-radius: 14px;
    padding: 8px 16px 8px 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: var(--hw-text);
    font-family: var(--hw-font);
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    animation: hw-slideUp 0.4s ease 0.8s forwards;
}

.histora-floating-widget.hw-open .hw-fullpage-shortcut {
    display: none;
}

.hw-fullpage-shortcut .hw-shortcut-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--hw-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.hw-fullpage-shortcut .hw-shortcut-icon svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

.hw-fullpage-shortcut .hw-shortcut-text {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.hw-fullpage-shortcut .hw-shortcut-subtext {
    font-size: 10px;
    font-weight: 400;
    color: var(--hw-text-light);
}

.hw-fullpage-shortcut:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
    border-color: var(--hw-primary);
    pointer-events: auto;
}

/* after animation completes, enable pointer events */
.hw-fullpage-shortcut.hw-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ================================
   Responsive
   ================================ */
@media (max-width: 480px) {
    .histora-floating-widget {
        bottom: 16px;
        right: 16px;
    }

    .histora-floating-widget.hw-shifted {
        right: 16px;
        /* don't shift on mobile */
    }

    .hw-toggle-btn {
        width: 56px;
        height: 56px;
    }

    .hw-toggle-label {
        display: none;
    }

    .hw-popup {
        width: calc(100vw - 20px);
        height: calc(100vh - 140px);
        max-height: calc(100vh - 140px);
        right: -12px;
        bottom: calc(100% + 12px);
    }

    .hw-fullpage-shortcut {
        right: -12px;
    }

    .hw-messages {
        flex: 1 1 auto;
        min-height: 0;
    }
}

@media (max-width: 360px) {
    .hw-popup {
        width: calc(100vw - 10px);
        right: -14px;
    }
}

/* ================================
   Print: hide widget
   ================================ */
@media print {
    .histora-floating-widget {
        display: none !important;
    }
}