/* Portal Widget Container */
#nowl-portal-widget-container {
    position: relative;
}

/* Toggle button container - positioned relative to sidebar */
#nowl-portal-widget-container .assistant-toggle {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--global-palette8);
    border: 2px solid var(--outline-color);
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    transition: right 0.3s ease, transform 0.2s ease;
    z-index: 1002;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* When sidebar is closed, button is at right edge */
#nowl-portal-widget-container:not(.portal-widget-open) .assistant-toggle {
    right: 20px;
}

/* When sidebar is open, button moves with sidebar (at left edge of sidebar) */
#nowl-portal-widget-container.portal-widget-open .assistant-toggle {
    right: 470px; /* 450px sidebar width + 20px offset */
}

/* Portal Widget - Full Height Collapsible Sidebar */
.nowl-portal-widget {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 450px;
    background: var(--global-palette9);
    border-left: 1px solid var(--outline-color);
    z-index: 1000;
    font-family: inherit;
    color: var(--global-palette3);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.15);
}

/* Prevent animation on initial load */
.nowl-portal-widget.no-transition {
    transition: none !important;
}

/* Sidebar open state */
.nowl-portal-widget.open {
    transform: translateX(0);
}


#nowl-portal-widget-container .assistant-toggle:hover {
    background: var(--global-palette7);
    border-color: var(--global-palette2);
    transform: scale(1.05);
}

#nowl-portal-widget-container .assistant-toggle img {
    height: auto;
    max-width: 100%;
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

#nowl-portal-widget-container .assistant-toggle-icon {
    object-fit: contain;
    display: block;
}

/* Panel - main sidebar content */
.nowl-portal-widget .assistant-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: var(--global-palette9);
}


/* Tab content wrapper */
.assistant-content {
    background: var(--global-palette9);
    flex: 1;                 /* Grow to fill space */
    overflow-y: auto;        /* Scroll only content */
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-bar-color) transparent;
    display: flex;
    flex-direction: column;
    min-height: 0;          /* Allow flex shrinking */
}

/* WebKit scrollbar style */
.assistant-content::-webkit-scrollbar {
    width: 6px;
}
.assistant-content::-webkit-scrollbar-track {
    background: transparent;
}
.assistant-content::-webkit-scrollbar-thumb {
    background-color: var(--scroll-bar-color);
    border-radius: 3px;
}

/* Tabs stay pinned at bottom */
.assistant-tabs {
    display: flex;
    align-items: center;
    border-top: 1px solid var(--outline-color);
    background: var(--global-palette8);
    flex-shrink: 0; /* Prevent collapsing */
    z-index: 1; /* Ensure tabs stay above content */
}

/* Adjust app-wrapper to account for sidebar when open */
/* Using class-based approach for better browser support */
.app-portal__body.portal-widget-open .app-wrapper {
    margin-right: 450px;
    transition: margin-right 0.3s ease;
}

.app-portal__body.portal-widget-closed .app-wrapper {
    margin-right: 0; /* No margin when closed - sidebar is completely hidden */
    transition: margin-right 0.3s ease;
}

/* Prevent body transition on initial load */
.app-portal__body.no-transition .app-wrapper {
    transition: none !important;
}

/* Prevent overflow above 1024px - ensure sidebar is contained */
@media (min-width: 1024px) {
    .app-portal__body {
        overflow-x: hidden; /* Prevent horizontal overflow from sidebar */
    }
    
    #nowl-portal-widget-container {
        position: relative;
        overflow: visible; /* Allow sidebar to be visible */
    }
    
    .nowl-portal-widget {
        overflow-y: auto; /* Allow vertical scrolling within sidebar */
        overflow-x: hidden; /* Prevent horizontal overflow */
    }
}

/* Tablet and mobile responsive adjustments - full width overlay below 1024px */
@media (max-width: 1023px) {
    /* Ensure container doesn't interfere with fixed positioning */
    #nowl-portal-widget-container {
        position: static;
    }
    
    .nowl-portal-widget {
        position: fixed !important;
        width: 100%;
        max-width: 100%;
        z-index: 10000; /* High z-index to ensure it's above everything */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        height: 100vh; /* Full viewport height */
    }
    
    #nowl-portal-widget-container .assistant-toggle {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
        position: fixed !important; /* Ensure toggle button is always visible */
        z-index: 10001; /* Above the sidebar */
    }
    
    #nowl-portal-widget-container .assistant-toggle img {
        width: 40px;
        height: 40px;
    }
    
    /* When sidebar is open (full width), hide the toggle button (X button in header handles closing) */
    #nowl-portal-widget-container.portal-widget-open .assistant-toggle {
        display: none; /* Hide owl button when sidebar is open - use X button in header instead */
    }
    
    /* Remove margin adjustments - sidebar overlays content */
    .app-portal__body.portal-widget-open .app-wrapper,
    .app-portal__body.portal-widget-closed .app-wrapper {
        margin-right: 0;
    }
}

