* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #e8ecf1;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    -webkit-text-size-adjust: 100%;
    overflow: hidden;
}

/* ========== AUTH MODAL ========== */
.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.auth-content {
    background: white;
    padding: 32px;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
    animation: authSlideIn 0.4s ease;
}

@keyframes authSlideIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.auth-logo {
    font-size: 32px;
    font-weight: 700;
    color: #0f172a;
    text-align: center;
    margin-bottom: 4px;
}

.auth-subtitle {
    text-align: center;
    color: #64748b;
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: 2px solid #e2e8f0;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
    color: #64748b;
}

.auth-tab.active {
    border-color: #4a9eff;
    background: #4a9eff;
    color: white;
}

.auth-tab:hover:not(.active) {
    background: #f1f5f9;
}

.auth-form {
    display: block;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    margin: 6px 0;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.2s;
    background: #f8fafc;
}

.auth-form input:focus {
    outline: none;
    border-color: #4a9eff;
    background: white;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #4a9eff, #6b5bff);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    transition: transform 0.15s, box-shadow 0.2s;
}

.auth-btn:active {
    transform: scale(0.97);
}

.auth-btn:hover {
    box-shadow: 0 4px 20px rgba(74, 158, 255, 0.3);
}

.auth-error {
    color: #ef4444;
    margin-top: 10px;
    text-align: center;
    font-size: 14px;
    min-height: 20px;
}

.auth-success {
    color: #22c55e;
    margin-top: 10px;
    text-align: center;
    font-size: 14px;
    min-height: 20px;
}

.auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: #64748b;
}

.auth-footer a {
    color: #4a9eff;
    text-decoration: none;
    font-weight: 500;
}

