/**
 * Chat Widget Styles
 * Self-contained CSS for the support chat widget.
 * Covers both static HTML (chat-widget.php) and JS-generated elements (chat-widget.js).
 * Does NOT rely on Tailwind CDN.
 */

/* ─── Reset for widget elements ──────────────────────────── */
#chat-widget *,
#chat-widget *::before,
#chat-widget *::after {
    box-sizing: border-box;
}
#chat-widget button {
    font-family: inherit;
    cursor: pointer;
}
#chat-widget textarea,
#chat-widget input {
    font-family: inherit;
}

/* ─── Container ──────────────────────────────────────────── */
#chat-widget {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 50;
}

/* ─── Toggle Button ──────────────────────────────────────── */
#chat-widget-toggle {
    background-color: #2563eb;
    color: #fff;
    border: none;
    border-radius: 9999px;
    padding: 1rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    transition: background-color 0.3s, transform 0.3s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
#chat-widget-toggle:hover {
    background-color: #1d4ed8;
}
#chat-widget-toggle svg {
    width: 1.5rem;
    height: 1.5rem;
    display: block;
}

/* ─── Unread Badge ───────────────────────────────────────── */
#chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 9999px;
    min-width: 18px;
    height: 18px;
    padding: 0 3px;
    display: none;
    align-items: center;
    justify-content: center;
}
#chat-widget-badge:not(.hidden) {
    display: flex;
}

/* ─── Chat Window ────────────────────────────────────────── */
#chat-widget-window {
    position: absolute;
    bottom: 5rem;
    right: 0;
    width: 24rem;         /* w-96 */
    height: 32rem;        /* h-[32rem] */
    background-color: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
}
#chat-widget-window:not(.hidden) {
    display: flex;
}

/* ─── Window Header ──────────────────────────────────────── */
#chat-widget-window > .bg-blue-600,
.cw-header {
    background-color: #2563eb;
    color: #fff;
    padding: 1rem;
    border-radius: 0.5rem 0.5rem 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* Header left cluster */
#chat-widget-window > .bg-blue-600 > .flex,
.cw-header > .flex {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
#chat-widget-window > .bg-blue-600 svg,
.cw-header svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}
#chat-widget-window > .bg-blue-600 h3,
.cw-header h3 {
    font-weight: 600;
    margin: 0;
    font-size: 0.95rem;
}
#chat-status {
    font-size: 0.75rem;
    opacity: 0.9;
    margin: 0;
}

/* Close Button */
#chat-widget-close {
    background: transparent;
    border: none;
    color: #fff;
    border-radius: 0.25rem;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s;
}
#chat-widget-close:hover {
    background-color: #1d4ed8;
}
#chat-widget-close svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* ─── Messages Area ──────────────────────────────────────── */
#chat-messages {
    flex: 1 1 0%;
    overflow-y: auto;
    padding: 1rem;
    background-color: #f9fafb;
}
#chat-messages > * + * {
    margin-top: 0.75rem;
}

/* Welcome message */
#chat-messages .flex.justify-center {
    display: flex;
    justify-content: center;
}
#chat-messages .flex.justify-center > div {
    background-color: #dbeafe;
    color: #1e40af;
    font-size: 0.875rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
}

/* ─── Typing Indicator ───────────────────────────────────── */
#chat-typing {
    display: none;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #6b7280;
    font-style: italic;
    flex-shrink: 0;
}
#chat-typing:not(.hidden) {
    display: block;
}

/* ─── Input Area ─────────────────────────────────────────── */
#chat-widget-window > div:last-child {
    flex-shrink: 0;
    border-top: 1px solid #e5e7eb;
    padding: 1rem;
}

/* Input row */
#chat-widget-window > div:last-child > .flex {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

/* Image upload label */
#chat-widget-window label[for="chat-image-upload"] {
    cursor: pointer;
    border-radius: 0.25rem;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #4b5563;
    transition: background-color 0.15s;
}
#chat-widget-window label[for="chat-image-upload"]:hover {
    background-color: #f3f4f6;
}
#chat-widget-window label[for="chat-image-upload"] svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Hidden file input */
#chat-image-upload {
    display: none;
}

/* Textarea */
#chat-input {
    flex: 1 1 0%;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    resize: none;
    font-size: 0.875rem;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    line-height: 1.5;
}
#chat-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

