@import url('https://fonts.googleapis.com/css2?family=Sora:wght@100;200;300;400;500;600;700;800&display=swap');

:root {
    --bg: #f1f3f4;
    --surface: #fff;
    --border: #dadce0;
    --text: #202124;
    --muted: #5f6368;
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    /* Base font size - will be overridden by JavaScript based on user setting */
    font-size: 0.9rem; /* Default: medium */
}

:root[data-theme="dark"] {
    --bg: #202124;
    --surface: #303134;
    --border: #5f6368;
    --text: #e8eaed;
    --muted: #9aa0a6;
}

:root[data-theme="dark"] body {
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    background-image: 
        linear-gradient(to right, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    color: var(--text);
    min-height: 100vh;
    padding: 2rem;
}

.app-shell {
    min-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(60, 64, 67, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 4rem);
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text);
    margin: 0;
}

header h1 {
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text);
}

.theme-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--border);
}

:root[data-theme="dark"] .theme-icon {
    background: #5f6368;
    border-color: #5f6368;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background-color: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.status-dot.disconnected {
    background-color: #ef4444;
}

.status-dot.connecting {
    background-color: #fbbf24;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.section {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

.hidden {
    display: none !important;
}

h2 {
    margin-bottom: 1.5rem;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    font-size: 0.95rem;
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #1a73e8;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.button-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

button {
    border: none;
    border-radius: 0.5rem;
    padding: 0.45rem 1.25rem;
    cursor: pointer;
    font-size: 0.95rem;
    font-family: 'Sora', sans-serif;
    color: var(--text);
    background: transparent;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

button.primary {
    background: #a8d5ff;
    color: black;
    font-size: 0.9rem;
    text-transform: uppercase;
    font-weight: 500;
    padding: 0.75rem 1rem;
    min-height: 2.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button.primary:hover {
    background: #8ab4f8;
    transform: translateY(-1px);
}

button.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

button.ghost:hover {
    background: var(--bg);
}

.danger-button {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.danger-button:hover {
    background: #ef4444;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}

.danger-button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.message {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
}

.message.error {
    background: rgba(239, 68, 68, 0.1);
    color: #991b1b;
    border-color: rgba(239, 68, 68, 0.3);
}

.message.success {
    background: rgba(74, 222, 128, 0.1);
    color: #065f46;
    border-color: rgba(74, 222, 128, 0.3);
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    display: flex;
    height: calc(100vh - 4rem - 60px);
    overflow: hidden;
    position: relative;
}

/* Left Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    height: 100%;
    width: 350px;
    min-width: 250px;
    max-width: 600px;
    flex-shrink: 0;
    overflow: hidden;
}


/* Resizable Divider */
.resizer {
    width: 4px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    position: relative;
    transition: background-color 0.2s ease;
}

.resizer:hover {
    background: #1a73e8;
}

.resizer::before {
    content: '';
    position: absolute;
    left: -2px;
    right: -2px;
    top: 0;
    bottom: 0;
    cursor: col-resize;
}

.sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.search-container {
    position: relative;
    padding: 0.75rem 1.5rem 0.5rem 1.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    margin: 0;
    box-sizing: border-box;
}

.search-icon {
    position: absolute;
    left: 2.25rem;
    color: var(--muted);
    pointer-events: none;
    z-index: 1;
}

.search-container input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    color: var(--text);
    outline: none;
    height: 44px;
    line-height: 1.5;
    box-sizing: border-box;
}

.search-container input:focus {
    border-color: #1a73e8;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.add-friend-section {
    padding: 0 1.5rem 0.25rem 1.5rem;
    flex-shrink: 0;
    box-sizing: border-box;
}

.add-friend-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 44px;
    line-height: 1.5;
    box-sizing: border-box;
}

.add-friend-button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(26, 115, 232, 0.2);
}

.add-friend-button:active {
    transform: translateY(0);
}

.add-friend-button svg {
    flex-shrink: 0;
    stroke: #ffffff;
}

.friend-request-section {
    padding: 0.25rem 1.5rem 0.75rem 1.5rem;
    flex-shrink: 0;
    box-sizing: border-box;
}

.friend-request-badge {
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.25rem;
}

.friends-toggle-section {
    padding: 0.25rem 1.5rem;
    flex-shrink: 0;
    box-sizing: border-box;
}

.topics-list-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    min-height: 0;
}

.topics-list-container.hidden {
    display: none;
}

.friends-list-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem;
    min-height: 0;
}

.friends-list-container.hidden {
    display: none;
}

.topic-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.25rem;
    background: transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topic-item:hover {
    background: var(--bg);
}

.topic-item.active {
    background: var(--bg);
    font-weight: 500;
}

.topic-item .topic-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
}

