:root {
    --primary-color: #5865f2;
    --primary-light: #7289da;
    --surface: #2f3136;
    --surface-secondary: #36393f;
    --surface-dark: #202225;
    --text-primary: #dbdee1;
    --text-secondary: #949ba4;
    --border: #202225;
    --success: #57f287;
    --danger: #ed4245;
    --warning: #faa61a;
    --link-color: #00b0f4;
    --message-bg: #36393f;
    --reply-border: #5865f2;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: var(--surface-dark);
    color: var(--text-primary);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    letter-spacing: 0.3px;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    background: var(--surface-dark);
}

.sidebar {
    width: 260px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.3);
}

.sidebar-header {
    padding: 16px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.sidebar-header h1, .mobile-title {
    color: var(--primary-color);
}

.sidebar-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    transform: scale(1.08);
}

.search-container {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 13px;
    min-height: 36px;
    transition: all 0.2s ease;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-input:focus {
    outline: none;
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(88, 101, 242, 0.4);
    box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.1);
}

.chats-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
}

.section-title {
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 8px;
}

.chats-list {
    display: flex;
    flex-direction: column;
}

.chat-item {
    display: flex;
    padding: 8px 10px;
    margin: 2px 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-radius: 8px;
    border-left: 3px solid transparent;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.chat-item.active {
    background: var(--primary-color);
    border-radius: 8px;
    border-left: none;
    box-shadow: 0 2px 8px rgba(88, 101, 242, 0.3);
}

.chat-item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #6d7bdb);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.chat-item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    gap: 3px;
}

.chat-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

.chat-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    margin-top: auto;
    flex-shrink: 0;
}

.user-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.user-footer:hover {
    background: rgba(255, 255, 255, 0.06);
}

.user-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
textarea,
select {
    font-family: inherit;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-dark);
}

.empty-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    font-size: 18px;
    flex-direction: column;
    gap: 12px;
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-secondary);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.chat-header-title h2 {
    font-size: 16px;
    font-weight: 600;
}

.header-btn, .create-btn {
    background: linear-gradient(180deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 80%, black 20%));
}

.chat-header-buttons {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.messages-container::-webkit-scrollbar {
    width: 8px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.message {
    display: flex;
    gap: 12px;
    margin-bottom: 3px;
    align-items: flex-end;
}

.message-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.message-author {
    font-weight: 600;
    color: var(--primary-light);
    font-size: 14px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    cursor: help;
}

.message-text {
    background: var(--message-bg);
    padding: 8px 12px;
    border-radius: 12px;
    word-wrap: break-word;
    line-height: 1.45;
    font-size: 15px;
    max-width: 55%;
}

.message-image {
    max-width: 300px;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 4px;
    transition: transform 0.2s ease;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--message-bg);
    padding: 10px 12px;
    border-radius: 12px;
    margin-top: 4px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.message-file span {
    font-size: 18px;
    min-width: 20px;
}

.message-file audio {
    flex: 1;
    height: 24px;
}

.message-file a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.message-file a:hover {
    text-decoration: underline;
}

.input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    background: var(--message-bg);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    transition: all 0.2s ease;
}

.message-input:focus {
    outline: none;
    border-color: rgba(88, 101, 242, 0.4);
    background: var(--message-bg);
    box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.1);
}

.input-buttons {
    display: flex;
    gap: 8px;
}

.attach-btn,
.send-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attach-btn:hover,
.send-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
}

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 1200;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mobile-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 6px;
    transition: background 0.2s ease;
    cursor: pointer;
}

.mobile-menu-btn:active {
    background: rgba(255, 255, 255, 0.08);
}

.mobile-title {
    font-weight: 600;
    font-size: 16px;
}

@media (max-width: 720px) {
    .mobile-header { display: flex; }
    .app-container { flex-direction: column; height: calc(100vh - 56px); margin-top: 56px; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        right: 0;
        height: 100vh;
        width: 100%;
        max-width: 100%;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1300;
        border-right: none;
        background: rgba(15,17,20,0.98);
        backdrop-filter: blur(6px);
    }
    .sidebar { display: flex; flex-direction: column; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; touch-action: none; }
    .chat-view { margin-left: 0; width: 100%; }
    .chat-header { padding: 12px; }
    .messages-container { padding: 12px; }
    .header-btn { padding: 8px; min-height: 36px; }
    .chat-item { padding: 10px; }
    .chat-item-avatar { width: 36px; height: 36px; }
    .attach-btn, .send-btn { padding: 10px; min-width: 44px; }
    .message-image { max-width: 100%; }
}

