* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body { margin: 0; padding: 0; font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Arial, sans-serif; background: #eef2f7; color: #1a1a2e; }
a { color: #2196F3; text-decoration: none; }
a:hover { color: #ff8800; }

.topmenu { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); position: sticky; top: 0; z-index: 500; box-shadow: 0 2px 12px rgba(0,0,0,0.15); }
.topmenu-inner { display: flex; align-items: center; max-width: 1280px; margin: 0 auto; padding: 0 16px; min-height: 52px; }
.topmenu-logo img { height: 28px; display: block; filter: brightness(1.2); }
.topmenu-nav { margin-left: auto; display: flex; gap: 2px; }
.topmenu-nav a { color: rgba(255,255,255,0.85); text-decoration: none; padding: 10px 14px; font-size: 13px; border-radius: 8px; transition: all 0.2s; }
.topmenu-nav a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.topmenu-nav a i { margin-right: 4px; }
.hamburger { display: none; background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; margin-left: auto; padding: 10px; }

.page-content { max-width: 1280px; margin: 0 auto; padding: 12px 16px; min-height: calc(100vh - 100px); }
.footer-bar { background: #1a1a2e; color: rgba(255,255,255,0.5); text-align: center; padding: 10px; font-size: 12px; }

h1 { font: 600 26px -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #1a1a2e; margin: 12px 0 16px; }
h1 i { color: #2196F3; margin-right: 6px; }
h2 { font: 600 20px -apple-system, sans-serif; color: #1a1a2e; margin: 16px 0 10px; }
h3 { font: 600 17px -apple-system, sans-serif; color: #1a1a2e; margin: 0 0 12px; }
h3 i { color: #2196F3; margin-right: 6px; }

.flash { font-size: 13px; border-radius: 8px; padding: 12px 16px; margin-bottom: 15px; }

.form-card { background: #fff; border: 1px solid #e0e6ed; border-radius: 12px; padding: 24px; max-width: 480px; margin: 0 0 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: #666; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 12px; font: 14px -apple-system, sans-serif; border: 1.5px solid #dde3ea; border-radius: 8px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; background: #fafbfc; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: #2196F3; box-shadow: 0 0 0 3px rgba(33,150,243,0.12); background: #fff; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; min-width: 0; }
.form-link { font-size: 13px; }

.server-settings { margin: 12px 0; padding: 12px; background: #f8fafc; border: 1px solid #e8eef4; border-radius: 8px; }
.server-settings summary { cursor: pointer; font-size: 12px; color: #2196F3; font-weight: 600; margin-bottom: 8px; }

.btn-primary { background: linear-gradient(135deg, #2196F3, #1976D2); color: #fff; border: none; padding: 11px 24px; font: 600 14px -apple-system, sans-serif; border-radius: 8px; cursor: pointer; width: 100%; text-align: center; text-decoration: none; transition: all 0.2s; box-shadow: 0 2px 8px rgba(33,150,243,0.25); }
.btn-primary:hover { background: linear-gradient(135deg, #1E88E5, #1565C0); color: #fff; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(33,150,243,0.35); }
.btn-secondary { background: #f0f2f5; color: #555; border: 1px solid #ddd; padding: 11px 24px; font: 14px -apple-system, sans-serif; border-radius: 8px; cursor: pointer; width: 100%; transition: all 0.2s; }
.btn-secondary:hover { background: #e4e6e9; }

.chat-container { display: flex; height: calc(100vh - 100px); height: calc(100dvh - 100px); border-radius: 12px; overflow: hidden; background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }

.chat-sidebar { width: 320px; min-width: 320px; background: #fff; border-right: 1px solid #e8eef4; display: flex; flex-direction: column; }
.sidebar-header { background: linear-gradient(135deg, #1a1a2e, #16213e); color: white; padding: 14px; }
.user-info-bar { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.3); object-fit: cover; }
.user-details { flex: 1; min-width: 0; }
.user-email { font: 600 13px -apple-system, sans-serif; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-details select { width: 100%; font: 12px -apple-system, sans-serif; padding: 3px 6px; border-radius: 6px; border: none; background: rgba(255,255,255,0.15); color: #fff; }
.user-details select option { background: #1a1a2e; color: #fff; }

.sidebar-actions { padding: 8px; display: flex; gap: 4px; border-bottom: 1px solid #e8eef4; background: #f8fafc; }
.btn-small { font-size: 13px; padding: 8px; background: transparent; color: #666; border: 1px solid #e0e6ed; border-radius: 8px; cursor: pointer; flex: 1; text-align: center; transition: all 0.2s; }
.btn-small:hover { background: #2196F3; color: #fff; border-color: #2196F3; }

.contact-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.contact-group { padding: 8px 14px; font: 600 11px -apple-system, sans-serif; color: #999; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; background: #f8fafc; border-bottom: 1px solid #f0f2f5; }
.contact-group:hover { background: #f0f2f5; }
.contact-group i { margin-right: 4px; font-size: 10px; }

.contact-item { padding: 10px 14px; cursor: pointer; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #f5f5f5; min-height: 56px; transition: background 0.15s; }
.contact-item:hover { background: #f0f7ff; }
.contact-item.active { background: #e3f2fd; }
.contact-item.offline { opacity: 0.45; }

.contact-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #e0e6ed; }
.contact-avatar-wrap { position: relative; flex-shrink: 0; }
.contact-status-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; }
.contact-status-dot.online { background: #4CAF50; }
.contact-status-dot.away { background: #FF9800; }
.contact-status-dot.offline { background: #bbb; }
.contact-status-dot.invisible { background: #9C27B0; }

.contact-name { flex: 1; overflow: hidden; min-width: 0; }
.contact-nick { font: 600 13px -apple-system, sans-serif; color: #1a1a2e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-email { font-size: 11px; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.contact-badges { font-size: 9px; color: #aaa; }
.contact-badges i { margin-right: 2px; }

.contact-actions { display: none; gap: 4px; flex-shrink: 0; }
.contact-item:hover .contact-actions { display: flex; }
.contact-actions button { font-size: 12px; padding: 4px 8px; border: none; background: #f0f2f5; cursor: pointer; border-radius: 6px; color: #666; transition: all 0.15s; }
.contact-actions button:hover { background: #2196F3; color: #fff; }
.contact-actions .btn-del:hover { background: #f44336; color: #fff; }

.unread-badge { background: #f44336; color: white; font-size: 10px; padding: 2px 7px; border-radius: 10px; font-weight: 700; flex-shrink: 0; }

.chat-main { flex: 1; display: flex; flex-direction: column; background: #fafbfc; min-width: 0; }
.chat-header { background: #fff; color: #1a1a2e; padding: 12px 16px; font: 600 14px -apple-system, sans-serif; border-bottom: 1px solid #e8eef4; display: flex; align-items: center; gap: 10px; min-height: 56px; }
.chat-header-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.chat-contact-name { flex: 1; }
.chat-contact-status { font-size: 12px; font-weight: 400; color: #999; }
.btn-back { display: none; background: none; border: none; color: #2196F3; font-size: 18px; cursor: pointer; padding: 4px 8px; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; background: #f0f4f8; -webkit-overflow-scrolling: touch; }
.no-chat { text-align: center; padding: 80px 20px; color: #bbb; }

.message { margin-bottom: 6px; max-width: 75%; clear: both; }
.message.incoming { float: left; }
.message.outgoing { float: right; }
.message-bubble { padding: 10px 14px; font: 13px/1.5 -apple-system, sans-serif; word-wrap: break-word; overflow-wrap: break-word; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.message.incoming .message-bubble { background: #fff; border-radius: 4px 16px 16px 16px; }
.message.outgoing .message-bubble { background: #2196F3; color: #fff; border-radius: 16px 4px 16px 16px; }
.message-sender { font-size: 11px; font-weight: 600; color: #2196F3; margin-bottom: 2px; }
.message-time { font-size: 10px; color: rgba(0,0,0,0.35); margin-top: 3px; text-align: right; }
.message.outgoing .message-time { color: rgba(255,255,255,0.6); }
.message-system { text-align: center; color: #999; font-size: 12px; margin: 12px 0; clear: both; }
.message-system i { margin-right: 4px; }
.message-auth { background: #fff3cd; border: 1px solid #ffc107; padding: 12px 16px; border-radius: 12px; margin: 8px 0; clear: both; font-size: 12px; }
.date-separator { text-align: center; color: #bbb; font-size: 11px; margin: 16px 0 8px; clear: both; }
.date-separator span { background: #f0f4f8; padding: 2px 14px; border-radius: 10px; }

.chat-input { padding: 10px 12px; border-top: 1px solid #e8eef4; display: flex; gap: 8px; background: #fff; align-items: flex-end; }
.chat-input textarea { flex: 1; height: 44px; resize: none; font: 14px -apple-system, sans-serif; padding: 10px 14px; border: 1.5px solid #dde3ea; border-radius: 12px; outline: none; min-width: 0; background: #f8fafc; transition: border-color 0.2s; }
.chat-input textarea:focus { border-color: #2196F3; background: #fff; }
.chat-input-buttons { display: flex; gap: 4px; }
.btn-send { padding: 10px 14px; background: linear-gradient(135deg, #2196F3, #1976D2); color: white; border: none; font-size: 16px; cursor: pointer; border-radius: 12px; transition: all 0.2s; }
.btn-send:hover { transform: scale(1.05); }
.btn-attach, .btn-alarm { padding: 10px 12px; background: #f0f2f5; color: #666; border: none; font-size: 14px; cursor: pointer; border-radius: 10px; transition: all 0.15s; }
.btn-attach:hover { background: #e3f2fd; color: #2196F3; }
.btn-alarm:hover { background: #fff3e0; color: #ff9800; }

.typing-indicator { padding: 6px 16px; font: 12px -apple-system, sans-serif; color: #999; background: #f8fafc; border-top: 1px solid #f0f2f5; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); z-index: 1000; backdrop-filter: blur(4px); }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 24px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); z-index: 1001; width: 90%; max-width: 420px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; padding-bottom: 12px; border-bottom: 1px solid #f0f2f5; }
.modal-buttons { display: flex; gap: 8px; margin-top: 16px; }
.modal-buttons .btn-primary, .modal-buttons .btn-secondary { flex: 1; padding: 11px; }

.loading { text-align: center; padding: 40px; color: #bbb; font: 13px -apple-system, sans-serif; }
.loading i { font-size: 20px; display: block; margin-bottom: 8px; }

.notification { position: fixed; top: 60px; right: 12px; left: 12px; max-width: 400px; margin-left: auto; background: #1a1a2e; color: white; padding: 14px 18px; border-radius: 12px; font: 13px -apple-system, sans-serif; z-index: 2000; box-shadow: 0 8px 32px rgba(0,0,0,0.25); animation: slideDown 0.3s ease; }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.profile-card { display: flex; gap: 24px; background: #fff; border-radius: 12px; padding: 24px; max-width: 500px; align-items: flex-start; flex-wrap: wrap; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.profile-avatar { width: 90px; height: 90px; border-radius: 50%; border: 3px solid #e3f2fd; object-fit: cover; }
.profile-info { flex: 1; min-width: 200px; }
.profile-row { padding: 6px 0; font-size: 13px; word-break: break-all; border-bottom: 1px solid #f5f5f5; }
.profile-row:last-child { border-bottom: none; }
.profile-row b { color: #666; font-weight: 600; }

.search-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 12px; }
.search-card { background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.04); transition: transform 0.15s, box-shadow 0.15s; }
.search-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.search-card-name { font: 600 14px -apple-system, sans-serif; color: #1a1a2e; }
.search-card-email { font-size: 12px; color: #888; }
.search-card-info { font-size: 11px; color: #aaa; margin-top: 4px; }

.sessions-list { display: flex; flex-direction: column; gap: 8px; max-width: 600px; }
.session-card { display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.04); transition: all 0.15s; }
.session-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.session-current { border-left: 3px solid #4CAF50; }
.session-icon { width: 40px; height: 40px; border-radius: 10px; background: #f0f2f5; display: flex; align-items: center; justify-content: center; font-size: 18px; color: #666; }
.session-current .session-icon { background: #e8f5e9; color: #4CAF50; }
.session-info { flex: 1; min-width: 0; }
.session-title { font: 600 14px -apple-system, sans-serif; color: #1a1a2e; }
.session-detail { font-size: 12px; color: #999; margin-top: 2px; }
.session-detail i { width: 14px; text-align: center; margin-right: 4px; }
.session-actions { flex-shrink: 0; }
.session-badge { font-size: 12px; color: #4CAF50; font-weight: 600; }
.session-badge i { margin-right: 3px; }
.btn-danger { display: inline-block; padding: 6px 14px; background: #fff; border: 1px solid #f44336; color: #f44336; border-radius: 8px; font-size: 12px; font-weight: 600; text-decoration: none; transition: all 0.15s; }
.btn-danger:hover { background: #f44336; color: #fff; }
.btn-danger-full { display: inline-block; padding: 10px 20px; background: #f44336; color: #fff; border-radius: 8px; font: 600 13px -apple-system, sans-serif; text-decoration: none; transition: all 0.15s; }
.btn-danger-full:hover { background: #d32f2f; color: #fff; }

@media (max-width: 768px) {
    .hamburger { display: block; }
    .topmenu-nav { display: none; position: absolute; top: 52px; left: 0; right: 0; background: #1a1a2e; flex-direction: column; padding: 0 0 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 501; }
    .topmenu-nav.open { display: flex; }
    .topmenu-nav a { padding: 14px 20px; border-radius: 0; font-size: 15px; }
    .page-content { padding: 8px; }
    h1 { font-size: 22px; margin: 8px 0 10px; }
    .chat-container { height: calc(100vh - 80px); height: calc(100dvh - 80px); border-radius: 0; margin: -8px; box-shadow: none; }
    .chat-sidebar { width: 100%; min-width: 100%; position: absolute; top: 0; bottom: 0; left: 0; z-index: 10; transition: transform 0.25s ease; }
    .chat-sidebar.hidden { transform: translateX(-100%); }
    .chat-main { width: 100%; }
    .btn-back { display: block; }
    .contact-item { padding: 12px 14px; }
    .contact-actions { display: flex; }
    .message { max-width: 88%; }
    .chat-input textarea { height: 40px; font-size: 16px; }
    .form-card { max-width: 100%; padding: 16px; }
    .form-row { flex-direction: column; gap: 0; }
    .modal { width: 95%; max-width: none; padding: 18px; }
    .notification { left: 8px; right: 8px; max-width: none; }
    .profile-card { flex-direction: column; align-items: center; text-align: center; }
    .search-results { grid-template-columns: 1fr; }
    .session-card { flex-wrap: wrap; }
}
