/* Modern CSS for Secure Communication System */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5; /* 更接近微信/QQ类应用的浅灰背景 */
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* Header */
.header {
    text-align: left;
    color: #111;
    margin-bottom: 10px;
    padding: 0;
}

.header h1 {
    font-size: 1.4em;
    margin-bottom: 2px;
    font-weight: 600;
}

.subtitle {
    font-size: 0.8em;
    opacity: 0.6;
}

/* Panel Styles */
.panel {
    background: white;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin-bottom: 15px;
}

.connection-panel {
    padding: 20px;
}

.panel h2 {
    color: #111;
    margin-bottom: 16px;
    font-size: 1.3em;
}

/* Form Styles */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #888;
    font-size: 0.85em;
}

/* Button Styles */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin: 4px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85em;
}

.btn-primary {
    background: #07c160; /* 微信绿色 */
    color: white;
    border: none;
}

.btn-primary:hover {
    background: #06ad56;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(7, 193, 96, 0.3);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #d0d0d0;
}

.btn-secondary:hover {
    background: #e0e0e0;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Status */
.status {
    margin-top: 15px;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
}

.status.connected {
    background: #d4edda;
    color: #155724;
}

.status.disconnected {
    background: #f8d7da;
    color: #721c24;
}

/* Chat Panel Wrapper - 三栏布局：房间列表 | 聊天区 | 加密详情 */
.chat-panel-wrapper {
    display: flex;
    gap: 0;
    height: calc(100vh - 120px);
    min-height: 600px;
    max-height: 92vh;
    align-items: stretch;
    overflow: hidden;
}

/* Room Sidebar - 左侧房间列表 */
.room-sidebar {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border-right: 1px solid #e8e8e8;
    background: #f8f8f8;
    flex-shrink: 0;
}

.room-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #e8e8e8;
    background: #fff;
}

.room-sidebar-header h3 {
    margin: 0;
    font-size: 0.9em;
    color: #333;
    font-weight: 600;
}

/* Room Sections */
.room-section {
    margin-bottom: 0;
}

.room-section-header {
    padding: 8px 12px;
    font-size: 0.7em;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border-bottom: 1px solid #f0f0f0;
}

