/* =============================================
   Agent Instaag - Real-time Chat Forum Styles
   ============================================= */

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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b8;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-light: rgba(233, 69, 96, 0.15);
    --success: #2ecc71;
    --warning: #f39c12;
    --border: #2a2a4a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --max-width: 800px;
}

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

/* --- Header --- */
.chat-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.chat-header h1 {
    font-size: 18px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #ff6b81);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.online-count {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    margin-top: 2px;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-card);
    object-fit: cover;
    border: 2px solid var(--accent);
    flex-shrink: 0;
}

.username-display {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.edit-name-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-size: 14px;
}

.edit-name-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
}

/* --- Connection Status --- */
.connection-status {
    text-align: center;
    padding: 4px 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.3s;
}

.connection-status.connected {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
}

.connection-status.disconnected {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.connection-status.reconnecting {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

/* --- Messages Container --- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
    min-height: 0;
    height: calc(100vh - 180px);
}

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

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

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

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* --- Message Bubbles --- */
.message {
    display: flex;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

.message:hover {
    background: var(--accent-light);
}

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-card);
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 4px;
}

.message.own .msg-avatar {
    display: none;
}

.msg-body {
    background: var(--bg-card);
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.own .msg-body {
    background: var(--accent);
    border-color: var(--accent);
    border-bottom-right-radius: 4px;
}

.message:not(.own) .msg-body {
    border-bottom-left-radius: 4px;
}

.msg-username {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 3px;
}

.message.own .msg-username {
    color: rgba(255,255,255,0.9);
}

.msg-content {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
}

.message.own .msg-content {
    color: #fff;
}

.msg-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: right;
}

.message.own .msg-time {
    color: rgba(255,255,255,0.7);
}

/* --- Date Separator --- */
.date-separator {
    text-align: center;
    padding: 16px 0 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    position: relative;
}

.date-separator::before,
.date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--border);
}

.date-separator::before {
    left: 0;
}

.date-separator::after {
    right: 0;
}

/* --- Loading & Empty State --- */
.loading, .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    text-align: center;
    flex: 1;
}

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

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

.empty-state .emoji {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* --- Input Area --- */
.input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.input-area textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.5;
}

.input-area textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.input-area textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

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

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

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

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h2 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.modal input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.modal input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}

.btn {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

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

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

/* --- Typing Indicator --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.typing-indicator .dots {
    display: flex;
    gap: 3px;
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.16s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* --- Message Status --- */
.msg-status {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    text-align: right;
}

.msg-status.sending {
    color: var(--warning);
}

.msg-status.sent {
    color: var(--success);
}

.msg-status.failed {
    color: #e74c3c;
}

/* --- New Message Indicator --- */
.new-message-bar {
    text-align: center;
    padding: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin: 8px 0;
    animation: fadeIn 0.3s ease;
}

.new-message-bar:hover {
    background: var(--accent-hover);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .chat-header {
        padding: 10px 12px;
    }

    .chat-header h1 {
        font-size: 16px;
    }

    .messages-container {
        padding: 12px;
        height: calc(100vh - 160px);
    }

    .message {
        max-width: 95%;
        padding: 4px 8px;
    }

    .msg-body {
        padding: 8px 12px;
    }

    .input-area {
        padding: 8px 12px;
    }

    .username-display {
        max-width: 80px;
        font-size: 13px;
    }

    .avatar {
        width: 30px;
        height: 30px;
    }
}
