/**
 * WorkmanBot Chat Widget — Frontend Styles
 *
 * Fully self-contained with .workmanbot- prefix to avoid theme conflicts.
 * Dark mode by default. CSS custom properties for theming.
 */

/* ── Custom Properties ── */
:root {
    --workmanbot-primary: #f5a623;
    --workmanbot-bg: #1a1a1a;
    --workmanbot-surface: #2a2a2a;
    --workmanbot-header-bg: #111111;
    --workmanbot-text: #ffffff;
    --workmanbot-text-muted: #999999;
    --workmanbot-input-bg: #333333;
    --workmanbot-input-border: #444444;
    --workmanbot-bubble-size: 64px;
    --workmanbot-panel-width: 400px;
    --workmanbot-panel-height: 520px;
    --workmanbot-radius: 12px;
    --workmanbot-radius-sm: 8px;
    --workmanbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --workmanbot-z: 999999;
}

/* ── Reset for widget scope ── */
.workmanbot-container,
.workmanbot-container *,
.workmanbot-container *::before,
.workmanbot-container *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Container ── */
.workmanbot-container {
    position: fixed;
    bottom: 28px;
    z-index: var(--workmanbot-z);
    font-size: 14px;
    color: var(--workmanbot-text);
}

.workmanbot-container--bottom-right {
    right: 20px;
}

.workmanbot-container--bottom-left {
    left: 20px;
}

/* ── Chat Bubble Button ── */
.workmanbot-bubble {
    width: var(--workmanbot-bubble-size);
    height: var(--workmanbot-bubble-size);
    border-radius: 50%;
    background: var(--workmanbot-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    position: relative;
    outline: none;
}

.workmanbot-bubble:hover {
    transform: scale(1.08);
    filter: brightness(1.15);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), 0 3px 10px rgba(0, 0, 0, 0.18);
}

.workmanbot-bubble:active {
    transform: scale(0.95);
}

.workmanbot-bubble:focus-visible {
    outline: 2px solid var(--workmanbot-primary);
    outline-offset: 3px;
}

.workmanbot-bubble svg {
    width: 30px;
    height: 30px;
    fill: #ffffff;
}

/* Close icon when panel is open */
.workmanbot-bubble--open svg.workmanbot-icon-chat {
    display: none;
}

.workmanbot-bubble svg.workmanbot-icon-close {
    display: none;
}

.workmanbot-bubble--open svg.workmanbot-icon-close {
    display: block;
}

/* Pulse animation on first load — more noticeable with glow */
.workmanbot-bubble--pulse {
    animation: workmanbot-pulse 2s ease-in-out 3;
}

@keyframes workmanbot-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15);
    }
    50% {
        transform: scale(1.12);
        box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), 0 0 12px rgba(255, 255, 255, 0.15);
    }
}

/* ── Chat Label Below Bubble ── */
.workmanbot-bubble-label {
    position: absolute;
    bottom: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 700;
    color: #333333;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
    pointer-events: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Hide label when panel is open */
.workmanbot-bubble--open .workmanbot-bubble-label {
    display: none;
}

/* ── Chat Panel ── */
.workmanbot-panel {
    position: absolute;
    bottom: calc(var(--workmanbot-bubble-size) + 16px);
    width: var(--workmanbot-panel-width);
    height: var(--workmanbot-panel-height);
    background: var(--workmanbot-bg);
    border-radius: var(--workmanbot-radius);
    box-shadow: var(--workmanbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.workmanbot-panel[hidden] {
    display: none !important;
}

.workmanbot-container--bottom-right .workmanbot-panel {
    right: 0;
}

.workmanbot-container--bottom-left .workmanbot-panel {
    left: 0;
}

.workmanbot-panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Panel Header ── */
.workmanbot-header {
    background: var(--workmanbot-header-bg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.workmanbot-header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--workmanbot-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.workmanbot-header-title::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    animation: workmanbot-online-pulse 3s ease-in-out infinite;
}

@keyframes workmanbot-online-pulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 4px rgba(74, 222, 128, 0);
    }
}

.workmanbot-header-actions {
    display: flex;
    gap: 4px;
}

.workmanbot-header-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--workmanbot-text-muted);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
    outline: none;
}

.workmanbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--workmanbot-text);
}

.workmanbot-header-btn:focus-visible {
    outline: 2px solid var(--workmanbot-primary);
    outline-offset: -2px;
}

/* ── Messages Area ── */
.workmanbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.workmanbot-messages::-webkit-scrollbar {
    width: 5px;
}

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

.workmanbot-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* ── Message Wrapper (bubble + timestamp) ── */
.workmanbot-msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: workmanbot-message-in 0.3s ease;
}

.workmanbot-msg-wrapper--bot {
    align-self: flex-start;
}

.workmanbot-msg-wrapper--user {
    align-self: flex-end;
    align-items: flex-end;
}

@keyframes workmanbot-message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Timestamp ── */
.workmanbot-timestamp {
    font-size: 10px;
    color: var(--workmanbot-text-muted);
    margin-top: 3px;
    padding: 0 4px;
    opacity: 0.6;
}