@media (min-width: 721px) {
    body.sidebar-open .sidebar { transform: none; }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 10px;
    overflow-y: auto;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.2s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 15px;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.search-results {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.create-btn {
    width: 100%;
    padding: 10px;
    margin-top: 15px;
    background: var(--primary-color);
    border: none;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 40px;
    font-size: 14px;
}

.create-btn:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(88, 101, 242, 0.3);
}

.settings-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.settings-section h3 {
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
}

.color-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 10px;
}

.color-option {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-wheel-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-wheel-btn i { 
    font-size: 14px; 
}

.color-wheel-btn:hover { 
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.color-option:hover {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.color-option.active {
    border-color: white;
    box-shadow: 0 0 12px rgba(88, 101, 242, 0.5);
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: 100vh;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-y: auto;
    }

    .sidebar-header {
        padding: 12px 15px;
        flex-shrink: 0;
    }

    .sidebar-header h1 {
        font-size: 16px;
        font-weight: 700;
    }

    .sidebar-buttons {
        gap: 6px;
    }

    .sidebar-btn {
        font-size: 16px;
        padding: 6px;
        min-width: 36px;
        min-height: 36px;
    }

    .search-container {
        padding: 8px 10px;
        flex-shrink: 0;
    }

    .search-input {
        font-size: 12px;
        min-height: 32px;
        padding: 8px 12px;
    }

    .section-title {
        padding: 10px 16px;
        font-size: 10px;
        margin-top: 6px;
    }

    .chats-container {
        max-height: calc(35vh - 80px);
        overflow-y: auto;
    }

    .chat-item {
        padding: 8px;
        margin: 2px 6px;
    }

    .chat-view {
        height: 65vh;
        min-height: 65vh;
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        padding: 10px 12px;
        flex-shrink: 0;
    }

    .chat-header-title h2 {
        font-size: 15px;
    }

    .header-btn {
        padding: 6px 10px;
        font-size: 12px;
        min-height: 32px;
    }

    .messages-container {
        padding: 10px 8px;
        gap: 3px;
        flex: 1;
        overflow-y: auto;
    }

    .message {
        gap: 8px;
    }

    .chat-item-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
        flex-shrink: 0;
    }

    .message-text {
        padding: 8px 12px;
        font-size: 13px;
        word-wrap: break-word;
        max-width: 80%;
    }

    .message-author {
        font-size: 13px;
    }

    .message-time {
        font-size: 10px;
    }

    .message-file,
    .message-image {
        max-width: 100%;
    }

    .input-area {
        padding: 10px;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    .input-group {
        gap: 8px;
        align-items: flex-end;
    }

    .message-input {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
        flex: 1;
        border-radius: 20px;
    }

    .attach-btn,
    .send-btn {
        padding: 8px 12px;
        font-size: 12px;
        flex-shrink: 0;
        white-space: nowrap;
        border-radius: 20px;
        min-height: 36px;
    }

    .modal-content {
        width: 95%;
        max-height: 85vh;
        padding: 15px;
        border-radius: 12px;
    }

    .modal-header {
        margin-bottom: 15px;
        padding-bottom: 12px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .search-results {
        max-height: 250px;
        border-radius: 8px;
    }

    .settings-section {
        margin-bottom: 15px;
        padding-bottom: 15px;
        z-index: 9999;
    }

    .settings-section h3 {
        font-size: 15px;
    }

    .color-picker {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
        gap: 8px;
    }

    .color-option {
        width: 40px;
        height: 40px;
        border: 2px solid transparent;
    }

    .sidebar-footer {
        padding: 10px;
        border-top: 1px solid var(--border);
        flex-shrink: 0;
    }

    .user-footer {
        padding: 6px 8px;
        gap: 10px;
    }

    .user-name {
        font-size: 13px;
    }
}

