/* Chat Page Specific Styles */

/* Chat Header Section */
.chat-header-section {
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    padding: 15px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Header Styles */
.chat-header-section .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.chat-header-section .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-section .logo {
    cursor: pointer;
    color: #00cfc8;
    font-weight: bold;
}

.chat-header-section .hamburger {
    display: none;
    cursor: pointer;
    font-size: 1.5em;
    color: #fff;
}

.chat-header-section .menu {
    display: flex;
    align-items: center;
    gap: 20px;
}

.chat-header-section .menu-item {
    color: #fff;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.chat-header-section .menu-item:hover {
    background-color: #333;
}

/* Mobile Menu Styles */
@media (max-width: 768px) {
    .chat-header-section .hamburger {
        display: block;
        z-index: 1001;
        position: relative;
    }
    
    .chat-header-section .menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100vh;
        background: #1a1a1a;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 30px;
        transition: left 0.3s ease;
        z-index: 1000;
    }
    
    .chat-header-section .menu.show {
        left: 0;
    }
    
    .chat-header-section .menu-item {
        font-size: 1.2em;
        padding: 15px 25px;
        color: #fff !important;
    }
}

/* Chat Container */
.chat-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    margin-top: 0; /* No margin needed with sticky header */
    height: calc(100vh - 80px); /* Adjust height to account for header only */
    display: flex;
    flex-direction: column;
    background: #0a0a0a;
    position: relative;
    z-index: 1; /* Ensure it's below the connection status */
}

/* Chat Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid #333;
    margin-bottom: 20px;
}

.chat-header h1 {
    color: #00cfc8;
    font-size: 2em;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.online-users {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #888;
    font-size: 0.9em;
}

.online-indicator {
    width: 8px;
    height: 8px;
    background: #00cfc8;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

/* Chat Main Layout */
.chat-main {
    display: flex;
    flex: 1;
    gap: 20px;
    min-height: 0;
}

/* Sidebar */
.chat-sidebar {
    width: 250px;
    background: #1a1a1a;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #333;
    overflow-y: auto;
}

.sidebar-section {
    margin-bottom: 30px;
}

.sidebar-section h3 {
    color: #00cfc8;
    font-size: 1.1em;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.users-list {
    max-height: 200px;
    overflow-y: auto;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #333;
    color: #fff;
}

.user-item:last-child {
    border-bottom: none;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #00cfc8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    color: #000;
}

.user-status {
    width: 6px;
    height: 6px;
    background: #00cfc8;
    border-radius: 50%;
    margin-left: auto;
}

.chat-rules {
    color: #888;
    font-size: 0.9em;
    line-height: 1.6;
}

.chat-rules p {
    margin: 8px 0;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    background: #1a1a1a;
    border-radius: 12px;
    border: 1px solid #333;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome-content {
    color: #888;
}

.welcome-content i {
    font-size: 3em;
    color: #00cfc8;
    margin-bottom: 20px;
}

.welcome-content h2 {
    color: #fff;
    margin-bottom: 10px;
}

/* Message Styles */
.message {
    margin-bottom: 15px;
    display: flex;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #00cfc8 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000 !important;
    font-weight: bold;
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}

.message-username {
    color: #00cfc8 !important;
    font-weight: 600;
    font-size: 0.9em;
}

.message-time {
    color: #666;
    font-size: 0.8em;
}

.message-text {
    color: #fff !important;
    line-height: 1.4;
    word-wrap: break-word;
    background: none !important;
    background-color: transparent !important;
    padding: 5px 0 !important;
    border-radius: 0 !important;
    margin-top: 5px !important;
    display: block !important;
    max-width: 100% !important;
}

/* Force remove all message backgrounds */
.message-content,
.message-content *,
.message-text,
.message-text * {
    background: none !important;
    background-color: transparent !important;
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 5px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message:hover .message-actions {
    opacity: 1;
}

.edit-btn, .delete-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    transition: all 0.2s ease;
}

.edit-btn:hover {
    color: #00cfc8;
    background: rgba(0, 207, 200, 0.1);
}

.delete-btn:hover {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

/* Edit Message Input */
.edit-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #00cfc8;
    border-radius: 6px;
    background: #2a2a2a;
    color: #fff;
    font-size: 0.9em;
    outline: none;
    margin-top: 5px;
}

.edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.save-btn, .cancel-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    transition: all 0.2s ease;
}

