* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #ededed; height: 100vh; overflow: hidden; }

/* Login - simplified */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-box {
    background: rgba(255, 255, 255, 0.97);
    padding: 48px 40px 40px;
    border-radius: 20px;
    width: 360px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
}

/* SVG Pig logo */
.pig-logo {
    display: block;
    margin: 0 auto 20px;
    width: 72px;
    height: 72px;
}
.pig-logo svg {
    width: 100%;
    height: 100%;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 8px;
    color: #1a1a2e;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 1px;
}

/* Tagline */
.login-tagline {
    text-align: center;
    margin-bottom: 20px;
}
.login-tagline strong {
    color: #1a1a2e;
    font-weight: 700;
    font-size: 16px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ===== Desktop/Home page - 简洁精致的单页风格 ===== */
.desktop-page {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    background: #f5f5f5;
    overflow-y: auto;
}
.desktop-page.active { display: flex; }

/* Desktop header */
.desktop-header {
    text-align: center;
    padding: 50px 20px 10px;
}
.desktop-header h1 {
    font-size: 24px;
    color: #1a1a2e;
    font-weight: 600;
    margin-bottom: 6px;
}
.desktop-header p {
    font-size: 14px;
    color: #999;
}

/* Desktop grid */
.desktop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 30px 20px;
    max-width: 800px;
    margin: 0 auto;
}
@media (min-width: 768px) {
    .desktop-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; padding: 40px 30px; }
}
@media (min-width: 1024px) {
    .desktop-grid { grid-template-columns: repeat(3, 1fr); max-width: 900px; gap: 20px; padding: 50px 40px; }
}

/* Desktop cards - 简洁风格，类似工具栏按钮 */
.desktop-card {
    background: white;
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid #eee;
}
.desktop-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    border-color: #4a90d9;
}
.desktop-card:active {
    transform: scale(0.97);
}
.desktop-card .card-icon {
    font-size: 36px;
    margin-bottom: 10px;
}
.desktop-card .card-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}
.desktop-card .card-desc {
    font-size: 11px;
    color: #bbb;
}