.topic-item .topic-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topic-item .topic-name {
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topic-item .topic-preview {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* User Profile Section (Bottom of Sidebar) */
.user-profile-section {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    gap: 0.5rem;
    flex-shrink: 0;
    margin: 0;
    box-sizing: border-box;
    border-top: none;
}

.settings-button-text {
    padding: 0.5rem 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text);
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    font-weight: 500;
    transition: color 0.2s ease;
    flex: 1;
    text-align: left;
}

.settings-button-text:hover {
    color: #1a73e8;
}

.user-avatar {
    cursor: pointer;
}

.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1rem;
}

.user-avatar-large {
    position: relative;
}

.avatar-placeholder-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 2rem;
}

/* Modal Styles */
.modal {
    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: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.settings-modal-content {
    max-width: 600px;
}

.settings-body {
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-weight: 600;
    font-size: 1.2rem;
    color: var(--text);
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.modal-close:hover {
    background: var(--bg);
}

.modal-body {
    padding: 1.5rem;
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: none;
    overflow-x: auto;
    overflow-y: visible;
}

.settings-tab {
    flex: 1;
    min-width: 0;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.settings-tab:hover {
    background: var(--bg);
}

.settings-tab.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    font-weight: 500;
}

.settings-tab-content {
    display: none;
}

.settings-tab-content.active {
    display: block;
}

.settings-tab-content .form-group {
    margin-bottom: 1.5rem;
}

.settings-tab-content .data-form-group {
    margin-bottom: 1rem;
}

.settings-tab-content .data-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.settings-tab-content .data-form-group > div {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.settings-tab-content select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    cursor: pointer;
}

.settings-tab-content select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.settings-tab-content input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.settings-tab-content input[type="color"] {
    cursor: pointer;
}

.settings-tab-content small {
    display: block;
    margin-top: 0.25rem;
    color: var(--muted);
    font-size: 0.85rem;
}

/* New Chat Modal Styles */
.new-chat-tabs {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.tab-button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    cursor: pointer;
    font-family: 'Sora', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
}

.tab-button:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.tab-button:active {
    transform: translateY(0);
}

.tab-button.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.tab-button.active:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(26, 115, 232, 0.2);
}

.new-chat-tab-content {
    min-height: 200px;
}

.new-chat-tab-content.hidden {
    display: none;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    position: relative;
}

.search-icon-inline {
    position: absolute;
    left: 0.75rem;
    color: var(--muted);
    pointer-events: none;
    z-index: 1;
}

.search-input-wrapper input {
    flex: 1;
    padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.search-input-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.search-input-wrapper button {
    padding: 0.75rem 1.5rem;
    white-space: nowrap;
}

.search-results {
    margin-top: 1.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--surface);
}

.search-result-item:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.search-result-item .result-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.search-result-item .result-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.search-result-item .result-info {
    flex: 1;
    min-width: 0;
}

.search-result-item .result-name {
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.search-result-item .result-id {
    font-size: 0.85rem;
    color: var(--muted);
    word-break: break-all;
}

.search-result-item .result-action {
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.search-result-item .result-action:hover {
    background: var(--primary-hover);
}

.search-result-item .result-action.pending {
    background: var(--muted);
    cursor: not-allowed;
    opacity: 0.7;
}

.search-result-item .result-action.pending:hover {
    background: var(--muted);
}

.search-results .no-results {
    text-align: center;
    padding: 2rem;
    color: var(--muted);
}

.selected-friends-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    min-height: 60px;
}

.no-selected-friends {
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    width: 100%;
    padding: 0.5rem;
}

.selected-friend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--primary);
    color: white;
    border-radius: 1.5rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.selected-friend-item img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
}

.selected-friend-item .remove-friend {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 0.75rem;
    line-height: 1;
    transition: background 0.2s ease;
}

.selected-friend-item .remove-friend:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Right Chat Window */
.chat-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg);
    flex: 1;
    min-width: 300px;
    position: relative;
    overflow: hidden;
}

.chat-window-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.chat-window-header h3 {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
    flex: 1;
}

.chat-title-container {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.chat-title-container h3 {
    flex: 0;
}

.mobile-back-button {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    margin-right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    border-radius: 0.5rem;
    transition: background 0.2s ease;
}

.mobile-back-button:hover {
    background: var(--bg);
}

.mobile-back-button svg {
    width: 20px;
    height: 20px;
}

.group-members-info {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.25rem;
}


.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    overflow-x: hidden;
    position: relative;
    background-attachment: local;
}

.message-item {
    margin-bottom: 0.25rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(32, 33, 36, 0.15);
    transition: box-shadow 0.2s ease;
    position: relative;
    width: fit-content;
    max-width: 70%;
}