.btn-icon-small {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-icon-small:hover {
    opacity: 1;
}

.room-list {
    overflow-y: auto;
    max-height: 280px;
}

.room-item {
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-left: 3px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.room-item:hover {
    background: #f0f0f0;
}

.room-item.active {
    background: #e7f3ff;
    border-left-color: #07c160;
}

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

.room-item-name {
    font-weight: 500;
    font-size: 0.85em;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-item-preview {
    font-size: 0.7em;
    color: #aaa;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-user-count {
    font-size: 0.75em;
    color: #666;
    background: #e8e8e8;
    padding: 2px 6px;
    border-radius: 8px;
}

.room-unread-badge {
    background: #f43530;
    color: white;
    border-radius: 10px;
    padding: 2px 7px;
    font-size: 0.7em;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* Chat Panel - 中间主聊天区 */
.chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #e8e8e8;
    background: #fff;
    flex-shrink: 0;
}

.room-info {
    flex: 1;
}

.room-info h2 {
    margin: 0 0 3px 0;
    font-size: 1.1em;
    font-weight: 600;
}

.current-room-name {
    font-size: 0.75em;
    color: #888;
    font-weight: 400;
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 20px;
}

.indicator-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #dc3545;
    animation: pulse 2s infinite;
}

.indicator-dot.connected {
    background: #28a745;
}

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

/* Chat Main Area - 包含消息和输入框 */
.chat-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 15px;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px;
    background: #f5f5f5;
    border-radius: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.message {
    margin-bottom: 6px;
    padding: 7px 11px;
    border-radius: 10px;
    animation: slideIn 0.25s ease-out;
    transition: background 0.15s;
    max-width: 60%;
    word-wrap: break-word;
    position: relative;
}

.message:hover {
    opacity: 0.96;
}

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

.message.sent {
    background: #95ec69;
    color: #1a1a1a;
    margin-left: auto;
    margin-right: 8px;
    text-align: left;
    box-shadow: 0 1px 1.5px rgba(0,0,0,0.05);
}

.message.received {
    background: #ffffff;
    color: #1a1a1a;
    margin-left: 8px;
    margin-right: auto;
    box-shadow: 0 1px 1.5px rgba(0,0,0,0.05);
}

.message.system-message {
    background: transparent;
    color: #b2b2b2;
    text-align: center;
    margin: 8px auto;
    border: none;
    padding: 4px 12px;
    font-size: 0.75em;
    max-width: 80%;
    box-shadow: none;
}

.message.system-message:hover {
    transform: none;
    box-shadow: none;
}

.message-header {
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 0.8em;
    opacity: 0.6;
    color: #666;
}

.message-content {
    word-wrap: break-word;
    line-height: 1.4;
}

.message-timestamp {
    font-size: 0.7em;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
    color: #999;
}

.encryption-info {
    display: none; /* 隐藏消息中的加密预览，只在侧边栏显示 */
}

/* Input Area */
.input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #e8e8e8;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.9em;
    font-family: inherit;
    resize: none;
    min-height: 45px;
    max-height: 90px;
    background: #fafafa;
    transition: all 0.2s;
    line-height: 1.5;
}

.input-group textarea:focus {
    outline: none;
    border-color: #07c160;
    box-shadow: 0 0 0 2px rgba(7, 193, 96, 0.08);
    background: #fff;
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Encryption Details Sidebar - 右侧边栏 */
.encryption-sidebar {
    width: 340px;
    min-width: 340px;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
    overflow: hidden;
    flex-shrink: 0;
    border-left: 1px solid #e8e8e8;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e8e8e8;
    background: #fafafa;
}

.sidebar-header h3 {
    color: #333;
    margin: 0;
    font-size: 0.95em;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    font-weight: 300;
    line-height: 1;
}

.btn-icon:hover {
    background: #e0e0e0;
    color: #333;
}

.encryption-sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    border: none;
    opacity: 0;
    transition: all 0.3s ease;
    gap: 0; /* 折叠时移除gap */
}

.encryption-sidebar:not(.collapsed) {
    opacity: 1;
    transition: all 0.3s ease;
}

.encryption-sidebar.collapsed .sidebar-header,
.encryption-sidebar.collapsed .details-content {
    display: none;
}

.details-content {
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    overflow-y: auto;
    flex: 1;
    padding: 20px;
    min-height: 0; /* Important for flex scrolling */
    background: white;
}

/* Custom scrollbar for details content */
.details-content::-webkit-scrollbar {
    width: 8px;
}

.details-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.details-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.details-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.detail-item {
    margin-bottom: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #667eea;
    transition: background 0.2s;
}

.detail-item:hover {
    background: #f0f0f0;
}

.detail-item label {
    font-weight: 600;
    color: #555;
    display: block;
    margin-bottom: 6px;
    font-size: 0.9em;
}

.detail-item .value {
    color: #222;
    word-break: break-all;
    padding: 8px;
    background: white;
    border-radius: 4px;
    font-size: 0.85em;
    line-height: 1.4;
    border: 1px solid #e0e0e0;
}

.info-text {
    color: #888;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

/* File Info */
.file-info {
    background: #e7f3ff;
    padding: 10px;
    border-radius: 5px;
    margin-top: 10px;
    border-left: 4px solid #2196F3;
}

.file-info strong {
    color: #1976D2;
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .chat-panel-wrapper {
        flex-direction: column;
    }
    
    .encryption-sidebar {
        width: 100%;
        max-width: 100%;
        max-height: 300px;
    }
    
    .encryption-sidebar.collapsed {
        display: none;
    }
}

@media (max-width: 768px) {
    .header h1 {
        font-size: 1.4em;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 10px;
    }
    
    .chat-header h2 {
        font-size: 1.1em;
    }
    
    .message.sent,
    .message.received {
        margin-left: 0;
        margin-right: 0;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .encryption-sidebar {
        max-height: 250px;
    }
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

