:root {
    --ink: #2c1810;
    --ink-soft: #3d2817;
    --ink-deep: #1f110a;
    --line: #5c4027;
    --surface: #4a301b;
    --surface-active: #654938;
    --paper: #fffdf9;
    --muted: #b8ada7;
    --muted-dark: #81736c;
    --green: #4ade80;
    --danger: #ff8a8a;
    --shadow: 0 22px 60px rgba(18, 8, 3, .22);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
    min-height: 100dvh;
    color: var(--paper);
    background: var(--ink);
    font-family: "DM Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled { cursor: not-allowed; opacity: .55; }

/* Authentication */
.auth-container {
    display: grid;
    min-height: 100dvh;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 12%, rgba(144, 94, 54, .35), transparent 36%),
        var(--ink-deep);
}
.auth-card {
    width: min(100%, 420px);
    padding: 38px;
    border: 1px solid var(--line);
    border-radius: 26px;
    color: var(--paper);
    background: var(--ink-soft);
    box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0; font-size: 1.8rem; letter-spacing: -.045em; }
.auth-card > p { margin: 10px 0 28px; color: var(--muted); }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 8px; color: #f2e8e1; font-size: .88rem; font-weight: 700; }
.form-group input {
    width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px;
    outline: none; color: var(--paper); background: var(--ink-deep);
}
.form-group input:focus { border-color: #9a7252; box-shadow: 0 0 0 3px rgba(240,195,157,.12); }
.btn {
    width: 100%; height: 48px; border: 0; border-radius: 12px; color: var(--ink);
    background: var(--paper); font-weight: 800; transition: .2s ease;
}
.btn:hover { background: #f0c39d; transform: translateY(-1px); }
.bottom-text { margin-top: 22px; color: var(--muted); font-size: .9rem; text-align: center; }
.bottom-text a { color: #f0c39d; font-weight: 700; text-decoration: none; }
#message { min-height: 20px; margin: 14px 0 0; color: var(--danger); font-size: .87rem; text-align: center; }

.chat-app { display: flex; min-height: 100dvh; overflow: hidden; }
.sidebar {
    width: min(380px, 31vw);
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: var(--ink);
    border-right: 1px solid var(--ink-soft);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 28px 22px 22px; }
.brand { color: var(--paper); text-decoration: none; font-size: 1.7rem; font-weight: 800; letter-spacing: -.06em; }
.header-actions { display: flex; gap: 12px; align-items: center; }
.icon-button, .profile-avatar, .send-button {
    display: grid; place-items: center; flex: 0 0 auto; width: 42px; height: 42px;
    border: 1px solid rgba(255,255,255,.12); border-radius: 50%; color: var(--paper);
    background: rgba(255,255,255,.09); transition: .2s ease;
}
.icon-button:hover, .profile-avatar:hover { transform: translateY(-1px); background: rgba(255,255,255,.16); }
.icon-button svg, .send-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.profile-avatar { border: 0; color: var(--ink); background: #f0c39d; font-size: .9rem; font-weight: 800; }
.search-wrap { position: relative; margin: 0 22px 12px; }
.search-wrap input {
    width: 100%; height: 52px; padding: 0 16px 0 48px; color: var(--paper); outline: none;
    border: 1px solid var(--line); border-radius: 999px; background: var(--ink-deep);
}
.search-wrap input::placeholder { color: var(--muted-dark); }
.search-wrap input:focus { border-color: #9a7252; box-shadow: 0 0 0 3px rgba(240, 195, 157, .12); }
.search-icon { position: absolute; width: 20px; height: 20px; left: 17px; top: 16px; fill: none; stroke: var(--muted); stroke-width: 2; }
.connection-bar { min-height: 24px; padding: 2px 23px 10px; color: var(--muted); font-size: .72rem; }
.connection-bar.connected { color: var(--green); }
.user-list { flex: 1; overflow-y: auto; padding: 3px 10px 16px; scrollbar-color: var(--line) transparent; }
.user-item {
    width: 100%; display: flex; align-items: center; gap: 13px; padding: 12px; border: 1px solid transparent;
    border-radius: 18px; color: var(--paper); background: transparent; text-align: left; transition: .2s ease;
}
.user-item:hover { background: rgba(255,255,255,.07); }
.user-item.active-chat { background: var(--surface-active); border-color: rgba(255,255,255,.28); }
.user-avatar, .recipient-avatar {
    width: 52px; height: 52px; border-radius: 50%; object-fit: cover; color: var(--ink);
    background: #efc5a2; display: grid; place-items: center; font-weight: 800; flex: 0 0 auto;
}
.user-info { min-width: 0; flex: 1; }
.user-top, .user-bottom { display: flex; align-items: center; gap: 8px; }
.user-top { justify-content: space-between; }
.user-top strong { overflow: hidden; font-size: .98rem; text-overflow: ellipsis; white-space: nowrap; }
.user-time { flex: 0 0 auto; color: var(--muted); font-size: .73rem; }
.user-bottom { margin-top: 5px; }
.last-message { overflow: hidden; color: #d4ccc7; font-size: .86rem; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 9px; height: 9px; flex: 0 0 auto; border: 2px solid var(--ink); border-radius: 50%; background: #777; }
.status-dot.online { background: var(--green); }
.unread-badge {
    display: grid; min-width: 22px; height: 22px; padding: 0 6px; place-items: center;
    border-radius: 999px; color: var(--ink); background: var(--paper); font-size: .7rem; font-weight: 800;
}

.chat-area { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--ink-deep); }
.chat-header {
    z-index: 1; display: flex; align-items: center; gap: 13px; margin: 27px 28px 0; padding: 14px 18px;
    border: 1px solid var(--line); border-radius: 27px; background: var(--ink-soft); box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.recipient-avatar { width: 48px; height: 48px; }
.recipient-details { min-width: 0; flex: 1; }
.recipient-details h1 { overflow: hidden; margin: 0; font-size: 1.12rem; text-overflow: ellipsis; white-space: nowrap; }
.recipient-details p { margin: 3px 0 0; color: var(--green); font-size: .82rem; }
.mobile-back { display: none; }
.empty-chat { display: grid; place-content: center; justify-items: center; flex: 1; gap: 9px; padding: 40px; text-align: center; color: var(--muted); }
.empty-chat-icon { display: grid; place-items: center; width: 62px; height: 62px; margin-bottom: 8px; border-radius: 22px; color: #f0c39d; background: var(--surface); font-size: 1.8rem; }
.empty-chat h2 { margin: 0; color: var(--paper); font-size: 1.2rem; }
.empty-chat p { max-width: 280px; margin: 0; font-size: .9rem; line-height: 1.5; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 42px; scrollbar-color: var(--line) transparent; }
.messages[hidden], .empty-chat[hidden], .typing[hidden] { display: none !important; }
.message { max-width: min(74%, 640px); width: fit-content; margin: 0 0 18px; padding: 13px 16px 9px; font-size: 1rem; line-height: 1.42; box-shadow: 0 4px 12px rgba(0,0,0,.05); }
.message.received { color: var(--paper); border: 1px solid #5a3c22; border-radius: 22px 22px 22px 7px; background: var(--surface); }
.message.sent { margin-left: auto; color: var(--ink); border-radius: 22px 22px 7px 22px; background: var(--paper); }
.message-content { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { display: block; margin-top: 5px; color: inherit; font-size: .68rem; opacity: .58; text-align: right; }
.message-status { margin-left: 3px; font-weight: 800; letter-spacing: -2px; }
.message-status.seen { color: #438cd5; opacity: 1; }
.typing { display: flex; align-items: center; gap: 5px; margin: 0 42px 8px; color: var(--muted); font-size: .75rem; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing-bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }.typing span:nth-child(3) { animation-delay: .3s; }.typing small { margin-left: 3px; }
@keyframes typing-bounce { 0%,60%,100% { transform: translateY(0); opacity:.35; } 30% { transform: translateY(-4px); opacity:1; } }
.message-box { display: flex; align-items: center; gap: 8px; margin: 0 28px 28px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 25px; background: var(--ink-soft); }
.message-box input { min-width: 0; flex: 1; height: 42px; padding: 0 8px; border: 0; outline: none; color: var(--paper); background: transparent; }
.message-box input::placeholder { color: var(--muted); }
.composer-action { width: 38px; height: 38px; }
.send-button { border: 0; color: var(--ink); background: var(--paper); }
.send-button:hover:not(:disabled) { transform: scale(1.04); background: #f0c39d; }
.toast-region { position: fixed; z-index: 20; right: 22px; bottom: 22px; display: grid; gap: 10px; width: min(360px, calc(100vw - 44px)); }
.toast { padding: 14px 16px; border: 1px solid rgba(255,255,255,.18); border-radius: 15px; color: var(--paper); background: #4b3021; box-shadow: var(--shadow); animation: toast-in .25s ease-out; }
.toast.error { border-color: rgba(255,138,138,.5); }.toast.success { border-color: rgba(74,222,128,.45); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
body.dashboard-page {
    height: 100dvh;
    overflow: hidden;
}

.dashboard-page .chat-app {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.dashboard-page .sidebar,
.dashboard-page .chat-area {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.dashboard-page .user-list,
.dashboard-page .messages {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.typing[hidden],
.messages[hidden],
.empty-chat[hidden] {
    display: none !important;
}

.recipient-details p.offline {
    color: var(--muted);
}

.logout-button:hover {
    color: #ffb4a8;
    background: rgba(255, 138, 138, .16);
}

.unread-badge {
    display: grid;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    place-items: center;
    border-radius: 999px;
    color: var(--ink);
    background: var(--paper);
    font-size: .7rem;
    font-weight: 800;
}