.message-item:hover {
    box-shadow: 0 2px 4px rgba(32, 33, 36, 0.2);
}

.message-item:hover .message-actions {
    opacity: 1;
}

.message-item.own {
    background: var(--primary, #1a73e8);
    color: white;
    border-color: var(--primary, #1a73e8);
    margin-left: auto;
    max-width: 70%;
    width: fit-content;
    min-width: auto;
}

.message-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.message-content {
    word-wrap: break-word;
    font-size: var(--message-font-size, 0.9rem);
    line-height: 1.5;
}

/* Message Reactions */
.message-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 1;
}

.message-item.own .message-actions {
    right: auto;
    left: 0.5rem;
}

.message-reaction-btn {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0.125rem 0.25rem;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    outline: none;
}

.message-reaction-btn:hover {
    background: transparent;
    transform: scale(1.1);
    outline: none;
    box-shadow: none;
}

.message-item.own .message-reaction-btn {
    background: transparent;
    border: none;
    color: white;
}

.message-item.own .message-reaction-btn:hover {
    background: transparent;
    outline: none;
    box-shadow: none;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0;
    padding-top: 0.25rem;
    border-top: 1px solid var(--border);
    align-items: baseline;
}

.message-item.own .message-reactions {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.reaction-item {
    display: inline-block;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    border: none !important;
    border-radius: 0 !important;
    font-size: 0.85rem;
    cursor: pointer;
    transition: transform 0.2s ease;
    user-select: none;
    outline: none !important;
    box-shadow: none !important;
    line-height: 1;
    vertical-align: baseline;
}

.message-item.own .reaction-item {
    background: none !important;
    border: none !important;
    color: white;
}

.reaction-item:hover {
    background: none !important;
    border: none !important;
    color: inherit;
    transform: scale(1.1);
    outline: none !important;
    box-shadow: none !important;
}

.reaction-item:focus {
    outline: none !important;
    box-shadow: none !important;
    background: none !important;
    border: none !important;
}

.reaction-item:active {
    background: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.reaction-item * {
    outline: none !important;
    box-shadow: none !important;
}

.reaction-count {
    font-weight: 500;
    font-size: 0.75rem;
    margin-left: 0.125rem;
}

.reaction-picker {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-width: calc(100vw - 16px);
    flex-wrap: wrap;
    width: max-content;
}

.reaction-emoji-btn {
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    padding: 0.25rem;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.reaction-emoji-btn:hover {
    background: var(--bg);
    transform: scale(1.2);
}

.message-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 1.5rem 1rem 0.75rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    align-items: flex-end;
    flex-shrink: 0;
}

.attach-button,
.emoji-button {
    position: absolute;
    left: 0.5rem;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
    z-index: 1;
}

.attach-button {
    left: 0.5rem;
}

.emoji-button {
    left: 2.5rem;
}

.attach-button:hover,
.emoji-button:hover {
    background: var(--bg);
}


.textarea-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: 0;
    width: 320px;
    max-height: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
}

.emoji-picker.hidden {
    display: none;
}

.emoji-picker-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.emoji-categories {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow-x: auto;
}

.emoji-category-btn {
    padding: 0.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.emoji-category-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.emoji-category-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

.emoji-category {
    display: none;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

/* Smaller scrollbar for emoji picker */
.emoji-picker .emoji-category::-webkit-scrollbar {
    width: 4px;
}

.emoji-picker .emoji-category::-webkit-scrollbar-track {
    background: transparent;
}

.emoji-picker .emoji-category::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.emoji-picker .emoji-category::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.emoji-category.active {
    display: flex;
}

.emoji-item {
    font-size: 1.5rem;
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
    user-select: none;
}

.emoji-item:hover {
    background: var(--bg);
    transform: scale(1.2);
}

.emoji-recent-section {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.emoji-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emoji-recent-grid {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.message-input-area input[type="text"],
.message-input-area textarea {
    flex: 1;
    padding: 0.75rem 1rem;
    padding-left: 5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-family: 'Sora', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-width: 0;
    resize: none;
    overflow-y: auto;
    max-height: 120px;
    line-height: 1.5;
    box-sizing: border-box;
}

.message-input-area textarea {
    height: 44px;
    min-height: 44px;
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}

/* Hide scrollbar on message input textarea */
.message-input-area textarea::-webkit-scrollbar {
    display: none;
}

.message-input-area input[type="text"]:focus,
.message-input-area textarea:focus {
    outline: none;
    border-color: var(--primary, #1a73e8);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.1);
}

.message-input-area button.primary {
    padding: 0.75rem 1.5rem;
    background: var(--primary, #1a73e8);
    color: white;
    font-weight: 500;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    white-space: nowrap;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border: 1px solid transparent;
    line-height: 1.5;
}

.message-input-area button.primary:hover {
    background: var(--primary-hover, #1557b0);
}

.log-section {
    padding: 1.5rem 2rem;
    background: var(--bg);
    border-top: 1px solid var(--border);
    max-height: 250px;
    display: flex;
    flex-direction: column;
}

.log-section h3 {
    margin-bottom: 1rem;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
}

.log-container {
    flex: 1;
    overflow-y: auto;
    background: var(--surface);
    padding: 1rem;
    border-radius: 0.75rem;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
}

.log-entry {
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    border-left: 3px solid #1a73e8;
    padding-left: 0.75rem;
    font-size: 0.75rem;
    line-height: 1.4;
}

.log-entry.error {
    border-left-color: #ef4444;
    color: #991b1b;
    background: rgba(239, 68, 68, 0.05);
}

.log-entry.success {
    border-left-color: #4ade80;
    color: #065f46;
    background: rgba(74, 222, 128, 0.05);
}

.log-entry.info {
    border-left-color: #1a73e8;
    color: var(--text);
}

.log-section button {
    align-self: flex-start;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
}

.log-section button:hover {
    background: var(--bg);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Sidebar scrollbar - smaller */
.sidebar ::-webkit-scrollbar {
    width: 2px;
}

.sidebar ::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.sidebar ::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        height: 100vh;
        border-radius: 0;
        max-width: 100%;
        width: 100%;
        border: none;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box;
    }

    header {
        padding: 0.75rem 1rem;
    }

    header h1 {
        font-size: 1.1rem;
    }

    .chat-container {
        position: relative;
        height: calc(100vh - 60px);
        display: flex;
        flex-direction: row;
        padding: 0 !important;
        margin: 0 !important;
        width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .sidebar {
        position: relative;
        width: 30%;
        height: 100%;
        border-right: 1px solid var(--border);
        transition: none;
        flex-shrink: 0;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .sidebar.hidden-mobile {
        display: none;
    }

    .sidebar.full-width-mobile {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        border-right: none !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    .chat-window {
        width: 70%;
        height: 100%;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .chat-window.hidden-mobile {
        display: none !important;
    }

    .chat-window.full-width-mobile {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }
    
    .resizer {
        display: none;
    }

    /* Touch-friendly buttons */
    button, .add-friend-button, .tab-button, .settings-tab {
        min-height: 44px;
        padding: 0.75rem 1rem;
    }

    /* Touch-friendly inputs */
    input[type="text"], input[type="password"], input[type="email"], select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Smaller padding for mobile */
    .search-container {
        padding: 0.5rem 1rem;
    }

    .add-friend-section, .friend-request-section {
        padding: 0.25rem 1rem;
    }

    .messages-container {
        padding: 0.5rem 0.5rem;
    }

    .message-input-area {
        padding: 0.75rem 1rem;
    }

    .chat-window-header {
        padding: 0.75rem 1rem;
    }

    /* Modal improvements */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
    }

    .settings-modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-header {
        padding: 1rem;
    }

    /* Form elements */
    .form-group {
        margin-bottom: 1.25rem;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    /* Topic items */
    .topic-item {
        padding: 0.75rem 1rem;
    }

    .topic-avatar {
        width: 40px;
        height: 40px;
    }

    /* Friend items */
    .friend-item {
        padding: 0.75rem 1rem;
    }

    /* User profile section */
    .user-profile-section {
        padding: 0.5rem 1rem;
    }

    /* Settings tabs */
    .settings-tabs {
        gap: 0.25rem;
        margin-bottom: 1rem;
    }

    .settings-tab {
        padding: 0.75rem 0.75rem;
        font-size: 0.85rem;
    }

    .chat-window-header {
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
    }

    .mobile-back-button {
        display: inline-flex !important;
        margin-right: 0.75rem;
    }
}

@media (max-width: 480px) {
    header {
        padding: 0.5rem 0.75rem;
    }

    header h1 {
        font-size: 1rem;
    }

    .search-container input {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .message-input-area input[type="text"] {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .add-friend-button {
        font-size: 0.85rem;
        padding: 0.625rem 0.875rem;
    }

    .topic-name {
        font-size: 0.9rem;
    }

    .topic-preview {
        font-size: 0.8rem;
    }

    .message-item {
        padding: 0.625rem 0.875rem;
    }

    .message-content {
        font-size: 0.95rem;
    }
}

/* Large screen adjustments (1920px and above) */
@media (min-width: 1920px) {
    .container {
        max-width: 1000px;
    }

    .sidebar {
        width: 280px !important;
        max-width: 280px !important;
        min-width: 280px !important;
    }
}