.assistant-tab {
    flex: 1;
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--global-palette5);
    text-align: center;
    transition: background 0.2s ease;
    border-radius: 0;
    border-bottom: 3px solid transparent;
}

.assistant-tab:focus, .assistant-tab.active, .assistant-tab:hover {
    background: none;
}

.assistant-tab:hover, .assistant-tab.active {
    border-bottom: 3px solid var(--global-palette2);
}

/* Close button in tabs - positioned on the right */
.assistant-tabs .assistant-close-btn {
    padding: 0.5rem 0.75rem;
    margin-left: 0.5rem;
    border-left: 1px solid var(--outline-color);
}

/* Tab panels */
.assistant-tab-panel {
    display: none;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.assistant-tab-panel.active {
    display: flex;
}

.assistant-content-header {
    font-size: 1.1rem;
    font-weight: 500;
    padding: 1rem;
    border-bottom: 1px solid var(--outline-color);
    background: var(--global-palette8);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.assistant-header-title {
    flex: 1;
}

.assistant-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Open in page button */
.assistant-content-header .assistant-open-page-btn {
    background: transparent;
    border: none;
    color: var(--global-palette5);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.15s ease, color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.assistant-content-header .assistant-open-page-btn:hover {
    color: var(--global-palette2);
    background-color: var(--global-palette7);
}

/* Close button in header */
.assistant-content-header .assistant-close-btn {
    background: transparent;
    border: none;
    color: var(--global-palette5);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.15s ease, color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.assistant-content-header .assistant-close-btn:hover {
    color: var(--global-palette2);
    background-color: var(--global-palette7);
}

.assistant-content-body {
    padding: 0 1rem 1rem;
    overflow: auto;
    scrollbar-color: var(--scroll-bar-color) transparent;
    scrollbar-width: thin;
    flex: 1;
    min-height: 0;
}


/* Checklist progress */
.checklist-progress {
    font-size: 0.8rem;
    color: var(--muted-text);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* Checklist items */
.checklist-items {
    list-style: none;
    padding: 0;
    margin: 0;
}

.checklist-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--global-palette3);
    gap: 0.5rem;
}

.checklist-item.done {
    opacity: 0.7;
    text-decoration: line-through;
}

.checklist-checkbox {
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.checklist-items a {
    color: var(--global-palette2);
    text-decoration: none;
}

.checklist-items a:hover {
    text-decoration: underline;
}

/* Checklist actions - now inline with progress */
.checklist-actions {
    margin-top: 0;
    font-size: 0.8rem;
    color: var(--muted-text);
    flex-shrink: 0;
}

.checklist-actions a {
    color: var(--global-palette2);
    cursor: pointer;
    text-decoration: none;
}

.checklist-actions a:hover {
    text-decoration: underline;
}

/* ------------------------
   Chat Component inside Portal Widget (Copilot Tab)
------------------------- */

/* Copilot tab - remove padding and ensure full height */
.nowl-portal-widget #assistant-copilot.assistant-tab-panel {
    padding: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Copilot tab content body - no padding, full height */
.nowl-portal-widget #assistant-copilot .assistant-content-body {
    padding: 0 !important;
    height: 100% !important;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Chat component fills the tab */
.nowl-portal-widget #assistant-copilot .nowl-chat-component {
    height: 100%;
    width: 100%;
    background: var(--global-palette9);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

/* Reduce padding in widget context */
.nowl-portal-widget .nowl-chat-component .nowl-messages {
    padding: 0.75rem;
}

.nowl-portal-widget .nowl-chat-component .nowl-input-area {
    margin: 0.75rem;
    border-radius: 0.375rem;
}

/* Smaller font sizes in widget */
.nowl-portal-widget .nowl-chat-component .msg {
    font-size: 0.9rem;
    max-width: 90%;
}

.nowl-portal-widget .nowl-chat-component .nowl-input {
    font-size: 0.9rem;
    padding: 0.625rem 0.875rem;
}

.nowl-portal-widget .nowl-chat-component .nowl-action-btn {
    width: 32px;
    height: 32px;
}

.nowl-portal-widget .nowl-chat-component .nowl-send-btn {
    width: 32px;
    height: 32px;
}

.nowl-portal-widget .nowl-chat-component .nowl-reset-btn {
    width: 36px;
    height: 36px;
}

/* Adjust debug widget position in widget */
.nowl-portal-widget .nowl-chat-component .nowl-chat-debug-widget {
    top: 0.25rem;
    right: 0.25rem;
}

.nowl-portal-widget .nowl-chat-component .nowl-chat-debug-widget__trigger {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.875rem;
}

/* Smaller components in widget */
.nowl-portal-widget .nowl-chat-component .nowl-post-card-component {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
}

.nowl-portal-widget .nowl-chat-component .nowl-message-wrapper > .nowl-components-container > .nowl-component .nowl-post-card-component {
    width: 300px;
    max-width: min(300px, 100%);
}

/* ------------------------
   Legacy Chatbot inside Portal Assistant (for backwards compatibility)
------------------------- */
/* -------- Chatbot Tab Overrides -------- */

/* Remove padding/scroll for chatbot tab */
.nowl-portal-widget #assistant-chatbot.assistant-tab-panel {
    padding: 0;
    height: 100%;
    overflow: hidden;
}

    /* Ensure chatbot container fills space */
.nowl-portal-widget #assistant-chatbot .mwai-chatbot-container {
    height: 100%;
}

/* Conversation scrolls inside */
.nowl-portal-widget #assistant-chatbot .mwai-conversation {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem; /* keep some breathing room */
}

/* Container */
.nowl-portal-widget .mwai-chatbot-container {
    overflow: hidden;
    width: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--global-palette9);
    font-size: 0.85rem;
}

