/* ============ Chat widget (floating) ============ */
.wpic-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

.wpic-chat-bubble {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 12px 18px 12px 14px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.wpic-chat-bubble:hover { transform: translateY(-1px); box-shadow: 0 14px 34px rgba(37, 99, 235, 0.42); }
.wpic-chat-bubble-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    background: #ef4444; border: 2px solid #fff;
}
.wpic-chat-widget[data-open="true"] .wpic-chat-bubble { display: none; }

.wpic-chat-panel {
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 48px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.wpic-chat-head {
    display: flex; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: #fff; padding: 14px 16px;
}

.wpic-chat-tabs {
    display: flex; gap: 2px; background: #f8fafc; padding: 6px; border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.wpic-chat-tabs button {
    flex: 1; background: transparent; color: #475569; border: 0; padding: 8px 10px;
    border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font-family: inherit;
}
.wpic-chat-tabs button:hover { background: #f1f5f9; color: #0f172a; }
.wpic-chat-tabs button.is-active { background: #fff; color: #0f172a; box-shadow: 0 1px 2px rgba(15,23,42,.08); }
.wpic-chat-tabs button svg { opacity: .8; }
.wpic-chat-tab-badge {
    min-width: 18px; height: 18px; padding: 0 6px; border-radius: 999px;
    background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
    display: inline-flex; align-items: center; justify-content: center;
}

.wpic-chat-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }

.wpic-chat-tickets-list { display: flex; flex-direction: column; flex: 1; min-height: 0; background: #fff; }
.wpic-chat-tickets-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid #e2e8f0;
}
.wpic-chat-tickets-head h4 { margin: 0; font-size: 15px; color: #0f172a; }
.wpic-chat-tickets-head button {
    background: #2563eb; color: #fff; border: 0; border-radius: 6px; padding: 6px 10px;
    font-size: 15px; font-weight: 600; cursor: pointer;
}
.wpic-chat-tickets-head button:hover { background: #1d4ed8; }
.wpic-chat-tickets-body { flex: 1; overflow-y: auto; background: #fff; }
.wpic-chat-tickets-empty { padding: 20px 14px; color: #94a3b8; font-size: 15px; text-align: center; }
.wpic-chat-ticket-item {
    padding: 10px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.wpic-chat-ticket-item:hover { background: #f8fafc; }
.wpic-chat-ticket-item .subject { font-weight: 600; color: #0f172a; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.wpic-chat-ticket-item .subject small { color: #94a3b8; font-weight: 400; font-size: 15px; white-space: nowrap; }
.wpic-chat-ticket-item .preview { color: #64748b; font-size: 15px; margin-top: 2px; line-height: 1.35; }
.wpic-chat-ticket-item .meta { margin-top: 4px; display: flex; gap: 4px; font-size: 10px; }
.wpic-chat-ticket-item .status-pill {
    padding: 1px 7px; border-radius: 999px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
.wpic-chat-ticket-item .status-pill.is-pending_human { background: #fef3c7; color: #92400e; }
.wpic-chat-ticket-item .status-pill.is-assigned { background: #dbeafe; color: #1d4ed8; }
.wpic-chat-ticket-item .status-pill.is-closed { background: #e2e8f0; color: #475569; }
.wpic-chat-ticket-item .status-pill.is-ai { background: #f3e8ff; color: #6b21a8; }
.wpic-chat-ticket-item .unread-pill { background: #ef4444; color: #fff; padding: 1px 7px; border-radius: 999px; font-weight: 700; }

.wpic-chat-ticket-detail { display: flex; flex-direction: column; flex: 1; min-height: 0; background: #fff; }
.wpic-chat-ticket-detail-head {
    padding: 10px 14px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #fff;
}
.wpic-chat-ticket-detail-head button[data-wpic-ticket-back] {
    background: transparent; border: 0; color: #2563eb; cursor: pointer; font-size: 15px; padding: 0; font-weight: 600;
}
.wpic-chat-ticket-detail-head h4 { margin: 0; font-size: 15px; color: #0f172a; flex: 1; }
.wpic-chat-ticket-status {
    font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600;
    background: #e2e8f0; color: #475569; text-transform: uppercase; letter-spacing: .04em;
}
.wpic-chat-head strong { display: block; font-size: 15px; }
.wpic-chat-head .wpic-chat-status { display: block; font-size: 15px; opacity: 0.85; margin-top: 2px; }
.wpic-chat-close { background: transparent; border: 0; color: #fff; font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.wpic-chat-close:hover { background: rgba(255,255,255,0.15); }

.wpic-chat-body { flex: 1; overflow-y: auto; padding: 16px; background: #f8fafc; display: flex; flex-direction: column; }
.wpic-chat-thread { display: flex; flex-direction: column; gap: 8px; }

.wpic-chat-msg { display: flex; flex-direction: column; max-width: 85%; font-size: 15px; line-height: 1.45; }
.wpic-chat-msg .wpic-chat-msg-meta { font-size: 15px; color: #64748b; margin: 2px 4px; }
.wpic-chat-msg .wpic-chat-msg-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.wpic-chat-msg.is-user { align-self: flex-end; }
.wpic-chat-msg.is-user .wpic-chat-msg-bubble {
    background: #2563eb; color: #fff;
    border-bottom-right-radius: 4px;
}
.wpic-chat-msg.is-user .wpic-chat-msg-meta { text-align: right; }
.wpic-chat-msg.is-ai .wpic-chat-msg-bubble,
.wpic-chat-msg.is-agent .wpic-chat-msg-bubble {
    background: #ffffff; color: #0f172a;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-bottom-left-radius: 4px;
}
.wpic-chat-msg.is-agent .wpic-chat-msg-bubble { border-color: #bfdbfe; background: #eff6ff; }
.wpic-chat-msg.is-system {
    align-self: center; max-width: 95%;
    font-size: 15px; color: #64748b; text-align: center;
    background: transparent;
}
.wpic-chat-msg.is-system .wpic-chat-msg-bubble { background: transparent; padding: 4px 8px; font-style: italic; }

.wpic-chat-msg .wpic-chat-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}
.wpic-chat-msg.is-ai .wpic-chat-msg-bubble a,
.wpic-chat-msg.is-agent .wpic-chat-msg-bubble a { color: #2563eb; }
.wpic-chat-msg.is-user .wpic-chat-msg-bubble a { color: #fff; text-decoration-color: rgba(255,255,255,0.7); }
.wpic-chat-msg .wpic-chat-msg-bubble a:hover { text-decoration-thickness: 2px; }

.wpic-chat-typing { display: flex; gap: 4px; align-items: center; padding: 10px 14px; align-self: flex-start; margin-top: 6px; }
.wpic-chat-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #94a3b8;
    animation: wpic-chat-bounce 1.1s infinite ease-in-out;
}
.wpic-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.wpic-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes wpic-chat-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-5px); opacity: 1; } }

.wpic-chat-compose {
    display: flex; gap: 8px; padding: 10px 12px;
    border-top: 1px solid rgba(15, 23, 42, 0.08); background: #fff;
}
.wpic-chat-compose textarea {
    flex: 1;
    resize: none;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.4;
    min-height: 40px;
    max-height: 120px;
    outline: none;
    color: #0f172a;
    background: #fff;
}
.wpic-chat-compose textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }
.wpic-chat-send {
    background: #2563eb; color: #fff; border: 0; border-radius: 10px; padding: 0 14px;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s ease;
}
.wpic-chat-send:hover { background: #1d4ed8; }
.wpic-chat-send[disabled] { opacity: 0.5; cursor: wait; }

.wpic-chat-actions {
    display: flex; gap: 8px; padding: 0 12px 12px;
    font-size: 15px; background: #fff;
}
.wpic-chat-actions button {
    flex: 1;
    background: #f1f5f9;
    color: #0f172a;
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-weight: 500;
}
.wpic-chat-actions button:hover { background: #e2e8f0; }

.wpic-chat-ticket-form {
    position: absolute; inset: 0; top: 52px;
    background: #fff; padding: 16px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
}
.wpic-chat-ticket-form h4 { margin: 0 0 4px; font-size: 15px; color: #0f172a; }
.wpic-chat-ticket-form label { display: block; font-size: 15px; color: #334155; font-weight: 500; }
.wpic-chat-ticket-form input,
.wpic-chat-ticket-form select,
.wpic-chat-ticket-form textarea {
    width: 100%; margin-top: 4px; padding: 8px 10px;
    border: 1px solid rgba(15, 23, 42, 0.12); border-radius: 8px;
    font-family: inherit; font-size: 15px; color: #0f172a; background: #fff;
}
.wpic-chat-ticket-form textarea { resize: vertical; }
.wpic-chat-ticket-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.wpic-chat-ticket-actions button {
    border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600;
}
.wpic-chat-ticket-actions button[type="button"] { background: #f1f5f9; color: #0f172a; }
.wpic-chat-ticket-actions button[type="submit"] { background: #2563eb; color: #fff; }

.wpic-chat-rating { padding: 10px 14px; background: #fff; border-top: 1px solid rgba(15, 23, 42, 0.08); text-align: center; }
.wpic-chat-rating p { margin: 0 0 6px; font-size: 15px; color: #334155; }
.wpic-chat-stars button {
    background: transparent; border: 0; color: #cbd5e1; font-size: 22px; cursor: pointer; padding: 0 2px;
}
.wpic-chat-stars button:hover,
.wpic-chat-stars button.is-active { color: #f59e0b; }

.wpic-chat-panel { position: relative; }

/* Mobile */
@media (max-width: 600px) {
    .wpic-chat-widget { right: 12px; bottom: 12px; }
    .wpic-chat-panel { width: calc(100vw - 24px); height: calc(100vh - 24px); }
}

/* ============ Chat inbox (manager + admin) ============ */
.wpic-inbox-wrap {
    max-width: 1200px;
    margin: clamp(24px, 4vw, 48px) auto;
    padding: 0 16px;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 18px;
    min-height: 640px;
    color: #0f172a;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}
.wpic-inbox-list {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
    overflow: hidden; display: flex; flex-direction: column;
}
.wpic-inbox-filters {
    padding: 12px 14px; border-bottom: 1px solid #e2e8f0;
    display: flex; gap: 8px; flex-wrap: wrap; font-size: 15px;
}
.wpic-inbox-filters select,
.wpic-inbox-filters label {
    padding: 5px 8px; border-radius: 6px; border: 1px solid #cbd5e1; font-size: 15px; background: #fff;
}
.wpic-inbox-items { flex: 1; overflow-y: auto; }
.wpic-inbox-item {
    display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer;
}
.wpic-inbox-item:hover { background: #f8fafc; }
.wpic-inbox-item.is-active { background: #eff6ff; border-left: 3px solid #2563eb; padding-left: 11px; }
.wpic-inbox-item .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 15px; }
.wpic-inbox-item .who { font-weight: 600; color: #0f172a; }
.wpic-inbox-item .when { color: #94a3b8; font-size: 15px; white-space: nowrap; }
.wpic-inbox-item .preview { color: #64748b; font-size: 15px; line-height: 1.4; }
.wpic-inbox-item .badges { display: flex; gap: 4px; margin-top: 2px; font-size: 11px; }
.wpic-inbox-item .badge {
    padding: 1px 6px; border-radius: 999px; font-weight: 600;
    background: #e2e8f0; color: #334155;
}
.wpic-inbox-item .badge.is-unread { background: #ef4444; color: #fff; }
.wpic-inbox-item .badge.is-ticket { background: #fef3c7; color: #92400e; }
.wpic-inbox-item .badge.is-pending { background: #fde68a; color: #78350f; }
.wpic-inbox-item .badge.is-assigned { background: #dbeafe; color: #1d4ed8; }
.wpic-inbox-item .badge.is-closed { background: #e2e8f0; color: #475569; }
.wpic-inbox-item .badge.is-high { background: #fecaca; color: #991b1b; }

.wpic-inbox-detail {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 14px;
    display: flex; flex-direction: column; min-height: 640px;
}
.wpic-inbox-detail-empty { display: flex; align-items: center; justify-content: center; color: #94a3b8; height: 100%; font-size: 15px; }
.wpic-inbox-detail-head {
    padding: 14px 18px; border-bottom: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    flex-wrap: wrap;
}
.wpic-inbox-detail-head h3 { margin: 0; font-size: 16px; }
.wpic-inbox-detail-head .who-meta { font-size: 15px; color: #64748b; }
.wpic-inbox-detail-actions { display: flex; gap: 6px; }
.wpic-inbox-detail-actions button {
    background: #f1f5f9; color: #0f172a; border: 0; border-radius: 6px;
    padding: 6px 10px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.wpic-inbox-detail-actions button:hover { background: #e2e8f0; }
.wpic-inbox-detail-actions button.is-danger { background: #fee2e2; color: #991b1b; }

.wpic-inbox-thread { flex: 1; overflow-y: auto; padding: 18px; background: #f8fafc; display: flex; flex-direction: column; gap: 8px; }
.wpic-inbox-compose {
    display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid #e2e8f0; background: #fff;
}
.wpic-inbox-compose textarea {
    flex: 1; resize: vertical; min-height: 48px; max-height: 200px;
    padding: 10px 12px; font-size: 15px; border: 1px solid #cbd5e1; border-radius: 8px; font-family: inherit;
}
.wpic-inbox-compose button {
    background: #2563eb; color: #fff; border: 0; border-radius: 8px; padding: 0 18px; font-weight: 600; cursor: pointer;
}
.wpic-inbox-compose button:hover { background: #1d4ed8; }

@media (max-width: 900px) {
    .wpic-inbox-wrap { grid-template-columns: 1fr; }
}

/* Dashboard "Support Tickets" section */
.wpic-dash-tickets-toolbar { display: flex; gap: 8px; }
.wpic-dash-new-ticket label { display: block; margin-bottom: 12px; font-size: 15px; font-weight: 500; color: #334155; }
.wpic-dash-new-ticket input,
.wpic-dash-new-ticket select,
.wpic-dash-new-ticket textarea {
    width: 100%; margin-top: 6px; padding: 10px 12px;
    border: 1px solid #cbd5e1; border-radius: 8px; font-family: inherit; font-size: 15px;
    background: #fff; color: #0f172a;
}
.wpic-dash-ticket-list { display: flex; flex-direction: column; gap: 10px; }
.wpic-dash-ticket {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; overflow: hidden;
}
.wpic-dash-ticket-head {
    padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
    cursor: pointer;
}
.wpic-dash-ticket-head:hover { background: #f8fafc; }
.wpic-dash-ticket-head strong { display: block; color: #0f172a; font-size: 15px; }
.wpic-dash-ticket-status {
    font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600;
    background: #e2e8f0; color: #475569; text-transform: uppercase; letter-spacing: .04em;
    white-space: nowrap;
}
.wpic-dash-ticket-status.is-pending_human { background: #fef3c7; color: #92400e; }
.wpic-dash-ticket-status.is-assigned { background: #dbeafe; color: #1d4ed8; }
.wpic-dash-ticket-status.is-closed { background: #e2e8f0; color: #475569; }
.wpic-dash-ticket-status.is-ai { background: #f3e8ff; color: #6b21a8; }
.wpic-dash-ticket-body { padding: 14px 16px; border-top: 1px solid #e2e8f0; background: #f8fafc; }
.wpic-dash-ticket-thread {
    display: flex; flex-direction: column; gap: 8px;
    max-height: 360px; overflow-y: auto; padding: 4px; margin-bottom: 10px;
}
.wpic-dash-ticket-reply { display: flex; flex-direction: column; gap: 8px; }
.wpic-dash-ticket-reply textarea {
    width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
    resize: vertical; font-family: inherit; font-size: 15px;
}

/* Admin list view helpers */
.wpic-admin-chat-table { width: 100%; border-collapse: collapse; background: #fff; }
.wpic-admin-chat-table th, .wpic-admin-chat-table td { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; text-align: left; font-size: 15px; }
.wpic-admin-chat-table th { background: #f8fafc; color: #475569; font-weight: 600; }
.wpic-admin-chat-table tr { cursor: pointer; }
.wpic-admin-chat-table tr:hover { background: #f8fafc; }