/* Send button */
#chat-send {
    background-color: #2563eb;
    color: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s;
}
#chat-send:hover {
    background-color: #1d4ed8;
}
#chat-send svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* ─── Image Preview ──────────────────────────────────────── */
#chat-image-preview {
    display: none;
    margin-top: 0.5rem;
    position: relative;
}
#chat-image-preview:not(.hidden) {
    display: inline-block;
}
#chat-image-preview img {
    max-width: 20rem;
    max-height: 8rem;
    border-radius: 0.25rem;
    border: 1px solid #e5e7eb;
    display: block;
}
#chat-image-remove {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    background-color: #ef4444;
    color: #fff;
    border: none;
    border-radius: 9999px;
    padding: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}
#chat-image-remove:hover {
    background-color: #dc2626;
}
#chat-image-remove svg {
    width: 1rem;
    height: 1rem;
}

/* ─── Reply Preview Bar ──────────────────────────────────── */
#reply-preview-bar {
    display: none;
    margin-top: 0.5rem;
    background-color: #eff6ff;
    border-left: 4px solid #3b82f6;
    padding: 0.5rem;
    border-radius: 0 0.25rem 0.25rem 0;
    position: relative;
}
#reply-preview-bar:not(.hidden) {
    display: block;
}
#cancel-reply {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 2px;
    transition: color 0.15s;
}
#cancel-reply:hover {
    color: #374151;
}
#cancel-reply svg {
    width: 1rem;
    height: 1rem;
}
#reply-preview-bar > .text-xs {
    font-size: 0.75rem;
    color: #4b5563;
    margin-bottom: 0.25rem;
}
#reply-to-name {
    font-weight: 600;
}
#reply-preview-text {
    font-size: 0.875rem;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 1.5rem;
}

/* ════════════════════════════════════════════════════════════
   Tailwind utility classes used by chat-widget.js (dynamic)
   ══════════════════════════════════════════════════════════ */

/* Display */
#chat-widget .hidden          { display: none !important; }
#chat-widget .flex            { display: flex; }
#chat-widget .inline-block    { display: inline-block; }
#chat-widget .block           { display: block; }

/* Flex direction */
#chat-widget .flex-col         { flex-direction: column; }
#chat-widget .flex-row         { flex-direction: row; }
#chat-widget .flex-row-reverse { flex-direction: row-reverse; }

/* Flex align/justify */
#chat-widget .items-center  { align-items: center; }
#chat-widget .items-start   { align-items: flex-start; }
#chat-widget .items-end     { align-items: flex-end; }
#chat-widget .justify-center  { justify-content: center; }
#chat-widget .justify-between { justify-content: space-between; }
#chat-widget .justify-start   { justify-content: flex-start; }
#chat-widget .justify-end     { justify-content: flex-end; }
#chat-widget .flex-1          { flex: 1 1 0%; }
#chat-widget .flex-shrink-0   { flex-shrink: 0; }

/* Gap */
#chat-widget .gap-1 { gap: 0.25rem; }
#chat-widget .gap-2 { gap: 0.5rem; }

/* Width / Height */
#chat-widget .w-4  { width: 1rem; }
#chat-widget .h-4  { height: 1rem; }
#chat-widget .w-5  { width: 1.25rem; }
#chat-widget .h-5  { height: 1.25rem; }
#chat-widget .w-6  { width: 1.5rem; }
#chat-widget .h-6  { height: 1.5rem; }
#chat-widget .w-full { width: 100%; }
#chat-widget .max-w-xs  { max-width: 20rem; }
#chat-widget .max-w-md  { max-width: 28rem; }
#chat-widget .max-w-full { max-width: 100%; }
#chat-widget .max-h-32  { max-height: 8rem; }

/* Position */
#chat-widget .relative { position: relative; }
#chat-widget .absolute { position: absolute; }

/* Z-index */
#chat-widget .z-50 { z-index: 50; }

/* Overflow */
#chat-widget .overflow-hidden   { overflow: hidden; }
#chat-widget .overflow-y-auto   { overflow-y: auto; }