/* ── Message Bubbles ── */
.workmanbot-message {
    padding: 10px 14px;
    border-radius: var(--workmanbot-radius-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 14px;
    line-height: 1.55;
    max-height: 300px;
    overflow-y: auto;
}

.workmanbot-message--bot {
    background: var(--workmanbot-surface);
    color: var(--workmanbot-text);
    border-bottom-left-radius: 4px;
}

.workmanbot-message--user {
    background: var(--workmanbot-primary);
    color: #ffffff;
    font-size: 14px;
    border-bottom-right-radius: 4px;
}

/* ── Bot Message Rich Content ── */
.workmanbot-message--bot p {
    margin-bottom: 8px;
}

.workmanbot-message--bot p:last-child {
    margin-bottom: 0;
}

.workmanbot-message--bot strong {
    color: var(--workmanbot-primary);
    font-weight: 600;
}

.workmanbot-message--bot em {
    font-style: italic;
    color: #cccccc;
}

.workmanbot-message--bot a {
    color: var(--workmanbot-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.workmanbot-message--bot a:hover {
    opacity: 0.85;
}

.workmanbot-message--bot ol,
.workmanbot-message--bot ul {
    margin: 8px 0;
    padding-left: 20px;
}

.workmanbot-message--bot li {
    margin-bottom: 4px;
    line-height: 1.5;
}

.workmanbot-message--bot li:last-child {
    margin-bottom: 0;
}

.workmanbot-message--bot ol {
    list-style-type: decimal;
}

.workmanbot-message--bot ul {
    list-style-type: disc;
}

/* ── Typing Indicator ── */
.workmanbot-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--workmanbot-surface);
    border-radius: var(--workmanbot-radius-sm);
    border-bottom-left-radius: 4px;
}

.workmanbot-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--workmanbot-text-muted);
    animation: workmanbot-bounce 1.4s infinite ease-in-out;
}

.workmanbot-typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.workmanbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.workmanbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes workmanbot-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ── Input Area ── */
.workmanbot-input-area {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--workmanbot-bg);
    flex-shrink: 0;
}

.workmanbot-input {
    flex: 1;
    background: var(--workmanbot-input-bg) !important;
    border: 1px solid var(--workmanbot-input-border);
    border-radius: var(--workmanbot-radius-sm);
    padding: 10px 12px;
    color: #ffffff !important;
    font-size: 16px;
    resize: none;
    min-height: 42px;
    max-height: 100px;
    outline: none;
    transition: border-color 0.15s ease;
    font-family: inherit;
    line-height: 1.4;
    -webkit-text-fill-color: #ffffff;
}

.workmanbot-input::placeholder {
    color: #999999 !important;
    -webkit-text-fill-color: #999999;
    opacity: 1;
}

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

.workmanbot-send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--workmanbot-radius-sm);
    background: var(--workmanbot-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
    outline: none;
}

.workmanbot-send-btn:hover {
    opacity: 0.9;
}

.workmanbot-send-btn:active {
    transform: scale(0.93);
}

.workmanbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.workmanbot-send-btn:focus-visible {
    outline: 2px solid var(--workmanbot-primary);
    outline-offset: 2px;
}

.workmanbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}

/* ── Powered By ── */
.workmanbot-powered {
    text-align: center;
    padding: 6px 12px;
    font-size: 11px;
    color: var(--workmanbot-text-muted);
    background: var(--workmanbot-bg);
    flex-shrink: 0;
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .workmanbot-container {
        --workmanbot-bubble-size: 52px;
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }

    .workmanbot-container--bottom-right {
        right: 16px;
    }

    .workmanbot-container--bottom-left {
        left: 16px;
    }

    .workmanbot-bubble svg {
        width: 25px;
        height: 25px;
    }

    .workmanbot-bubble-label {
        display: none;
    }

    .workmanbot-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: calc(var(--workmanbot-z) + 1);
    }

    .workmanbot-container--bottom-right .workmanbot-panel,
    .workmanbot-container--bottom-left .workmanbot-panel {
        right: 0;
        left: 0;
    }

    .workmanbot-panel--open {
        transform: translateY(0) scale(1);
    }

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

    .workmanbot-header {
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
    }
}

@media (max-width: 480px) {
    .workmanbot-msg-wrapper {
        max-width: 92%;
    }

    .workmanbot-message {
        font-size: 15px;
    }
}

/* ── Quick Reply Chips ── */
.workmanbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 16px 12px;
    animation: workmanbot-message-in 0.3s ease;
}

.workmanbot-quick-reply {
    background: transparent;
    border: 1.5px solid var(--workmanbot-primary);
    color: var(--workmanbot-primary);
    padding: 6px 14px;
    border-radius: 18px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    white-space: nowrap;
    outline: none;
    font-family: inherit;
    line-height: 1.3;
}

.workmanbot-quick-reply:hover {
    background: var(--workmanbot-primary);
    color: #ffffff;
}

.workmanbot-quick-reply:active {
    transform: scale(0.95);
}

.workmanbot-quick-reply:focus-visible {
    outline: 2px solid var(--workmanbot-primary);
    outline-offset: 2px;
}

/* ── Print: Hide Widget ── */
@media print {
    .workmanbot-container {
        display: none !important;
    }
}
