* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    font-size: 14px;
    color: #222;
    background: #f5f5f5;
}

button {
    font: inherit;
    cursor: pointer;
    background: #fff;
    border: 1px solid #c0c0c0;
    padding: 6px 14px;
    color: #222;
}

button:hover {
    background: #ededed;
}

button:active {
    background: #e0e0e0;
}

input[type="text"], input[type="password"] {
    font: inherit;
    background: #fff;
    border: 1px solid #c0c0c0;
    padding: 6px 10px;
    color: #222;
    outline: none;
}

input:focus {
    border-color: #888;
}

.hidden {
    display: none !important;
}

.error {
    color: #b00020;
    font-size: 13px;
    margin-top: 4px;
    min-height: 1em;
}

/* ----- Login screen ----- */

.login-screen {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 320px;
    background: #fff;
    border: 1px solid #e0e0e0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-card h1 {
    font-size: 18px;
    margin: 0 0 8px 0;
    font-weight: 600;
}

.login-card label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.login-card label span {
    font-size: 12px;
    color: #555;
}

.login-card button {
    margin-top: 8px;
}

/* ----- Main screen ----- */

.main-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.header {
    flex: 0 0 auto;
    height: 52px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 12px;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-left #account-input {
    width: 200px;
}

.login-name {
    color: #555;
    font-size: 13px;
}

.content {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

/* ----- Sidebar ----- */

.sidebar {
    flex: 0 0 320px;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-title {
    flex: 0 0 auto;
    height: 44px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
    color: #444;
    font-weight: 600;
}

.dialogs-list {
    flex: 1 1 auto;
    overflow-y: auto;
}

.dialog-item {
    padding: 10px 14px;
    border-bottom: 1px solid #ededed;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dialog-item:hover {
    background: #fafafa;
}

.dialog-item.last-in {
    background: #ececec;
}

.dialog-item.last-in:hover {
    background: #e4e4e4;
}

.dialog-item.active,
.dialog-item.last-in.active {
    background: #eef3f8;
}

.dialog-item.banned .di-name {
    color: #999;
    text-decoration: line-through;
}

.dialog-item.banned .di-preview {
    color: #aaa;
}

.dialog-item .di-line1 {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
}

.dialog-item .di-name {
    font-weight: 600;
    color: #222;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog-item .di-time {
    color: #888;
    font-size: 12px;
    flex: 0 0 auto;
}

.dialog-item .di-line2 {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.dialog-item .di-preview {
    color: #555;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}

.dialog-item .di-badge {
    flex: 0 0 auto;
    background: #4a6fa5;
    color: #fff;
    border-radius: 4px;
    padding: 0 6px;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 12px;
}

/* ----- Chat ----- */

.chat {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fafafa;
}

.chat-header {
    flex: 0 0 auto;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 10px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-header .ch-info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header .ch-name {
    font-weight: 600;
    color: #222;
}

.chat-header .ch-meta {
    color: #777;
    font-size: 12px;
}

.chat-header .ch-actions {
    flex: 0 0 auto;
}

.ban-btn {
    border-color: #d44;
    color: #b00020;
}

.ban-btn:hover {
    background: #fbeaea;
}

.ban-btn:active {
    background: #f5d8d8;
}

.ch-banned {
    color: #b00020;
    font-weight: 600;
    font-size: 13px;
}

.messages-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    word-wrap: break-word;
    word-break: break-word;
}

.message.in {
    align-self: flex-start;
    background: #f0f0f0;
    color: #222;
}

.message.out {
    align-self: flex-end;
    background: #dde6f1;
    border-color: #c8d4e3;
    color: #222;
}

.message .m-text {
    white-space: pre-wrap;
}

.message .m-time {
    margin-top: 4px;
    font-size: 11px;
    color: #777;
}

.message.pending {
    opacity: 0.6;
}

.message.failed {
    border-color: #d44;
    background: #fbeaea;
}

.message.failed .m-time {
    color: #b00020;
}

/* ----- Media ----- */

.message .m-photo-link {
    display: block;
    margin-bottom: 4px;
}

.message .m-photo {
    display: block;
    max-width: 100%;
    max-height: 320px;
    border: 1px solid #d4d4d4;
}

.message .m-voice {
    display: block;
    width: 100%;
    max-width: 280px;
    margin-bottom: 4px;
}

.message .m-sticker {
    display: block;
    max-width: 128px;
    max-height: 128px;
    margin-bottom: 4px;
}

.message .m-doc {
    display: inline-block;
    padding: 6px 10px;
    background: #fff;
    border: 1px solid #d4d4d4;
    color: #2c5aa0;
    text-decoration: none;
    margin-bottom: 4px;
    word-break: break-all;
}

.message .m-doc:hover {
    background: #f5f5f5;
}

.message .m-media-stub {
    color: #888;
    font-style: italic;
    margin-bottom: 4px;
}

.send-form {
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding: 10px;
    display: flex;
    gap: 8px;
}

.send-form input {
    flex: 1 1 auto;
}

.chat-empty {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
}