.nowl-portal-widget .mwai-chat {
    display: flex;
    height: 100%;
    overflow: hidden;
}


.nowl-portal-widget .mwai-window-box {
    width: 100%;
}

/* Chat area */
.nowl-portal-widget .mwai-conversation {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
    display: flex;
    height: 100%;
    flex-direction: column;
    row-gap: 1rem;
    background-color: var(--global-palette9);
    scrollbar-color: var(--scroll-bar-color) transparent;
    scrollbar-width: thin;
}

.nowl-portal-widget .mwai-name {
    display: none;
}

.nowl-portal-widget .mwai-body {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.nowl-portal-widget .mwai-conversation::-webkit-scrollbar {
    width: 6px;
}
.nowl-portal-widget .mwai-conversation::-webkit-scrollbar-thumb {
    background-color: var(--scroll-bar-color);
    border-radius: 3px;
}

/* Messages */
.nowl-portal-widget .mwai-reply {
    display: flex;
    align-items: flex-start;
    column-gap: 0.5rem;
    font-size: 0.85rem;
}
.nowl-portal-widget .mwai-reply > div {
    background-color: var(--global-palette7);
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    color: var(--mwai-fontColor, #fff);
    position: relative;
    overflow: hidden;
}
.nowl-portal-widget .mwai-user {
    align-self: flex-end;
}
.nowl-portal-widget .mwai-user > div {
    background-color: var(--global-palette1);
    color: var(--global-palette3);
}

/* Avatar */
.nowl-portal-widget .mwai-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nowl-portal-widget .mwai-avatar img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 50%;
}

/* Reply actions (copy, etc.) */
.nowl-portal-widget .mwai-reply-actions {
    display: flex;
    margin-left: 0.25rem;
}
.nowl-portal-widget .mwai-copy-button,
.nowl-portal-widget .mwai-action-button {
    width: 18px;
    height: 18px;
    margin-top: 0.25rem;
    cursor: pointer;
}
.nowl-portal-widget .mwai-copy-button svg,
.nowl-portal-widget .mwai-action-button svg {
    width: 100%;
    height: 100%;
    fill: var(--global-palette5);
    transition: fill 0.2s ease;
}
.nowl-portal-widget .mwai-copy-button svg:hover,
.nowl-portal-widget .mwai-action-button svg:hover {
    fill: var(--global-palette2);
}

/* Input area */
.nowl-portal-widget .mwai-input {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background-color: var(--global-palette8);
    border-top: 1px solid var(--outline-color);
    column-gap: 0.5rem;
}
.nowl-portal-widget .mwai-input-text {
    flex: 1;
    background-color: var(--global-palette7);
    border: 1px solid var(--outline-color);
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    display: flex;
    align-items: center;
}
.nowl-portal-widget .mwai-input-text textarea {
    flex: 1;
    border: none;
    resize: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--global-palette3);
}
.nowl-portal-widget .mwai-input .mwai-microphone {
    display: flex;
    align-items: center;
}

/* Send button */
.nowl-portal-widget .mwai-input-submit {
    background: var(--global-palette1);
    color: var(--global-palette3);
    border: none;
    border-radius: 4px !important;
    padding: 0.4rem 0.8rem !important;
    cursor: pointer;
    font-size: 0.9rem !important;
    height: 100%;
}
.nowl-portal-widget .mwai-input-submit:hover {
    background: var(--global-palette2);
}

.nowl-portal-widget .mwai-footer {
    display: none;
}


@media (max-width: 767px) {
    .nowl-portal-widget {
        bottom: 4px;
        right: 4px;
    }

    .nowl-portal-widget .assistant-panel {
        bottom: 48px;
    }

    .nowl-portal-widget .assistant-toggle {
        width: 40px;
        height: 40px;
    }
}