.save-btn {
    background: #00cfc8;
    color: #000;
}

.save-btn:hover {
    background: #00b2a8;
}

.cancel-btn {
    background: #555;
    color: #fff;
}

.cancel-btn:hover {
    background: #666;
}

/* Edited Message Indicator */
.edited-indicator {
    color: #888;
    font-size: 0.75em;
    font-style: italic;
    margin-left: 5px;
}

/* Admin Controls */
.admin-delete-btn {
    background: none;
    border: none;
    color: #ff6b6b;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    transition: all 0.2s ease;
    margin-left: 5px;
    display: inline-block !important; /* Force show for admins */
}

.admin-delete-btn:hover {
    color: #ff4444;
    background: rgba(255, 107, 107, 0.1);
}

/* Clear All Button */
.clear-all-btn {
    background: #ff6b6b;
    color: #fff;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    transition: all 0.2s ease;
    margin-right: 15px;
}

.clear-all-btn:hover {
    background: #ff4444;
    transform: translateY(-1px);
}

.clear-all-btn i {
    margin-right: 5px;
}

/* Own Messages */
.message.own {
    flex-direction: row-reverse;
}

.message.own .message-content {
    text-align: right;
}

.message.own .message-avatar {
    background: #333 !important;
    color: #fff !important;
}

.message.own .message-username {
    color: #888 !important;
}

.message.own .message-text {
    background: none !important;
    color: #fff !important;
}

/* Chat Input */
.chat-input-container {
    margin-top: 20px;
    position: relative;
}

.rate-limit-info {
    text-align: center;
    margin-top: 8px;
    color: #666;
    font-size: 0.8em;
}

.typing-indicator {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    padding: 10px;
    background: rgba(0, 207, 200, 0.1);
    border-radius: 8px 8px 0 0;
    color: #00cfc8;
    font-size: 0.9em;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.typing-indicator.show {
    opacity: 1;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.3s ease;
}

.input-wrapper:focus-within {
    border-color: #00cfc8;
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    color: #fff;
    font-size: 1em;
    outline: none;
    padding: 8px 0;
}

#messageInput::placeholder {
    color: #666;
}

.send-btn {
    background: #00cfc8;
    border: none;
    border-radius: 8px;
    color: #000;
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    background: #00b0a5;
}

.send-btn:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        padding: 10px;
        height: calc(100vh - 60px);
    }
    
    .chat-main {
        flex-direction: column;
    }
    
    .chat-sidebar {
        width: 100%;
        order: 2;
        max-height: 200px;
    }
    
    .chat-messages {
        order: 1;
        min-height: 300px;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .chat-header h1 {
        font-size: 1.5em;
    }
}

