/**
 * PHP 聊天室樣式 - LINE 風格
 */

:root {
    /* LINE 經典綠色 */
    --line-green: #06C755;
    --line-green-dark: #05a647;
    --line-green-light: #07d95e;
    
    /* 背景色 */
    --bg-chat: #7AACB4;
    --bg-white: #ffffff;
    --bg-gray: #f7f7f7;
    --bg-input: #ffffff;
    
    /* 訊息氣泡 */
    --bubble-sent: #06C755;
    --bubble-received: #ffffff;
    
    /* 文字色 */
    --text-primary: #111111;
    --text-secondary: #666666;
    --text-muted: #999999;
    --text-white: #ffffff;
    --text-time: #8a8a8a;
    
    /* 邊框 */
    --border-color: #e5e5e5;
    --border-light: #f0f0f0;
    
    /* 陰影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
    
    /* 圓角 */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-bubble: 18px;
    --radius-full: 9999px;
    
    /* 動畫 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

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

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
    background: var(--bg-gray);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    /* 防止 iOS 彈性滾動 */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.hidden {
    display: none !important;
}

/* ==================== 登入/註冊頁面 - LINE 風格 ==================== */
#auth-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(180deg, #06C755 0%, #05a647 100%);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.auth-box {
    width: 100%;
    max-width: 380px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: var(--line-green);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(6, 199, 85, 0.3);
}

.auth-logo svg {
    width: 48px;
    height: 48px;
    color: white;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-radius: var(--radius-full);
    background: var(--bg-gray);
    padding: 4px;
}

.auth-tab {
    flex: 1;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    background: var(--bg-white);
    color: var(--line-green);
    box-shadow: var(--shadow-sm);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding-left: 4px;
}

.form-group input {
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--line-green);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--line-green);
    color: white;
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--line-green-dark);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border-radius: var(--radius-full);
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
}

.btn-icon svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

#notification-btn {
    position: relative;
}

#notification-btn:not(:disabled):hover {
    background: rgba(6, 199, 85, 0.1);
}

#notification-btn::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #ff3b30;
    border-radius: 50%;
    display: none;
}

#notification-btn.needs-setup::after {
    display: block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.auth-error {
    color: #ff3b30;
    font-size: 0.85rem;
    text-align: center;
    min-height: 20px;
}

.auth-demo-hint {
    margin-top: 24px;
    padding: 16px;
    background: rgba(6, 199, 85, 0.08);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(6, 199, 85, 0.2);
}

.auth-demo-hint p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ==================== 聊天介面 - LINE 風格 ==================== */
#chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: var(--bg-white);
}

.chat-wrapper {
    width: 100%;
    max-width: 500px;
    height: 100%;
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 768px) {
    .chat-wrapper {
        height: calc(100vh - 40px);
        max-height: 800px;
        border-radius: var(--radius-lg);
        margin: 20px;
    }
}

/* 聊天標題列 - LINE 風格 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    min-height: 60px;
    flex-shrink: 0;
}

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

.partner-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #a8e063 0%, #56ab2f 100%);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    color: white;
}

.online-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #c7c7c7;
    border: 2px solid var(--bg-white);
    border-radius: var(--radius-full);
}

.online-indicator.online {
    background: var(--line-green);
}

.partner-details h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1px;
}

.partner-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.partner-status.online {
    color: var(--line-green);
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.current-user {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 6px 12px;
    background: var(--bg-gray);
    border-radius: var(--radius-full);
    font-weight: 500;
}

/* 訊息區域 - LINE 風格聊天背景 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: 
        linear-gradient(135deg, #8fbbc4 0%, #7aacb4 50%, #6a9ca4 100%);
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.messages-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

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

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

/* 訊息氣泡 - LINE 風格 */
.message {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 6px;
    max-width: 80%;
    animation: messageIn 0.2s ease;
}

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

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

.message.received {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-bubble);
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message.sent .message-bubble {
    background: var(--bubble-sent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
    background: var(--bubble-received);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.45;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: block;
}

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

.message-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 45px;
    padding-bottom: 2px;
}

.message.received .message-meta {
    align-items: flex-start;
}

.message-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.read-status {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.read-status.read {
    color: #ffeb3b;
}

.sender-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 4px;
    margin-left: 4px;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

/* 日期分隔線 */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0;
}

.date-separator span {
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    color: white;
}

/* 輸入區域 - LINE 風格 */
.chat-input-area {
    padding: 8px 12px 12px;
    background: var(--bg-white);
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-gray);
    border-radius: var(--radius-lg);
    padding: 6px 8px;
}

.image-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.image-upload-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.image-upload-btn svg {
    width: 24px;
    height: 24px;
    color: var(--line-green);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    padding: 8px 4px;
}

#message-input:focus {
    outline: none;
}

#message-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--line-green);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:disabled {
    background: #c7c7c7;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--line-green-dark);
}

.send-btn:not(:disabled):active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
    margin-left: 2px;
}

/* 圖片預覽 */
.image-preview-container {
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-gray);
    border-radius: var(--radius-sm);
}

.image-preview {
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 150px;
    max-height: 100px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--line-green);
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    background: #ff3b30;
    color: white;
    border: 2px solid white;
    border-radius: var(--radius-full);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

/* 圖片檢視器 */
.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.image-viewer-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.image-viewer-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.close-viewer-btn {
    position: absolute;
    top: -48px;
    right: 0;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.close-viewer-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 通知提示 - LINE 風格 */
.notification-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background: var(--text-primary);
    color: white;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    z-index: 999;
    animation: toastIn 0.3s ease;
    max-width: 300px;
    text-align: center;
}

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

.notification-toast .toast-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.notification-toast .toast-title {
    font-weight: 600;
    font-size: 0.9rem;
}

.notification-toast .toast-body {
    font-size: 0.85rem;
    margin-top: 4px;
    opacity: 0.9;
}

/* 響應式設計 */
@media (max-width: 500px) {
    .chat-wrapper {
        border-radius: 0;
        max-width: 100%;
    }
    
    .message {
        max-width: 85%;
    }
    
    .current-user {
        display: none;
    }
    
    .auth-box {
        padding: 32px 24px;
        border-radius: var(--radius-md);
    }
}

/* 打字指示器 - LINE 風格 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 10px 14px;
    background: var(--bubble-received);
    border-radius: var(--radius-bubble);
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: #b0b0b0;
    border-radius: 50%;
    animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-3px);
    }
}

/* LINE 風格已讀標記文字 */
.read-status svg {
    display: none;
}

.read-status::before {
    content: '';
}

.read-status.read::before {
    content: '已讀';
}