/* Philosophy section */
.philosophy-section {
    text-align: center;
    padding: 40px 20px;
    max-width: 600px;
    margin: 30px auto 0;
}
.philosophy-quote {
    font-size: 18px;
    color: #555;
    font-weight: 500;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Desktop logout */
.desktop-logout {
    text-align: center;
    padding: 20px;
}
.desktop-logout button {
    background: rgba(255,255,255,0.6);
    border: 1px solid #ddd;
    padding: 8px 24px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    color: #999;
}

.login-box input { width: 100%; padding: 12px; margin: 8px 0; border: none; border-bottom: 1px solid #ddd; font-size: 15px; outline: none; background: transparent; transition: border-color 0.3s; }
.login-box input:focus { border-bottom-color: #4a90d9; }
.login-box button { width: 100%; padding: 12px; background: #4a90d9; color: white; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; margin-top: 24px; transition: transform 0.2s, box-shadow 0.2s, background 0.2s; }
.login-box button:hover { background: #3d7fc7; box-shadow: 0 4px 15px rgba(74, 144, 217, 0.3); }
.login-box button:active { transform: translateY(0); }
.error-msg { color: red; text-align: center; margin-top: 10px; font-size: 13px; }

/* Main App */
.app { display: none; height: 100vh; min-height: 200px; flex-direction: column; }

/* Top bar (wechat style) */
.topbar { background: #ededed; padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #d9d9d9; flex-shrink: 0; min-height: 44px; }
.topbar-left { display: flex; align-items: center; gap: 4px; }
.topbar-back {
    background: none;
    border: none;
    cursor: pointer;
    color: #191919;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 14px;
}
.topbar-back svg {
    width: 20px;
    height: 20px;
}
.topbar-title { font-size: 17px; font-weight: 500; color: #191919; flex: 1; text-align: center; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: #191919; padding: 4px 8px; }
.ws-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ws-status.connected { background: #07c160; }
.ws-status.disconnected { background: #fa5151; }

/* Container */
.container { flex: 1; display: flex; overflow: hidden; }

/* Admin mode: left panel for buttons, right panel for details - side by side */
.container.admin-mode {
    background: #f5f5f5;
}
.container.admin-mode .chat-area,
.container.admin-mode #noChatSelected,
.container.admin-mode .message-list,
.container.admin-mode .input-bar {
    display: none !important;
}
.container.admin-mode .sidebar {
    width: 35% !important;
    max-width: 35% !important;
    min-width: 260px !important;
    border-right: 1px solid #e5e5e5;
    overflow-y: auto;
}
/* Admin detail panel */
#adminDetail {
    display: none;
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f5f5f5;
}
.container.admin-mode #adminDetail {
    display: block !important;
}
/* Sidebar (group list - wechat style) */
.sidebar { width: 180px; min-width: 120px; max-width: 500px; background: white; border-right: 1px solid #e5e5e5; overflow-y: auto; flex-shrink: 1; position: relative; }
/* Resize handle */
.sidebar-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    z-index: 10;
}
.sidebar-resize-handle:hover {
    background: #4a90d9;
}
.sidebar-tabs { display: flex; border-bottom: 1px solid #e5e5e5; position: sticky; top: 0; background: white; z-index: 1; }
.sidebar-tab { flex: 1; padding: 12px; text-align: center; font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; color: #666; }
.sidebar-tab.active { color: #07c160; border-bottom-color: #07c160; font-weight: 500; }

/* Group list items */
.group-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0; transition: background 0.1s; }
.group-item:hover { background: #f5f5f5; }
.group-item.active { background: #d6eaf8; }
.group-avatar { width: 32px; height: 32px; border-radius: 4px; background: #07c160; color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.group-info { flex: 1; overflow: hidden; }
.group-name { font-size: 13px; color: #191919; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-last-msg { font-size: 11px; color: #999; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat area (fullscreen focus) */
.chat-area { flex: 1; display: flex; flex-direction: column; background: #f5f5f5; min-height: 0; }
.chat-area.visible { flex: 1; }

/* Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.message { margin-bottom: 20px; display: flex; flex-direction: column; }
.message.sent { align-items: flex-end; }
.message.received { align-items: flex-start; }

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
    margin-bottom: 4px;
    overflow: hidden;
}
.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sent .msg-avatar { background: #07c160; }
.received .msg-avatar { background: #e91e63; }

.msg-bubble-wrap { display: flex; gap: 8px; align-items: flex-start; max-width: 75%; }
.sent .msg-bubble-wrap { flex-direction: row-reverse; }

.msg-bubble { padding: 10px 14px; border-radius: 4px; font-size: 15px; line-height: 1.5; word-wrap: break-word; position: relative; cursor: pointer; }
.msg-bubble:hover { opacity: 0.9; }
.sent .msg-bubble { background: #95ec69; color: #191919; }
/* Image/video bubbles: no colored background */
.msg-bubble.has-media.sent { background: transparent !important; }
.msg-bubble.has-media.sent:hover { opacity: 1; }
.received .msg-bubble { background: white; color: #191919; border: none; }

/* Selected message highlight */
.msg-bubble.selected {
    opacity: 0.6;
}

/* Message context menu for forwarding */
.msg-context-menu {
    display: none;
    position: fixed;
    background: #3a3a3c;
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    min-width: 150px;
    overflow: hidden;
}
.msg-context-menu.visible { display: block; }
.msg-context-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 999;
}
.msg-context-overlay.visible { display: block; }

.msg-time-divider { text-align: center; margin: 16px 0; font-size: 12px; color: #999; }
.msg-name { font-size: 12px; color: #999; margin-bottom: 2px; padding-left: 4px; }

.active-chat { display: none; flex-direction: column; min-height: 0; overflow: hidden; flex: 1; }
.active-chat.visible { display: flex; }

/* Messages area - fill remaining space */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

/* msg action bar */
.msg-action-bar {
    display: none;
    background: #fff;
    padding: 12px;
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0;
    gap: 8px;
    align-items: center;
}
.msg-action-bar.visible { display: flex; }

/* Input bar - always at bottom */
.chat-input-bar {
    background: #fff;
    padding: 10px 14px;
    display: flex;
    gap: 6px;
    align-items: center;
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0;
}
.chat-input-bar input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 20px;
    font-size: 14px;
    background: #f8f8f8;
    outline: none;
    min-width: 50px;
    transition: border-color 0.2s, background 0.2s;
}
.chat-input-bar input[type="text"]:focus {
    border-color: #07c160;
    background: #fff;
}
/* Toolbar buttons (image, video, voice) */
.chat-toolbar {
    display: flex;
    gap: 2px;
    align-items: center;
}
.toolbar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: background 0.15s;
    padding: 0;
    flex-shrink: 0;
}
.toolbar-btn:hover {
    background: #f0f0f0;
}
.toolbar-btn.recording {
    background: #ffeaea;
    animation: pulse-red 1.5s infinite;
}
@keyframes pulse-red {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,70,70,0.3); }
    50% { box-shadow: 0 0 0 6px rgba(255,70,70,0); }
}
.toolbar-btn svg {
    width: 22px;
    height: 22px;
}
.chat-input-bar button.send-btn {
    padding: 8px 18px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
    transition: background 0.15s, transform 0.1s;
}
.chat-input-bar button.send-btn:hover {
    background: #06ad56;
}
.chat-input-bar button.send-btn:active {
    transform: scale(0.96);
}

/* Reply quote bar - shows when replying to a message */
.reply-quote-bar {
    background: #f7f7f7;
    padding: 8px 14px;
    border-top: 1px solid #e5e5e5;
    display: none;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.reply-quote-bar.visible { display: flex; }
.reply-quote-bar .reply-info {
    flex: 1;
    font-size: 13px;
}
.reply-quote-bar .reply-name {
    color: #07c160;
    font-weight: 600;
    margin-right: 6px;
}
.reply-quote-bar .reply-text {
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}
.reply-quote-bar button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #999;
    padding: 4px;
}

/* Reply preview in message bubble - WeChat style */
.msg-reply-preview {
    background: #f5f5f5;
    padding: 6px 10px;
    margin-bottom: 4px;
    border-radius: 4px;
    font-size: 13px;
    color: #999;
    display: flex;
    align-items: center;
    gap: 6px;
}
.msg-reply-preview .reply-name {
    color: #07c160;
    color: #666;
    font-weight: 500;
}

/* Revoked message */
.msg-revoked {
    color: #bbb;
    font-style: italic;
    font-size: 13px;
}

/* Message context menu (long press / right click) */
.msg-context-menu {
    display: none;
    position: fixed;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    z-index: 3000;
    min-width: 140px;
    overflow: hidden;
    padding: 4px 0;
}
.msg-context-menu.visible { display: block; }
.msg-context-item {
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}
.msg-context-item:hover { background: #f5f5f5; }
.msg-context-item.danger { color: #fa5151; }

/* Message action bar (appears when message is selected) */
.msg-action-bar {
    display: none;
    background: #fff;
    padding: 12px;
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0;
    gap: 8px;
    align-items: center;
}
.msg-action-bar.visible { display: flex; }
.msg-action-btn {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    flex: 1;
    text-align: center;
}
.msg-action-btn.forward { background: #4a90d9; color: white; }
.msg-action-btn.deselect { background: #eee; color: #333; }

/* Image editor overlay */
.image-editor-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    flex-direction: column;
}
.image-editor-overlay.visible { display: flex; }
.image-editor-toolbar {
    background: #333;
    padding: 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}
.editor-btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
}
.editor-btn.danger { background: #fa5151; color: white; }
.editor-btn.success { background: #07c160; color: white; }
.editor-btn.secondary { background: #666; color: white; }
.editor-btn.crop-active { background: #07c160; color: white; box-shadow: 0 0 0 2px white; }
.image-editor-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.image-editor-canvas-wrap canvas {
    max-width: 100%;
    max-height: 100%;
    touch-action: none;
    cursor: crosshair;
}

/* Crop overlay - dark mask with selection rectangle */
.crop-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
}
.crop-overlay.active { 
    display: block;
    pointer-events: auto;
}
.crop-selection {
    position: absolute;
    border: 2px solid #07c160;
    background: rgba(7, 193, 96, 0.1);
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
}

/* Admin Panel */
.admin-panel { flex: 1; overflow-y: auto; padding: 16px; background: #f5f5f5; }
.card { background: white; border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.card h3 { margin-bottom: 16px; color: #333; font-size: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 13px; color: #666; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; }
.btn { padding: 8px 16px; background: #07c160; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 13px; }
.btn:hover { background: #06ad56; }
.btn-danger { background: #fa5151; }

.member-checkbox { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.member-checkbox input[type="checkbox"] { width: auto; }

.group-table { width: 100%; border-collapse: collapse; }
.group-table th, .group-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #eee; }
.group-table th { font-size: 12px; color: #999; font-weight: normal; }

.question-card { background: white; border-radius: 8px; padding: 16px; margin-bottom: 12px; border-left: 4px solid #07c160; }
.question-card h4 { margin-bottom: 8px; }

/* Empty state */
.empty-chat { flex: 1; display: flex; align-items: center; justify-content: center; color: #999; font-size: 14px; }

/* Tab content panels */
.tab-panel { display: none; flex: 1; overflow: hidden; }
.tab-panel.active { display: flex; flex-direction: column; }

/* No chat selected state */
.no-chat-selected { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: #999; }
.no-chat-selected .icon { font-size: 48px; }

/* Mobile responsive - iPad/tablet */
@media (max-width: 1024px) {
    .container { overflow: visible !important; }
    .sidebar { width: 100%; flex-shrink: 0; }
    /* Chat area is hidden by default on mobile, shown only after group selected */
    .chat-area {
        display: none;
        flex: 1;
        min-width: 0;
        min-height: 0;
        flex-direction: column;
    }
    .chat-area.visible {
        position: fixed !important;
        top: 44px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        z-index: 50 !important;
        display: flex !important;
        background: #f5f5f5 !important;
        width: 100% !important;
        transition: background 0.2s;
    }
    
    .chat-area.drag-active {
        background: #e8f4fd !important;
        outline: 3px dashed #4a90d9;
        outline-offset: -3px;
    }
    /* When chat is visible, force sidebar to stay hidden even if inline style fails */
    .sidebar + .chat-area.visible ~ .sidebar,
    .container > .chat-area.visible {
        /* ensure container layout works with fixed child */
    }
    .msg-bubble-wrap { max-width: 85%; }
}
@media (min-width: 1025px) {
    .chat-area { display: flex !important; flex-direction: column; }
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