/* ========== CONTAINER ========== */
.container {
    width: 100vw;
    height: 100vh;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ========== HEADER ========== */
.header {
    background: #1a2332;
    color: white;
    padding: 10px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid #4a9eff;
    flex-shrink: 0;
    min-height: 50px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.header h1 {
    font-size: 16px;
    font-weight: 600;
}

.header-badge {
    display: none;
}

.connection-status {
    font-size: 9px !important;
    padding: 2px 6px !important;
    color: #22c55e;
}

#appContent.container {
    display: flex;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.online-count {
    font-size: 10px;
    background: rgba(255,255,255,0.08);
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.inbox-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border: none;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.unread-count {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.private-chat-item.has-unread {
    font-weight: 700;
}

.header-btn, .clear-btn, .logout-btn {
    background: rgba(255,255,255,0.08);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.header-btn:hover, .logout-btn:hover {
    background: rgba(255,255,255,0.15);
}

.clear-btn {
    color: #ff6b6b;
}

.logout-btn {
    color: #ff6b6b;
}

/* ========== CHAT MAIN ========== */
.chat-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ========== SIDEBAR ========== */
.sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: #f7f9fc;
    padding: 16px;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 2px 0 20px rgba(0,0,0,0.15);
}

.sidebar.open {
    display: block;
}

.sidebar-close-btn {
    display: block;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #64748b;
    padding: 4px 8px;
    margin-bottom: 8px;
    float: right;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 4px;
    margin-bottom: 8px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4a9eff, #6b5bff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    font-weight: 600;
}

.user-info {
    flex: 1;
}

.user-name-display {
    font-weight: 600;
    color: #0f172a;
    font-size: 14px;
}

.user-status {
    font-size: 11px;
    color: #22c55e;
}

.sidebar-section {
    margin-bottom: 4px;
    clear: both;
}

.sidebar h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 6px;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.section-head h3 {
    margin-bottom: 0;
}

.section-add {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: #e8edf5;
    color: #334155;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.section-add:hover {
    background: #4a9eff;
    color: #fff;
}

.invite-card {
    background: #eff6ff;
    border-radius: 8px;
    padding: 8px;
    margin: 0 0 8px;
    font-size: 12px;
}

.invite-copy {
    color: #334155;
    margin-bottom: 6px;
}

.invite-actions {
    display: flex;
    gap: 6px;
}

.invite-actions button,
.member-row button {
    border: none;
    border-radius: 6px;
    background: #4a9eff;
    color: #fff;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
}

.invite-actions button.ghost,
.member-row button.ghost {
    background: #e2e8f0;
    color: #334155;
}

.invite-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.invite-row .search-input {
    flex: 1;
}

.invite-send {
    width: auto;
    padding: 8px 12px;
    margin: 0;
}

.member-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 13px;
    color: #334155;
}

.member-row.pending {
    color: #64748b;
    font-style: italic;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-chip {
    border: none;
    border-radius: 12px;
    background: rgba(74, 158, 255, 0.12);
    color: #2563eb;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
}

.room {
    padding: 8px 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    color: #334155;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.room,
button.room,
button.user-item,
button.private-chat-item {
    width: 100%;
    border: none;
    background: transparent;
    font: inherit;
    text-align: left;
}

.room:hover {
    background: #e8edf5;
}

.room.active {
    background: #4a9eff;
    color: white;
    font-weight: 500;
}

.room.active .favorite-star {
    color: #fff;
    opacity: 0.8;
}

.favorite-star {
    color: #fbbf24;
    font-size: 16px;
    cursor: pointer;
    opacity: 0.4;
    transition: all 0.2s;
    user-select: none;
    flex-shrink: 0;
    margin-left: auto;
    padding: 0 4px;
}

.favorite-star:hover {
    opacity: 1;
    transform: scale(1.2);
}

.favorite-star.active {
    opacity: 1;
}

hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 10px 0;
}

.user-list {
    font-size: 13px;
    max-height: 200px;
    overflow-y: auto;
}

.user-item {
    padding: 6px 10px;
    margin: 2px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 6px;
    transition: background 0.15s;
    cursor: pointer;
}

.user-item:hover {
    background: #e8edf5;
}

.user-item .status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
    flex-shrink: 0;
}

.user-item .user-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-item .private-badge {
    font-size: 11px;
    color: #4a9eff;
    opacity: 0.7;
    flex-shrink: 0;
}

.user-item .you-badge {
    font-size: 10px;
    color: #94a3b8;
    background: #f1f5f9;
    padding: 1px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.bot-badge {
    font-size: 10px;
    color: #7c3aed;
    background: #ede9fe;
    padding: 1px 8px;
    border-radius: 10px;
    flex-shrink: 0;
    font-weight: 700;
    font-style: normal;
}

.message.bot .text {
    color: #475569;
}

.private-chat-list {
    font-size: 13px;
}

.private-chat-item {
    padding: 6px 12px;
    margin: 2px 0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
    color: #334155;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.private-chat-item:hover {
    background: #e8edf5;
}

.private-chat-item.active {
    background: #4a9eff;
    color: white;
}

/* ========== CHAT AREA ========== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fafcff;
    min-width: 0;
    width: 100%;
}

/* ========== CHAT HEADER ========== */
.chat-header {
    padding: 8px 12px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 40px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

#currentRoom {
    font-weight: 600;
    font-size: 14px;
    color: #0f172a;
}

.menu-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    color: #334155;
}

.private-indicator {
    color: #4a9eff;
    font-size: 10px;
    font-weight: 400;
    background: rgba(74, 158, 255, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
}

.typing-indicator {
    color: #64748b;
    font-size: 11px;
    font-style: normal;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.message-count {
    font-size: 10px;
    color: #94a3b8;
    flex-shrink: 0;
}

/* ========== MESSAGES ========== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #fafcff;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    color: #94a3b8;
    padding: 40px 16px;
    align-self: center;
    margin: auto;
}

.welcome-message p:first-child {
    font-size: 18px;
    font-weight: 500;
    color: #334155;
}

.welcome-sub {
    font-size: 13px;
    margin-top: 6px;
}

.message {
    padding: 8px 12px;
    border-radius: 14px;
    max-width: 85%;
    word-wrap: break-word;
    animation: fadeIn 0.25s ease;
    position: relative;
}

.message.system {
    align-self: center;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
    padding: 3px 14px;
    max-width: 90%;
    border-radius: 20px;
    text-align: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.own {
    background: linear-gradient(135deg, #4a9eff, #6b5bff);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(74, 158, 255, 0.2);
}

.message.other {
    background: white;
    color: #0f172a;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.message .sender {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 2px;
    letter-spacing: 0.2px;
}

.message.own .sender {
    color: rgba(255,255,255,0.8);
}

.message .time {
    font-size: 9px;
    opacity: 0.5;
    margin-top: 2px;
    display: block;
}

.message.own .time {
    color: rgba(255,255,255,0.7);
}

.message .text {
    font-size: 14px;
    line-height: 1.4;
}

.message .text a {
    color: inherit;
    text-decoration: underline;
}

.message .file-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,0,0,0.05);
    padding: 6px 10px;
    border-radius: 8px;
    margin-top: 4px;
}

.message.own .file-attachment {
    background: rgba(255,255,255,0.15);
}

.message .reactions {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
    margin-top: 3px;
}

.message .reaction {
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 2px;
}

.message .reaction:hover {
    background: #e2e8f0;
}

.message .reaction .count {
    font-size: 10px;
    color: #94a3b8;
}

.message.own .reaction {
    background: rgba(255,255,255,0.2);
}

.message.own .reaction .count {
    color: rgba(255,255,255,0.7);
}

.message .reply-badge {
    font-size: 10px;
    color: #94a3b8;
    margin-bottom: 2px;
    padding: 1px 6px;
    background: rgba(0,0,0,0.05);
    border-radius: 6px;
    display: inline-block;
}

.message.highlight {
    animation: highlightPulse 1s ease;
}

@keyframes highlightPulse {
    0%, 100% { background-color: inherit; }
    50% { background-color: #fef3c7; }
}

.message .message-actions {
    position: absolute;
    top: -14px;
    right: 2px;
    display: none;
    gap: 2px;
    background: white;
    border-radius: 8px;
    padding: 2px 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.message:hover .message-actions {
    display: flex;
}

.message .message-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.15s;
}

.message .message-actions button:hover {
    background: #f1f5f9;
}

.message .message-actions .delete-btn {
    color: #ef4444;
}

.message .message-actions .reply-btn {
    color: #4a9eff;
}

.message .message-actions .react-btn {
    color: #f59e0b;
}

/* ========== INPUT AREA ========== */
.input-area {
    padding: 8px 10px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

.input-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.message-input {
    flex: 1;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 16px !important;
    outline: none;
    min-width: 0;
    background: #f8fafc;
    -webkit-appearance: none;
}

.message-input:focus {
    border-color: #4a9eff;
    box-shadow: 0 0 0 3px rgba(74,158,255,0.1);
    background: white;
}

.message-input::placeholder {
    color: #94a3b8;
    font-size: 14px;
}

.emoji-btn, .file-btn {
    padding: 10px 12px;
    background: #f1f5f9;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-btn:active, .file-btn:active {
    transform: scale(0.95);
    background: #e2e8f0;
}

.send-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, #4a9eff, #6b5bff);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
    min-width: 60px;
}

.send-btn:active {
    transform: scale(0.95);
}

.back-btn {
    padding: 10px 14px;
    background: #64748b;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 44px;
}

.back-btn:active {
    transform: scale(0.95);
    background: #475569;
}

.input-hint {
    font-size: 9px;
    color: #94a3b8;
    margin-top: 4px;
    text-align: right;
}

/* ========== EMOJI PICKER ========== */
.emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 10px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    z-index: 1000;
    width: 240px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}

.emoji-grid span {
    font-size: 26px;
    cursor: pointer;
    text-align: center;
    padding: 4px;
    border-radius: 8px;
    transition: all 0.15s;
}

.emoji-grid span:active {
    background: #f1f5f9;
    transform: scale(1.1);
}

/* ========== REACTION POPUP ========== */
.reaction-popup {
    position: fixed;
    background: white;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    border: 1px solid #e2e8f0;
    z-index: 1001;
}

.reaction-options {
    display: flex;
    gap: 3px;
}

.reaction-options span {
    font-size: 24px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: transform 0.15s;
}

.reaction-options span:active {
    transform: scale(1.3);
    background: #f1f5f9;
}

/* ========== SEARCH MODAL ========== */
.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.search-modal-content {
    background: white;
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.search-modal-content h3 {
    margin-bottom: 10px;
    color: #0f172a;
    font-size: 16px;
}

.search-input {
    padding: 12px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 16px !important;
    outline: none;
    margin-bottom: 10px;
    -webkit-appearance: none;
    background: #f8fafc;
}

.search-input:focus {
    border-color: #4a9eff;
}

.search-results {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    max-height: 300px;
}

.search-result-item {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 4px;
}

.search-result-item:active {
    background: #f1f5f9;
}

.search-result-item .result-room {
    font-size: 10px;
    color: #4a9eff;
    font-weight: 500;
}

.search-result-item .result-text {
    font-size: 14px;
    margin: 2px 0;
}

.search-result-item .result-user {
    font-size: 10px;
    color: #94a3b8;
}

.close-modal-btn {
    padding: 10px 20px;
    background: #64748b;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.2s;
    align-self: flex-end;
    min-height: 44px;
}

.close-modal-btn:active {
    background: #475569;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ========== SIDEBAR OVERLAY ========== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.open {
    display: block;
}

/* ========== MOBILE STYLES ========== */
@media (max-width: 768px) {
    .auth-content {
        padding: 24px;
        margin: 10px;
    }
    
    .auth-logo {
        font-size: 26px;
    }
    
    .header {
        padding: 8px 10px;
        min-height: 44px;
    }
    
    .header h1 {
        font-size: 15px;
    }
    
    .connection-status {
        font-size: 8px !important;
        padding: 1px 5px !important;
    }
    
    .online-count {
        font-size: 10px;
        padding: 2px 8px;
    }
    
    .header-btn, .clear-btn, .logout-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .chat-header {
        padding: 6px 10px;
        min-height: 36px;
    }
    
    #currentRoom {
        font-size: 13px;
    }
    
    .menu-btn {
        font-size: 18px;
    }
    
    .messages {
        padding: 8px 10px;
        gap: 4px;
    }
    
    .message {
        padding: 8px 12px;
        max-width: 88%;
        border-radius: 14px;
    }
    
    .message .text {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .message .sender {
        font-size: 10px;
    }
    
    .message .time {
        font-size: 9px;
    }
    
    .input-area {
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
    
    .input-row {
        gap: 6px;
    }
    
    .message-input {
        padding: 10px 10px;
        font-size: 16px !important;
        border-radius: 10px;
    }
    
    .emoji-btn, .file-btn {
        padding: 8px 10px;
        font-size: 16px;
        min-width: 40px;
        min-height: 40px;
    }
    
    .send-btn {
        padding: 8px 14px;
        font-size: 13px;
        min-width: 54px;
        min-height: 40px;
    }
    
    .back-btn {
        padding: 8px 12px;
        font-size: 11px;
        min-height: 40px;
    }
    
    .input-hint {
        font-size: 8px;
        margin-top: 3px;
    }
    
    .sidebar {
        width: 280px;
        padding: 16px;
    }
    
    .emoji-picker {
        width: 200px;
        padding: 8px;
        bottom: 65px;
        right: 8px;
    }
    
    .emoji-grid span {
        font-size: 22px;
        padding: 3px;
    }
    
    .reaction-options span {
        font-size: 22px;
        padding: 3px 5px;
    }
    
    .search-modal-content {
        padding: 16px;
        margin: 10px;
    }
    
    .search-input {
        font-size: 16px !important;
        padding: 12px 14px;
    }
    
    .welcome-message p:first-child {
        font-size: 17px;
    }
    
    .welcome-sub {
        font-size: 12px;
    }
    
    .private-indicator {
        font-size: 9px;
        padding: 1px 8px;
    }
    
    .typing-indicator {
        font-size: 9px;
    }
    
    .message-count {
        font-size: 9px;
    }
}

/* ========== LANDSCAPE PHONES ========== */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 4px 8px;
        min-height: 32px;
    }
    
    .header h1 {
        font-size: 13px;
    }
    
    .online-count {
        font-size: 8px;
        padding: 1px 6px;
    }
    
    .header-btn, .clear-btn, .logout-btn {
        width: 26px;
        height: 26px;
        font-size: 11px;
    }
    
    .chat-header {
        padding: 4px 8px;
        min-height: 28px;
    }
    
    #currentRoom {
        font-size: 11px;
    }
    
    .messages {
        padding: 4px 8px;
        gap: 2px;
    }
    
    .message {
        padding: 4px 8px;
        max-width: 80%;
    }
    
    .message .text {
        font-size: 12px;
    }
    
    .message .sender {
        font-size: 8px;
    }
    
    .message .time {
        font-size: 7px;
    }
    
    .input-area {
        padding: 4px 6px;
    }
    
    .input-row {
        gap: 4px;
    }
    
    .message-input {
        padding: 6px 8px;
        font-size: 14px !important;
    }
    
    .emoji-btn, .file-btn {
        padding: 4px 6px;
        font-size: 14px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .send-btn {
        padding: 4px 10px;
        font-size: 11px;
        min-width: 44px;
        min-height: 32px;
    }
    
    .back-btn {
        padding: 4px 8px;
        font-size: 10px;
        min-height: 32px;
    }
    
    .input-hint {
        display: none;
    }
    
    .sidebar {
        width: 200px;
        padding: 10px;
    }
}

/* ========== DARK MODE ========== */
html.dark-ui {
    body {
        background: #0f172a;
    }
    
    .auth-content {
        background: #1e293b;
    }
    
    .auth-logo {
        color: #e2e8f0;
    }
    
    .auth-subtitle {
        color: #94a3b8;
    }
    
    .auth-tab {
        color: #94a3b8;
        border-color: #334155;
    }
    
    .auth-tab.active {
        background: #4a9eff;
        color: white;
        border-color: #4a9eff;
    }
    
    .auth-form input {
        background: #2d3748;
        border-color: #334155;
        color: #e2e8f0;
    }
    
    .auth-footer {
        color: #94a3b8;
    }
    
    .container {
        background: #1e293b;
    }
    
    .sidebar {
        background: #1a2332;
        border-right-color: #2d3748;
    }
    
    .chat-area {
        background: #0f172a;
    }
    
    .chat-header {
        background: #1a2332;
        border-bottom-color: #2d3748;
    }
    
    #currentRoom {
        color: #e2e8f0;
    }
    
    .messages {
        background: #0f172a;
    }
    
    .message.other {
        background: #2d3748;
        color: #e2e8f0;
        box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    }
    
    .message .sender {
        color: #94a3b8;
    }
    
    .message .reaction {
        background: #374151;
    }
    
    .message .reaction:hover {
        background: #4b5563;
    }
    
    .input-area {
        background: #1a2332;
        border-top-color: #2d3748;
    }
    
    .message-input {
        background: #2d3748;
        border-color: #4b5563;
        color: #e2e8f0;
    }
    
    .message-input::placeholder {
        color: #94a3b8;
    }
    
    .emoji-btn, .file-btn {
        background: #2d3748;
        border-color: #4b5563;
    }
    
    .emoji-picker {
        background: #1e293b;
        border-color: #2d3748;
    }
    
    .emoji-grid span:hover {
        background: #2d3748;
    }
    
    .search-modal-content {
        background: #1e293b;
    }
    
    .search-modal-content h3 {
        color: #e2e8f0;
    }
    
    .search-input {
        background: #2d3748;
        border-color: #4b5563;
        color: #e2e8f0;
    }
    
    .search-result-item {
        border-bottom-color: #2d3748;
    }
    
    .search-result-item:hover {
        background: #2d3748;
    }
    
    .search-result-item .result-text {
        color: #e2e8f0;
    }
    
    .reaction-popup {
        background: #1e293b;
        border-color: #2d3748;
    }
    
    .reaction-options span:hover {
        background: #2d3748;
    }
    
    .welcome-message p:first-child {
        color: #e2e8f0;
    }
    
    .welcome-message {
        color: #94a3b8;
    }
    
    .input-hint {
        color: #64748b;
    }
    
    .room {
        color: #cbd5e1;
    }
    
    .room:hover {
        background: #2d3748;
    }

    .section-add {
        background: #2d3748;
        color: #e2e8f0;
    }

    .invite-card {
        background: #1e3a5f;
    }

    .invite-copy,
    .member-row {
        color: #e2e8f0;
    }

    .invite-actions button.ghost,
    .member-row button.ghost {
        background: #334155;
        color: #e2e8f0;
    }

    .member-row {
        border-bottom-color: #2d3748;
    }

    .header-chip {
        background: rgba(74, 158, 255, 0.18);
        color: #93c5fd;
    }
    
    .user-item:hover {
        background: #2d3748;
    }
    
    .user-item .user-name {
        color: #e2e8f0;
    }
    
    .private-chat-item {
        color: #cbd5e1;
    }
    
    .private-chat-item:hover {
        background: #2d3748;
    }
    
    .sidebar h3 {
        color: #94a3b8;
    }
    
    hr {
        border-top-color: #2d3748;
    }
    
    .room.active {
        background: #4a9eff;
        color: white;
    }
    
    .private-chat-item.active {
        background: #4a9eff;
        color: white;
    }
    
    .header {
        background: #0f172a;
        border-bottom-color: #4a9eff;
    }
    
    .online-count {
        background: rgba(255,255,255,0.05);
    }
    
    .menu-btn {
        color: #e2e8f0;
    }
}

.header .menu-btn {
    color: #f8fafc;
}

.auth-brand {
    text-align: center;
    margin-bottom: 8px;
}

.auth-mark {
    display: block;
    margin: 0 auto 12px;
    border-radius: 14px;
}

.auth-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin: 10px 0 4px;
}

.auth-btn:disabled,
.auth-btn.busy {
    opacity: 0.7;
    cursor: wait;
}

.room-topic {
    font-size: 12px;
    font-weight: 400;
    color: #64748b;
    flex-basis: 100%;
}

.reply-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: #475569;
    background: #f1f5f9;
    border-left: 3px solid #4a9eff;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.reply-bar[hidden] {
    display: none !important;
}

.reply-bar-close {
    border: none;
    background: none;
    cursor: pointer;
    color: #ef4444;
    font-size: 14px;
}

.day-sep {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    margin: 14px 0 8px;
}

.day-sep::before,
.day-sep::after {
    content: '';
}

.message.compact {
    margin-top: 2px;
}

.message.compact .sender {
    display: none;
}

@media (min-width: 900px) {
    .sidebar {
        display: flex;
        flex-direction: column;
        position: relative;
        top: auto;
        left: auto;
        height: auto;
        width: 260px;
        flex-shrink: 0;
        box-shadow: none;
        z-index: 1;
    }

    .sidebar-overlay,
    .sidebar-close-btn,
    .header .menu-btn {
        display: none !important;
    }
}

.theme-fab {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10050;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #1a2332;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
}

body.app-open .theme-fab {
    display: none;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 11000;
    max-width: min(90vw, 420px);
}

.toast[hidden] {
    display: none !important;
}

.composer-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
}

