/* RosterMate Chat Support - Draggable Window Styles */

/* Chat Window (replaces modal overlay) */
.chat-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 450px;
    height: 600px;
    background: var(--background-main);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 9999;
    resize: both;
    overflow: hidden;
    min-width: 500px;
    min-height: 600px;
    max-width: 800px;
    max-height: 90vh;
    animation: slideInUp 0.3s ease-out;
}

    .chat-window.dragging {
        transition: none;
        cursor: move;
    }

/* Header - Draggable area */
.chat-window-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--background-main-elements);
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

    .chat-window-header:active {
        cursor: grabbing;
    }

.help-center-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--background-main);
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    cursor: pointer;
}

    .help-center-btn:hover {
        background: var(--button-positive);
        color: var(--button-positive-text);
        border-color: var(--button-positive);
        transform: translateY(-1px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }

    .help-center-btn:active {
        transform: translateY(0);
    }

    .help-center-btn i {
        font-size: 1.1rem;
    }

.chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

.chat-action-btn {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
    font-size: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .chat-action-btn:hover {
        background: var(--background-main);
    }

    .chat-action-btn:active {
        transform: scale(0.95);
    }

/* Minimize button special styling */
#minimizeChatBtn:hover {
    background: rgba(255, 193, 7, 0.1);
    color: #ffc107;
}

/* Usage Container */
.chat-usage-container {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-main-elements);
    flex-shrink: 0;
}

.usage-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.usage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
}

.usage-tier {
    color: var(--text-faded);
    font-weight: 500;
}

.usage-count {
    font-weight: 600;
    font-size: 0.9rem;
}

.usage-bar {
    height: 6px;
    background: var(--background-main);
    border-radius: 3px;
    overflow: hidden;
}

.usage-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

.usage-upgrade-hint {
    font-size: 0.75rem;
    color: var(--text-faded);
    text-align: center;
    padding-top: 0.25rem;
}

/* Messages container */
.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Welcome message */
.chat-welcome-message {
    background: var(--background-main-elements);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    color: var(--text-main);
    align-items: flex-start;
}

    .chat-welcome-message i {
        color: var(--button-positive);
        font-size: 1.25rem;
        flex-shrink: 0;
        margin-top: 0.15rem;
    }

    .chat-welcome-message p {
        margin: 0;
        line-height: 1.5;
    }

/* Message bubbles */
.chat-message {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.chat-message-content {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.95rem;
}

.chat-message-user {
    justify-content: flex-end;
}

    .chat-message-user .chat-message-content {
        background: var(--button-positive);
        color: var(--button-positive-text);
        border-bottom-right-radius: 4px;
    }

.chat-message-assistant {
    justify-content: flex-start;
}

    .chat-message-assistant .chat-message-content {
        background: var(--background-main-elements);
        color: var(--text-main);
        border: 1px solid var(--border-color);
        border-bottom-left-radius: 4px;
    }

/* Markdown styling within messages */
.chat-message-content p {
    margin: 0 0 0.75rem 0;
}

    .chat-message-content p:last-child {
        margin-bottom: 0;
    }

.chat-message-content strong {
    font-weight: 600;
    color: var(--text-main);
}

.chat-message-content em {
    font-style: italic;
}

.chat-message-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0.5rem 0 0.5rem 0;
    color: var(--text-main);
}

    .chat-message-content h3:first-child {
        margin-top: 0;
    }

.chat-message-content h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.5rem 0 0.5rem 0;
    color: var(--text-main);
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.chat-message-content li {
    margin: 0.25rem 0;
    line-height: 1.6;
}

.chat-message-content ul li {
    list-style-type: disc;
}

.chat-message-content ol li {
    list-style-type: decimal;
}

.chat-message-content br {
    display: block;
    content: "";
    margin: 0.25rem 0;
}

.chat-message-content a {
    color: var(--button-positive);
    text-decoration: underline;
    word-break: break-word;
}

    .chat-message-content a:hover {
        opacity: 0.8;
    }

    .chat-message-content a:visited {
        color: var(--button-positive);
    }

/* Typing indicator */
.chat-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1.5rem;
    align-items: center;
    flex-shrink: 0;
}

    .chat-typing-indicator span {
        height: 8px;
        width: 8px;
        background: var(--text-faded);
        border-radius: 50%;
        display: inline-block;
        animation: bounce 1.4s infinite ease-in-out;
    }

        .chat-typing-indicator span:nth-child(1) {
            animation-delay: 0s;
        }

        .chat-typing-indicator span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .chat-typing-indicator span:nth-child(3) {
            animation-delay: 0.4s;
        }

