/* ================================================================
   assets/css/image-chat.css
   Image Preview Modal + Chat Bubble + Lightbox styles
   ต้อง @import หรือ <link> ใน header.php / หน้า dashboard
   ================================================================ */

/* ── Attach button ──────────────────────────────────────────────── */
#img-attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--c-border);
    background: transparent;
    color: var(--c-text-2);
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
}
#img-attach-btn:hover {
    background: var(--c-hover, rgba(0,0,0,.05));
    color: var(--c-primary);
    border-color: var(--c-primary);
}

/* ── Hidden file input ──────────────────────────────────────────── */
#img-file-input { display: none; }

/* ── Drag-over highlight ────────────────────────────────────────── */
#chat-input-area.drag-over {
    outline: 2px dashed var(--c-primary);
    outline-offset: -4px;
    background: color-mix(in srgb, var(--c-primary) 5%, transparent);
    border-radius: var(--radius-md, 8px);
    transition: outline .1s;
}

/* ── Preview overlay ────────────────────────────────────────────── */
#img-preview-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
#img-preview-overlay.open {
    opacity: 1;
    pointer-events: all;
}

/* ── Preview modal ──────────────────────────────────────────────── */
#img-preview-modal {
    background: var(--c-surface);
    border-radius: var(--radius-lg, 16px);
    box-shadow: 0 24px 80px rgba(0,0,0,.3);
    width: min(480px, 92vw);
    overflow: hidden;
    transform: scale(.94) translateY(10px);
    transition: transform .2s;
}
#img-preview-overlay.open #img-preview-modal {
    transform: scale(1) translateY(0);
}

.img-preview-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.img-preview-header h3 {
    font-size: .95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.img-preview-body {
    padding: 20px;
}

/* รูปตัวอย่าง */
.img-preview-frame {
    border-radius: var(--radius-md, 10px);
    overflow: hidden;
    background: var(--c-bg, #f4f4f4);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    max-height: 320px;
    margin-bottom: 14px;
    border: 1px solid var(--c-border);
    position: relative;
}
#img-preview-img {
    max-width: 100%;
    max-height: 320px;
    object-fit: contain;
    display: block;
}

/* ข้อมูลไฟล์ */
.img-file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--c-bg, #f8f8f8);
    border-radius: var(--radius-md, 8px);
    margin-bottom: 16px;
    border: 1px solid var(--c-border);
}
.img-file-info .file-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}
.img-file-info .file-meta { flex: 1; min-width: 0; }
#img-preview-name {
    font-size: .85rem;
    font-weight: 600;
    color: var(--c-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#img-preview-size {
    font-size: .75rem;
    color: var(--c-text-2);
    margin-top: 2px;
}

/* Progress bar */
#img-send-progress {
    margin-bottom: 14px;
}
#img-send-progress.hidden { display: none; }
.img-prog-bar-wrap {
    height: 6px;
    background: var(--c-border);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 4px;
}
#img-send-bar {
    height: 100%;
    background: var(--c-primary);
    border-radius: 99px;
    transition: width .25s ease;
    width: 0%;
}
.img-prog-label {
    font-size: .72rem;
    color: var(--c-text-2);
}

/* Buttons */
.img-preview-footer {
    display: flex;
    gap: 10px;
    padding: 0 20px 20px;
}
.img-preview-footer .btn { flex: 1; }

/* ── Chat image thumbnail ───────────────────────────────────────── */
.msg-bubble--image {
    padding: 4px !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 260px;
}
.chat-img-thumb {
    display: block;
    width: 100%;
    max-width: 260px;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-md, 10px);
    cursor: pointer;
    transition: opacity .15s, transform .15s;
    border: 1px solid var(--c-border);
}
.chat-img-thumb:hover {
    opacity: .9;
    transform: scale(1.01);
}

/* รูปขาเข้า (ลูกค้าส่งมา) */
.msg-in .chat-img-thumb {
    border-radius: 4px 10px 10px 10px;
}
/* รูปขาออก (เราส่ง) */
.msg-out .chat-img-thumb {
    border-radius: 10px 4px 10px 10px;
}

/* Loading skeleton */
.chat-img-thumb[data-loading] {
    background: linear-gradient(90deg,
        var(--c-border) 25%,
        color-mix(in srgb, var(--c-border) 60%, transparent) 50%,
        var(--c-border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Lightbox ───────────────────────────────────────────────────── */
#img-lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    cursor: zoom-out;
}
#img-lightbox.open {
    opacity: 1;
    pointer-events: all;
}
#img-lightbox-img {
    max-width: min(90vw, 1200px);
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-md, 10px);
    box-shadow: 0 20px 80px rgba(0,0,0,.5);
    transform: scale(.95);
    transition: transform .2s;
    cursor: default;
}
#img-lightbox.open #img-lightbox-img { transform: scale(1); }

#img-lightbox-close {
    position: absolute;
    top: 20px; right: 24px;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    border-radius: 50%;
    width: 40px; height: 40px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
    z-index: 10;
}
#img-lightbox-close:hover { background: rgba(255,255,255,.25); }

/* Download button ใน lightbox */
#img-lightbox-download {
    position: absolute;
    top: 20px; right: 72px;
    background: rgba(255,255,255,.12);
    border: none;
    color: #fff;
    border-radius: 50%;
    width: 40px; height: 40px;
    font-size: 1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
    z-index: 10;
    text-decoration: none;
}
#img-lightbox-download:hover { background: rgba(255,255,255,.25); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .msg-bubble--image { max-width: 200px; }
    .chat-img-thumb    { max-width: 200px; }
    #img-preview-modal { width: 96vw; }
}
