:root {
    --green: #07c160;
    --green-dark: #06ad56;
    --bg: #ededed;
    --sidebar-bg: #2e2e2e;
    --chat-bg: #f0efe7;
    --bubble-in: #fff;
    --bubble-out: #95ec69;
    --text: #333;
    --text-light: #999;
    --border: #ddd;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* ===== Login ===== */
#login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--bg);
}

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.login-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
}

.login-card .sub {
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 24px;
}

#qr-box {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.btn-g {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 12px 40px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}

.btn-g:hover {
    background: var(--green-dark);
}

.btn-g:disabled {
    background: #ccc;
    cursor: default;
}

#login-status {
    font-size: 14px;
    color: var(--text-light);
    margin: 12px 0;
    min-height: 20px;
}

.ok {
    color: var(--green) !important;
    font-weight: bold;
}

.err {
    color: #e64340 !important;
}

/* ===== Chat Layout ===== */
#chat-screen {
    display: none;
    height: 100vh;
    flex-direction: row;
}

.side {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.side-hd {
    padding: 14px 16px;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.side-hd .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    display: inline-block;
    margin-right: 4px;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .3
    }
}

#conv-list {
    flex: 1;
    overflow-y: auto;
}

#conv-list::-webkit-scrollbar {
    width: 4px;
}

#conv-list::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 2px;
}

.ci {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    gap: 10px;
    transition: background .15s;
}

.ci:hover {
    background: #3a3a3a;
}

.ci.active {
    background: #444;
}

.ci-av {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    background: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-size: 13px;
    flex-shrink: 0;
}

.ci-info {
    flex: 1;
    min-width: 0;
}

.ci-name {
    color: #eee;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ci-last {
    color: #888;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.ci-meta {
    text-align: right;
    flex-shrink: 0;
}

.ci-time {
    color: #777;
    font-size: 11px;
}

.badge {
    background: #e64340;
    color: #fff;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-top: 4px;
}

/* ===== Main Panel ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-hd {
    padding: 14px 20px;
    background: #f5f5f5;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    font-weight: 500;
}

#empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 14px;
}

#msgs {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.chat-hd,
#msgs,
.inp-area {
    display: none;
}

#msgs::-webkit-scrollbar {
    width: 6px;
}

#msgs::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* ===== Messages ===== */
.m {
    display: flex;
    margin-bottom: 16px;
    gap: 8px;
    max-width: 75%;
}

.m-in {
    align-self: flex-start;
}

.m-out {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-left: auto;
}

.m-av {
    width: 34px;
    height: 34px;
    border-radius: 4px;
    background: #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #666;
    flex-shrink: 0;
}

.m-out .m-av {
    background: var(--green);
    color: #fff;
}

.m-body {
    display: flex;
    flex-direction: column;
}

.m-in .m-body {
    align-items: flex-start;
}

.m-out .m-body {
    align-items: flex-end;
}

.m-c {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.m-in .m-c {
    background: var(--bubble-in);
}

.m-out .m-c {
    background: var(--bubble-out);
}

.m-t {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 3px;
    padding: 0 4px;
}

.m-img {
    max-width: 220px;
    max-height: 300px;
    border-radius: 6px;
    cursor: pointer;
    display: block;
}

.m-voice {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    min-width: 80px;
}

.m-voice-txt {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 2px;
}

.m-voice-bar {
    display: flex;
    align-items: center;
    gap: 4px;
}

.m-voice-save {
    font-size: 11px;
    color: var(--text-light);
    cursor: pointer;
    text-decoration: underline;
}

.m-voice-save:hover {
    color: var(--text);
}

.m-ref {
    font-size: 12px;
    color: var(--text-light);
    border-left: 2px solid #ccc;
    padding-left: 8px;
    margin-bottom: 6px;
}

.m-file {
    display: flex;
    align-items: center;
    gap: 6px;
}

.m-sys {
    text-align: center;
    color: var(--text-light);
    font-size: 12px;
    margin: 12px 0;
}

/* ===== Input ===== */
.inp-area {
    padding: 10px 16px;
    background: #f5f5f5;
    border-top: 1px solid var(--border);
    flex-direction: column;
    gap: 6px;
}

.inp-toolbar {
    display: flex;
    gap: 2px;
}

.inp-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ib {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 18px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ib:hover {
    background: #e5e5e5;
}

.ib.rec {
    background: #fdd;
    color: #e64340;
}

.ib-logout {
    width: auto;
    height: auto;
    font-size: 12px;
    color: #aaa;
    padding: 2px 6px;
}

#msg-in {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
    background: #fff;
}

#msg-in:focus {
    border-color: var(--green);
}

.btn-send {
    background: var(--green);
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--green-dark);
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .85);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.modal.show {
    display: flex;
}

.modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.rec-tip {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, .7);
    color: #fff;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 14px;
    z-index: 100;
}

.rec-tip.show {
    display: block;
}

@media (max-width: 640px) {
    .side {
        width: 72px;
    }

    .ci-info,
    .ci-meta {
        display: none;
    }

    .ci {
        justify-content: center;
        padding: 12px 8px;
    }
}