:root {
    --bg: #0f1720;
    --panel: #17212b;
    --panel-2: #1f2b38;
    --text: #e9eef3;
    --muted: #8fa3b7;
    --accent: #2f8ee5;
    --accent-2: #54a9eb;
    --danger: #e05656;
    --incoming: #1f2b38;
    --outgoing: #2b5278;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, "Microsoft YaHei", sans-serif;
}

a { color: var(--accent-2); text-decoration: none; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid #0b1218;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { font-weight: 700; font-size: 18px; color: var(--text); }

.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); }
.logout-form { margin: 0; }

.link-button {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}
.link-button:hover { color: var(--text); }

.page { max-width: 900px; margin: 0 auto; padding: 20px; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.card {
    background: var(--panel);
    border-radius: 12px;
    padding: 24px;
    margin-top: 24px;
}
.card.narrow { max-width: 420px; margin: 60px auto 0; }

.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

input[type="text"], input[type="password"], input[type="tel"], input[type="search"] {
    width: 100%;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid #2d3d4d;
    background: var(--panel-2);
    color: var(--text);
    font-size: 14px;
    outline: none;
}
input:focus { border-color: var(--accent); }

button, .button {
    display: inline-block;
    padding: 11px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
}
button.primary, .button.primary { background: var(--accent); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--accent-2); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid #2d3d4d; }
button.secondary:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }

.alert {
    background: rgba(224, 86, 86, .12);
    border: 1px solid rgba(224, 86, 86, .4);
    color: #ffb4b4;
    padding: 10px 12px;
    border-radius: 8px;
    margin-top: 14px;
    font-size: 14px;
    white-space: pre-wrap;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar-actions { display: flex; align-items: center; gap: 10px; }
.toolbar-actions input { width: 220px; }
.back { color: var(--muted); margin-right: 4px; }

.chat-list { display: flex; flex-direction: column; gap: 6px; }

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--panel);
    border-radius: 10px;
    color: var(--text);
    position: relative;
}
.chat-item:hover { background: var(--panel-2); }

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex: 0 0 auto;
}

.chat-main { flex: 1; min-width: 0; }
.chat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-name { font-weight: 600; }
.chat-time { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

.chat-preview {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    font-size: 12px;
    padding: 2px 7px;
    flex: 0 0 auto;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    padding: 8px 4px 24px;
}

.msg-row { display: flex; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }

.bubble {
    max-width: 72%;
    padding: 9px 12px;
    border-radius: 10px;
    background: var(--incoming);
    white-space: pre-wrap;
    word-break: break-word;
}
.msg-row.out .bubble { background: var(--outgoing); }

.sender { font-size: 12px; color: var(--accent-2); margin-bottom: 3px; }
.text { font-size: 14px; line-height: 1.5; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
