/* ================================================
   Floating Chat Window Styles
   Movable and resizable window for AI Chat
   ================================================ */

/* ====== WINDOW CONTAINER ====== */

.floating-chat-window {
    position: fixed;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    background: var(--mud-palette-surface);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.floating-chat-window:focus-within,
.floating-chat-window:hover {
    z-index: 1150;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.12);
}

.floating-chat-window.dragging {
    opacity: 0.95;
    cursor: grabbing !important;
    transition: none;
}

.floating-chat-window.resizing {
    transition: none;
}

/* ====== TITLE BAR ====== */

.floating-chat-window .window-title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: linear-gradient(to bottom, var(--mud-palette-primary), var(--mud-palette-primary-darken));
    color: var(--mud-palette-primary-text);
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

.floating-chat-window.dragging .window-title-bar {
    cursor: grabbing;
}

.floating-chat-window.maximized .window-title-bar {
    cursor: default;
    border-radius: 0;
}

.floating-chat-window .window-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

.floating-chat-window .window-title .mud-icon-root {
    font-size: 1.25rem;
}

/* ====== WINDOW CONTROLS ====== */

.floating-chat-window .window-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.floating-chat-window .window-control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.15);
    color: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}

.floating-chat-window .window-control-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.floating-chat-window .window-control-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

.floating-chat-window .window-control-btn .mud-icon-root {
    font-size: 1rem;
}

.floating-chat-window .window-control-btn.close-btn:hover {
    background: rgba(244, 67, 54, 0.8);
}

/* ====== WINDOW CONTENT ====== */

.floating-chat-window .window-content {
    flex: 1;
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.floating-chat-window .window-content > * {
    height: 100%;
    width: 100%;
    max-width: 100%;
}

/* Override TroubleshootingChat fixed height when inside floating window */
.floating-chat-window .window-content .mud-paper {
    height: 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    padding-right: 8px !important;
}

/* Ensure input area doesn't overflow - critical fix for send button visibility */
.floating-chat-window .chat-input-area {
    display: flex !important;
    align-items: flex-end !important;
    gap: 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding: 0 16px 0 0 !important;
}

/* Force text field to shrink, leaving room for button */
.floating-chat-window .chat-input-area .mud-input-control {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    max-width: calc(100% - 70px) !important;
}

/* Ensure send button is always visible and never pushed off-screen */
.floating-chat-window .chat-input-area > .mud-icon-button,
.floating-chat-window .chat-input-area > button {
    flex: 0 0 48px !important;
    width: 48px !important;
    min-width: 48px !important;
    height: 48px !important;
    margin: 0 !important;
}

/* ====== RESIZE HANDLES ====== */

.floating-chat-window .resize-handle {
    position: absolute;
    z-index: 10;
}

/* Edge handles */
.floating-chat-window .resize-handle.resize-n {
    top: 0;
    left: 8px;
    right: 8px;
    height: 6px;
    cursor: n-resize;
}

.floating-chat-window .resize-handle.resize-s {
    bottom: 0;
    left: 8px;
    right: 8px;
    height: 6px;
    cursor: s-resize;
}

.floating-chat-window .resize-handle.resize-e {
    top: 8px;
    right: 0;
    bottom: 8px;
    width: 6px;
    cursor: e-resize;
}

.floating-chat-window .resize-handle.resize-w {
    top: 8px;
    left: 0;
    bottom: 8px;
    width: 6px;
    cursor: w-resize;
}

/* Corner handles */
.floating-chat-window .resize-handle.resize-nw {
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: nw-resize;
}

.floating-chat-window .resize-handle.resize-ne {
    top: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: ne-resize;
}

.floating-chat-window .resize-handle.resize-sw {
    bottom: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: sw-resize;
}

.floating-chat-window .resize-handle.resize-se {
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    cursor: se-resize;
}

/* Visual indicator on corner hover (optional) */
.floating-chat-window .resize-handle.resize-se::after {
    content: '';
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid rgba(0, 0, 0, 0.2);
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.floating-chat-window:hover .resize-handle.resize-se::after {
    opacity: 1;
}

/* ====== MINIMIZED STATE ====== */

.floating-chat-window.minimized {
    height: auto !important;
}

.floating-chat-window.minimized .window-content {
    display: none;
}

.floating-chat-window.minimized .resize-handle {
    display: none;
}

.floating-chat-window.minimized .window-title-bar {
    border-radius: 12px;
}

/* ====== MAXIMIZED STATE ====== */

.floating-chat-window.maximized {
    /* Use fixed positioning to properly respect viewport boundaries */
    position: fixed !important;
    border-radius: 0;
    box-sizing: border-box;
    /* Position below app bar (64px = mt-16) and to the right of drawer */
    /* Drawer width is set dynamically via JavaScript based on open/closed state */
    top: 64px !important;
    right: 0 !important;
    bottom: 0 !important;
    /* left is set dynamically in JS to account for drawer state */
    /* Ensure proper z-index - above content but below critical overlays */
    z-index: 1150 !important;
}

.floating-chat-window.maximized .resize-handle {
    display: none;
}

/* Ensure title bar is always visible when maximized */
.floating-chat-window.maximized .window-title-bar {
    position: relative;
    z-index: 10;
}

/* Ensure content fills the maximized window */
.floating-chat-window.maximized .window-content {
    width: 100%;
    height: calc(100% - 48px); /* Subtract title bar height */
}

/* Make restore button more prominent when maximized */
.floating-chat-window.maximized .window-control-btn:nth-child(2) {
    background: rgba(255, 255, 255, 0.3);
    animation: pulse-restore 2s ease-in-out infinite;
}

.floating-chat-window.maximized .window-control-btn:nth-child(2):hover {
    background: rgba(255, 255, 255, 0.5);
    animation: none;
}

@keyframes pulse-restore {
    0%, 100% {
        transform: scale(1);
        box-shadow: none;
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
    }
}

/* Add a floating restore hint that appears briefly when maximized */
.floating-chat-window.maximized::before {
    content: 'Click title bar buttons or double-click to restore';
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.85rem;
    z-index: 100;
    opacity: 0;
    animation: fadeHint 4s ease-in-out forwards;
    pointer-events: none;
}

@keyframes fadeHint {
    0% { opacity: 0; }
    10% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* ====== ANIMATIONS ====== */

@keyframes windowFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.floating-chat-window.visible {
    animation: windowFadeIn 0.2s ease-out;
}

/* ====== DARK MODE SUPPORT ====== */

.mud-theme-dark .floating-chat-window {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.mud-theme-dark .floating-chat-window:focus-within,
.mud-theme-dark .floating-chat-window:hover {
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.mud-theme-dark .floating-chat-window .resize-handle.resize-se::after {
    border-color: rgba(255, 255, 255, 0.3);
}

/* ====== RESPONSIVE ADJUSTMENTS ====== */

@media (max-width: 600px) {
    .floating-chat-window {
        /* On mobile, take more of the screen */
        min-width: 90vw !important;
        max-width: 100vw !important;
    }
}
