/* ======================================================================
   HUKO HELPDESK — Standalone Website Chat Widget
   Modern floating popup with image previews, typing, drag-drop
   ====================================================================== */

:root {
    --hw-primary: #6366f1;
    --hw-primary-dark: #4f46e5;
    --hw-primary-light: #eef2ff;
    --hw-surface: #ffffff;
    --hw-bg: #f8fafc;
    --hw-text: #1e293b;
    --hw-text-muted: #64748b;
    --hw-border: #e2e8f0;
    --hw-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
    --hw-radius: 16px;
    --hw-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ==================== WIDGET ROOT ==================== */
.huko-helpdesk-widget {
    position: fixed;
    bottom: 20px;
    z-index: 99990;
    font-family: var(--hw-font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--hw-text);
    -webkit-font-smoothing: antialiased;
}

.huko-helpdesk-widget[data-position="right"] { right: 20px; }
.huko-helpdesk-widget[data-position="left"] { left: 20px; }

.huko-helpdesk-widget *,
.huko-helpdesk-widget *::before,
.huko-helpdesk-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ==================== TOGGLE BUTTON ==================== */
.huko-helpdesk-toggle {
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--hw-primary), var(--hw-primary-dark));
    color: #fff;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
    padding: 0 20px 0 14px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.huko-helpdesk-toggle:hover {
    box-shadow: 0 6px 28px rgba(99, 102, 241, 0.45);
    transform: translateY(-2px);
}

.huko-helpdesk-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
    pointer-events: none;
}

.huko-helpdesk-toggle__icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.huko-helpdesk-toggle__icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.huko-helpdesk-toggle__dot {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid var(--hw-primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
    animation: hwPulse 2s infinite;
}

@keyframes hwPulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.1); }
}

/* ==================== PANEL ==================== */
.huko-helpdesk-panel {
    width: min(400px, calc(100vw - 24px));
    height: min(640px, calc(100vh - 100px));
    margin-top: 12px;
    border-radius: var(--hw-radius);
    border: 1px solid var(--hw-border);
    background: var(--hw-surface);
    box-shadow: var(--hw-shadow);
    display: none;
    overflow: hidden;
    flex-direction: column;
    animation: hwSlideUp 0.3s ease-out;
}

.huko-helpdesk-widget.is-open .huko-helpdesk-panel {
    display: flex;
}

@keyframes hwSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== HEADER ==================== */
.huko-helpdesk-header {
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--hw-primary), var(--hw-primary-dark));
    color: #fff;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.huko-helpdesk-header::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 60%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.08), transparent 70%);
    pointer-events: none;
}

.huko-helpdesk-header__top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.huko-helpdesk-header h4 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    line-height: 1.3;
}

.huko-helpdesk-header p {
    margin: 3px 0 0;
    font-size: 12px;
    opacity: 0.85;
}

.huko-helpdesk-header__close {
    border: 0;
    background: rgba(255,255,255,0.15);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.15s;
    flex-shrink: 0;
}

.huko-helpdesk-header__close:hover { background: rgba(255,255,255,0.25); }

.huko-helpdesk-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 500;
}

.huko-helpdesk-status__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
}

.huko-helpdesk-status.is-offline .huko-helpdesk-status__dot { background: #94a3b8; }

/* ==================== BODY ==================== */
.huko-helpdesk-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--hw-bg);
}

/* ==================== PRE-CHAT FORM ==================== */
.huko-helpdesk-prechat {
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    justify-content: center;
}

.huko-helpdesk-prechat__intro {
    font-size: 13px;
    color: var(--hw-text-muted);
    text-align: center;
    margin-bottom: 4px;
    line-height: 1.5;
}