/* Spacing — margin */
#chat-widget .mb-1 { margin-bottom: 0.25rem; }
#chat-widget .mb-2 { margin-bottom: 0.5rem; }
#chat-widget .mb-4 { margin-bottom: 1rem; }
#chat-widget .mt-2 { margin-top: 0.5rem; }

/* Spacing — padding */
#chat-widget .p-1   { padding: 0.25rem; }
#chat-widget .p-1\.5 { padding: 0.375rem; }
#chat-widget .p-2   { padding: 0.5rem; }
#chat-widget .p-4   { padding: 1rem; }
#chat-widget .px-2  { padding-left: 0.5rem; padding-right: 0.5rem; }
#chat-widget .px-3  { padding-left: 0.75rem; padding-right: 0.75rem; }
#chat-widget .px-4  { padding-left: 1rem; padding-right: 1rem; }
#chat-widget .py-1  { padding-top: 0.25rem; padding-bottom: 0.25rem; }
#chat-widget .py-2  { padding-top: 0.5rem; padding-bottom: 0.5rem; }
#chat-widget .py-3  { padding-top: 0.75rem; padding-bottom: 0.75rem; }
#chat-widget .pr-6  { padding-right: 1.5rem; }

/* Background */
#chat-widget .bg-white      { background-color: #fff; }
#chat-widget .bg-gray-50    { background-color: #f9fafb; }
#chat-widget .bg-gray-100   { background-color: #f3f4f6; }
#chat-widget .bg-gray-200   { background-color: #e5e7eb; }
#chat-widget .bg-gray-700   { background-color: #374151; }
#chat-widget .bg-blue-50    { background-color: #eff6ff; }
#chat-widget .bg-blue-100   { background-color: #dbeafe; }
#chat-widget .bg-blue-500   { background-color: #3b82f6; }
#chat-widget .bg-blue-600   { background-color: #2563eb; }
#chat-widget .bg-red-500    { background-color: #ef4444; }
#chat-widget .bg-red-600    { background-color: #dc2626; }
#chat-widget .bg-gradient-to-br.from-blue-500.to-purple-600 {
    background-image: linear-gradient(to bottom right, #3b82f6, #9333ea);
}

/* Hover backgrounds */
#chat-widget .hover\:bg-blue-700:hover  { background-color: #1d4ed8; }
#chat-widget .hover\:bg-gray-100:hover  { background-color: #f3f4f6; }
#chat-widget .hover\:bg-gray-200:hover  { background-color: #e5e7eb; }
#chat-widget .hover\:bg-red-600:hover   { background-color: #dc2626; }

/* Text color */
#chat-widget .text-white      { color: #fff; }
#chat-widget .text-gray-500   { color: #6b7280; }
#chat-widget .text-gray-600   { color: #4b5563; }
#chat-widget .text-gray-700   { color: #374151; }
#chat-widget .text-gray-800   { color: #1f2937; }
#chat-widget .text-blue-800   { color: #1e40af; }

/* Hover text */
#chat-widget .hover\:text-gray-700:hover { color: #374151; }

/* Font size */
#chat-widget .text-xs   { font-size: 0.75rem;  line-height: 1rem; }
#chat-widget .text-sm   { font-size: 0.875rem; line-height: 1.25rem; }
#chat-widget .text-base { font-size: 1rem;     line-height: 1.5rem; }

/* Font weight */
#chat-widget .font-medium   { font-weight: 500; }
#chat-widget .font-semibold { font-weight: 600; }
#chat-widget .font-bold     { font-weight: 700; }

/* Font style */
#chat-widget .italic { font-style: italic; }

/* Border radius */
#chat-widget .rounded        { border-radius: 0.25rem; }
#chat-widget .rounded-lg     { border-radius: 0.5rem; }
#chat-widget .rounded-full   { border-radius: 9999px; }
#chat-widget .rounded-t-lg   { border-radius: 0.5rem 0.5rem 0 0; }
#chat-widget .rounded-br-none { border-bottom-right-radius: 0; }
#chat-widget .rounded-bl-none { border-bottom-left-radius: 0; }

/* Border */
#chat-widget .border        { border: 1px solid #e5e7eb; }
#chat-widget .border-t      { border-top: 1px solid #e5e7eb; }
#chat-widget .border-l-4    { border-left-width: 4px; border-left-style: solid; }
#chat-widget .border-gray-200 { border-color: #e5e7eb; }
#chat-widget .border-gray-300 { border-color: #d1d5db; }
#chat-widget .border-blue-500 { border-color: #3b82f6; }

