/* === 全局重置与变量 === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #07c160;
    --primary-dark: #06ad56;
    --primary-light: #e8f8ee;
    --bg: #ededed;
    --card-bg: #ffffff;
    --text-primary: #191919;
    --text-secondary: #666;
    --text-light: #999;
    --border: #e5e5e5;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
    --nav-height: 56px;
    --header-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* === 顶部状态栏 === */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 16px;
    background: var(--card-bg);
    font-size: 12px;
    color: var(--text-primary);
    height: 28px;
    border-bottom: 1px solid var(--border);
}

.status-icons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.signal, .wifi, .battery {
    display: inline-block;
    width: 16px;
    height: 10px;
    background: currentColor;
    border-radius: 2px;
    opacity: 0.8;
}

.signal {
    clip-path: polygon(0 100%, 30% 60%, 60% 80%, 100% 0);
    width: 14px;
    height: 12px;
}

.wifi {
    clip-path: circle(40% at 50% 50%);
    width: 14px;
    height: 11px;
}

.battery {
    width: 18px;
    height: 10px;
    position: relative;
    background: transparent;
    border: 1.5px solid var(--text-primary);
    border-radius: 2px;
}
.battery::after {
    content: '';
    position: absolute;
    right: -4px;
    top: 2px;
    width: 3px;
    height: 4px;
    background: var(--text-primary);
    border-radius: 1px;
}

/* === 主应用 === */
#app {
    height: calc(100vh - 28px);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.page {
    display: none;
    height: 100%;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 1;
    transition: transform 0.3s ease;
}

.page.active {
    display: flex;
    z-index: 2;
}

/* === 头部 === */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo-img {
    width: 32px;
    height: 32px;
    display: block;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    text-align: center;
}

.header-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover, .icon-btn:active {
    background: var(--border);
}

/* === 搜索栏 === */
.search-bar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 20px;
    background: var(--bg);
    font-size: 14px;
    outline: none;
}

.cancel-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 14px;
    cursor: pointer;
}

/* === 聊天列表 === */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: var(--card-bg);
    -webkit-overflow-scrolling: touch;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

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

.chat-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    margin-right: 12px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
}

.chat-item .avatar img {
    width: 100%;
    height: 100%;
    border-radius: 6px;
    object-fit: cover;
}

.chat-item .info {
    flex: 1;
    min-width: 0;
}

.chat-item .info .name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-item .info .last-msg {
    font-size: 13px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .time {
    font-size: 11px;
    color: var(--text-light);
    flex-shrink: 0;
    margin-left: 8px;
    align-self: flex-start;
    margin-top: 4px;
}

.chat-item .badge {
    position: absolute;
    top: 8px;
    right: 16px;
    background: #f44336;
    color: white;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
}

/* === 底部导航 === */
.bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--nav-height);
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    padding-bottom: var(--safe-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    padding: 4px 12px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 10px;
    transition: color 0.2s;
    position: relative;
}

.nav-item svg {
    width: 24px;
    height: 24px;
}

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

.nav-item span {
    font-size: 10px;
}

/* === 聊天详情页 === */
.chat-detail-header {
    display: flex;
    align-items: center;
    padding: 0 8px;
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

.chat-detail-header h2 {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 600;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.message.received {
    align-self: flex-start;
    background: var(--card-bg);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.sent {
    align-self: flex-end;
    background: var(--primary-light);
    border-bottom-right-radius: 4px;
}

.message .msg-time {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 4px;
    text-align: right;
}

.message-input-bar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    gap: 8px;
    flex-shrink: 0;
    padding-bottom: calc(8px + var(--safe-bottom));
}

.voice-btn {
    color: var(--text-secondary);
}

#message-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 15px;
    outline: none;
    background: var(--bg);
    transition: border-color 0.2s;
}

#message-input:focus {
    border-color: var(--primary);
}

.send-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.send-btn:active {
    background: var(--primary-dark);
    transform: scale(0.96);
}

/* === 弹窗 === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius);
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    animation: modalIn 0.2s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 0;
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-body input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.modal-body input:focus {
    border-color: var(--primary);
}

.confirm-add-btn {
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.confirm-add-btn:active {
    background: var(--primary-dark);
}

.contact-detail-modal .contact-detail-avatar {
    width: 80px;
    height: 80px;
    border-radius: 12px;
    object-fit: cover;
    margin: 0 auto 12px;
    display: block;
    background: var(--primary-light);
}

.contact-detail-body p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.contact-detail-body strong {
    color: var(--text-primary);
}

/* === 响应式 === */
@media (max-width: 480px) {
    .header-title {
        font-size: 16px;
    }
    .chat-item .avatar {
        width: 44px;
        height: 44px;
    }
    .message {
        max-width: 85%;
        font-size: 14px;
    }
    .modal-content {
        max-width: 100%;
        margin: 0 12px;
    }
}

@media (min-width: 768px) {
    body {
        max-width: 420px;
        margin: 0 auto;
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
        box-shadow: 0 0 30px rgba(0,0,0,0.1);
    }
    .status-bar {
        padding: 4px 20px;
    }
}

@media (min-width: 1024px) {
    body {
        max-width: 480px;
    }
}

/* === 滚动条美化 === */
::-webkit-scrollbar {
    width: 4px;
}

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

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

/* === 空状态 === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-light);
    padding: 40px;
    text-align: center;
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
    opacity: 0.4;
}

/* 后台入口（隐藏，通过特殊手势触发） */
.admin-entry {
    position: absolute;
    bottom: 60px;
    right: 10px;
    width: 40px;
    height: 40px;
    opacity: 0;
    z-index: 0;
    pointer-events: none;
}