/* Input container */
.chat-input-container {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
    background: var(--background-main);
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    background: var(--background-main-elements);
    color: var(--text-main);
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.2s;
}

    #chatInput:focus {
        outline: none;
        border-color: var(--button-positive);
    }

    #chatInput:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }

    #chatInput::placeholder {
        color: var(--text-faded);
    }

.chat-send-btn {
    background: var(--button-positive);
    color: var(--button-positive-text);
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    font-size: 1.1rem;
    flex-shrink: 0;
}

    .chat-send-btn:hover:not(:disabled) {
        opacity: 0.9;
    }

    .chat-send-btn:active:not(:disabled) {
        transform: scale(0.95);
    }

    .chat-send-btn:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }

/* Error message */
.chat-error {
    background: var(--button-negative);
    color: var(--button-negative-text);
    padding: 0.75rem 1.5rem;
    margin: 0 1.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* Resize handle */
.chat-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 0%, transparent 50%, var(--border-color) 50%);
    border-bottom-right-radius: 12px;
}

    .chat-resize-handle::after {
        content: '';
        position: absolute;
        bottom: 6px;
        right: 6px;
        width: 8px;
        height: 8px;
        border-right: 2px solid var(--text-faded);
        border-bottom: 2px solid var(--text-faded);
    }

/* Minimized button */
.chat-minimized-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--button-positive);
    color: var(--button-positive-text);
    padding: 1rem 1.5rem;
    border-radius: 50px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    z-index: 9998;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: slideInUp 0.3s ease-out;
}

    .chat-minimized-button:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }

    .chat-minimized-button:active {
        transform: translateY(0);
    }

    .chat-minimized-button i {
        font-size: 1.25rem;
    }

.chat-minimized-badge {
    background: var(--button-negative);
    color: white;
    border-radius: 50%;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    min-width: 20px;
    text-align: center;
    font-weight: 700;
}

/* Scrollbar styling */
.chat-messages-container::-webkit-scrollbar {
    width: 6px;
}

.chat-messages-container::-webkit-scrollbar-track {
    background: var(--background-main);
}

.chat-messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

    .chat-messages-container::-webkit-scrollbar-thumb:hover {
        background: var(--text-faded);
    }

/* Animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-8px);
    }
}

/* Mobile responsive - on mobile it becomes full screen */
@media (max-width: 768px) {
    .chat-window {
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        bottom: 0 !important;
        right: 0 !important;
        border-radius: 0;
        min-width: 100%;
        max-width: 100%;
    }

    .chat-window-header {
        cursor: default;
    }

    .chat-resize-handle {
        display: none;
    }

    .chat-message-content {
        max-width: 85%;
    }

    .chat-usage-container {
        padding: 0.5rem 1rem;
    }

    .chat-messages-container {
        padding: 1rem;
    }

    .chat-input-container {
        padding: 1rem;
    }

    .chat-minimized-button {
        right: 10px;
        bottom: 10px;
    }
}

@media (max-width: 480px) {
    .chat-message-content {
        max-width: 90%;
        font-size: 0.9rem;
    }

    .help-center-btn {
        font-size: 0.9rem;
        padding: 0.4rem 0.75rem;
    }

        .help-center-btn span {
            display: none;
        }

        .help-center-btn i {
            font-size: 1.2rem;
        }

    .chat-input-container {
        gap: 0.5rem;
    }

    .chat-send-btn {
        padding: 0.75rem 1rem;
    }

    .usage-header {
        font-size: 0.8rem;
    }

    .usage-upgrade-hint {
        font-size: 0.7rem;
    }

    .chat-minimized-button span:not(.chat-minimized-badge) {
        display: none;
    }

    .chat-minimized-button {
        padding: 1rem;
        border-radius: 50%;
        width: 56px;
        height: 56px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .chat-window,
    .chat-message,
    .chat-action-btn,
    .chat-send-btn,
    .usage-bar-fill,
    .chat-minimized-button {
        animation: none;
        transition: none;
    }

    .chat-typing-indicator span {
        animation: none;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .chat-window {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    }
}