.huko-helpdesk-prechat input {
    width: 100%;
    border: 1px solid var(--hw-border);
    border-radius: 10px;
    font-size: 13px;
    padding: 10px 12px;
    background: #fff;
    color: var(--hw-text);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.huko-helpdesk-prechat input:focus {
    border-color: var(--hw-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.huko-helpdesk-prechat input::placeholder { color: #94a3b8; }

.huko-helpdesk-prechat__btn {
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--hw-primary), var(--hw-primary-dark));
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    padding: 11px 16px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.huko-helpdesk-prechat__btn:hover {
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}

.huko-helpdesk-prechat__btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ==================== MESSAGE THREAD ==================== */
.huko-helpdesk-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    display: none;
    gap: 8px;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 10% 10%, rgba(99, 102, 241, 0.04), transparent 50%),
        radial-gradient(ellipse at 90% 90%, rgba(16, 185, 129, 0.03), transparent 50%),
        var(--hw-bg);
}

.huko-helpdesk-thread.is-active { display: flex; }

/* ==================== MESSAGE BUBBLES ==================== */
.huko-helpdesk-message {
    max-width: 84%;
    animation: hwMsgIn 0.2s ease-out;
}

@keyframes hwMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.huko-helpdesk-message__bubble {
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}

.huko-helpdesk-message--visitor {
    margin-left: auto;
    align-self: flex-end;
}

.huko-helpdesk-message--visitor .huko-helpdesk-message__bubble {
    background: linear-gradient(135deg, var(--hw-primary), var(--hw-primary-dark));
    color: #fff;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.huko-helpdesk-message--visitor .huko-helpdesk-message__meta { color: rgba(255,255,255,0.6); }

.huko-helpdesk-message--staff,
.huko-helpdesk-message--admin {
    margin-right: auto;
    align-self: flex-start;
}

.huko-helpdesk-message--staff .huko-helpdesk-message__bubble,
.huko-helpdesk-message--admin .huko-helpdesk-message__bubble {
    background: #fff;
    border: 1px solid var(--hw-border);
    color: var(--hw-text);
    border-radius: 4px 14px 14px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.huko-helpdesk-message--system {
    margin: 2px auto;
    max-width: 90%;
    align-self: center;
}

.huko-helpdesk-message--system .huko-helpdesk-message__bubble {
    background: #fefce8;
    border: 1px solid #fef08a;
    border-radius: 8px;
    text-align: center;
    font-size: 12px;
    color: #854d0e;
    padding: 6px 12px;
}

.huko-helpdesk-message__meta {
    font-size: 10px;
    color: var(--hw-text-muted);
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

/* ==================== MESSAGE ATTACHMENTS ==================== */
.huko-helpdesk-message__files {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.huko-helpdesk-message__files a {
    text-decoration: none;
    color: inherit;
}

.hw-attach-thumb {
    display: inline-block;
    border-radius: 8px;
    overflow: hidden;
    max-width: 160px;
    max-height: 120px;
    border: 1px solid rgba(0,0,0,0.06);
    transition: transform 0.2s;
}

.hw-attach-thumb:hover { transform: scale(1.03); }
.hw-attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.hw-attach-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    background: rgba(0,0,0,0.05);
    transition: background 0.15s;
}

.hw-attach-file:hover { background: rgba(0,0,0,0.1); }

/* ==================== TYPING INDICATOR ==================== */
.huko-helpdesk-typing {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 14px 0;
    font-size: 11px;
    color: var(--hw-text-muted);
}

.huko-helpdesk-typing.is-active { display: flex; }

.hw-typing-dots {
    display: flex;
    gap: 3px;
}

.hw-typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--hw-primary);
    animation: hwTypingBounce 1.2s infinite;
}

.hw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.hw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes hwTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ==================== COMPOSER ==================== */
.huko-helpdesk-composer {
    border-top: 1px solid var(--hw-border);
    background: #fff;
    display: none;
    flex-shrink: 0;
}

.huko-helpdesk-composer.is-active { display: block; }

/* Attachment Preview */
.hw-attach-preview {
    display: none;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

.hw-attach-preview.is-active { display: block; }

.hw-attach-preview__list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.hw-attach-preview-item {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--hw-border);
    width: 48px;
    height: 48px;
}

.hw-attach-preview-item img { width: 100%; height: 100%; object-fit: cover; }

.hw-attach-preview-item--file {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    font-size: 9px;
    color: var(--hw-text-muted);
    text-align: center;
    padding: 2px;
    word-break: break-all;
}

.hw-attach-preview-item__remove {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    cursor: pointer;
    transition: background 0.15s;
    line-height: 1;
}

.hw-attach-preview-item__remove:hover { background: #ef4444; }

/* Composer Row */
.huko-helpdesk-composer__row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
}

.hw-composer-attach-btn {
    border: 0;
    background: transparent;
    color: var(--hw-text-muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    transition: all 0.15s;
}

.hw-composer-attach-btn:hover { background: var(--hw-primary-light); color: var(--hw-primary); }

.huko-helpdesk-composer textarea {
    flex: 1;
    border: 0;
    outline: 0;
    resize: none;
    font-size: 13px;
    font-family: inherit;
    min-height: 34px;
    max-height: 100px;
    padding: 6px 0;
    line-height: 1.5;
    color: var(--hw-text);
    background: transparent;
}

.huko-helpdesk-composer textarea::placeholder { color: #94a3b8; }

.hw-send-btn {
    border: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--hw-primary), var(--hw-primary-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.hw-send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); }
.hw-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.huko-helpdesk-composer input[type="file"] { display: none; }

/* Drop Overlay */
.hw-drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(99, 102, 241, 0.08);
    backdrop-filter: blur(2px);
    border: 2px dashed var(--hw-primary);
    border-radius: var(--hw-radius);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
    color: var(--hw-primary);
    font-weight: 600;
    font-size: 13px;
}

.hw-drop-overlay.is-active { display: flex; }
.hw-drop-overlay svg { width: 36px; height: 36px; fill: var(--hw-primary); }

/* ==================== ERROR ==================== */
.huko-helpdesk-error {
    font-size: 12px;
    color: #dc2626;
    min-height: 0;
}

.huko-helpdesk-error:empty { display: none; }

.huko-helpdesk-composer .huko-helpdesk-error {
    padding: 0 12px 6px;
}

/* ==================== POWERED BY ==================== */
.hw-powered-by {
    text-align: center;
    padding: 4px 0 6px;
    font-size: 10px;
    color: #94a3b8;
    background: #fff;
    border-top: 1px solid rgba(226, 232, 240, 0.5);
}

.hw-powered-by a { color: var(--hw-primary); text-decoration: none; font-weight: 600; }

/* ==================== SATISFACTION RATING ==================== */
.hw-rating {
    display: none;
    padding: 14px;
    text-align: center;
    border-top: 1px solid var(--hw-border);
    background: #fff;
}

.hw-rating.is-active { display: block; }

.hw-rating__title { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--hw-text); }

.hw-rating__stars {
    display: flex;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
}

.hw-rating__stars svg {
    width: 28px;
    height: 28px;
    fill: #d1d5db;
    transition: fill 0.15s, transform 0.15s;
}

.hw-rating__stars svg:hover,
.hw-rating__stars svg.active { fill: #f59e0b; transform: scale(1.15); }

.hw-rating__feedback {
    width: 100%;
    border: 1px solid var(--hw-border);
    border-radius: 8px;
    font-size: 12px;
    padding: 8px 10px;
    font-family: inherit;
    resize: none;
    margin-top: 8px;
    outline: none;
    color: var(--hw-text);
}

.hw-rating__feedback:focus { border-color: var(--hw-primary); }

.hw-rating__submit {
    border: 0;
    border-radius: 8px;
    background: var(--hw-primary);
    color: #fff;
    font-weight: 600;
    font-size: 12px;
    padding: 8px 16px;
    cursor: pointer;
    margin-top: 8px;
    font-family: inherit;
    transition: opacity 0.15s;
}

.hw-rating__submit:hover { opacity: 0.9; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 767px) {
    .huko-helpdesk-widget {
        left: 10px !important;
        right: 10px !important;
        bottom: 10px;
    }

    .huko-helpdesk-widget[data-position="left"],
    .huko-helpdesk-widget[data-position="right"] {
        left: 10px !important;
        right: 10px !important;
    }

    .huko-helpdesk-toggle {
        width: 100%;
        justify-content: center;
    }

    .huko-helpdesk-panel {
        width: 100%;
        height: min(75vh, 580px);
    }
}
:root {
    --huko-chat-primary: #1456f0;
    --huko-chat-surface: #ffffff;
    --huko-chat-text: #1c2738;
    --huko-chat-muted: #6d7788;
    --huko-chat-border: #dfe4ef;
    --huko-chat-shadow: 0 14px 40px rgba(15, 26, 44, 0.2);
}

.huko-helpdesk-widget {
    position: fixed;
    bottom: 18px;
    z-index: 99990;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.huko-helpdesk-widget[data-position="right"] {
    right: 18px;
}

.huko-helpdesk-widget[data-position="left"] {
    left: 18px;
}

.huko-helpdesk-toggle {
    border: 0;
    border-radius: 999px;
    background: var(--huko-chat-primary);
    color: #fff;
    box-shadow: var(--huko-chat-shadow);
    padding: 12px 18px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
}

.huko-helpdesk-toggle__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #28d17c;
    box-shadow: 0 0 0 4px rgba(40, 209, 124, 0.22);
}

.huko-helpdesk-panel {
    width: min(390px, calc(100vw - 20px));
    height: min(620px, calc(100vh - 90px));
    margin-top: 10px;
    border-radius: 16px;
    border: 1px solid var(--huko-chat-border);
    background: var(--huko-chat-surface);
    box-shadow: var(--huko-chat-shadow);
    display: none;
    overflow: hidden;
}

.huko-helpdesk-widget.is-open .huko-helpdesk-panel {
    display: flex;
    flex-direction: column;
}

.huko-helpdesk-header {
    padding: 14px 16px;
    background: linear-gradient(130deg, var(--huko-chat-primary), color-mix(in srgb, var(--huko-chat-primary), #001f4d 30%));
    color: #fff;
}

.huko-helpdesk-header h4 {
    font-size: 16px;
    margin: 0;
    line-height: 1.3;
}

.huko-helpdesk-header p {
    margin: 4px 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.huko-helpdesk-status {
    margin-top: 8px;
    font-size: 11px;
    opacity: 0.95;
}

.huko-helpdesk-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: linear-gradient(180deg, #f8faff 0%, #f4f8ff 45%, #f9fbff 100%);
}

.huko-helpdesk-prechat {
    padding: 14px;
    display: grid;
    gap: 8px;
}

.huko-helpdesk-prechat input,
.huko-helpdesk-prechat textarea,
.huko-helpdesk-composer textarea,
.huko-helpdesk-composer input[type="file"] {
    width: 100%;
    border: 1px solid #cfd8e8;
    border-radius: 10px;
    font-size: 13px;
    padding: 9px 10px;
    background: #fff;
    color: var(--huko-chat-text);
}

.huko-helpdesk-prechat button,
.huko-helpdesk-composer button {
    border: 0;
    border-radius: 10px;
    background: var(--huko-chat-primary);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 10px 12px;
    cursor: pointer;
}

.huko-helpdesk-prechat-help {
    font-size: 12px;
    color: var(--huko-chat-muted);
}

.huko-helpdesk-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    display: none;
    gap: 10px;
    flex-direction: column;
}

.huko-helpdesk-thread.is-active {
    display: flex;
}

.huko-helpdesk-message {
    max-width: 85%;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #dbe4f3;
    background: #fff;
    color: var(--huko-chat-text);
    font-size: 13px;
    line-height: 1.35;
    word-break: break-word;
}

.huko-helpdesk-message--visitor {
    margin-left: auto;
    border-color: color-mix(in srgb, var(--huko-chat-primary), #b7c8f7 65%);
    background: color-mix(in srgb, var(--huko-chat-primary), #ffffff 88%);
}

.huko-helpdesk-message--staff,
.huko-helpdesk-message--admin {
    margin-right: auto;
    background: #ffffff;
}

.huko-helpdesk-message--system {
    max-width: 100%;
    background: #fff8e3;
    border-color: #ffe5a7;
}

.huko-helpdesk-message__meta {
    font-size: 11px;
    color: var(--huko-chat-muted);
    margin-bottom: 4px;
}

.huko-helpdesk-message__files {
    margin-top: 6px;
    font-size: 12px;
}

.huko-helpdesk-message__files a {
    color: var(--huko-chat-primary);
    text-decoration: none;
}

.huko-helpdesk-composer {
    border-top: 1px solid var(--huko-chat-border);
    padding: 10px;
    background: #fff;
    display: none;
}

.huko-helpdesk-composer.is-active {
    display: block;
}

.huko-helpdesk-composer-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.huko-helpdesk-composer textarea {
    resize: vertical;
    min-height: 44px;
    max-height: 110px;
}

.huko-helpdesk-error {
    font-size: 12px;
    color: #cb2935;
    margin-top: 4px;
}

.huko-helpdesk-muted {
    font-size: 12px;
    color: var(--huko-chat-muted);
}

@media (max-width: 767px) {
    .huko-helpdesk-widget {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }

    .huko-helpdesk-widget[data-position="left"],
    .huko-helpdesk-widget[data-position="right"] {
        left: 10px;
        right: 10px;
    }

    .huko-helpdesk-toggle {
        width: 100%;
        justify-content: center;
    }

    .huko-helpdesk-panel {
        width: 100%;
        height: min(72vh, 560px);
    }
}
