/* MacDesk AI Support Widget Styling */
:root {
    --chat-primary: #0a84ff;
    --chat-primary-hover: #0071e3;
    --chat-bg-opacity: 0.95;
    --chat-modal-opacity: 0.95;
    --chat-bg: rgba(28, 28, 30, var(--chat-bg-opacity));
    --chat-card-bg: rgba(44, 44, 46, 0.85);
    --chat-text: #ffffff;
    --chat-subtext: #8e8e93;
    --chat-border: rgba(255, 255, 255, 0.16);
    --mobile-chat-height: 78dvh;
}

/* Floating Launch Button */
.macdesk-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: linear-gradient(135deg, #0a84ff 0%, #0056b3 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 30px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(10, 132, 255, 0.4);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.macdesk-chat-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 30px rgba(10, 132, 255, 0.55);
}

.macdesk-chat-btn .icon {
    font-size: 18px;
}

/* Main Modal Window */
.macdesk-chat-modal {
    position: fixed;
    bottom: 84px;
    right: 24px;
    width: 380px;
    min-width: 320px;
    max-width: calc(100vw - 32px);
    height: 540px;
    min-height: 380px;
    max-height: calc(100vh - 100px);
    background: rgba(28, 28, 30, var(--chat-bg-opacity, 0.95));
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--chat-border);
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}

.macdesk-chat-modal.open {
    transform: translateY(0) scale(1);
    opacity: var(--chat-modal-opacity, 0.95);
    visibility: visible;
    pointer-events: auto;
}

.macdesk-chat-modal.maximized {
    width: min(720px, calc(100vw - 40px)) !important;
    height: min(780px, calc(100vh - 100px)) !important;
}

.macdesk-chat-modal.dragging,
.macdesk-chat-modal.resizing {
    transition: none !important;
    user-select: none;
    -webkit-user-select: none;
}

/* Desktop Resize Handles */
.chat-resize-handle {
    position: absolute;
    z-index: 10005;
}

.chat-resize-handle.resize-n {
    top: 0;
    left: 14px;
    right: 14px;
    height: 7px;
    cursor: ns-resize;
}

.chat-resize-handle.resize-s {
    bottom: 0;
    left: 14px;
    right: 14px;
    height: 7px;
    cursor: ns-resize;
}

.chat-resize-handle.resize-w {
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 7px;
    cursor: ew-resize;
}

.chat-resize-handle.resize-e {
    right: 0;
    top: 14px;
    bottom: 14px;
    width: 7px;
    cursor: ew-resize;
}

.chat-resize-handle.resize-nw {
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
}

.chat-resize-handle.resize-ne {
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

.chat-resize-handle.resize-sw {
    bottom: 0;
    left: 0;
    width: 16px;
    height: 16px;
    cursor: nesw-resize;
}

.chat-resize-handle.resize-se {
    bottom: 0;
    right: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
}

/* Subtle corner grip indicators */
.chat-resize-handle.resize-nw::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    border-top: 2px solid rgba(255, 255, 255, 0.35);
    border-left: 2px solid rgba(255, 255, 255, 0.35);
    border-top-left-radius: 3px;
}

.chat-resize-handle.resize-se::after {
    content: "";
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 6px;
    height: 6px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.35);
    border-right: 2px solid rgba(255, 255, 255, 0.35);
    border-bottom-right-radius: 3px;
}

/* Mobile top grabber bar (hidden on desktop) */
.chat-sheet-notch {
    display: none;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: rgba(44, 44, 46, 0.7);
    border-bottom: 1px solid var(--chat-border);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.macdesk-chat-modal.dragging .chat-header {
    cursor: grabbing;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: default;
}

.chat-header-btn {
    background: none;
    border: none;
    color: var(--chat-subtext);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    padding: 0;
    transition: color 0.2s, background 0.2s, transform 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

.chat-header-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
}

.chat-expand-btn svg {
    transition: transform 0.25s ease;
}

.macdesk-chat-modal.maximized .chat-expand-btn svg {
    transform: rotate(180deg);
}

.chat-close-btn {
    font-size: 20px;
    line-height: 1;
}

.chat-close-btn:hover {
    transform: scale(1.12);
}

.chat-opacity-control {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.35);
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    cursor: default;
}

.opacity-icon {
    font-size: 11px;
    opacity: 0.8;
}

.chat-opacity-slider {
    width: 46px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.chat-opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #0a84ff;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.chat-opacity-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #0a84ff;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    background: #0a84ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-title-group h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #30d158;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: #30d158;
    border-radius: 50%;
    animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Quick Topic Chips */
.chat-chips {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    overflow-x: auto;
    scrollbar-width: none;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--chat-border);
}

.chat-chips::-webkit-scrollbar {
    display: none;
}

