/**
 * PHP 聊天室樣式
 * 靈感來自現代通訊軟體的簡潔設計
 */

:root {
    /* 主色調 - 深邃的靛藍色系 */
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #6366f1;
    
    /* 背景色 */
    --bg-dark: #0f172a;
    --bg-medium: #1e293b;
    --bg-light: #334155;
    --bg-card: #1e293b;
    
    /* 文字色 */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* 訊息氣泡 */
    --bubble-sent: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --bubble-received: #334155;
    
    /* 狀態色 */
    --online: #22c55e;
    --offline: #64748b;
    --unread: #ef4444;
    
    /* 陰影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    
    /* 圓角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    /* 動畫 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* ==================== 登入/註冊頁面 ==================== */
#auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: 
        radial-gradient(ellipse at top left, rgba(79, 70, 229, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(124, 58, 237, 0.1) 0%, transparent 50%),
        var(--bg-dark);
}

.auth-box {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: var(--bubble-sent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-logo svg {
    width: 36px;
    height: 36px;
    color: white;
}

.auth-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.auth-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    background: var(--primary);
    color: white;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    padding: 14px 16px;
    border: 1px solid var(--bg-light);
    border-radius: var(--radius-sm);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn {
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--bubble-sent);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
}

.btn-icon:hover {
    background: var(--bg-medium);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.auth-error {
    color: var(--unread);
    font-size: 0.9rem;
    text-align: center;
    min-height: 24px;
}

.auth-demo-hint {
    margin-top: 24px;
    padding: 16px;
    background: rgba(79, 70, 229, 0.1);
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(79, 70, 229, 0.3);
}

.auth-demo-hint p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ==================== 聊天介面 ==================== */
#chat-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: 
        radial-gradient(ellipse at top, rgba(79, 70, 229, 0.08) 0%, transparent 60%),
        var(--bg-dark);
}

.chat-wrapper {
    width: 100%;
    max-width: 800px;
    height: calc(100vh - 40px);
    max-height: 900px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* 聊天標題列 */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-medium);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-partner-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.partner-avatar {
    position: relative;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--offline);
    border: 2px solid var(--bg-medium);
    border-radius: var(--radius-full);
}

.online-indicator.online {
    background: var(--online);
}

.partner-details h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.partner-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.partner-status.online {
    color: var(--online);
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.current-user {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 6px 12px;
    background: var(--bg-light);
    border-radius: var(--radius-full);
}

/* 訊息區域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-light);
    border-radius: 3px;
}

.messages-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 16px;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 訊息氣泡 */
.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    word-break: break-word;
    position: relative;
}

.message.sent .message-bubble {
    background: var(--bubble-sent);
    border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
    background: var(--bubble-received);
    border-bottom-left-radius: 4px;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.5;
}

.message-image {
    max-width: 280px;
    max-height: 280px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.message-image:hover {
    transform: scale(1.02);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.message.sent .message-meta {
    justify-content: flex-end;
}

.read-status {
    display: flex;
    align-items: center;
}

.read-status svg {
    width: 14px;
    height: 14px;
}

.read-status.read svg {
    color: #60a5fa;
}

.sender-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* 日期分隔線 */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.date-separator span {
    padding: 6px 16px;
    background: var(--bg-light);
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* 輸入區域 */
.chat-input-area {
    padding: 16px 20px;
    background: var(--bg-medium);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-dark);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    border: 1px solid var(--bg-light);
    transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--primary);
}

.image-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.image-upload-btn:hover {
    background: var(--bg-light);
}

.image-upload-btn svg {
    width: 22px;
    height: 22px;
    color: var(--text-secondary);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 8px 0;
}

#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(--bubble-sent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
}

.send-btn svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* 圖片預覽 */
.image-preview-container {
    margin-top: 12px;
}

.image-preview {
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 200px;
    max-height: 150px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--primary);
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--unread);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 圖片檢視器 */
.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);
    backdrop-filter: blur(8px);
}

.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: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    background: var(--bg-light);
    color: var(--text-primary);
    border: none;
    border-radius: var(--radius-full);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 通知提示 */
.notification-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 999;
    animation: slideIn 0.3s ease;
    max-width: 320px;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.notification-toast .toast-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.notification-toast .toast-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.notification-toast .toast-body {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* 響應式設計 */
@media (max-width: 640px) {
    #chat-container {
        padding: 0;
    }
    
    .chat-wrapper {
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }
    
    .auth-box {
        padding: 24px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .current-user {
        display: none;
    }
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bubble-received);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

