/* ============================================
   微聊 · 微信风格移动APP  (PWA)
   设计：现代、圆润、绿色品牌、触摸友好
   ============================================ */

/* ---------- 全局重置 ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --green: #07C160;
    --green-dark: #06AD56;
    --green-light: #E8F8EE;
    --bg-primary: #F7F7F7;
    --bg-white: #FFFFFF;
    --text-primary: #1B1B1B;
    --text-secondary: #6B6B6B;
    --text-hint: #B0B0B0;
    --border-color: #ECECEC;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius-md: 18px;
    --radius-lg: 24px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tab-height: 64px;
    --header-height: 56px;
    --status-height: 28px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

/* ---------- 滚动条美化 ---------- */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #C8C8C8;
    border-radius: 8px;
}

/* ---------- 头部 ---------- */
#appHeader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: box-shadow 0.3s;
}
#appHeader.scrolled {
    box-shadow: 0 2px 16px rgba(0,0,0,0.06);
}
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--status-height);
    padding: 0 20px;
    background: var(--bg-white);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}
.status-icons span {
    margin-left: 4px;
    font-size: 12px;
    opacity: 0.8;
}
.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    padding: 0 16px;
}
.header-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.header-actions {
    display: flex;
    gap: 12px;
}
.header-btn {
    background: none;
    border: none;
    font-size: 22px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    cursor: pointer;
}
.header-btn:active {
    background: var(--border-color);
}

/* 搜索栏 */
.search-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px 12px;
    gap: 10px;
    background: var(--bg-white);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}
.search-bar.open {
    max-height: 60px;
    padding: 8px 16px 12px;
}
.search-bar input {
    flex: 1;
    height: 36px;
    background: var(--bg-primary);
    border: none;
    border-radius: 20px;
    padding: 0 16px;
    font-size: 15px;
    outline: none;
    color: var(--text-primary);
}
.search-bar input::placeholder {
    color: var(--text-hint);
}
.search-cancel {
    background: none;
    border: none;
    color: var(--green);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

/* ---------- 底部标签栏 ---------- */
#bottomTabBar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 99;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}
.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    padding: 6px 12px;
    min-width: 64px;
    cursor: pointer;
    transition: transform 0.15s;
    color: var(--text-hint);
    fill: var(--text-hint);
}
.tab-item.active {
    color: var(--green);
    fill: var(--green);
}
.tab-item:active {
    transform: scale(0.92);
}
.tab-icon {
    font-size: 24px;
    line-height: 1;
}
.tab-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.2px;
}

/* ---------- 主内容 ---------- */
#appContent {
    position: fixed;
    top: calc(var(--status-height) + var(--header-height));
    left: 0;
    right: 0;
    bottom: calc(var(--tab-height) + var(--safe-bottom));
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg-primary);
    -webkit-overflow-scrolling: touch;
}
.tab-content {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    padding: 4px 0;
}
.tab-content.hidden {
    display: none;
}

/* ---------- 聊天列表 ---------- */
.chat-list {
    padding: 4px 12px;
}
.chat-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 8px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
    border-radius: var(--radius-sm);
    margin: 2px 0;
}
.chat-item:active {
    background: var(--green-light);
}
.chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(145deg, #07C160, #06AD56);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(7,193,96,0.2);
}
.chat-info {
    flex: 1;
    min-width: 0;
}
.chat-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
}
.chat-time {
    font-size: 12px;
    color: var(--text-hint);
    font-weight: 400;
}
.chat-preview {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.chat-badge {
    background: #F54336;
    color: white;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    margin-left: 8px;
}

/* ---------- 通讯录 ---------- */
.contacts-wrapper {
    padding: 8px 12px;
}
.contact-group-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-hint);
    padding: 12px 8px 4px;
    letter-spacing: 0.3px;
}
.contact-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
    border-radius: var(--radius-sm);
}
.contact-item:active {
    background: var(--green-light);
}
.contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3B82F6, #6366F1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
}
.contact-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

/* ---------- 发现页 ---------- */
.discover-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px 16px;
}
.discover-card {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    padding: 20px 12px 16px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid var(--border-color);
}
.discover-card:active {
    transform: scale(0.96);
    box-shadow: var(--shadow-md);
}
.discover-icon {
    font-size: 36px;
    margin-bottom: 8px;
}
.discover-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}
.discover-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ---------- 个人页 ---------- */
.profile-wrapper {
    padding: 16px;
}
.profile-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}
.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(145deg, #07C160, #06AD56);
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(7,193,96,0.25);
}
.profile-name {
    font-size: 22px;
    font-weight: 700;
}
.profile-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.profile-menu {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
.profile-menu-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 16px;
}
.profile-menu-item:last-child {
    border-bottom: none;
}
.profile-menu-item:active {
    background: var(--green-light);
}
.menu-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.menu-icon {
    font-size: 20px;
}
.menu-arrow {
    color: var(--text-hint);
    font-size: 18px;
}

/* ---------- 模态弹窗 (聊天详情) ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 200;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease-out;
}
.modal-overlay.hidden {
    display: none;
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.modal-back {
    background: none;
    border: none;
    font-size: 18px;
    font-weight: 500;
    color: var(--green);
    cursor: pointer;
    padding: 8px 12px 8px 0;
}
.modal-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
}
.modal-action {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-hint);
    cursor: pointer;
    padding: 8px;
}
.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.message-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.message.received {
    align-self: flex-start;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}
.message.sent {
    align-self: flex-end;
    background: var(--green);
    color: white;
    border-bottom-right-radius: 4px;
}
.modal-footer {
    flex-shrink: 0;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-bottom));
}
.input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-primary);
    border-radius: 24px;
    padding: 4px 6px 4px 12px;
}
.input-emoji {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
}
#chatInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 4px;
    font-size: 16px;
    outline: none;
    color: var(--text-primary);
}
.input-send {
    background: var(--green);
    border: none;
    color: white;
    font-size: 15px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}
.input-send:active {
    background: var(--green-dark);
}

/* ---------- Toast ---------- */
.toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.toast {
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    animation: toastFade 2.4s ease forwards;
    pointer-events: auto;
}
@keyframes toastFade {
    0% { opacity: 0; transform: translateY(-12px) scale(0.9); }
    15% { opacity: 1; transform: translateY(0) scale(1); }
    85% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

/* ---------- 响应式微调 ---------- */
@media (min-width: 600px) {
    #appContent {
        max-width: 480px;
        margin: 0 auto;
        left: auto;
        right: auto;
        width: 100%;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
    #bottomTabBar {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
    #appHeader {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
}
@media (min-width: 1024px) {
    #appContent, #bottomTabBar, #appHeader {
        max-width: 420px;
    }
}

/* ---------- 其他小工具 ---------- */
.hidden {
    display: none !important;
}