.chat-chip {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 5px 10px;
    font-size: 11px;
    color: #e5e5ea;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

.chat-chip:hover {
    background: rgba(10, 132, 255, 0.25);
    border-color: #0a84ff;
    color: #ffffff;
}

/* Message History Area */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
}

.chat-bubble.assistant {
    align-self: flex-start;
    background: var(--chat-card-bg);
    color: #ffffff;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-bubble.user {
    align-self: flex-end;
    background: var(--chat-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-bubble code {
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: ui-monospace, Menlo, Monaco, monospace;
    font-size: 11px;
}

.chat-bubble pre {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
}

.chat-bubble pre code {
    background: none;
    padding: 0;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--chat-card-bg);
    border-radius: 14px;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #8e8e93;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input Area */
.chat-input-area {
    padding: 12px 14px;
    background: rgba(44, 44, 46, 0.6);
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 8px 14px;
    color: #ffffff;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--chat-primary);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    background: var(--chat-primary);
    border: none;
    border-radius: 50%;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--chat-primary-hover);
    transform: scale(1.05);
}

/* ========================================================
   Mobile Bottom Sheet Design (<= 640px)
   ======================================================== */
@media (max-width: 640px) {
    /* Hide floating button when chat is open on mobile */
    body.macdesk-chat-open .macdesk-chat-btn {
        opacity: 0;
        pointer-events: none;
        transform: translateY(16px) scale(0.85);
    }

    .macdesk-chat-btn {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: 16px;
        padding: 10px 15px;
        font-size: 13px;
        gap: 6px;
        box-shadow: 0 6px 20px rgba(10, 132, 255, 0.45);
    }

    .macdesk-chat-btn .icon {
        font-size: 16px;
    }

    /* Modal transformed into a modern iOS Bottom Sheet */
    .macdesk-chat-modal {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: var(--mobile-chat-height, 78dvh) !important;
        min-height: 260px !important;
        max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 10px) !important;
        border-radius: 20px 20px 0 0 !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: none !important;
        box-shadow: 0 -12px 35px rgba(0, 0, 0, 0.65);
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.18, 0.89, 0.32, 1.05), opacity 0.22s, visibility 0.22s;
    }

    .macdesk-chat-modal.open {
        transform: translateY(0);
        opacity: var(--chat-modal-opacity, 0.98);
        visibility: visible;
        pointer-events: auto;
    }

    .macdesk-chat-modal.maximized {
        height: calc(100dvh - env(safe-area-inset-top, 0px)) !important;
        border-radius: 0 !important;
    }

    .chat-resize-handle {
        display: none !important;
    }

    /* iOS Drag Handle Notch */
    .chat-sheet-notch {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 8px 0 2px;
        cursor: grab;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        flex-shrink: 0;
    }

    .notch-bar {
        width: 38px;
        height: 4.5px;
        border-radius: 3px;
        background: rgba(255, 255, 255, 0.35);
        transition: background 0.2s, width 0.2s;
    }

    .chat-sheet-notch:active .notch-bar {
        background: rgba(255, 255, 255, 0.7);
        width: 48px;
    }

    .chat-header {
        padding: 6px 14px 10px;
        cursor: default;
    }

    .chat-header-info {
        gap: 8px;
        min-width: 0;
        flex: 1;
    }

    .chat-avatar {
        width: 30px;
        height: 30px;
        font-size: 14px;
        flex-shrink: 0;
    }

    .chat-title-group {
        min-width: 0;
        overflow: hidden;
    }

    .chat-title-group h4 {
        font-size: 13px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-status {
        font-size: 10.5px;
        white-space: nowrap;
    }

    .chat-header-actions {
        gap: 4px;
        flex-shrink: 0;
    }

    .chat-opacity-control {
        padding: 2px 6px;
    }

    .chat-opacity-slider {
        width: 36px;
    }

    .chat-chips {
        padding: 8px 12px;
        gap: 5px;
        -webkit-overflow-scrolling: touch;
    }

    .chat-chip {
        padding: 4px 9px;
        font-size: 11px;
    }

    .chat-messages {
        padding: 12px 14px;
        gap: 10px;
    }

    .chat-bubble {
        max-width: 90%;
        font-size: 13px;
        padding: 9px 12px;
    }

    .chat-input-area {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }

    .chat-input {
        font-size: 16px; /* Prevents auto-zoom in mobile Safari */
        padding: 9px 14px;
    }

    .chat-send-btn {
        width: 38px;
        height: 38px;
        flex-shrink: 0;
    }
}

/* Extra small mobile screens (<= 380px) */
@media (max-width: 380px) {
    .chat-opacity-slider {
        width: 28px;
    }

    .chat-title-group h4 {
        font-size: 12px;
    }

    .chat-status {
        font-size: 9.5px;
    }

    .chat-chips {
        padding: 6px 10px;
    }
}
