/* 私密聊天室樣式表 */
/* 現代化、響應式設計，支援行動裝置 */

:root {
    --primary-color: #FFB6C1;
    --primary-dark: #FFA0B4;
    --secondary-color: #D4A59A;
    --accent-color: #F4C2C2;
    --text-primary: #6B4C4C;
    --text-secondary: #A08080;
    --bg-light: #FFF5F7;
    --bg-lighter: #FFF9FA;
    --bg-white: #FFFFFF;
    --border-color: #F5D5D5;
    --shadow-sm: 0 2px 6px rgba(212, 165, 154, 0.15);
    --shadow-md: 0 3px 12px rgba(212, 165, 154, 0.2);
    --shadow-lg: 0 6px 24px rgba(212, 165, 154, 0.25);
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'PingFang TC', 'Microsoft JhengHei', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    letter-spacing: 0.3px;
}

/* ========== 登入頁面 ========== */
.login-page {
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-box {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 50px 40px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.5s ease-out;
    border: 1px solid var(--border-color);
}

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

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.heart-icon {
    font-size: 60px;
    margin-bottom: 15px;
    animation: heartBeat 1.5s ease-in-out infinite;
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    10%, 30% { transform: scale(1.1); }
    20%, 40% { transform: scale(1); }
}

.login-header h1 {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: 1px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form .input-group {
    margin-bottom: 20px;
}

.login-form input[type="password"] {
    width: 100%;
    padding: 15px 18px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 16px;
    transition: var(--transition);
    outline: none;
    background: var(--bg-lighter);
}

.login-form input[type="password"]:focus {
    border-color: var(--primary-color);
    background: var(--bg-white);
    box-shadow: 0 0 0 4px rgba(255, 182, 193, 0.15);
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    letter-spacing: 0.5px;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

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

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-msg {
    margin-top: 15px;
    padding: 12px 16px;
    background: #FFF0F0;
    color: #D88888;
    border: 1px solid #FFD5D5;
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-align: center;
}

/* ========== 聊天頁面 ========== */
.chat-page {
    background: var(--bg-lighter);
}

.chat-container {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-white);
    box-shadow: var(--shadow-md);
}

/* 標題列 */
.chat-header {
    background: var(--primary-color);
    color: white;
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    border-bottom: 1px solid var(--primary-dark);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.partner-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.online-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #95a5a6;
    border: 2px solid white;
    transition: var(--transition);
}

.online-indicator.online {
    background: #A8E6CF;
    box-shadow: 0 0 8px rgba(168, 230, 207, 0.6);
}

.partner-name {
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.btn-logout,
.btn-search,
.btn-settings,
.btn-notification-toggle {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.btn-logout:hover,
.btn-search:hover,
.btn-settings:hover,
.btn-notification-toggle:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* 推播通知按鈕狀態 */
.btn-notification-toggle.enabled {
    background: rgba(46, 204, 113, 0.5);
}

.btn-notification-toggle.disabled {
    background: rgba(231, 76, 60, 0.5);
}

.btn-notification-toggle.disabled svg {
    opacity: 0.6;
}

/* 訊息區域 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: var(--bg-lighter);
    -webkit-overflow-scrolling: touch;
}

.messages-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.loading-messages {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 66.67%;
    animation: messageSlide 0.3s ease-out;
}

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

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
    background-size: cover;
    background-position: center;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 有頭像的可以點擊放大 */
.message-avatar.has-avatar {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-avatar.has-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.message-content {
    flex: 0 1 auto;
    min-width: 0;
}

.message-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.message.own .message-info {
    flex-direction: row-reverse;
}

.message-name {
    font-size: 13px;
    font-weight: 600;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.read-status {
    font-size: 12px;
    font-weight: bold;
    margin-left: 4px;
}

.read-status.read {
    color: var(--primary-color);
}

.read-status.unread {
    color: var(--text-secondary);
    opacity: 0.6;
}

/* 訊息氣泡可滑動 */
.message-bubble {
    transition: transform 0.3s ease;
    position: relative;
}

/* 圖片訊息的氣泡框不需要 padding */
.message-bubble:has(.message-image) {
    padding: 0;
    overflow: hidden;
    background: var(--bg-lighter) !important;
    border: none !important;
    box-shadow: none !important;
}

/* 訊息選單 */
.message-menu {
    position: absolute;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 8px;
    z-index: 1000;
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 手機版選單 */
.message-menu.mobile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
    max-width: 160px;
}

.message-menu.mobile.show {
    opacity: 1;
    transform: translateY(-50%) translateX(0) !important; /* 滑入後：垂直置中，水平歸位（左右皆適用） */
}

.message-menu.mobile .menu-item {
    padding: 10px 14px;
    font-size: 14px;
}

/* 桌面版選單縮放淡入 */
.message-menu:not(.mobile).show {
    opacity: 1;
    transform: scale(1);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 15px;
    cursor: pointer;
    width: 100%;
    text-align: left;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease;
    white-space: nowrap;
}

.menu-item:hover {
    background: var(--bg-light);
}

.menu-item:active {
    background: var(--bg-lighter);
}

.menu-item svg {
    flex-shrink: 0;
}

.menu-item-danger {
    color: #e74c3c;
}

.menu-item-danger:hover {
    background: rgba(231, 76, 60, 0.1);
}

/* Toast 提示訊息 */
.toast-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.toast-message.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
    border: 1px solid transparent;
}

/* 圖片訊息的氣泡框不需要 padding */
.message-bubble:has(.message-image) {
    padding: 0;
    overflow: hidden;
    background: var(--bg-lighter) !important;
    border: none !important;
    box-shadow: none !important;
}

.message:not(.own) .message-bubble {
    background: white;
    border-bottom-left-radius: 6px;
    border-color: var(--border-color);
}

.message.own .message-bubble {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 6px;
}

.message-text {
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
    letter-spacing: 0.3px;
}

.message-image {
    max-width: 100%;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.message-image:hover {
    opacity: 0.95;
}

/* 輸入區域 */
.input-container {
    flex-shrink: 0;
    padding: 15px;
    background: white;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.message-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.btn-image {
    background: white;
    border: 2px solid var(--border-color);
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--primary-color);
    flex-shrink: 0;
}

.btn-image:hover {
    background: var(--bg-lighter);
    border-color: var(--primary-color);
}

#messageInput {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--transition);
    background: white;
    letter-spacing: 0.3px;
}

#messageInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 182, 193, 0.15);
}

.btn-send {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

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

/* ========== 圖片預覽介面 ========== */
.image-preview-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.preview-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.preview-card {
    position: relative;
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

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

/* 關閉按鈕 */
.preview-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    color: var(--text-primary);
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
    z-index: 10;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.preview-close-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: rotate(90deg) scale(1.1);
}

/* 圖片顯示區 */
.preview-image-area {
    width: 100%;
    min-height: 300px;
    max-height: 60vh;
    background: var(--bg-lighter);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.preview-image-area img {
    max-width: 100%;
    max-height: 55vh;
    width: auto;
    height: auto;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

/* 底部區域 */
.preview-footer {
    padding: 20px;
    background: white;
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-lighter);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
}

.info-icon {
    font-size: 18px;
}

.info-text {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
}

.preview-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.preview-btn {
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    letter-spacing: 0.5px;
}

.preview-btn-cancel {
    background: white;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.preview-btn-cancel:hover {
    background: var(--bg-lighter);
    border-color: var(--primary-color);
    color: var(--text-primary);
}

.preview-btn-send {
    background: var(--primary-color);
    color: white;
}

.preview-btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.preview-btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 圖片查看器 */
.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.viewer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
}

.viewer-content {
    position: relative;
    z-index: 1;
    padding: 20px;
    max-width: 90vw;
    max-height: 90vh;
}

.viewer-content img {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-md);
    cursor: grab;
    touch-action: none;
    user-select: none;
    transition: transform 0.1s ease-out;
}

.viewer-content img:active {
    cursor: grabbing;
}

/* 查看器關閉按鈕 */
.btn-viewer-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(255, 182, 193, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2001;
}

.btn-viewer-close:hover {
    background: var(--primary-dark);
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 6px 20px rgba(255, 182, 193, 0.6);
}

/* 設定面板 */
.settings-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.settings-content {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

.settings-header {
    padding: 24px;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--primary-dark);
}

.settings-header h2 {
    font-size: 20px;
    margin: 0;
    font-weight: 500;
    letter-spacing: 1px;
}

.btn-settings-close {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-settings-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.settings-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.setting-section {
    margin-bottom: 30px;
}

.setting-section:last-child {
    margin-bottom: 0;
}

.setting-section h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 15px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* 頭像上傳 */
.avatar-upload-container {
    display: flex;
    gap: 20px;
    align-items: center;
}

.current-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 500;
    color: white;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    box-shadow: var(--shadow-sm);
    border: 3px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.current-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 有頭像時可以點擊放大 */
.current-avatar[style*="cursor: pointer"]:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.avatar-upload-controls {
    flex: 1;
}

.btn-upload-avatar {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    letter-spacing: 0.5px;
}

.btn-upload-avatar:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.hint-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* 資訊項目 */
.info-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-item:last-child {
    border-bottom: none;
}

.info-item label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.info-value {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

/* 管理功能按鈕 */
.btn-manage {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--secondary-color) 0%, #C99A8A 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(212, 165, 154, 0.3);
    text-decoration: none;
    margin-bottom: 10px;
}

.btn-manage:hover {
    background: linear-gradient(135deg, #C99A8A 0%, #B88A7A 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 165, 154, 0.4);
}

.btn-manage:active {
    transform: translateY(0);
}

/* 顯示名稱編輯 */
.display-name-edit-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.display-name-input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    font-size: 15px;
    transition: var(--transition);
    background: white;
}

.display-name-input:focus {
    outline: none;
    border-color: var(--primary-dark);
    box-shadow: 0 0 0 3px rgba(255, 182, 193, 0.2);
}

.btn-save-name {
    padding: 10px 18px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-save-name:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 182, 193, 0.4);
}

.btn-save-name:active {
    transform: translateY(0);
}

.btn-save-name:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 搜尋面板 */
.search-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

.search-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.search-content {
    position: relative;
    background: white;
    border-radius: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
}

.search-header {
    padding: 20px 24px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-radius: 24px 24px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-header h2 {
    color: white;
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.btn-search-close {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-search-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.search-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.search-input-container {
    position: relative;
    margin-bottom: 16px;
}

.search-input {
    width: 100%;
    padding: 14px 40px 14px 16px;
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    font-size: 16px;
    transition: var(--transition);
    background: var(--bg-lighter);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-dark);
    background: white;
}

.btn-clear-search {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--text-secondary);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-clear-search:hover {
    background: var(--text-primary);
}

.search-stats {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-lighter);
    border-radius: 8px;
}

.search-stats #searchCount {
    color: var(--primary-color);
    font-weight: bold;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.search-result-item {
    background: var(--bg-lighter);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid var(--primary-color);
}

.search-result-item:hover {
    background: var(--bg-chat-light);
    transform: translateX(4px);
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.search-result-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.search-result-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.search-result-content {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
}

.search-result-content .highlight {
    background: var(--primary-color);
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 600;
}

.search-result-image {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.search-result-image svg {
    width: 16px;
    height: 16px;
}

/* ========== 響應式設計 ========== */
@media (max-width: 768px) {
    .chat-container {
        box-shadow: none;
    }
    
    .message {
        max-width: 66.67%;
    }
    
    .login-box {
        padding: 30px 20px;
    }
    
    .login-header h1 {
        font-size: 24px;
    }
    
    .heart-icon {
        font-size: 50px;
    }
}

@media (max-width: 480px) {
    .messages-container {
        padding: 15px 10px;
    }
    
    .message {
        max-width: 66.67%;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
    
    .message-bubble {
        padding: 10px 14px;
    }
    
    .input-container {
        padding: 10px;
    }
    
    /* 圖片預覽響應式 */
    .image-preview-container {
        padding: 10px;
    }
    
    .preview-card {
        max-width: 100%;
    }
    
    .preview-image-area {
        min-height: 250px;
        max-height: 50vh;
        padding: 15px;
    }
    
    .preview-image-area img {
        max-height: 45vh;
    }
    
    .preview-footer {
        padding: 16px;
    }
    
    .preview-actions {
        grid-template-columns: 1fr;
    }
    
    .preview-btn {
        padding: 12px 16px;
    }
}

/* ========== 自訂捲軸 ========== */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========== iOS 安全區域 ========== */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .input-container {
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
}

/* ==================== PWA 安裝提示樣式 ==================== */
#pwa-install-prompt {
    position: fixed;
    bottom: -200px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    padding: 20px;
    width: 100%;
    max-width: 500px;
    z-index: 10000;
    transition: bottom 0.3s ease-out;
}

#pwa-install-prompt.show {
    bottom: 0;
}

.pwa-prompt-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.pwa-prompt-icon {
    font-size: 48px;
    text-align: center;
}

.pwa-prompt-text {
    text-align: center;
}

.pwa-prompt-text h3 {
    margin: 0 0 8px;
    font-size: 20px;
    color: #5a4545;
    font-weight: 600;
}

.pwa-prompt-text p {
    margin: 0;
    font-size: 14px;
    color: #8a7575;
    line-height: 1.4;
}

.pwa-prompt-actions {
    display: flex;
    gap: 10px;
}

.pwa-btn-install,
.pwa-btn-dismiss {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pwa-btn-install {
    background: #d4a5a5;
    color: white;
}

.pwa-btn-install:hover {
    background: #c89595;
    transform: translateY(-1px);
}

.pwa-btn-install:active {
    transform: translateY(0);
}

.pwa-btn-dismiss {
    background: #f5e8e4;
    color: #8a7575;
}

.pwa-btn-dismiss:hover {
    background: #ede0dc;
}

.pwa-success-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #4caf50;
    color: white;
    padding: 12px 24px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    font-size: 16px;
    font-weight: 500;
    z-index: 10001;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* iOS 通知啟用提示 */
#ios-notification-prompt {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 30px;
    width: 90%;
    max-width: 400px;
    z-index: 10002;
    opacity: 0;
    transition: all 0.3s ease-out;
}

#ios-notification-prompt.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

#ios-notification-prompt::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: -1;
}

.ios-notification-content {
    text-align: center;
}

.ios-notification-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.ios-notification-content h3 {
    margin: 0 0 12px;
    font-size: 24px;
    color: #5a4545;
    font-weight: 600;
}

.ios-notification-content p {
    margin: 0 0 24px;
    font-size: 16px;
    color: #8a7575;
    line-height: 1.5;
}

.ios-enable-btn,
.ios-dismiss-btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    margin-bottom: 10px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ios-enable-btn {
    background: #d4a5a5;
    color: white;
}

.ios-enable-btn:hover {
    background: #c89595;
    transform: translateY(-2px);
}

.ios-enable-btn:active {
    transform: translateY(0);
}

.ios-dismiss-btn {
    background: transparent;
    color: #8a7575;
}

.ios-dismiss-btn:hover {
    background: #f5e8e4;
}

/* 通知測試樣式 */
.notification-test-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.test-status {
    background: #f5e8e4;
    padding: 12px;
    border-radius: 10px;
    font-size: 14px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.status-label {
    color: #8a7575;
    font-weight: 500;
}

.status-value {
    font-weight: 600;
    color: #5a4545;
}

.status-value.success {
    color: #4caf50;
}

.status-value.error {
    color: #f44336;
}

.status-value.warning {
    color: #ff9800;
}

.test-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-test {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: #d4a5a5;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-test:hover {
    background: #c89595;
    transform: translateY(-1px);
}

.btn-test:active {
    transform: translateY(0);
}

.btn-test svg {
    flex-shrink: 0;
}

/* 調試日誌面板 */
.debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: calc(100% - 40px);
    max-width: 400px;
    max-height: 400px;
    background: rgba(0, 0, 0, 0.95);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 10003;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

.debug-panel.minimized .debug-body {
    display: none;
}

.debug-panel.minimized {
    max-height: 50px;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px 12px 0 0;
}

.debug-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.debug-controls {
    display: flex;
    gap: 8px;
}

.btn-debug-clear,
.btn-debug-toggle,
.btn-debug-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-debug-clear:hover,
.btn-debug-toggle:hover,
.btn-debug-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.debug-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.4;
    color: #fff;
}

.debug-log-entry {
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    word-break: break-word;
    background: rgba(255, 255, 255, 0.03);
}

.debug-log-entry.info {
    color: #4fc3f7;
}

.debug-log-entry.success {
    color: #81c784;
}

.debug-log-entry.warning {
    color: #ffb74d;
}

.debug-log-entry.error {
    color: #e57373;
}

.debug-log-entry .timestamp {
    color: #888;
    margin-right: 8px;
}

.debug-log-empty {
    text-align: center;
    color: #888;
    padding: 20px;
    font-size: 12px;
}

.btn-debug-open {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10002;
    transition: all 0.2s;
}

.btn-debug-open:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}

/* PWA 模式下的樣式調整 */
@media (display-mode: standalone) {
    /* 在 PWA 模式下隱藏瀏覽器特定的元素 */
    body {
        user-select: none; /* 防止長按選擇文字 */
    }
    
    input, textarea {
        user-select: text; /* 允許在輸入框選擇文字 */
    }
}