@media (max-width: 480px) {
    .chat-container {
        padding: 5px;
    }
    
    .chat-header h1 {
        font-size: 1.3em;
    }
    
    .message {
        gap: 8px;
    }
    
    .message-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.8em;
    }
    
    .input-wrapper {
        padding: 8px;
    }
    
    .send-btn {
        padding: 8px 12px;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar,
.users-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-sidebar::-webkit-scrollbar-track,
.users-list::-webkit-scrollbar-track {
    background: #333;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb,
.users-list::-webkit-scrollbar-thumb {
    background: #00cfc8;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-sidebar::-webkit-scrollbar-thumb:hover,
.users-list::-webkit-scrollbar-thumb:hover {
    background: #00b0a5;
}

/* Loading Animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #333;
    border-radius: 50%;
    border-top-color: #00cfc8;
    animation: spin 1s ease-in-out infinite;
}

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

/* Connection Status */
.connection-status {
    position: fixed;
    top: 90px; /* Position below the header */
    right: 20px; /* Move to top right corner */
    padding: 8px 12px;
    border-radius: 6px;
    color: white;
    font-size: 0.8em;
    z-index: 999; /* Lower than header */
    transition: all 0.3s ease;
    max-width: 200px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.connection-status.connected {
    background: #00cfc8;
    color: #000;
}

.connection-status.disconnected {
    background: #ff6b6b;
}

.connection-status.connecting {
    background: #ffa500;
}

/* Large Tablets and Small Desktops */
@media (max-width: 1024px) {
    .chat-container {
        padding: 15px;
        height: calc(100vh - 75px);
    }
    
    .chat-main {
        gap: 20px;
    }
    
    .online-users-sidebar {
        width: 250px;
    }
    
    .chat-messages {
        height: 400px;
    }
}

/* Tablets */
@media (max-width: 768px) {
    /* Chat Container */
    .chat-container {
        padding: 10px;
        margin-top: 0;
        height: calc(100vh - 70px);
    }
    
    /* Chat Header */
    .chat-header {
        flex-direction: column;
        gap: 10px;
        padding: 15px 0;
        text-align: center;
    }
    
    .chat-header h1 {
        font-size: 1.5em;
    }
    
    /* Chat Main Layout */
    .chat-main {
        flex-direction: column;
        gap: 15px;
    }
    
    /* Chat Messages */
    .chat-messages {
        height: 50vh;
        min-height: 300px;
        max-height: 50vh;
        overflow-y: auto;
    }
    
    /* Message Styling */
    .message {
        max-width: 85%;
        margin: 8px 0;
    }
    
    .message-content {
        padding: 8px 12px;
        font-size: 0.9em;
    }
    
    .message-time {
        font-size: 0.7em;
    }
    
    /* Online Users Sidebar */
    .online-users-sidebar {
        width: 100%;
        height: auto;
        max-height: 120px;
        order: 2;
        overflow-y: auto;
    }
    
    .online-users-sidebar h3 {
        font-size: 1em;
        padding: 10px;
    }
    
    .user-item {
        padding: 6px 10px;
        font-size: 0.8em;
    }
    
    /* Chat Input */
    .chat-input-container {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }
    
    .chat-input {
        width: 100%;
        padding: 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .send-button {
        width: 100%;
        padding: 12px;
        font-size: 1em;
    }
    
           /* Connection Status */
           .connection-status {
               top: 80px; /* Position below mobile header */
               right: 10px;
               left: auto;
               transform: none;
               text-align: center;
               font-size: 0.75em;
               padding: 6px 10px;
               max-width: 150px;
           }
    
    /* Rate Limit Info */
    .rate-limit-info {
        font-size: 0.8em;
        padding: 8px 12px;
        margin: 10px;
    }
    
    /* Auth Modal */
    .auth-modal {
        padding: 20px;
    }
    
    .auth-box {
        width: 95%;
        max-width: 400px;
        padding: 20px;
    }
    
    .auth-box h2 {
        font-size: 1.5em;
    }
    
    .auth-box input {
        padding: 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .auth-box button {
        padding: 12px;
        font-size: 1em;
    }
}

/* Medium Mobile Devices */
@media (max-width: 600px) {
    .chat-container {
        padding: 8px;
        height: calc(100vh - 65px);
    }
    
    .chat-header h1 {
        font-size: 1.4em;
    }
    
    .chat-messages {
        height: 300px;
        min-height: 300px;
    }
    
    .message {
        max-width: 88%;
    }
    
    .message-content {
        padding: 7px 11px;
        font-size: 0.88em;
    }
    
    .online-users-sidebar {
        max-height: 130px;
    }
    
    .chat-input-container {
        padding: 12px;
    }
    
           .connection-status {
               top: 75px;
               right: 10px;
               left: auto;
               font-size: 0.75em;
               padding: 7px 11px;
               max-width: 140px;
           }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    .chat-container {
        padding: 5px;
        margin-top: 0;
        height: calc(100vh - 60px);
        overflow: hidden;
    }
    
    .chat-header {
        padding: 8px 0;
        margin-bottom: 8px;
    }
    
    .chat-header h1 {
        font-size: 1.2em;
        margin: 0;
    }
    
    .chat-main {
        height: calc(100% - 100px);
        gap: 8px;
    }
    
    .chat-messages {
        height: 45vh;
        min-height: 200px;
        max-height: 45vh;
        overflow-y: auto;
        padding: 8px;
    }
    
    .message {
        max-width: 92%;
        margin: 4px 0;
    }
    
    .message-content {
        padding: 0;
        font-size: 0.85em;
    }
    
    .message-text {
        padding: 2px 0 !important;
        font-size: 0.85em;
    }
    
    .online-users-sidebar {
        max-height: 100px;
        padding: 8px;
    }
    
    .online-users-sidebar h3 {
        font-size: 0.9em;
        margin: 0 0 5px 0;
        padding: 3px 0;
    }
    
    .chat-input-container {
        padding: 8px;
        margin-top: 8px;
    }
    
    .chat-input {
        padding: 10px;
        font-size: 16px;
    }
    
    .send-button {
        padding: 10px;
        font-size: 0.9em;
    }
    
    .connection-status {
        top: 60px;
        right: 8px;
        left: auto;
        font-size: 0.65em;
        padding: 4px 8px;
        max-width: 100px;
    }
}

/* Extra Small Mobile Devices */
@media (max-width: 360px) {
    .chat-container {
        padding: 3px;
        height: calc(100vh - 55px);
    }
    
    .chat-header h1 {
        font-size: 1.2em;
    }
    
    .chat-messages {
        height: 40vh;
        min-height: 180px;
        max-height: 40vh;
        overflow-y: auto;
        padding: 6px;
    }
    
    .message {
        max-width: 92%;
    }
    
    .message-content {
        padding: 0;
        font-size: 0.8em;
    }
    
    .message-text {
        padding: 1px 0 !important;
        font-size: 0.8em;
    }
    
    .online-users-sidebar {
        max-height: 100px;
    }
    
    .chat-input-container {
        padding: 8px;
    }
    
           .connection-status {
               top: 65px;
               right: 10px;
               left: auto;
               font-size: 0.65em;
               padding: 5px 8px;
               max-width: 120px;
           }
    
    .auth-box {
        width: 98%;
        padding: 15px;
    }
}

/* Landscape Mobile - General */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-container {
        margin-top: 0;
        height: calc(100vh - 50px);
    }
    
    .chat-header {
        padding: 10px 0;
    }
    
    .chat-header h1 {
        font-size: 1.2em;
    }
    
    .chat-messages {
        height: 180px;
        min-height: 180px;
    }
    
    .online-users-sidebar {
        max-height: 80px;
        order: 2;
    }
    
    .chat-input-container {
        padding: 8px 15px;
    }
    
           .connection-status {
               top: 60px;
               right: 10px;
               left: auto;
               font-size: 0.7em;
               padding: 5px 10px;
               max-width: 120px;
           }
}

/* Landscape Mobile - Small */
@media (max-width: 480px) and (orientation: landscape) {
    .chat-container {
        height: calc(100vh - 45px);
    }
    
    .chat-messages {
        height: 150px;
        min-height: 150px;
    }
    
    .online-users-sidebar {
        max-height: 60px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .message-content {
        padding: 4px 8px;
        font-size: 0.8em;
    }
}

/* Large Desktop Screens */
@media (min-width: 1440px) {
    .chat-container {
        max-width: 1400px;
        padding: 30px;
    }
    
    .chat-messages {
        height: 500px;
    }
    
    .online-users-sidebar {
        width: 300px;
    }
    
    .message {
        max-width: 70%;
    }
    
    .message-content {
        padding: 12px 16px;
        font-size: 1em;
    }
}

/* Ultra-wide Screens */
@media (min-width: 1920px) {
    .chat-container {
        max-width: 1600px;
        padding: 40px;
    }
    
    .chat-messages {
        height: 600px;
    }
    
    .online-users-sidebar {
        width: 350px;
    }
    
    .message {
        max-width: 65%;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .message {
        margin: 10px 0;
    }
    
    .message-content {
        padding: 10px 14px;
    }
    
    .chat-input {
        padding: 14px;
        font-size: 16px;
    }
    
    .send-button {
        padding: 14px 20px;
        min-height: 48px;
    }
    
    .menu-item {
        padding: 12px 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    .hamburger {
        padding: 12px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .chat-header h1 {
        font-weight: 600;
    }
    
    .message-content {
        font-weight: 500;
    }
    
    .connection-status {
        font-weight: 500;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .message {
        animation: none;
    }
    
    .online-indicator {
        animation: none;
    }
    
    .connection-status {
        transition: none;
    }
    
    .menu {
        transition: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chat-container {
        background: #0a0a0a;
    }
    
    .chat-header-section {
        background: #1a1a1a;
        border-bottom-color: #333;
    }
    
    .message-content {
        background: none;
        color: #fff;
    }
    
    .message.own .message-content {
        background: none;
        color: #fff;
    }
}
