/**
 * 即時通訊浮動元件樣式
 */

/* ============================================================
   觸發按鈕（內嵌於 .subscription-trigger，與訂閱按鈕並列）
   ============================================================ */
#mchatWidget {
    display: inline-block;
    font-family: inherit;
}

/* 觸發按鈕：與 .subscription-btn 視覺一致（outlined pill） */
.mchat-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: transparent;
    border: 2px solid var(--theme-accent, #e94560);
    border-radius: 30px;
    color: var(--theme-text, #fff);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    font-family: inherit;
}

.mchat-trigger:hover {
    background: var(--theme-accent, #e94560);
    color: #fff;
}

.mchat-trigger:active {
    transform: scale(0.98);
}

.mchat-trigger-icon {
    font-size: 1.25rem !important;
}

.mchat-trigger-label {
    white-space: nowrap;
}

.mchat-trigger-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ff3030;
    color: #fff;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--theme-bg, #fff);
    line-height: 1;
}

/* 讓 .subscription-trigger 容器內兩顆按鈕並列且置中 */
.subscription-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

@media (max-width: 480px) {
    .subscription-trigger {
        gap: 8px;
    }
    .mchat-trigger {
        padding: 10px 18px;
        font-size: 0.9375rem;
    }
}

/* ============================================================
   對話面板
   ============================================================ */
.mchat-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 380px;
    max-width: 100vw;
    height: 600px;
    max-height: 100vh;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    animation: mchatSlideUp 0.25s ease-out;
    color: #2c3e50;
}

/* 降低「進入編輯」浮動按鈕 z-index，確保聊天視窗永遠在其上方 */
.owner-actions {
    z-index: 1 !important;
}

@media (min-width: 768px) {
    .mchat-panel {
        bottom: 1rem;
        right: 1rem;
        border-radius: 16px;
        height: 600px;
        max-height: calc(100vh - 2rem);
    }
}

@media (max-width: 767px) {
    .mchat-panel {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
    }
}

@keyframes mchatSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.mchat-panel-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ============================================================
   標頭
   ============================================================ */
.mchat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: #fff;
    flex-shrink: 0;
}

.mchat-header-info {
    flex: 1;
    min-width: 0;
}

.mchat-header-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.125rem 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
}

.mchat-header-subtitle {
    font-size: 0.75rem;
    opacity: 0.9;
}

.mchat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.mchat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.mchat-close .material-icons {
    font-size: 1.25rem;
}

/* ============================================================
   鎖定提示
   ============================================================ */
.mchat-locked-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fff8e1;
    color: #ad6800;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.mchat-locked-banner .material-icons {
    font-size: 1.125rem;
    flex-shrink: 0;
}

/* ============================================================
   初始化表單
   ============================================================ */
.mchat-form-view {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.mchat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem 0 1.5rem;
    color: #5d6d7e;
}

.mchat-welcome .material-icons {
    color: #fc4a1a;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.mchat-welcome p {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.mchat-init-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mchat-field {
    display: flex;
    flex-direction: column;
}

.mchat-field label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #34495e;
    margin-bottom: 0.375rem;
}

.mchat-field label .required {
    color: #e74c3c;
}

.mchat-field label .mchat-optional {
    font-weight: 400;
    color: #95a5a6;
    font-size: 0.75rem;
}

.mchat-field input {
    padding: 0.625rem 0.875rem;
    border: 1.5px solid #e0e6ed;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-family: inherit;
    color: #2c3e50;
    background: #fff;
    transition: border-color 0.2s;
}

.mchat-field input:focus {
    outline: none;
    border-color: #fc4a1a;
}

.mchat-field-hint {
    font-size: 0.75rem;
    color: #95a5a6;
    margin-top: 0.375rem;
}

.mchat-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    margin-top: 0.5rem;
}

.mchat-btn-primary:hover {
    box-shadow: 0 4px 12px rgba(252, 74, 26, 0.3);
}

.mchat-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.mchat-error {
    padding: 0.625rem 0.875rem;
    background: #fdecea;
    color: #c0392b;
    border-radius: 6px;
    font-size: 0.8125rem;
}

/* Honeypot 完全隱藏 */
.mchat-hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
}

/* ============================================================
   對話視窗
   ============================================================ */
.mchat-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.mchat-msg {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.mchat-msg.mchat-msg-visitor {
    align-self: flex-end;
    align-items: flex-end;
}

.mchat-msg.mchat-msg-family {
    align-self: flex-start;
    align-items: flex-start;
}

.mchat-msg-bubble {
    padding: 0.625rem 0.875rem;
    border-radius: 14px;
    font-size: 0.9375rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.mchat-msg-visitor .mchat-msg-bubble {
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.mchat-msg-family .mchat-msg-bubble {
    background: #fff;
    color: #2c3e50;
    border: 1px solid #e0e6ed;
    border-bottom-left-radius: 4px;
}

.mchat-msg-image {
    max-width: 240px;
    max-height: 240px;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid #e0e6ed;
}

.mchat-msg-meta {
    font-size: 0.6875rem;
    color: #95a5a6;
    margin-top: 0.25rem;
    padding: 0 0.25rem;
}

.mchat-empty {
    text-align: center;
    color: #95a5a6;
    font-size: 0.875rem;
    padding: 2rem 1rem;
}

/* ============================================================
   輸入區
   ============================================================ */
.mchat-send-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    padding-bottom: max(0.625rem, calc(env(safe-area-inset-bottom) - 0.5rem));
    background: #fff;
    border-top: 1px solid #e0e6ed;
    flex-shrink: 0;
}

.mchat-send-form textarea {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1.5px solid #e0e6ed;
    border-radius: 18px;
    font-size: 0.9375rem;
    font-family: inherit;
    color: #2c3e50;
    background: #f8f9fa;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

.mchat-send-form textarea:focus {
    outline: none;
    border-color: #fc4a1a;
    background: #fff;
}

.mchat-icon-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    color: #5d6d7e;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.mchat-icon-btn:hover {
    background: #f1f3f5;
}

.mchat-icon-btn .material-icons {
    font-size: 1.25rem;
}

.mchat-send-btn {
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    color: #fff;
}

.mchat-send-btn:hover {
    background: linear-gradient(135deg, #f7b733 0%, #fc4a1a 100%);
    transform: scale(1.05);
}

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

.mchat-upload-progress {
    padding: 0.5rem 1rem;
    background: #f8f9fa;
    color: #5d6d7e;
    font-size: 0.8125rem;
    text-align: center;
    border-top: 1px solid #e0e6ed;
}

