/* ───────────── Reset & Base ───────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary: #111b21;
    --bg-secondary: #202c33;
    --bg-tertiary: #2a3942;
    --bg-chat: #0b141a;
    --msg-mine: #005c4b;
    --msg-other: #202c33;
    --msg-mine-hover: #025c4b;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --accent: #00a884;
    --accent-hover: #06cf9c;
    --danger: #ef5350;
    --border: #313d45;
    --shadow: rgba(0,0,0,0.4);
    font-size: 15px;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ───────────── Login Page ───────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-chat);
    min-height: 100vh;
    padding: 1rem;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 32px var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-icon {
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* ───────────── Buttons ───────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-block {
    width: 100%;
}

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.4rem;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.btn-logout:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ───────────── Alert ───────────── */
.alert {
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.alert-error {
    background: rgba(239, 83, 80, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 83, 80, 0.3);
}

/* ───────────── Chat App Layout ───────────── */
.chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-primary);
    position: relative;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

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

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
}

.online-status {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
}

.user-badge {
    background: var(--bg-tertiary);
    color: var(--accent);
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* ───────────── Messages ───────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    background: var(--bg-chat);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5 L35 15 L45 15 L37 22 L40 32 L30 26 L20 32 L23 22 L15 15 L25 15 Z' fill='rgba(255,255,255,0.02)'/%3E%3C/svg%3E");
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Date separator */
.date-separator {
    text-align: center;
    margin: 0.75rem 0;
}

.date-separator span {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 7px;
    font-size: 0.75rem;
    color: var(--text-muted);
    box-shadow: 0 1px 2px var(--shadow);
}

/* Message bubbles */
.message-row {
    display: flex;
    margin-bottom: 0.3rem;
    animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-row.mine {
    justify-content: flex-end;
}

.message-row.others {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 0.5rem 0.7rem 0.4rem;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.45;
    font-size: 0.925rem;
}

.message-row.mine .message-bubble {
    background: var(--msg-mine);
    border-bottom-right-radius: 4px;
}

.message-row.others .message-bubble {
    background: var(--msg-other);
    border-bottom-left-radius: 4px;
}

.message-sender {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.15rem;
}

.message-text {
    margin-bottom: 0.2rem;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.message-row.mine .message-meta {
    color: rgba(255,255,255,0.6);
}

/* Consecutive messages (same sender) group tighter */
.message-row.consecutive {
    margin-bottom: 0.1rem;
}

.message-row.consecutive .message-bubble {
    border-radius: 8px;
}

.message-row.mine.consecutive .message-bubble {
    border-bottom-right-radius: 4px;
    border-top-right-radius: 4px;
}

.message-row.others.consecutive .message-bubble {
    border-bottom-left-radius: 4px;
    border-top-left-radius: 4px;
}

.message-row.consecutive .message-sender {
    display: none;
}

/* Loading / system messages */
.messages-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 0.5rem;
    text-align: center;
}

.empty-state svg {
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.9rem;
}

/* New message indicator */
.new-msg-indicator {
    position: absolute;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 5;
    display: none;
    animation: bounceIn 0.3s ease;
}

@keyframes bounceIn {
    0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ───────────── Input Area ───────────── */
.input-area {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.input-wrapper textarea {
    flex: 1;
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.925rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.input-wrapper textarea:focus {
    border-color: var(--accent);
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

/* ───────────── Responsive ───────────── */
@media (max-width: 600px) {
    :root { font-size: 14px; }
    .message-bubble { max-width: 85%; }
    .messages-container { padding: 0.75rem 0.75rem; }
    .chat-header { padding: 0.5rem 0.75rem; }
    .input-area { padding: 0.4rem 0.75rem; }
}
