/* ============================================
   NexusChat - Main Styles
   ============================================ */

:root {
    /* 品牌色彩 - LINE 風格綠色 */
    --primary: #06C755;
    --primary-light: #2BD670;
    --primary-dark: #00B548;
    --primary-bg: rgba(6, 199, 85, 0.1);
    
    /* 背景色 */
    --bg-primary: #FFFFFF;
    --bg-secondary: #F7F8FA;
    --bg-tertiary: #EDEFF2;
    --bg-hover: #E8EAED;
    --bg-active: #DFE1E5;
    
    /* 表面色 */
    --surface: #FFFFFF;
    --surface-elevated: #FFFFFF;
    --surface-overlay: rgba(0, 0, 0, 0.5);
    
    /* 邊框色 */
    --border: #E0E0E0;
    --border-light: #EEEEEE;
    --border-focus: var(--primary);
    
    /* 文字色 */
    --text-primary: #1A1A1A;
    --text-secondary: #666666;
    --text-muted: #999999;
    --text-inverse: #FFFFFF;
    
    /* 狀態色 */
    --success: #06C755;
    --warning: #FFA726;
    --error: #F44336;
    --info: #2196F3;
    --online: #06C755;
    --offline: #9E9E9E;
    
    /* 訊息氣泡 */
    --bubble-sent: var(--primary);
    --bubble-sent-text: #FFFFFF;
    --bubble-received: #F0F0F0;
    --bubble-received-text: #1A1A1A;
    
    /* 陰影 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.2);
    
    /* 圓角 */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    /* 過渡動畫 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    
    /* 字體 */
    --font-sans: 'Nunito', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'SF Mono', 'Monaco', monospace;
    
    /* 層級 */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 300;
    --z-toast: 400;
    --z-tooltip: 500;
    
    /* 安全區域 */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    
    /* 導航高度 */
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --input-area-height: 60px;
}

/* 深色模式 */
[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-secondary: #1E1E1E;
    --bg-tertiary: #2A2A2A;
    --bg-hover: #333333;
    --bg-active: #404040;
    
    --surface: #1E1E1E;
    --surface-elevated: #2A2A2A;
    
    --border: #333333;
    --border-light: #404040;
    
    --text-primary: #FFFFFF;
    --text-secondary: #B0B0B0;
    --text-muted: #707070;
    
    --bubble-received: #2A2A2A;
    --bubble-received-text: #FFFFFF;
    
    --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);
}

/* ============================================
   重置樣式
   ============================================ */

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

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    height: 100%;
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    outline: none;
}

input, textarea, select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

ul, ol {
    list-style: none;
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   啟動畫面
   ============================================ */

#splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #06C755 0%, #00B548 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#splash-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-logo {
    width: 100px;
    height: 100px;
    margin: 0 auto 20px;
    animation: splash-bounce 1s ease infinite;
}

.splash-logo svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2));
}

.splash-logo svg circle {
    fill: white;
}

.splash-logo svg path {
    fill: #06C755;
}

@keyframes splash-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.splash-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.splash-text {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 16px;
}

.splash-loader {
    width: 120px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    margin: 0 auto;
    overflow: hidden;
}

.loader-bar {
    width: 40%;
    height: 100%;
    background: white;
    border-radius: var(--radius-full);
    animation: loader-slide 1.2s ease infinite;
}

@keyframes loader-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* ============================================
   應用程式容器
   ============================================ */

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

/* ============================================
   底部導航
   ============================================ */

#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: var(--z-sticky);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    color: var(--text-muted);
    transition: color var(--transition-fast);
    position: relative;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item:active {
    transform: scale(0.95);
}

.nav-icon {
    position: relative;
    width: 24px;
    height: 24px;
}

.nav-icon svg {
    width: 100%;
    height: 100%;
}

.nav-item span:not(.nav-badge) {
    font-size: 11px;
    font-weight: 600;
}

.nav-badge {
    position: absolute;
    top: -4px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--error);
    color: white;
    font-size: 11px;
    font-weight: 700;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   視圖容器
   ============================================ */

.view {
    position: fixed;
    top: var(--safe-area-top);
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    opacity: 0;
    visibility: hidden;
    transform: translateX(20px);
    transition: all var(--transition-normal);
}

.view.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.view-header {
    height: var(--header-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.view-header h1 {
    font-size: 20px;
    font-weight: 700;
}

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

.view-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   通用按鈕樣式
   ============================================ */

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-hover);
}

.icon-btn:active {
    background: var(--bg-active);
    transform: scale(0.95);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* ============================================
   搜尋框
   ============================================ */

.search-box {
    position: relative;
    margin: 12px 16px;
}

.search-box svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-box input {
    width: 100%;
    height: 44px;
    padding: 0 16px 0 44px;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    font-size: 15px;
    transition: all var(--transition-fast);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box input:focus {
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

/* ============================================
   狀態指示器
   ============================================ */

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    border: 2px solid var(--surface);
}

.status-dot.online {
    background: var(--online);
}

.status-dot.offline {
    background: var(--offline);
}

.status-dot.busy {
    background: var(--error);
}

.status-dot.away {
    background: var(--warning);
}

/* ============================================
   離線指示器
   ============================================ */

.offline-indicator {
    position: fixed;
    top: calc(var(--safe-area-top) + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--text-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-toast);
    opacity: 0;
    transition: all var(--transition-normal);
}

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

.offline-indicator svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   Toast 通知
   ============================================ */

.toast-container {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 16px);
    left: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: var(--z-toast);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--text-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: toast-in var(--transition-spring) forwards;
    pointer-events: auto;
}

.toast.hiding {
    animation: toast-out var(--transition-normal) forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }

/* ============================================
   Toggle 開關
   ============================================ */

.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ============================================
   響應式設計
   ============================================ */

@media (min-width: 768px) {
    #bottom-nav {
        width: 80px;
        height: 100%;
        flex-direction: column;
        justify-content: flex-start;
        padding: 20px 0;
        gap: 8px;
        border-top: none;
        border-right: 1px solid var(--border);
    }
    
    .nav-item {
        width: 100%;
        padding: 12px;
    }
    
    .view {
        left: 80px;
        bottom: 0;
    }
}

@media (min-width: 1024px) {
    .view-content {
        max-width: 600px;
        margin: 0 auto;
    }
}

/* ============================================
   動畫效果
   ============================================ */

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

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

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

@keyframes scaleIn {
    from { 
        opacity: 0;
        transform: scale(0.9);
    }
    to { 
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* 骨架屏動畫 */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
