*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg: #111b21;
    --panel: #202c33;
    --sidebar: #111b21;
    --accent: #00a884;
    --accent-hover: #06cf9c;
    --incoming: #202c33;
    --outgoing: #005c4b;
    --text: #e9edef;
    --muted: #8696a0;
    --border: #2a3942;
    --badge: #25d366;
    --danger: #ea4335;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html, body {
    margin: 0;
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

.hidden { display: none !important; }

/* Login */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    background: var(--panel);
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-card h1 {
    margin: 0;
    font-size: 1.5rem;
}

.login-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.login-card input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
}

.login-card button {
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.login-card button:hover {
    background: var(--accent-hover);
}

.error {
    color: var(--danger);
    font-size: 0.85rem;
    margin: 0;
}

/* App layout */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 360px;
    min-width: 280px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--panel);
}

.sidebar-header h1 {
    margin: 0;
    font-size: 1.15rem;
}

.logout {
    color: var(--muted);
    text-decoration: none;
    font-size: 1.25rem;
    padding: 0.25rem 0.5rem;
}

.logout:hover {
    color: var(--text);
}

.search-wrap {
    padding: 0.5rem 0.75rem;
}

.search-wrap input {
    width: 100%;
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    font-size: 0.9rem;
}

.user-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.no-users {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
}

.user-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.user-item:hover,
.user-item.active {
    background: var(--panel);
}

.user-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-name {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-time {
    font-size: 0.75rem;
    color: var(--muted);
}

.badge {
    background: var(--badge);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.35rem;
}

.user-preview {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.2rem;
}

/* Chat panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0b141a;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23182229' fill-opacity='0.4'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

.chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-header {
    padding: 0.85rem 1.25rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.chat-header h2 {
    margin: 0;
    font-size: 1rem;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--muted);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 4%;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.message {
    display: flex;
    max-width: 75%;
}

.message.incoming {
    align-self: flex-start;
}

.message.outgoing {
    align-self: flex-end;
}

.bubble {
    padding: 0.45rem 0.65rem 0.35rem;
    border-radius: 8px;
    position: relative;
    word-break: break-word;
}

.incoming .bubble {
    background: var(--incoming);
    border-top-left-radius: 0;
}

.outgoing .bubble {
    background: var(--outgoing);
    border-top-right-radius: 0;
}

.bubble-text {
    font-size: 0.92rem;
    line-height: 1.4;
}

.bubble-caption {
    font-size: 0.85rem;
    margin-top: 0.35rem;
    opacity: 0.9;
}

.bubble-media img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 6px;
    display: block;
}

.bubble-media {
    font-size: 0.85rem;
    color: var(--muted);
}

.msg-time {
    display: block;
    text-align: right;
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.reply-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--panel);
    border-top: 1px solid var(--border);
    align-items: flex-end;
}

.reply-form textarea {
    flex: 1;
    resize: none;
    border: none;
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    max-height: 120px;
}

.reply-form button {
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    padding: 0.65rem 1.25rem;
    cursor: pointer;
    white-space: nowrap;
}

.reply-form button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.reply-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    .app.chat-open .sidebar {
        display: none;
    }

    .message {
        max-width: 90%;
    }
}