/* Shadow */
#chat-widget .shadow-lg  { box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1); }
#chat-widget .shadow-md  { box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1); }
#chat-widget .shadow-2xl { box-shadow: 0 25px 50px -12px rgba(0,0,0,.25); }

/* Opacity */
#chat-widget .opacity-0  { opacity: 0; }
#chat-widget .opacity-60 { opacity: 0.6; }
#chat-widget .opacity-80 { opacity: 0.8; }
#chat-widget .opacity-90 { opacity: 0.9; }

/* Transition */
#chat-widget .transition         { transition: all 0.15s ease; }
#chat-widget .transition-all     { transition: all 0.3s ease; }
#chat-widget .transition-colors  { transition: background-color 0.15s, color 0.15s, border-color 0.15s; }
#chat-widget .transition-opacity { transition: opacity 0.15s ease; }

/* Cursor */
#chat-widget .cursor-pointer { cursor: pointer; }

/* Pointer events */
#chat-widget .pointer-events-none { pointer-events: none; }

/* Resize */
#chat-widget .resize-none { resize: none; }

/* Text overflow */
#chat-widget .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Group hover pattern */
#chat-widget .group:hover .group-hover\:opacity-100 { opacity: 1; }
#chat-widget .group:hover .group-hover\:block        { display: block; }

/* ─── Custom widget animations & component classes ───────── */

/* Message highlight animation (when scrolling to replied message) */
@keyframes cw-highlightPulse {
    0%, 100% { background-color: transparent; }
    50%       { background-color: rgba(59, 130, 246, 0.2); }
}
.message-highlight,
.highlight-message {
    animation: cw-highlightPulse 1.5s ease-in-out 2;
}

/* Message wrapper */
.message-wrapper {
    max-width: 100%;
}

/* Action menu (context menu for messages) */
.action-menu {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,.1);
    z-index: 50;
    min-width: 120px;
}
.action-menu.hidden {
    display: none;
}
.action-menu > div {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    font-size: 0.875rem;
    color: #374151;
    transition: background-color 0.15s;
    cursor: pointer;
}
.action-menu > div:hover          { background-color: #f3f4f6; }
.action-menu > div:first-child    { border-radius: 6px 6px 0 0; }
.action-menu > div:last-child     { border-radius: 0 0 6px 6px; }

/* Reply preview bubble outside message bubble */
.reply-preview-external {
    transition: opacity 0.15s, transform 0.15s;
}
.reply-preview-external:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

/* Deleted message */
.message-deleted {
    opacity: 0.6;
    font-style: italic;
    color: #9ca3af;
}

/* Edited indicator */
.message-edited-indicator {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-left: 6px;
}

/* Autoload spinner */
.autoload-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: cw-spin 0.6s linear infinite;
}
@keyframes cw-spin {
    to { transform: rotate(360deg); }
}

/* Reply icon button */
.reply-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    padding: 0.375rem;
    transition: background-color 0.15s;
    color: #4b5563;
}
.reply-icon-btn:hover {
    background-color: #e5e7eb;
}
.reply-icon-btn svg {
    width: 1rem;
    height: 1rem;
}

/* Message timestamp tooltip */
.message-timestamp {
    position: absolute;
    font-size: 0.75rem;
    color: #fff;
    padding: 0.25rem 0.5rem;
    background-color: #374151;
    border-radius: 0.25rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,.1);
    pointer-events: none;
    z-index: 50;
    white-space: nowrap;
    display: none;
}
.group:hover .message-timestamp {
    display: block;
}

/* ─── Mobile Responsive ──────────────────────────────────── */
@media (max-width: 480px) {
    /* Double ID for specificity > utility class ID+class rules */
    #chat-widget #chat-widget-window {
        position: fixed !important;
        bottom: 5rem;
        left: 0.75rem;
        right: 0.75rem;
        width: auto !important;
        height: calc(100dvh - 7rem);
        max-height: 32rem;
    }

    /* Prevent iOS Safari auto-zoom on input focus (requires font-size >= 16px) */
    #chat-input {
        font-size: 1rem;
    }
}