.char-count {
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.search-hint {
    font-size: 12px;
    color: #94a3b8;
    margin: 0 0 8px;
}

.sidebar-empty {
    font-size: 12px;
    color: #94a3b8;
    padding: 6px 10px;
    line-height: 1.4;
}

textarea.message-input {
    resize: none;
    min-height: 44px;
    max-height: 128px;
    line-height: 1.35;
    font-family: inherit;
}

.input-row {
    align-items: flex-end;
}

.msg-avatar,
.sender-btn {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0;
    text-align: left;
}

.msg-avatar {
    position: absolute;
    left: -36px;
    top: 2px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4a9eff, #6b5bff);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msg-avatar.bot {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    cursor: default;
}

.message.other:not(.compact) {
    margin-left: 40px;
}

.sender-btn {
    font: inherit;
    font-weight: 600;
    color: inherit;
}

.sender-btn:hover {
    text-decoration: underline;
}

html.dark-ui .theme-fab {
    background: #e2e8f0;
    color: #0f172a;
}

html.dark-ui .toast {
    background: #e2e8f0;
    color: #0f172a;
}

html.dark-ui .sidebar-empty,
html.dark-ui .char-count,
html.dark-ui .search-hint {
    color: #94a3b8;
}

html.dark-ui .bot-badge {
    color: #c4b5fd;
    background: #3b2f63;
}

html.dark-ui .message.bot .text {
    color: #cbd5e1;
}

html.dark-ui .reply-bar {
    background: #1e293b;
    color: #cbd5e1;
}

html.dark-ui .auth-label {
    color: #94a3b8;
}

.typing-dots {
    display: inline-flex;
    gap: 3px;
}

.typing-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    animation: typingBounce 1.1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.load-more {
    align-self: center;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    margin: 4px 0 8px;
}

.file-attachment.image-preview {
    padding: 0;
    background: transparent;
    border: none;
    cursor: zoom-in;
}

.file-attachment.image-preview img {
    max-width: 180px;
    border-radius: 8px;
    display: block;
}

.link-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.06);
    color: inherit;
    text-decoration: none;
    font-size: 12px;
}

.link-card-host { font-weight: 600; }
.link-card-url { opacity: 0.75; word-break: break-all; }
.message.own .link-card { background: rgba(255, 255, 255, 0.16); }
.edited-flag { font-style: italic; margin-left: 4px; }

.edit-box textarea {
    width: 100%;
    min-height: 64px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    padding: 8px;
    font: inherit;
}

.edit-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.edit-actions button {
    border: none;
    border-radius: 6px;
    background: #4a9eff;
    color: #fff;
    padding: 4px 10px;
    cursor: pointer;
}

.edit-actions .ghost {
    background: #e2e8f0;
    color: #334155;
}

.message-actions .edit-btn { color: #0f766e; }

.emoji-suggest {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 4px 0;
}

.emoji-suggest-item {
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 13px;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.88);
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.lightbox[hidden] { display: none; }

.lightbox img {
    max-width: min(96vw, 1100px);
    max-height: 90vh;
    border-radius: 12px;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: #0f172a;
    font-size: 24px;
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

html.dark-ui .load-more,
html.dark-ui .emoji-suggest-item,
html.dark-ui .edit-box textarea {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}

