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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f0f7fc 0%, #e3ecf7 100%);
    color: #1a3a52;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    gap: 0;
    padding: 0;
}

/* Header Section */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: rgba(232, 243, 252, 0.95);
    border-bottom: 1px solid #c9e4f5;
    box-shadow: 0 2px 10px rgba(95, 179, 232, 0.1);
    flex-wrap: wrap;
    gap: 16px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.8rem;
    color: #2c6fa1;
    margin: 0;
    white-space: nowrap;
}

.dm-init {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 300px;
    max-width: 500px;
}

.dm-init input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #b3d9ff;
    border-radius: 20px;
    font-size: 0.95rem;
    outline: none;
    background: white;
    transition: border-color 0.2s;
}

.dm-init input:focus {
    border-color: #5fb3e8;
}

.dm-init button {
    padding: 10px 20px;
    background: #5fb3e8;
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.dm-init button:hover {
    background: #4a9fd8;
}

.dm-init button:disabled {
    background: #b3d9ff;
    cursor: not-allowed;
}

.user-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #e8f4fc;
    border-radius: 20px;
    font-size: 0.9rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef5350;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: #66bb6a;
    animation: none;
}

.logout-btn {
    padding: 8px 16px;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.logout-btn:hover {
    background: #ee5a52;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.logout-btn:active {
    transform: scale(0.95);
}

/* Quote Widget - Compact and Always Visible */
.quote-widget {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #b3d9ff;
    border-radius: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.quote-display {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#quoteText {
    font-size: 0.9rem;
    color: #1a3a52;
    margin: 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#quoteAuthor {
    font-size: 0.75rem;
    color: #5d7a8f;
    margin: 2px 0 0 0;
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.randomize-btn {
    padding: 8px 16px;
    background: #5fb3e8;
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.randomize-btn:hover {
    background: #4a9fd8;
    transform: scale(1.05);
}

.randomize-btn:active {
    transform: scale(0.95);
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Main Layout: Sidebar + Chat Area */
.main-layout {
    display: flex;
    flex: 1;
    gap: 0;
    overflow: hidden;
    min-height: 0;
}

/* Sidebar with minimized chats */
.sidebar {
    width: 300px;
    background: rgba(232, 243, 252, 0.95);
    border-right: 1px solid #c9e4f5;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-title {
    font-weight: 600;
    font-size: 1rem;
    color: #2c6fa1;
    padding: 8px 12px;
    margin-bottom: 4px;
}

.chat-item {
    padding: 12px;
    background: white;
    border: 1px solid #c9e4f5;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item:hover {
    background: #e8f4fc;
    border-color: #5fb3e8;
    transform: translateX(2px);
}

.chat-item.active {
    background: #5fb3e8;
    color: white;
    border-color: #4a9fd8;
    font-weight: 600;
}

.chat-item-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.chat-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-sidebar {
    padding: 20px;
    text-align: center;
    color: #5d7a8f;
    font-size: 0.9rem;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.chat-area-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #5d7a8f;
    text-align: center;
}

.chat-area-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* Chat Room Content */
.room-header {
    padding: 16px;
    background: linear-gradient(135deg, #5fb3e8 0%, #4a9fd8 100%);
    color: white;
    border-bottom: 2px solid #2c6fa1;
    flex-shrink: 0;
}

.room-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.room-status {
    font-size: 0.85rem;
    opacity: 0.9;
}

/* Messages Container */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.message {
    padding: 10px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    font-size: 0.95rem;
    animation: slideIn 0.3s ease-out;
    max-width: 70%;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    background: #d4e8f8;
    color: #1a3a52;
    border-left: 3px solid #5fb3e8;
}

.message.received {
    align-self: flex-start;
    background: #e8f4fc;
    color: #1a3a52;
    border-left: 3px solid #2c6fa1;
}

.message.system {
    align-self: center;
    background: #f5f5f5;
    color: #666;
    font-size: 0.85rem;
    font-style: italic;
    max-width: 100%;
}

.message.error {
    align-self: flex-start;
    background: #ffebee;
    color: #c62828;
    border-left: 3px solid #ef5350;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 2px;
}

/* Input Section */
.input-section {
    padding: 12px;
    border-top: 1px solid #c9e4f5;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: white;
}

.input-section textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #c9e4f5;
    border-radius: 8px;
    background: #f5f9fd;
    color: #1a3a52;
    font-family: inherit;
    font-size: 0.95rem;
    resize: none;
    min-height: 40px;
    max-height: 60px;
    transition: border-color 0.2s;
}

.input-section textarea:focus {
    outline: none;
    border-color: #5fb3e8;
    background: white;
}

.input-section button {
    padding: 8px 16px;
    background: #5fb3e8;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s;
}

.input-section button:hover {
    background: #4a9fd8;
}

.input-section button:active {
    transform: scale(0.98);
}

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

.messages::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: #c9e4f5;
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #5fb3e8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 120px;
        border-right: none;
        border-bottom: 1px solid #c9e4f5;
        flex-direction: row;
        overflow-x: auto;
    }

    .sidebar-title {
        display: none;
    }

    .message {
        max-width: 90%;
    }

    .dm-init {
        max-width: 100%;
    }
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Debug Panel (development only) */
.debug-panel {
    display: none;
    position: fixed;
    bottom: 16px;
    right: 16px;
    background: rgba(0, 0, 0, 0.9);
    color: #0f0;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-family: monospace;
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
}

.debug-panel.show {
    display: block;
}

/* GIF Modal */
.gif-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 3000;
    animation: fadeIn 0.3s ease;
}

.gif-modal.show {
    display: flex;
}

.gif-modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.gif-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #c9e4f5;
}

.gif-modal-header h3 {
    margin: 0;
    color: #2c6fa1;
    font-size: 1.1rem;
}

.gif-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gif-modal-close:hover {
    color: #000;
}

.gif-modal-body {
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-height: 400px;
}

.gif-search-input {
    padding: 12px;
    border: 1px solid #b3d9ff;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.gif-search-input:focus {
    border-color: #5fb3e8;
    box-shadow: 0 0 0 3px rgba(95, 179, 232, 0.1);
}

.gif-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

.gif-item {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.gif-item:hover {
    border-color: #5fb3e8;
    transform: scale(1.05);
}

.gif-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
}

.gif-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    color: #5d7a8f;
    padding: 40px;
    margin: auto;
}

.gif-loading {
    grid-column: 1 / -1;
    text-align: center;
    color: #5fb3e8;
    padding: 20px;
}

.gif-btn {
    padding: 8px 16px;
    background: #5fb3e8;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.gif-btn:hover {
    background: #4a9fd8;
}

.gif-btn:active {
    transform: scale(0.95);
}